mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 19:45:21 +00:00
Move suspend capabilities APIs out of util.h into virnodesuspend.c
The node suspend capabilities APIs should not have been put into util.[ch]. Instead move them into virnodesuspend.[ch] * src/util/util.c, src/util/util.h: Remove suspend capabilities APIs * src/util/virnodesuspend.c, src/util/virnodesuspend.h: Add suspend capabilities APIs * src/qemu/qemu_capabilities.c: Include virnodesuspend.h
This commit is contained in:
parent
53c2aad88b
commit
c92653f4dd
@ -34,6 +34,7 @@
|
||||
#include "domain_conf.h"
|
||||
#include "qemu_conf.h"
|
||||
#include "command.h"
|
||||
#include "virnodesuspend.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
@ -2621,99 +2621,3 @@ virTypedParameterArrayClear(virTypedParameterPtr params, int nparams)
|
||||
VIR_FREE(params[i].value.s);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* virNodeSuspendSupportsTarget:
|
||||
* @target: The power management target to check whether it is supported
|
||||
* by the host. Values could be:
|
||||
* VIR_NODE_SUSPEND_TARGET_MEM
|
||||
* VIR_NODE_SUSPEND_TARGET_DISK
|
||||
* VIR_NODE_SUSPEND_TARGET_HYBRID
|
||||
* @supported: set to true if supported, false otherwise
|
||||
*
|
||||
* Run the script 'pm-is-supported' (from the pm-utils package)
|
||||
* to find out if @target is supported by the host.
|
||||
*
|
||||
* Returns 0 if the query was successful, -1 on failure.
|
||||
*/
|
||||
int
|
||||
virNodeSuspendSupportsTarget(unsigned int target, bool *supported)
|
||||
{
|
||||
virCommandPtr cmd;
|
||||
int status;
|
||||
int ret = -1;
|
||||
|
||||
*supported = false;
|
||||
|
||||
switch (target) {
|
||||
case VIR_NODE_SUSPEND_TARGET_MEM:
|
||||
cmd = virCommandNewArgList("pm-is-supported", "--suspend", NULL);
|
||||
break;
|
||||
case VIR_NODE_SUSPEND_TARGET_DISK:
|
||||
cmd = virCommandNewArgList("pm-is-supported", "--hibernate", NULL);
|
||||
break;
|
||||
case VIR_NODE_SUSPEND_TARGET_HYBRID:
|
||||
cmd = virCommandNewArgList("pm-is-supported", "--suspend-hybrid", NULL);
|
||||
break;
|
||||
default:
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (virCommandRun(cmd, &status) < 0)
|
||||
goto cleanup;
|
||||
|
||||
/*
|
||||
* Check return code of command == 0 for success
|
||||
* (i.e., the PM capability is supported)
|
||||
*/
|
||||
*supported = (status == 0);
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
virCommandFree(cmd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* virNodeSuspendGetTargetMask:
|
||||
*
|
||||
* 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 targets.
|
||||
*
|
||||
* Returns 0 if the query was successful, -1 on failure.
|
||||
*/
|
||||
int
|
||||
virNodeSuspendGetTargetMask(unsigned int *bitmask)
|
||||
{
|
||||
int ret;
|
||||
bool supported;
|
||||
|
||||
*bitmask = 0;
|
||||
|
||||
/* Check support for Suspend-to-RAM (S3) */
|
||||
ret = virNodeSuspendSupportsTarget(VIR_NODE_SUSPEND_TARGET_MEM, &supported);
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
if (supported)
|
||||
*bitmask |= (1 << VIR_NODE_SUSPEND_TARGET_MEM);
|
||||
|
||||
/* Check support for Suspend-to-Disk (S4) */
|
||||
ret = virNodeSuspendSupportsTarget(VIR_NODE_SUSPEND_TARGET_DISK, &supported);
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
if (supported)
|
||||
*bitmask |= (1 << VIR_NODE_SUSPEND_TARGET_DISK);
|
||||
|
||||
/* Check support for Hybrid-Suspend */
|
||||
ret = virNodeSuspendSupportsTarget(VIR_NODE_SUSPEND_TARGET_HYBRID, &supported);
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
if (supported)
|
||||
*bitmask |= (1 << VIR_NODE_SUSPEND_TARGET_HYBRID);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -261,9 +261,4 @@ int virEmitXMLWarning(int fd,
|
||||
|
||||
void virTypedParameterArrayClear(virTypedParameterPtr params, int nparams);
|
||||
|
||||
/* Power Management Capabilities of the host system */
|
||||
|
||||
int virNodeSuspendSupportsTarget(unsigned int target, bool *supported);
|
||||
int virNodeSuspendGetTargetMask(unsigned int *bitmask);
|
||||
|
||||
#endif /* __VIR_UTIL_H__ */
|
||||
|
@ -269,3 +269,100 @@ cleanup:
|
||||
VIR_FREE(cmdString);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virNodeSuspendSupportsTarget:
|
||||
* @target: The power management target to check whether it is supported
|
||||
* by the host. Values could be:
|
||||
* VIR_NODE_SUSPEND_TARGET_MEM
|
||||
* VIR_NODE_SUSPEND_TARGET_DISK
|
||||
* VIR_NODE_SUSPEND_TARGET_HYBRID
|
||||
* @supported: set to true if supported, false otherwise
|
||||
*
|
||||
* Run the script 'pm-is-supported' (from the pm-utils package)
|
||||
* to find out if @target is supported by the host.
|
||||
*
|
||||
* Returns 0 if the query was successful, -1 on failure.
|
||||
*/
|
||||
static int
|
||||
virNodeSuspendSupportsTarget(unsigned int target, bool *supported)
|
||||
{
|
||||
virCommandPtr cmd;
|
||||
int status;
|
||||
int ret = -1;
|
||||
|
||||
*supported = false;
|
||||
|
||||
switch (target) {
|
||||
case VIR_NODE_SUSPEND_TARGET_MEM:
|
||||
cmd = virCommandNewArgList("pm-is-supported", "--suspend", NULL);
|
||||
break;
|
||||
case VIR_NODE_SUSPEND_TARGET_DISK:
|
||||
cmd = virCommandNewArgList("pm-is-supported", "--hibernate", NULL);
|
||||
break;
|
||||
case VIR_NODE_SUSPEND_TARGET_HYBRID:
|
||||
cmd = virCommandNewArgList("pm-is-supported", "--suspend-hybrid", NULL);
|
||||
break;
|
||||
default:
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (virCommandRun(cmd, &status) < 0)
|
||||
goto cleanup;
|
||||
|
||||
/*
|
||||
* Check return code of command == 0 for success
|
||||
* (i.e., the PM capability is supported)
|
||||
*/
|
||||
*supported = (status == 0);
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
virCommandFree(cmd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* virNodeSuspendGetTargetMask:
|
||||
*
|
||||
* 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 targets.
|
||||
*
|
||||
* Returns 0 if the query was successful, -1 on failure.
|
||||
*/
|
||||
int
|
||||
virNodeSuspendGetTargetMask(unsigned int *bitmask)
|
||||
{
|
||||
int ret;
|
||||
bool supported;
|
||||
|
||||
*bitmask = 0;
|
||||
|
||||
/* Check support for Suspend-to-RAM (S3) */
|
||||
ret = virNodeSuspendSupportsTarget(VIR_NODE_SUSPEND_TARGET_MEM, &supported);
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
if (supported)
|
||||
*bitmask |= (1 << VIR_NODE_SUSPEND_TARGET_MEM);
|
||||
|
||||
/* Check support for Suspend-to-Disk (S4) */
|
||||
ret = virNodeSuspendSupportsTarget(VIR_NODE_SUSPEND_TARGET_DISK, &supported);
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
if (supported)
|
||||
*bitmask |= (1 << VIR_NODE_SUSPEND_TARGET_DISK);
|
||||
|
||||
/* Check support for Hybrid-Suspend */
|
||||
ret = virNodeSuspendSupportsTarget(VIR_NODE_SUSPEND_TARGET_HYBRID, &supported);
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
if (supported)
|
||||
*bitmask |= (1 << VIR_NODE_SUSPEND_TARGET_HYBRID);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -31,6 +31,6 @@ int nodeSuspendForDuration(virConnectPtr conn,
|
||||
unsigned int flags);
|
||||
|
||||
int virNodeSuspendInit(void);
|
||||
|
||||
int virNodeSuspendGetTargetMask(unsigned int *bitmask);
|
||||
|
||||
#endif /* __VIR_NODE_SUSPEND_H__ */
|
||||
|
Loading…
Reference in New Issue
Block a user