[PATCH v2 3/7] qemu_domain: Introduce qemuDomainDiskSourceDiffers

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

 



This new private API should return true iff sources of two disks
differs in sense that qemu should be instructed to change the
disk backend. For instance, ejecting a CDROM is such case, or
pointing disk into a different ISO location, and so on.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/qemu/qemu_domain.c | 33 +++++++++++++++++++++++++++++++++
 src/qemu/qemu_domain.h |  4 ++++
 2 files changed, 37 insertions(+)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index c8b0ccd..60bd560 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -3002,6 +3002,39 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
 
 
 bool
+qemuDomainDiskSourceDiffers(virConnectPtr conn,
+                            virDomainDiskDefPtr disk,
+                            virDomainDiskDefPtr origDisk)
+{
+    char *diskSrc = NULL, *origDiskSrc = NULL;
+    bool diskEmpty, origDiskEmpty;
+    bool ret = true;
+
+    diskEmpty = virStorageSourceIsEmpty(disk->src);
+    origDiskEmpty = virStorageSourceIsEmpty(origDisk->src);
+
+    if (diskEmpty && origDiskEmpty)
+        return false;
+
+    if (diskEmpty ^ origDiskEmpty)
+        return true;
+
+    if (qemuGetDriveSourceString(disk->src, conn, &diskSrc) < 0 ||
+        qemuGetDriveSourceString(origDisk->src, conn, &origDiskSrc) < 0)
+        goto cleanup;
+
+    /* So far in qemu disk sources are considered different
+     * if either path to disk or its format changes. */
+    ret = virDomainDiskGetFormat(disk) != virDomainDiskGetFormat(origDisk) ||
+          STRNEQ_NULLABLE(diskSrc, origDiskSrc);
+ cleanup:
+    VIR_FREE(diskSrc);
+    VIR_FREE(origDiskSrc);
+    return ret;
+}
+
+
+bool
 qemuDomainDiskBlockJobIsActive(virDomainDiskDefPtr disk)
 {
     qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 91eaea1..0b9fd1c 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -411,6 +411,10 @@ int qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
                                  bool force_probe,
                                  bool report_broken);
 
+bool qemuDomainDiskSourceDiffers(virConnectPtr conn,
+                                 virDomainDiskDefPtr disk,
+                                 virDomainDiskDefPtr origDisk);
+
 int qemuDomainStorageFileInit(virQEMUDriverPtr driver,
                               virDomainObjPtr vm,
                               virStorageSourcePtr src);
-- 
2.4.6

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]