Skip to contentSkip to conversation

tools/libxc: perpare xc_domain_save for upcoming changes

PATCH In review Olaf Hering 2 participants 3 messages Feb 18, 2013 – Feb 19, 2013 Arm/actions semi architecture

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/libxc: perpare xc_domain_save for upcoming changes

# HG changeset patch
# User Olaf Hering <[email protected]>
# Date 1361218116 -3600
# Node ID b096442271cf6a0d12510b4ee95d251f3dd63ea9 # Parent 6e66717b75a9f3797b43b73ea6c328a9cb44f9f1 tools/libxc: perpare xc_domain_save for upcoming changes

An upcoming patch will pass min_remaining to xc_domain_save. Because such a will be an API change, take the opportunity to change the API so that it will be easier to pass more options in the future.

- remove the hvm parameter, its already in flags XCFLAGS_HVM
- move flags, max_iters, max_factor and vm_generation_addr into a new struct xc_domain_save_props
- bump SONAME due to the incompatible change

tools/libxc/Makefile +1 -1
diff -r 6e66717b75a9 -r b096442271cf tools/libxc/Makefile
@@ -1,7 +1,7 @@
 XEN_ROOT = $(CURDIR)/../..
 include $(XEN_ROOT)/tools/Rules.mk
 
-MAJOR    = 4.2
+MAJOR    = 4.3
 MINOR    = 0
 
 CTRL_SRCS-y       :=
tools/libxc/xc_domain_save.c +9 -7
diff -r 6e66717b75a9 -r b096442271cf tools/libxc/xc_domain_save.c
@@ -793,17 +793,19 @@ static int save_tsc_info(xc_interface *x
     return 0;
 }
 
