Enable libvirt users to set logging level of a daemon from outside.
Signed-off-by: Erik Skultety <eskultet(a)redhat.com>
---
daemon/admin.c | 10 ++++++++++
include/libvirt/libvirt-admin.h | 4 ++++
src/admin/admin_protocol.x | 12 +++++++++++-
src/admin_protocol-structs | 5 +++++
src/libvirt-admin.c | 35 +++++++++++++++++++++++++++++++++++
src/libvirt_admin_private.syms | 1 +
src/libvirt_admin_public.syms | 1 +
src/util/virlog.c | 2 --
8 files changed, 67 insertions(+), 3 deletions(-)
diff --git a/daemon/admin.c b/daemon/admin.c
index 5f7a957..a2d35df 100644
--- a/daemon/admin.c
+++ b/daemon/admin.c
@@ -323,6 +323,16 @@ adminConnectGetLoggingFilters(char **filters, unsigned int flags)
}
static int
+adminConnectSetLoggingLevel(virNetDaemonPtr dmn ATTRIBUTE_UNUSED,
+ unsigned int priority,
+ unsigned int flags)
+{
+ virCheckFlags(0, -1);
+
+ return virLogSetDefaultPriority(priority);
+}
+
+static int
adminConnectGetLoggingOutputs(char **outputs, unsigned int flags)
{
char *tmp = NULL;
diff --git a/include/libvirt/libvirt-admin.h b/include/libvirt/libvirt-admin.h
index 755e6a6..41a9e2b 100644
--- a/include/libvirt/libvirt-admin.h
+++ b/include/libvirt/libvirt-admin.h
@@ -359,6 +359,10 @@ int virAdmConnectGetLoggingOutputs(virAdmConnectPtr conn,
char **outputs,
unsigned int flags);
+int virAdmConnectSetLoggingLevel(virAdmConnectPtr conn,
+ unsigned int level,
+ unsigned int flags);
+
# ifdef __cplusplus
}
# endif
diff --git a/src/admin/admin_protocol.x b/src/admin/admin_protocol.x
index 5465efe..d20c9d5 100644
--- a/src/admin/admin_protocol.x
+++ b/src/admin/admin_protocol.x
@@ -187,6 +187,11 @@ struct admin_connect_get_logging_outputs_ret {
unsigned int noutputs;
};
+struct admin_connect_set_logging_level_args {
+ unsigned int level;
+ unsigned int flags;
+};
+
/* Define the program number, protocol version and procedure numbers here. */
const ADMIN_PROGRAM = 0x06900690;
const ADMIN_PROTOCOL_VERSION = 1;
@@ -272,5 +277,10 @@ enum admin_procedure {
/**
* @generate: none
*/
- ADMIN_PROC_CONNECT_GET_LOGGING_OUTPUTS = 13
+ ADMIN_PROC_CONNECT_GET_LOGGING_OUTPUTS = 13,
+
+ /**
+ * @generate: both
+ */
+ ADMIN_PROC_CONNECT_SET_LOGGING_LEVEL = 14
};
diff --git a/src/admin_protocol-structs b/src/admin_protocol-structs
index 7cf2421..6620fb3 100644
--- a/src/admin_protocol-structs
+++ b/src/admin_protocol-structs
@@ -126,6 +126,10 @@ struct admin_connect_get_logging_outputs_ret {
admin_nonnull_string outputs;
u_int noutputs;
};
+struct admin_connect_set_logging_level_args {
+ u_int level;
+ u_int flags;
+};
enum admin_procedure {
ADMIN_PROC_CONNECT_OPEN = 1,
ADMIN_PROC_CONNECT_CLOSE = 2,
@@ -140,4 +144,5 @@ enum admin_procedure {
ADMIN_PROC_CONNECT_GET_LOGGING_LEVEL = 11,
ADMIN_PROC_CONNECT_GET_LOGGING_FILTERS = 12,
ADMIN_PROC_CONNECT_GET_LOGGING_OUTPUTS = 13,
+ ADMIN_PROC_CONNECT_SET_LOGGING_LEVEL = 14,
};
diff --git a/src/libvirt-admin.c b/src/libvirt-admin.c
index 95b47c0..7ac72d1 100644
--- a/src/libvirt-admin.c
+++ b/src/libvirt-admin.c
@@ -1088,3 +1088,38 @@ virAdmConnectGetLoggingOutputs(virAdmConnectPtr conn,
virDispatchError(NULL);
return -1;
}
+
+/**
+ * virAdmConnectSetLoggingLevel:
+ * @conn: pointer to an active admin connection
+ * @level: desired logging level, valid values are (see virLogPriority):
+ * 1) VIR_LOG_DEBUG
+ * 2) VIR_LOG_INFO
+ * 3) VIR_LOG_WARNING
+ * 4) VIR_LOG_ERROR
+ * @flags: extra flags; not used yet, so callers should always pass 0
+ *
+ * Set the current global logging level to @level.
+ *
+ * Returns 0 on success, -1 on error.
+ */
+int
+virAdmConnectSetLoggingLevel(virAdmConnectPtr conn,
+ unsigned int level,
+ unsigned int flags)
+{
+ int ret = -1;
+
+ VIR_DEBUG("conn=%p, level=%u, flags=%x", conn, level, flags);
+
+ virResetLastError();
+ virCheckAdmConnectReturn(conn, -1);
+
+ if ((ret = remoteAdminConnectSetLoggingLevel(conn, level, 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 ac183c6..28ff81c 100644
--- a/src/libvirt_admin_private.syms
+++ b/src/libvirt_admin_private.syms
@@ -20,6 +20,7 @@ xdr_admin_connect_list_servers_ret;
xdr_admin_connect_lookup_server_args;
xdr_admin_connect_lookup_server_ret;
xdr_admin_connect_open_args;
+xdr_admin_connect_set_logging_level_args;
xdr_admin_server_get_threadpool_parameters_args;
xdr_admin_server_get_threadpool_parameters_ret;
xdr_admin_server_list_clients_args;
diff --git a/src/libvirt_admin_public.syms b/src/libvirt_admin_public.syms
index 68475b1..a8b51c3 100644
--- a/src/libvirt_admin_public.syms
+++ b/src/libvirt_admin_public.syms
@@ -37,4 +37,5 @@ LIBVIRT_ADMIN_1.3.0 {
virAdmServerSetThreadPoolParameters;
virAdmServerListClients;
virAdmClientGetInfo;
+ virAdmConnectSetLoggingLevel;
};
diff --git a/src/util/virlog.c b/src/util/virlog.c
index 240d6e3..857a326 100644
--- a/src/util/virlog.c
+++ b/src/util/virlog.c
@@ -276,8 +276,6 @@ virLogSetDefaultPriority(virLogPriority priority)
"invalid"), priority);
return -1;
}
- if (virLogInitialize() < 0)
- return -1;
virLogAPILock();
virLogDefaultPriority = priority;
--
2.4.11