diff options
author | Ian Campbell <ian.campbell@citrix.com> | 2009-02-06 21:46:48 -0500 |
---|---|---|
committer | Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com> | 2010-10-20 19:22:26 -0400 |
commit | 655d406a7c80bffc03263d071b6ba1e0fcf548f9 (patch) | |
tree | d3cbe97860bff0d347111ff293b6f5b3124bf67e /drivers/xen/xenfs | |
parent | cd07202cc8262e1669edff0d97715f3dd9260917 (diff) |
xen: add /proc/xen/xsd_{kva,port} to xenfs
These are used by the userspace xenstore daemon, which runs in dom0.
Xenstored is what's behind the xenfs "xenbus" filesystem.
[ Impact: provide mapping and port to usermode for xenstore ]
Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
Diffstat (limited to 'drivers/xen/xenfs')
-rw-r--r-- | drivers/xen/xenfs/Makefile | 3 | ||||
-rw-r--r-- | drivers/xen/xenfs/super.c | 54 | ||||
-rw-r--r-- | drivers/xen/xenfs/xenfs.h | 2 | ||||
-rw-r--r-- | drivers/xen/xenfs/xenstored.c | 68 |
4 files changed, 125 insertions, 2 deletions
diff --git a/drivers/xen/xenfs/Makefile b/drivers/xen/xenfs/Makefile index 25275c3bbdff..5d45ff13cc01 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 |
4 | xenfs-$(CONFIG_XEN_DOM0) += xenstored.o | ||
diff --git a/drivers/xen/xenfs/super.c b/drivers/xen/xenfs/super.c index 78bfab0700ba..3cf7707217f2 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 | { |
@@ -45,8 +85,20 @@ static int xenfs_fill_super(struct super_block *sb, void *data, int silent) | |||
45 | { "capabilities", &capabilities_file_ops, S_IRUGO }, | 85 | { "capabilities", &capabilities_file_ops, S_IRUGO }, |
46 | {""}, | 86 | {""}, |
47 | }; | 87 | }; |
88 | int rc; | ||
89 | |||
90 | rc = simple_fill_super(sb, XENFS_SUPER_MAGIC, xenfs_files); | ||
91 | if (rc < 0) | ||
92 | return rc; | ||
93 | |||
94 | if (xen_initial_domain()) { | ||
95 | xenfs_create_file(sb, sb->s_root, "xsd_kva", | ||
96 | &xsd_kva_file_ops, NULL, S_IRUSR|S_IWUSR); | ||
97 | xenfs_create_file(sb, sb->s_root, "xsd_port", | ||
98 | &xsd_port_file_ops, NULL, S_IRUSR|S_IWUSR); | ||
99 | } | ||
48 | 100 | ||
49 | return simple_fill_super(sb, XENFS_SUPER_MAGIC, xenfs_files); | 101 | return rc; |
50 | } | 102 | } |
51 | 103 | ||
52 | static int xenfs_get_sb(struct file_system_type *fs_type, | 104 | static int xenfs_get_sb(struct file_system_type *fs_type, |
diff --git a/drivers/xen/xenfs/xenfs.h b/drivers/xen/xenfs/xenfs.h index 51f08b2d0bf1..5056306e7aa8 100644 --- a/drivers/xen/xenfs/xenfs.h +++ b/drivers/xen/xenfs/xenfs.h | |||
@@ -2,5 +2,7 @@ | |||
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 xsd_kva_file_ops; | ||
6 | extern const struct file_operations xsd_port_file_ops; | ||
5 | 7 | ||
6 | #endif /* _XENFS_XENBUS_H */ | 8 | #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 | }; | ||