From 6613661ab68003b6a99a4e361733354f18d6f3eb Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Tue, 2 Aug 2011 10:12:05 +0200
Subject: [PATCH] Instance transfer: export component name to backend

This modifies the RPC layer to export the component name too to the
backend, so that it can be used in log files and messages.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
---
 lib/backend.py          |  8 ++++++--
 lib/masterd/instance.py |  6 +++---
 lib/rpc.py              | 14 ++++++++++----
 lib/server/noded.py     |  8 ++++----
 4 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/lib/backend.py b/lib/backend.py
index 89dbe46cd..7728bb46f 100644
--- a/lib/backend.py
+++ b/lib/backend.py
@@ -2964,7 +2964,8 @@ def _CreateImportExportStatusDir(prefix):
                                   (prefix, utils.TimestampForFilename())))
 
 
-def StartImportExportDaemon(mode, opts, host, port, instance, ieio, ieioargs):
+def StartImportExportDaemon(mode, opts, host, port, instance, component,
+                            ieio, ieioargs):
   """Starts an import or export daemon.
 
   @param mode: Import/output mode
@@ -2976,6 +2977,9 @@ def StartImportExportDaemon(mode, opts, host, port, instance, ieio, ieioargs):
   @param port: Remote port for export (None for import)
   @type instance: L{objects.Instance}
   @param instance: Instance object
+  @type component: string
+  @param component: which part of the instance is transferred now,
+      e.g. 'disk/0'
   @param ieio: Input/output type
   @param ieioargs: Input/output arguments
 
@@ -3015,7 +3019,7 @@ def StartImportExportDaemon(mode, opts, host, port, instance, ieio, ieioargs):
     if not os.path.exists(i):
       _Fail("File '%s' does not exist" % i)
 
-  status_dir = _CreateImportExportStatusDir(prefix)
+  status_dir = _CreateImportExportStatusDir("%s-%s" % (prefix, component))
   try:
     status_file = utils.PathJoin(status_dir, _IES_STATUS_FILE)
     pid_file = utils.PathJoin(status_dir, _IES_PID_FILE)
diff --git a/lib/masterd/instance.py b/lib/masterd/instance.py
index f7c721a43..2597887f7 100644
--- a/lib/masterd/instance.py
+++ b/lib/masterd/instance.py
@@ -534,7 +534,7 @@ class DiskImport(_DiskImportExportBase):
 
     """
     return self._lu.rpc.call_import_start(self.node_name, self._opts,
-                                          self._instance,
+                                          self._instance, self._component,
                                           self._dest, self._dest_args)
 
   def CheckListening(self):
@@ -620,8 +620,8 @@ class DiskExport(_DiskImportExportBase):
     """
     return self._lu.rpc.call_export_start(self.node_name, self._opts,
                                           self._dest_host, self._dest_port,
-                                          self._instance, self._source,
-                                          self._source_args)
+                                          self._instance, self._component,
+                                          self._source, self._source_args)
 
   def CheckListening(self):
     """Checks whether the daemon is listening.
diff --git a/lib/rpc.py b/lib/rpc.py
index 6205dcfac..c93c16d2b 100644
--- a/lib/rpc.py
+++ b/lib/rpc.py
@@ -1498,7 +1498,8 @@ class RpcRunner(object):
     return self._SingleNodeCall(node, "x509_cert_remove", [name])
 
   @_RpcTimeout(_TMO_NORMAL)
-  def call_import_start(self, node, opts, instance, dest, dest_args):
+  def call_import_start(self, node, opts, instance, component,
+                        dest, dest_args):
     """Starts a listener for an import.
 
     This is a single-node call.
@@ -1507,16 +1508,18 @@ class RpcRunner(object):
     @param node: Node name
     @type instance: C{objects.Instance}
     @param instance: Instance object
+    @type component: string
+    @param component: which part of the instance is being imported
 
     """
     return self._SingleNodeCall(node, "import_start",
                                 [opts.ToDict(),
-                                 self._InstDict(instance), dest,
+                                 self._InstDict(instance), component, dest,
                                  _EncodeImportExportIO(dest, dest_args)])
 
   @_RpcTimeout(_TMO_NORMAL)
   def call_export_start(self, node, opts, host, port,
-                        instance, source, source_args):
+                        instance, component, source, source_args):
     """Starts an export daemon.
 
     This is a single-node call.
@@ -1525,11 +1528,14 @@ class RpcRunner(object):
     @param node: Node name
     @type instance: C{objects.Instance}
     @param instance: Instance object
+    @type component: string
+    @param component: which part of the instance is being imported
 
     """
     return self._SingleNodeCall(node, "export_start",
                                 [opts.ToDict(), host, port,
-                                 self._InstDict(instance), source,
+                                 self._InstDict(instance),
+                                 component, source,
                                  _EncodeImportExportIO(source, source_args)])
 
   @_RpcTimeout(_TMO_FAST)
diff --git a/lib/server/noded.py b/lib/server/noded.py
index 683f7015c..527b261c4 100644
--- a/lib/server/noded.py
+++ b/lib/server/noded.py
@@ -919,14 +919,14 @@ class NodeHttpServer(http.server.HttpServer):
     """Starts an import daemon.
 
     """
-    (opts_s, instance, dest, dest_args) = params
+    (opts_s, instance, component, dest, dest_args) = params
 
     opts = objects.ImportExportOptions.FromDict(opts_s)
 
     return backend.StartImportExportDaemon(constants.IEM_IMPORT, opts,
                                            None, None,
                                            objects.Instance.FromDict(instance),
-                                           dest,
+                                           component, dest,
                                            _DecodeImportExportIO(dest,
                                                                  dest_args))
 
@@ -935,14 +935,14 @@ class NodeHttpServer(http.server.HttpServer):
     """Starts an export daemon.
 
     """
-    (opts_s, host, port, instance, source, source_args) = params
+    (opts_s, host, port, instance, component, source, source_args) = params
 
     opts = objects.ImportExportOptions.FromDict(opts_s)
 
     return backend.StartImportExportDaemon(constants.IEM_EXPORT, opts,
                                            host, port,
                                            objects.Instance.FromDict(instance),
-                                           source,
+                                           component, source,
                                            _DecodeImportExportIO(source,
                                                                  source_args))
 
-- 
GitLab