Skip to contentSkip to conversation

tools/xl: add suspend-to-ram and resume subcommands

PATCH In review zithro / Cyril Rébert 3 participants 7 messages Feb 29, 2024 – Aug 7, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/xl: add suspend-to-ram and resume subcommands

The xl command doesn't provide suspend/resume, so add them :
xl suspend-to-ram <Domain>
xl resume <Domain>

This patch follows a discussion on XenDevel: when you want the virtualized equivalent of "sleep"-ing a host, it's better to suspend/resume than to pause/unpause a domain.

---
- Tested on v4.17, x86
- the function "libxl_domain_resume" is called like libvirt does, so using a "co-operative resume", but I don't know what it means (:
- there may be a problem with the words resume <-> restore, like for "LIBXL_HAVE_NO_SUSPEND_RESUME"
- for the docs, I only slightly adapted a copy/paste from xl pause ...
---

---
 docs/man/xl.1.pod.in    | 10 ++++++++++
 tools/xl/xl.h           |  2 ++
 tools/xl/xl_cmdtable.c  | 10 ++++++++++
 tools/xl/xl_vmcontrol.c | 36 ++++++++++++++++++++++++++++++++++++
 4 files changed, 58 insertions(+)
docs/man/xl.1.pod.in +10 -0
index bed8393473..63d80f1449 100644
@@ -682,6 +682,10 @@ Pass the VNC password to vncviewer via stdin.
 
 =back
 
+=item B<resume> I<domain-id>
+
+Resume a domain, after having been suspended to RAM.
+
 =item B<save> [I<OPTIONS>] I<domain-id> I<checkpointfile> [I<configfile>]
 
 Saves a running domain to a state file so that it can be restored
@@ -760,6 +764,12 @@ in response to this event.
 
 =back
 
+=item B<suspend-to-ram> I<domain-id>
+
+Suspend a domain to RAM.  When in a suspended state the domain will still
+consume allocated resources (such as memory), but will not be eligible for
+scheduling by the Xen hypervisor. It is in a shutdown state, but not dying.
+
 =item B<sysrq> I<domain-id> I<letter>
 
 Send a <Magic System Request> to the domain, each type of request is
tools/xl/xl.h +2 -0
index 9c86bb1d98..716ad32423 100644
@@ -133,6 +133,8 @@ int main_migrate(int argc, char **argv);
 int main_dump_core(int argc, char **argv);
 int main_pause(int argc, char **argv);
 int main_unpause(int argc, char **argv);
+int main_suspendtoram(int argc, char **argv);
+int main_resume(int argc, char **argv);
 int main_destroy(int argc, char **argv);
 int main_shutdown(int argc, char **argv);
 int main_reboot(int argc, char **argv);
tools/xl/xl_cmdtable.c +10 -0
index 62bdb2aeaa..1382282252 100644
@@ -136,6 +136,16 @@ const struct cmd_spec cmd_table[] = {
       "Unpause a paused domain",
       "<Domain>",
     },
+    { "suspend-to-ram",
+      &main_suspendtoram, 0, 1,
+      "Suspend a domain to RAM",
+      "<Domain>",
+    },
+    { "resume",
+      &main_resume, 0, 1,
+      "Resume a domain from RAM",
+      "<Domain>",
+    },
     { "console",
       &main_console, 0, 0,
       "Attach to domain's console",
tools/xl/xl_vmcontrol.c +36 -0
index 98f6bd2e76..ba45f89c5a 100644
@@ -42,6 +42,16 @@ static void unpause_domain(uint32_t domid)
     libxl_domain_unpause(ctx, domid, NULL);
 }
 
+static void suspend_domain_toram(uint32_t domid)
+{
+    libxl_domain_suspend_only(ctx, domid, NULL);
+}
+
+static void resume_domain(uint32_t domid)
+{
+    libxl_domain_resume(ctx, domid, 1, NULL);
+}
+
 static void destroy_domain(uint32_t domid, int force)
 {
     int rc;
@@ -82,6 +92,32 @@ int main_unpause(int argc, char **argv)
     return EXIT_SUCCESS;
 }
 
