aboutsummaryrefslogtreecommitdiffstats
path: root/xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/block/xl_segment_proc.c
blob: 59a3884de95659ab4a08d72e47831a483747bd7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/*
 * xl_segment_proc.c
 * 
 * XenoLinux virtual disk proc interface .
 */

#include "xl_block.h"
#include <linux/proc_fs.h>
#include <linux/delay.h>

static struct proc_dir_entry *vhd;

static int proc_read_vhd(char *page, char **start, off_t off,
			 int count, int *eof, void *data)
{
    return 0;
}

#define isdelim(c) \
  (c==' '||c==','||c=='\n'||c=='\r'||c=='\t'||c==':'||c=='('||c==')' ? 1 : 0)

char *get_string(char *string)                          /* a bit like strtok */
{
    static char *temp;
    int loop = 0;

    if (string != NULL)	
        temp = string;
    else
        string = temp;

 try_again:

    while (!isdelim(string[loop]))
    {
        if (string[loop] == '\0')
            return NULL;
        loop++;
    }

    string[loop] = '\0';	
    temp = (string + loop + 1);

    if (loop == 0)
    {
        string = temp;
        goto try_again;
    }

    return string;
}


#define isdigit(c) (c >= '0' && c <= '9' ? 1 : 0)
unsigned long to_number(char *string)                                /* atoi */
{
    unsigned long value = 0;

    if (string == NULL) return 0;

    while (!isdigit(*string) && *string != '\0') string++;

    while (isdigit(*string))
    {
        value = value * 10 + (*string - '0');
        string++;
    }

    return value;
}

static int proc_write_vhd(struct file *file, const char *buffer,
			  unsigned long count, void *data)
{
    char *local = kmalloc((count + 1) * sizeof(char), GFP_KERNEL);
    char *string;
    int loop;
    xv_disk_t xvd;

    memset (&xvd, 0, sizeof(xvd));

    if (copy_from_user(local, buffer, count))
    {
        return -EFAULT;
    }
    local[count] = '\0';

    string = get_string(local); /* domain specifier */
    if (string == NULL)
    {
        return count;
    }
    if (*string != 'd' && *string != 'D')
    {
        printk (KERN_ALERT 
                "error: domain specifier missing [%s]. should be \"domain\".\n",
                string);
        return count;
    }

    string = get_string(NULL); /* domain number */
    if (string == NULL)
    {
        printk (KERN_ALERT "error: domain number missing\n");
        return count;
    }
    xvd.domain = (int) to_number(string);

    string = get_string(NULL);
    if (string && (strcmp(string, "RO") == 0 || strcmp(string, "ro") == 0))
    {
        xvd.mode = XEN_DISK_READ_ONLY;
    }
    else if (string && (strcmp(string, "RW") == 0 || strcmp(string, "rw") == 0))
    {
        xvd.mode = XEN_DISK_READ_WRITE;
    }
    else
    {
        printk (KERN_ALERT 
                "error: bad mode [%s]. should be \"rw\" or \"ro\".\n",
                string);
        return count;
    }

    string = get_string(NULL);                           /* look for Segment */
    if (string == NULL || (*string != 's' && *string != 'S'))
    {
        printk (KERN_ALERT 
                "error: segment specifier missing [%s]. should be \"segment\".\n",
                string);
        return count;
    }

    string = get_string(NULL);                             /* segment number */
    if (string == NULL)
    {
        printk (KERN_ALERT "error: segment number missing\n");
        return count;
    }
    xvd.segment = (int) to_number(string);

    string = get_string(NULL);                           /* look for Extents */
    if (string == NULL || (*string != 'e' && *string != 'E'))
    {
        printk (KERN_ALERT 
                "error: extents specifier missing [%s]. should be \"extents\".\n",
                string);
        return count;
    }

    string = get_string(NULL);                          /* number of extents */
    if (string == NULL)
    {
        printk (KERN_ALERT "error: number of extents missing\n");
        return count;
    }
    xvd.ext_count = (int) to_number(string);

    /* ignore parenthesis */

    for (loop = 0; loop < xvd.ext_count; loop++)
    {
        string = get_string(NULL);                          /* look for Disk */
        if (string == NULL || (*string != 'd' && *string != 'D'))
        {
            printk (KERN_ALERT 
                    "hmm, extent disk specifier missing [%s]. should be \"disk\".\n",
                    string);
            return count;
        }
        string = get_string(NULL);                            /* disk number */
        if (string == NULL)
        {
            printk (KERN_ALERT "error: disk number missing\n");
            return count;
        }
        xvd.extents[loop].disk = xldev_to_physdev((int) to_number(string));

        string = get_string(NULL);                        /* look for Offset */
        if (string == NULL || (*string != 'o' && *string != 'O'))
        {
            printk (KERN_ALERT 
                    "error: disk offset missing [%s]. should be \"offset\".\n",
                    string);
            return count;
        }
        string = get_string(NULL);                                 /* offset */
        if (string == NULL)
        {
            printk (KERN_ALERT "error: offset missing\n");
            return count;
        }
        xvd.extents[loop].offset =  to_number(string);

        string = get_string(NULL);                          /* look for Size */
        if (string == NULL || (*string != 's' && *string != 'S'))
        {
            printk (KERN_ALERT 
                    "error: extent size missing [%s]. should be \"size\".\n",
                    string);
            return count;
        }
        string = get_string(NULL);                                   /* size */
        if (string == NULL)
        {
            printk (KERN_ALERT "error: extent size missing\n");
            return count;
        }
        xvd.extents[loop].size =  to_number(string);
    }

    xenolinux_control_msg(XEN_BLOCK_SEG_CREATE, (char *)&xvd, sizeof(xvd));

    return count;
}

/******************************************************************/

int __init xlseg_proc_init(void)
{
    vhd = create_proc_entry("xeno/dom0/vhd", 0644, NULL);
    if (vhd == NULL)
    {
        panic ("xlseg_init: unable to create vhd proc entry\n");
    }
    vhd->data       = NULL;
    vhd->read_proc  = proc_read_vhd;
    vhd->write_proc = proc_write_vhd;
    vhd->owner      = THIS_MODULE;

    printk(KERN_ALERT "XenoLinux Virtual Disk Device Monitor installed\n");
    return 0;
}

static void __exit xlseg_proc_cleanup(void)
{
    printk(KERN_ALERT "XenoLinux Virtual Disk Device Monitor uninstalled\n");
}

#ifdef MODULE
module_init(xlseg_proc_init);
module_exit(xlseg_proc_cleanup);
#endif