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@xxxxxxxxxx> --- src/qemu/qemu_nbdkit.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c index 5abccf1536..f2ff9552a3 100644 --- a/src/qemu/qemu_nbdkit.c +++ b/src/qemu/qemu_nbdkit.c @@ -850,15 +850,28 @@ qemuNbdkitProcessStart(qemuNbdkitProcess *proc, int rc; int exitstatus = 0; int cmdret = 0; - g_autofree char *errbuf = NULL; virTimeBackOffVar timebackoff; bool socketCreated = false; + g_autofree char *basename = g_strdup_printf("%s-nbdkit-%i", vm->def->name, proc->source->id); + int logfd = -1; + g_autoptr(qemuLogContext) logContext = NULL; + g_autofree char *errmsg = NULL; + g_autoptr(virURI) uri = NULL; + g_autofree char *uristring = 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) @@ -902,9 +915,16 @@ qemuNbdkitProcessStart(qemuNbdkitProcess *proc, return 0; error: - if (errbuf) - virReportError(VIR_ERR_OPERATION_FAILED, - _("nbdkit failed to start and reported: %s"), errbuf); + if (qemuLogContextReadFiltered(logContext, &errmsg, 1024) < 0) + VIR_WARN("Unable to read from nbdkit log"); + + if ((uri = qemuBlockStorageSourceGetURI(proc->source))) + uristring = virURIFormat(uri); + + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to connect to nbdkit for '%s': %s"), + NULLSTR(uristring), NULLSTR(errmsg)); + qemuNbdkitProcessStop(proc); return -1; } -- 2.39.1