From: Marc-André Lureau <marcandre.lureau(a)redhat.com>
Add an option to ease setting up a VM with existing libvirt qemu.conf.
Fixes:
https://bugzilla.redhat.com/show_bug.cgi?id=1817776
Signed-off-by: Marc-André Lureau <marcandre.lureau(a)redhat.com>
---
docs/manpages/virt-qemu-run.rst | 6 ++++++
src/libvirt_private.syms | 1 -
src/qemu/qemu_shim.c | 36 +++++++++++++++++++++++++++++++++
3 files changed, 42 insertions(+), 1 deletion(-)
diff --git a/docs/manpages/virt-qemu-run.rst b/docs/manpages/virt-qemu-run.rst
index b06c311b1d..3196b4c8f4 100644
--- a/docs/manpages/virt-qemu-run.rst
+++ b/docs/manpages/virt-qemu-run.rst
@@ -71,6 +71,12 @@ is a path to the XML description of the secret, whose UUID should
match a secret referenced in the guest domain XML. The ``VALUE-FILE``
is a path containing the raw value of the secret.
+``-c``, ``--with-config``
+
+Copy the libvirt qemu.conf configuration to the root directory. If
+there is already a qemu.conf file in the $ROOT/etc directory, exit
+with failure.
+
EXIT STATUS
===========
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 88fea4fc43..cb2b279401 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1899,7 +1899,6 @@ virConfWalk;
virConfWriteFile;
virConfWriteMem;
-
# util/vircrypto.h
virCryptoEncryptData;
virCryptoHashBuf;
diff --git a/src/qemu/qemu_shim.c b/src/qemu/qemu_shim.c
index 7e87b8fb96..553a37ab60 100644
--- a/src/qemu/qemu_shim.c
+++ b/src/qemu/qemu_shim.c
@@ -24,6 +24,7 @@
#include <stdbool.h>
#include <unistd.h>
+#include "virconf.h"
#include "virfile.h"
#include "virstring.h"
#include "virgettext.h"
@@ -99,6 +100,7 @@ int main(int argc, char **argv)
g_auto(GStrv) secrets = NULL;
gboolean verbose = false;
gboolean debug = false;
+ gboolean with_config = false;
GStrv tmpsecrets;
GOptionContext *ctx;
GOptionEntry entries[] = {
@@ -106,6 +108,7 @@ int main(int argc, char **argv)
{ "root", 'r', 0, G_OPTION_ARG_STRING, &root, "Root
directory", "DIR" },
{ "debug", 'd', 0, G_OPTION_ARG_NONE, &debug, "Debug
output", NULL },
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
"Verbose output", NULL },
+ { "with-config", 'c', 0, G_OPTION_ARG_NONE, &with_config,
"Use system/home qemu.conf", NULL },
{ 0 }
};
int quitfd[2] = {-1, -1};
@@ -167,6 +170,39 @@ int main(int argc, char **argv)
}
}
+ if (with_config) {
+ g_autofree char *src = virConfLoadConfigPath("qemu.conf");
+ g_autofree char *dir = g_build_filename(root, "etc", NULL);
+ g_autofree char *dst = g_build_filename(dir, "qemu.conf", NULL);
+ g_autofree char *contents = NULL;
+ gsize len;
+
+ if (g_mkdir_with_parents(dir, 0755) < 0) {
+ g_printerr("%s: cannot create %s dir: %s\n",
+ argv[0], dir, g_strerror(errno));
+ goto cleanup;
+ }
+
+
+ if (g_file_test(dst, G_FILE_TEST_EXISTS)) {
+ g_printerr("%s: %s file already exists\n",
+ argv[0], dst);
+ goto cleanup;
+ }
+
+ if (!g_file_get_contents(src, &contents, &len, &error)) {
+ g_printerr("%s: cannot read %s: %s\n",
+ argv[0], src, error->message);
+ goto cleanup;
+ }
+
+ if (!g_file_set_contents(dst, contents, len, &error)) {
+ g_printerr("%s: cannot write %s: %s\n",
+ argv[0], dst, error->message);
+ goto cleanup;
+ }
+ }
+
virFileActivateDirOverrideForProg(argv[0]);
if (verbose)
--
2.26.0.rc2.42.g98cedd0233