From nobody Sun May 5 18:29:59 2024 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1499788006216361.68612751762316; Tue, 11 Jul 2017 08:46:46 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3978EC04B92B; Tue, 11 Jul 2017 15:46:44 +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 CCAF077DE0; Tue, 11 Jul 2017 15:46:43 +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 0164E1853E31; Tue, 11 Jul 2017 15:46:42 +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 v6BFkeQn026829 for ; Tue, 11 Jul 2017 11:46:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6B41A177F2; Tue, 11 Jul 2017 15:46:40 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id BAD11177DA; Tue, 11 Jul 2017 15:46:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3978EC04B92B Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 3978EC04B92B From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 11 Jul 2017 17:46:38 +0200 Message-Id: <30e2308692334c7278e784900710e53e0456aef3.1499787961.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 1/5] qemu: driver: Split out access to VIR_DOMAIN_BLOCK_COPY_REUSE_EXT 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: , MIME-Version: 1.0 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 11 Jul 2017 15:46:45 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Extract the presence of the flag into a boolean to simplify conditions and allow further manipulation of the state of the flag. Reviewed-by: John Ferlan --- src/qemu/qemu_driver.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index a7019c53c..d03a9dbc3 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -16709,6 +16709,7 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm, const char *format =3D NULL; int desttype =3D virStorageSourceGetActualType(mirror); virErrorPtr monitor_error =3D NULL; + bool reuse =3D !!(flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT); /* Preliminaries: find the disk we are editing, sanity checks */ virCheckFlags(VIR_DOMAIN_BLOCK_COPY_SHALLOW | @@ -16769,8 +16770,7 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm, /* unless the user provides a pre-created file, shallow copy into a raw * file is not possible */ - if ((flags & VIR_DOMAIN_BLOCK_COPY_SHALLOW) && - !(flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT) && + if ((flags & VIR_DOMAIN_BLOCK_COPY_SHALLOW) && !reuse && mirror->format =3D=3D VIR_STORAGE_FILE_RAW) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("shallow copy of disk '%s' into a raw file " @@ -16791,15 +16791,14 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm, virReportSystemError(errno, _("unable to stat for disk %s: %s"= ), disk->dst, mirror->path); goto endjob; - } else if (flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT || - desttype =3D=3D VIR_STORAGE_TYPE_BLOCK) { + } else if (reuse || desttype =3D=3D VIR_STORAGE_TYPE_BLOCK) { virReportSystemError(errno, _("missing destination file for disk %s: = %s"), disk->dst, mirror->path); goto endjob; } } else if (!S_ISBLK(st.st_mode)) { - if (st.st_size && !(flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT)) { + if (st.st_size && !reuse) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("external destination file for disk %s alread= y " "exists and is not a block device: %s"), @@ -16816,7 +16815,7 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm, } if (!mirror->format) { - if (!(flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT)) { + if (!reuse) { mirror->format =3D disk->src->format; } else { /* If the user passed the REUSE_EXT flag, then either they @@ -16829,7 +16828,7 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm, } /* pre-create the image file */ - if (!(flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT)) { + if (!reuse) { int fd =3D qemuOpenFile(driver, vm, mirror->path, O_WRONLY | O_TRUNC | O_CREAT, &need_unlink, NULL); --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 18:29:59 2024 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1499788019278948.9029730139387; Tue, 11 Jul 2017 08:46:59 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7D3C44E4D8; Tue, 11 Jul 2017 15:46:57 +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 5156E177EF; Tue, 11 Jul 2017 15:46:57 +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 E82B41853E38; Tue, 11 Jul 2017 15:46:56 +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 v6BFkgwh026861 for ; Tue, 11 Jul 2017 11:46:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9330D18028; Tue, 11 Jul 2017 15:46:42 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id E5548177F2; Tue, 11 Jul 2017 15:46:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7D3C44E4D8 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 7D3C44E4D8 From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 11 Jul 2017 17:46:39 +0200 Message-Id: <77ac57aa05a6efc092451787d97d8ea21466ee2e.1499787961.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 2/5] qemu: blockcopy: Explicitly assert 'reuse' for block devices 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: , MIME-Version: 1.0 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 11 Jul 2017 15:46:58 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When copying to a block device, the block device will already exist. To allow users using a block device without any preparation, they need to use the block copy without VIR_DOMAIN_BLOCK_COPY_REUSE_EXT. This means that if the target is an existing block device we don't need to prepare it, but we can't reject it as being existing. To avoid breaking this feature, explicitly assume that existing block devices will be reused even without that flag explicitly specified, while skipping attempts to create it. qemuMonitorDriveMirror still needs to honor the flag as specified by the user, since qemu overwrites the metadata otherwise. Reviewed-by: John Ferlan --- src/qemu/qemu_driver.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index d03a9dbc3..d00166f23 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -16812,6 +16812,10 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm, disk->dst, mirror->path); goto endjob; } + } else { + /* if the target is a block device, assume that we are reusing it,= so + * there are no attempts to create it */ + reuse =3D true; } if (!mirror->format) { @@ -16851,6 +16855,8 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm, /* Actually start the mirroring */ qemuDomainObjEnterMonitor(driver, vm); + /* qemuMonitorDriveMirror needs to honor the REUSE_EXT flag as specifi= ed + * by the user regardless of how @reuse was modified */ ret =3D qemuMonitorDriveMirror(priv->mon, device, mirror->path, format, bandwidth, granularity, buf_size, flags); virDomainAuditDisk(vm, NULL, mirror, "mirror", ret >=3D 0); --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 18:29:59 2024 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1499788009156167.75392408170046; Tue, 11 Jul 2017 08:46:49 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8AB3861B8D; Tue, 11 Jul 2017 15:46:47 +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 55A2B7F1DD; Tue, 11 Jul 2017 15:46:47 +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 DF96D1853E34; Tue, 11 Jul 2017 15:46:46 +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 v6BFkjQi026901 for ; Tue, 11 Jul 2017 11:46:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 59EF0177F2; Tue, 11 Jul 2017 15:46:45 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id AB35B18028; Tue, 11 Jul 2017 15:46:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8AB3861B8D Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 8AB3861B8D From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 11 Jul 2017 17:46:40 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 3/5] qemu: blockcopy: reuse storage driver APIs to pre-create copy target 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: , MIME-Version: 1.0 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 11 Jul 2017 15:46:48 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Rather than using the local-file only implementation 'qemuOpenFile' switch to the imagelabel aware storage driver implementation. Reviewed-by: John Ferlan --- src/qemu/qemu_driver.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index d00166f23..48dc5e5cc 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -16786,6 +16786,10 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm, _("non-file destination not supported yet")); goto endjob; } + + if (qemuDomainStorageFileInit(driver, vm, mirror) < 0) + goto endjob; + if (stat(mirror->path, &st) < 0) { if (errno !=3D ENOENT) { virReportSystemError(errno, _("unable to stat for disk %s: %s"= ), @@ -16833,12 +16837,12 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm, /* pre-create the image file */ if (!reuse) { - int fd =3D qemuOpenFile(driver, vm, mirror->path, - O_WRONLY | O_TRUNC | O_CREAT, - &need_unlink, NULL); - if (fd < 0) + if (virStorageFileCreate(mirror) < 0) { + virReportSystemError(errno, "%s", _("failed to create copy tar= get")); goto endjob; - VIR_FORCE_CLOSE(fd); + } + + need_unlink =3D true; } if (mirror->format > 0) @@ -16870,6 +16874,7 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm, /* Update vm in place to match changes. */ need_unlink =3D false; + virStorageFileDeinit(mirror); disk->mirror =3D mirror; mirror =3D NULL; disk->mirrorJob =3D VIR_DOMAIN_BLOCK_JOB_TYPE_COPY; @@ -16880,8 +16885,10 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm, vm->def->name); endjob: - if (need_unlink && unlink(mirror->path)) - VIR_WARN("unable to unlink just-created %s", mirror->path); + if (need_unlink && virStorageFileUnlink(mirror)) + VIR_WARN("%s", _("unable to remove just-created copy target")); + virStorageFileDeinit(mirror); + virStorageSourceFree(mirror); qemuDomainObjEndJob(driver, vm); if (monitor_error) { virSetError(monitor_error); --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 18:29:59 2024 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1499788022753610.8525453558785; Tue, 11 Jul 2017 08:47:02 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 47784C0587F2; Tue, 11 Jul 2017 15:46:59 +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 EF01F177DA; Tue, 11 Jul 2017 15:46:58 +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 84F633FADF; Tue, 11 Jul 2017 15:46:58 +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 v6BFkkhx026915 for ; Tue, 11 Jul 2017 11:46:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 53874177F2; Tue, 11 Jul 2017 15:46:46 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id A69C6177EF; Tue, 11 Jul 2017 15:46:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 47784C0587F2 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 47784C0587F2 From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 11 Jul 2017 17:46:41 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 4/5] qemu: blockcopy: Split out checking of the target image file 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: , MIME-Version: 1.0 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 11 Jul 2017 15:46:59 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Move the code into a separate function so that the flow of creating the copy is more obvious and split into logical pieces. Reviewed-by: John Ferlan --- src/qemu/qemu_driver.c | 79 +++++++++++++++++++++++++++++-----------------= ---- 1 file changed, 46 insertions(+), 33 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 48dc5e5cc..5beb14e64 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -16685,6 +16685,50 @@ qemuDomainBlockJobSetSpeed(virDomainPtr dom, } +static int +qemuDomainBlockCopyValidateMirror(virStorageSourcePtr mirror, + const char *dst, + bool *reuse) +{ + int desttype =3D virStorageSourceGetActualType(mirror); + struct stat st; + + if (stat(mirror->path, &st) < 0) { + if (errno !=3D ENOENT) { + virReportSystemError(errno, _("unable to stat for disk %s: %s"= ), + dst, mirror->path); + return -1; + } else if (*reuse || desttype =3D=3D VIR_STORAGE_TYPE_BLOCK) { + virReportSystemError(errno, + _("missing destination file for disk %s: = %s"), + dst, mirror->path); + return -1; + } + } else if (!S_ISBLK(st.st_mode)) { + if (st.st_size && !(*reuse)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("external destination file for disk %s alread= y " + "exists and is not a block device: %s"), + dst, mirror->path); + return -1; + } + if (desttype =3D=3D VIR_STORAGE_TYPE_BLOCK) { + virReportError(VIR_ERR_INVALID_ARG, + _("blockdev flag requested for disk %s, but fil= e " + "'%s' is not a block device"), + dst, mirror->path); + return -1; + } + } else { + /* if the target is a block device, assume that we are reusing it,= so + * there are no attempts to create it */ + *reuse =3D true; + } + + return 0; +} + + /* bandwidth in bytes/s. Caller must lock vm beforehand, and not * access mirror afterwards. */ static int @@ -16703,11 +16747,9 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm, char *device =3D NULL; virDomainDiskDefPtr disk =3D NULL; int ret =3D -1; - struct stat st; bool need_unlink =3D false; virQEMUDriverConfigPtr cfg =3D NULL; const char *format =3D NULL; - int desttype =3D virStorageSourceGetActualType(mirror); virErrorPtr monitor_error =3D NULL; bool reuse =3D !!(flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT); @@ -16790,37 +16832,8 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm, if (qemuDomainStorageFileInit(driver, vm, mirror) < 0) goto endjob; - if (stat(mirror->path, &st) < 0) { - if (errno !=3D ENOENT) { - virReportSystemError(errno, _("unable to stat for disk %s: %s"= ), - disk->dst, mirror->path); - goto endjob; - } else if (reuse || desttype =3D=3D VIR_STORAGE_TYPE_BLOCK) { - virReportSystemError(errno, - _("missing destination file for disk %s: = %s"), - disk->dst, mirror->path); - goto endjob; - } - } else if (!S_ISBLK(st.st_mode)) { - if (st.st_size && !reuse) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("external destination file for disk %s alread= y " - "exists and is not a block device: %s"), - disk->dst, mirror->path); - goto endjob; - } - if (desttype =3D=3D VIR_STORAGE_TYPE_BLOCK) { - virReportError(VIR_ERR_INVALID_ARG, - _("blockdev flag requested for disk %s, but fil= e " - "'%s' is not a block device"), - disk->dst, mirror->path); - goto endjob; - } - } else { - /* if the target is a block device, assume that we are reusing it,= so - * there are no attempts to create it */ - reuse =3D true; - } + if (qemuDomainBlockCopyValidateMirror(mirror, disk->dst, &reuse) < 0) + goto endjob; if (!mirror->format) { if (!reuse) { --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 18:29:59 2024 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1499788024369199.14554535443528; Tue, 11 Jul 2017 08:47:04 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 291977484E; Tue, 11 Jul 2017 15:47:02 +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 BF5AD18395; Tue, 11 Jul 2017 15:47:01 +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 BB48B3FAE2; Tue, 11 Jul 2017 15:47:00 +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 v6BFkltI026947 for ; Tue, 11 Jul 2017 11:46:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id E46C9177DA; Tue, 11 Jul 2017 15:46:47 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.201]) by smtp.corp.redhat.com (Postfix) with ESMTP id 44683177F2; Tue, 11 Jul 2017 15:46:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 291977484E Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 291977484E From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 11 Jul 2017 17:46:42 +0200 Message-Id: <6fd3a70047ef4e8113ed8c1a5807c5b908f15a6f.1499787961.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 5/5] qemu: blockcopy: Refactor logic checking the target storage file 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: , MIME-Version: 1.0 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 11 Jul 2017 15:47:03 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Use virStorageSource accessors to check the file and call virStorageFileAccess before even attempting to stat the target. This will be helpful once we try to add network destinations for block copy, since there will be no need to stat them. Reviewed-by: John Ferlan --- src/qemu/qemu_driver.c | 53 +++++++++++++++++++++++++++++++---------------= ---- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 5beb14e64..f93c5cb21 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -16693,36 +16693,49 @@ qemuDomainBlockCopyValidateMirror(virStorageSourc= ePtr mirror, int desttype =3D virStorageSourceGetActualType(mirror); struct stat st; - if (stat(mirror->path, &st) < 0) { + if (virStorageFileAccess(mirror, F_OK) < 0) { if (errno !=3D ENOENT) { - virReportSystemError(errno, _("unable to stat for disk %s: %s"= ), - dst, mirror->path); + virReportSystemError(errno, "%s", + _("unable to verify existance of " + "block copy target")); return -1; - } else if (*reuse || desttype =3D=3D VIR_STORAGE_TYPE_BLOCK) { + } + + if (*reuse || desttype =3D=3D VIR_STORAGE_TYPE_BLOCK) { virReportSystemError(errno, _("missing destination file for disk %s: = %s"), dst, mirror->path); return -1; } - } else if (!S_ISBLK(st.st_mode)) { - if (st.st_size && !(*reuse)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("external destination file for disk %s alread= y " - "exists and is not a block device: %s"), - dst, mirror->path); + } else { + if (virStorageFileStat(mirror, &st) < 0) { + virReportSystemError(errno, + _("unable to stat block copy target '%s'"= ), + mirror->path); return -1; } - if (desttype =3D=3D VIR_STORAGE_TYPE_BLOCK) { - virReportError(VIR_ERR_INVALID_ARG, - _("blockdev flag requested for disk %s, but fil= e " - "'%s' is not a block device"), - dst, mirror->path); - return -1; + + if (S_ISBLK(st.st_mode)) { + /* if the target is a block device, assume that we are reusing= it, + * so there are no attempts to create it */ + *reuse =3D true; + } else { + if (st.st_size && !(*reuse)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("external destination file for disk %s al= ready " + "exists and is not a block device: %s"), + dst, mirror->path); + return -1; + } + + if (desttype =3D=3D VIR_STORAGE_TYPE_BLOCK) { + virReportError(VIR_ERR_INVALID_ARG, + _("blockdev flag requested for disk %s, but= file " + "'%s' is not a block device"), + dst, mirror->path); + return -1; + } } - } else { - /* if the target is a block device, assume that we are reusing it,= so - * there are no attempts to create it */ - *reuse =3D true; } return 0; --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list