+int main_suspendtoram(int argc, char **argv)
+{
+    int opt;
+
+    SWITCH_FOREACH_OPT(opt, "", NULL, "suspend-to-ram", 1) {
+        /* No options */
+    }
+
+    suspend_domain_toram(find_domain(argv[optind]));
+
+    return EXIT_SUCCESS;
+}
+
+int main_resume(int argc, char **argv)
+{
+    int opt;
+
+    SWITCH_FOREACH_OPT(opt, "", NULL, "resume", 1) {
+        /* No options */
+    }
+
+    resume_domain(find_domain(argv[optind]));
+
+    return EXIT_SUCCESS;
+}
+
 int main_destroy(int argc, char **argv)
 {
     int opt;
Signature · 1 line
2.39.2
#1 lore raw
Quoted 10 lines · zithro / Cyril Rébert

The xl command doesn't provide suspend/resume, so add them :
xl suspend-to-ram <Domain>
xl resume <Domain>

This patch follows a discussion on XenDevel: when you want the virtualized equivalent of "sleep"-ing a host, it's better to suspend/resume than to pause/unpause a domain.

You should include you S-o-B here to certify your patch under the Developer's Certificate of Origin. You can read what that means in CONTRIBUTING. tl;dr: You are stating you can make the open source contribution.

I tested this with a PVH and HVM guest. suspend-to-ram and resume seem to function properly. The VCPUs stop, but the domain & qemu remain. Resume works - the VCPUs start running again.

However, the domain destruction seems to hang on poweroff. The VM transitions to powered off - state shutdown - but the domain and QEMU instance are not cleaned up.

If I power off without a suspend-to-ram, everything is cleaned up properly.

Have you seen this? It's not your code, but I guess something with libxl or qemu.

Quoted 17 lines

---
- Tested on v4.17, x86
- the function "libxl_domain_resume" is called like libvirt does, so using a "co-operative resume", but I don't know what it means (:
- there may be a problem with the words resume <-> restore, like for "LIBXL_HAVE_NO_SUSPEND_RESUME"
- for the docs, I only slightly adapted a copy/paste from xl pause ...
---

tools/xl/xl_vmcontrol.c +0 -0
index 98f6bd2e76..ba45f89c5a 100644
@@ -42,6 +42,16 @@ static void unpause_domain(uint32_t domid)
      libxl_domain_unpause(ctx, domid, NULL);
  }
 

tools/xl/xl_vmcontrol.c static void unpause_domain(uint32_t domid) · line 54

Quoted 10 lines
tools/xl/xl_vmcontrol.c +10 -0
+static void suspend_domain_toram(uint32_t domid)
+{
+    libxl_domain_suspend_only(ctx, domid, NULL);
+}
+
+static void resume_domain(uint32_t domid)
+{
+    libxl_domain_resume(ctx, domid, 1, NULL);
+}
+

I would just inline these functions below.

tools/xl/xl_vmcontrol.c int main_unpause(int argc, char **argv) · line 95

Quoted 8 lines
tools/xl/xl_vmcontrol.c +1 -0
  static void destroy_domain(uint32_t domid, int force)
  {
      int rc;
@@ -82,6 +92,32 @@ int main_unpause(int argc, char **argv)
      return EXIT_SUCCESS;
  }
 
+int main_suspendtoram(int argc, char **argv)

Maybe main_suspend_to_ram to be closer to the command line suspend-to-ram.

Thanks,
Jason

#2 lore raw

Hi Zithro,

Quoted 5 lines · Jason Andryuk
Quoted 4 lines · zithro / Cyril Rébert

The xl command doesn't provide suspend/resume, so add them :
   xl suspend-to-ram <Domain>
   xl resume <Domain>

Quoted 8 lines
Quoted 6 lines

This patch follows a discussion on XenDevel: when you want the virtualized equivalent of "sleep"-ing a host, it's better to suspend/resume than to pause/unpause a domain.

You should include you S-o-B here to certify your patch under the Developer's Certificate of Origin.  You can read what that means in CONTRIBUTING.  tl;dr: You are stating you can make the open source contribution.

I'd like to re-submit this while retaining your authorship. Are you able to provide your S-o-B?

I'll do all the follow ups, but I need your S-o-B for me to make the submission.

Quoted 7 lines

I tested this with a PVH and HVM guest.  suspend-to-ram and resume seem to function properly.  The VCPUs stop, but the domain & qemu remain. Resume works - the VCPUs start running again.

However, the domain destruction seems to hang on poweroff.  The VM transitions to powered off - state shutdown - but the domain and QEMU instance are not cleaned up.

If I power off without a suspend-to-ram, everything is cleaned up properly.

