From: Jonathon Jongsma Date: Mon, 12 Dec 2022 21:12:33 +0000 (-0600) Subject: qemu: log error output from nbdkit X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=e04373794c34f77be1eec977cb10ba0339dda90b;p=libvirt.git qemu: log error output from nbdkit 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 Reviewed-by: Peter Krempa --- diff --git a/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c index 6bf962d0f1..2d70e72c42 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -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));