From d34b16d715ff7f678370bb5045dae2027b4745a8 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Wed, 28 Jan 2009 19:06:00 +0000 Subject: [PATCH] Actually mark drives as read-only if so configured 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 | 3 +++ lib/hypervisor/hv_xen.py | 10 +++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/hypervisor/hv_kvm.py b/lib/hypervisor/hv_kvm.py index 22cbdc5c9..13bc8d4ab 100644 --- a/lib/hypervisor/hv_kvm.py +++ b/lib/hypervisor/hv_kvm.py @@ -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' diff --git a/lib/hypervisor/hv_xen.py b/lib/hypervisor/hv_xen.py index 506f200b1..c8dd58107 100644 --- a/lib/hypervisor/hv_xen.py +++ b/lib/hypervisor/hv_xen.py @@ -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 -- GitLab