[libvirt PATCH 04/16] qemu: add ability to associate a string message with taint warning

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

 



Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
---
 src/qemu/qemu_domain.c | 49 ++++++++++++++++++++++++++++++++++--------
 src/qemu/qemu_domain.h |  7 ++++++
 2 files changed, 47 insertions(+), 9 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index dd79cfd9d9..e63bea8b32 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -6166,22 +6166,51 @@ void qemuDomainObjTaint(virQEMUDriverPtr driver,
                         virDomainObjPtr obj,
                         virDomainTaintFlags taint,
                         qemuDomainLogContextPtr logCtxt)
+{
+    qemuDomainObjTaintMsg(driver, obj, taint, logCtxt, NULL);
+}
+
+void qemuDomainObjTaintMsg(virQEMUDriverPtr driver,
+                           virDomainObjPtr obj,
+                           virDomainTaintFlags taint,
+                           qemuDomainLogContextPtr logCtxt,
+                           const char *fmt, ...)
 {
     virErrorPtr orig_err = NULL;
     g_autofree char *timestamp = NULL;
     char uuidstr[VIR_UUID_STRING_BUFLEN];
     int rc;
-
-    if (!virDomainObjTaint(obj, taint))
-        return;
+    g_autofree char *extra = NULL;
+    const char *extraprefix = "";
+    const char *extramsg = "";
+    const char *extrasuffix = "";
+    va_list args;
+
+    if (virDomainObjTaint(obj, taint)) {
+        /* If an extra message was given we must always
+         * emit the taint warning, otherwise it is a
+         * one-time only warning per VM
+         */
+        if (!fmt)
+            return;
+    }
 
     virUUIDFormat(obj->def->uuid, uuidstr);
 
-    VIR_WARN("Domain id=%d name='%s' uuid=%s is tainted: %s",
+    if (fmt) {
+        va_start(args, fmt);
+        extraprefix = " (";
+        extramsg = extra = g_strdup_vprintf(fmt, args);
+        extrasuffix = ")";
+        va_end(args);
+    }
+
+    VIR_WARN("Domain id=%d name='%s' uuid=%s is tainted: %s%s%s%s",
              obj->def->id,
              obj->def->name,
              uuidstr,
-             virDomainTaintTypeToString(taint));
+             virDomainTaintTypeToString(taint),
+             extraprefix, extramsg, extrasuffix);
 
     /* We don't care about errors logging taint info, so
      * preserve original error, and clear any error that
@@ -6193,16 +6222,18 @@ void qemuDomainObjTaint(virQEMUDriverPtr driver,
 
     if (logCtxt) {
         rc = qemuDomainLogContextWrite(logCtxt,
-                                       "%s: Domain id=%d is tainted: %s\n",
+                                       "%s: Domain id=%d is tainted: %s%s%s%s\n",
                                        timestamp,
                                        obj->def->id,
-                                       virDomainTaintTypeToString(taint));
+                                       virDomainTaintTypeToString(taint),
+                                       extraprefix, extramsg, extrasuffix);
     } else {
         rc = qemuDomainLogAppendMessage(driver, obj,
-                                        "%s: Domain id=%d is tainted: %s\n",
+                                        "%s: Domain id=%d is tainted: %s%s%s%s\n",
                                         timestamp,
                                         obj->def->id,
-                                        virDomainTaintTypeToString(taint));
+                                        virDomainTaintTypeToString(taint),
+                                        extraprefix, extramsg, extrasuffix);
     }
 
     if (rc < 0)
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 154339ef8f..7453881a31 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -565,6 +565,13 @@ void qemuDomainObjTaint(virQEMUDriverPtr driver,
                         virDomainTaintFlags taint,
                         qemuDomainLogContextPtr logCtxt);
 
+void qemuDomainObjTaintMsg(virQEMUDriverPtr driver,
+                           virDomainObjPtr obj,
+                           virDomainTaintFlags taint,
+                           qemuDomainLogContextPtr logCtxt,
+                           const char *msg,
+                           ...) G_GNUC_PRINTF(5, 6);
+
 void qemuDomainObjCheckTaint(virQEMUDriverPtr driver,
                              virDomainObjPtr obj,
                              qemuDomainLogContextPtr logCtxt,
-- 
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