]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: log error output from nbdkit
authorJonathon Jongsma <jjongsma@redhat.com>
Mon, 12 Dec 2022 21:12:33 +0000 (15:12 -0600)
committerJonathon Jongsma <jjongsma@redhat.com>
Tue, 19 Sep 2023 19:28:50 +0000 (14:28 -0500)
log stderr and stdout from nbdkit into its own log so that
nbdkit-related issues can be debugged more easily.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/qemu/qemu_nbdkit.c

index 6bf962d0f14e300cb623cc7d016be83c52b146f2..2d70e72c42842330db177b6af6f0e28d81c1174d 100644 (file)
@@ -852,12 +852,23 @@ qemuNbdkitProcessStart(qemuNbdkitProcess *proc,
     virTimeBackOffVar timebackoff;
     g_autoptr(virURI) uri = NULL;
     g_autofree char *uristring = NULL;
+    g_autofree char *basename = g_strdup_printf("%s-nbdkit-%i", vm->def->name, proc->source->id);
+    int logfd = -1;
+    g_autoptr(qemuLogContext) logContext = NULL;
 
     if (!(cmd = qemuNbdkitProcessBuildCommand(proc)))
         return -1;
 
+    if (!(logContext = qemuLogContextNew(driver, vm, basename))) {
+        virLastErrorPrefixMessage("%s", _("can't connect to virtlogd"));
+        return -1;
+    }
+
+    logfd = qemuLogContextGetWriteFD(logContext);
+
     VIR_DEBUG("starting nbdkit process for %s", proc->source->nodestorage);
-    virCommandSetErrorBuffer(cmd, &errbuf);
+    virCommandSetErrorFD(cmd, &logfd);
+    virCommandSetOutputFD(cmd, &logfd);
     virCommandSetPidFile(cmd, proc->pidfile);
 
     if (qemuExtDeviceLogCommand(driver, vm, cmd, "nbdkit") < 0)
@@ -899,6 +910,9 @@ qemuNbdkitProcessStart(qemuNbdkitProcess *proc,
     if ((uri = qemuBlockStorageSourceGetURI(proc->source)))
         uristring = virURIFormat(uri);
 
+    if (qemuLogContextReadFiltered(logContext, &errbuf, 1024) < 0)
+        VIR_WARN("Unable to read from nbdkit log");
+
     virReportError(VIR_ERR_OPERATION_FAILED,
                    _("Failed to connect to nbdkit for '%1$s': %2$s"),
                    NULLSTR(uristring), NULLSTR(errbuf));