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

[libvirt] [PATCH REPOST 32/38] admin: Introduce virAdmConnectGetLoggingFilters



Enable libvirt users to query logging filter settings.
---
 daemon/admin.c                  | 45 +++++++++++++++++++++++++++++++++++++++++
 include/libvirt/libvirt-admin.h |  4 ++++
 src/admin/admin_protocol.x      | 16 ++++++++++++++-
 src/admin/admin_remote.c        | 43 +++++++++++++++++++++++++++++++++++++++
 src/admin_protocol-structs      |  8 ++++++++
 src/libvirt-admin.c             | 40 ++++++++++++++++++++++++++++++++++++
 src/libvirt_admin_private.syms  |  2 ++
 src/libvirt_admin_public.syms   |  1 +
 8 files changed, 158 insertions(+), 1 deletion(-)

diff --git a/daemon/admin.c b/daemon/admin.c
index 5129e2d..ac81b82 100644
--- a/daemon/admin.c
+++ b/daemon/admin.c
@@ -304,4 +304,49 @@ adminConnectGetLoggingLevel(virNetDaemonPtr dmn ATTRIBUTE_UNUSED,
 
     return virLogGetDefaultPriority();
 }
+
+static int
+adminConnectGetLoggingFilters(char **filters, unsigned int flags)
+{
+    char *tmp = NULL;
+    int ret = -1;
+
+    virCheckFlags(0, -1);
+
+    if (!(tmp = virLogGetFilters()))
+        return -1;
+
+    ret = virLogGetNbFilters();
+
+    *filters = tmp;
+    return ret;
+}
+
+static int
+adminDispatchConnectGetLoggingFilters(virNetServerPtr server ATTRIBUTE_UNUSED,
+                                      virNetServerClientPtr client ATTRIBUTE_UNUSED,
+                                      virNetMessagePtr msg ATTRIBUTE_UNUSED,
+                                      virNetMessageErrorPtr rerr ATTRIBUTE_UNUSED,
+                                      admin_connect_get_logging_filters_args *args,
+                                      admin_connect_get_logging_filters_ret *ret)
+{
+    char *filters = NULL;
+    int nfilters = 0;
+    int rv = -1;
+
+    if ((nfilters = adminConnectGetLoggingFilters(&filters, args->flags)) < 0)
+        goto cleanup;
+
+    if (VIR_STRDUP(ret->filters, filters) < 0)
+        goto cleanup;
+
+    ret->nfilters = nfilters;
+    rv = 0;
+
+ cleanup:
+    if (rv < 0)
+        virNetMessageSaveError(rerr);
+    VIR_FREE(filters);
+    return rv;
+}
 #include "admin_dispatch.h"
diff --git a/include/libvirt/libvirt-admin.h b/include/libvirt/libvirt-admin.h
index 2878c78..87616d0 100644
--- a/include/libvirt/libvirt-admin.h
+++ b/include/libvirt/libvirt-admin.h
@@ -351,6 +351,10 @@ int virAdmClientGetInfo(virAdmClientPtr client,
 
 int virAdmConnectGetLoggingLevel(virAdmConnectPtr conn, unsigned int flags);
 
+int virAdmConnectGetLoggingFilters(virAdmConnectPtr conn,
+                                   char **filters,
+                                   unsigned int flags);
+
 # ifdef __cplusplus
 }
 # endif
diff --git a/src/admin/admin_protocol.x b/src/admin/admin_protocol.x
index 6a95665..05eecec 100644
--- a/src/admin/admin_protocol.x
+++ b/src/admin/admin_protocol.x
@@ -169,6 +169,15 @@ struct admin_connect_get_logging_level_ret {
     int level;
 };
 
+struct admin_connect_get_logging_filters_args {
+    unsigned int flags;
+};
+
+struct admin_connect_get_logging_filters_ret {
+    admin_nonnull_string filters;
+    unsigned int nfilters;
+};
+
 /* Define the program number, protocol version and procedure numbers here. */
 const ADMIN_PROGRAM = 0x06900690;
 const ADMIN_PROTOCOL_VERSION = 1;
@@ -244,5 +253,10 @@ enum admin_procedure {
     /**
      * @generate: both
      */
-    ADMIN_PROC_CONNECT_GET_LOGGING_LEVEL = 11
+    ADMIN_PROC_CONNECT_GET_LOGGING_LEVEL = 11,
+
+    /**
+     * @generate: none
+     */
+    ADMIN_PROC_CONNECT_GET_LOGGING_FILTERS = 12
 };
diff --git a/src/admin/admin_remote.c b/src/admin/admin_remote.c
index 40fcddb..86deaec 100644
--- a/src/admin/admin_remote.c
+++ b/src/admin/admin_remote.c
@@ -355,3 +355,46 @@ remoteAdminClientGetInfo(virAdmClientPtr client,
     virObjectUnlock(priv);
     return rv;
 }