Have you seen this?  It's not your code, but I guess something with libxl or qemu.

I've found the issue. xl exits when the domain suspends. When the domain finally shuts down, xl isn't there to perform the remaining cleanup.

Quoted 20 lines
Quoted 20 lines

---
- Tested on v4.17, x86
- the function "libxl_domain_resume" is called like libvirt does, so using a "co-operative resume", but I don't know what it means (:
- there may be a problem with the words resume <-> restore, like for "LIBXL_HAVE_NO_SUSPEND_RESUME"
- for the docs, I only slightly adapted a copy/paste from xl pause ...
---

tools/xl/xl_vmcontrol.c +4 -0
index 98f6bd2e76..ba45f89c5a 100644
@@ -42,6 +42,16 @@ static void unpause_domain(uint32_t domid)
       libxl_domain_unpause(ctx, domid, NULL);
   }
+static void suspend_domain_toram(uint32_t domid)
+{
+    libxl_domain_suspend_only(ctx, domid, NULL);
+}
Quoted 8 lines

tools/xl/xl_vmcontrol.c static void unpause_domain(uint32_t domid) · line 54

Quoted 6 lines
tools/xl/xl_vmcontrol.c +6 -0
+
+static void resume_domain(uint32_t domid)
+{
+    libxl_domain_resume(ctx, domid, 1, NULL);
+}
+

I would just inline these functions below.

I see you were following the existing style, so this may remain as you wrote it.

Quoted 9 lines

tools/xl/xl_vmcontrol.c int main_unpause(int argc, char **argv) · line 94

Quoted 7 lines
tools/xl/xl_vmcontrol.c +1 -0
   static void destroy_domain(uint32_t domid, int force)
   {
       int rc;
@@ -82,6 +92,32 @@ int main_unpause(int argc, char **argv)
       return EXIT_SUCCESS;
   }
+int main_suspendtoram(int argc, char **argv)

Maybe main_suspend_to_ram to be closer to the command line suspend-to-ram.

I'm thinking we may want to just use "suspend" for the command name and all the functions.

Thanks,
Jason

author
#3 lore raw
In reply to zithro / Cyril Rébert

Added my S-o-B (no other change).

Quoted 10 lines · zithro / Cyril Rébert

The xl command doesn't provide suspend/resume, so add them :
xl suspend-to-ram <Domain>
xl resume <Domain>

This patch follows a discussion on XenDevel: when you want the virtualized equivalent of "sleep"-ing a host, it's better to suspend/resume than to pause/unpause a domain.

Quoted 132 lines

---
- Tested on v4.17, x86
- the function "libxl_domain_resume" is called like libvirt does, so using a "co-operative resume", but I don't know what it means (:
- there may be a problem with the words resume <-> restore, like for "LIBXL_HAVE_NO_SUSPEND_RESUME"
- for the docs, I only slightly adapted a copy/paste from xl pause ...
---

---
  docs/man/xl.1.pod.in    | 10 ++++++++++
  tools/xl/xl.h           |  2 ++
  tools/xl/xl_cmdtable.c  | 10 ++++++++++
  tools/xl/xl_vmcontrol.c | 36 ++++++++++++++++++++++++++++++++++++
  4 files changed, 58 insertions(+)
docs/man/xl.1.pod.in +10 -0
index bed8393473..63d80f1449 100644
@@ -682,6 +682,10 @@ Pass the VNC password to vncviewer via stdin.
 
  =back
 
+=item B<resume> I<domain-id>
+
+Resume a domain, after having been suspended to RAM.
+
  =item B<save> [I<OPTIONS>] I<domain-id> I<checkpointfile> [I<configfile>]
 
  Saves a running domain to a state file so that it can be restored
@@ -760,6 +764,12 @@ in response to this event.
 
  =back
 
+=item B<suspend-to-ram> I<domain-id>
+
+Suspend a domain to RAM.  When in a suspended state the domain will still
+consume allocated resources (such as memory), but will not be eligible for
+scheduling by the Xen hypervisor. It is in a shutdown state, but not dying.
+
  =item B<sysrq> I<domain-id> I<letter>
 
  Send a <Magic System Request> to the domain, each type of request is
tools/xl/xl.h +2 -0
index 9c86bb1d98..716ad32423 100644
@@ -133,6 +133,8 @@ int main_migrate(int argc, char **argv);
  int main_dump_core(int argc, char **argv);
  int main_pause(int argc, char **argv);
  int main_unpause(int argc, char **argv);
