KVM and Xen: add the HV_ROOT_PATH parameter
authorGuido Trotter <ultrotter@google.com>
Tue, 27 Jan 2009 11:31:38 +0000 (11:31 +0000)
committerGuido Trotter <ultrotter@google.com>
Tue, 27 Jan 2009 11:31:38 +0000 (11:31 +0000)
This parameter allows a different path to be passed to the instance
kernel. The new parameter is mandatory, and by default has the value of
the old hardcoded value for both kvm and xen.

Beta1 clusters will need to have this parameter added for their
instances to be able to boot.

Reviewed-by: iustinp

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

index 0c44675..9d85e61 100644 (file)
@@ -287,6 +287,7 @@ HV_ACPI = "acpi"
 HV_PAE = "pae"
 HV_KERNEL_PATH = "kernel_path"
 HV_INITRD_PATH = "initrd_path"
+HV_ROOT_PATH = "root_path"
 
 HVS_PARAMETERS = frozenset([
   HV_BOOT_ORDER,
@@ -298,6 +299,7 @@ HVS_PARAMETERS = frozenset([
   HV_PAE,
   HV_KERNEL_PATH,
   HV_INITRD_PATH,
+  HV_ROOT_PATH,
   ])
 
 # BE parameter names
@@ -426,6 +428,7 @@ HVC_DEFAULTS = {
     HT_XEN_PVM: {
         HV_KERNEL_PATH: "/boot/vmlinuz-2.6-xenU",
         HV_INITRD_PATH: None,
+        HV_ROOT_PATH: '/dev/sda',
         },
     HT_XEN_HVM: {
         HV_BOOT_ORDER: "cd",
@@ -439,6 +442,7 @@ HVC_DEFAULTS = {
     HT_KVM: {
         HV_KERNEL_PATH: "/boot/vmlinuz-2.6-kvmU",
         HV_INITRD_PATH: None,
+        HV_ROOT_PATH: '/dev/vda',
         HV_ACPI: True,
         },
     HT_FAKE: {
index 0316b1b..22cbdc5 100644 (file)
@@ -51,6 +51,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
   PARAMETERS = [
     constants.HV_KERNEL_PATH,
     constants.HV_INITRD_PATH,
+    constants.HV_ROOT_PATH,
     constants.HV_ACPI,
     ]
 
@@ -240,7 +241,8 @@ class KVMHypervisor(hv_base.BaseHypervisor):
     if initrd_path:
       kvm_cmd.extend(['-initrd', initrd_path])
 
-    kvm_cmd.extend(['-append', 'console=ttyS0,38400 root=/dev/vda'])
+    root_path = instance.hvparams[constants.HV_ROOT_PATH]
+    kvm_cmd.extend(['-append', 'console=ttyS0,38400 root=%s ro' % root_path])
 
     #"hvm_boot_order",
     #"hvm_cdrom_image_path",
@@ -626,6 +628,9 @@ class KVMHypervisor(hv_base.BaseHypervisor):
     if not os.path.isabs(hvparams[constants.HV_KERNEL_PATH]):
       raise errors.HypervisorError("The kernel path must be an absolute path")
 
+    if not hvparams[constants.HV_ROOT_PATH]:
+      raise errors.HypervisorError("Need a root partition for the instance")
+
     if hvparams[constants.HV_INITRD_PATH]:
       if not os.path.isabs(hvparams[constants.HV_INITRD_PATH]):
         raise errors.HypervisorError("The initrd path must be an absolute path"
index f92b2fe..5b71ff2 100644 (file)
@@ -364,6 +364,7 @@ class XenPvmHypervisor(XenHypervisor):
   PARAMETERS = [
     constants.HV_KERNEL_PATH,
     constants.HV_INITRD_PATH,
+    constants.HV_ROOT_PATH,
     ]
 
   @classmethod
@@ -386,6 +387,9 @@ class XenPvmHypervisor(XenHypervisor):
     if not os.path.isabs(hvparams[constants.HV_KERNEL_PATH]):
       raise errors.HypervisorError("The kernel path must be an absolute path")
 
+    if not hvparams[constants.HV_ROOT_PATH]:
+      raise errors.HypervisorError("Need a root partition for the instance")
+
     if hvparams[constants.HV_INITRD_PATH]:
       if not os.path.isabs(hvparams[constants.HV_INITRD_PATH]):
         raise errors.HypervisorError("The initrd path must be an absolute path"
@@ -443,7 +447,9 @@ class XenPvmHypervisor(XenHypervisor):
     config.write("disk = [%s]\n" % ",".join(
                  cls._GetConfigFileDiskData(instance.disk_template,
                                             block_devices)))
-    config.write("root = '/dev/sda ro'\n")
+
+    rpath = instance.hvparams[constants.HV_ROOT_PATH]
+    config.write("root = '%s ro'\n" % rpath)
     config.write("on_poweroff = 'destroy'\n")
     config.write("on_reboot = 'restart'\n")
     config.write("on_crash = 'restart'\n")