+
+static int
+remoteAdminConnectGetLoggingFilters(virAdmConnectPtr conn,
+                                    char **filters,
+                                    unsigned int flags)
+{
+    int rv = -1;
+    char *tmp_filters = NULL;
+    remoteAdminPrivPtr priv = conn->privateData;
+    admin_connect_get_logging_filters_args args;
+    admin_connect_get_logging_filters_ret ret;
+
+    args.flags = flags;
+
+    memset(&ret, 0, sizeof(ret));
+    virObjectLock(priv);
+
+    if (call(conn,
+             0,
+             ADMIN_PROC_CONNECT_GET_LOGGING_FILTERS,
+             (xdrproc_t) xdr_admin_connect_get_logging_filters_args,
+             (char *) &args,
+             (xdrproc_t) xdr_admin_connect_get_logging_filters_ret,
+             (char *) &ret) == -1)
+        goto done;
+
+    if (filters) {
+        if (VIR_STRDUP(tmp_filters, ret.filters) < 0)
+            goto cleanup;
+
+        *filters = tmp_filters;
+        tmp_filters = NULL;
+    }
+
+    rv = ret.nfilters;
+
+ cleanup:
+    xdr_free((xdrproc_t) xdr_admin_connect_get_logging_filters_ret, (char *) &ret);
+
+ done:
+    virObjectUnlock(priv);
+    return rv;
+}
diff --git a/src/admin_protocol-structs b/src/admin_protocol-structs
index 72d93ec..bbe4a5a 100644
--- a/src/admin_protocol-structs
+++ b/src/admin_protocol-structs
@@ -112,6 +112,13 @@ struct admin_connect_get_logging_level_args {
 struct admin_connect_get_logging_level_ret {
         int                        level;
 };
+struct admin_connect_get_logging_filters_args {
+        u_int                      flags;
+};
+struct admin_connect_get_logging_filters_ret {
+        admin_nonnull_string       filters;
+        u_int                      nfilters;
+};
 enum admin_procedure {
         ADMIN_PROC_CONNECT_OPEN = 1,
         ADMIN_PROC_CONNECT_CLOSE = 2,
@@ -124,4 +131,5 @@ enum admin_procedure {
         ADMIN_PROC_SERVER_LOOKUP_CLIENT = 9,
         ADMIN_PROC_CLIENT_GET_INFO = 10,
         ADMIN_PROC_CONNECT_GET_LOGGING_LEVEL = 11,
+        ADMIN_PROC_CONNECT_GET_LOGGING_FILTERS = 12,
 };
diff --git a/src/libvirt-admin.c b/src/libvirt-admin.c
index 898b9c1..e61dc10 100644
--- a/src/libvirt-admin.c
+++ b/src/libvirt-admin.c
@@ -1009,3 +1009,43 @@ virAdmConnectGetLoggingLevel(virAdmConnectPtr conn,
     virDispatchError(NULL);
     return -1;
 }
+
+/**
+ * virAdmConnectGetLoggingFilters:
+ * @conn: pointer to an active admin connection
+ * @filters: pointer to a variable to store a string containing all currently
+ *           defined logging filters on daemon (allocated automatically)
+ * @flags: extra flags; not used yet, so callers should always pass 0
+ *
+ * Retrieves a list of currently installed logging filters. Filters returned
+ * are contained within an automatically allocated string and delimited by
+ * spaces. The format of each filter conforms to the format described in
+ * daemon's configuration file (e.g. libvirtd.conf).
+ * To retrieve individual filters, additional parsing needs to be done by the
+ * caller. Caller is also responsible for freeing @filters correctly.
+ *
+ * Returns the number of filters returned in @filters, or -1 in case of
+ * an error.
+ */
+int
+virAdmConnectGetLoggingFilters(virAdmConnectPtr conn,
+                               char **filters,
+                               unsigned int flags)
+{
+    int ret = -1;
+
+    VIR_DEBUG("conn=%p, flags=%x", conn, flags);
+
+    virResetLastError();
+    virCheckAdmConnectReturn(conn, -1);
+    virCheckNonNullArgGoto(filters, error);
+
+    if ((ret = remoteAdminConnectGetLoggingFilters(conn, filters,
+                                                   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 8534ab1..6029575 100644
--- a/src/libvirt_admin_private.syms
+++ b/src/libvirt_admin_private.syms
@@ -9,6 +9,8 @@
 xdr_admin_client_get_info_args;
 xdr_admin_client_get_info_ret;
 xdr_admin_connect_get_lib_version_ret;
+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_list_servers_args;
diff --git a/src/libvirt_admin_public.syms b/src/libvirt_admin_public.syms
index 4cc0a5b..d7648a3 100644
--- a/src/libvirt_admin_public.syms
+++ b/src/libvirt_admin_public.syms
@@ -27,6 +27,7 @@ LIBVIRT_ADMIN_1.3.0 {
         virAdmConnectUnregisterCloseCallback;
         virAdmConnectListServers;
         virAdmConnectGetLoggingLevel;
+        virAdmConnectGetLoggingFilters;
         virAdmServerGetName;
         virAdmServerGetThreadPoolParameters;
         virAdmServerFree;
-- 
2.4.11


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