qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org, xen-devel@lists.xensource.com
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 7/7] xen: blk & nic configuration via cmd line.
Date: Mon,  4 Aug 2008 17:50:45 +0200	[thread overview]
Message-ID: <1217865045-10722-8-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1217865045-10722-1-git-send-email-kraxel@redhat.com>

This patch makes qemu create backend and frontend device entries in
xenstore for devices configured on the command line.  It will use
qdisk and qnic backend names, so the qemu internal backends will
be used.

Disks can be created using -drive if=xen,file=...
Nics can be created using -net nic,macaddr=...

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 Makefile.target  |    2 +-
 hw/xen-backend.h |    7 +++
 hw/xen-config.c  |  139 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/xen-machine.c |   19 +++++++-
 4 files changed, 165 insertions(+), 2 deletions(-)
 create mode 100644 hw/xen-config.c

diff --git a/Makefile.target b/Makefile.target
index 85f938c..a3f8d24 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -516,7 +516,7 @@ LIBS += $(CONFIG_VNC_TLS_LIBS)
 endif
 
 # xen backend driver support
-XEN_OBJS := xen-machine.o xen-backend.o
+XEN_OBJS := xen-machine.o xen-backend.o xen-config.o
 XEN_OBJS += xen-console.o xen-framebuffer.o xen-disk.o xen-nic.o
 ifeq ($(CONFIG_XEN), yes)
   OBJS += $(XEN_OBJS)
diff --git a/hw/xen-backend.h b/hw/xen-backend.h
index b484752..c1da2ca 100644
--- a/hw/xen-backend.h
+++ b/hw/xen-backend.h
@@ -3,6 +3,8 @@
 
 #include "xen-common.h"
 #include "sysemu.h"
+#include "net.h"
+#include "block_int.h"
 
 /* ------------------------------------------------------------- */
 
@@ -94,4 +96,9 @@ struct XenDevOps xen_netdev_ops;       /* xen_nic.c         */
 
 void xen_set_display(int domid, DisplayState *ds);
 
+/* configuration (aka xenbus setup) */
+void xen_config_cleanup(void);
+int xen_config_dev_blk(DriveInfo *disk);
+int xen_config_dev_nic(NICInfo *nic);
+
 #endif /* QEMU_XEN_BACKEND_H */
diff --git a/hw/xen-config.c b/hw/xen-config.c
new file mode 100644
index 0000000..4156f82
--- /dev/null
+++ b/hw/xen-config.c
@@ -0,0 +1,139 @@
+#include "xen-backend.h"
+
+/* ------------------------------------------------------------- */
+
+struct xs_dirs {
+    char *xs_dir;
+    TAILQ_ENTRY(xs_dirs) list;
+};
+static TAILQ_HEAD(xs_dirs_head, xs_dirs) xs_cleanup = TAILQ_HEAD_INITIALIZER(xs_cleanup);
+
+static void xen_config_cleanup_dir(char *dir)
+{
+    struct xs_dirs *d;
+
+    d = qemu_malloc(sizeof(*d));
+    if (!d)
+        return;
+    d->xs_dir = dir;
+    TAILQ_INSERT_TAIL(&xs_cleanup, d, list);
+}
+
+void xen_config_cleanup(void)
+{
+    struct xs_dirs *d;
+
+    fprintf(stderr, "xen be: %s\n", __FUNCTION__);
+    TAILQ_FOREACH(d, &xs_cleanup, list) {
+	xs_rm(xenstore, 0, d->xs_dir);
+    }
+}
+
+/* ------------------------------------------------------------- */
+
+static int xen_config_dev_mkdir(char *dev, int p)
+{
+    struct xs_permissions perms = {
+	.id    = xen_domid,
+	.perms = p,
+    };
+
+    if (!xs_mkdir(xenstore, 0, dev)) {
+	fprintf(stderr, "xs_mkdir %s: failed\n", dev);
+	return -1;
+    }
+    xen_config_cleanup_dir(qemu_strdup(dev));
+
+    if (!xs_set_permissions(xenstore, 0, dev, &perms, 1)) {
+	fprintf(stderr, "%s: xs_set_permissions failed\n", __FUNCTION__);
+	return -1;
+    }
+    return 0;
+}
+
+static int xen_config_dev_dirs(char *ftype, char *btype, int vdev,
+			       char *fe, char *be, int len)
+{
+    snprintf(fe, len, "/local/domain/%d/device/%s/%d",
+	     xen_domid, ftype, vdev);
+    snprintf(be, len, "/local/domain/0/backend/%s/%d/%d",
+	     btype, xen_domid, vdev);
+
+    xen_config_dev_mkdir(fe, XS_PERM_WRITE);
+    xen_config_dev_mkdir(be, XS_PERM_READ);
+    return 0;
+}
+
+static int xen_config_dev_all(char *fe, char *be)
+{
+    /* frontend */
+#if 0
+    xenstore_write_str(fe, "protocol",
+			    xen_config_dev_protocol(xen));
+#endif
+    xenstore_write_int(fe, "state",           XenbusStateInitialising);
+    xenstore_write_int(fe, "backend-id",      0);
+    xenstore_write_str(fe, "backend",         be);
+
+    /* backend */
+    xenstore_write_str(be, "domain",          qemu_name ? qemu_name : "no-name");
+    xenstore_write_int(be, "online",          1);
+    xenstore_write_int(be, "state",           XenbusStateInitialising);
+    xenstore_write_int(be, "frontend-id",     xen_domid);
+    xenstore_write_str(be, "frontend",        fe);
+
+    return 0;
+}
+
+/* ------------------------------------------------------------- */
+
+int xen_config_dev_blk(DriveInfo *disk)
+{
+    char fe[256], be[256];
+    int vdev = 202 * 256 + 16 * disk->unit;
+    int cdrom = disk->bdrv->type == BDRV_TYPE_CDROM;
+    char *devtype = cdrom ? "cdrom" : "disk";
+    char *mode    = cdrom ? "r"     : "w";
+
+    snprintf(disk->bdrv->device_name, sizeof(disk->bdrv->device_name),
+	     "xvd%c", 'a' + disk->unit);
+    fprintf(stderr, "xen be: config disk %d [%s]: %s\n",
+	    disk->unit, disk->bdrv->device_name, disk->bdrv->filename);
+    xen_config_dev_dirs("vbd", "qdisk", vdev, fe, be, sizeof(fe));
+
+    /* frontend */
+    xenstore_write_int(fe, "virtual-device",  vdev);
+    xenstore_write_str(fe, "device-type",     devtype);
+
+    /* backend */
+    xenstore_write_str(be, "dev",             disk->bdrv->device_name);
+    xenstore_write_str(be, "type",            "file");
+    xenstore_write_str(be, "params",          disk->bdrv->filename);
+    xenstore_write_str(be, "mode",            mode);
+
+    /* common stuff */
+    return xen_config_dev_all(fe, be);
+}
+
+int xen_config_dev_nic(NICInfo *nic)
+{
+    char fe[256], be[256];
+    char mac[20];
+
+    snprintf(mac, sizeof(mac), "%02x:%02x:%02x:%02x:%02x:%02x",
+	     nic->macaddr[0], nic->macaddr[1], nic->macaddr[2],
+	     nic->macaddr[3], nic->macaddr[4], nic->macaddr[5]);
+    fprintf(stderr, "xen be: config nic %d: mac=\"%s\"\n", nic->vlan->id, mac);
+    xen_config_dev_dirs("vif", "qnic", nic->vlan->id, fe, be, sizeof(fe));
+
+    /* frontend */
+    xenstore_write_int(fe, "handle",     nic->vlan->id);
+    xenstore_write_str(fe, "mac",        mac);
+
+    /* backend */
+    xenstore_write_int(be, "handle",     nic->vlan->id);
+    xenstore_write_str(be, "mac",        mac);
+
+    /* common stuff */
+    return xen_config_dev_all(fe, be);
+}
diff --git a/hw/xen-machine.c b/hw/xen-machine.c
index c8fb256..4e4d893 100644
--- a/hw/xen-machine.c
+++ b/hw/xen-machine.c
@@ -121,7 +121,7 @@ static void xenpv_init(ram_addr_t ram_size, int vga_ram_size,
 		       const char *cpu_model)
 {
     CPUState *env;
-    int rc;
+    int index,i,rc;
 
     rc = xen_init_pv(ds);
     if (-1 == rc)
@@ -147,6 +147,23 @@ static void xenpv_init(ram_addr_t ram_size, int vga_ram_size,
     env = cpu_init(cpu_model);
     env->halted = 1;
 
+    /* configure disks */
+    for (i = 0; i < 16; i++) {
+        index = drive_get_index(IF_XEN, 0, i);
+	if (index == -1)
+	    continue;
+	xen_config_dev_blk(drives_table + index);
+    }
+
+    /* configure nics */
+    for (i = 0; i < nb_nics; i++) {
+	if (nd_table[i].model && 0 != strcmp(nd_table[i].model, "xen"))
+	    continue;
+        xen_config_dev_nic(nd_table + i);
+    }
+
+    /* config cleanup hook */
+    atexit(xen_config_cleanup);
     return;
 
 err:
-- 
1.5.5.1

  parent reply	other threads:[~2008-08-04 15:52 UTC|newest]

Thread overview: 93+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-04 15:50 [Qemu-devel] [PATCH 0/7] merge some xen bits into qemu Gerd Hoffmann
2008-08-04 15:50 ` [Qemu-devel] [PATCH 1/7] xen: groundwork for xen support Gerd Hoffmann
2008-08-04 16:34   ` Blue Swirl
2008-08-04 18:01     ` Gerd Hoffmann
2008-08-04 17:35   ` Anthony Liguori
2008-08-04 18:04     ` Gerd Hoffmann
2008-08-04 15:50 ` [Qemu-devel] [PATCH 2/7] xen: backend driver core Gerd Hoffmann
2008-08-04 15:50 ` [Qemu-devel] [PATCH 3/7] xen: add console backend driver Gerd Hoffmann
2008-08-04 16:52   ` Blue Swirl
2008-08-04 18:15     ` Gerd Hoffmann
2008-08-04 20:47       ` Blue Swirl
2008-08-04 15:50 ` [Qemu-devel] [PATCH 4/7] xen: add framebuffer " Gerd Hoffmann
2008-08-04 17:09   ` Blue Swirl
2008-08-04 18:20     ` Gerd Hoffmann
2008-08-04 15:50 ` [Qemu-devel] [PATCH 5/7] xen: add block device " Gerd Hoffmann
2008-08-04 17:26   ` Blue Swirl
2008-08-04 17:37     ` Samuel Thibault
2008-08-04 17:46     ` Anthony Liguori
2008-08-04 19:50     ` Gerd Hoffmann
2008-08-04 20:04       ` Paul Brook
2008-08-05  7:18         ` Gerd Hoffmann
2008-08-04 20:58       ` Blue Swirl
2008-08-05  7:01         ` Gerd Hoffmann
2008-08-04 21:34       ` [Xen-devel] " Samuel Thibault
2008-08-05  6:52         ` Gerd Hoffmann
2008-08-05 10:47           ` Samuel Thibault
2008-08-05 11:07             ` Gerd Hoffmann
2008-08-05 11:36               ` Samuel Thibault
2008-08-04 15:50 ` [Qemu-devel] [PATCH 6/7] xen: add net " Gerd Hoffmann
2008-08-04 15:50 ` Gerd Hoffmann [this message]
2008-08-04 17:35   ` [Qemu-devel] [PATCH 7/7] xen: blk & nic configuration via cmd line Blue Swirl
2008-08-04 18:12     ` Gerd Hoffmann
2008-08-04 20:45       ` Blue Swirl
2008-08-04 17:42 ` [Qemu-devel] [PATCH 0/7] merge some xen bits into qemu Anthony Liguori
2008-08-05  9:58   ` Gerd Hoffmann
2008-08-05 10:15     ` Samuel Thibault
2008-08-05 10:46   ` Samuel Thibault
2008-08-05 11:12     ` Gerd Hoffmann
2008-08-05 11:29       ` Samuel Thibault
2008-08-05 13:18         ` Gerd Hoffmann
2008-08-05 15:03           ` Samuel Thibault
2008-08-05 15:41             ` Samuel Thibault
2008-08-05 15:46               ` Anthony Liguori
2008-08-05 16:07                 ` Blue Swirl
2008-08-05 15:47               ` Samuel Thibault
2008-08-06 10:14               ` Gerd Hoffmann
2008-08-06 10:23                 ` Samuel Thibault
2008-08-06 12:43                   ` [Xen-devel] " Markus Armbruster
2008-08-06 12:50                     ` Samuel Thibault
2008-08-06 13:54                       ` Gerd Hoffmann
2008-08-06 14:01                         ` Samuel Thibault
2008-08-06 14:08                           ` Gerd Hoffmann
2008-08-06 14:25                             ` Samuel Thibault
2008-08-06 15:35                               ` Gerd Hoffmann
2008-08-06 15:47                                 ` Samuel Thibault
2008-08-06 22:10                                   ` Gerd Hoffmann
2008-08-06 22:16                                     ` Samuel Thibault
2008-08-06 16:01                                 ` Laurent Vivier
2008-08-06 22:10                               ` Samuel Thibault
2008-08-07  7:33                                 ` Gerd Hoffmann
2008-08-07 10:53                                   ` Samuel Thibault
2008-08-07 12:13                                     ` Gerd Hoffmann
2008-08-07 12:54                                       ` Samuel Thibault
2008-08-07 16:17                                         ` Gerd Hoffmann
2008-08-07 16:48                                           ` Samuel Thibault
2008-08-07 16:54                                             ` Samuel Thibault
2008-08-07 16:09                                       ` Samuel Thibault
2008-08-07 16:34                                       ` Samuel Thibault
2008-08-11  8:16                                         ` Gerd Hoffmann
2008-08-11  9:23                                           ` Stefano Stabellini
2008-08-11 10:12                                       ` Ian Jackson
2008-08-07 15:06                                   ` Blue Swirl
2008-08-07 15:13                                     ` Samuel Thibault
2008-08-07 15:13                                     ` Samuel Thibault
2008-08-07 15:21                                     ` Gerd Hoffmann
2008-08-08 15:24                                       ` Blue Swirl
2008-08-11 12:46                                         ` Gerd Hoffmann
2008-08-11 18:53                                           ` Blue Swirl
2008-08-08 11:03                                     ` Samuel Thibault
2008-08-07 17:40                         ` Stefano Stabellini
2008-08-11  9:18                         ` Ian Jackson
2008-08-11 11:08                           ` Gerd Hoffmann
2008-08-06 13:24                   ` Gerd Hoffmann
2008-08-06 13:39                     ` Samuel Thibault
2008-08-06 14:18                       ` Gerd Hoffmann
2008-08-06 14:51                         ` Samuel Thibault
2008-08-06 15:25                           ` Gerd Hoffmann
2008-08-11 16:36   ` [Qemu-devel] Xen's qemu branches, etc Ian Jackson
2008-08-11 16:48     ` [Qemu-devel] Re: [Xen-devel] " Samuel Thibault
2008-08-11 19:17     ` [Qemu-devel] " Anthony Liguori
2008-08-11 19:34     ` [Qemu-devel] " Gerd Hoffmann
  -- strict thread matches above, loose matches on Subject: below --
2008-10-28 12:23 [Qemu-devel] [PATCH 0/7] merge some xen bits into qemu Gerd Hoffmann
2008-10-28 12:23 ` [Qemu-devel] [PATCH 7/7] xen: blk & nic configuration via cmd line Gerd Hoffmann
2008-07-28 13:17 [Qemu-devel] [PATCH 0/7] merge some xen bits into qemu Gerd Hoffmann
2008-07-28 13:17 ` [Qemu-devel] [PATCH 7/7] xen: blk & nic configuration via cmd line Gerd Hoffmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1217865045-10722-8-git-send-email-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).