[libvirt] [PATCHv7 4/4] libvirt/qemu - verify new device at attaching persistent.

KAMEZAWA Hiroyuki kamezawa.hiroyu at jp.fujitsu.com
Fri Mar 25 08:19:09 UTC 2011


>From 8423316cbd8e4efa4240cc73ac65955d87cb9921 Mon Sep 17 00:00:00 2001
From: KAMEZAWA Hiroyuki <kamezawa.hiroyu at jp.fujitsu.com>
Date: Fri, 25 Mar 2011 17:13:05 +0900
Subject: [PATCHv7 4/4] libvirt/qemu - verify new device at attaching persistent

When adding a device by attach-device in --persistent mode,
the user can pass invalid devices. For example,

XX
<disk type='file' device='disk'>
   <driver name='qemu' type='qcow2'/>
   <source file='/var/lib/libvirt/images/test3.img'/>
   <target dev='hde' bus='ide'/>
</disk>
XX

When adding this, 2nd IDE controller will be added but
qemu only supports 1 controller. It's better to check this kinds
of qemu/qemu_driver limitation.
(This can be added by virsh edit...)

Check we can make a command line or not at adding device will
be a consistent verification with future qemu driver updates.

Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu at jp.fujitsu.com>
---
 src/qemu/qemu_driver.c |   35 +++++++++++++++++++++++++++++++++++
 1 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index e746576..482f762 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4156,6 +4156,38 @@ static int qemuDomainDeviceAddressFixup(virDomainDefPtr vmdef, bool pci)
 }
 
 /*
+ * Check the device definition meet's qemu/qemu_drriver's requirements.
+ */
+static int qemuDeviceVerifyDefinition(virDomainDefPtr vmdef,
+                                      virDomainDeviceDefPtr dev)
+{
+    virBitmapPtr qemuCaps = NULL;
+    int ret = -1;
+    char *optstr;
+
+    if (qemuCapsExtractVersionInfo(vmdef->emulator, vmdef->os.arch,
+                                   NULL,
+                                   &qemuCaps))
+        goto out;
+    switch(dev->type) {
+    case VIR_DOMAIN_DEVICE_DISK:
+        /* for verify, check we can create qemu command line or not */
+        optstr = qemuBuildDriveStr(dev->data.disk, 0, qemuCaps);
+        if (!optstr)
+            goto free_out;
+        ret = 0;
+        VIR_FREE(optstr);
+        /* now,  don't need to check qemuBuildDriveDevStr() */
+        break;
+    default:
+        break;
+    }
+free_out:
+    qemuCapsFree(qemuCaps);
+out:
+    return ret;
+}
+/*
  * Attach a device given by XML, the change will be persistent
  * and domain XML definition file is updated.
  */
@@ -4166,6 +4198,9 @@ static int qemuDomainAttachDevicePersistent(virDomainDefPtr vmdef,
     bool pci;
     int ret;
 
+    if (qemuDeviceVerifyDefinition(vmdef, newdev))
+        return -1;
+
     if (virDomainDefFindDeviceAddressConflict(vmdef, newdev)) {
         qemuReportError(VIR_ERR_INVALID_ARG, "%s",
                         _("the device address already in use"));
-- 
1.7.4.1





More information about the libvir-list mailing list