Enable libvirt users to set logging level of a daemon from outside.
---
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 43ba2cb..866717a 100644
--- a/daemon/admin.c
+++ b/daemon/admin.c
@@ -160,6 +160,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 9608c42..8f26778 100644
--- a/include/libvirt/libvirt-admin.h
+++ b/include/libvirt/libvirt-admin.h
@@ -120,6 +120,10 @@ int virAdmConnectGetLoggingOutputs(virAdmConnectPtr conn,
char **logOutputs,
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 2decb1e..c62319c 100644
--- a/src/admin/admin_protocol.x
+++ b/src/admin/admin_protocol.x
@@ -100,6 +100,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;
@@ -160,5 +165,10 @@ enum admin_procedure {
/**
* @generate: none
*/
- ADMIN_PROC_CONNECT_GET_LOGGING_OUTPUTS = 8
+ ADMIN_PROC_CONNECT_GET_LOGGING_OUTPUTS = 8,
+
+ /**
+ * @generate: both
+ */
+ ADMIN_PROC_CONNECT_SET_LOGGING_LEVEL = 9
};
diff --git a/src/admin_protocol-structs b/src/admin_protocol-structs
index 8482dee..e6741c3 100644
--- a/src/admin_protocol-structs
+++ b/src/admin_protocol-structs
@@ -46,6 +46,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,
@@ -55,4 +59,5 @@ enum admin_procedure {
ADMIN_PROC_CONNECT_GET_LOGGING_LEVEL = 6,
ADMIN_PROC_CONNECT_GET_LOGGING_FILTERS = 7,
ADMIN_PROC_CONNECT_GET_LOGGING_OUTPUTS = 8,
+ ADMIN_PROC_CONNECT_SET_LOGGING_LEVEL = 9,
};
diff --git a/src/libvirt-admin.c b/src/libvirt-admin.c
index 39a7b02..7b50dcb 100644
--- a/src/libvirt-admin.c
+++ b/src/libvirt-admin.c
@@ -786,3 +786,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 2e34178..f94e3f6 100644
--- a/src/libvirt_admin_private.syms
+++ b/src/libvirt_admin_private.syms
@@ -18,6 +18,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;
# datatypes.h
virAdmConnectClass;
diff --git a/src/libvirt_admin_public.syms b/src/libvirt_admin_public.syms
index 56bb073..0feadee 100644
--- a/src/libvirt_admin_public.syms
+++ b/src/libvirt_admin_public.syms
@@ -28,4 +28,5 @@ LIBVIRT_ADMIN_1.3.0 {
virAdmServerGetName;
virAdmServerFree;
virAdmConnectLookupServer;
+ 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.3