Skip to content

Commit

Permalink
xen: add xenfs to allow usermode <-> Xen interaction
Browse files Browse the repository at this point in the history
The xenfs filesystem exports various interfaces to usermode.  Initially
this exports a file to allow usermode to interact with xenbus/xenstore.

Traditionally this appeared in /proc/xen.  Rather than extending procfs,
this patch adds a backward-compat mountpoint on /proc/xen, and provides
a xenfs filesystem which can be mounted there.

Signed-off-by: Alex Zeffertt <[email protected]>
Signed-off-by: Jeremy Fitzhardinge <[email protected]>
Cc: Ingo Molnar <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
alexz authored and torvalds committed Jan 8, 2009
1 parent d822034 commit 1107ba8
Show file tree
Hide file tree
Showing 10 changed files with 716 additions and 8 deletions.
24 changes: 24 additions & 0 deletions drivers/xen/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,27 @@ config XEN_SCRUB_PAGES
is not accidentally visible to other domains. Is it more
secure, but slightly less efficient.
If in doubt, say yes.

config XENFS
tristate "Xen filesystem"
depends on XEN
default y
help
The xen filesystem provides a way for domains to share
information with each other and with the hypervisor.
For example, by reading and writing the "xenbus" file, guests
may pass arbitrary information to the initial domain.
If in doubt, say yes.

config XEN_COMPAT_XENFS
bool "Create compatibility mount point /proc/xen"
depends on XENFS
default y
help
The old xenstore userspace tools expect to find "xenbus"
under /proc/xen, but "xenbus" is now found at the root of the
xenfs filesystem. Selecting this causes the kernel to create
the compatibilty mount point /proc/xen if it is running on
a xen platform.
If in doubt, say yes.

2 changes: 2 additions & 0 deletions drivers/xen/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
obj-y += grant-table.o features.o events.o manage.o
obj-y += xenbus/

obj-$(CONFIG_HOTPLUG_CPU) += cpu_hotplug.o
obj-$(CONFIG_XEN_XENCOMM) += xencomm.o
obj-$(CONFIG_XEN_BALLOON) += balloon.o
obj-$(CONFIG_XENFS) += xenfs/
28 changes: 22 additions & 6 deletions drivers/xen/xenbus/xenbus_probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <linux/ctype.h>
#include <linux/fcntl.h>
#include <linux/mm.h>
#include <linux/proc_fs.h>
#include <linux/notifier.h>
#include <linux/kthread.h>
#include <linux/mutex.h>
Expand All @@ -55,7 +56,10 @@
#include "xenbus_comms.h"
#include "xenbus_probe.h"


int xen_store_evtchn;
EXPORT_SYMBOL(xen_store_evtchn);

struct xenstore_domain_interface *xen_store_interface;
static unsigned long xen_store_mfn;

Expand Down Expand Up @@ -166,6 +170,9 @@ static int read_backend_details(struct xenbus_device *xendev)
return read_otherend_details(xendev, "backend-id", "backend");
}

static struct device_attribute xenbus_dev_attrs[] = {
__ATTR_NULL
};

/* Bus type for frontend drivers. */
static struct xen_bus_type xenbus_frontend = {
Expand All @@ -174,12 +181,13 @@ static struct xen_bus_type xenbus_frontend = {
.get_bus_id = frontend_bus_id,
.probe = xenbus_probe_frontend,
.bus = {
.name = "xen",
.match = xenbus_match,
.uevent = xenbus_uevent,
.probe = xenbus_dev_probe,
.remove = xenbus_dev_remove,
.shutdown = xenbus_dev_shutdown,
.name = "xen",
.match = xenbus_match,
.uevent = xenbus_uevent,
.probe = xenbus_dev_probe,
.remove = xenbus_dev_remove,
.shutdown = xenbus_dev_shutdown,
.dev_attrs = xenbus_dev_attrs,
},
};

Expand Down Expand Up @@ -852,6 +860,14 @@ static int __init xenbus_probe_init(void)
if (!xen_initial_domain())
xenbus_probe(NULL);

#ifdef CONFIG_XEN_COMPAT_XENFS
/*
* Create xenfs mountpoint in /proc for compatibility with
* utilities that expect to find "xenbus" under "/proc/xen".
*/
proc_mkdir("xen", NULL);
#endif

return 0;

out_unreg_back:
Expand Down
1 change: 1 addition & 0 deletions drivers/xen/xenbus/xenbus_xs.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ void *xenbus_dev_request_and_reply(struct xsd_sockmsg *msg)

return ret;
}
EXPORT_SYMBOL(xenbus_dev_request_and_reply);

/* Send message to xs, get kmalloc'ed reply. ERR_PTR() on error. */
static void *xs_talkv(struct xenbus_transaction t,
Expand Down
3 changes: 3 additions & 0 deletions drivers/xen/xenfs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
obj-$(CONFIG_XENFS) += xenfs.o

xenfs-objs = super.o xenbus.o
64 changes: 64 additions & 0 deletions drivers/xen/xenfs/super.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* xenfs.c - a filesystem for passing info between the a domain and
* the hypervisor.
*
* 2008-10-07 Alex Zeffertt Replaced /proc/xen/xenbus with xenfs filesystem
* and /proc/xen compatibility mount point.
* Turned xenfs into a loadable module.
*/

#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/magic.h>

#include "xenfs.h"

#include <asm/xen/hypervisor.h>

MODULE_DESCRIPTION("Xen filesystem");
MODULE_LICENSE("GPL");

static int xenfs_fill_super(struct super_block *sb, void *data, int silent)
{
static struct tree_descr xenfs_files[] = {
[2] = {"xenbus", &xenbus_file_ops, S_IRUSR|S_IWUSR},
{""},
};

return simple_fill_super(sb, XENFS_SUPER_MAGIC, xenfs_files);
}

static int xenfs_get_sb(struct file_system_type *fs_type,
int flags, const char *dev_name,
void *data, struct vfsmount *mnt)
{
return get_sb_single(fs_type, flags, data, xenfs_fill_super, mnt);
}

static struct file_system_type xenfs_type = {
.owner = THIS_MODULE,
.name = "xenfs",
.get_sb = xenfs_get_sb,
.kill_sb = kill_litter_super,
};

static int __init xenfs_init(void)
{
if (xen_pv_domain())
return register_filesystem(&xenfs_type);

printk(KERN_INFO "XENFS: not registering filesystem on non-xen platform\n");
return 0;
}

static void __exit xenfs_exit(void)
{
if (xen_pv_domain())
unregister_filesystem(&xenfs_type);
}

module_init(xenfs_init);
module_exit(xenfs_exit);

Loading

0 comments on commit 1107ba8

Please sign in to comment.