[et-mgmt-tools] [PATCH] Check the making domain's disk sources

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

 



Hi,

The virt-install command specify the Domain's disk sources.
But the virt-install command doesn't check that the disk sources are
conflicted among the other domains.

The attached patch resolve this issue in the following way:

  1) Count that the making domian's disk src is already use
     the exists domain's disk source.
  2) if count > 0, print confirmation message.
  3) if type yes then leave disk source as it is,
     else ask disk source again.

I am making a patch for virt-manager about this issue.

Signed-off-by: Tatsuro Enokura <fj7716hz@xxxxxxxxxxxxxxxxx>

Thanks,
Tatsuro Enokura.

--------------------------------------------------------------------
diff -r 057e8c1b54df virt-install
--- a/virt-install      Wed Mar 14 16:11:43 2007 -0400
+++ b/virt-install      Thu Mar 15 16:31:43 2007 +0900
@@ -103,7 +103,7 @@ def get_keymap(keymap, guest):
         except ValueError, e:
             print "ERROR: ", e

-def get_disk(disk, size, sparse, guest, hvm):
+def get_disk(disk, size, sparse, guest, hvm, conn):
     # FIXME: need to handle a list of disks at some point
     while 1:
         msg = "What would you like to use as the disk (path)?"
@@ -121,6 +121,57 @@ def get_disk(disk, size, sparse, guest,
                 print "ERROR: ", e
                 size = None

+        # disk src confilct check
+        vms = []
+        # get working domain's name
+        ids = conn.listDomainsID();
+        for id in ids:
+            vm = conn.lookupByID(id)
+            vms.append(vm)
+        # get defined domain
+        names = conn.listDefinedDomains()
+        for name in names:
+            vm = conn.lookupByName(name)
+            vms.append(vm)
+
+        count = 0
+        for vm in vms:
+            doc = None
+            try:
+                doc = libxml2.parseDoc(vm.XMLDesc(0))
+            except:
+                continue
+            ctx = doc.xpathNewContext()
+            try:
+                try:
+                    count +=
ctx.xpathEval("count(/domain/devices/disk/source[@dev='%s'])" % disk)
+                except:
+                    continue
+            finally:
+                if ctx is not None:
+                    ctx.xpathFreeContext()
+                if doc is not None:
+                    doc.freeDoc()
+        if count > 0:
+            # confilct disk src
+            while 1:
+                retryFlg = False
+                warnmsg = "Disk %s is already in use by another guest!"
% disk
+                res = prompt_for_input(warnmsg + "  Do you really want
to use the disk (yes or no)? ")
+                try:
+                    if yes_or_no(res) is True:
+                        break
+                    else:
+                        retryFlg = True
+                        break
+                except ValueError, e:
+                    print "ERROR: ", e
+                    continue
+            if retryFlg is True:
+                # disk data clear, ask agein
+                disk = None
+                continue
+
         try:
             d = virtinst.VirtualDisk(disk, size, sparse = sparse)
             if d.type == virtinst.VirtualDisk.TYPE_FILE and not(hvm)
and virtinst.util.is_blktap_capable():
@@ -133,7 +184,7 @@ def get_disk(disk, size, sparse, guest,
         guest.disks.append(d)
         break

-def get_disks(disk, size, sparse, guest, hvm):
+def get_disks(disk, size, sparse, guest, hvm, conn):
     # ensure we have equal length lists
     if (type(disk) == type(size) == list):
         if len(disk) != len(size):
@@ -145,13 +196,13 @@ def get_disks(disk, size, sparse, guest,
         disk = [ None ] * len(size)

     if (type(disk) == list):
-        map(lambda d, s: get_disk(d, s, sparse, guest, hvm),
+        map(lambda d, s: get_disk(d, s, sparse, guest, hvm, conn),
             disk, size)
     elif (type(size) == list):
-        map(lambda d, s: get_disk(d, s, sparse, guest, hvm),
+        map(lambda d, s: get_disk(d, s, sparse, guest, hvm, conn),
             disk, size)
     else:
-        get_disk(disk, size, sparse, guest, hvm)
+        get_disk(disk, size, sparse, guest, hvm, conn)

 def get_network(mac, bridge, guest):
     if mac == "RANDOM":
@@ -461,7 +512,7 @@ def main():

     # set up disks
     get_disks(options.diskfile, options.disksize, options.sparse,
-              guest, hvm)
+              guest, hvm, conn)

     # set up network information
     get_networks(options.mac, options.bridge, guest)
--------------------------------------------------------------------


[Index of Archives]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux