diff options
Diffstat (limited to 'drivers/xen/xenfs')
-rw-r--r-- | drivers/xen/xenfs/Makefile | 3 | ||||
-rw-r--r-- | drivers/xen/xenfs/privcmd.c | 400 | ||||
-rw-r--r-- | drivers/xen/xenfs/super.c | 66 | ||||
-rw-r--r-- | drivers/xen/xenfs/xenbus.c | 32 | ||||
-rw-r--r-- | drivers/xen/xenfs/xenfs.h | 3 | ||||
-rw-r--r-- | drivers/xen/xenfs/xenstored.c | 68 |
6 files changed, 547 insertions, 25 deletions
diff --git a/drivers/xen/xenfs/Makefile b/drivers/xen/xenfs/Makefile index 25275c3bbdff..4fde9440fe1f 100644 --- a/drivers/xen/xenfs/Makefile +++ b/drivers/xen/xenfs/Makefile | |||
@@ -1,3 +1,4 @@ | |||
1 | obj-$(CONFIG_XENFS) += xenfs.o | 1 | obj-$(CONFIG_XENFS) += xenfs.o |
2 | 2 | ||
3 | xenfs-objs = super.o xenbus.o \ No newline at end of file | 3 | xenfs-y = super.o xenbus.o privcmd.o |
4 | xenfs-$(CONFIG_XEN_DOM0) += xenstored.o | ||
diff --git a/drivers/xen/xenfs/privcmd.c b/drivers/xen/xenfs/privcmd.c new file mode 100644 index 000000000000..dbd3b16fd131 --- /dev/null +++ b/drivers/xen/xenfs/privcmd.c | |||
@@ -0,0 +1,400 @@ | |||
1 | /****************************************************************************** | ||
2 | * privcmd.c | ||
3 | * | ||
4 | * Interface to privileged domain-0 commands. | ||
5 | * | ||
6 | * Copyright (c) 2002-2004, K A Fraser, B Dragovic | ||
7 | */ | ||
8 | |||
9 | #include <linux/kernel.h> | ||
10 | #include <linux/sched.h> | ||
11 | #include <linux/slab.h> | ||
12 | #include <linux/string.h> | ||
13 | #include <linux/errno.h> | ||
14 | #include <linux/mm.h> | ||
15 | #include <linux/mman.h> | ||
16 | #include <linux/uaccess.h> | ||
17 | #include <linux/swap.h> | ||
18 | #include <linux/highmem.h> | ||
19 | #include <linux/pagemap.h> | ||
20 | #include <linux/seq_file.h> | ||
21 | |||
22 | #include <asm/pgalloc.h> | ||
23 | #include <asm/pgtable.h> | ||
24 | #include <asm/tlb.h> | ||
25 | #include <asm/xen/hypervisor.h> | ||
26 | #include <asm/xen/hypercall.h> | ||
27 | |||
28 | #include <xen/xen.h> | ||
29 | #include <xen/privcmd.h> | ||
30 | #include <xen/interface/xen.h> | ||
31 | #include <xen/features.h> | ||
32 | #include <xen/page.h> | ||
33 | #include <xen/xen-ops.h> | ||
34 | |||
35 | #ifndef HAVE_ARCH_PRIVCMD_MMAP | ||
36 | static int privcmd_enforce_singleshot_mapping(struct vm_area_struct *vma); | ||
37 | #endif | ||
38 | |||
39 | static long privcmd_ioctl_hypercall(void __user *udata) | ||
40 | { | ||
41 | struct privcmd_hypercall hypercall; | ||
42 | long ret; | ||
43 | |||
44 | if (copy_from_user(&hypercall, udata, sizeof(hypercall))) | ||
45 | return -EFAULT; | ||
46 | |||
47 | ret = privcmd_call(hypercall.op, | ||
48 | hypercall.arg[0], hypercall.arg[1], | ||
49 | hypercall.arg[2], hypercall.arg[3], | ||
50 | hypercall.arg[4]); | ||
51 | |||
52 | return ret; | ||
53 | } | ||
54 | |||
55 | static void free_page_list(struct list_head *pages) | ||
56 | { | ||
57 | struct page *p, *n; | ||
58 | |||
59 | list_for_each_entry_safe(p, n, pages, lru) | ||
60 | __free_page(p); | ||
61 | |||
62 | INIT_LIST_HEAD(pages); | ||
63 | } | ||
64 | |||
65 | /* | ||
66 | * Given an array of items in userspace, return a list of pages | ||
67 | * containing the data. If copying fails, either because of memory | ||
68 | * allocation failure or a problem reading user memory, return an | ||
69 | * error code; its up to the caller to dispose of any partial list. | ||
70 | */ | ||
71 | static int gather_array(struct list_head *pagelist, | ||
72 | unsigned nelem, size_t size, | ||
73 | void __user *data) | ||
74 | { | ||
75 | unsigned pageidx; | ||
76 | void *pagedata; | ||
77 | int ret; | ||
78 | |||
79 | if (size > PAGE_SIZE) | ||
80 | return 0; | ||
81 | |||
82 | pageidx = PAGE_SIZE; | ||
83 | pagedata = NULL; /* quiet, gcc */ | ||
84 | while (nelem--) { | ||
85 | if (pageidx > PAGE_SIZE-size) { | ||
86 | struct page *page = alloc_page(GFP_KERNEL); | ||
87 | |||
88 | ret = -ENOMEM; | ||
89 | if (page == NULL) | ||
90 | goto fail; | ||
91 | |||
92 | pagedata = page_address(page); | ||
93 | |||
94 | list_add_tail(&page->lru, pagelist); | ||
95 | pageidx = 0; | ||
96 | } | ||
97 | |||
98 | ret = -EFAULT; | ||
99 | if (copy_from_user(pagedata + pageidx, data, size)) | ||
100 | goto fail; | ||
101 | |||
102 | data += size; | ||
103 | pageidx += size; | ||
104 | } | ||
105 | |||
106 | ret = 0; | ||
107 | |||
108 | fail: | ||
109 | return ret; | ||
110 | } | ||
111 | |||
112 | /* | ||
113 | * Call function "fn" on each element of the array fragmented | ||
114 | * over a list of pages. | ||
115 | */ | ||
116 | static int traverse_pages(unsigned nelem, size_t size, | ||
117 | struct list_head *pos, | ||
118 | int (*fn)(void *data, void *state), | ||
119 | void *state) | ||
120 | { | ||
121 | void *pagedata; | ||
122 | unsigned pageidx; | ||
123 | int ret = 0; | ||
124 | |||
125 | BUG_ON(size > PAGE_SIZE); | ||
126 | |||
127 | pageidx = PAGE_SIZE; | ||
128 | pagedata = NULL; /* hush, gcc */ | ||
129 | |||
130 | while (nelem--) { | ||
131 | if (pageidx > PAGE_SIZE-size) { | ||
132 | struct page *page; | ||
133 | pos = pos->next; | ||
134 | page = list_entry(pos, struct page, lru); | ||
135 | pagedata = page_address(page); | ||
136 | pageidx = 0; | ||
137 | } | ||
138 | |||
139 | ret = (*fn)(pagedata + pageidx, state); | ||
140 | if (ret) | ||
141 | break; | ||
142 | pageidx += size; | ||
143 | } | ||
144 | |||
145 | return ret; | ||
146 | } | ||
147 | |||
148 | struct mmap_mfn_state { | ||
149 | unsigned long va; | ||
150 | struct vm_area_struct *vma; | ||
151 | domid_t domain; | ||
152 | }; | ||
153 | |||
154 | static int mmap_mfn_range(void *data, void *state) | ||
155 | { | ||
156 | struct privcmd_mmap_entry *msg = data; | ||
157 | struct mmap_mfn_state *st = state; | ||
158 | struct vm_area_struct *vma = st->vma; | ||
159 | int rc; | ||
160 | |||
161 | /* Do not allow range to wrap the address space. */ | ||
162 | if ((msg->npages > (LONG_MAX >> PAGE_SHIFT)) || | ||
163 | ((unsigned long)(msg->npages << PAGE_SHIFT) >= -st->va)) | ||
164 | return -EINVAL; | ||
165 | |||
166 | /* Range chunks must be contiguous in va space. */ | ||
167 | if ((msg->va != st->va) || | ||
168 | ((msg->va+(msg->npages<<PAGE_SHIFT)) > vma->vm_end)) | ||
169 | return -EINVAL; | ||
170 | |||
171 | rc = xen_remap_domain_mfn_range(vma, | ||
172 | msg->va & PAGE_MASK, | ||
173 | msg->mfn, msg->npages, | ||
174 | vma->vm_page_prot, | ||
175 | st->domain); | ||
176 | if (rc < 0) | ||
177 | return rc; | ||
178 | |||
179 | st->va += msg->npages << PAGE_SHIFT; | ||
180 | |||
181 | return 0; | ||
182 | } | ||
183 | |||
184 | static long privcmd_ioctl_mmap(void __user *udata) | ||
185 | { | ||
186 | struct privcmd_mmap mmapcmd; | ||
187 | struct mm_struct *mm = current->mm; | ||
188 | struct vm_area_struct *vma; | ||
189 | int rc; | ||
190 | LIST_HEAD(pagelist); | ||
191 | struct mmap_mfn_state state; | ||
192 | |||
193 | if (!xen_initial_domain()) | ||
194 | return -EPERM; | ||
195 | |||
196 | if (copy_from_user(&mmapcmd, udata, sizeof(mmapcmd))) | ||
197 | return -EFAULT; | ||
198 | |||
199 | rc = gather_array(&pagelist, | ||
200 | mmapcmd.num, sizeof(struct privcmd_mmap_entry), | ||
201 | mmapcmd.entry); | ||
202 | |||
203 | if (rc || list_empty(&pagelist)) | ||
204 | goto out; | ||
205 | |||
206 | down_write(&mm->mmap_sem); | ||
207 | |||
208 | { | ||
209 | struct page *page = list_first_entry(&pagelist, | ||
210 | struct page, lru); | ||
211 | struct privcmd_mmap_entry *msg = page_address(page); | ||
212 | |||
213 | vma = find_vma(mm, msg->va); | ||
214 | rc = -EINVAL; | ||
215 | |||
216 | if (!vma || (msg->va != vma->vm_start) || | ||
217 | !privcmd_enforce_singleshot_mapping(vma)) | ||
218 | goto out_up; | ||
219 | } | ||
220 | |||
221 | state.va = vma->vm_start; | ||
222 | state.vma = vma; | ||
223 | state.domain = mmapcmd.dom; | ||
224 | |||
225 | rc = traverse_pages(mmapcmd.num, sizeof(struct privcmd_mmap_entry), | ||
226 | &pagelist, | ||
227 | mmap_mfn_range, &state); | ||
228 | |||
229 | |||
230 | out_up: | ||
231 | up_write(&mm->mmap_sem); | ||
232 | |||
233 | out: | ||
234 | free_page_list(&pagelist); | ||
235 | |||
236 | return rc; | ||
237 | } | ||
238 | |||
239 | struct mmap_batch_state { | ||
240 | domid_t domain; | ||
241 | unsigned long va; | ||
242 | struct vm_area_struct *vma; | ||
243 | int err; | ||
244 | |||
245 | xen_pfn_t __user *user; | ||
246 | }; | ||
247 | |||
248 | static int mmap_batch_fn(void *data, void *state) | ||
249 | { | ||
250 | xen_pfn_t *mfnp = data; | ||
251 | struct mmap_batch_state *st = state; | ||
252 | |||
253 | if (xen_remap_domain_mfn_range(st->vma, st->va & PAGE_MASK, *mfnp, 1, | ||
254 | st->vma->vm_page_prot, st->domain) < 0) { | ||
255 | *mfnp |= 0xf0000000U; | ||
256 | st->err++; | ||
257 | } | ||
258 | st->va += PAGE_SIZE; | ||
259 | |||
260 | return 0; | ||
261 | } | ||
262 | |||
263 | static int mmap_return_errors(void *data, void *state) | ||
264 | { | ||
265 | xen_pfn_t *mfnp = data; | ||
266 | struct mmap_batch_state *st = state; | ||
267 | |||
268 | return put_user(*mfnp, st->user++); | ||
269 | } | ||
270 | |||
271 | static struct vm_operations_struct privcmd_vm_ops; | ||
272 | |||
273 | static long privcmd_ioctl_mmap_batch(void __user *udata) | ||
274 | { | ||
275 | int ret; | ||
276 | struct privcmd_mmapbatch m; | ||
277 | struct mm_struct *mm = current->mm; | ||
278 | struct vm_area_struct *vma; | ||
279 | unsigned long nr_pages; | ||
280 | LIST_HEAD(pagelist); | ||
281 | struct mmap_batch_state state; | ||
282 | |||
283 | if (!xen_initial_domain()) | ||
284 | return -EPERM; | ||
285 | |||
286 | if (copy_from_user(&m, udata, sizeof(m))) | ||
287 | return -EFAULT; | ||
288 | |||
289 | nr_pages = m.num; | ||
290 | if ((m.num <= 0) || (nr_pages > (LONG_MAX >> PAGE_SHIFT))) | ||
291 | return -EINVAL; | ||
292 | |||
293 | ret = gather_array(&pagelist, m.num, sizeof(xen_pfn_t), | ||
294 | m.arr); | ||
295 | |||
296 | if (ret || list_empty(&pagelist)) | ||
297 | goto out; | ||
298 | |||
299 | down_write(&mm->mmap_sem); | ||
300 | |||
301 | vma = find_vma(mm, m.addr); | ||
302 | ret = -EINVAL; | ||
303 | if (!vma || | ||
304 | vma->vm_ops != &privcmd_vm_ops || | ||
305 | (m.addr != vma->vm_start) || | ||
306 | ((m.addr + (nr_pages << PAGE_SHIFT)) != vma->vm_end) || | ||
307 | !privcmd_enforce_singleshot_mapping(vma)) { | ||
308 | up_write(&mm->mmap_sem); | ||
309 | goto out; | ||
310 | } | ||
311 | |||
312 | state.domain = m.dom; | ||
313 | state.vma = vma; | ||
314 | state.va = m.addr; | ||
315 | state.err = 0; | ||
316 | |||
317 | ret = traverse_pages(m.num, sizeof(xen_pfn_t), | ||
318 | &pagelist, mmap_batch_fn, &state); | ||
319 | |||
320 | up_write(&mm->mmap_sem); | ||
321 | |||
322 | if (state.err > 0) { | ||
323 | state.user = m.arr; | ||
324 | ret = traverse_pages(m.num, sizeof(xen_pfn_t), | ||
325 | &pagelist, | ||
326 | mmap_return_errors, &state); | ||
327 | } | ||
328 | |||
329 | out: | ||
330 | free_page_list(&pagelist); | ||
331 | |||
332 | return ret; | ||
333 | } | ||
334 | |||
335 | static long privcmd_ioctl(struct file *file, | ||
336 | unsigned int cmd, unsigned long data) | ||
337 | { | ||
338 | int ret = -ENOSYS; | ||
339 | void __user *udata = (void __user *) data; | ||
340 | |||
341 | switch (cmd) { | ||
342 | case IOCTL_PRIVCMD_HYPERCALL: | ||
343 | ret = privcmd_ioctl_hypercall(udata); | ||
344 | break; | ||
345 | |||
346 | case IOCTL_PRIVCMD_MMAP: | ||
347 | ret = privcmd_ioctl_mmap(udata); | ||
348 | break; | ||
349 | |||
350 | case IOCTL_PRIVCMD_MMAPBATCH: | ||
351 | ret = privcmd_ioctl_mmap_batch(udata); | ||
352 | break; | ||
353 | |||
354 | default: | ||
355 | ret = -EINVAL; | ||
356 | break; | ||
357 | } | ||
358 | |||
359 | return ret; | ||
360 | } | ||
361 | |||
362 | #ifndef HAVE_ARCH_PRIVCMD_MMAP | ||
363 | static int privcmd_fault(struct vm_area_struct *vma, struct vm_fault *vmf) | ||
364 | { | ||
365 | printk(KERN_DEBUG "privcmd_fault: vma=%p %lx-%lx, pgoff=%lx, uv=%p\n", | ||
366 | vma, vma->vm_start, vma->vm_end, | ||
367 | vmf->pgoff, vmf->virtual_address); | ||
368 | |||
369 | return VM_FAULT_SIGBUS; | ||
370 | } | ||
371 | |||
372 | static struct vm_operations_struct privcmd_vm_ops = { | ||
373 | .fault = privcmd_fault | ||
374 | }; | ||
375 | |||
376 | static int privcmd_mmap(struct file *file, struct vm_area_struct *vma) | ||
377 | { | ||
378 | /* Unsupported for auto-translate guests. */ | ||
379 | if (xen_feature(XENFEAT_auto_translated_physmap)) | ||
380 | return -ENOSYS; | ||
381 | |||
382 | /* DONTCOPY is essential for Xen because copy_page_range doesn't know | ||
383 | * how to recreate these mappings */ | ||
384 | vma->vm_flags |= VM_RESERVED | VM_IO | VM_DONTCOPY | VM_PFNMAP; | ||
385 | vma->vm_ops = &privcmd_vm_ops; | ||
386 | vma->vm_private_data = NULL; | ||
387 | |||
388 | return 0; | ||
389 | } | ||
390 | |||
391 | static int privcmd_enforce_singleshot_mapping(struct vm_area_struct *vma) | ||
392 | { | ||
393 | return (xchg(&vma->vm_private_data, (void *)1) == NULL); | ||
394 | } | ||
395 | #endif | ||
396 | |||
397 | const struct file_operations privcmd_file_ops = { | ||
398 | .unlocked_ioctl = privcmd_ioctl, | ||
399 | .mmap = privcmd_mmap, | ||
400 | }; | ||
diff --git a/drivers/xen/xenfs/super.c b/drivers/xen/xenfs/super.c index 78bfab0700ba..1aa389719846 100644 --- a/drivers/xen/xenfs/super.c +++ b/drivers/xen/xenfs/super.c | |||
@@ -22,6 +22,46 @@ | |||
22 | MODULE_DESCRIPTION("Xen filesystem"); | 22 | MODULE_DESCRIPTION("Xen filesystem"); |
23 | MODULE_LICENSE("GPL"); | 23 | MODULE_LICENSE("GPL"); |
24 | 24 | ||
25 | static struct inode *xenfs_make_inode(struct super_block *sb, int mode) | ||
26 | { | ||
27 | struct inode *ret = new_inode(sb); | ||
28 | |||
29 | if (ret) { | ||
30 | ret->i_mode = mode; | ||
31 | ret->i_uid = ret->i_gid = 0; | ||
32 | ret->i_blocks = 0; | ||
33 | ret->i_atime = ret->i_mtime = ret->i_ctime = CURRENT_TIME; | ||
34 | } | ||
35 | return ret; | ||
36 | } | ||
37 | |||
38 | static struct dentry *xenfs_create_file(struct super_block *sb, | ||
39 | struct dentry *parent, | ||
40 | const char *name, | ||
41 | const struct file_operations *fops, | ||
42 | void *data, | ||
43 | int mode) | ||
44 | { | ||
45 | struct dentry *dentry; | ||
46 | struct inode *inode; | ||
47 | |||
48 | dentry = d_alloc_name(parent, name); | ||
49 | if (!dentry) | ||
50 | return NULL; | ||
51 | |||
52 | inode = xenfs_make_inode(sb, S_IFREG | mode); | ||
53 | if (!inode) { | ||
54 | dput(dentry); | ||
55 | return NULL; | ||
56 | } | ||
57 | |||
58 | inode->i_fop = fops; | ||
59 | inode->i_private = data; | ||
60 | |||
61 | d_add(dentry, inode); | ||
62 | return dentry; | ||
63 | } | ||
64 | |||
25 | static ssize_t capabilities_read(struct file *file, char __user *buf, | 65 | static ssize_t capabilities_read(struct file *file, char __user *buf, |
26 | size_t size, loff_t *off) | 66 | size_t size, loff_t *off) |
27 | { | 67 | { |
@@ -35,6 +75,7 @@ static ssize_t capabilities_read(struct file *file, char __user *buf, | |||
35 | 75 | ||
36 | static const struct file_operations capabilities_file_ops = { | 76 | static const struct file_operations capabilities_file_ops = { |
37 | .read = capabilities_read, | 77 | .read = capabilities_read, |
78 | .llseek = default_llseek, | ||
38 | }; | 79 | }; |
39 | 80 | ||
40 | static int xenfs_fill_super(struct super_block *sb, void *data, int silent) | 81 | static int xenfs_fill_super(struct super_block *sb, void *data, int silent) |
@@ -43,23 +84,36 @@ static int xenfs_fill_super(struct super_block *sb, void *data, int silent) | |||
43 | [1] = {}, | 84 | [1] = {}, |
44 | { "xenbus", &xenbus_file_ops, S_IRUSR|S_IWUSR }, | 85 | { "xenbus", &xenbus_file_ops, S_IRUSR|S_IWUSR }, |
45 | { "capabilities", &capabilities_file_ops, S_IRUGO }, | 86 | { "capabilities", &capabilities_file_ops, S_IRUGO }, |
87 | { "privcmd", &privcmd_file_ops, S_IRUSR|S_IWUSR }, | ||
46 | {""}, | 88 | {""}, |
47 | }; | 89 | }; |
90 | int rc; | ||
91 | |||
92 | rc = simple_fill_super(sb, XENFS_SUPER_MAGIC, xenfs_files); | ||
93 | if (rc < 0) | ||
94 | return rc; | ||
95 | |||
96 | if (xen_initial_domain()) { | ||
97 | xenfs_create_file(sb, sb->s_root, "xsd_kva", | ||
98 | &xsd_kva_file_ops, NULL, S_IRUSR|S_IWUSR); | ||
99 | xenfs_create_file(sb, sb->s_root, "xsd_port", | ||
100 | &xsd_port_file_ops, NULL, S_IRUSR|S_IWUSR); | ||
101 | } | ||
48 | 102 | ||
49 | return simple_fill_super(sb, XENFS_SUPER_MAGIC, xenfs_files); | 103 | return rc; |
50 | } | 104 | } |
51 | 105 | ||
52 | static int xenfs_get_sb(struct file_system_type *fs_type, | 106 | static struct dentry *xenfs_mount(struct file_system_type *fs_type, |
53 | int flags, const char *dev_name, | 107 | int flags, const char *dev_name, |
54 | void *data, struct vfsmount *mnt) | 108 | void *data) |
55 | { | 109 | { |
56 | return get_sb_single(fs_type, flags, data, xenfs_fill_super, mnt); | 110 | return mount_single(fs_type, flags, data, xenfs_fill_super); |
57 | } | 111 | } |
58 | 112 | ||
59 | static struct file_system_type xenfs_type = { | 113 | static struct file_system_type xenfs_type = { |
60 | .owner = THIS_MODULE, | 114 | .owner = THIS_MODULE, |
61 | .name = "xenfs", | 115 | .name = "xenfs", |
62 | .get_sb = xenfs_get_sb, | 116 | .mount = xenfs_mount, |
63 | .kill_sb = kill_litter_super, | 117 | .kill_sb = kill_litter_super, |
64 | }; | 118 | }; |
65 | 119 | ||
diff --git a/drivers/xen/xenfs/xenbus.c b/drivers/xen/xenfs/xenbus.c index 3b39c3752e21..bbd000f88af7 100644 --- a/drivers/xen/xenfs/xenbus.c +++ b/drivers/xen/xenfs/xenbus.c | |||
@@ -122,6 +122,7 @@ static ssize_t xenbus_file_read(struct file *filp, | |||
122 | int ret; | 122 | int ret; |
123 | 123 | ||
124 | mutex_lock(&u->reply_mutex); | 124 | mutex_lock(&u->reply_mutex); |
125 | again: | ||
125 | while (list_empty(&u->read_buffers)) { | 126 | while (list_empty(&u->read_buffers)) { |
126 | mutex_unlock(&u->reply_mutex); | 127 | mutex_unlock(&u->reply_mutex); |
127 | if (filp->f_flags & O_NONBLOCK) | 128 | if (filp->f_flags & O_NONBLOCK) |
@@ -144,7 +145,7 @@ static ssize_t xenbus_file_read(struct file *filp, | |||
144 | i += sz - ret; | 145 | i += sz - ret; |
145 | rb->cons += sz - ret; | 146 | rb->cons += sz - ret; |
146 | 147 | ||
147 | if (ret != sz) { | 148 | if (ret != 0) { |
148 | if (i == 0) | 149 | if (i == 0) |
149 | i = -EFAULT; | 150 | i = -EFAULT; |
150 | goto out; | 151 | goto out; |
@@ -160,6 +161,8 @@ static ssize_t xenbus_file_read(struct file *filp, | |||
160 | struct read_buffer, list); | 161 | struct read_buffer, list); |
161 | } | 162 | } |
162 | } | 163 | } |
164 | if (i == 0) | ||
165 | goto again; | ||
163 | 166 | ||
164 | out: | 167 | out: |
165 | mutex_unlock(&u->reply_mutex); | 168 | mutex_unlock(&u->reply_mutex); |
@@ -407,6 +410,7 @@ static int xenbus_write_watch(unsigned msg_type, struct xenbus_file_priv *u) | |||
407 | 410 | ||
408 | mutex_lock(&u->reply_mutex); | 411 | mutex_lock(&u->reply_mutex); |
409 | rc = queue_reply(&u->read_buffers, &reply, sizeof(reply)); | 412 | rc = queue_reply(&u->read_buffers, &reply, sizeof(reply)); |
413 | wake_up(&u->read_waitq); | ||
410 | mutex_unlock(&u->reply_mutex); | 414 | mutex_unlock(&u->reply_mutex); |
411 | } | 415 | } |
412 | 416 | ||
@@ -455,7 +459,7 @@ static ssize_t xenbus_file_write(struct file *filp, | |||
455 | 459 | ||
456 | ret = copy_from_user(u->u.buffer + u->len, ubuf, len); | 460 | ret = copy_from_user(u->u.buffer + u->len, ubuf, len); |
457 | 461 | ||
458 | if (ret == len) { | 462 | if (ret != 0) { |
459 | rc = -EFAULT; | 463 | rc = -EFAULT; |
460 | goto out; | 464 | goto out; |
461 | } | 465 | } |
@@ -488,21 +492,6 @@ static ssize_t xenbus_file_write(struct file *filp, | |||
488 | msg_type = u->u.msg.type; | 492 | msg_type = u->u.msg.type; |
489 | 493 | ||
490 | switch (msg_type) { | 494 | switch (msg_type) { |
491 | case XS_TRANSACTION_START: | ||
492 | case XS_TRANSACTION_END: | ||
493 | case XS_DIRECTORY: | ||
494 | case XS_READ: | ||
495 | case XS_GET_PERMS: | ||
496 | case XS_RELEASE: | ||
497 | case XS_GET_DOMAIN_PATH: | ||
498 | case XS_WRITE: | ||
499 | case XS_MKDIR: | ||
500 | case XS_RM: | ||
501 | case XS_SET_PERMS: | ||
502 | /* Send out a transaction */ | ||
503 | ret = xenbus_write_transaction(msg_type, u); | ||
504 | break; | ||
505 | |||
506 | case XS_WATCH: | 495 | case XS_WATCH: |
507 | case XS_UNWATCH: | 496 | case XS_UNWATCH: |
508 | /* (Un)Ask for some path to be watched for changes */ | 497 | /* (Un)Ask for some path to be watched for changes */ |
@@ -510,7 +499,8 @@ static ssize_t xenbus_file_write(struct file *filp, | |||
510 | break; | 499 | break; |
511 | 500 | ||
512 | default: | 501 | default: |
513 | ret = -EINVAL; | 502 | /* Send out a transaction */ |
503 | ret = xenbus_write_transaction(msg_type, u); | ||
514 | break; | 504 | break; |
515 | } | 505 | } |
516 | if (ret != 0) | 506 | if (ret != 0) |
@@ -555,6 +545,7 @@ static int xenbus_file_release(struct inode *inode, struct file *filp) | |||
555 | struct xenbus_file_priv *u = filp->private_data; | 545 | struct xenbus_file_priv *u = filp->private_data; |
556 | struct xenbus_transaction_holder *trans, *tmp; | 546 | struct xenbus_transaction_holder *trans, *tmp; |
557 | struct watch_adapter *watch, *tmp_watch; | 547 | struct watch_adapter *watch, *tmp_watch; |
548 | struct read_buffer *rb, *tmp_rb; | ||
558 | 549 | ||
559 | /* | 550 | /* |
560 | * No need for locking here because there are no other users, | 551 | * No need for locking here because there are no other users, |
@@ -573,6 +564,10 @@ static int xenbus_file_release(struct inode *inode, struct file *filp) | |||
573 | free_watch_adapter(watch); | 564 | free_watch_adapter(watch); |
574 | } | 565 | } |
575 | 566 | ||
567 | list_for_each_entry_safe(rb, tmp_rb, &u->read_buffers, list) { | ||
568 | list_del(&rb->list); | ||
569 | kfree(rb); | ||
570 | } | ||
576 | kfree(u); | 571 | kfree(u); |
577 | 572 | ||
578 | return 0; | 573 | return 0; |
@@ -594,4 +589,5 @@ const struct file_operations xenbus_file_ops = { | |||
594 | .open = xenbus_file_open, | 589 | .open = xenbus_file_open, |
595 | .release = xenbus_file_release, | 590 | .release = xenbus_file_release, |
596 | .poll = xenbus_file_poll, | 591 | .poll = xenbus_file_poll, |
592 | .llseek = no_llseek, | ||
597 | }; | 593 | }; |
diff --git a/drivers/xen/xenfs/xenfs.h b/drivers/xen/xenfs/xenfs.h index 51f08b2d0bf1..b68aa6200003 100644 --- a/drivers/xen/xenfs/xenfs.h +++ b/drivers/xen/xenfs/xenfs.h | |||
@@ -2,5 +2,8 @@ | |||
2 | #define _XENFS_XENBUS_H | 2 | #define _XENFS_XENBUS_H |
3 | 3 | ||
4 | extern const struct file_operations xenbus_file_ops; | 4 | extern const struct file_operations xenbus_file_ops; |
5 | extern const struct file_operations privcmd_file_ops; | ||
6 | extern const struct file_operations xsd_kva_file_ops; | ||
7 | extern const struct file_operations xsd_port_file_ops; | ||
5 | 8 | ||
6 | #endif /* _XENFS_XENBUS_H */ | 9 | #endif /* _XENFS_XENBUS_H */ |
diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c new file mode 100644 index 000000000000..fef20dbc6a5c --- /dev/null +++ b/drivers/xen/xenfs/xenstored.c | |||
@@ -0,0 +1,68 @@ | |||
1 | #include <linux/slab.h> | ||
2 | #include <linux/types.h> | ||
3 | #include <linux/mm.h> | ||
4 | #include <linux/fs.h> | ||
5 | |||
6 | #include <xen/page.h> | ||
7 | |||
8 | #include "xenfs.h" | ||
9 | #include "../xenbus/xenbus_comms.h" | ||
10 | |||
11 | static ssize_t xsd_read(struct file *file, char __user *buf, | ||
12 | size_t size, loff_t *off) | ||
13 | { | ||
14 | const char *str = (const char *)file->private_data; | ||
15 | return simple_read_from_buffer(buf, size, off, str, strlen(str)); | ||
16 | } | ||
17 | |||
18 | static int xsd_release(struct inode *inode, struct file *file) | ||
19 | { | ||
20 | kfree(file->private_data); | ||
21 | return 0; | ||
22 | } | ||
23 | |||
24 | static int xsd_kva_open(struct inode *inode, struct file *file) | ||
25 | { | ||
26 | file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p", | ||
27 | xen_store_interface); | ||
28 | if (!file->private_data) | ||
29 | return -ENOMEM; | ||
30 | return 0; | ||
31 | } | ||
32 | |||
33 | static int xsd_kva_mmap(struct file *file, struct vm_area_struct *vma) | ||
34 | { | ||
35 | size_t size = vma->vm_end - vma->vm_start; | ||
36 | |||
37 | if ((size > PAGE_SIZE) || (vma->vm_pgoff != 0)) | ||
38 | return -EINVAL; | ||
39 | |||
40 | if (remap_pfn_range(vma, vma->vm_start, | ||
41 | virt_to_pfn(xen_store_interface), | ||
42 | size, vma->vm_page_prot)) | ||
43 | return -EAGAIN; | ||
44 | |||
45 | return 0; | ||
46 | } | ||
47 | |||
48 | const struct file_operations xsd_kva_file_ops = { | ||
49 | .open = xsd_kva_open, | ||
50 | .mmap = xsd_kva_mmap, | ||
51 | .read = xsd_read, | ||
52 | .release = xsd_release, | ||
53 | }; | ||
54 | |||
55 | static int xsd_port_open(struct inode *inode, struct file *file) | ||
56 | { | ||
57 | file->private_data = (void *)kasprintf(GFP_KERNEL, "%d", | ||
58 | xen_store_evtchn); | ||
59 | if (!file->private_data) | ||
60 | return -ENOMEM; | ||
61 | return 0; | ||
62 | } | ||
63 | |||
64 | const struct file_operations xsd_port_file_ops = { | ||
65 | .open = xsd_port_open, | ||
66 | .read = xsd_read, | ||
67 | .release = xsd_release, | ||
68 | }; | ||