Skip to contentSkip to conversation

xm: Reuse VDI if location is same

PATCH New Masaki Kanno 1 participant 1 message Oct 15, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xm: Reuse VDI if location is same

Hi,

In XenAPI mode, when we start a VM by using xm create command, VDIs are always automatically created for VBDs. Once we shut down the VM, then start the VM again, then VDIs are newly created. As a result, a vdi.xml file continues to expand.

This patch reuses VDIs if location of the VDIs is same.

Best regards,
Kan

tools/python/xen/xm/xenapi_create.py +10 -0
diff -r 18758847bf31 tools/python/xen/xm/xenapi_create.py
@@ -215,6 +215,16 @@
     def create_vdi(self, vdi):
         log(DEBUG, "create_vdi")
 
+        for ref, record in server.xenapi.VDI.get_all_records().items():
+            location = record["other_config"]["location"]
+            if vdi.attributes["src"].value != location:
+                continue
+
+            # Reuse the VDI because the location is same.
+            key = vdi.attributes["name"].value
+            return (key, ref)
+
+        # Create a new VDI.
         vdi_record = {
             "name_label":       get_name_label(vdi),
             "name_description": get_name_description(vdi),

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel