This patch adds an ioctl interface to /proc/xen/xenbus to allow simple
access to xenstore from domU. This patch introduces only
xenbus_read() support, but write, remove, etc could be easily added.
Also, this interface can be easily moved to /dev/xen/xenbus (or
something similar) later.
The following snippet of a C program provides easy access to xenstore
nodes from inside a domU:
#include <xen/io/xenbus.h>
int main(int argc, char **argv)
{
int fd;
int ret;
struct xenbus_ioctl param;
fd = open("/proc/xen/xenbus", O_RDWR);
strcpy(param.path, argv[1]);
ret = ioctl(fd, 0, ¶m);
printf("%s\n", param.value);
}
Comments welcome, of course ;)
# HG changeset patch
# User Dan Smith <danms@xxxxxxxxxx>
# Node ID c01070e1dbed9f19098431fd82120960695f5240
# Parent 96ba0a2bc9de7da1c70a2528481f7448f3a9524d
Add a preliminary ioctl interface to xenbus.
This patch adds an ioctl interface to /proc/xen/xenbus to allow simple
access to xenstore from domU. This patch introduces only xenbus_read()
support, but write, remove, etc could be easily added. Also, this
interface can be easily moved to /dev/xen/xenbus (or something similar)
later.
Signed-off-by: Dan Smith <danms@xxxxxxxxxx>
diff -r 96ba0a2bc9de -r c01070e1dbed
linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_dev.c
--- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_dev.c Wed Mar 15
13:35:43 2006 +0100
+++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_dev.c Fri Mar 17
14:27:23 2006 -0800
@@ -208,11 +208,63 @@ static int xenbus_dev_release(struct ino
return 0;
}
+static int xenbus_dev_ioctl(struct inode *inode, struct file *filp,
+ unsigned int cmd, unsigned long arg)
+{
+ void *output;
+ struct xenbus_ioctl *param;
+ unsigned int len;
+ int ret = 0;
+
+ if (!access_ok(VERIFY_WRITE, (void __user *)arg, sizeof(param)))
+ return -EACCES;
+
+ param = kmalloc(sizeof(*param), GFP_KERNEL);
+ if (param == NULL)
+ return -ENOMEM;
+
+ if (copy_from_user(param, (void *)arg, sizeof(*param))) {
+ ret = -EACCES;
+ goto out;
+ }
+
+ param->path[XENBUS_IOCTL_ARG_LEN - 1] = '\0';
+
+ switch (cmd) {
+ case XEN_XENBUS_IOCTL_READ:
+
+ output = (char *)xenbus_read(XBT_NULL, param->path, "", &len);
+
+ if (IS_ERR(output)) {
+ ret = -EINVAL;
+ goto out;
+ }
+
+ strncpy(param->value, output, XENBUS_IOCTL_ARG_LEN);
+ param->value_len = len;
+ break;
+
+ default:
+ ret = -EINVAL;
+ goto out;
+ }
+
+ if (copy_to_user((void*)arg, param, sizeof(*param))) {
+ ret = -EACCES;
+ goto out;
+ }
+
+ out:
+ kfree(param);
+ return ret;
+}
+
static struct file_operations xenbus_dev_file_ops = {
.read = xenbus_dev_read,
.write = xenbus_dev_write,
.open = xenbus_dev_open,
.release = xenbus_dev_release,
+ .ioctl = xenbus_dev_ioctl,
};
static int __init
diff -r 96ba0a2bc9de -r c01070e1dbed xen/include/public/io/xenbus.h
--- a/xen/include/public/io/xenbus.h Wed Mar 15 13:35:43 2006 +0100
+++ b/xen/include/public/io/xenbus.h Fri Mar 17 14:27:23 2006 -0800
@@ -29,6 +29,18 @@ typedef enum
} XenbusState;
+/*
+ * XenBus ioctl support
+ */
+#define XENBUS_IOCTL_ARG_LEN 256
+struct xenbus_ioctl {
+ char path[XENBUS_IOCTL_ARG_LEN];
+ char value[XENBUS_IOCTL_ARG_LEN];
+ uint32_t value_len;
+};
+
+#define XEN_XENBUS_IOCTL_READ 0
+
#endif /* _XEN_PUBLIC_IO_XENBUS_H */
/*
--
Dan Smith
IBM Linux Technology Center
Open Hypervisor Team
email: danms@xxxxxxxxxx
pgphGTJGQAg8E.pgp
Description: PGP signature
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|