[libvirt PATCH 0/5] meson: Introduce qemu_datadir option

This is mostly useful to macOS users (see [1] for background). The first two commits are fixes for small issues discovered while looking into this. Test pipeline: https://gitlab.com/abologna/libvirt/-/pipelines/409294109 [1] https://gitlab.com/libvirt/libvirt/-/issues/168 Andrea Bolognani (5): meson: Define qemu_moddir correctly qemu: Set QEMU data location correctly qemu: Rename interop locations meson: Introduce qemu_datadir option spec: Explicitly provide locations for QEMU data libvirt.spec.in | 6 ++++++ meson.build | 8 +++++++- meson_options.txt | 1 + src/qemu/qemu_interop_config.c | 11 +++++------ 4 files changed, 19 insertions(+), 7 deletions(-) -- 2.31.1

We can't hardcode /usr here, because the user might have configured whatever arbitrary prefix. Everything appeared to be okay because when joining paths Meson will drop any component that precedes an absolute path and libdir happens to be absolute, but we should still do things correctly instead of relying on this. Fixes: 2ad009eadde27491ff4248f481560953776b2a87 Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index dd46572365..e1e4621868 100644 --- a/meson.build +++ b/meson.build @@ -1681,7 +1681,7 @@ if not get_option('driver_qemu').disabled() qemu_moddir = get_option('qemu_moddir') if qemu_moddir == '' - qemu_moddir = '/usr' / libdir / 'qemu' + qemu_moddir = libdir / 'qemu' endif conf.set_quoted('QEMU_MODDIR', qemu_moddir) -- 2.31.1

While datadir must live under prefix, there is no requirement that its name must necessarily be "share": a different, arbitrary name could have been provided by the user. Fixes: 3c876d2428ee3abbb11a50698a9e225cffb72cbc Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- src/qemu/qemu_interop_config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qemu/qemu_interop_config.c b/src/qemu/qemu_interop_config.c index 848e8f7381..fe1bd44b41 100644 --- a/src/qemu/qemu_interop_config.c +++ b/src/qemu/qemu_interop_config.c @@ -80,7 +80,7 @@ qemuBuildFileList(GHashTable *files, const char *dir) return 0; } -#define QEMU_SYSTEM_LOCATION PREFIX "/share/qemu" +#define QEMU_SYSTEM_LOCATION DATADIR "/qemu" #define QEMU_ETC_LOCATION SYSCONFDIR "/qemu" int -- 2.31.1

Use abstract names that more closely match the Meson nomenclature. Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- src/qemu/qemu_interop_config.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_interop_config.c b/src/qemu/qemu_interop_config.c index fe1bd44b41..d3f1f34ecf 100644 --- a/src/qemu/qemu_interop_config.c +++ b/src/qemu/qemu_interop_config.c @@ -80,8 +80,8 @@ qemuBuildFileList(GHashTable *files, const char *dir) return 0; } -#define QEMU_SYSTEM_LOCATION DATADIR "/qemu" -#define QEMU_ETC_LOCATION SYSCONFDIR "/qemu" +#define QEMU_DATADIR DATADIR "/qemu" +#define QEMU_CONFDIR SYSCONFDIR "/qemu" int qemuInteropFetchConfigs(const char *name, @@ -91,8 +91,8 @@ qemuInteropFetchConfigs(const char *name, g_autoptr(GHashTable) files = virHashNew(g_free); g_autofree char *homeConfig = NULL; g_autofree char *xdgConfig = NULL; - g_autofree char *sysLocation = virFileBuildPath(QEMU_SYSTEM_LOCATION, name, NULL); - g_autofree char *etcLocation = virFileBuildPath(QEMU_ETC_LOCATION, name, NULL); + g_autofree char *dataLocation = virFileBuildPath(QEMU_DATADIR, name, NULL); + g_autofree char *confLocation = virFileBuildPath(QEMU_CONFDIR, name, NULL); g_autofree virHashKeyValuePair *pairs = NULL; size_t npairs; virHashKeyValuePair *tmp = NULL; @@ -117,10 +117,10 @@ qemuInteropFetchConfigs(const char *name, homeConfig = g_strdup_printf("%s/qemu/%s", xdgConfig, name); } - if (qemuBuildFileList(files, sysLocation) < 0) + if (qemuBuildFileList(files, dataLocation) < 0) return -1; - if (qemuBuildFileList(files, etcLocation) < 0) + if (qemuBuildFileList(files, confLocation) < 0) return -1; if (homeConfig && -- 2.31.1

