Skip to contentSkip to conversation

tools/xendomains: Only save/restore/migrate if supported by xenlight

PATCH In review Peter Hoyes 4 participants 10 messages Mar 22, 2023 – Oct 23, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/xendomains: Only save/restore/migrate if supported by xenlight

From: Peter Hoyes <[email protected]>

Saving, restoring and migrating domains are not currently supported on arm and arm64 platforms, so xendomains prints the warning:

An error occurred while saving domain:
command not implemented

when attempting to run xendomains stop. It otherwise continues to shut down the domains cleanly, with the unsupported steps skipped.

Use xl help to detect whether save/restore/migrate is supported by the platform. If not, do not attempt to run the corresponding command.

---
 tools/hotplug/Linux/xendomains.in | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
tools/hotplug/Linux/xendomains.in +13 -3
index 70f4129ef4..bafcb874e1 100644
@@ -229,6 +229,15 @@ parseln()
     [ -n "$name" -a -n "$id" ] && return 0 || return 1
 }
 
+subcmd_supported()
+{
+    local output
+    output=$("$CMD help | grep "^ $1"")
+    if [ ! "$output" ]; then
+        return 1
+    fi
+}
+
 is_running()
 {
     get_xsdomid
@@ -260,7 +269,8 @@ start()
 
     saved_domains=" "
     if [ "$XENDOMAINS_RESTORE" = "true" ] &&
-       contains_something "$XENDOMAINS_SAVE"
+       contains_something "$XENDOMAINS_SAVE" &&
+       subcmd_supported "restore"
     then
 	echo -n "Restoring Xen domains:"
 	saved_domains=`ls $XENDOMAINS_SAVE`
@@ -411,7 +421,7 @@ stop()
 	    echo -n "(zomb)"
 	    continue
 	fi
-	if test -n "$XENDOMAINS_MIGRATE"; then
+	if test -n "$XENDOMAINS_MIGRATE" && subcmd_supported "migrate"; then
 	    echo -n "(migr)"
 	    watchdog_xencmd migrate &
 	    WDOG_PID=$!
@@ -430,7 +440,7 @@ stop()
 		continue
 	    fi
 	fi
-	if test -n "$XENDOMAINS_SAVE"; then
+	if test -n "$XENDOMAINS_SAVE" && subcmd_supported "save"; then
 	    echo -n "(save)"
 	    watchdog_xencmd save &
 	    WDOG_PID=$!
Signature · 1 line
2.34.1
#1 lore raw
Quoted 10 lines · Peter Hoyes

From: Peter Hoyes <[email protected]>

Saving, restoring and migrating domains are not currently supported on arm and arm64 platforms, so xendomains prints the warning:

An error occurred while saving domain:
command not implemented

when attempting to run xendomains stop. It otherwise continues to shut down the domains cleanly, with the unsupported steps skipped.

The patch looks kind of ok, but shouldn't $XENDOMAINS_SAVE be set to an empty string in the config by the admin instead?

Or is the issue that $XENDOMAINS_SAVE is set by default, even on arm* ?

Maybe it's easier to check that the command is implemented at run time rather than trying to have a good default value for XENDOMAINS_SAVE at install/package time.

Quoted 13 lines

Use xl help to detect whether save/restore/migrate is supported by the platform. If not, do not attempt to run the corresponding command.

---
 tools/hotplug/Linux/xendomains.in | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
tools/hotplug/Linux/xendomains.in +0 -0
index 70f4129ef4..bafcb874e1 100644

tools/hotplug/Linux/xendomains.in parseln() · line 238

Quoted 10 lines
tools/hotplug/Linux/xendomains.in +7 -0
@@ -229,6 +229,15 @@ parseln()
     [ -n "$name" -a -n "$id" ] && return 0 || return 1
 }
 