+int main_suspendtoram(int argc, char **argv);
+int main_resume(int argc, char **argv);
  int main_destroy(int argc, char **argv);
  int main_shutdown(int argc, char **argv);
  int main_reboot(int argc, char **argv);
tools/xl/xl_cmdtable.c +10 -0
index 62bdb2aeaa..1382282252 100644
@@ -136,6 +136,16 @@ const struct cmd_spec cmd_table[] = {
        "Unpause a paused domain",
        "<Domain>",
      },
+    { "suspend-to-ram",
+      &main_suspendtoram, 0, 1,
+      "Suspend a domain to RAM",
+      "<Domain>",
+    },
+    { "resume",
+      &main_resume, 0, 1,
+      "Resume a domain from RAM",
+      "<Domain>",
+    },
      { "console",
        &main_console, 0, 0,
        "Attach to domain's console",
tools/xl/xl_vmcontrol.c +36 -0
index 98f6bd2e76..ba45f89c5a 100644
@@ -42,6 +42,16 @@ static void unpause_domain(uint32_t domid)
      libxl_domain_unpause(ctx, domid, NULL);
  }
 
+static void suspend_domain_toram(uint32_t domid)
+{
+    libxl_domain_suspend_only(ctx, domid, NULL);
+}
+
+static void resume_domain(uint32_t domid)
+{
+    libxl_domain_resume(ctx, domid, 1, NULL);
+}
+
  static void destroy_domain(uint32_t domid, int force)
  {
      int rc;
@@ -82,6 +92,32 @@ int main_unpause(int argc, char **argv)
      return EXIT_SUCCESS;
  }
 
