From nobody Sat Nov 23 18:18:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1723387547; cv=none; d=zohomail.com; s=zohoarc; b=hN1g2UdoZ0ekuekqOL8hPn18JkKTbMQa+m/b+vLaa+l25i+tkq1cHoBkWzcUhgefFLjeKxHWhYZMdxIc68ZkQyE92Om6SIBU0zszc/WlJ44/rnPASUQYDlkEIPo8PvPFxLMT+piyNQlyt5svRoIbe2TM17s3sOX+i4vCz9wJuqU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1723387547; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id; bh=KnYOAc/uzMlZqSaNBqZgCrizYNBEsOr2n6Gc+tIGv3Q=; b=gKVScsGSQR/ounftvZiX4ggEOZLPig80BZVM44/mkU5zlRszkYTLktY34E0QaId/qTondf7IdmxNKvcFWOYb5Aqs2uDhcZjDFg/ERZ27zNGiA/F99/8iF5shU0BYpv6UcMrXhmhGF2ermYsVhdm0Zbq0IqNJzZnQT3UgXXGaj6w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1723387547754532.6258812273675; Sun, 11 Aug 2024 07:45:47 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id B420111AD; Sun, 11 Aug 2024 10:45:46 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 01E7615B7; Sun, 11 Aug 2024 10:44:18 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 59A711528; Sun, 11 Aug 2024 10:44:11 -0400 (EDT) Received: from relay.virtuozzo.com (relay.virtuozzo.com [130.117.225.111]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 95D8312C1 for ; Sun, 11 Aug 2024 10:44:10 -0400 (EDT) Received: from [130.117.225.1] (helo=vz9-barybin-2.ch-qa.vzint.dev) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1sd9m7-00FzIb-1f; Sun, 11 Aug 2024 16:44:02 +0200 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-ID:Date:Subject:From: Content-Type; bh=sfrCsrUjGwNYnELqoVYYLboi46PacmpKjKrA32CMEXU=; b=Y5lRb4i41dov DcncsNW8wRG7/YDJmWCvfIwIutBEFJUwdy9eH+HFS2JVivGXBoPGVl6Oj8OSe0XkVUSjw1jzr5nl5 T8VrPBr31nLuqs7JZyqe2ZfF053Cli+18LIjjRiv/gi8PpFtE2n5GVgPicUHObjx9e1TU0C0Pfa73 WMDVaLNHqfp7fhR+ihOuf1fsBTenEpnSJAYjWyq5JVtcvWUTvVpPJG/B/E6r4MU0/z9WegmcJP/Mv L8GTePrGq7mjN5ZROWdPovAUp/yj5o9GWNKtVOq1f7z8qz8B9ArpwJlsXx7WzCNYAWOseaYW0vRjH BgCEaAeZbZ1gl8h9rZbFSA==; To: devel@lists.libvirt.org Subject: [PATCH 3/3] qemu: enable qcow2 data-file attach to VM on start Date: Sun, 11 Aug 2024 17:34:48 +0300 Message-ID: <20240811144340.60108-4-nikolai.barybin@virtuozzo.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240811144340.60108-1-nikolai.barybin@virtuozzo.com> References: <20240811144340.60108-1-nikolai.barybin@virtuozzo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: LZJZCDQZ4KL7QKUIQOQBRFRPENXYDSIM X-Message-ID-Hash: LZJZCDQZ4KL7QKUIQOQBRFRPENXYDSIM X-MailFrom: nikolai.barybin@virtuozzo.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: den@openvz.org, Nikolai Barybin X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: From: Nikolai Barybin via Devel Reply-To: Nikolai Barybin X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1723387548449116600 Content-Type: text/plain; charset="utf-8" - parse data-file metadata and init src->dataFileStore struct - chown data-file to allow qemu to open it - add data-file path to VM's cgroup and namespace - add data-file option to QEMU process command line Signed-off-by: Nikolai Barybin --- src/qemu/qemu_block.c | 45 +++++++++++++++++++++++++++++++ src/qemu/qemu_cgroup.c | 3 +++ src/qemu/qemu_namespace.c | 6 +++++ src/storage_file/storage_source.c | 38 ++++++++++++++++++++++++-- 4 files changed, 90 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index d6cdf521c4..38f4717d56 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -1271,6 +1271,48 @@ qemuBlockStorageSourceGetFormatQcowGenericProps(virS= torageSource *src, } =20 =20 +static int +qemuBlockStorageGetQcow2DataFileProps(virStorageSource *src, + virJSONValue *props) +{ + g_autoptr(virJSONValue) dataFileDef =3D NULL; + virStorageType actualType; + g_autofree char *driverName =3D NULL; + + if (!src->dataFileRaw) + return 0; + + actualType =3D virStorageSourceGetActualType(src->dataFileStore); + if (actualType !=3D VIR_STORAGE_TYPE_BLOCK && + actualType !=3D VIR_STORAGE_TYPE_FILE) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("%1$s storage type is not supported for qcow2 dat= a-file"), + NULLSTR(virStorageTypeToString(actualType))); + return -1; + } + + if (virStorageSourceIsBlockLocal(src->dataFileStore)) + driverName =3D g_strdup("host_device"); + else + driverName =3D g_strdup("file"); + + if (virJSONValueObjectAdd(&dataFileDef, + "s:driver", driverName, + "b:read-only", src->readonly, + "s:filename", src->dataFileRaw, + NULL) < 0) + return -1; + + if (virJSONValueObjectAdd(&props, + "A:data-file", &dataFileDef, + NULL) < 0) + return -1; + + return 0; +} + + + static int qemuBlockStorageSourceGetFormatQcow2Props(virStorageSource *src, virJSONValue *props) @@ -1301,6 +1343,9 @@ qemuBlockStorageSourceGetFormatQcow2Props(virStorageS= ource *src, NULL) < 0) return -1; =20 + if (qemuBlockStorageGetQcow2DataFileProps(src, props) < 0) + return -1; + return 0; } =20 diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 23b7e6b4e8..84c749b567 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -223,6 +223,9 @@ qemuSetupImageCgroupInternal(virDomainObj *vm, qemuSetupImagePathCgroup(vm, QEMU_DEVICE_MAPPER_CONTROL_PATH, fals= e) < 0) return -1; =20 + if (src->dataFileRaw && qemuSetupImagePathCgroup(vm, src->dataFileRaw,= readonly) < 0) + return -1; + return qemuSetupImagePathCgroup(vm, path, readonly); } =20 diff --git a/src/qemu/qemu_namespace.c b/src/qemu/qemu_namespace.c index bbe3d5a1f7..32653443ec 100644 --- a/src/qemu/qemu_namespace.c +++ b/src/qemu/qemu_namespace.c @@ -290,6 +290,12 @@ qemuDomainSetupDisk(virStorageSource *src, =20 if (targetPaths) *paths =3D g_slist_concat(g_slist_reverse(targetPaths), *p= aths); + + if (next->dataFileRaw) { + g_autofree char *datafile =3D NULL; + datafile =3D g_strdup(next->dataFileRaw); + *paths =3D g_slist_prepend(*paths, g_steal_pointer(&datafi= le)); + } } =20 *paths =3D g_slist_prepend(*paths, g_steal_pointer(&tmpPath)); diff --git a/src/storage_file/storage_source.c b/src/storage_file/storage_s= ource.c index 2cfe3bc325..0ea11228d4 100644 --- a/src/storage_file/storage_source.c +++ b/src/storage_file/storage_source.c @@ -1378,8 +1378,16 @@ virStorageSourceGetMetadataRecurse(virStorageSource = *src, &buf, &headerLen) < 0) return -1; =20 - if (virStorageFileProbeGetMetadata(src, buf, headerLen) < 0) - return -1; + if (!parent->dataFileRaw) { + if (virStorageFileProbeGetMetadata(src, buf, headerLen) < 0) + return -1; + } else { + if (virStorageSourceInitAs(src, uid, gid) < 0) + return -1; + if (virStorageSourceChown(src, uid, gid) < 0) + return -1; + virStorageSourceDeinit(src); + } =20 /* If we probed the format we MUST ensure that nothing else than the c= urrent * image is considered for security labelling and/or recursion. */ @@ -1417,6 +1425,32 @@ virStorageSourceGetMetadataRecurse(virStorageSource = *src, =20 backingStore->id =3D depth; src->backingStore =3D g_steal_pointer(&backingStore); + + } else if (src->dataFileRaw) { + if ((rv =3D virStorageSourceNewFromChild(src, src->dataFileRaw, &b= ackingStore)) < 0) + return -1; + + if (rv =3D=3D 1) + return 0; + + if ((rv =3D virStorageSourceGetMetadataRecurse(backingStore, paren= t, + uid, gid, + report_broken, + max_depth, depth + 1)= ) < 0) { + if (!report_broken) + return 0; + + if (rv =3D=3D -2) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("format of data file image '%1$s' of imag= e '%2$s' was not specified in the image metadata (See https://libvirt.org/k= base/backing_chains.html for troubleshooting)"), + src->dataFileRaw, NULLSTR(src->path)); + } + + return -1; + } + + backingStore->id =3D depth; + src->dataFileStore =3D g_steal_pointer(&backingStore); } else { /* add terminator */ src->backingStore =3D virStorageSourceNew(); --=20 2.43.5