[libvirt PATCH 4/6] remote: add RPC support for the virDomainGetMessages API

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

 



Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
---
 src/remote/remote_daemon_dispatch.c | 45 +++++++++++++++++++++++++++++
 src/remote/remote_driver.c          | 44 ++++++++++++++++++++++++++++
 src/remote/remote_protocol.x        | 21 +++++++++++++-
 src/remote_protocol-structs         | 11 +++++++
 4 files changed, 120 insertions(+), 1 deletion(-)

diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon_dispatch.c
index b7ef1f4b26..e9f2a0ce5b 100644
--- a/src/remote/remote_daemon_dispatch.c
+++ b/src/remote/remote_daemon_dispatch.c
@@ -7463,3 +7463,48 @@ remoteDispatchDomainAuthorizedSshKeysSet(virNetServerPtr server G_GNUC_UNUSED,
 
     return rv;
 }
+
+static int
+remoteDispatchDomainGetMessages(virNetServerPtr server G_GNUC_UNUSED,
+                                virNetServerClientPtr client,
+                                virNetMessagePtr msg G_GNUC_UNUSED,
+                                virNetMessageErrorPtr rerr,
+                                remote_domain_get_messages_args *args,
+                                remote_domain_get_messages_ret *ret)
+{
+    int rv = -1;
+    virConnectPtr conn = remoteGetHypervisorConn(client);
+    int nmsgs = 0;
+    char **msgs = NULL;
+    virDomainPtr dom = NULL;
+
+    if (!conn)
+        goto cleanup;
+
+    if (!(dom = get_nonnull_domain(conn, args->dom)))
+        goto cleanup;
+
+    if ((nmsgs = virDomainGetMessages(dom, &msgs, args->flags)) < 0)
+        goto cleanup;
+
+    if (nmsgs > REMOTE_DOMAIN_MESSAGES_MAX) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Number of msgs %d, which exceeds max limit: %d"),
+                       nmsgs, REMOTE_DOMAIN_MESSAGES_MAX);
+        goto cleanup;
+    }
+
+    ret->msgs.msgs_val = g_steal_pointer(&msgs);
+    ret->msgs.msgs_len = nmsgs;
+
+    rv = nmsgs;
+
+ cleanup:
+    if (rv < 0)
+        virNetMessageSaveError(rerr);
+    if (nmsgs > 0)
+        virStringListFreeCount(msgs, nmsgs);
+    virObjectUnref(dom);
+
+    return rv;
+}
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 8d6790ccf2..a83cd866e7 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -8098,6 +8098,49 @@ remoteDomainAuthorizedSSHKeysSet(virDomainPtr domain,
 }
 
 
+static int
+remoteDomainGetMessages(virDomainPtr domain,
+                        char ***msgs,
+                        unsigned int flags)
+{
+    int rv = -1;
+    size_t i;
+    struct private_data *priv = domain->conn->privateData;
+    remote_domain_get_messages_args args;
+    remote_domain_get_messages_ret ret;
+
+    remoteDriverLock(priv);
+
+    make_nonnull_domain(&args.dom, domain);
+    args.flags = flags;
+    memset(&ret, 0, sizeof(ret));
+
+    if (call(domain->conn, priv, 0, REMOTE_PROC_DOMAIN_GET_MESSAGES,
+             (xdrproc_t) xdr_remote_domain_get_messages_args, (char *)&args,
+             (xdrproc_t) xdr_remote_domain_get_messages_ret, (char *)&ret) == -1) {
+        goto cleanup;
+    }
+
+    if (ret.msgs.msgs_len > REMOTE_DOMAIN_MESSAGES_MAX) {
+        virReportError(VIR_ERR_RPC, "%s",
+                       _("remoteDomainGetMessages: "
+                         "returned number of msgs exceeds limit"));
+        goto cleanup;
+    }
+
+    *msgs = g_new0(char *, ret.msgs.msgs_len + 1);
+    for (i = 0; i < ret.msgs.msgs_len; i++)
+        (*msgs)[i] = g_strdup(ret.msgs.msgs_val[i]);
+
+    rv = ret.msgs.msgs_len;
+
+ cleanup:
+    remoteDriverUnlock(priv);
+    xdr_free((xdrproc_t)xdr_remote_domain_get_messages_ret,
+             (char *) &ret);
+    return rv;
+}
+
 /* get_nonnull_domain and get_nonnull_network turn an on-wire
  * (name, uuid) pair into virDomainPtr or virNetworkPtr object.
  * These can return NULL if underlying memory allocations fail,
@@ -8531,6 +8574,7 @@ static virHypervisorDriver hypervisor_driver = {
     .domainBackupGetXMLDesc = remoteDomainBackupGetXMLDesc, /* 6.0.0 */
     .domainAuthorizedSSHKeysGet = remoteDomainAuthorizedSSHKeysGet, /* 6.10.0 */
     .domainAuthorizedSSHKeysSet = remoteDomainAuthorizedSSHKeysSet, /* 6.10.0 */
