Actually mark drives as read-only if so configured
authorIustin Pop <iustin@google.com>
Wed, 28 Jan 2009 19:06:00 +0000 (19:06 +0000)
committerIustin Pop <iustin@google.com>
Wed, 28 Jan 2009 19:06:00 +0000 (19:06 +0000)
This patch correctly marks the drives as read-only for Xen, and raises
and exception for KVM since it doesn't support read-only drives.

Reviewed-by: ultrotter

lib/hypervisor/hv_kvm.py
lib/hypervisor/hv_xen.py

index 22cbdc5..13bc8d4 100644 (file)
@@ -222,6 +222,9 @@ class KVMHypervisor(hv_base.BaseHypervisor):
 
     boot_drive = True
     for cfdev, dev_path in block_devices:
+      if cfdev.mode != constants.DISK_RDWR:
+        raise errors.HypervisorError("Instance has read-only disks which"
+                                     " are not supported by KVM")
       # TODO: handle FD_LOOP and FD_BLKTAP (?)
       if boot_drive:
         boot_val = ',boot=on'
index 506f200..c8dd581 100644 (file)
@@ -277,11 +277,15 @@ class XenHypervisor(hv_base.BaseHypervisor):
     # directly export their info (currently HVM will just sed this info)
     namespace = ["sd" + chr(i + ord('a')) for i in range(24)]
     for sd_name, (cfdev, dev_path) in zip(namespace, block_devices):
+      if cfdev.mode == constants.DISK_RDWR:
+        mode = "w"
+      else:
+        mode = "r"
       if cfdev.dev_type == constants.LD_FILE:
-        line = "'%s:%s,%s,w'" % (FILE_DRIVER_MAP[cfdev.physical_id[0]],
-                                 dev_path, sd_name)
+        line = "'%s:%s,%s,%s'" % (FILE_DRIVER_MAP[cfdev.physical_id[0]],
+                                  dev_path, sd_name, mode)
       else:
-        line = "'phy:%s,%s,w'" % (dev_path, sd_name)
+        line = "'phy:%s,%s,%s'" % (dev_path, sd_name, mode)
       disk_data.append(line)
 
     return disk_data