[PATCH 33/38] admin: Introduce virAdmConnectGetLoggingOutputs

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

 



Enable libvirt users to query logging output settings.
---
 daemon/admin.c                  | 42 ++++++++++++++++++++++++++++++++++++++++
 include/libvirt/libvirt-admin.h |  5 +++++
 src/admin/admin_protocol.x      | 16 ++++++++++++++-
 src/admin/admin_remote.c        | 43 +++++++++++++++++++++++++++++++++++++++++
 src/admin_protocol-structs      |  8 ++++++++
 src/libvirt-admin.c             | 39 +++++++++++++++++++++++++++++++++++++
 src/libvirt_admin_private.syms  |  2 ++
 src/libvirt_admin_public.syms   |  1 +
 8 files changed, 155 insertions(+), 1 deletion(-)

diff --git a/daemon/admin.c b/daemon/admin.c
index 5098286..43ba2cb 100644
--- a/daemon/admin.c
+++ b/daemon/admin.c
@@ -160,6 +160,23 @@ adminConnectGetLoggingFilters(char **filters, unsigned int flags)
 }
 
 static int
+adminConnectGetLoggingOutputs(char **outputs, unsigned int flags)
+{
+    char *tmp = NULL;
+    int ret = -1;
+
+    virCheckFlags(0, -1);
+
+    if (!(tmp = virLogGetOutputs()))
+        return -1;
+
+    ret = virLogGetNbOutputs();
+
+    *outputs = tmp;
+    return ret;
+}
+
+static int
 adminDispatchConnectGetLoggingFilters(virNetServerPtr server ATTRIBUTE_UNUSED,
                                       virNetServerClientPtr client ATTRIBUTE_UNUSED,
                                       virNetMessagePtr msg ATTRIBUTE_UNUSED,
@@ -186,4 +203,29 @@ adminDispatchConnectGetLoggingFilters(virNetServerPtr server ATTRIBUTE_UNUSED,
     VIR_FREE(filters);
     return rv;
 }
+
+static int
+adminDispatchConnectGetLoggingOutputs(virNetServerPtr server ATTRIBUTE_UNUSED,
+                                      virNetServerClientPtr client ATTRIBUTE_UNUSED,
+                                      virNetMessagePtr msg ATTRIBUTE_UNUSED,
+                                      virNetMessageErrorPtr rerr ATTRIBUTE_UNUSED,
+                                      admin_connect_get_logging_outputs_args *args,
+                                      admin_connect_get_logging_outputs_ret *ret)
+{
+    char *outputs = NULL;
+    int noutputs = 0;
+    int rv = -1;
+
+    if ((noutputs = adminConnectGetLoggingOutputs(&outputs, args->flags) < 0))
+        goto cleanup;
+
+    ret->outputs = outputs;
+    ret->noutputs = noutputs;
+    rv = 0;
+
+ cleanup:
+    if (rv < 0)
+        virNetMessageSaveError(rerr);
+    return rv;
+}
 #include "admin_dispatch.h"
diff --git a/include/libvirt/libvirt-admin.h b/include/libvirt/libvirt-admin.h
index 27e1f0b..9608c42 100644
--- a/include/libvirt/libvirt-admin.h
+++ b/include/libvirt/libvirt-admin.h
@@ -115,6 +115,11 @@ int virAdmConnectGetLoggingLevel(virAdmConnectPtr conn, unsigned int flags);
 int virAdmConnectGetLoggingFilters(virAdmConnectPtr conn,
                                    char **logFilters,
                                    unsigned int flags);
+
+int virAdmConnectGetLoggingOutputs(virAdmConnectPtr conn,
+                                   char **logOutputs,
+                                   unsigned int flags);
+
 # ifdef __cplusplus
 }
 # endif
diff --git a/src/admin/admin_protocol.x b/src/admin/admin_protocol.x
index 60ebe03..2decb1e 100644
--- a/src/admin/admin_protocol.x
+++ b/src/admin/admin_protocol.x
@@ -91,6 +91,15 @@ struct admin_connect_get_logging_filters_ret {
     unsigned int nfilters;
 };
 
+struct admin_connect_get_logging_outputs_args {
+    unsigned int flags;
+};
+
+struct admin_connect_get_logging_outputs_ret {
+    admin_nonnull_string outputs;
+    unsigned int noutputs;
+};
+
 /* Define the program number, protocol version and procedure numbers here. */
 const ADMIN_PROGRAM = 0x06900690;
 const ADMIN_PROTOCOL_VERSION = 1;
@@ -146,5 +155,10 @@ enum admin_procedure {
     /**
      * @generate: none
      */
-    ADMIN_PROC_CONNECT_GET_LOGGING_FILTERS = 7
+    ADMIN_PROC_CONNECT_GET_LOGGING_FILTERS = 7,
+
+    /**
+     * @generate: none
+     */
+    ADMIN_PROC_CONNECT_GET_LOGGING_OUTPUTS = 8
 };
diff --git a/src/admin/admin_remote.c b/src/admin/admin_remote.c
index 17954e6..b533149 100644
--- a/src/admin/admin_remote.c
+++ b/src/admin/admin_remote.c
@@ -267,3 +267,46 @@ remoteAdminConnectGetLoggingFilters(virAdmConnectPtr conn,
     virObjectUnlock(priv);
     return rv;
 }
