[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 1 of 2] libxc: Pass the save_ctx struct to more functions



This is in preparation for a patch that will print the domain ID
in the error messages.

Signed-off-by: George Dunlap <george.dunlap@xxxxxxxxxxxxx>

diff --git a/tools/libxc/xc_domain_save.c b/tools/libxc/xc_domain_save.c
--- a/tools/libxc/xc_domain_save.c
+++ b/tools/libxc/xc_domain_save.c
@@ -125,7 +125,8 @@ static int noncached_write(xc_interface 
     return rc;
 }
 
-static int outbuf_init(xc_interface *xch, struct outbuf* ob, size_t size)
+static int outbuf_init(xc_interface *xch, struct save_ctx *ctx,
+                       struct outbuf* ob, size_t size)
 {
     memset(ob, 0, sizeof(*ob));
 
@@ -139,7 +140,7 @@ static int outbuf_init(xc_interface *xch
     return 0;
 }
 
-static inline int outbuf_write(xc_interface *xch,
+static inline int outbuf_write(xc_interface *xch, struct save_ctx *ctx,
                                struct outbuf* ob, void* buf, size_t len)
 {
     if ( len > ob->size - ob->pos ) {
@@ -154,7 +155,8 @@ static inline int outbuf_write(xc_interf
 }
 
 /* prep for nonblocking I/O */
-static int outbuf_flush(xc_interface *xch, struct outbuf* ob, int fd)
+static int outbuf_flush(xc_interface *xch, struct save_ctx *ctx,
+                        struct outbuf* ob, int fd)
 {
     int rc;
     int cur = 0;
@@ -180,45 +182,46 @@ static int outbuf_flush(xc_interface *xc
 }
 
 /* if there's no room in the buffer, flush it and try again. */
-static inline int outbuf_hardwrite(xc_interface *xch,
+static inline int outbuf_hardwrite(xc_interface *xch, struct save_ctx *ctx,
                                    struct outbuf* ob, int fd, void* buf,
                                    size_t len)
 {
     if ( !len )
         return 0;
 
-    if ( !outbuf_write(xch, ob, buf, len) )
+    if ( !outbuf_write(xch, ctx, ob, buf, len) )
         return 0;
 
-    if ( outbuf_flush(xch, ob, fd) < 0 )
+    if ( outbuf_flush(xch, ctx, ob, fd) < 0 )
         return -1;
 
-    return outbuf_write(xch, ob, buf, len);
+    return outbuf_write(xch, ctx, ob, buf, len);
 }
 
 /* start buffering output once we've reached checkpoint mode. */
-static inline int write_buffer(xc_interface *xch,
+static inline int write_buffer(xc_interface *xch, struct save_ctx *ctx,
                                int dobuf, struct outbuf* ob, int fd, void* buf,
                                size_t len)
 {
     if ( dobuf )
-        return outbuf_hardwrite(xch, ob, fd, buf, len);
+        return outbuf_hardwrite(xch, ctx, ob, fd, buf, len);
     else
         return write_exact(fd, buf, len);
 }
 
 /* like write_buffer for noncached, which returns number of bytes written */
-static inline int write_uncached(xc_interface *xch,
+static inline int write_uncached(xc_interface *xch, struct save_ctx *ctx,
                                    int dobuf, struct outbuf* ob, int fd,
                                    void* buf, size_t len)
 {
     if ( dobuf )
-        return outbuf_hardwrite(xch, ob, fd, buf, len) ? -1 : len;
+        return outbuf_hardwrite(xch, ctx, ob, fd, buf, len) ? -1 : len;
     else
         return noncached_write(xch, ob, fd, buf, len);
 }
 
-static int write_compressed(xc_interface *xch, comp_ctx *compress_ctx,
+static int write_compressed(xc_interface *xch, struct save_ctx *ctx,
+                            comp_ctx *compress_ctx,
                             int dobuf, struct outbuf* ob, int fd)
 {
     int rc = 0;
@@ -231,7 +234,7 @@ static int write_compressed(xc_interface
         /* check for available space (atleast 8k) */
         if ((ob->pos + header + XC_PAGE_SIZE * 2) > ob->size)
         {
-            if (outbuf_flush(xch, ob, fd) < 0)
+            if (outbuf_flush(xch, ctx, ob, fd) < 0)
             {
                 ERROR("Error when flushing outbuf intermediate");
                 return -1;
@@ -245,20 +248,20 @@ static int write_compressed(xc_interface
         if (!rc)
             return 0;
 
-        if (outbuf_hardwrite(xch, ob, fd, &marker, sizeof(marker)) < 0)
+        if (outbuf_hardwrite(xch, ctx, ob, fd, &marker, sizeof(marker)) < 0)
         {
             PERROR("Error when writing marker (errno %d)", errno);
             return -1;
         }
 
-        if (outbuf_hardwrite(xch, ob, fd, &compbuf_len, sizeof(compbuf_len)) < 
0)
+        if (outbuf_hardwrite(xch, ctx, ob, fd, &compbuf_len, 
sizeof(compbuf_len)) < 0)
         {
             PERROR("Error when writing compbuf_len (errno %d)", errno);
             return -1;
         }
 
         ob->pos += (size_t) compbuf_len;
-        if (!dobuf && outbuf_flush(xch, ob, fd) < 0)
+        if (!dobuf && outbuf_flush(xch, ctx, ob, fd) < 0)
         {
             ERROR("Error when writing compressed chunk");
             return -1;
@@ -273,7 +276,8 @@ struct time_stats {
     long long d0_cpu, d1_cpu;
 };
 
-static int print_stats(xc_interface *xch, uint32_t domid, int pages_sent,
+static int print_stats(xc_interface *xch, struct save_ctx *ctx,
+                       uint32_t domid, int pages_sent,
                        struct time_stats *last,
                        xc_shadow_op_stats_t *stats, int print)
 {
@@ -349,7 +353,8 @@ static int analysis_phase(xc_interface *
 }
 
 static int suspend_and_state(int (*suspend)(void*), void* data,
-                             xc_interface *xch, int io_fd, int dom,
+                             xc_interface *xch, struct save_ctx *ctx,
+                             int io_fd, int dom,
                              xc_dominfo_t *info)
 {
     if ( !(*suspend)(data) )
@@ -904,7 +909,7 @@ int xc_domain_save(xc_interface *xch, in
         return 1;
     }
 
-    outbuf_init(xch, &ob_pagebuf, OUTBUF_SIZE);
+    outbuf_init(xch, ctx, &ob_pagebuf, OUTBUF_SIZE);
 
     memset(ctx, 0, sizeof(*ctx));
 
@@ -984,7 +989,7 @@ int xc_domain_save(xc_interface *xch, in
     else
     {
         /* This is a non-live suspend. Suspend the domain .*/
-        if ( suspend_and_state(callbacks->suspend, callbacks->data, xch,
+        if ( suspend_and_state(callbacks->suspend, callbacks->data, xch, ctx,
                                io_fd, dom, &info) )
         {
             ERROR("Domain appears not to have suspended");
@@ -999,7 +1004,7 @@ int xc_domain_save(xc_interface *xch, in
             ERROR("Failed to create compression context");
             goto out;
         }
-        outbuf_init(xch, &ob_tailbuf, OUTBUF_SIZE/4);
+        outbuf_init(xch, ctx, &ob_tailbuf, OUTBUF_SIZE/4);
     }
 
     last_iter = !live;
@@ -1094,7 +1099,7 @@ int xc_domain_save(xc_interface *xch, in
         DPRINTF("Had %d unexplained entries in p2m table\n", err);
     }
 
-    print_stats(xch, dom, 0, &time_stats, &shadow_stats, 0);
+    print_stats(xch, ctx, dom, 0, &time_stats, &shadow_stats, 0);
 
     tmem_saved = xc_tmem_save(xch, dom, io_fd, live, XC_SAVE_ID_TMEM);
     if ( tmem_saved == -1 )
@@ -1110,9 +1115,9 @@ int xc_domain_save(xc_interface *xch, in
     }
 
   copypages:
-#define wrexact(fd, buf, len) write_buffer(xch, last_iter, ob, (fd), (buf), 
(len))
-#define wruncached(fd, live, buf, len) write_uncached(xch, last_iter, ob, 
(fd), (buf), (len))
-#define wrcompressed(fd) write_compressed(xch, compress_ctx, last_iter, ob, 
(fd))
+#define wrexact(fd, buf, len) write_buffer(xch, ctx, last_iter, ob, (fd), 
(buf), (len))
+#define wruncached(fd, live, buf, len) write_uncached(xch, ctx, last_iter, ob, 
(fd), (buf), (len))
+#define wrcompressed(fd) write_compressed(xch, ctx, compress_ctx, last_iter, 
ob, (fd))
 
     ob = &ob_pagebuf; /* Holds pfn_types, pages/compressed pages */
     /* Now write out each data page, canonicalising page tables as we go... */
@@ -1494,7 +1499,7 @@ int xc_domain_save(xc_interface *xch, in
 
         if ( last_iter )
         {
-            print_stats( xch, dom, sent_this_iter, &time_stats, &shadow_stats, 
1);
+            print_stats( xch, ctx, dom, sent_this_iter, &time_stats, 
&shadow_stats, 1);
 
             DPRINTF("Total pages sent= %ld (%.2fx)\n",
                     total_sent, ((float)total_sent)/dinfo->p2m_size );
@@ -1531,7 +1536,7 @@ int xc_domain_save(xc_interface *xch, in
                 last_iter = 1;
 
                 if ( suspend_and_state(callbacks->suspend, callbacks->data,
-                                       xch, io_fd, dom, &info) )
+                                       xch, ctx, io_fd, dom, &info) )
                 {
                     ERROR("Domain appears not to have suspended");
                     goto out;
@@ -1564,7 +1569,7 @@ int xc_domain_save(xc_interface *xch, in
 
             sent_last_iter = sent_this_iter;
 
-            print_stats(xch, dom, sent_this_iter, &time_stats, &shadow_stats, 
1);
+            print_stats(xch, ctx, dom, sent_this_iter, &time_stats, 
&shadow_stats, 1);
 
         }
     } /* end of infinite for loop */
@@ -2023,7 +2028,7 @@ int xc_domain_save(xc_interface *xch, in
     }
 
     /* Flush last write and discard cache for file. */
-    if ( outbuf_flush(xch, ob, io_fd) < 0 ) {
+    if ( outbuf_flush(xch, ctx, ob, io_fd) < 0 ) {
         PERROR("Error when flushing output buffer");
         rc = 1;
     }
@@ -2038,18 +2043,18 @@ int xc_domain_save(xc_interface *xch, in
         callbacks->checkpoint(callbacks->data) > 0)
     {
         /* reset stats timer */
-        print_stats(xch, dom, 0, &time_stats, &shadow_stats, 0);
+        print_stats(xch, ctx, dom, 0, &time_stats, &shadow_stats, 0);
 
         rc = 1;
         /* last_iter = 1; */
-        if ( suspend_and_state(callbacks->suspend, callbacks->data, xch,
+        if ( suspend_and_state(callbacks->suspend, callbacks->data, xch, ctx,
                                io_fd, dom, &info) )
         {
             ERROR("Domain appears not to have suspended");
             goto out;
         }
         DPRINTF("SUSPEND shinfo %08lx\n", info.shared_info_frame);
-        print_stats(xch, dom, 0, &time_stats, &shadow_stats, 1);
+        print_stats(xch, ctx, dom, 0, &time_stats, &shadow_stats, 1);
 
         if ( xc_shadow_control(xch, dom,
                                XEN_DOMCTL_SHADOW_OP_CLEAN, 
HYPERCALL_BUFFER(to_send),

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.