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(a)redhat.com>
Reviewed-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_nbdkit.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
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));
--
2.41.0