All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Add an ioctl interface for simple xenstore access
@ 2006-03-17 22:33 Dan Smith
  2006-03-18  7:14 ` Muli Ben-Yehuda
  0 siblings, 1 reply; 11+ messages in thread
From: Dan Smith @ 2006-03-17 22:33 UTC (permalink / raw)
  To: Xen Developers


[-- Attachment #1.1.1: Type: text/plain, Size: 768 bytes --]

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, &param);
  
          printf("%s\n", param.value);
  }

Comments welcome, of course ;)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.1.2: xenbus_ioctl.patch --]
[-- Type: text/x-patch, Size: 2735 bytes --]

# HG changeset patch
# User Dan Smith <danms@us.ibm.com>
# 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@us.ibm.com>

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 */
 
 /*

[-- Attachment #1.1.3: Type: text/plain, Size: 92 bytes --]

-- 
Dan Smith
IBM Linux Technology Center
Open Hypervisor Team
email: danms@us.ibm.com

[-- Attachment #1.2: Type: application/pgp-signature, Size: 190 bytes --]

[-- Attachment #2: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2006-03-20 10:10 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-03-17 22:33 [PATCH] Add an ioctl interface for simple xenstore access Dan Smith
2006-03-18  7:14 ` Muli Ben-Yehuda
2006-03-18  9:50   ` Keir Fraser
2006-03-18 18:02     ` Anthony Liguori
2006-03-18 19:32       ` Keir Fraser
2006-03-20  8:38       ` Gerd Hoffmann
2006-03-20  8:52         ` Ewan Mellor
2006-03-20 10:08           ` Keir Fraser
2006-03-20 10:10           ` Gerd Hoffmann
2006-03-18 17:56   ` Anthony Liguori
2006-03-19  0:10     ` Muli Ben-Yehuda

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.