Skip to contentSkip to conversation

xl save but leave domain paused

PATCH In review Ian Murray 3 participants 5 messages Jul 2, 2013 – Jul 3, 2013

lore
Share & tools
lore

Ian Murray

author
#0 lore raw

PATCH 1/1 xl save but leave domain paused

New feature to allow xl save to leave a domain paused after its memory has been saved. This is to allow disk snapshots of domU to be taken that exactly correspond to the memory state at save time. Once the snapshot(s) have been taken or whatever, the domain can be unpaused in the usual manner.

Usage:
xl save -p <domid> <filespec>

---
 tools/libxl/xl_cmdimpl.c  |   16 ++++++++++++----
 tools/libxl/xl_cmdtable.c |    4 +++-
 2 files changed, 15 insertions(+), 5 deletions(-)
tools/libxl/xl_cmdimpl.c +12 -4
index 8a478ba..670620b 100644
@@ -3266,7 +3266,7 @@ static void save_domain_core_writeconfig(int fd, const char *source,
 }
 
 static int save_domain(uint32_t domid, const char *filename, int checkpoint,
-                const char *override_config_file)
+                int leavepaused, const char *override_config_file)
 {
     int fd;
     uint8_t *config_data;
@@ -3293,8 +3293,12 @@ static int save_domain(uint32_t domid, const char *filename, int checkpoint,
     if (rc < 0)
         fprintf(stderr, "Failed to save domain, resuming domain\n");
 
-    if (checkpoint || rc < 0)
+    if (leavepaused || checkpoint || rc < 0) {
+        if (leavepaused && !(rc < 0)) {
+            libxl_domain_pause(ctx, domid);
+        }
         libxl_domain_resume(ctx, domid, 1, 0);
+    }
     else
         libxl_domain_destroy(ctx, domid, 0);
 
@@ -3838,12 +3842,16 @@ int main_save(int argc, char **argv)
     const char *filename;
     const char *config_filename = NULL;
     int checkpoint = 0;
+    int leavepaused = 0;
     int opt;
 
-    SWITCH_FOREACH_OPT(opt, "c", NULL, "save", 2) {
+    SWITCH_FOREACH_OPT(opt, "cp", NULL, "save", 2) {
     case 'c':
         checkpoint = 1;
         break;
+    case 'p':
+        leavepaused = 1;
+        break;
     }
 
     if (argc-optind > 3) {
@@ -3856,7 +3864,7 @@ int main_save(int argc, char **argv)
     if ( argc - optind >= 3 )
         config_filename = argv[optind + 2];
 
-    save_domain(domid, filename, checkpoint, config_filename);
+    save_domain(domid, filename, checkpoint, leavepaused, config_filename);
     return 0;
 }
 
tools/libxl/xl_cmdtable.c +3 -1
index 44b42b0..c429cea 100644
@@ -142,7 +142,9 @@ struct cmd_spec cmd_table[] = {
       "Save a domain state to restore later",
       "[options] <Domain> <CheckpointFile> [<ConfigFile>]",
       "-h  Print this help.\n"
-      "-c  Leave domain running after creating the snapshot."
+      "-c  Leave domain running after creating the snapshot.\n"
+      "-p  Leave domain paused after creating the snapshot."
+
     },
     { "migrate",
       &main_migrate, 0, 1,
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 20 lines · Ian Murray

New feature to allow xl save to leave a domain paused after its memory has been saved. This is to allow disk snapshots of domU to be taken that exactly correspond to the memory state at save time. Once the snapshot(s) have been taken or whatever, the domain can be unpaused in the usual manner.

Usage:
xl save -p <domid> <filespec>

---
 tools/libxl/xl_cmdimpl.c  |   16 ++++++++++++----
 tools/libxl/xl_cmdtable.c |    4 +++-
 2 files changed, 15 insertions(+), 5 deletions(-)
tools/libxl/xl_cmdimpl.c +0 -0
index 8a478ba..670620b 100644

tools/libxl/xl_cmdimpl.c static void save_domain_core_writeconfig(int fd, const char *source, · line 3269

Quoted 5 lines
tools/libxl/xl_cmdimpl.c +1 -1
@@ -3266,7 +3266,7 @@ static void save_domain_core_writeconfig(int fd, const char *source,
 }
 
 static int save_domain(uint32_t domid, const char *filename, int checkpoint,
-                const char *override_config_file)
+                int leavepaused, const char *override_config_file)

#include <stdbool.h> and use bool rather than int. Also, re-align the second line arguments which was misaligned when the function was made static

Quoted 4 lines
tools/libxl/xl_cmdimpl.c +0 -0
 {
     int fd;
     uint8_t *config_data;

tools/libxl/xl_cmdimpl.c static int save_domain(uint32_t domid, const char *filename, int checkpoint, · line 3301

Quoted 10 lines
tools/libxl/xl_cmdimpl.c +5 -1
@@ -3293,8 +3293,12 @@ static int save_domain(uint32_t domid, const char *filename, int checkpoint,
     if (rc < 0)
         fprintf(stderr, "Failed to save domain, resuming domain\n");
 
-    if (checkpoint || rc < 0)
+    if (leavepaused || checkpoint || rc < 0) {
+        if (leavepaused && !(rc < 0)) {
+            libxl_domain_pause(ctx, domid);
+        }
         libxl_domain_resume(ctx, domid, 1, 0);
+    }

This logic is quite opaque. It would be clearer to have

if (leavepaused && rc == 0)
pause()
else if (checkpoint ...

Quoted 35 lines
tools/libxl/xl_cmdimpl.c +6 -2
     else
         libxl_domain_destroy(ctx, domid, 0);
 
@@ -3838,12 +3842,16 @@ int main_save(int argc, char **argv)
     const char *filename;
     const char *config_filename = NULL;
     int checkpoint = 0;
+    int leavepaused = 0;
     int opt;
 
-    SWITCH_FOREACH_OPT(opt, "c", NULL, "save", 2) {
+    SWITCH_FOREACH_OPT(opt, "cp", NULL, "save", 2) {
     case 'c':
         checkpoint = 1;
         break;
+    case 'p':
+        leavepaused = 1;
+        break;
     }
 
     if (argc-optind > 3) {
@@ -3856,7 +3864,7 @@ int main_save(int argc, char **argv)
     if ( argc - optind >= 3 )
         config_filename = argv[optind + 2];
 
-    save_domain(domid, filename, checkpoint, config_filename);
+    save_domain(domid, filename, checkpoint, leavepaused, config_filename);
     return 0;
 }
 
tools/libxl/xl_cmdtable.c +0 -0
index 44b42b0..c429cea 100644

tools/libxl/xl_cmdtable.c struct cmd_spec cmd_table[] = { · line 147

Quoted 7 lines
tools/libxl/xl_cmdtable.c +3 -1
@@ -142,7 +142,9 @@ struct cmd_spec cmd_table[] = {
       "Save a domain state to restore later",
       "[options] <Domain> <CheckpointFile> [<ConfigFile>]",
       "-h  Print this help.\n"
-      "-c  Leave domain running after creating the snapshot."
+      "-c  Leave domain running after creating the snapshot.\n"
+      "-p  Leave domain paused after creating the snapshot."
+

Needless whitespace

tools/libxl/xl_cmdtable.c struct cmd_spec cmd_table[] = { · line 150

Quoted 3 lines
tools/libxl/xl_cmdtable.c +0 -0
     },
     { "migrate",
       &main_migrate, 0, 1,

Can you also patch the manpage, docs/man/xl.pod.1 to the same effect

~Andrew

author
#2 lore raw
Quoted 7 lines
Quoted 8 lines

________________________________
From: Andrew Cooper <[email protected]>
To: Ian Murray <[email protected]>
Cc: [email protected]; [email protected]
Sent: Wednesday, 3 July 2013, 0:55
Subject: Re: [Xen-devel] [PATCH] xl save but leave domain paused

Thanks for your feedback.

Quoted 16 lines · Ian Murray
Quoted 15 lines

New feature to allow xl save to leave a domain paused after its memory has been saved. This is to allow disk snapshots of domU to be taken that exactly correspond to the memory state at save time. Once the snapshot(s) have been taken or whatever, the domain can be unpaused in the usual manner.

Usage:
   xl save -p <domid> <filespec>

---
  tools/libxl/xl_cmdimpl.c  |   16 ++++++++++++---- tools/libxl/xl_cmdtable.c |    4 +++-

  2 files changed, 15 insertions(+), 5 deletions(-)
Quoted 13 lines
Quoted 10 lines
tools/libxl/xl_cmdimpl.c +0 -0
index 8a478ba..670620b 100644
@@ -3266,7 +3266,7 @@ static void save_domain_core_writeconfig(int fd, const char *source,
   }


  static int save_domain(uint32_t domid, const char *filename, int checkpoint, -                const char *override_config_file)
+                int leavepaused, const char *override_config_file)

#include <stdbool.h> and use bool rather than int.  Also, re-align the second line arguments which was misaligned when the function was made static

I used an int for consistency, as this was how the checkpoint was done. I can change it if you like, but it is going to be inconsistent with checkpoint. I could do checkpoint as well but that would be fixing code that isn't broken, which is a bit out of scope and makes the patch footprint bigger.

As for the misalignment, is there a style guide or should I just look round some more? I just re-used what was there, which wasn't helpful given it was already broke. I don't want to copy any more OP's  mis-alignment mistakes. :)

Quoted 18 lines
Quoted 7 lines

  {
      int fd;
      uint8_t *config_data;

tools/libxl/xl_cmdimpl.c +0 -0
@@ -3293,8 +3293,12 @@ static int save_domain(uint32_t domid, const char *filename, int checkpoint,
       if (rc < 0)
           fprintf(stderr, "Failed to save domain, resuming domain\n");
Quoted 8 lines


-    if (checkpoint || rc < 0)
+    if (leavepaused || checkpoint || rc < 0) {
+        if (leavepaused && !(rc < 0)) {
+            libxl_domain_pause(ctx, domid);
+        }
          libxl_domain_resume(ctx, domid, 1, 0);
+    }

This logic is quite opaque.  It would be clearer to have

Quoted 3 lines

if (leavepaused && rc == 0)
  pause()
else if (checkpoint ...

In itself, this isn't correct logic because the resume has to occur for both checkpointing or pausing.

You would end up with

if (leavepaused && ...) {

    pause()
    resume()

} else if (checkpoint && ...) {
    resume()

}

Is this preferable? I tend to avoid repeating code if I can help it esp in if statements, although perhaps it does read easier.

I used the !(rc<0) because I didn't want to make assumptions about the possible value of rc, given the rest of the code uses rc<0

Quoted 37 lines
Quoted 37 lines

      else
          libxl_domain_destroy(ctx, domid, 0);

tools/libxl/xl_cmdimpl.c +1 -0
@@ -3838,12 +3842,16 @@ int main_save(int argc, char **argv)
       const char *filename;
       const char *config_filename = NULL;
       int checkpoint = 0;
+    int leavepaused = 0;
       int opt;


-    SWITCH_FOREACH_OPT(opt, "c", NULL, "save", 2) { +    SWITCH_FOREACH_OPT(opt, "cp", NULL, "save", 2) { case 'c':
          checkpoint = 1;
          break;
+    case 'p':
+        leavepaused = 1;
+        break;
      }

      if (argc-optind > 3) {

tools/libxl/xl_cmdimpl.c +0 -0
@@ -3856,7 +3864,7 @@ int main_save(int argc, char **argv)
       if ( argc - optind >= 3 )
           config_filename = argv[optind + 2];


-    save_domain(domid, filename, checkpoint, config_filename); +    save_domain(domid, filename, checkpoint, leavepaused, config_filename); return 0;
  }

tools/libxl/xl_cmdtable.c +0 -0
index 44b42b0..c429cea 100644
@@ -142,7 +142,9 @@ struct cmd_spec cmd_table[] = {
         "Save a domain state to restore later",
Quoted 8 lines
Quoted 6 lines
tools/libxl/xl_cmdtable.c +0 -0
         "[options] <Domain> <CheckpointFile> [<ConfigFile>]",

        "-h  Print this help.\n"
-      "-c  Leave domain running after creating the snapshot." +      "-c  Leave domain running after creating the snapshot.\n" +      "-p  Leave domain paused after creating the snapshot." +

Needless whitespace

Sure. Slipped in by accident.

Quoted 6 lines
Quoted 4 lines

      },
      { "migrate",
        &main_migrate, 0, 1,

Can you also patch the manpage, docs/man/xl.pod.1 to the same effect

Yeah, I forgot about that. Thanks.

Thanks again for your response.

Quoted 10 lines

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#3 lore raw
Quoted 49 lines · Ian Murray
Quoted 6 lines
Quoted 8 lines

________________________________
From: Andrew Cooper <[email protected]>
To: Ian Murray <[email protected]>
Cc: [email protected]; [email protected]
Sent: Wednesday, 3 July 2013, 0:55
Subject: Re: [Xen-devel] [PATCH] xl save but leave domain paused

Thanks for your feedback.

Quoted 23 lines · Ian Murray
Quoted 22 lines

New feature to allow xl save to leave a domain paused after its memory has been saved. This is to allow disk snapshots of domU to be taken that exactly correspond to the memory state at save time. Once the snapshot(s) have been taken or whatever, the domain can be unpaused in the usual manner.

Usage:
xl save -p <domid> <filespec>

---
 tools/libxl/xl_cmdimpl.c  |   16 ++++++++++++----
 tools/libxl/xl_cmdtable.c |    4 +++-
 2 files changed, 15 insertions(+), 5 deletions(-)
tools/libxl/xl_cmdimpl.c +0 -0
index 8a478ba..670620b 100644
@@ -3266,7 +3266,7 @@ static void save_domain_core_writeconfig(int fd, const char *source,
 }
 
Quoted 6 lines

tools/libxl/xl_cmdimpl.c static void save_domain_core_writeconfig(int fd, const char *source, · line 3269

Quoted 3 lines
tools/libxl/xl_cmdimpl.c +1 -1
 static int save_domain(uint32_t domid, const char *filename, int checkpoint,
-                const char *override_config_file)
+                int leavepaused, const char *override_config_file)

#include <stdbool.h> and use bool rather than int. Also, re-align the second line arguments which was misaligned when the function was made static

Quoted 5 lines

I used an int for consistency, as this was how the checkpoint was done. I can change it if you like, but it is going to be inconsistent with checkpoint. I could do checkpoint as well but that would be fixing code that isn't broken, which is a bit out of scope and makes the patch footprint bigger.

I don't think this is necessary unless you really want to. If xl_cmdimpl.c was already using bool in some places it might be more worthwhile, but currently it doesn't use it at all.

IMHO any overall change to use bool should be in a separate patch, but there is no onus on you to make this change unless you want to.

Quoted 4 lines

As for the misalignment, is there a style guide or should I just look round some more? I just re-used what was there, which wasn't helpful given it was already broke. I don't want to copy any more OP's mis-alignment mistakes. :)

tools/libxl/CODING_STYLE covers this code.

There is also a top-level CODING_STYLE which sometimes applies when there is no more specific CODING_STYLE documented (although see the caveats at the top of the file)

Quoted 27 lines
Quoted 17 lines
Quoted 4 lines
tools/libxl/xl_cmdimpl.c +0 -0
 {
     int fd;
     uint8_t *config_data;

tools/libxl/xl_cmdimpl.c static int save_domain(uint32_t domid, const char *filename, int checkpoint, · line 3301

Quoted 10 lines
tools/libxl/xl_cmdimpl.c +5 -1
@@ -3293,8 +3293,12 @@ static int save_domain(uint32_t domid, const char *filename, int checkpoint,
     if (rc < 0)
         fprintf(stderr, "Failed to save domain, resuming domain\n");
 
-    if (checkpoint || rc < 0)
+    if (leavepaused || checkpoint || rc < 0) {
+        if (leavepaused && !(rc < 0)) {
+            libxl_domain_pause(ctx, domid);
+        }
         libxl_domain_resume(ctx, domid, 1, 0);
+    }

This logic is quite opaque. It would be clearer to have

Quoted 3 lines

if (leavepaused && rc == 0)
pause()
else if (checkpoint ...

In itself, this isn't correct logic because the resume has to occur for both checkpointing or pausing.

You would end up with

if (leavepaused && ...) {

Quoted 7 lines
    pause()
    resume()

} else if (checkpoint && ...) {
resume()

}

    else if ( rc < 0 ) {
      resume()

too...

Quoted 2 lines

Is this preferable? I tend to avoid repeating code if I can help it esp in if statements, although perhaps it does read easier.

Both variants have their upside and downside IMHO.

What about refactoring the failure case (rc < 0) out from the success cases?

    if (rc < 0) {
        resume(...)
    } else if (leavepaused || checkpoint) {
        if (leavepaused) pause(...)
        resume(...)
    }

It's still a repetitive but "error" and "not error" are somewhat different cases IYSWIM.

Ian.

author
#4 lore raw

----- Original Message -----

Quoted 69 lines

From: Ian Campbell <[email protected]>
To: Ian Murray <[email protected]>
Cc: Andrew Cooper <[email protected]>; "[email protected]" <[email protected]>
Sent: Wednesday, 3 July 2013, 9:38
Subject: Re: [Xen-devel] [PATCH] xl save but leave domain paused

Quoted 15 lines · Ian Murray
Quoted 6 lines
Quoted 8 lines

________________________________
From: Andrew Cooper <[email protected]>
To: Ian Murray <[email protected]>
Cc: [email protected]; [email protected]
Sent: Wednesday, 3 July 2013, 0:55
Subject: Re: [Xen-devel] [PATCH] xl save but leave domain paused

Quoted 8 lines

Thanks for your feedback.

Quoted 4 lines · Ian Murray
Quoted 3 lines

New feature to allow xl save to leave a domain paused after its memory has been saved. This is to allow disk snapshots of domU to be taken that exactly correspond to the memory state at save

time.

Quoted 1 line
Quoted 1 line
Quoted 1 line

Once the snapshot(s) have been taken or whatever, the domain can

be

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

unpaused in the usual manner.

Usage:
  xl save -p <domid> <filespec>

---
  tools/libxl/xl_cmdimpl.c  |  16 ++++++++++++---- tools/libxl/xl_cmdtable.c |    4 +++-

  2 files changed, 15 insertions(+), 5 deletions(-)
Quoted 5 lines
Quoted 5 lines

tools/libxl/xl_cmdimpl.c static void save_domain_core_writeconfig(int

Quoted 5 lines
tools/libxl/xl_cmdimpl.c +0 -0
index 8a478ba..670620b 100644
@@ -3266,7 +3266,7 @@ static void save_domain_core_writeconfig(int 

fd, const char *source,

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
tools/libxl/xl_cmdimpl.c +0 -0
   }


  static int save_domain(uint32_t domid, const char *filename, int

checkpoint,

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

-                const char *override_config_file) +                int leavepaused, const char

*override_config_file)

Quoted 2 lines
Quoted 2 lines

#include <stdbool.h> and use bool rather than int.  Also,

re-align the

Quoted 1 line
Quoted 1 line

second line arguments which was misaligned when the function was made

static

Quoted 6 lines

I used an int for consistency, as this was how the checkpoint was done. I can change it if you like, but it is going to be inconsistent with checkpoint. I could do checkpoint as well but that would be fixing code that isn't broken, which is a bit out of scope and makes the patch footprint bigger.

Quoted 7 lines

I don't think this is necessary unless you really want to. If xl_cmdimpl.c was already using bool in some places it might be more worthwhile, but currently it doesn't use it at all.

IMHO any overall change to use bool should be in a separate patch, but there is no onus on you to make this change unless you want to.

No, I will leave as is, if it's all the same.

Quoted 10 lines
Quoted 4 lines

As for the misalignment, is there a style guide or should I just look round some more? I just re-used what was there, which wasn't helpful given it was already broke. I don't want to copy any more OP's mis-alignment mistakes. :)

tools/libxl/CODING_STYLE covers this code.

There is also a top-level CODING_STYLE which sometimes applies when there is no more specific CODING_STYLE documented (although see the caveats at the top of the file)

)
Thanks, I will take a look.

Quoted 56 lines
Quoted 5 lines
Quoted 5 lines

tools/libxl/xl_cmdimpl.c static int save_domain(uint32_t domid,

Quoted 5 lines

  {
      int fd;
      uint8_t *config_data;

tools/libxl/xl_cmdimpl.c +0 -0
@@ -3293,8 +3293,12 @@ static int save_domain(uint32_t domid, 

const char *filename, int checkpoint,

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
tools/libxl/xl_cmdimpl.c +0 -0
       if (rc < 0)

          fprintf(stderr, "Failed to save domain, resuming

domain\n");

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines


-    if (checkpoint || rc < 0)
+    if (leavepaused || checkpoint || rc < 0) {
+        if (leavepaused && !(rc < 0)) {
+            libxl_domain_pause(ctx, domid);
+        }
          libxl_domain_resume(ctx, domid, 1, 0);
+    }

Quoted 7 lines
Quoted 5 lines

This logic is quite opaque.  It would be clearer to have

if (leavepaused && rc == 0)
  pause()
else if (checkpoint ...

In itself, this isn't correct logic because the resume has to occur for

both checkpointing or pausing.

Quoted 5 lines

You would end up with

if (leavepaused && ...) {

Quoted 7 lines

    pause()
    resume()

} else if (checkpoint && ...) {
    resume()

}

    else if ( rc < 0 ) {
      resume()
too...

Quoted 2 lines

Is this preferable? I tend to avoid repeating code if I can help it esp in if statements, although perhaps it does read easier.

Both variants have their upside and downside IMHO.

What about refactoring the failure case (rc < 0) out from the success cases?
    if (rc < 0) {
        resume(...)
    } else if (leavepaused || checkpoint) {
        if (leavepaused) pause(...)
        resume(...)
    }

Quoted 3 lines

It's still a repetitive but "error" and "not error" are somewhat
different cases IYSWIM.

Possibly an exercise in cat skinning, but I do see the logic of your logic ( ;) ), so am happy to go with it.

Quoted 9 lines

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel