diff options
author | Bastian Blank <waldi@debian.org> | 2011-12-10 13:29:48 -0500 |
---|---|---|
committer | Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> | 2011-12-16 13:29:41 -0500 |
commit | e9f0fec3f5d406c500861da779d16a779a110055 (patch) | |
tree | 54746773f093c060f1112ad1d8067d37010b92a3 /drivers/xen | |
parent | 2fb3683e7b164ee2b324039f7c9d90fe5b1a259b (diff) |
xen: Add xenbus_backend device
Access for xenstored to the event channel and pre-allocated ring is
managed via xenfs. This adds its own character device featuring mmap
for the ring and an ioctl for the event channel.
Signed-off-by: Bastian Blank <waldi@debian.org>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Diffstat (limited to 'drivers/xen')
-rw-r--r-- | drivers/xen/xenbus/Makefile | 1 | ||||
-rw-r--r-- | drivers/xen/xenbus/xenbus_dev_backend.c | 89 |
2 files changed, 90 insertions, 0 deletions
diff --git a/drivers/xen/xenbus/Makefile b/drivers/xen/xenbus/Makefile index a2ea363b9f34..31e2e9050c7a 100644 --- a/drivers/xen/xenbus/Makefile +++ b/drivers/xen/xenbus/Makefile | |||
@@ -10,4 +10,5 @@ xenbus-objs += xenbus_probe.o | |||
10 | xenbus-be-objs-$(CONFIG_XEN_BACKEND) += xenbus_probe_backend.o | 10 | xenbus-be-objs-$(CONFIG_XEN_BACKEND) += xenbus_probe_backend.o |
11 | xenbus-objs += $(xenbus-be-objs-y) | 11 | xenbus-objs += $(xenbus-be-objs-y) |
12 | 12 | ||
13 | obj-$(CONFIG_XEN_BACKEND) += xenbus_dev_backend.o | ||
13 | obj-$(CONFIG_XEN_XENBUS_FRONTEND) += xenbus_probe_frontend.o | 14 | obj-$(CONFIG_XEN_XENBUS_FRONTEND) += xenbus_probe_frontend.o |
diff --git a/drivers/xen/xenbus/xenbus_dev_backend.c b/drivers/xen/xenbus/xenbus_dev_backend.c new file mode 100644 index 000000000000..a2092bd97693 --- /dev/null +++ b/drivers/xen/xenbus/xenbus_dev_backend.c | |||
@@ -0,0 +1,89 @@ | |||
1 | #include <linux/slab.h> | ||
2 | #include <linux/types.h> | ||
3 | #include <linux/mm.h> | ||
4 | #include <linux/fs.h> | ||
5 | #include <linux/miscdevice.h> | ||
6 | #include <linux/module.h> | ||
7 | #include <linux/capability.h> | ||
8 | |||
9 | #include <xen/page.h> | ||
10 | #include <xen/xenbus_dev.h> | ||
11 | |||
12 | #include "xenbus_comms.h" | ||
13 | |||
14 | MODULE_LICENSE("GPL"); | ||
15 | |||
16 | static int xenbus_backend_open(struct inode *inode, struct file *filp) | ||
17 | { | ||
18 | if (!capable(CAP_SYS_ADMIN)) | ||
19 | return -EPERM; | ||
20 | |||
21 | return nonseekable_open(inode, filp); | ||
22 | } | ||
23 | |||
24 | static long xenbus_backend_ioctl(struct file *file, unsigned int cmd, unsigned long data) | ||
25 | { | ||
26 | if (!capable(CAP_SYS_ADMIN)) | ||
27 | return -EPERM; | ||
28 | |||
29 | switch (cmd) { | ||
30 | case IOCTL_XENBUS_BACKEND_EVTCHN: | ||
31 | if (xen_store_evtchn > 0) | ||
32 | return xen_store_evtchn; | ||
33 | return -ENODEV; | ||
34 | |||
35 | default: | ||
36 | return -ENOTTY; | ||
37 | } | ||
38 | } | ||
39 | |||
40 | static int xenbus_backend_mmap(struct file *file, struct vm_area_struct *vma) | ||
41 | { | ||
42 | size_t size = vma->vm_end - vma->vm_start; | ||
43 | |||
44 | if (!capable(CAP_SYS_ADMIN)) | ||
45 | return -EPERM; | ||
46 | |||
47 | if ((size > PAGE_SIZE) || (vma->vm_pgoff != 0)) | ||
48 | return -EINVAL; | ||
49 | |||
50 | if (remap_pfn_range(vma, vma->vm_start, | ||
51 | virt_to_pfn(xen_store_interface), | ||
52 | size, vma->vm_page_prot)) | ||
53 | return -EAGAIN; | ||
54 | |||
55 | return 0; | ||
56 | } | ||
57 | |||
58 | const struct file_operations xenbus_backend_fops = { | ||
59 | .open = xenbus_backend_open, | ||
60 | .mmap = xenbus_backend_mmap, | ||
61 | .unlocked_ioctl = xenbus_backend_ioctl, | ||
62 | }; | ||
63 | |||
64 | static struct miscdevice xenbus_backend_dev = { | ||
65 | .minor = MISC_DYNAMIC_MINOR, | ||
66 | .name = "xen/xenbus_backend", | ||
67 | .fops = &xenbus_backend_fops, | ||
68 | }; | ||
69 | |||
70 | static int __init xenbus_backend_init(void) | ||
71 | { | ||
72 | int err; | ||
73 | |||
74 | if (!xen_initial_domain()) | ||
75 | return -ENODEV; | ||
76 | |||
77 | err = misc_register(&xenbus_backend_dev); | ||
78 | if (err) | ||
79 | printk(KERN_ERR "Could not register xenbus backend device\n"); | ||
80 | return err; | ||
81 | } | ||
82 | |||
83 | static void __exit xenbus_backend_exit(void) | ||
84 | { | ||
85 | misc_deregister(&xenbus_backend_dev); | ||
86 | } | ||
87 | |||
88 | module_init(xenbus_backend_init); | ||
89 | module_exit(xenbus_backend_exit); | ||