[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCHv8 3/4] libvirt/qemu - support persistent disk modification



>From 96e42331674c9de4640422dd6f9e044319d9f700 Mon Sep 17 00:00:00 2001
From: root <root bluextal (none)>
Date: Fri, 1 Apr 2011 11:38:49 +0900
Subject: [PATCH 3/4] libvirt/qemu - support persistent disk modification

support changes of disks by VIR_DOMAIN_DEVICE_MODIFY_CONFIG
for qemu.

Signed-off-by: KAMEZAWA Hiroyuki <kamezawa hiroyu jp fujitsu com>
Changelog: v7->v8
 - adjusted to use Copy/Sync/Undo mechanism.
---
 src/conf/domain_conf.c   |   22 ++++++++++++++++++++++
 src/conf/domain_conf.h   |    2 ++
 src/libvirt_private.syms |    2 ++
 src/qemu/qemu_driver.c   |   30 ++++++++++++++++++++++++++++++
 4 files changed, 56 insertions(+), 0 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 098face..8948ab0 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -4877,6 +4877,19 @@ virVirtualPortProfileFormat(virBufferPtr buf,
     virBufferVSprintf(buf, "%s</virtualport>\n", indent);
 }
 
+int virDomainDiskIndexByName(virDomainDefPtr def, const char *name)
+{
+    virDomainDiskDefPtr vdisk;
+    int i;
+
+    for (i = 0; i < def->ndisks; i++) {
+        vdisk = def->disks[i];
+        if (STREQ(vdisk->dst, name))
+            return i;
+    }
+    return -1;
+}
+
 int virDomainDiskInsert(virDomainDefPtr def,
                         virDomainDiskDefPtr disk)
 {
@@ -4948,6 +4961,15 @@ void virDomainDiskRemove(virDomainDefPtr def, size_t i)
     }
 }
 
+int virDomainDiskRemoveByName(virDomainDefPtr def, const char *name)
+{
+    int i = virDomainDiskIndexByName(def, name);
+    if (i < 0)
+        return -1;
+    virDomainDiskRemove(def, i);
+    return 0;
+}
+
 
 int virDomainControllerInsert(virDomainDefPtr def,
                               virDomainControllerDefPtr controller)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 28b3c0e..fc46700 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1282,6 +1282,7 @@ int virDomainVcpupinAdd(virDomainDefPtr def,
                         int maplen,
                         int vcpu);
 
+int virDomainDiskIndexByName(virDomainDefPtr def, const char *name);
 int virDomainDiskInsert(virDomainDefPtr def,
                         virDomainDiskDefPtr disk);
 void virDomainDiskInsertPreAlloced(virDomainDefPtr def,
@@ -1289,6 +1290,7 @@ void virDomainDiskInsertPreAlloced(virDomainDefPtr def,
 int virDomainDiskDefAssignAddress(virCapsPtr caps, virDomainDiskDefPtr def);
 
 void virDomainDiskRemove(virDomainDefPtr def, size_t i);
+int virDomainDiskRemoveByName(virDomainDefPtr def, const char *name);
 
 int virDomainControllerInsert(virDomainDefPtr def,
                               virDomainControllerDefPtr controller);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 62643d4..e8c5dce 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -245,11 +245,13 @@ virDomainDiskDefFree;
 virDomainDiskDeviceTypeToString;
 virDomainDiskErrorPolicyTypeFromString;
 virDomainDiskErrorPolicyTypeToString;
+virDomainDiskIndexByName;
 virDomainDiskInsert;
 virDomainDiskInsertPreAlloced;
 virDomainDiskIoTypeFromString;
 virDomainDiskIoTypeToString;
 virDomainDiskRemove;
+virDomainDiskRemoveByName;
 virDomainDiskTypeFromString;
 virDomainDiskTypeToString;
 virDomainFSDefFree;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 08055ef..eeaea0c 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -3884,8 +3884,28 @@ cleanup:
 static int qemuDomainAttachDevicePersistent(virDomainDefPtr vmdef,
                                             virDomainDeviceDefPtr newdev)
 {
+    virDomainDiskDefPtr disk;
 
     switch(newdev->type) {
+    case VIR_DOMAIN_DEVICE_DISK:
+        disk = newdev->data.disk;
+        if (virDomainDiskIndexByName(vmdef, disk->dst) >= 0) {
+            qemuReportError(VIR_ERR_INVALID_ARG,
+                            _("target %s already exists."), disk->dst);
+            return -1;
+        }
+        if (virDomainDiskInsert(vmdef, disk)) {
+            virReportOOMError();
+            return -1;
+        }
+        /* It's inserted. CopySync() or CopyUndo() will do all jobs */
+        newdev->data.disk = NULL;
+        if (disk->bus != VIR_DOMAIN_DISK_BUS_VIRTIO)
+            if (virDomainDefAddImplicitControllers(vmdef) < 0)
+                return -1;
+        if (qemuDomainAssignPCIAddresses(vmdef) < 0)
+            return -1;
+        break;
     default:
         qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                         _("the device is not supported for now"));
@@ -3898,7 +3918,17 @@ static int qemuDomainAttachDevicePersistent(virDomainDefPtr vmdef,
 static int qemuDomainDetachDevicePersistent(virDomainDefPtr vmdef,
                                             virDomainDeviceDefPtr device)
 {
+    virDomainDiskDefPtr disk;
+
     switch(device->type) {
+    case VIR_DOMAIN_DEVICE_DISK:
+        disk = device->data.disk;
+        if (virDomainDiskRemoveByName(vmdef, disk->dst)) {
+            qemuReportError(VIR_ERR_INVALID_ARG,
+                            _("no target device %s"), disk->dst);
+            return -1;
+        }
+        break;
     default:
         qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                         _("the device is not supported for now"));
-- 
1.7.4.1



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]