Introduce virDomainPMSuspendForDuration API

This API allows a domain to be put into one of S# ACPI states.
Currently, S3 and S4 are supported. These states are shared
with virNodeSuspendForDuration.
However, for now we don't support any duration other than zero.
The same apply for flags.
This commit is contained in:
Michal Privoznik 2012-01-26 19:05:46 +01:00
parent 835817806e
commit 8f8b080263
8 changed files with 88 additions and 3 deletions

View File

@ -1232,7 +1232,10 @@ int virDomainFree (virDomainPtr domain);
*/
int virDomainSuspend (virDomainPtr domain);
int virDomainResume (virDomainPtr domain);
int virDomainPMSuspendForDuration (virDomainPtr domain,
unsigned int target,
unsigned long long duration,
unsigned int flags);
/*
* Domain save/restore
*/

View File

@ -119,6 +119,11 @@ typedef int
(*virDrvDomainSuspend) (virDomainPtr domain);
typedef int
(*virDrvDomainResume) (virDomainPtr domain);
typedef int
(*virDrvDomainPMSuspendForDuration) (virDomainPtr,
unsigned int target,
unsigned long long duration,
unsigned int flags);
typedef int
(*virDrvDomainShutdown) (virDomainPtr domain);
typedef int
@ -831,6 +836,7 @@ struct _virDriver {
virDrvDomainLookupByUUID domainLookupByUUID;
virDrvDomainLookupByName domainLookupByName;
virDrvDomainSuspend domainSuspend;
virDrvDomainPMSuspendForDuration domainPMSuspendForDuration;
virDrvDomainResume domainResume;
virDrvDomainShutdown domainShutdown;
virDrvDomainShutdownFlags domainShutdownFlags;

View File

@ -2432,6 +2432,64 @@ error:
return -1;
}
/**
* virDomainPMSuspendForDuration:
* @dom: a domain object
* @target: an OR'ed set of virNodeSuspendTarget
* @duration: currently unused, pass 0
* @flags: ditto
*
* Attempt to suspend given domain. However, more
* states are supported than in virDomainSuspend.
*
* Dependent on hypervisor used, this may require
* guest agent to be available, e.g. QEMU.
*
* Returns: 0 on success,
* -1 on failure.
*/
int
virDomainPMSuspendForDuration(virDomainPtr dom,
unsigned int target,
unsigned long long duration,
unsigned int flags)
{
virConnectPtr conn;
VIR_DOMAIN_DEBUG(dom, "target=%u duration=%llu flags=%x",
target, duration, flags);
virResetLastError();
if (!VIR_IS_CONNECTED_DOMAIN(dom)) {
virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
virDispatchError(NULL);
return -1;
}
conn = dom->conn;
if (conn->flags & VIR_CONNECT_RO) {
virLibConnError(VIR_ERR_OPERATION_DENIED, __FUNCTION__);
goto error;
}
if (conn->driver->domainPMSuspendForDuration) {
int ret;
ret = conn->driver->domainPMSuspendForDuration(dom, target,
duration, flags);
if (ret < 0)
goto error;
return ret;
}
virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
error:
virDispatchError(conn);
return -1;
}
/**
* virDomainSave:
* @domain: a domain object

View File

@ -521,6 +521,7 @@ LIBVIRT_0.9.10 {
virDomainShutdownFlags;
virStorageVolResize;
virStorageVolWipePattern;
virDomainPMSuspendForDuration;
} LIBVIRT_0.9.9;
# .... define new API here using predicted next version number ....

View File

@ -4616,6 +4616,7 @@ static virDriver remote_driver = {
.domainLookupByName = remoteDomainLookupByName, /* 0.3.0 */
.domainSuspend = remoteDomainSuspend, /* 0.3.0 */
.domainResume = remoteDomainResume, /* 0.3.0 */
.domainPMSuspendForDuration = remoteDomainPMSuspendForDuration, /* 0.9.10 */
.domainShutdown = remoteDomainShutdown, /* 0.3.0 */
.domainShutdownFlags = remoteDomainShutdownFlags, /* 0.9.10 */
.domainReboot = remoteDomainReboot, /* 0.3.0 */

View File

@ -732,6 +732,13 @@ struct remote_domain_suspend_args {
remote_nonnull_domain dom;
};
struct remote_domain_pm_suspend_for_duration_args {
remote_nonnull_domain dom;
unsigned int target;
unsigned hyper duration;
unsigned int flags;
};
struct remote_domain_resume_args {
remote_nonnull_domain dom;
};
@ -2674,7 +2681,9 @@ enum remote_procedure {
REMOTE_PROC_DOMAIN_GET_INTERFACE_PARAMETERS = 257, /* skipgen skipgen */
REMOTE_PROC_DOMAIN_SHUTDOWN_FLAGS = 258, /* autogen autogen */
REMOTE_PROC_STORAGE_VOL_WIPE_PATTERN = 259, /* autogen autogen */
REMOTE_PROC_STORAGE_VOL_RESIZE = 260 /* autogen autogen */
REMOTE_PROC_STORAGE_VOL_RESIZE = 260, /* autogen autogen */
REMOTE_PROC_DOMAIN_PM_SUSPEND_FOR_DURATION = 261 /* autogen autogen */
/*
* Notice how the entries are grouped in sets of 10 ?

View File

@ -440,6 +440,12 @@ struct remote_domain_lookup_by_name_ret {
struct remote_domain_suspend_args {
remote_nonnull_domain dom;
};
struct remote_domain_pm_suspend_for_duration_args {
remote_nonnull_domain dom;
u_int target;
uint64_t duration;
u_int flags;
};
struct remote_domain_resume_args {
remote_nonnull_domain dom;
};
@ -2107,4 +2113,5 @@ enum remote_procedure {
REMOTE_PROC_DOMAIN_SHUTDOWN_FLAGS = 258,
REMOTE_PROC_STORAGE_VOL_WIPE_PATTERN = 259,
REMOTE_PROC_STORAGE_VOL_RESIZE = 260,
REMOTE_PROC_DOMAIN_PM_SUSPEND_FOR_DURATION = 261,
};

View File

@ -37,7 +37,7 @@ sub name_to_ProcName {
@elems = map { $_ =~ s/Nwfilter/NWFilter/; $_ =~ s/Xml$/XML/;
$_ =~ s/Uri$/URI/; $_ =~ s/Uuid$/UUID/; $_ =~ s/Id$/ID/;
$_ =~ s/Mac$/MAC/; $_ =~ s/Cpu$/CPU/; $_ =~ s/Os$/OS/;
$_ =~ s/Nmi$/NMI/; $_ } @elems;
$_ =~ s/Nmi$/NMI/; $_ =~ s/Pm/PM/; $_ } @elems;
join "", @elems
}