There is no guarantee that QEMU and libvirt have been configured with the same prefix. In particular, Homebrew on macOS will pass a different, private prefix for each package version and then use symlinks to make the files for a specific version appear in the usual locations. This works perfectly fine as long as one package doesn't try to go poking around another package's data - which is exactly what libvirt needs to do in order to read and parse the QEMU interop data. qemu_datadir can now be explicitly provided to make this and other uncommon scenarios work. The common scenario, where QEMU and libvirt both use the same prefix, is unaffected. https://gitlab.com/libvirt/libvirt/-/issues/168 Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- meson.build | 6 ++++++ meson_options.txt | 1 + src/qemu/qemu_interop_config.c | 1 - 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index e1e4621868..9022bcfdc9 100644 --- a/meson.build +++ b/meson.build @@ -1685,6 +1685,12 @@ if not get_option('driver_qemu').disabled() endif conf.set_quoted('QEMU_MODDIR', qemu_moddir) + qemu_datadir = get_option('qemu_datadir') + if qemu_datadir == '' + qemu_datadir = datadir / 'qemu' + endif + conf.set_quoted('QEMU_DATADIR', qemu_datadir) + if host_machine.system() in [ 'freebsd', 'darwin' ] default_qemu_user = 'root' default_qemu_group = 'wheel' diff --git a/meson_options.txt b/meson_options.txt index 859ed36b8f..5b43cdbd6b 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -62,6 +62,7 @@ option('driver_qemu', type: 'feature', value: 'auto', description: 'QEMU/KVM dri option('qemu_user', type: 'string', value: '', description: 'username to run QEMU system instance as') option('qemu_group', type: 'string', value: '', description: 'groupname to run QEMU system instance as') option('qemu_moddir', type: 'string', value: '', description: 'set the directory where QEMU modules are located') +option('qemu_datadir', type: 'string', value: '', description: 'set the directory where QEMU shared data is located') option('driver_remote', type: 'feature', value: 'auto', description: 'remote driver') option('remote_default_mode', type: 'combo', choices: ['legacy', 'direct'], value: 'direct', description: 'remote driver default mode') option('driver_secrets', type: 'feature', value: 'auto', description: 'local secrets management driver') diff --git a/src/qemu/qemu_interop_config.c b/src/qemu/qemu_interop_config.c index d3f1f34ecf..24db722c0b 100644 --- a/src/qemu/qemu_interop_config.c +++ b/src/qemu/qemu_interop_config.c @@ -80,7 +80,6 @@ qemuBuildFileList(GHashTable *files, const char *dir) return 0; } -#define QEMU_DATADIR DATADIR "/qemu" #define QEMU_CONFDIR SYSCONFDIR "/qemu" int -- 2.31.1

These are the defaults, but we prefer to be explicit. Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- libvirt.spec.in | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libvirt.spec.in b/libvirt.spec.in index 5f1773ef93..80770a41bb 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -190,6 +190,10 @@ %define qemu_user qemu %define qemu_group qemu +# Locations for QEMU data +%define qemu_moddir %{_libdir}/qemu +%define qemu_datadir %{_datadir}/qemu + # RHEL releases provide stable tool chains and so it is safe to turn # compiler warning into errors without being worried about frequent @@ -1160,6 +1164,8 @@ export SOURCE_DATE_EPOCH=$(stat --printf='%Y' %{_specdir}/%{name}.spec) %{arg_packager_version} \ -Dqemu_user=%{qemu_user} \ -Dqemu_group=%{qemu_group} \ + -Dqemu_moddir=%{qemu_moddir} \ + -Dqemu_datadir=%{qemu_datadir} \ -Dtls_priority=%{tls_priority} \ %{?enable_werror} \ -Dexpensive_tests=enabled \ -- 2.31.1

On a Monday in 2021, Andrea Bolognani wrote:
This is mostly useful to macOS users (see [1] for background).
The first two commits are fixes for small issues discovered while looking into this.
Test pipeline: https://gitlab.com/abologna/libvirt/-/pipelines/409294109
[1] https://gitlab.com/libvirt/libvirt/-/issues/168
Andrea Bolognani (5): meson: Define qemu_moddir correctly qemu: Set QEMU data location correctly qemu: Rename interop locations meson: Introduce qemu_datadir option spec: Explicitly provide locations for QEMU data
libvirt.spec.in | 6 ++++++ meson.build | 8 +++++++- meson_options.txt | 1 + src/qemu/qemu_interop_config.c | 11 +++++------ 4 files changed, 19 insertions(+), 7 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano
participants (2)
-
Andrea Bolognani
-
Ján Tomko