diff --git a/docs/formatcaps.html.in b/docs/formatcaps.html.in index 423bc480ec6108713cdfe2e6445d300c390c2306..c1bc2f58e166d2d6b464dce4fab72d8dad915807 100644 --- a/docs/formatcaps.html.in +++ b/docs/formatcaps.html.in @@ -31,6 +31,7 @@ BIOS you will see

<power_management> <S3/> <S4/> + <Hybrid-Suspend/> <power_management/> </host> @@ -71,8 +72,9 @@ BIOS you will see

model, within a feature block (the block is similar to what you will find in a Xen fully virtualized domain description). Further, the power management features - supported by the host are shown, such as Suspend-to-RAM (S3) - and Suspend-to-Disk (S4). In case the query for power + supported by the host are shown, such as Suspend-to-RAM (S3), + Suspend-to-Disk (S4) and Hybrid-Suspend (a combination of S3 + and S4). In case the query for power management features succeeded but the host does not support any such feature, then an empty <power_management/> tag will be shown. Otherwise, if the query itself failed, no diff --git a/docs/schemas/capability.rng b/docs/schemas/capability.rng index 645769e330df7ac54edf48392aae94c8fef445cf..6cf21885aecbb7c4b5ea46f35e9b927b5f90033b 100644 --- a/docs/schemas/capability.rng +++ b/docs/schemas/capability.rng @@ -121,6 +121,11 @@ + + + + + diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index ac132f9ec4c448f84f735e9a4ab1dc4e8ff0fe91..70f9ab0b4985979a25a1f89092610033f7d5a371 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -37,7 +37,7 @@ #define VIR_FROM_THIS VIR_FROM_CAPABILITIES VIR_ENUM_IMPL(virHostPMCapability, VIR_HOST_PM_LAST, - "S3", "S4") + "S3", "S4", "Hybrid-Suspend") /** * virCapabilitiesNew: diff --git a/src/util/util.c b/src/util/util.c index ce697fb7b444781b6ff99ac9284ecd7951785d5d..34541ec93a9011fc87f02961690af511418aa2b0 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -2623,47 +2623,50 @@ virTypedParameterArrayClear(virTypedParameterPtr params, int nparams) } /** - * Get the Power Management Capabilities of the host system. - * The script 'pm-is-supported' (from the pm-utils package) is run - * to find out all the power management features supported by the host, - * such as Suspend-to-RAM (S3) and Suspend-to-Disk (S4). + * virDiscoverHostPMFeature: + * @bitmask: The bitmask which should be populated with the result of + * the query + * @feature: The power management feature to check whether it is supported + * by the host. Values could be: + * VIR_HOST_PM_S3 for Suspend-to-RAM + * VIR_HOST_PM_S4 for Suspend-to-Disk + * VIR_HOST_PM_HYBRID_SUSPEND for Hybrid-Suspend * - * @bitmask: Pointer to the bitmask which will be set appropriately to - * indicate all the supported host power management features. + * Run the script 'pm-is-supported' (from the pm-utils package) + * to find out if @feature is supported by the host. * - * Returns 0 if the query was successful, -1 upon failure. + * Returns 0 if the query was successful, -1 on failure. */ int -virGetPMCapabilities(unsigned int *bitmask) +virDiscoverHostPMFeature(unsigned int *bitmask, unsigned int feature) { - int ret = -1; - int status; virCommandPtr cmd; + int status; + int ret = -1; - *bitmask = 0; - - /* Check support for Suspend-to-RAM (S3) */ - cmd = virCommandNewArgList("pm-is-supported", "--suspend", NULL); - if (virCommandRun(cmd, &status) < 0) - goto cleanup; - - /* Check return code of command == 0 for success - * (i.e., the PM capability is supported) - */ - if (status == 0) - *bitmask |= 1U << VIR_HOST_PM_S3; - virCommandFree(cmd); + switch (feature) { + case VIR_HOST_PM_S3: + cmd = virCommandNewArgList("pm-is-supported", "--suspend", NULL); + break; + case VIR_HOST_PM_S4: + cmd = virCommandNewArgList("pm-is-supported", "--hibernate", NULL); + break; + case VIR_HOST_PM_HYBRID_SUSPEND: + cmd = virCommandNewArgList("pm-is-supported", "--suspend-hybrid", NULL); + break; + default: + return ret; + } - /* Check support for Suspend-to-Disk (S4) */ - cmd = virCommandNewArgList("pm-is-supported", "--hibernate", NULL); if (virCommandRun(cmd, &status) < 0) goto cleanup; - /* Check return code of command == 0 for success - * (i.e., the PM capability is supported) - */ + /* + * Check return code of command == 0 for success + * (i.e., the PM capability is supported) + */ if (status == 0) - *bitmask |= 1U << VIR_HOST_PM_S4; + *bitmask |= 1U << feature; ret = 0; @@ -2671,3 +2674,40 @@ cleanup: virCommandFree(cmd); return ret; } + +/** + * virGetPMCapabilities: + * + * Get the Power Management Capabilities that the host system supports, + * such as Suspend-to-RAM (S3), Suspend-to-Disk (S4) and Hybrid-Suspend + * (a combination of S3 and S4). + * + * @bitmask: Pointer to the bitmask which will be set appropriately to + * indicate all the supported host power management features. + * + * Returns 0 if the query was successful, -1 on failure. + */ +int +virGetPMCapabilities(unsigned int *bitmask) +{ + int ret; + + *bitmask = 0; + + /* Check support for Suspend-to-RAM (S3) */ + ret = virDiscoverHostPMFeature(bitmask, VIR_HOST_PM_S3); + if (ret < 0) + return -1; + + /* Check support for Suspend-to-Disk (S4) */ + ret = virDiscoverHostPMFeature(bitmask, VIR_HOST_PM_S4); + if (ret < 0) + return -1; + + /* Check support for Hybrid-Suspend */ + ret = virDiscoverHostPMFeature(bitmask, VIR_HOST_PM_HYBRID_SUSPEND); + if (ret < 0) + return -1; + + return 0; +} diff --git a/src/util/util.h b/src/util/util.h index 5afcf58dccc1645b41675f6b3aeb671ed9b09886..eda60d2db592c06e0f566c6a6cc8379b6bbdddf5 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -264,14 +264,16 @@ void virTypedParameterArrayClear(virTypedParameterPtr params, int nparams); /* Power Management Capabilities of the host system */ enum virHostPMCapability { - VIR_HOST_PM_S3, /* Suspend-to-RAM */ - VIR_HOST_PM_S4, /* Suspend-to-Disk */ + VIR_HOST_PM_S3, /* Suspend-to-RAM */ + VIR_HOST_PM_S4, /* Suspend-to-Disk */ + VIR_HOST_PM_HYBRID_SUSPEND, /* Hybrid-Suspend */ VIR_HOST_PM_LAST }; VIR_ENUM_DECL(virHostPMCapability) -int virGetPMCapabilities(unsigned int *); +int virDiscoverHostPMFeature(unsigned int *bitmask, unsigned int feature); +int virGetPMCapabilities(unsigned int *bitmask); #endif /* __VIR_UTIL_H__ */