[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 2/4] api: Add api to set domain note and description in runtime



The <description> element was accessible only throught 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
---
 include/libvirt/libvirt.h.in |   15 +++++++++++++
 src/driver.h                 |    5 ++++
 src/libvirt.c                |   47 ++++++++++++++++++++++++++++++++++++++++++
 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..7edbb9c 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -1405,6 +1405,21 @@ int                     virDomainGetMaxVcpus    (virDomainPtr domain);
 int                     virDomainGetSecurityLabel (virDomainPtr domain,
                                                    virSecurityLabelPtr seclabel);

+typedef enum {
+    /* See virDomainModificationImpact for these flags.  */
+    VIR_DOMAIN_DESCRIPTION_CURRENT = VIR_DOMAIN_AFFECT_CURRENT,
+    VIR_DOMAIN_DESCRIPTION_LIVE    = VIR_DOMAIN_AFFECT_LIVE,
+    VIR_DOMAIN_DESCRIPTION_CONFIG  = VIR_DOMAIN_AFFECT_CONFIG,
+    /* Additionaly, these flags may be bitwise-OR'd in. */
+    VIR_DOMAIN_DESCRIPTION_NOTE    = (1 << 2), /* Operate on note instead of
+                                                  the complete description
+                                                  field */
+} 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 a540424..c0f052b 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -8746,6 +8746,53 @@ 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->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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]