Rather than having NBDKIT_MODDIR as a build configuration option, query
the nbdkit binary for the location to these directories. nbdkit provides
a --dump-config optiont that outputs this information and can be easily
parsed. We can also get the version from this output rather than
executing `nbdkit --version` separately.
Signed-off-by: Jonathon Jongsma <jjongsma(a)redhat.com>
---
meson.build | 6 ----
meson_options.txt | 1 -
src/qemu/qemu_nbdkit.c | 75 +++++++++++++++++++++++++++++++++---------
3 files changed, 60 insertions(+), 22 deletions(-)
diff --git a/meson.build b/meson.build
index ca02fde91b..e498b49be4 100644
--- a/meson.build
+++ b/meson.build
@@ -1664,12 +1664,6 @@ if not get_option('driver_qemu').disabled()
qemu_dbus_daemon_path = '/usr/bin/dbus-daemon'
endif
conf.set_quoted('QEMU_DBUS_DAEMON', qemu_dbus_daemon_path)
-
- nbdkit_moddir = get_option('nbdkit_moddir')
- if nbdkit_moddir == ''
- nbdkit_moddir = libdir / 'nbdkit'
- endif
- conf.set_quoted('NBDKIT_MODDIR', nbdkit_moddir)
endif
endif
diff --git a/meson_options.txt b/meson_options.txt
index d5ea4376e0..861c5577d2 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -71,7 +71,6 @@ option('driver_vbox', type: 'feature', value:
'auto', description: 'VirtualBox X
option('vbox_xpcomc_dir', type: 'string', value: '', description:
'Location of directory containing VirtualBox XPCOMC library')
option('driver_vmware', type: 'feature', value: 'auto',
description: 'VMware driver')
option('driver_vz', type: 'feature', value: 'auto', description:
'Virtuozzo driver')
-option('nbdkit_moddir', type: 'string', value: '', description:
'set the directory where nbdkit modules are located')
option('secdriver_apparmor', type: 'feature', value: 'auto',
description: 'use AppArmor security driver')
option('apparmor_profiles', type: 'feature', value: 'auto',
description: 'install apparmor profiles')
diff --git a/src/qemu/qemu_nbdkit.c b/src/qemu/qemu_nbdkit.c
index 231908b6b1..840710862e 100644
--- a/src/qemu/qemu_nbdkit.c
+++ b/src/qemu/qemu_nbdkit.c
@@ -39,9 +39,6 @@
VIR_LOG_INIT("qemu.nbdkit");
-#define NBDKIT_PLUGINDIR NBDKIT_MODDIR "/plugins"
-#define NBDKIT_FILTERDIR NBDKIT_MODDIR "/filters"
-
VIR_ENUM_IMPL(qemuNbdkitCaps,
QEMU_NBDKIT_CAPS_LAST,
/* 0 */
@@ -55,6 +52,9 @@ struct _qemuNbdkitCaps {
char *path;
char *version;
+ char *filterDir;
+ char *pluginDir;
+
time_t ctime;
time_t libvirtCtime;
time_t pluginDirMtime;
@@ -128,18 +128,47 @@ qemuNbdkitCapsQueryFilters(qemuNbdkitCaps *nbdkit)
static int
-qemuNbdkitCapsQueryVersion(qemuNbdkitCaps *nbdkit)
+qemuNbdkitCapsQueryBuildConfig(qemuNbdkitCaps *nbdkit)
{
+ size_t i;
+ g_autofree char *output = NULL;
+ g_auto(GStrv) lines = NULL;
+ const char *line;
g_autoptr(virCommand) cmd = virCommandNewArgList(nbdkit->path,
- "--version",
+ "--dump-config",
NULL);
- virCommandSetOutputBuffer(cmd, &nbdkit->version);
+ virCommandSetOutputBuffer(cmd, &output);
if (virCommandRun(cmd, NULL) != 0)
return -1;
- VIR_DEBUG("Got nbdkit version %s", nbdkit->version);
+ lines = g_strsplit(output, "\n", 0);
+ if (!lines)
+ return -1;
+
+ for (i = 0; (line = lines[i]); i++) {
+ const char *key;
+ const char *val;
+ char *p;
+
+ p = strchr(line, '=');
+ if (!p)
+ continue;
+
+ *p = '\0';
+ key = line;
+ val = p + 1;
+
+ VIR_DEBUG("Got nbdkit config value %s=%s", key, val);
+
+ if (STREQ(key, "version"))
+ nbdkit->version = g_strdup(val);
+ else if (STREQ(key, "filterdir"))
+ nbdkit->filterDir = g_strdup(val);
+ else if (STREQ(key, "plugindir"))
+ nbdkit->pluginDir = g_strdup(val);
+ }
return 0;
}
@@ -151,6 +180,8 @@ qemuNbdkitCapsFinalize(GObject *object)
g_clear_pointer(&nbdkit->path, g_free);
g_clear_pointer(&nbdkit->version, g_free);
+ g_clear_pointer(&nbdkit->filterDir, g_free);
+ g_clear_pointer(&nbdkit->pluginDir, g_free);
g_clear_pointer(&nbdkit->flags, virBitmapFree);
G_OBJECT_CLASS(qemu_nbdkit_caps_parent_class)->finalize(object);
@@ -213,15 +244,15 @@ qemuNbdkitCapsQuery(qemuNbdkitCaps *caps)
return;
}
+ qemuNbdkitCapsQueryBuildConfig(caps);
+ qemuNbdkitCapsQueryPlugins(caps);
+ qemuNbdkitCapsQueryFilters(caps);
+
caps->ctime = st.st_ctime;
- caps->filterDirMtime = qemuNbdkitGetDirMtime(NBDKIT_FILTERDIR);
- caps->pluginDirMtime = qemuNbdkitGetDirMtime(NBDKIT_PLUGINDIR);
+ caps->filterDirMtime = qemuNbdkitGetDirMtime(caps->filterDir);
+ caps->pluginDirMtime = qemuNbdkitGetDirMtime(caps->pluginDir);
caps->libvirtCtime = virGetSelfLastChanged();
caps->libvirtVersion = LIBVIR_VERSION_NUMBER;
-
- qemuNbdkitCapsQueryPlugins(caps);
- qemuNbdkitCapsQueryFilters(caps);
- qemuNbdkitCapsQueryVersion(caps);
}
@@ -266,9 +297,9 @@ virNbdkitCapsIsValid(void *data,
if (!nbdkitCaps->path)
return true;
- if (!virNbkditCapsCheckModdir(NBDKIT_PLUGINDIR, nbdkitCaps->pluginDirMtime))
+ if (!virNbkditCapsCheckModdir(nbdkitCaps->pluginDir,
nbdkitCaps->pluginDirMtime))
return false;
- if (!virNbkditCapsCheckModdir(NBDKIT_FILTERDIR, nbdkitCaps->filterDirMtime))
+ if (!virNbkditCapsCheckModdir(nbdkitCaps->filterDir,
nbdkitCaps->filterDirMtime))
return false;
if (nbdkitCaps->libvirtCtime != virGetSelfLastChanged() ||
@@ -420,12 +451,22 @@ qemuNbdkitCapsLoadCache(qemuNbdkitCaps *nbdkitCaps,
}
nbdkitCaps->ctime = (time_t)l;
+ if ((nbdkitCaps->pluginDir = virXPathString("string(./plugindir)",
ctxt)) == NULL) {
+ VIR_DEBUG("missing plugindir in nbdkit capabilities cache");
+ return -1;
+ }
+
if (virXPathLongLong("string(./plugindirmtime)", ctxt, &l) < 0) {
VIR_DEBUG("missing plugindirmtime in nbdkit capabilities XML");
return -1;
}
nbdkitCaps->pluginDirMtime = (time_t)l;
+ if ((nbdkitCaps->filterDir = virXPathString("string(./filterdir)",
ctxt)) == NULL) {
+ VIR_DEBUG("missing filterdir in nbdkit capabilities cache");
+ return -1;
+ }
+
if (virXPathLongLong("string(./filterdirmtime)", ctxt, &l) < 0) {
VIR_DEBUG("missing filterdirmtime in nbdkit capabilities XML");
return -1;
@@ -481,8 +522,12 @@ qemuNbdkitCapsFormatCache(qemuNbdkitCaps *nbdkitCaps)
nbdkitCaps->path);
virBufferAsprintf(&buf,
"<nbdkitctime>%lu</nbdkitctime>\n",
nbdkitCaps->ctime);
+ virBufferEscapeString(&buf, "<plugindir>%s</plugindir>\n",
+ nbdkitCaps->pluginDir);
virBufferAsprintf(&buf,
"<plugindirmtime>%lu</plugindirmtime>\n",
nbdkitCaps->pluginDirMtime);
+ virBufferEscapeString(&buf, "<filterdir>%s</filterdir>\n",
+ nbdkitCaps->filterDir);
virBufferAsprintf(&buf,
"<filterdirmtime>%lu</filterdirmtime>\n",
nbdkitCaps->filterDirMtime);
virBufferAsprintf(&buf, "<selfctime>%lu</selfctime>\n",
--
2.39.0