From: Dan Smith Subject: [PATCH] Add an ioctl interface for simple xenstore access Date: Fri, 17 Mar 2006 14:33:36 -0800 Message-ID: <87r750pupr.fsf@caffeine.beaverton.ibm.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0817315505==" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Mime-version: 1.0 Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Xen Developers List-Id: xen-devel@lists.xenproject.org --===============0817315505== Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Transfer-Encoding: quoted-printable 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 =20=20 int main(int argc, char **argv) { int fd; int ret; struct xenbus_ioctl param; =20=20 fd =3D open("/proc/xen/xenbus", O_RDWR); =20=20 strcpy(param.path, argv[1]); ret =3D ioctl(fd, 0, ¶m); =20=20 printf("%s\n", param.value); } Comments welcome, of course ;) --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=xenbus_ioctl.patch Content-Transfer-Encoding: quoted-printable # HG changeset patch # User Dan Smith # 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 diff -r 96ba0a2bc9de -r c01070e1dbed linux-2.6-xen-sparse/drivers/xen/xenbu= s/xenbus_dev.c =2D-- 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; } =20 +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 =3D 0; + + if (!access_ok(VERIFY_WRITE, (void __user *)arg, sizeof(param)))=20 + return -EACCES; +=09 + param =3D kmalloc(sizeof(*param), GFP_KERNEL); + if (param =3D=3D NULL) + return -ENOMEM; + + if (copy_from_user(param, (void *)arg, sizeof(*param))) { + ret =3D -EACCES; + goto out; + } +=09 + param->path[XENBUS_IOCTL_ARG_LEN - 1] =3D '\0'; + + switch (cmd) { + case XEN_XENBUS_IOCTL_READ: +=09=09 + output =3D (char *)xenbus_read(XBT_NULL, param->path, "", &len); +=09=09 + if (IS_ERR(output)) { + ret =3D -EINVAL; + goto out; + } +=09=09 + strncpy(param->value, output, XENBUS_IOCTL_ARG_LEN); + param->value_len =3D len; + break; + + default: + ret =3D -EINVAL; + goto out; + } + + if (copy_to_user((void*)arg, param, sizeof(*param))) { + ret =3D -EACCES; + goto out; + } + + out: + kfree(param); + return ret; +} + static struct file_operations xenbus_dev_file_ops =3D { .read =3D xenbus_dev_read, .write =3D xenbus_dev_write, .open =3D xenbus_dev_open, .release =3D xenbus_dev_release, + .ioctl =3D xenbus_dev_ioctl, }; =20 static int __init diff -r 96ba0a2bc9de -r c01070e1dbed xen/include/public/io/xenbus.h =2D-- 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 =20 } XenbusState; =20 +/* + * 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 */ =20 /* --=-=-= Content-Transfer-Encoding: quoted-printable =2D-=20 Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms@us.ibm.com --=-=-=-- --==-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.1 (GNU/Linux) iD8DBQBEGzlCwtEf7b4GJVQRAqlgAJ4uUUtL4sASaWrXfg68+akYCymEoQCeJPGs iqHiqOkeLtOjALzXbOm8+s8= =p110 -----END PGP SIGNATURE----- --==-=-=-- --===============0817315505== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --===============0817315505==--