libxl: libxl_domain_restore: Put fd back to blocking mode
authorKeir Fraser <keir.fraser@citrix.com>
Mon, 12 Apr 2010 16:40:06 +0000 (17:40 +0100)
committerKeir Fraser <keir.fraser@citrix.com>
Mon, 12 Apr 2010 16:40:06 +0000 (17:40 +0100)
libxl_domain_restore calls, indirectly, xc_domain_restore.  The
latter, when doing a live migration, sets the fd from blocking mode
(which it must be on entry, or things go wrong) to nonblocking mode
and leaves it this way.  Arguably this is a bug in libxc, but to avoid
disrupting any callers we fix it in libxl.

So libxl_domain_restore now puts the fd back into blocking mode
before returning.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
tools/libxl/libxl.c

index 46a42a5d205d0aabb823f291343250bca8fef8d3..87a51fa898d6640592722fb533f503873de8d497 100644 (file)
@@ -221,7 +221,7 @@ int libxl_domain_restore(struct libxl_ctx *ctx, libxl_domain_build_info *info,
                          libxl_device_model_info *dm_info)
 {
     char **vments = NULL, **localents = NULL;
-    int i, ret;
+    int i, ret, esave, flags;
 
     ret = build_pre(ctx, domid, info, state);
     if (ret) goto out;
@@ -259,6 +259,19 @@ int libxl_domain_restore(struct libxl_ctx *ctx, libxl_domain_build_info *info,
     else
         dm_info->saved_state = NULL;
 out:
+    esave = errno;
+
+    flags = fcntl(fd, F_GETFL);
+    if (flags == -1) {
+        XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "unable to get flags on restore fd");
+    } else {
+        flags &= ~O_NONBLOCK;
+        if (fcntl(fd, F_SETFL, flags) == -1)
+            XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "unable to put restore fd"
+                         " back to blocking mode");
+    }
+
+    errno = esave;
     return ret;
 }