[PATCH] libvirt: support block device storage type in virshParseSnapshotDiskspec

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

 



virsh snapshot-create-as supports 'file' storage type in --diskspec by default.
It doesn't support 'block' storage type in the process of virshParseSnapshotDiskspec().
So if a snapshot on a block device (e.g. LV) was created, the type of current running
storage source in dumpxml is inconsistent with the actual backend storage source.
It will check file-system type mismatch failed and return an error message of
'Migration without shared storage is unsafe' when VM performs a live migration
after this snapshot.

Signed-off-by: Liu Dayu <liu.dayu@xxxxxxxxxx>
---
 tools/virsh-snapshot.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c
index f6bb38b..f9c55e0 100644
--- a/tools/virsh-snapshot.c
+++ b/tools/virsh-snapshot.c
@@ -255,6 +255,8 @@ virshParseSnapshotDiskspec(vshControl *ctl, virBufferPtr buf, const char *str)
     char **array = NULL;
     int narray;
     size_t i;
+    struct stat st;
+    int stor_type = VIR_STORAGE_TYPE_NONE;
 
     narray = vshStringToArray(str, &array);
     if (narray <= 0)
@@ -272,16 +274,29 @@ virshParseSnapshotDiskspec(vshControl *ctl, virBufferPtr buf, const char *str)
             goto cleanup;
     }
 
+    /* possibly update storage type */
+    if (file && STRPREFIX(file, "/dev/") && stat(file, &st) == 0 && S_ISBLK(st.st_mode))
+        stor_type = VIR_STORAGE_TYPE_BLOCK;
+    else
+        stor_type = VIR_STORAGE_TYPE_FILE;
+
     virBufferEscapeString(buf, "<disk name='%s'", name);
     if (snapshot)
         virBufferAsprintf(buf, " snapshot='%s'", snapshot);
+    if (stor_type == VIR_STORAGE_TYPE_BLOCK)
+        virBufferAsprintf(buf, " type='%s'", virStorageTypeToString(stor_type));
+
     if (driver || file) {
         virBufferAddLit(buf, ">\n");
         virBufferAdjustIndent(buf, 2);
         if (driver)
             virBufferAsprintf(buf, "<driver type='%s'/>\n", driver);
-        if (file)
-            virBufferEscapeString(buf, "<source file='%s'/>\n", file);
+        if (file) {
+            if (stor_type == VIR_STORAGE_TYPE_BLOCK)
+                virBufferEscapeString(buf, "<source dev='%s'/>\n", file);
+            else
+                virBufferEscapeString(buf, "<source file='%s'/>\n", file);
+        }
         virBufferAdjustIndent(buf, -2);
         virBufferAddLit(buf, "</disk>\n");
     } else {
-- 
1.8.3.1

--
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]

  Powered by Linux