+    .domainGetMessages = remoteDomainGetMessages, /* 7.1.0 */
 };
 
 static virNetworkDriver network_driver = {
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index 2df38cef77..d3724bc305 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -283,6 +283,9 @@ const REMOTE_NETWORK_PORT_PARAMETERS_MAX = 16;
 /* Upper limit on number of SSH keys */
 const REMOTE_DOMAIN_AUTHORIZED_SSH_KEYS_MAX = 2048;
 
+/* Upper limit on number of messages */
+const REMOTE_DOMAIN_MESSAGES_MAX = 2048;
+
 
 /* UUID.  VIR_UUID_BUFLEN definition comes from libvirt.h */
 typedef opaque remote_uuid[VIR_UUID_BUFLEN];
@@ -3799,6 +3802,16 @@ struct remote_domain_authorized_ssh_keys_set_args {
     unsigned int flags;
 };
 
+struct remote_domain_get_messages_args {
+    remote_nonnull_domain dom;
+    unsigned int flags;
+};
+
+struct remote_domain_get_messages_ret {
+    remote_nonnull_string msgs<REMOTE_DOMAIN_MESSAGES_MAX>;
+};
+
+
 /*----- Protocol. -----*/
 
 /* Define the program number, protocol version and procedure numbers here. */
@@ -6714,5 +6727,11 @@ enum remote_procedure {
      * @generate: none
      * @acl: domain:write
      */
-    REMOTE_PROC_DOMAIN_AUTHORIZED_SSH_KEYS_SET = 425
+    REMOTE_PROC_DOMAIN_AUTHORIZED_SSH_KEYS_SET = 425,
+
+    /**
+     * @generate: none
+     * @acl: domain:read
+     */
+    REMOTE_PROC_DOMAIN_GET_MESSAGES = 426
 };
diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs
index 9bcd14603d..c0c034ac6a 100644
--- a/src/remote_protocol-structs
+++ b/src/remote_protocol-structs
@@ -3162,6 +3162,16 @@ struct remote_domain_authorized_ssh_keys_set_args {
         } keys;
         u_int                      flags;
 };
+struct remote_domain_get_messages_args {
+        remote_nonnull_domain      dom;
+        u_int                      flags;
+};
+struct remote_domain_get_messages_ret {
+        struct {
+                u_int              msgs_len;
+                remote_nonnull_string * msgs_val;
+        } msgs;
+};
 enum remote_procedure {
         REMOTE_PROC_CONNECT_OPEN = 1,
         REMOTE_PROC_CONNECT_CLOSE = 2,
@@ -3588,4 +3598,5 @@ enum remote_procedure {
         REMOTE_PROC_DOMAIN_EVENT_MEMORY_FAILURE = 423,
         REMOTE_PROC_DOMAIN_AUTHORIZED_SSH_KEYS_GET = 424,
         REMOTE_PROC_DOMAIN_AUTHORIZED_SSH_KEYS_SET = 425,
+        REMOTE_PROC_DOMAIN_GET_MESSAGES = 426,
 };
-- 
2.29.2




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux