From nobody Mon Feb 9 01:47:22 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 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=1558092088; cv=none; d=zoho.com; s=zohoarc; b=L4qFLRlRScKOUMDeqqtsgOmTNI6MhogC8CLn2pmIq3YITRsvOdHXlbG9BOd3wOckCDKkLba/Ei5fVL0lFfNTMCioUkpn7VjfQ+Q++Krc0uxOVfaUdOV18uDE5A1+zcTehdD1bnz63KQUc/bjHFCNmQ5O5bI+UYxjw3VWfvl//qM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558092088; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=eO9vpeKwhELwxS1THgRY22o0cOaFcOGsaGQU7BaB624=; b=Kpht0CPj9qAGI+UxER7qLeCxUup8vjkwYrRugTr4VIaRMM29UmB9VJf2WSX3zLuWzRJ+2OI7n0IuHcmW/VMjK6rqkjEv6+fLn4E6t7WaAQvccICBaS/Z12G38LGqmDLqv3tc2TO4F9aEivbSzqLZmNFfL0tBsvq0E/xObvYiFy4= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 155809208872047.24666035130235; Fri, 17 May 2019 04:21:28 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F22F09D406; Fri, 17 May 2019 11:21:23 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C23CB78381; Fri, 17 May 2019 11:21:23 +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 83DCA206D6; Fri, 17 May 2019 11:21:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x4HBKShE000994 for ; Fri, 17 May 2019 07:20:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9FF28473BE; Fri, 17 May 2019 11:20:28 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 296D158C87 for ; Fri, 17 May 2019 11:20:17 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 17 May 2019 13:19:56 +0200 Message-Id: <1728dc9aebf218633bb50b8d64927b23ace885d9.1558091835.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 10/12] qemu: Validate backing store of 'mirror' for block copy 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 17 May 2019 11:21:25 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Since 4e797f1a we parse backingStore of mirror which will later be used with blockdev. Add some validation for the user passed mirror at the current point to make sure it's not used improperly. Validate that it's not used without blockdev and also that it's not passed when not requesting a shallow copy. Also add a chain terminator for a deep copy since we know the resulting mirror will not have chain. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_driver.c | 72 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 66 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 66a6eb0483..a9c41d1592 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -17560,6 +17560,63 @@ qemuDomainBlockCopyValidateMirror(virStorageSource= Ptr mirror, } +/** + * qemuDomainBlockCopyCommonValidateUserMirrorBackingStore: + * @mirror: target of the block copy + * @flags: block copy API flags + * @blockdev: true if blockdev is used for the VM + * + * Validates whether backingStore of @mirror makes sense according to @fla= gs. + * This makes sure that: + * 1) mirror has a terminator if it isn't supposed to have backing chain + * 2) if shallow copy is requested there is a chain or prepopulated image + * 3) user specified chain is present only when blockdev is used + * 4) if deep copy is requested, there's no chain + */ +static int +qemuDomainBlockCopyCommonValidateUserMirrorBackingStore(virStorageSourcePt= r mirror, + unsigned int flags, + bool blockdev) +{ + /* note that if original disk does not have backing chain, shallow is = cleared */ + bool shallow =3D flags & VIR_DOMAIN_BLOCK_COPY_SHALLOW; + bool reuse =3D flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT; + + if (!mirror->backingStore) { + /* deep copy won't need backing store so we can terminate it */ + if (!shallow && + !(mirror->backingStore =3D virStorageSourceNew())) + return -1; + + return 0; + } + + /* validate user provided backing store */ + if (virStorageSourceHasBacking(mirror)) { + if (!blockdev) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("backingStore of mirror target is not support= ed by this qemu")); + return -1; + } + + if (!shallow) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("backingStore of mirror without VIR_DOMAIN_BL= OCK_COPY_SHALLOW doesn't make sense")); + return -1; + } + } else { + /* shallow copy without reuse requires some kind of backing data */ + if (!reuse && shallow) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("VIR_DOMAIN_BLOCK_COPY_SHALLOW implies backin= g chain for mirror")); + return -1; + } + } + + return 0; +} + + /* bandwidth in bytes/s. Caller must lock vm beforehand, and not * access mirror afterwards. */ static int @@ -17574,7 +17631,7 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm, bool keepParentLabel) { virQEMUDriverPtr driver =3D conn->privateData; - qemuDomainObjPrivatePtr priv; + qemuDomainObjPrivatePtr priv =3D vm->privateData; VIR_AUTOFREE(char *) device =3D NULL; virDomainDiskDefPtr disk =3D NULL; int ret =3D -1; @@ -17584,14 +17641,13 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm, bool reuse =3D !!(flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT); qemuBlockJobDataPtr job =3D NULL; VIR_AUTOUNREF(virStorageSourcePtr) mirror =3D mirrorsrc; + bool blockdev =3D virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV); /* Preliminaries: find the disk we are editing, sanity checks */ virCheckFlags(VIR_DOMAIN_BLOCK_COPY_SHALLOW | VIR_DOMAIN_BLOCK_COPY_REUSE_EXT | VIR_DOMAIN_BLOCK_COPY_TRANSIENT_JOB, -1); - priv =3D vm->privateData; - if (virStorageSourceIsRelative(mirror)) { virReportError(VIR_ERR_INVALID_ARG, "%s", _("absolute path must be used as block copy target"= )); @@ -17640,6 +17696,10 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm, if (!virStorageSourceHasBacking(disk->src)) flags &=3D ~VIR_DOMAIN_BLOCK_COPY_SHALLOW; + if (qemuDomainBlockCopyCommonValidateUserMirrorBackingStore(mirror, fl= ags, + blockdev) = < 0) + goto endjob; + /* unless the user provides a pre-created file, shallow copy into a raw * file is not possible */ if ((flags & VIR_DOMAIN_BLOCK_COPY_SHALLOW) && !reuse && @@ -17705,11 +17765,11 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm, keepParentLabel) < 0) goto endjob; - /* If reusing an external image that includes a backing file, the pivo= t may - * result in qemu needing to open the entire backing chain, so we need= to - * label the full backing chain of the mirror instead of just the top = image */ + /* If reusing an external image that includes a backing file but the u= ser + * did not enumerate the chain in the XML we need to detect the chain = */ if (flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT && mirror->format >=3D VIR_STORAGE_FILE_BACKING && + mirror->backingStore =3D=3D NULL && qemuDomainDetermineDiskChain(driver, vm, disk, mirror, true) < 0) goto endjob; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list