WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel][PATCH]improve suspend_evtchn lock processing

To: <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel][PATCH]improve suspend_evtchn lock processing
From: "Chun Yan Liu" <cyliu@xxxxxxxxxx>
Date: Wed, 24 Nov 2010 20:10:18 -0700
Delivery-date: Wed, 24 Nov 2010 19:26:41 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
While doing migration, sometimes found suspend lock file was not unlinked in previous operations, then there is an obsolete lock file in place, which causes the current and later migration cannot get lock. That happens seldomly but do happen.

After checking the source code, I found there are some places that potentially cause lock file unlinked, including:
1) in lock_suspend_event() function, when write_exact fails, it doesn't remove the lock file and later there is no chance to remove it.
2) in xc_suspend_evtchn_init() function, in "cleanup" block, I can't see any reason for checking if(suspend_evtchn != -1), if suspend_evtchn=-1, it doesn't remove the lock file and later there is no chance to remove it.

These places have been modified in the following patch, and, in addition, a function clean_obsolete_lock() is added to clean an invalid lock file which is unlinked from previous operations for any kind of reason (e.g., kill the process).

Any comments?


Signed-off-by Chunyan Liu <cyliu@xxxxxxxxxx>

diff -r 3c4c3d48a835 tools/libxc/xc_suspend.c
--- a/tools/libxc/xc_suspend.c    Thu Aug 26 11:16:56 2010 +0100
+++ b/tools/libxc/xc_suspend.c    Thu Nov 25 18:44:35 2010 +0800
@@ -16,8 +16,40 @@
 
 #include "xc_private.h"
 #include "xenguest.h"
+#include <signal.h>
 
 #define SUSPEND_LOCK_FILE "/var/lib/xen/suspend_evtchn"
+/* cleanup obsolete suspend lock file which is unlinked for any reason,
+so that current process can get lock */
+static void clean_obsolete_lock(int domid)
+{
+    int fd, pid, n;
+    char buf[128];
+    char suspend_file[256];
+
+    snprintf(suspend_file, sizeof(suspend_file), "%s_%d_lock.d",
+        SUSPEND_LOCK_FILE, domid);
+    fd = open(suspend_file, O_RDWR);
+
+    if (fd < 0)
+        return;
+
+    n = read(fd, buf, 127);
+
+    close(fd);
+
+    if (n > 0)
+    {
+        sscanf(buf, "%d", &pid);
+        /* pid does not exist, this lock file is obsolete, just delete it */
+        if ( kill(pid,0) )
+        {
+            unlink(suspend_file);
+            return;
+        }
+    }
+}
+
 static int lock_suspend_event(xc_interface *xch, int domid)
 {
     int fd, rc;
@@ -27,6 +59,7 @@
 
     snprintf(suspend_file, sizeof(suspend_file), "%s_%d_lock.d",
         SUSPEND_LOCK_FILE, domid);
+    clean_obsolete_lock(domid);
     mask = umask(022);
     fd = open(suspend_file, O_CREAT | O_EXCL | O_RDWR, 0666);
     if (fd < 0)
@@ -41,6 +74,9 @@
     rc = write_exact(fd, buf, strlen(buf));
     close(fd);
 
+    if(rc)
+    unlink(suspend_file);
+
     return rc;
 }
 
@@ -127,8 +163,7 @@
     return suspend_evtchn;
 
 cleanup:
-    if (suspend_evtchn != -1)
-        xc_suspend_evtchn_release(xch, xce, domid, suspend_evtchn);
+    xc_suspend_evtchn_release(xch, xce, domid, suspend_evtchn);
 
     return -1;
 }

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
<Prev in Thread] Current Thread [Next in Thread>