Skip to contentSkip to conversation

qemu blkback implementation

PATCH In review Stefano Stabellini 2 participants 6 messages Nov 18, 2010 – Nov 23, 2010

lore
Share & tools
lore
#0 lore raw

cover qemu blkback implementation

Hi all,
this patch series adds a pure userspace blkback implementation to qemu that is used by default when blktap2 is not present in the system (for example because your dom0 kernel doesn't have a blkback or blktap2 backend). For the moment the goal is just to make it easier for developers to work with upstream 2.6.37 kernels as dom0 for debugging and development.

The first patch backports xen_disk from upstream qemu to qemu-xen; xen_disk is a pure userspace blkback implementation. Xen_disk looks for qdisk paths on xenstore so it doesn' conflict with blkback or blktap. The second patch adds support for qdisks in qemu for PV and HVM guests. The third patch adds a second qdisk backend when qemu is run as backend provider for stubdoms, so that it can serve both the stubdom and the guest at the same time.
The last patch adds support for qdisk in libxl: qdisks are used only when blktap2 is not available.

I want to highlight again that this series is not a substitute for blktap2 but mainly a development and debugging tool, that allow you to actually create and boot VMs on upstream 2.6.37 dom0 kernels! Also this series doesn't start a qemu for PV guests by default yet, so if you want to use qdisks make sure that you have a vfb configured in your VM config file, even if you don't plan to use it.

Enjoy your shiny 2.6.37rc2 kernel,

Stefano

#1 lore raw

PATCH 1/4 qemu-xen: backport xen_disk from upstream qemu

xen_disk is a pure userspace blkback implementation that can be used to provided a disk backend called qdisk.
It is particularly useful with a dom0 kernel that doesn't have blktap2 (Linux 2.6.37).

hw/xen_backend.h +1 -0
index 7e89ef4..c48c593 100644
@@ -89,6 +89,7 @@ void xen_be_printf(struct XenDevice *xendev, int msg_level, const char *fmt, ...
 extern struct XenDevOps xen_console_ops;      /* xen_console.c     */
 extern struct XenDevOps xen_kbdmouse_ops;     /* xen_framebuffer.c */
 extern struct XenDevOps xen_framebuffer_ops;  /* xen_framebuffer.c */
+extern struct XenDevOps xen_blkdev_ops;       /* xen_disk.c        */
 
 void xen_init_display(int domid);
 
hw/xen_blkif.h new file +103 -0

103 lines not on this page · raw message

hw/xen_disk.c new file +783 -0

783 lines not on this page · raw message

hw/xen_machine_fv.c +1 -0
index 79880a8..7eb3792 100644
@@ -368,6 +368,7 @@ static void xen_init_fv(ram_addr_t ram_size, int vga_ram_size,
         exit(1);
     }
     xen_be_register("console", &xen_console_ops);
+    xen_be_register("qdisk", &xen_blkdev_ops);
 
     pc_machine.init(ram_size, vga_ram_size, boot_device,
 		    kernel_filename, kernel_cmdline, initrd_filename,
hw/xen_machine_pv.c +1 -0
index 34fe4d4..b2475ba 100644
@@ -69,6 +69,7 @@ static void xen_init_pv(ram_addr_t ram_size, int vga_ram_size,
     xen_be_register("console", &xen_console_ops);
     xen_be_register("vkbd", &xen_kbdmouse_ops);
     xen_be_register("vfb", &xen_framebuffer_ops);
+    xen_be_register("qdisk", &xen_blkdev_ops);
 
     /* setup framebuffer */
     xen_init_display(xen_domid);
sysemu.h +1 -1
index 87b278b..66b8ab2 100644
@@ -127,7 +127,7 @@ extern unsigned int nb_prom_envs;
 
 typedef enum {
     IF_BLKTAP,
-    IF_IDE, IF_SCSI, IF_FLOPPY, IF_PFLASH, IF_MTD, IF_SD, IF_VIRTIO
+    IF_IDE, IF_SCSI, IF_FLOPPY, IF_PFLASH, IF_MTD, IF_SD, IF_VIRTIO, IF_XEN
 } BlockInterfaceType;
 
 typedef enum {
vl.c +4 -0
index a90da8c..2fb5f82 100644
@@ -2396,6 +2396,9 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque)
 	} else if (!strcmp(buf, "mtd")) {
 	    type = IF_MTD;
             max_devs = 0;
+	} else if (!strcmp(buf, "xen")) {
+	    type = IF_XEN;
+            max_devs = 0;
 	} else if (!strcmp(buf, "sd")) {
 	    type = IF_SD;
             max_devs = 0;
@@ -2615,6 +2618,7 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque)
 
     switch(type) {
     case IF_IDE:
+    case IF_XEN:
     case IF_SCSI:
         switch(media) {
 	case MEDIA_DISK:
xen-hooks.mak +1 -0
index 93f4402..891d1aa 100644
@@ -30,6 +30,7 @@ OBJS += xen_machine_pv.o
 OBJS += xen_backend.o
 OBJS += xenfb.o
 OBJS += xen_console.o
+OBJS += xen_disk.o
 OBJS += xen_machine_fv.o
 OBJS += exec-dm.o
 OBJS += pci_emulation.o
#2 lore raw

PATCH 2/4 qemu-xen: support qdisk as disk backend

In reply to Stefano Stabellini

Support qdisk in xenstore_parse_domain_config; do not call xenstore_parse_domain_config with pv guests.

qemu-xen.h +1 -0
index a2d57ac..7821b54 100644
@@ -62,6 +62,7 @@ void handle_buffered_pio(void);
 #endif
 
 /* xenstore.c */
+void xenstore_init(void);
 void xenstore_parse_domain_config(int domid);
 int xenstore_parse_disable_pf_config(void);
 int xenstore_fd(void);
vl.c +4 -3
index 2fb5f82..d465a09 100644
@@ -5813,17 +5813,18 @@ int main(int argc, char **argv, char **envp)
     dma_helper_init();
 
     xc_handle = xc_interface_open(0,0,0); /* fixme check errors */
+    xenstore_init();
+    if (!strcmp(machine->name, "xenfv")) {
 #ifdef CONFIG_STUBDOM
-    {
         char *domid_s, *msg;
         if ((msg = xenbus_read(XBT_NIL, "domid", &domid_s)))
             fprintf(stderr,"Can not read our own domid: %s\n", msg);
         else
             xenstore_parse_domain_config(atoi(domid_s));
-    }
 #else
-    xenstore_parse_domain_config(domid);
+        xenstore_parse_domain_config(domid);
 #endif /* CONFIG_STUBDOM */
+    }
 
     /* we always create the cdrom drive, even if no disk is there */
 
xenstore.c +19 -12
index 7b9c2ae..b7e7c28 100644
@@ -278,11 +278,14 @@ static void xenstore_get_backend_path(char **backend, const char *devtype,
     backend_dompath = xs_get_domain_path(xsh, domid_backend);
     if (!backend_dompath) goto out;
     
-    const char *expected_devtypes[3];
+    const char *expected_devtypes[4];
     const char **expected_devtype = expected_devtypes;
 
     *expected_devtype++ = devtype;
-    if (!strcmp(devtype, "vbd")) *expected_devtype++ = "tap";
+    if (!strcmp(devtype, "vbd")) {
+	*expected_devtype++ = "tap";
+	*expected_devtype++ = "qdisk";
+    }
     *expected_devtype = 0;
     assert(expected_devtype <
            expected_devtypes + ARRAY_SIZE(expected_devtypes));
@@ -392,6 +395,17 @@ static const char *xenstore_get_guest_uuid(void)
 #define PT_PCI_POWER_MANAGEMENT_DEFAULT 0
 int direct_pci_msitranslate;
 int direct_pci_power_mgmt;
+void xenstore_init(void)
+{
+    xenstore_get_guest_uuid();
+
+    xsh = xs_daemon_open();
+    if (xsh == NULL) {
+        fprintf(logfile, "Could not contact xenstore for domain config\n");
+        return;
+    }
+}
+
 void xenstore_parse_domain_config(int hvm_domid)
 {
     char **e_danger = NULL;
@@ -416,14 +430,6 @@ void xenstore_parse_domain_config(int hvm_domid)
     for(i = 0; i < MAX_DRIVES + 1; i++)
         media_filename[i] = NULL;
 
-    xenstore_get_guest_uuid();
-
-    xsh = xs_daemon_open();
-    if (xsh == NULL) {
-        fprintf(logfile, "Could not contact xenstore for domain config\n");
-        return;
-    }
-
     danger_path = xs_get_domain_path(xsh, hvm_domid);
     if (danger_path == NULL) {
         fprintf(logfile, "xs_get_domain_path() error\n");
@@ -496,7 +502,7 @@ void xenstore_parse_domain_config(int hvm_domid)
         if (drv == NULL)
             continue;
         /* Obtain blktap sub-type prefix */
-        if (!strcmp(drv, "tap") && params[0]) {
+        if ((!strcmp(drv, "tap") || !strcmp(drv, "qdisk")) && params[0]) {
             char *offset = strchr(params, ':'); 
             if (!offset)
                 continue ;
@@ -1055,7 +1061,8 @@ void xenstore_process_event(void *opaque)
         if (pasprintf(&buf, "%s/type", bpath) == -1) 
             goto out;
         drv = xs_read(xsh, XBT_NULL, buf, &len);
-        if (drv && !strcmp(drv, "tap") && ((offset = strchr(image, ':')) != NULL))
+	if (drv && (!strcmp(drv, "tap") || !strcmp(drv, "qdisk")) &&
+		((offset = strchr(image, ':')) != NULL))
             memmove(image, offset+1, strlen(offset+1)+1);
 
         if (!strcmp(image, drives_table[hd_index].bdrv->filename))
Signature · 1 line
1.5.6.5
#3 lore raw

PATCH 3/4 qemu-xen: support qdisk with stubdoms

In reply to Stefano Stabellini

In the qemu used as backend provider for stubdoms, register two qdisk
backends: one for the stubdom and one for the guest.

hw/xen_backend.c +1 -1
index afd0bf2..537e21f 100644
@@ -526,7 +526,7 @@ void xen_be_check_state(struct XenDevice *xendev)
 
 /* ------------------------------------------------------------- */
 
-static int xenstore_scan(const char *type, int dom, struct XenDevOps *ops)
+int xenstore_scan(const char *type, int dom, struct XenDevOps *ops)
 {
     struct XenDevice *xendev;
     char path[XEN_BUFSIZE], token[XEN_BUFSIZE];
hw/xen_backend.h +1 -0
index c48c593..28e77ac 100644
@@ -78,6 +78,7 @@ void xen_be_check_state(struct XenDevice *xendev);
 /* xen backend driver bits */
 int xen_be_init(void);
 int xen_be_register(const char *type, struct XenDevOps *ops);
+int xenstore_scan(const char *type, int dom, struct XenDevOps *ops);
 int xen_be_set_state(struct XenDevice *xendev, enum xenbus_state state);
 int xen_be_bind_evtchn(struct XenDevice *xendev);
 void xen_be_unbind_evtchn(struct XenDevice *xendev);
hw/xen_machine_pv.c +4 -0
index b2475ba..434a902 100644
@@ -44,6 +44,7 @@ static void xen_init_pv(ram_addr_t ram_size, int vga_ram_size,
 			const char *direct_pci)
 {
     CPUState *env;
+    uint32_t domid_target;
 
 #ifndef CONFIG_STUBDOM
     /* Initialize tapdisk client */
@@ -70,6 +71,9 @@ static void xen_init_pv(ram_addr_t ram_size, int vga_ram_size,
     xen_be_register("vkbd", &xen_kbdmouse_ops);
     xen_be_register("vfb", &xen_framebuffer_ops);
     xen_be_register("qdisk", &xen_blkdev_ops);
+    domid_target = xenstore_read_target();
+    if (domid_target)
+        xenstore_scan("qdisk", domid_target, &xen_blkdev_ops);
 
     /* setup framebuffer */
     xen_init_display(xen_domid);
qemu-xen.h +1 -0
index 7821b54..0e70dbe 100644
@@ -63,6 +63,7 @@ void handle_buffered_pio(void);
 
 /* xenstore.c */
 void xenstore_init(void);
+uint32_t xenstore_read_target(void);
 void xenstore_parse_domain_config(int domid);
 int xenstore_parse_disable_pf_config(void);
 int xenstore_fd(void);
xenstore.c +36 -0
index b7e7c28..d364a5e 100644
@@ -391,6 +391,42 @@ static const char *xenstore_get_guest_uuid(void)
     return already_computed;
 }
 
+uint32_t xenstore_read_target(void)
+{
+    char *domain_path = NULL, *target_path = NULL, *target_value = NULL, *p = NULL;
+    unsigned int len;
+    uint32_t target_domid = 0;
+
+    if (xsh == NULL)
+        return 0;
+
+    domain_path = xs_get_domain_path(xsh, domid);
+    if (domain_path == NULL) {
+        fprintf(logfile, "xs_get_domain_path() error. domid %d.\n", domid);
+        goto out;
+    }
+
+    if (pasprintf(&target_path, "%s/target", domain_path) == -1) {
+        fprintf(logfile, "xenstore_get_guest_uuid(): out of memory.\n");
+        goto out;
+    }
+    target_value = xs_read(xsh, XBT_NULL, target_path, &len);
+    if (target_value == NULL) {
+        fprintf(logfile, "xs_read(): target get error. %s.\n", target_path);
+        goto out;
+    }
+
+    fprintf(logfile, "target = %s\n", target_value);
+    target_domid = strtoul(target_value, NULL, 10);
+
+ out:
+    free(domain_path);
+    free(target_path);
+    free(target_value);
+
+    return target_domid;
+}
+
 #define PT_PCI_MSITRANSLATE_DEFAULT 1
 #define PT_PCI_POWER_MANAGEMENT_DEFAULT 0
 int direct_pci_msitranslate;
#4 lore raw

PATCH 4/4 xl: use qdisk if blktap2 is not available

In reply to Stefano Stabellini

Whenever blktap2 is not available use qdisk as block backend instead.

tools/libxl/libxl.c +4 -1
diff -r 388c44a63613 tools/libxl/libxl.c
@@ -1856,7 +1856,10 @@ int libxl_device_disk_add(libxl_ctx *ctx
             flexarray_set(back, boffset++, libxl__sprintf(&gc, "%s:%s",
                           libxl__device_disk_string_of_phystype(disk->phystype), disk->physpath));
 
-            device.backend_kind = DEVICE_TAP;
+            if (libxl__blktap_enabled(&gc))
+                device.backend_kind = DEVICE_TAP;
+            else
+                device.backend_kind = DEVICE_QDISK;
             break;
 
         default:
tools/libxl/libxl_device.c +1 -0
diff -r 388c44a63613 tools/libxl/libxl_device.c
@@ -33,6 +33,7 @@ static const char *string_of_kinds[] = {
     [DEVICE_VIF2] = "vif2",
     [DEVICE_VBD] = "vbd",
     [DEVICE_TAP] = "tap",
+    [DEVICE_QDISK] = "qdisk",
     [DEVICE_PCI] = "pci",
     [DEVICE_VFB] = "vfb",
     [DEVICE_VKBD] = "vkbd",
tools/libxl/libxl_internal.h +1 -0
diff -r 388c44a63613 tools/libxl/libxl_internal.h
@@ -82,6 +82,7 @@ typedef enum {
     DEVICE_VIF2,
     DEVICE_VBD,
     DEVICE_TAP,
+    DEVICE_QDISK,
     DEVICE_PCI,
     DEVICE_VFB,
     DEVICE_VKBD,