]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: Fix qemuDomainObjTaint with virtlogd
authorJiri Denemark <jdenemar@redhat.com>
Thu, 5 Sep 2019 13:35:35 +0000 (15:35 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Thu, 5 Sep 2019 15:09:34 +0000 (17:09 +0200)
When virtlogd is used to capture QEMU's stdout, qemuDomainObjTaint would
always fail to write the message to the log file when QEMU is already
running (i.e., outside qemuProcessLaunch). This can happen during device
hotplug or by sending a custom QEMU guest agent command:

    warning : qemuDomainObjTaint:8757 : Domain id=9 name='blaf'
        uuid=9cfa4e37-2930-405b-bcb4-faac1829dad8 is tainted:
        custom-ga-command
    error : virLogHandlerDomainOpenLogFile:388 : Cannot open log file:
        '/var/log/libvirt/qemu/blaf.log': Device or resource busy
    error : virNetClientProgramDispatchError:172 : Cannot open log file:
        '/var/log/libvirt/qemu/blaf.log': Device or resource busy

The fix is easy, we just need to use the right API for appending a
message to QEMU log file instead of creating a new log context.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_domain.c

index c7eb0b5e9a2a588cbcc149cd2e35e8289c7081f3..709e4e568bfdb820d53d7da963fda70314d8c002 100644 (file)
@@ -8783,9 +8783,9 @@ void qemuDomainObjTaint(virQEMUDriverPtr driver,
                         qemuDomainLogContextPtr logCtxt)
 {
     virErrorPtr orig_err = NULL;
-    bool closeLog = false;
     char *timestamp = NULL;
     char uuidstr[VIR_UUID_STRING_BUFLEN];
+    int rc;
 
     if (!virDomainObjTaint(obj, taint))
         return;
@@ -8806,27 +8806,25 @@ void qemuDomainObjTaint(virQEMUDriverPtr driver,
     if (!(timestamp = virTimeStringNow()))
         goto cleanup;
 
-    if (logCtxt == NULL) {
-        logCtxt = qemuDomainLogContextNew(driver, obj,
-                                          QEMU_DOMAIN_LOG_CONTEXT_MODE_ATTACH);
-        if (!logCtxt) {
-            VIR_WARN("Unable to open domainlog");
-            goto cleanup;
-        }
-        closeLog = true;
+    if (logCtxt) {
+        rc = qemuDomainLogContextWrite(logCtxt,
+                                       "%s: Domain id=%d is tainted: %s\n",
+                                       timestamp,
+                                       obj->def->id,
+                                       virDomainTaintTypeToString(taint));
+    } else {
+        rc = qemuDomainLogAppendMessage(driver, obj,
+                                        "%s: Domain id=%d is tainted: %s\n",
+                                        timestamp,
+                                        obj->def->id,
+                                        virDomainTaintTypeToString(taint));
     }
 
-    if (qemuDomainLogContextWrite(logCtxt,
-                                  "%s: Domain id=%d is tainted: %s\n",
-                                  timestamp,
-                                  obj->def->id,
-                                  virDomainTaintTypeToString(taint)) < 0)
+    if (rc < 0)
         virResetLastError();
 
  cleanup:
     VIR_FREE(timestamp);
-    if (closeLog)
-        virObjectUnref(logCtxt);
     if (orig_err) {
         virSetError(orig_err);
         virFreeError(orig_err);