From nobody Mon Apr 29 09:24:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) client-ip=216.205.24.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1585352362; cv=none; d=zohomail.com; s=zohoarc; b=V7daMS1iIBeORYsabP+jKP+1crFq3vwqELHwVqVGu9sCEEaxXqhECUy3vLJVi1oBY1JGqSnr5xNFMwjGpUUULmioAju47SIi1bkBljPKkTg3VWvbyPvGyCyfHPAbrGbZen9TrmqISBrjZfqY5JKJ0Q2GXVzQB1/OdAUzGFzorL4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585352362; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=e7C0EK3RXtxJMlSAW6swYXz+WbkwsZTGQl2J3xVjCVU=; b=nZvMsugICOdjTVUfGR/cqQlCyix7z5VuTI8OHGQGgjj7TzdTlcAe436NiENRboAv3E6PpNLvrm3RpvjWrp5Tnip4gvcXHihblYFtA9MGfAR2bxHR/0oD02pIp/1WysoRgPc2i+4OQY8viVDmnNQy8cmcl89hl9wwi9kp5pqfN6w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [216.205.24.74]) by mx.zohomail.com with SMTPS id 1585352362930940.6208302302383; Fri, 27 Mar 2020 16:39:22 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-339-VJGvz_RyOse6XbitrAH0sA-1; Fri, 27 Mar 2020 19:39:19 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 193AA18B9FC1; Fri, 27 Mar 2020 23:39:12 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 927371001925; Fri, 27 Mar 2020 23:39:09 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 282D718089CD; Fri, 27 Mar 2020 23:39:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02RNd4vr025175 for ; Fri, 27 Mar 2020 19:39:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id 61FDA5C8A6; Fri, 27 Mar 2020 23:39:04 +0000 (UTC) Received: from localhost (unknown [10.36.110.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2B4635C883; Fri, 27 Mar 2020 23:38:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585352361; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=e7C0EK3RXtxJMlSAW6swYXz+WbkwsZTGQl2J3xVjCVU=; b=Dl37UFd34vAWDv+3g4qiMqTXaHQW3/MMWjgZCV/24yT6ItG4fpwy8cJhq2vjGcWJBfU1tA oRfdlR5cqkLM7ZiFFmR0tvIaYS2hflPF8n8Ic7o8oW0rU9RJrfXbF5GVU/WBxulu2W2/9Q VhW584TIViXGdqoptreZdCy7cLecesc= X-MC-Unique: VJGvz_RyOse6XbitrAH0sA-1 From: marcandre.lureau@redhat.com To: libvir-list@redhat.com Subject: [PATCH] qemu-shim: add a --with-config option Date: Sat, 28 Mar 2020 00:38:57 +0100 Message-Id: <20200327233857.2673304-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Marc-Andr=C3=A9 Lureau Add an option to ease setting up a VM with existing libvirt qemu.conf. Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=3D1817776 Signed-off-by: Marc-Andr=C3=A9 Lureau --- 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 UU= ID should match a secret referenced in the guest domain XML. The ``VALUE-FILE`` is a path containing the raw value of the secret. =20 +``-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 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 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; =20 - # 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 #include =20 +#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 =3D NULL; gboolean verbose =3D false; gboolean debug =3D false; + gboolean with_config =3D false; GStrv tmpsecrets; GOptionContext *ctx; GOptionEntry entries[] =3D { @@ -106,6 +108,7 @@ int main(int argc, char **argv) { "root", 'r', 0, G_OPTION_ARG_STRING, &root, "Root directory", "D= IR" }, { "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 sys= tem/home qemu.conf", NULL }, { 0 } }; int quitfd[2] =3D {-1, -1}; @@ -167,6 +170,39 @@ int main(int argc, char **argv) } } =20 + if (with_config) { + g_autofree char *src =3D virConfLoadConfigPath("qemu.conf"); + g_autofree char *dir =3D g_build_filename(root, "etc", NULL); + g_autofree char *dst =3D g_build_filename(dir, "qemu.conf", NULL); + g_autofree char *contents =3D 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]); =20 if (verbose) --=20 2.26.0.rc2.42.g98cedd0233