From nobody Mon Feb 9 22:54:48 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 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