+
+static int
+remoteAdminConnectGetLoggingOutputs(virAdmConnectPtr conn,
+                                    char **outputs,
+                                    unsigned int flags)
+{
+    int rv = -1;
+    char *tmp_outputs = NULL;
+    remoteAdminPrivPtr priv = conn->privateData;
+    admin_connect_get_logging_outputs_args args;
+    admin_connect_get_logging_outputs_ret ret;
+
+    args.flags = flags;
+
+    memset(&ret, 0, sizeof(ret));
+    virObjectLock(priv);
+
+    if (call(conn,
+             0,
+             ADMIN_PROC_CONNECT_GET_LOGGING_OUTPUTS,
+             (xdrproc_t) xdr_admin_connect_get_logging_outputs_args,
+             (char *) &args,
+             (xdrproc_t) xdr_admin_connect_get_logging_outputs_ret,
+             (char *) &ret) == -1)
+        goto done;
+
+    if (outputs) {
+        if (VIR_STRDUP(tmp_outputs, ret.outputs) < 0)
+            goto cleanup;
+
+        *outputs = tmp_outputs;
+        tmp_outputs = NULL;
+    }
+
+    rv = ret.noutputs;
+
+ cleanup:
+    xdr_free((xdrproc_t) xdr_admin_connect_get_logging_outputs_ret, (char *) &ret);
+
+ done:
+    virObjectUnlock(priv);
+    return rv;
+}
diff --git a/src/admin_protocol-structs b/src/admin_protocol-structs
index b7d5fa1..8482dee 100644
--- a/src/admin_protocol-structs
+++ b/src/admin_protocol-structs
@@ -39,6 +39,13 @@ struct admin_connect_get_logging_filters_ret {
         admin_nonnull_string       filters;
         u_int                      nfilters;
 };
+struct admin_connect_get_logging_outputs_args {
+        u_int                      flags;
+};
+struct admin_connect_get_logging_outputs_ret {
+        admin_nonnull_string       outputs;
+        u_int                      noutputs;
+};
 enum admin_procedure {
         ADMIN_PROC_CONNECT_OPEN = 1,
         ADMIN_PROC_CONNECT_CLOSE = 2,
@@ -47,4 +54,5 @@ enum admin_procedure {
         ADMIN_PROC_CONNECT_LOOKUP_SERVER = 5,
         ADMIN_PROC_CONNECT_GET_LOGGING_LEVEL = 6,
         ADMIN_PROC_CONNECT_GET_LOGGING_FILTERS = 7,
+        ADMIN_PROC_CONNECT_GET_LOGGING_OUTPUTS = 8,
 };
diff --git a/src/libvirt-admin.c b/src/libvirt-admin.c
index 2c7548c..39a7b02 100644
--- a/src/libvirt-admin.c
+++ b/src/libvirt-admin.c
@@ -747,3 +747,42 @@ virAdmConnectGetLoggingFilters(virAdmConnectPtr conn,
     virDispatchError(NULL);
     return -1;
 }
+
+/**
+ * virAdmConnectGetLoggingOutputs:
+ * @conn: pointer to an active admin connection
+ * @outputs: pointer to a variable to store a NULL-terminated list of
+ *           currently defined logging outputs;
+ * @flags: extra flags; not used yet, so callers should always pass 0
+ *
+ * Retrieves a list of currently installed logging outputs. Outputs returned
+ * are contained within a string and delimited by spaces. The format of each
+ * output conforms to the format described in daemon's configuration file
+ * (e.g. libvirtd.conf).
+ * To retrieve individual outputs, additional parsing needs to be done by the
+ * caller. Caller is also responsible for freeing @outputs correctly.
+ *
+ * Returns the count of outputs in @outputs, or -1 in case of an error.
+ */
+int
+virAdmConnectGetLoggingOutputs(virAdmConnectPtr conn,
+                               char **outputs,
+                               unsigned int flags)
+{
+    int ret = -1;
+
+    VIR_DEBUG("conn=%p, flags=%x", conn, flags);
+
+    virResetLastError();
+    virCheckAdmConnectReturn(conn, -1);
+    virCheckNonNullArgGoto(outputs, error);
+
+    if ((ret = remoteAdminConnectGetLoggingOutputs(conn, outputs,
+                                                   flags)) < 0)
+        goto error;
+
+    return ret;
+ error:
+    virDispatchError(NULL);
+    return -1;
+}
diff --git a/src/libvirt_admin_private.syms b/src/libvirt_admin_private.syms
index 341f896..2e34178 100644
--- a/src/libvirt_admin_private.syms
+++ b/src/libvirt_admin_private.syms
@@ -11,6 +11,8 @@ xdr_admin_connect_get_logging_filters_args;
 xdr_admin_connect_get_logging_filters_ret;
 xdr_admin_connect_get_logging_level_args;
 xdr_admin_connect_get_logging_level_ret;
+xdr_admin_connect_get_logging_outputs_args;
+xdr_admin_connect_get_logging_outputs_ret;
 xdr_admin_connect_list_servers_args;
 xdr_admin_connect_list_servers_ret;
 xdr_admin_connect_lookup_server_args;
diff --git a/src/libvirt_admin_public.syms b/src/libvirt_admin_public.syms
index 41c858f..56bb073 100644
--- a/src/libvirt_admin_public.syms
+++ b/src/libvirt_admin_public.syms
@@ -24,6 +24,7 @@ LIBVIRT_ADMIN_1.3.0 {
         virAdmConnectListServers;
         virAdmConnectGetLoggingLevel;
         virAdmConnectGetLoggingFilters;
+        virAdmConnectGetLoggingOutputs;
         virAdmServerGetName;
         virAdmServerFree;
         virAdmConnectLookupServer;
-- 
2.4.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[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]