+subcmd_supported()
+{
+    local output
+    output=$("$CMD help | grep "^ $1"")
+    if [ ! "$output" ]; then
+        return 1
+    fi

It looks like some quote are in the wrong place. You probably wanted to write:

    output="$($CMD help | grep "^ $1")"

But I'd like to have this slightly more robust, to match the whole command, rather than the beginning.
(For example subcmd_supported "pci" would reture true even if no "pci" command exist.)

Something like:

    $CMD help | grep "^ $1\( \|$\)"

To check that the command name is followed by a space or end-of-line (even if it seems that there's always a space printed.)
A similar pattern is used in "tools/xl/bash-completion", so it should probably be fine in the future.

Then, we don't really need the "$output" from grep, we could just ask it if there's a match or not, with --quiet:

    $CMD help | grep -q "^ $1\( \|$\)"

And that would be the whole function. Would that works for you?

The rest of the patch looks fine.

Thanks,

Signature · 1 line
Anthony PERARD
#2 lore raw
Quoted 9 lines · Anthony PERARD
Quoted 8 lines · Peter Hoyes

From: Peter Hoyes <[email protected]>

Saving, restoring and migrating domains are not currently supported on arm and arm64 platforms, so xendomains prints the warning:

An error occurred while saving domain:
command not implemented

Quoted 6 lines
Quoted 2 lines

when attempting to run xendomains stop. It otherwise continues to shut down the domains cleanly, with the unsupported steps skipped.

The patch looks kind of ok, but shouldn't $XENDOMAINS_SAVE be set to an empty string in the config by the admin instead?

Or is the issue that $XENDOMAINS_SAVE is set by default, even on arm* ?

Yea the default is the issue. We are building for embedded, using Yocto, so there isn't really an admin.

Quoted 4 lines

Maybe it's easier to check that the command is implemented at run time rather than trying to have a good default value for XENDOMAINS_SAVE at install/package time.

It would be cleaner to do this at build time for sure, but I'm not sure the autotools config file approach for sysconfig.xendomains.in can handle the logic for this?

Thanks,

Peter

#3 lore raw
Quoted 19 lines · Peter Hoyes
Quoted 9 lines · Anthony PERARD
Quoted 8 lines · Peter Hoyes

From: Peter Hoyes <[email protected]>

Saving, restoring and migrating domains are not currently supported on arm and arm64 platforms, so xendomains prints the warning:

An error occurred while saving domain:
command not implemented

Quoted 6 lines
Quoted 2 lines

when attempting to run xendomains stop. It otherwise continues to shut down the domains cleanly, with the unsupported steps skipped.

The patch looks kind of ok, but shouldn't $XENDOMAINS_SAVE be set to an empty string in the config by the admin instead?

Or is the issue that $XENDOMAINS_SAVE is set by default, even on arm* ?

Yea the default is the issue. We are building for embedded, using Yocto, so there isn't really an admin.

Quoted 1 line
Quoted 7 lines
Quoted 3 lines

Maybe it's easier to check that the command is implemented at run time rather than trying to have a good default value for XENDOMAINS_SAVE at install/package time.

It would be cleaner to do this at build time for sure, but I'm not sure the autotools config file approach for sysconfig.xendomains.in can handle the logic for this?

I think that possible, we can already change config in ./configure based on the CPU.

I'm preparing a patch.

Thanks,

Signature · 1 line
Anthony PERARD
#4 lore raw

PATCH 1/1 tools/xendomains: Don't auto save/restore/migrate on Arm*

Saving, restoring and migrating domains are not currently supported on arm and arm64 platforms, so xendomains prints the warning:

An error occurred while saving domain:
command not implemented

when attempting to run xendomains stop. It otherwise continues to shut down the domains cleanly, with the unsupported steps skipped.

Also in sysconfig.xendomains, change "Default" to "Example" as the real default is an empty value.

---

Peter, what do you think of this approach?

For reference, there's also a way to findout if a macro exist, with AC_CHECK_DECL(), but the libxl.h header depends on other headers that needs to be generated.

---
 tools/configure                                    | 11 +++++++++++
 tools/configure.ac                                 | 13 +++++++++++++
 tools/hotplug/Linux/init.d/sysconfig.xendomains.in |  4 ++--
 3 files changed, 26 insertions(+), 2 deletions(-)
tools/configure +11 -0
index 52b4717d01..a722f72c08 100755
@@ -624,6 +624,7 @@ ac_includes_default="\
 
 ac_subst_vars='LTLIBOBJS
 LIBOBJS
+XENDOMAINS_SAVE_DIR
 pvshim
 ninepfs
 SYSTEMD_LIBS
@@ -10155,6 +10156,16 @@ if test "$ax_found" = "0"; then :
 fi
 
 
+case "$host_cpu" in
+    arm*|aarch64)
+        XENDOMAINS_SAVE_DIR=
+        ;;
+    *)
+        XENDOMAINS_SAVE_DIR="$XEN_LIB_DIR/save"
+        ;;
+esac
+
+
 cat >confcache <<\_ACEOF
 # This file is a shell script that caches the results of configure
 # tests run on this system so they can be shared between configure
tools/configure.ac +13 -0
index 3cccf41960..0f0983f6b7 100644
@@ -517,4 +517,17 @@ AS_IF([test "x$pvshim" = "xy"], [
 
 AX_FIND_HEADER([INCLUDE_ENDIAN_H], [endian.h sys/endian.h])
 
+dnl Disable autosave of domain in xendomains on shutdown
+dnl due to missing support. This should be in sync with
+dnl LIBXL_HAVE_NO_SUSPEND_RESUME in libxl.h
+case "$host_cpu" in
+    arm*|aarch64)
+        XENDOMAINS_SAVE_DIR=
+        ;;
+    *)
+        XENDOMAINS_SAVE_DIR="$XEN_LIB_DIR/save"
+        ;;
+esac
+AC_SUBST(XENDOMAINS_SAVE_DIR)
+
 AC_OUTPUT()
tools/hotplug/Linux/init.d/sysconfig.xendomains.in +2 -2
index f61ef9c4d1..3c49f18bb0 100644
@@ -45,7 +45,7 @@ XENDOMAINS_CREATE_USLEEP=5000000
 XENDOMAINS_MIGRATE=""
 
 ## Type: string
-## Default: @XEN_LIB_DIR@/save
+## Example: @XEN_LIB_DIR@/save
 #
 # Directory to save running domains to when the system (dom0) is
 # shut down. Will also be used to restore domains from if # XENDOMAINS_RESTORE
@@ -53,7 +53,7 @@ XENDOMAINS_MIGRATE=""
 # (e.g. because you rather shut domains down).
 # If domain saving does succeed, SHUTDOWN will not be executed.
 #
-XENDOMAINS_SAVE=@XEN_LIB_DIR@/save
+XENDOMAINS_SAVE=@XENDOMAINS_SAVE_DIR@
 
 ## Type: string
 ## Default: "--wait"
Signature · 1 line
Anthony PERARD
author Tested-by on v1 1/1
#5 lore raw

Re: [XEN PATCH] tools/xendomains: Don't auto save/restore/migrate on Arm*

Quoted 9 lines · Anthony PERARD

Saving, restoring and migrating domains are not currently supported on arm and arm64 platforms, so xendomains prints the warning:

An error occurred while saving domain:
command not implemented

when attempting to run xendomains stop. It otherwise continues to shut down the domains cleanly, with the unsupported steps skipped.

Quoted 8 lines

Also in sysconfig.xendomains, change "Default" to "Example" as the real default is an empty value.

---

Peter, what do you think of this approach?

Thanks for preparing this. Just validated that the warning above is not present with both qemu-aarch64 and an internal stack.

Quoted 83 lines

For reference, there's also a way to findout if a macro exist, with AC_CHECK_DECL(), but the libxl.h header depends on other headers that needs to be generated.

---
  tools/configure                                    | 11 +++++++++++
  tools/configure.ac                                 | 13 +++++++++++++
  tools/hotplug/Linux/init.d/sysconfig.xendomains.in |  4 ++--
  3 files changed, 26 insertions(+), 2 deletions(-)
tools/configure +11 -0
index 52b4717d01..a722f72c08 100755
@@ -624,6 +624,7 @@ ac_includes_default="\
 
  ac_subst_vars='LTLIBOBJS
  LIBOBJS
+XENDOMAINS_SAVE_DIR
  pvshim
  ninepfs
  SYSTEMD_LIBS
@@ -10155,6 +10156,16 @@ if test "$ax_found" = "0"; then :
  fi
 
 
+case "$host_cpu" in
+    arm*|aarch64)
+        XENDOMAINS_SAVE_DIR=
+        ;;
+    *)
+        XENDOMAINS_SAVE_DIR="$XEN_LIB_DIR/save"
+        ;;
+esac
+
+
  cat >confcache <<\_ACEOF
  # This file is a shell script that caches the results of configure
  # tests run on this system so they can be shared between configure
