]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/xen/xenfs/super.c
Merge branch 'for-linus' of git://git.infradead.org/users/eparis/notify
[net-next-2.6.git] / drivers / xen / xenfs / super.c
CommitLineData
1107ba88
AZ
1/*
2 * xenfs.c - a filesystem for passing info between the a domain and
3 * the hypervisor.
4 *
5 * 2008-10-07 Alex Zeffertt Replaced /proc/xen/xenbus with xenfs filesystem
6 * and /proc/xen compatibility mount point.
7 * Turned xenfs into a loadable module.
8 */
9
10#include <linux/kernel.h>
11#include <linux/errno.h>
12#include <linux/module.h>
13#include <linux/fs.h>
14#include <linux/magic.h>
24a89b5b
JF
15#include <linux/mm.h>
16#include <linux/backing-dev.h>
1107ba88 17
1ccbf534
JF
18#include <xen/xen.h>
19
1107ba88
AZ
20#include "xenfs.h"
21
22#include <asm/xen/hypervisor.h>
23
24MODULE_DESCRIPTION("Xen filesystem");
25MODULE_LICENSE("GPL");
26
24a89b5b
JF
27static int xenfs_set_page_dirty(struct page *page)
28{
35f8c1c3 29 return !TestSetPageDirty(page);
24a89b5b
JF
30}
31
32static const struct address_space_operations xenfs_aops = {
33 .set_page_dirty = xenfs_set_page_dirty,
34};
35
36static struct backing_dev_info xenfs_backing_dev_info = {
37 .ra_pages = 0, /* No readahead */
38 .capabilities = BDI_CAP_NO_ACCT_AND_WRITEBACK,
39};
40
655d406a
IC
41static struct inode *xenfs_make_inode(struct super_block *sb, int mode)
42{
43 struct inode *ret = new_inode(sb);
44
45 if (ret) {
46 ret->i_mode = mode;
24a89b5b
JF
47 ret->i_mapping->a_ops = &xenfs_aops;
48 ret->i_mapping->backing_dev_info = &xenfs_backing_dev_info;
655d406a
IC
49 ret->i_uid = ret->i_gid = 0;
50 ret->i_blocks = 0;
51 ret->i_atime = ret->i_mtime = ret->i_ctime = CURRENT_TIME;
52 }
53 return ret;
54}
55
56static struct dentry *xenfs_create_file(struct super_block *sb,
57 struct dentry *parent,
58 const char *name,
59 const struct file_operations *fops,
60 void *data,
61 int mode)
62{
63 struct dentry *dentry;
64 struct inode *inode;
65
66 dentry = d_alloc_name(parent, name);
67 if (!dentry)
68 return NULL;
69
70 inode = xenfs_make_inode(sb, S_IFREG | mode);
71 if (!inode) {
72 dput(dentry);
73 return NULL;
74 }
75
76 inode->i_fop = fops;
77 inode->i_private = data;
78
79 d_add(dentry, inode);
80 return dentry;
81}
82
818fd206
JF
83static ssize_t capabilities_read(struct file *file, char __user *buf,
84 size_t size, loff_t *off)
85{
86 char *tmp = "";
87
88 if (xen_initial_domain())
89 tmp = "control_d\n";
90
91 return simple_read_from_buffer(buf, size, off, tmp, strlen(tmp));
92}
93
94static const struct file_operations capabilities_file_ops = {
95 .read = capabilities_read,
6038f373 96 .llseek = default_llseek,
818fd206
JF
97};
98
1107ba88
AZ
99static int xenfs_fill_super(struct super_block *sb, void *data, int silent)
100{
101 static struct tree_descr xenfs_files[] = {
818fd206
JF
102 [1] = {},
103 { "xenbus", &xenbus_file_ops, S_IRUSR|S_IWUSR },
104 { "capabilities", &capabilities_file_ops, S_IRUGO },
9387377e 105 { "privcmd", &privcmd_file_ops, S_IRUSR|S_IWUSR },
1107ba88
AZ
106 {""},
107 };
655d406a 108 int rc;
1107ba88 109
655d406a
IC
110 rc = simple_fill_super(sb, XENFS_SUPER_MAGIC, xenfs_files);
111 if (rc < 0)
112 return rc;
113
114 if (xen_initial_domain()) {
115 xenfs_create_file(sb, sb->s_root, "xsd_kva",
116 &xsd_kva_file_ops, NULL, S_IRUSR|S_IWUSR);
117 xenfs_create_file(sb, sb->s_root, "xsd_port",
118 &xsd_port_file_ops, NULL, S_IRUSR|S_IWUSR);
119 }
1107ba88 120
655d406a 121 return rc;
1107ba88
AZ
122}
123
fc14f2fe 124static int xenfs_mount(struct file_system_type *fs_type,
1107ba88 125 int flags, const char *dev_name,
fc14f2fe 126 void *data)
1107ba88 127{
fc14f2fe 128 return mount_single(fs_type, flags, data, xenfs_fill_super);
1107ba88
AZ
129}
130
131static struct file_system_type xenfs_type = {
132 .owner = THIS_MODULE,
133 .name = "xenfs",
fc14f2fe 134 .mount = xenfs_mount,
1107ba88
AZ
135 .kill_sb = kill_litter_super,
136};
137
138static int __init xenfs_init(void)
139{
24a89b5b
JF
140 int err;
141 if (!xen_domain()) {
142 printk(KERN_INFO "xenfs: not registering filesystem on non-xen platform\n");
143 return 0;
144 }
1107ba88 145
24a89b5b
JF
146 err = register_filesystem(&xenfs_type);
147 if (err) {
148 printk(KERN_ERR "xenfs: Unable to register filesystem!\n");
149 goto out;
150 }
151
152 err = bdi_init(&xenfs_backing_dev_info);
153 if (err)
154 unregister_filesystem(&xenfs_type);
155
156 out:
1107ba88 157
24a89b5b 158 return err;
1107ba88
AZ
159}
160
161static void __exit xenfs_exit(void)
162{
43df95c4 163 if (xen_domain())
1107ba88
AZ
164 unregister_filesystem(&xenfs_type);
165}
166
167module_init(xenfs_init);
168module_exit(xenfs_exit);
169