From nobody Fri May 16 05:17:14 2025 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