Skip to contentSkip to conversation

xend: Receive error message of migration from destination server

PATCH New Masaki Kanno 1 participant 1 message Sep 14, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xend: Receive error message of migration from destination server

Hi,

The following error message was shown by xm migrate command. In fact, I caused the command error by intention. I prepared a destination server where free memory was insufficient, and then I tried to migrate a VM to the destination server. As I had expected, the command error occurred. However the error message was different from my expectation. I would like to show an error message from the destination server if an error occurred on the destination server.

# xm migrate --live vm3 bx339
Error: (107, 'Transport endpoint is not connected')
Usage: xm migrate <Domain> <Host>

Migrate a domain to another machine.

Options:

-h, --help Print this help.
-l, --live Use live migration.
-p=portnum, --port=portnum
Use specified port for migration.
-n=nodenum, --node=nodenum
Use specified NUMA node on target.
-s, --ssl Use ssl connection for migration.

If a destination server sends an error message, this patch shows the error message. For example, the following error message is shown if free memory of the destination server is insufficient.

# xm migrate --live vm3 bx339
Error: I need 262144 KiB, but dom0_min_mem is 716800 and shrinking to 
716800 KiB would leave only 50368 KiB free. (from bx339)
Usage: xm migrate <Domain> <Host>

Migrate a domain to another machine.

Options:

-h, --help Print this help.
-l, --live Use live migration.
-p=portnum, --port=portnum
Use specified port for migration.
-n=nodenum, --node=nodenum
Use specified NUMA node on target.
-s, --ssl Use ssl connection for migration.

Best regards,
Kan

tools/python/xen/xend/XendDomain.py +67 -6
diff -r d2a32e24fe50 tools/python/xen/xend/XendDomain.py
@@ -28,6 +28,7 @@
 import socket
 import tempfile
 import threading
+import re
 
 import xen.lowlevel.xc
 
@@ -1350,10 +1351,40 @@
                              args=(sock, p2cread)).start()
 
             try:
-                XendCheckpoint.save(p2cwrite, dominfo, True, live, dst,
-                                    node=node)
+                try:
+                    XendCheckpoint.save(p2cwrite, dominfo, True, live, dst,
+                                        node=node)
+                except Exception, ex:
+                    m_dsterr = None
+                    try:
+                        sock.settimeout(3.0)
+                        dsterr = sock.recv(1024)
+                        sock.settimeout(None)
+                        if dsterr:
+                            # See [email protected]. If an error occurred
+                            # in a destination side, an error message with the
+                            # following form is returned from the destination
+                            # side.
+                            m_dsterr = \
+                                re.match(r"^\(err\s\(type\s(.+)\)\s\(value\s'(.+)'\)\)", dsterr)
+                    except:
+                        # Probably socket.timeout exception occurred.
+                        # Ignore the exception because it has nothing to do with
+                        # an exception of XendCheckpoint.save.
+                        pass
+
+                    if m_dsterr:
+                        raise XendError("%s (from %s)" % (m_dsterr.group(2), dst))
+                    raise
             finally:
-                sock.shutdown(2)
+                try:
+                    sock.shutdown(2)
+                except:
+                    # Probably the socket is already disconnected by sock.close
+                    # in the destination side.
+                    # Ignore the exception because it has nothing to do with
+                    # an exception of XendCheckpoint.save.
+                    pass
                 sock.close()
 
             os.close(p2cread)
@@ -1376,10 +1407,40 @@
                 raise XendError("can't connect: %s" % err)
 
             try:
-                XendCheckpoint.save(sock.fileno(), dominfo, True, live,
-                                    dst, node=node)
+                try:
+                    XendCheckpoint.save(sock.fileno(), dominfo, True, live,
+                                        dst, node=node)
+                except Exception, ex:
+                    m_dsterr = None
+                    try:
+                        sock.settimeout(3.0)
+                        dsterr = sock.recv(1024)
+                        sock.settimeout(None)
+                        if dsterr:
+                            # See [email protected]. If an error occurred
+                            # in a destination side, an error message with the
+                            # following form is returned from the destination
+                            # side.
+                            m_dsterr = \
+                                re.match(r"^\(err\s\(type\s(.+)\)\s\(value\s'(.+)'\)\)", dsterr)
+                    except:
+                        # Probably socket.timeout exception occurred.
+                        # Ignore the exception because it has nothing to do with
+                        # an exception of XendCheckpoint.save.
+                        pass
+
+                    if m_dsterr:
+                        raise XendError("%s (from %s)" % (m_dsterr.group(2), dst))
+                    raise
             finally:
-                sock.shutdown(2)
+                try:
+                    sock.shutdown(2)
+                except:
+                    # Probably the socket is already disconnected by sock.close
+                    # in the destination side.
+                    # Ignore the exception because it has nothing to do with
+                    # an exception of XendCheckpoint.save.
+                    pass
                 sock.close()
 
     def domain_save(self, domid, dst, checkpoint=False):

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel