libxl: Reset toolstack_save file position in libxl
authorJason Andryuk <andryuk@aero.org>
Mon, 19 May 2014 18:36:37 +0000 (14:36 -0400)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Thu, 22 May 2014 15:35:22 +0000 (16:35 +0100)
toolstack_save data is written to a temporary file in libxl and read
back in libxl-save-helper.  The file position must be reset prior to
reading the file, which is done in libxl-save-helper with lseek.

lseek is unsupported for pipes and sockets, so a wrapper passing such an
fd to libxl-save-helper fails the lseek.  Moving the lseek to libxl
avoids the error, allowing the save to continue.

Signed-off-by: Jason Andryuk <andryuk@aero.org>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/libxl/libxl_save_callout.c
tools/libxl/libxl_save_helper.c

index e3bda8f812b72511d36d2a273679754d84562ade..c35da4dfed2e21718874f67d897d240236db8e8e 100644 (file)
@@ -105,6 +105,10 @@ void libxl__xc_domain_save(libxl__egc *egc, libxl__domain_suspend_state *dss,
                                 toolstack_data_buf, toolstack_data_len,
                                 "toolstack data tmpfile", 0);
         if (r) { rc = ERROR_FAIL; goto out; }
+
+        /* file position must be reset before passing to libxl-save-helper. */
+        r = lseek(toolstack_data_fd, 0, SEEK_SET);
+        if (r) { rc = ERROR_FAIL; goto out; }
     }
 
     const unsigned long argnums[] = {
index c36314ca0a2f81cb7ef0e4001d837830c2f56f0d..b259bd0215ff3a5ffe7ef599cb77c765d0a61229 100644 (file)
@@ -163,10 +163,9 @@ static uint32_t toolstack_save_len;
 static int toolstack_save_cb(uint32_t domid, uint8_t **buf,
                              uint32_t *len, void *data)
 {
-    assert(toolstack_save_fd > 0);
+    int r;
 
-    int r = lseek(toolstack_save_fd, 0, SEEK_SET);
-    if (r) fail(errno,"rewind toolstack data tmpfile");
+    assert(toolstack_save_fd > 0);
 
     *buf = xmalloc(toolstack_save_len);
     r = read_exactly(toolstack_save_fd, *buf, toolstack_save_len);