+int main_suspendtoram(int argc, char **argv)
+{
+    int opt;
+
+    SWITCH_FOREACH_OPT(opt, "", NULL, "suspend-to-ram", 1) {
+        /* No options */
+    }
+
+    suspend_domain_toram(find_domain(argv[optind]));
+
+    return EXIT_SUCCESS;
+}
+
+int main_resume(int argc, char **argv)
+{
+    int opt;
+
+    SWITCH_FOREACH_OPT(opt, "", NULL, "resume", 1) {
+        /* No options */
+    }
+
+    resume_domain(find_domain(argv[optind]));
+
+    return EXIT_SUCCESS;
+}
+
  int main_destroy(int argc, char **argv)
  {
      int opt;
Signature · 2 lines
++
zithro / Cyril
author
#4 lore raw
In reply to zithro / Cyril Rébert

Added my S-o-B (no other change).

PS: re-sent to account for Anthony mail address change

Quoted 10 lines · zithro / Cyril Rébert

The xl command doesn't provide suspend/resume, so add them :
xl suspend-to-ram <Domain>
xl resume <Domain>

This patch follows a discussion on XenDevel: when you want the virtualized equivalent of "sleep"-ing a host, it's better to suspend/resume than to pause/unpause a domain.

Quoted 132 lines

---
- Tested on v4.17, x86
- the function "libxl_domain_resume" is called like libvirt does, so using a "co-operative resume", but I don't know what it means (:
- there may be a problem with the words resume <-> restore, like for "LIBXL_HAVE_NO_SUSPEND_RESUME"
- for the docs, I only slightly adapted a copy/paste from xl pause ...
---

---
  docs/man/xl.1.pod.in    | 10 ++++++++++
  tools/xl/xl.h           |  2 ++
  tools/xl/xl_cmdtable.c  | 10 ++++++++++
  tools/xl/xl_vmcontrol.c | 36 ++++++++++++++++++++++++++++++++++++
  4 files changed, 58 insertions(+)
docs/man/xl.1.pod.in +10 -0
index bed8393473..63d80f1449 100644
@@ -682,6 +682,10 @@ Pass the VNC password to vncviewer via stdin.
 
  =back
 
+=item B<resume> I<domain-id>
+
+Resume a domain, after having been suspended to RAM.
+
  =item B<save> [I<OPTIONS>] I<domain-id> I<checkpointfile> [I<configfile>]
 
  Saves a running domain to a state file so that it can be restored
@@ -760,6 +764,12 @@ in response to this event.
 
  =back
 
+=item B<suspend-to-ram> I<domain-id>
+
+Suspend a domain to RAM.  When in a suspended state the domain will still
+consume allocated resources (such as memory), but will not be eligible for
+scheduling by the Xen hypervisor. It is in a shutdown state, but not dying.
+
  =item B<sysrq> I<domain-id> I<letter>
 
  Send a <Magic System Request> to the domain, each type of request is
tools/xl/xl.h +2 -0
index 9c86bb1d98..716ad32423 100644
@@ -133,6 +133,8 @@ int main_migrate(int argc, char **argv);
  int main_dump_core(int argc, char **argv);
  int main_pause(int argc, char **argv);
  int main_unpause(int argc, char **argv);
+int main_suspendtoram(int argc, char **argv);
+int main_resume(int argc, char **argv);
  int main_destroy(int argc, char **argv);
  int main_shutdown(int argc, char **argv);
  int main_reboot(int argc, char **argv);
tools/xl/xl_cmdtable.c +10 -0
index 62bdb2aeaa..1382282252 100644
@@ -136,6 +136,16 @@ const struct cmd_spec cmd_table[] = {
        "Unpause a paused domain",
        "<Domain>",
      },
+    { "suspend-to-ram",
+      &main_suspendtoram, 0, 1,
+      "Suspend a domain to RAM",
+      "<Domain>",
+    },
+    { "resume",
+      &main_resume, 0, 1,
+      "Resume a domain from RAM",
+      "<Domain>",
+    },
      { "console",
        &main_console, 0, 0,
        "Attach to domain's console",
tools/xl/xl_vmcontrol.c +36 -0
index 98f6bd2e76..ba45f89c5a 100644
@@ -42,6 +42,16 @@ static void unpause_domain(uint32_t domid)
      libxl_domain_unpause(ctx, domid, NULL);
  }
 
+static void suspend_domain_toram(uint32_t domid)
+{
+    libxl_domain_suspend_only(ctx, domid, NULL);
+}
+
+static void resume_domain(uint32_t domid)
+{
+    libxl_domain_resume(ctx, domid, 1, NULL);
+}
+
  static void destroy_domain(uint32_t domid, int force)
  {
      int rc;
@@ -82,6 +92,32 @@ int main_unpause(int argc, char **argv)
      return EXIT_SUCCESS;
  }
 
+int main_suspendtoram(int argc, char **argv)
+{
+    int opt;
+
+    SWITCH_FOREACH_OPT(opt, "", NULL, "suspend-to-ram", 1) {
+        /* No options */
+    }
+
+    suspend_domain_toram(find_domain(argv[optind]));
+
+    return EXIT_SUCCESS;
+}
+
+int main_resume(int argc, char **argv)
+{
+    int opt;
+
+    SWITCH_FOREACH_OPT(opt, "", NULL, "resume", 1) {
+        /* No options */
+    }
+
+    resume_domain(find_domain(argv[optind]));
+
+    return EXIT_SUCCESS;
+}
+
  int main_destroy(int argc, char **argv)
  {
      int opt;
Signature · 2 lines
++
zithro / Cyril
#5 lore raw
Quoted 9 lines · zithro

Added my S-o-B (no other change).

PS: re-sent to account for Anthony mail address change

Quoted 4 lines · zithro / Cyril Rébert

The xl command doesn't provide suspend/resume, so add them :
xl suspend-to-ram <Domain>
xl resume <Domain>

Quoted 7 lines
Quoted 6 lines

This patch follows a discussion on XenDevel: when you want the virtualized equivalent of "sleep"-ing a host, it's better to suspend/resume than to pause/unpause a domain.

Imo you want to properly re-submit, ...

Quoted 2 lines
Quoted 2 lines

---
- Tested on v4.17, x86

... with this testing also advanced to 4.19.

Jan

#6 lore raw
Quoted 16 lines · Jan Beulich
Quoted 15 lines · zithro

Added my S-o-B (no other change).

PS: re-sent to account for Anthony mail address change

Quoted 10 lines · zithro / Cyril Rébert

The xl command doesn't provide suspend/resume, so add them :
xl suspend-to-ram <Domain>
xl resume <Domain>

This patch follows a discussion on XenDevel: when you want the virtualized equivalent of "sleep"-ing a host, it's better to suspend/resume than to pause/unpause a domain.

Quoted 8 lines
Quoted 1 line

Imo you want to properly re-submit, ...

Quoted 2 lines
Quoted 2 lines

---
- Tested on v4.17, x86

... with this testing also advanced to 4.19.

I'll test and re-submit this.

Thanks,
Jason