The <description> and <title> elements are accessible only through the XML, that makes it hard to work with. Atomic operations and modification of the live domain are impossible. This patch adds a function to the public API to set arbitrary descriptions for live and persistent domains. *include/libvirt/libvirt.h.in - add api function virDomainSetDescription - add flags for this new api *src/driver.h *src/libvirt.c - add driver support - implement the public api *src/libvirt_public.syms - export the new function *src/remote/remote_driver.c *src/remote/remote_protocol.x - wire up the remote protocol --- Changes to v1: - tweaked spellings - left out "renaming" of flags. Now there's just a reference to VIR_DOMAIN_AFFECT_* - reject setting flags on read-only connections include/libvirt/libvirt.h.in | 10 ++++++++ src/driver.h | 5 ++++ src/libvirt.c | 52 ++++++++++++++++++++++++++++++++++++++++++ src/libvirt_public.syms | 5 ++++ src/remote/remote_driver.c | 1 + src/remote/remote_protocol.x | 9 ++++++- 6 files changed, 81 insertions(+), 1 deletions(-) diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index e436f3c..40e0032 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -1405,6 +1405,16 @@ int virDomainGetMaxVcpus (virDomainPtr domain); int virDomainGetSecurityLabel (virDomainPtr domain, virSecurityLabelPtr seclabel); +typedef enum { + /* bits 0 and 1 are reserverd for @virDomainModificationImpact */ + VIR_DOMAIN_DESCRIPTION_TITLE = (1 << 2), /* Operate on title instead of + the domain's description */ +} virDomainDescriptionFlags; + +int virDomainSetDescription(virDomainPtr domain, + const char *description, + unsigned int flags); + /* * XML domain description */ diff --git a/src/driver.h b/src/driver.h index 24636a4..afb8f3c 100644 --- a/src/driver.h +++ b/src/driver.h @@ -793,6 +793,10 @@ typedef int virTypedParameterPtr params, int *nparams, unsigned int flags); +typedef int + (*virDrvDomainSetDescription)(virDomainPtr dom, + const char *description, + unsigned int flags); /** * _virDriver: @@ -962,6 +966,7 @@ struct _virDriver { virDrvNodeSuspendForDuration nodeSuspendForDuration; virDrvDomainSetBlockIoTune domainSetBlockIoTune; virDrvDomainGetBlockIoTune domainGetBlockIoTune; + virDrvDomainSetDescription domainSetDescription; }; typedef int diff --git a/src/libvirt.c b/src/libvirt.c index 7b8adf7..177d52d 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -8746,6 +8746,58 @@ error: } /** + * virDomainSetDescription: + * @domain: a domain object + * @description: new description text + * @flags: bitwise-OR of virDomainDescriptionFlags + * + * Sets the domain description field or note field depending on the flags + * parameter. + * + * Returns 0 on success, -1 in case of failure; + */ +int +virDomainSetDescription(virDomainPtr domain, + const char *description, + unsigned int flags) +{ + virConnectPtr conn; + + VIR_DOMAIN_DEBUG(domain, "description=%p, flags=%x", description, flags); + + if (!VIR_IS_CONNECTED_DOMAIN(domain)) { + virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__); + goto error; + } + + if (description == NULL) { + virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__); + goto error; + } + + conn = domain->conn; + + if (conn->flags & VIR_CONNECT_RO) { + virLibDomainError(VIR_ERR_OPERATION_DENIED, __FUNCTION__); + goto error; + } + + if (conn->driver->domainSetDescription) { + int ret; + ret = conn->driver->domainSetDescription(domain, description, flags); + if (ret < 0) + goto error; + return ret; + } + + virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__); + +error: + virDispatchError(domain->conn); + return -1; +} + +/** * virNodeGetSecurityModel: * @conn: a connection object * @secmodel: pointer to a virSecurityModel structure diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 4ca7216..882b746 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -516,4 +516,9 @@ LIBVIRT_0.9.9 { virDomainSetNumaParameters; } LIBVIRT_0.9.8; +LIBVIRT_0.9.10 { + global: + virDomainSetDescription; +} LIBVIRT_0.9.9; + # .... define new API here using predicted next version number .... diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index e28840b..4d64bc9 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -4750,6 +4750,7 @@ static virDriver remote_driver = { .domainGetBlockIoTune = remoteDomainGetBlockIoTune, /* 0.9.8 */ .domainSetNumaParameters = remoteDomainSetNumaParameters, /* 0.9.9 */ .domainGetNumaParameters = remoteDomainGetNumaParameters, /* 0.9.9 */ + .domainSetDescription = remoteDomainSetDescription, /* 0.9.10 */ }; static virNetworkDriver network_driver = { diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index ca739ff..ad3e12f 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -1095,6 +1095,12 @@ struct remote_domain_set_autostart_args { int autostart; }; +struct remote_domain_set_description_args { + remote_nonnull_domain dom; + remote_nonnull_string description; + unsigned int flags; +}; + struct remote_domain_block_job_abort_args { remote_nonnull_domain dom; remote_nonnull_string path; @@ -2653,7 +2659,8 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_SET_NUMA_PARAMETERS = 254, /* autogen autogen */ REMOTE_PROC_DOMAIN_GET_NUMA_PARAMETERS = 255, /* skipgen skipgen */ REMOTE_PROC_DOMAIN_SET_INTERFACE_PARAMETERS = 256, /* autogen autogen */ - REMOTE_PROC_DOMAIN_GET_INTERFACE_PARAMETERS = 257 /* skipgen skipgen */ + REMOTE_PROC_DOMAIN_GET_INTERFACE_PARAMETERS = 257, /* skipgen skipgen */ + REMOTE_PROC_DOMAIN_SET_DESCRIPTION = 258 /* autogen autogen */ /* * Notice how the entries are grouped in sets of 10 ? -- 1.7.3.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list