tools/configure.ac +13 -0
index 3cccf41960..0f0983f6b7 100644
@@ -517,4 +517,17 @@ AS_IF([test "x$pvshim" = "xy"], [
 
  AX_FIND_HEADER([INCLUDE_ENDIAN_H], [endian.h sys/endian.h])
 
+dnl Disable autosave of domain in xendomains on shutdown
+dnl due to missing support. This should be in sync with
+dnl LIBXL_HAVE_NO_SUSPEND_RESUME in libxl.h
+case "$host_cpu" in
+    arm*|aarch64)
+        XENDOMAINS_SAVE_DIR=
+        ;;
+    *)
+        XENDOMAINS_SAVE_DIR="$XEN_LIB_DIR/save"
+        ;;
+esac
+AC_SUBST(XENDOMAINS_SAVE_DIR)
+
  AC_OUTPUT()
tools/hotplug/Linux/init.d/sysconfig.xendomains.in +2 -2
index f61ef9c4d1..3c49f18bb0 100644
@@ -45,7 +45,7 @@ XENDOMAINS_CREATE_USLEEP=5000000
  XENDOMAINS_MIGRATE=""
 
  ## Type: string
-## Default: @XEN_LIB_DIR@/save
+## Example: @XEN_LIB_DIR@/save
  #
  # Directory to save running domains to when the system (dom0) is
  # shut down. Will also be used to restore domains from if # XENDOMAINS_RESTORE
@@ -53,7 +53,7 @@ XENDOMAINS_MIGRATE=""
  # (e.g. because you rather shut domains down).
  # If domain saving does succeed, SHUTDOWN will not be executed.
  #
-XENDOMAINS_SAVE=@XEN_LIB_DIR@/save
+XENDOMAINS_SAVE=@XENDOMAINS_SAVE_DIR@
 
  ## Type: string
  ## Default: "--wait"
#6 lore raw

Re: [XEN PATCH] tools/xendomains: Don't auto save/restore/migrate on Arm*

In reply to Anthony PERARD

Hi Anthony,

Quoted 61 lines · Anthony PERARD

Saving, restoring and migrating domains are not currently supported on arm and arm64 platforms, so xendomains prints the warning:

An error occurred while saving domain:
command not implemented

when attempting to run xendomains stop. It otherwise continues to shut down the domains cleanly, with the unsupported steps skipped.

Also in sysconfig.xendomains, change "Default" to "Example" as the real default is an empty value.

---

Peter, what do you think of this approach?

For reference, there's also a way to findout if a macro exist, with AC_CHECK_DECL(), but the libxl.h header depends on other headers that needs to be generated.

---
  tools/configure                                    | 11 +++++++++++
  tools/configure.ac                                 | 13 +++++++++++++
  tools/hotplug/Linux/init.d/sysconfig.xendomains.in |  4 ++--
  3 files changed, 26 insertions(+), 2 deletions(-)
tools/configure +11 -0
index 52b4717d01..a722f72c08 100755
@@ -624,6 +624,7 @@ ac_includes_default="\
 
  ac_subst_vars='LTLIBOBJS
  LIBOBJS
+XENDOMAINS_SAVE_DIR
  pvshim
  ninepfs
  SYSTEMD_LIBS
@@ -10155,6 +10156,16 @@ if test "$ax_found" = "0"; then :
  fi
 
 
+case "$host_cpu" in
+    arm*|aarch64)
+        XENDOMAINS_SAVE_DIR=
+        ;;
+    *)
+        XENDOMAINS_SAVE_DIR="$XEN_LIB_DIR/save"
+        ;;
+esac
+
+
  cat >confcache <<\_ACEOF
  # This file is a shell script that caches the results of configure
  # tests run on this system so they can be shared between configure
tools/configure.ac +0 -0
index 3cccf41960..0f0983f6b7 100644

