2 * xenfs.c - a filesystem for passing info between the a domain and
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.
10 #include <linux/kernel.h>
11 #include <linux/errno.h>
12 #include <linux/module.h>
14 #include <linux/magic.h>
16 #include <linux/backing-dev.h>
22 #include <asm/xen/hypervisor.h>
24 MODULE_DESCRIPTION("Xen filesystem");
25 MODULE_LICENSE("GPL");
27 static int xenfs_set_page_dirty(struct page
*page
)
29 return !TestSetPageDirty(page
);
32 static const struct address_space_operations xenfs_aops
= {
33 .set_page_dirty
= xenfs_set_page_dirty
,
36 static struct backing_dev_info xenfs_backing_dev_info
= {
37 .ra_pages
= 0, /* No readahead */
38 .capabilities
= BDI_CAP_NO_ACCT_AND_WRITEBACK
,
41 static struct inode
*xenfs_make_inode(struct super_block
*sb
, int mode
)
43 struct inode
*ret
= new_inode(sb
);
47 ret
->i_mapping
->a_ops
= &xenfs_aops
;
48 ret
->i_mapping
->backing_dev_info
= &xenfs_backing_dev_info
;
49 ret
->i_uid
= ret
->i_gid
= 0;
51 ret
->i_atime
= ret
->i_mtime
= ret
->i_ctime
= CURRENT_TIME
;
56 static struct dentry
*xenfs_create_file(struct super_block
*sb
,
57 struct dentry
*parent
,
59 const struct file_operations
*fops
,
63 struct dentry
*dentry
;
66 dentry
= d_alloc_name(parent
, name
);
70 inode
= xenfs_make_inode(sb
, S_IFREG
| mode
);
77 inode
->i_private
= data
;
83 static ssize_t
capabilities_read(struct file
*file
, char __user
*buf
,
84 size_t size
, loff_t
*off
)
88 if (xen_initial_domain())
91 return simple_read_from_buffer(buf
, size
, off
, tmp
, strlen(tmp
));
94 static const struct file_operations capabilities_file_ops
= {
95 .read
= capabilities_read
,
96 .llseek
= default_llseek
,
99 static int xenfs_fill_super(struct super_block
*sb
, void *data
, int silent
)
101 static struct tree_descr xenfs_files
[] = {
103 { "xenbus", &xenbus_file_ops
, S_IRUSR
|S_IWUSR
},
104 { "capabilities", &capabilities_file_ops
, S_IRUGO
},
105 { "privcmd", &privcmd_file_ops
, S_IRUSR
|S_IWUSR
},
110 rc
= simple_fill_super(sb
, XENFS_SUPER_MAGIC
, xenfs_files
);
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
);
124 static int xenfs_get_sb(struct file_system_type
*fs_type
,
125 int flags
, const char *dev_name
,
126 void *data
, struct vfsmount
*mnt
)
128 return get_sb_single(fs_type
, flags
, data
, xenfs_fill_super
, mnt
);
131 static struct file_system_type xenfs_type
= {
132 .owner
= THIS_MODULE
,
134 .get_sb
= xenfs_get_sb
,
135 .kill_sb
= kill_litter_super
,
138 static int __init
xenfs_init(void)
142 printk(KERN_INFO
"xenfs: not registering filesystem on non-xen platform\n");
146 err
= register_filesystem(&xenfs_type
);
148 printk(KERN_ERR
"xenfs: Unable to register filesystem!\n");
152 err
= bdi_init(&xenfs_backing_dev_info
);
154 unregister_filesystem(&xenfs_type
);
161 static void __exit
xenfs_exit(void)
164 unregister_filesystem(&xenfs_type
);
167 module_init(xenfs_init
);
168 module_exit(xenfs_exit
);