The API can be used to query current state of an interface to VMM used to control a domain. In QEMU world this translates into monitor connection. --- include/libvirt/libvirt.h.in | 40 ++++++++++++++++++++++++++++++++ python/generator.py | 1 + python/libvirt-override-api.xml | 6 +++++ src/driver.h | 5 ++++ src/libvirt.c | 48 +++++++++++++++++++++++++++++++++++++++ src/libvirt_public.syms | 5 ++++ 6 files changed, 105 insertions(+), 0 deletions(-) diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index df213f1..1454ca0 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -141,6 +141,43 @@ typedef enum { VIR_DOMAIN_CRASHED_UNKNOWN = 0, /* crashed for unknown reason */ } virDomainCrashedReason; + +/** + * virDomainControlState: + * + * Current state of a control interface to the domain. + */ +typedef enum { + VIR_DOMAIN_CONTROL_OK = 0, /* operational, ready to accept commands */ + VIR_DOMAIN_CONTROL_JOB = 1, /* background job is running (can be + monitored by virDomainGetJobInfo); only + limited set of commands may be allowed */ + VIR_DOMAIN_CONTROL_OCCUPIED = 2, /* occupied by a running command */ + VIR_DOMAIN_CONTROL_ERROR = 3, /* unusable, domain cannot be fully operated */ +} virDomainControlState; + +/** + * virDomainControlInfo: + * + * Structure filled in by virDomainGetControlInfo and providing details about + * current state of control interface to a domain. + */ +typedef struct _virDomainControlInfo virDomainControlInfo; +struct _virDomainControlInfo { + unsigned int state; /* control state, one of virDomainControlState */ + unsigned int details; /* state details, currently 0 */ + unsigned long long stateTime; /* for how long (in msec) control interface + has been in current state (except for OK + and ERROR states) */ +}; + +/** + * virDomainControlInfoPtr: + * + * Pointer to virDomainControlInfo structure. + */ +typedef virDomainControlInfo *virDomainControlInfoPtr; + /** * virDomainModificationImpact: * @@ -781,6 +818,9 @@ int virDomainGetState (virDomainPtr domain, int *state, int *reason, unsigned int flags); +int virDomainGetControlInfo (virDomainPtr domain, + virDomainControlInfoPtr info, + unsigned int flags); /* * Return scheduler type in effect 'sedf', 'credit', 'linux' diff --git a/python/generator.py b/python/generator.py index 7c38fdd..4e3e9fa 100755 --- a/python/generator.py +++ b/python/generator.py @@ -306,6 +306,7 @@ skip_impl = ( 'virGetLastError', 'virDomainGetInfo', 'virDomainGetState', + 'virDomainGetControlInfo', 'virDomainGetBlockInfo', 'virDomainGetJobInfo', 'virNodeGetInfo', diff --git a/python/libvirt-override-api.xml b/python/libvirt-override-api.xml index ec08e69..01207d6 100644 --- a/python/libvirt-override-api.xml +++ b/python/libvirt-override-api.xml @@ -54,6 +54,12 @@ <arg name='domain' type='virDomainPtr' info='a domain object'/> <arg name='flags' type='unsigned int' info='additional flags'/> </function> + <function name='virDomainGetControlInfo' file='python'> + <info>Extract details about current state of control interface to a domain.</info> + <return type='int *' info='the list of information or None in case of error'/> + <arg name='domain' type='virDomainPtr' info='a domain object'/> + <arg name='flags' type='unsigned int' info='additional flags'/> + </function> <function name='virDomainGetBlockInfo' file='python'> <info>Extract information about a domain block device size</info> <return type='int *' info='the list of information or None in case of error'/> diff --git a/src/driver.h b/src/driver.h index 5df798a..ca49b08 100644 --- a/src/driver.h +++ b/src/driver.h @@ -171,6 +171,10 @@ typedef int int *reason, unsigned int flags); typedef int + (*virDrvDomainGetControlInfo) (virDomainPtr domain, + virDomainControlInfoPtr info, + unsigned int flags); +typedef int (*virDrvDomainSave) (virDomainPtr domain, const char *to); typedef int @@ -663,6 +667,7 @@ struct _virDriver { virDrvDomainGetBlkioParameters domainGetBlkioParameters; virDrvDomainGetInfo domainGetInfo; virDrvDomainGetState domainGetState; + virDrvDomainGetControlInfo domainGetControlInfo; virDrvDomainSave domainSave; virDrvDomainRestore domainRestore; virDrvDomainCoreDump domainCoreDump; diff --git a/src/libvirt.c b/src/libvirt.c index 18c4e08..81dd879 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -3261,6 +3261,54 @@ error: } /** + * virDomainGetControlInfo: + * @domain: a domain object + * @info: pointer to a virDomainControlInfo structure allocated by the user + * @flags: additional flags, 0 for now + * + * Extract details about current state of control interface to a domain. + * + * Returns 0 in case of success and -1 in case of failure. + */ +int +virDomainGetControlInfo(virDomainPtr domain, + virDomainControlInfoPtr info, + unsigned int flags) +{ + virConnectPtr conn; + + VIR_DOMAIN_DEBUG(domain, "info=%p", info); + + virResetLastError(); + + if (!VIR_IS_CONNECTED_DOMAIN(domain)) { + virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__); + virDispatchError(NULL); + return -1; + } + + if (!info) { + virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__); + goto error; + } + + conn = domain->conn; + if (conn->driver->domainGetControlInfo) { + int ret; + ret = conn->driver->domainGetControlInfo(domain, info, flags); + if (ret < 0) + goto error; + return ret; + } + + virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__); + +error: + virDispatchError(domain->conn); + return -1; +} + +/** * virDomainGetXMLDesc: * @domain: a domain object * @flags: an OR'ed set of virDomainXMLFlags diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 4d4299a..0e55097 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -450,4 +450,9 @@ LIBVIRT_0.9.2 { virInterfaceChangeRollback; } LIBVIRT_0.9.0; +LIBVIRT_0.9.3 { + global: + virDomainGetControlInfo; +} LIBVIRT_0.9.2; + # .... define new API here using predicted next version number .... -- 1.7.5.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list