tools/configure.ac AS_IF([test "x$pvshim" = "xy"], [ · line 522

Quoted 6 lines
tools/configure.ac +3 -0
@@ -517,4 +517,17 @@ AS_IF([test "x$pvshim" = "xy"], [
 
  AX_FIND_HEADER([INCLUDE_ENDIAN_H], [endian.h sys/endian.h])
 
+dnl Disable autosave of domain in xendomains on shutdown
+dnl due to missing support. This should be in sync with
+dnl LIBXL_HAVE_NO_SUSPEND_RESUME in libxl.h

Quite likely, a developer adding a new arch will first look at the definition of LIXBL_HAVE_NO_SUSPEND_RESUME. So it would be good if we have a similar message there to remind them to update this case. That said...

tools/configure.ac AS_IF([test "x$pvshim" = "xy"], [ · line 530

Quoted 8 lines
tools/configure.ac +8 -0
+case "$host_cpu" in
+    arm*|aarch64)
+        XENDOMAINS_SAVE_DIR=
+        ;;
+    *)
+        XENDOMAINS_SAVE_DIR="$XEN_LIB_DIR/save"
+        ;;
+esac

... I am wondering if the switch should be the other way around. IOW, the default should be no support for suspend/resume. This will make easier to add support for RISC-V (I suspect support for suspend/resume will not be in the first version) or any new other arch.

Cheers,

Signature · 1 line
Julien Grall
#7 lore raw

Re: [XEN PATCH] tools/xendomains: Don't auto save/restore/migrate on Arm*

Quoted 14 lines · Julien Grall

tools/configure.ac AS_IF([test "x$pvshim" = "xy"], [ · line 520

Quoted 9 lines · Anthony PERARD
tools/configure.ac +3 -0
index 3cccf41960..0f0983f6b7 100644
@@ -517,4 +517,17 @@ AS_IF([test "x$pvshim" = "xy"], [
  AX_FIND_HEADER([INCLUDE_ENDIAN_H], [endian.h sys/endian.h])
+dnl Disable autosave of domain in xendomains on shutdown
+dnl due to missing support. This should be in sync with
+dnl LIBXL_HAVE_NO_SUSPEND_RESUME in libxl.h

Quite likely, a developer adding a new arch will first look at the definition of LIXBL_HAVE_NO_SUSPEND_RESUME. So it would be good if we have a similar message there to remind them to update this case. That said...

Probably true, I'll look at adding a comment there.

Quoted 5 lines
Quoted 5 lines
tools/configure.ac +5 -0
+case "$host_cpu" in
+    arm*|aarch64)
+        XENDOMAINS_SAVE_DIR=
+        ;;
+    *)
Quoted 8 lines

tools/configure.ac AS_IF([test "x$pvshim" = "xy"], [ · line 528

Quoted 3 lines
tools/configure.ac +3 -0
+        XENDOMAINS_SAVE_DIR="$XEN_LIB_DIR/save"
+        ;;
+esac

... I am wondering if the switch should be the other way around. IOW, the default should be no support for suspend/resume. This will make easier to add support for RISC-V (I suspect support for suspend/resume will not be in the first version) or any new other arch.

Sounds good, I'll look at that.

Thanks,

Signature · 1 line
Anthony PERARD
#8 lore raw
In reply to Peter Hoyes
Quoted 12 lines · Peter Hoyes

From: Peter Hoyes <[email protected]>

Saving, restoring and migrating domains are not currently supported on arm and arm64 platforms, so xendomains prints the warning:

An error occurred while saving domain:
command not implemented

Quoted 8 lines

when attempting to run xendomains stop. It otherwise continues to shut down the domains cleanly, with the unsupported steps skipped.

Use xl help to detect whether save/restore/migrate is supported by the platform. If not, do not attempt to run the corresponding command.

---

Hi Anthony,

Regarding this patch, is there any update?

I’m asking just because here https://patchwork.kernel.org/project/xen-devel/patch/[email protected]/ it seems you were volunteering to fix that in another way.

Cheers,
Luca

#9 lore raw
Quoted 18 lines · Luca Fancellu
Quoted 18 lines · Peter Hoyes

From: Peter Hoyes <[email protected]>

Saving, restoring and migrating domains are not currently supported on arm and arm64 platforms, so xendomains prints the warning:

An error occurred while saving domain:
command not implemented

when attempting to run xendomains stop. It otherwise continues to shut down the domains cleanly, with the unsupported steps skipped.

Use xl help to detect whether save/restore/migrate is supported by the platform. If not, do not attempt to run the corresponding command.

Quoted 8 lines
Quoted 2 lines

---

Hi Anthony,

Regarding this patch, is there any update?

I’m asking just because here https://patchwork.kernel.org/project/xen-devel/patch/[email protected]/ it seems you were volunteering to fix that in another way.

I did, https://patchwork.kernel.org/project/xen-devel/patch/[email protected]/
But looks like I need to update the patch.

I think it's a bit late for 3.18, but I should be able to update the patch for next release.

Cheers,

Signature · 1 line
Anthony PERARD