From 78411c605129c46acd97bbacf229b2f4eea9713c Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Wed, 4 Nov 2009 12:29:15 +0100
Subject: [PATCH] Introduce HV_MIGRATION_PORT hypervisor parameter

This parameter will replace the direct use of KVM_MIGRATION_PORT and the
implicit use of the Xen migration port.

While it doesn't make sense to change this at instance level, we don't
have any other infrastructure for cluster-wide hypervisor parameters, so
we add it here (and document that it usually shouldn't be changed on a
per-instance basis).

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
---
 lib/constants.py          |  5 +++++
 lib/hypervisor/hv_base.py |  2 ++
 lib/hypervisor/hv_kvm.py  |  5 +++--
 lib/hypervisor/hv_xen.py  |  2 ++
 man/gnt-instance.sgml     | 16 ++++++++++++++++
 5 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/lib/constants.py b/lib/constants.py
index eeba79b55..96454e7ab 100644
--- a/lib/constants.py
+++ b/lib/constants.py
@@ -390,6 +390,7 @@ HV_SERIAL_CONSOLE = "serial_console"
 HV_USB_MOUSE = "usb_mouse"
 HV_DEVICE_MODEL = "device_model"
 HV_INIT_SCRIPT = "init_script"
+HV_MIGRATION_PORT = "migration_port"
 
 HVS_PARAMETER_TYPES = {
   HV_BOOT_ORDER: VTYPE_STRING,
@@ -414,6 +415,7 @@ HVS_PARAMETER_TYPES = {
   HV_USB_MOUSE: VTYPE_STRING,
   HV_DEVICE_MODEL: VTYPE_STRING,
   HV_INIT_SCRIPT: VTYPE_STRING,
+  HV_MIGRATION_PORT: VTYPE_INT,
   }
 
 HVS_PARAMETERS = frozenset(HVS_PARAMETER_TYPES.keys())
@@ -607,6 +609,7 @@ HVC_DEFAULTS = {
     HV_INITRD_PATH: '',
     HV_ROOT_PATH: '/dev/sda1',
     HV_KERNEL_ARGS: 'ro',
+    HV_MIGRATION_PORT: 8002,
     },
   HT_XEN_HVM: {
     HV_BOOT_ORDER: "cd",
@@ -619,6 +622,7 @@ HVC_DEFAULTS = {
     HV_PAE: True,
     HV_KERNEL_PATH: "/usr/lib/xen/boot/hvmloader",
     HV_DEVICE_MODEL: "/usr/lib/xen/bin/qemu-dm",
+    HV_MIGRATION_PORT: 8002,
     },
   HT_KVM: {
     HV_KERNEL_PATH: "/boot/vmlinuz-2.6-kvmU",
@@ -637,6 +641,7 @@ HVC_DEFAULTS = {
     HV_NIC_TYPE: HT_NIC_PARAVIRTUAL,
     HV_DISK_TYPE: HT_DISK_PARAVIRTUAL,
     HV_USB_MOUSE: '',
+    HV_MIGRATION_PORT: _autoconf.KVM_MIGRATION_PORT,
     },
   HT_FAKE: {
     },
diff --git a/lib/hypervisor/hv_base.py b/lib/hypervisor/hv_base.py
index 45316e0bc..fbac820d7 100644
--- a/lib/hypervisor/hv_base.py
+++ b/lib/hypervisor/hv_base.py
@@ -62,6 +62,8 @@ REQ_FILE_CHECK = (True, ) + _FILE_CHECK
 OPT_FILE_CHECK = (False, ) + _FILE_CHECK
 REQ_DIR_CHECK = (True, ) + _DIR_CHECK
 OPT_DIR_CHECK = (False, ) + _DIR_CHECK
+NET_PORT_CHECK = (True, lambda x: x > 0 and x < 65535, "invalid port number",
+                  None, None)
 
 # no checks at all
 NO_CHECK = (False, None, None, None, None)
diff --git a/lib/hypervisor/hv_kvm.py b/lib/hypervisor/hv_kvm.py
index 118adcbc0..6da5bd594 100644
--- a/lib/hypervisor/hv_kvm.py
+++ b/lib/hypervisor/hv_kvm.py
@@ -72,6 +72,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
       hv_base.ParamInSet(True, constants.HT_KVM_VALID_DISK_TYPES),
     constants.HV_USB_MOUSE:
       hv_base.ParamInSet(False, constants.HT_KVM_VALID_MOUSE_TYPES),
+    constants.HV_MIGRATION_PORT: hv_base.NET_PORT_CHECK,
     }
 
   _MIGRATION_STATUS_RE = re.compile('Migration\s+status:\s+(\w+)',
@@ -556,8 +557,8 @@ class KVMHypervisor(hv_base.BaseHypervisor):
     # to shutdown and restart.
     pidfile, pid, alive = self._InstancePidAlive(instance.name)
     if not alive:
-      raise errors.HypervisorError("Failed to reboot instance %s: not running" %
-                                             (instance.name))
+      raise errors.HypervisorError("Failed to reboot instance %s:"
+                                   " not running" % instance.name)
     # StopInstance will delete the saved KVM runtime so:
     # ...first load it...
     kvm_runtime = self._LoadKVMRuntime(instance)
diff --git a/lib/hypervisor/hv_xen.py b/lib/hypervisor/hv_xen.py
index cb194f766..5a4eb6462 100644
--- a/lib/hypervisor/hv_xen.py
+++ b/lib/hypervisor/hv_xen.py
@@ -445,6 +445,7 @@ class XenPvmHypervisor(XenHypervisor):
     constants.HV_INITRD_PATH: hv_base.OPT_FILE_CHECK,
     constants.HV_ROOT_PATH: hv_base.REQUIRED_CHECK,
     constants.HV_KERNEL_ARGS: hv_base.NO_CHECK,
+    constants.HV_MIGRATION_PORT: hv_base.NET_PORT_CHECK,
     }
 
   @classmethod
@@ -542,6 +543,7 @@ class XenHvmHypervisor(XenHypervisor):
     constants.HV_KERNEL_PATH: hv_base.REQ_FILE_CHECK,
     constants.HV_DEVICE_MODEL: hv_base.REQ_FILE_CHECK,
     constants.HV_VNC_PASSWORD_FILE: hv_base.REQ_FILE_CHECK,
+    constants.HV_MIGRATION_PORT: hv_base.NET_PORT_CHECK,
     }
 
   @classmethod
diff --git a/man/gnt-instance.sgml b/man/gnt-instance.sgml
index a40452138..61bfdc095 100644
--- a/man/gnt-instance.sgml
+++ b/man/gnt-instance.sgml
@@ -504,7 +504,23 @@
                 emulate a serial console for the instance.</simpara>
               </listitem>
             </varlistentry>
+
+            <varlistentry>
+              <term>migration_port</term>
+              <listitem>
+                <simpara>Valid for the Xen PVM and KVM hypervisors.</simpara>
+
+                <para>
+                  This options specifies the TCP port to use for
+                  live-migration. Note that this shouldn't (usually)
+                  be changed at the instance level, but only at
+                  cluster-level.
+                </para>
+              </listitem>
+            </varlistentry>
+
           </variablelist>
+
         </para>
 
         <para>
-- 
GitLab