-int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iters,
-                   uint32_t max_factor, uint32_t flags,
-                   struct save_callbacks* callbacks, int hvm,
-                   unsigned long vm_generationid_addr)
+int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom,
+                   struct xc_domain_save_props *props,
+                   struct save_callbacks *callbacks)
 {
     xc_dominfo_t info;
     DECLARE_DOMCTL;
 
+    uint32_t max_iters, max_factor;
+    uint32_t flags = props->flags;
     int rc = 1, frc, i, j, last_iter = 0, iter = 0;
     int live  = (flags & XCFLAGS_LIVE);
     int debug = (flags & XCFLAGS_DEBUG);
+    int hvm = (flags & XCFLAGS_HVM);
     int superpages = !!hvm;
     int race = 0, sent_last_iter, skip_this_iter = 0;
     unsigned int sent_this_iter = 0;
@@ -902,8 +904,8 @@ int xc_domain_save(xc_interface *xch, in
     memset(ctx, 0, sizeof(*ctx));
 
     /* If no explicit control parameters given, use defaults */
-    max_iters  = max_iters  ? : DEF_MAX_ITERS;
-    max_factor = max_factor ? : DEF_MAX_FACTOR;
+    max_iters  = props->max_iters  ? : DEF_MAX_ITERS;
+    max_factor = props->max_factor ? : DEF_MAX_FACTOR;
 
     if ( !get_platform_info(xch, dom,
                             &ctx->max_mfn, &ctx->hvirt_start, &ctx->pt_levels, &dinfo->guest_width) )
@@ -1623,7 +1625,7 @@ int xc_domain_save(xc_interface *xch, in
         } chunk = { 0, };
 
         chunk.id = XC_SAVE_ID_HVM_GENERATION_ID_ADDR;
-        chunk.data = vm_generationid_addr;
+        chunk.data = props->vm_generationid_addr;
 
         if ( (chunk.data != 0) &&
              wrexact(io_fd, &chunk, sizeof(chunk)) )
tools/libxc/xc_nomigrate.c +3 -4
diff -r 6e66717b75a9 -r b096442271cf tools/libxc/xc_nomigrate.c
@@ -21,10 +21,9 @@
 #include <xenctrl.h>
 #include <xenguest.h>
 
-int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iters,
-                   uint32_t max_factor, uint32_t flags,
-                   struct save_callbacks* callbacks, int hvm,
-                   unsigned long vm_generationid_addr)
+int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom,
+                   struct xc_domain_save_props *props,
+                   struct save_callbacks *callbacks)
 {
     errno = ENOSYS;
     return -1;
tools/libxc/xenguest.h +10 -5
diff -r 6e66717b75a9 -r b096442271cf tools/libxc/xenguest.h
@@ -76,6 +76,13 @@ struct save_callbacks {
     void* data;
 };
 
+struct xc_domain_save_props {
+    uint32_t max_iters;
+    uint32_t max_factor;
+    uint32_t flags; /* XCFLAGS_xxx */
+    unsigned long vm_generationid_addr;
+};
+
 /**
  * This function will save a running domain.
  *
@@ -84,11 +91,9 @@ struct save_callbacks {
  * @parm dom the id of the domain
  * @return 0 on success, -1 on failure
  */
-int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iters,
-                   uint32_t max_factor, uint32_t flags /* XCFLAGS_xxx */,
-                   struct save_callbacks* callbacks, int hvm,
-                   unsigned long vm_generationid_addr);
-
+int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom,
+                   struct xc_domain_save_props *props,
+                   struct save_callbacks *callbacks);
 
 /* callbacks provided by xc_domain_restore */
 struct restore_callbacks {
tools/libxl/libxl_save_helper.c +12 -13
diff -r 6e66717b75a9 -r b096442271cf tools/libxl/libxl_save_helper.c
@@ -216,17 +216,17 @@ int main(int argc, char **argv)
     assert(mode);
 
     if (!strcmp(mode,"--save-domain")) {
-
-        int io_fd =                atoi(NEXTARG);
-        uint32_t dom =             strtoul(NEXTARG,0,10);
-        uint32_t max_iters =       strtoul(NEXTARG,0,10);
-        uint32_t max_factor =      strtoul(NEXTARG,0,10);
-        uint32_t flags =           strtoul(NEXTARG,0,10);
-        int hvm =                  atoi(NEXTARG);
-        unsigned long genidad =    strtoul(NEXTARG,0,10);
-        toolstack_save_fd  =       atoi(NEXTARG);
-        toolstack_save_len =       strtoul(NEXTARG,0,10);
-        unsigned cbflags =         strtoul(NEXTARG,0,10);
+        struct xc_domain_save_props props = { };
+        unsigned cbflags;
+        int io_fd =                  atoi(NEXTARG);
+        uint32_t dom =               strtoul(NEXTARG,0,10);
+        props.max_iters =            strtoul(NEXTARG,0,10);
+        props.max_factor =           strtoul(NEXTARG,0,10);
+        props.flags =                strtoul(NEXTARG,0,10);
+        props.vm_generationid_addr = strtoul(NEXTARG,0,10);
+        toolstack_save_fd  =         atoi(NEXTARG);
+        toolstack_save_len =         strtoul(NEXTARG,0,10);
+        cbflags =                    strtoul(NEXTARG,0,10);
         assert(!*++argv);
 
         if (toolstack_save_fd >= 0)
@@ -235,8 +235,7 @@ int main(int argc, char **argv)
         helper_setcallbacks_save(&helper_save_callbacks, cbflags);
 
         startup("save");
-        r = xc_domain_save(xch, io_fd, dom, max_iters, max_factor, flags,
-                           &helper_save_callbacks, hvm, genidad);
+        r = xc_domain_save(xch, io_fd, dom, &props, &helper_save_callbacks);
         complete(r);
 
     } else if (!strcmp(mode,"--restore-domain")) {
tools/python/xen/lowlevel/checkpoint/libcheckpoint.c +5 -9
diff -r 6e66717b75a9 -r b096442271cf tools/python/xen/lowlevel/checkpoint/libcheckpoint.c
@@ -173,9 +173,8 @@ int checkpoint_start(checkpoint_state* s
 		     struct save_callbacks* callbacks,
 		     unsigned int remus_flags)
 {
+    struct xc_domain_save_props props = { .flags = XCFLAGS_LIVE };
     int hvm, rc;
-    int flags = XCFLAGS_LIVE;
-    unsigned long vm_generationid_addr;
 
     if (!s->domid) {
        s->errstr = "checkpoint state not opened";
@@ -192,22 +191,19 @@ int checkpoint_start(checkpoint_state* s
        sprintf(path, "/local/domain/%u/hvmloader/generation-id-address", s->domid);
        addr = xs_read(s->xsh, XBT_NULL, path, NULL);
 
-       vm_generationid_addr = (addr) ? strtoul(addr, NULL, 0) : 0;
+       props.vm_generationid_addr = (addr) ? strtoul(addr, NULL, 0) : 0;
        free(addr);
 
-       flags |= XCFLAGS_HVM;
+       props.flags |= XCFLAGS_HVM;
        if (switch_qemu_logdirty(s, 1))
            return -1;
-    } else {
-       vm_generationid_addr = 0;
     }
     if (remus_flags & CHECKPOINT_FLAGS_COMPRESSION)
-      flags |= XCFLAGS_CHECKPOINT_COMPRESS;
+      props.flags |= XCFLAGS_CHECKPOINT_COMPRESS;
 
     callbacks->switch_qemu_logdirty = noop_switch_logdirty;
 
-    rc = xc_domain_save(s->xch, fd, s->domid, 0, 0, flags, callbacks, hvm,
-                        vm_generationid_addr);
+    rc = xc_domain_save(s->xch, fd, s->domid, &props, callbacks);
 
     if (hvm)
        switch_qemu_logdirty(s, 0);
tools/xcutils/xc_save.c +6 -5
diff -r 6e66717b75a9 -r b096442271cf tools/xcutils/xc_save.c
@@ -175,7 +175,8 @@ int
 main(int argc, char **argv)
 {
     xc_interface *xch;
-    unsigned int maxit, max_f, lflags;
+    struct xc_domain_save_props props = { };
+    unsigned int lflags;
     int io_fd, ret, port;
     struct save_callbacks callbacks;
     xentoollog_level lvl;
@@ -186,10 +187,11 @@ main(int argc, char **argv)
 
     io_fd = atoi(argv[1]);
     si.domid = atoi(argv[2]);
-    maxit = atoi(argv[3]);
-    max_f = atoi(argv[4]);
+    props.max_iters = atoi(argv[3]);
+    props.max_factor = atoi(argv[4]);
     si.flags = atoi(argv[5]);
 
+    props.flags = si.flags;
     si.suspend_evtchn = -1;
 
     lvl = si.flags & XCFLAGS_DEBUG ? XTL_DEBUG: XTL_DETAIL;
@@ -221,8 +223,7 @@ main(int argc, char **argv)
     memset(&callbacks, 0, sizeof(callbacks));
     callbacks.suspend = suspend;
     callbacks.switch_qemu_logdirty = switch_qemu_logdirty;
-    ret = xc_domain_save(si.xch, io_fd, si.domid, maxit, max_f, si.flags, 
-                         &callbacks, !!(si.flags & XCFLAGS_HVM), 0);
+    ret = xc_domain_save(si.xch, io_fd, si.domid, &props, &callbacks);
 
     if (si.suspend_evtchn > 0)
 	 xc_suspend_evtchn_release(si.xch, si.xce, si.domid, si.suspend_evtchn);
#1 lore raw

Olaf Hering writes ("[Xen-devel] [PATCH] tools/libxc: perpare xc_domain_save for upcoming changes"):

Quoted 5 lines

tools/libxc: perpare xc_domain_save for upcoming changes

An upcoming patch will pass min_remaining to xc_domain_save. Because such a will be an API change, take the opportunity to change the API so that it will be easier to pass more options in the future.

I'm not sure why changing the large number of arguments to xc_domain_save to a struct is an improvement, even given that you are proposing to add one. Can you explain further ?

Thanks,
Ian.

#2 lore raw
Quoted 10 lines · Ian Jackson

Olaf Hering writes ("[Xen-devel] [PATCH] tools/libxc: perpare xc_domain_save for upcoming changes"):

Quoted 5 lines

tools/libxc: perpare xc_domain_save for upcoming changes

An upcoming patch will pass min_remaining to xc_domain_save. Because such a will be an API change, take the opportunity to change the API so that it will be easier to pass more options in the future.

I'm not sure why changing the large number of arguments to xc_domain_save to a struct is an improvement, even given that you are proposing to add one. Can you explain further ?

If new parameters will be passed into xc_domain_save it will change the API every time. If instead such parameters are stuffed into a struct the API will not change for callers, if the new struct member is really optional.

I'm fine with adding yet another parameter to xc_domain_save, given that there are appearently no external callers. libvirt uses libxl.

Olaf