From nobody Thu Dec 18 17:59:29 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1594030736; cv=none; d=zohomail.com; s=zohoarc; b=BPsGNq1avuVBudzCBGvcuVd9Uib8BVUSlPd4Tcxl3bzoapBLP5YOZYg182qRv8B/68oRt8mcET2iRjVe66HH42y5Rl3pUFXz5vTyIpTYc0d2Td2PJ8bkZSoKqRbBEYbM2tOZgLyvjC0f9HJK8u3PvE1pCenwnZQpmamBGAXOf1Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594030736; h=Content-Type:Content-Transfer-Encoding:Cc: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; bh=u004E6Ep2Z81gMtCqTLi6rp1iyBNdEC4/fTCVYChyRI=; b=nTsMMnLQI4VcRVwK8uEyGQeAAhpsmCH902qtUWb1PAc+uh9DWlUmqwDtiGmyDz/VAfzYrAeNfVqDpmAYWKaFsfVwXOI5cPS6t6GAcFTl3o+MOYk55KoQcgnzHw3zoNTgri6UWbxHLHKWs4mCDY5714FAyxpmUe+Eke0Kl3pCqSY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1594030736654365.2990258659411; Mon, 6 Jul 2020 03:18:56 -0700 (PDT) Received: from localhost ([::1]:45066 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jsOD9-0004BG-AL for importer@patchew.org; Mon, 06 Jul 2020 06:18:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54124) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jsO0Y-0004vy-5Q for qemu-devel@nongnu.org; Mon, 06 Jul 2020 06:05:54 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:24451 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jsO0W-0004ND-7N for qemu-devel@nongnu.org; Mon, 06 Jul 2020 06:05:53 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-407-W4Uz5gDRMlCgZ60pO16yyQ-1; Mon, 06 Jul 2020 06:05:49 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4778A800D5C; Mon, 6 Jul 2020 10:05:48 +0000 (UTC) Received: from localhost (ovpn-112-176.ams2.redhat.com [10.36.112.176]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BAB6810013D9; Mon, 6 Jul 2020 10:05:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594029951; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=u004E6Ep2Z81gMtCqTLi6rp1iyBNdEC4/fTCVYChyRI=; b=FLNE9Jo9QquuZiVa5ODNtbu8J8tB16jG6fjP1zMAvRvsacHdrOzGO+kFglCtZ/qapjvc1B O2MX13ou6s1FU9910Om0h8uVX5A0dyp+fIjqefb89a6j9sjOo5kgzG9xkXxlSsmRqDcqiS C1cLktVA0z6VhwFxTx15np7Mj3tcsf0= X-MC-Unique: W4Uz5gDRMlCgZ60pO16yyQ-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PULL 31/31] qed: Simplify backing reads Date: Mon, 6 Jul 2020 12:04:32 +0200 Message-Id: <20200706100432.2301919-32-mreitz@redhat.com> In-Reply-To: <20200706100432.2301919-1-mreitz@redhat.com> References: <20200706100432.2301919-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mreitz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=207.211.31.81; envelope-from=mreitz@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/06 01:39:15 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Eric Blake The other four drivers that support backing files (qcow, qcow2, parallels, vmdk) all rely on the block layer to populate zeroes when reading beyond EOF of a short backing file. We can simplify the qed code by doing likewise. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy Message-Id: <20200528094405.145708-11-vsementsov@virtuozzo.com> Signed-off-by: Max Reitz --- block/qed.h | 1 - block/qed.c | 64 +++++------------------------------------------------ 2 files changed, 6 insertions(+), 59 deletions(-) diff --git a/block/qed.h b/block/qed.h index 42c115d822..3d12bf78d4 100644 --- a/block/qed.h +++ b/block/qed.h @@ -140,7 +140,6 @@ typedef struct QEDAIOCB { =20 /* Current cluster scatter-gather list */ QEMUIOVector cur_qiov; - QEMUIOVector *backing_qiov; uint64_t cur_pos; /* position on block device, in bytes = */ uint64_t cur_cluster; /* cluster offset in image file */ unsigned int cur_nclusters; /* number of clusters being accessed */ diff --git a/block/qed.c b/block/qed.c index a2dd952699..ece8b9bb60 100644 --- a/block/qed.c +++ b/block/qed.c @@ -849,56 +849,18 @@ static BDRVQEDState *acb_to_s(QEDAIOCB *acb) * @s: QED state * @pos: Byte position in device * @qiov: Destination I/O vector - * @backing_qiov: Possibly shortened copy of qiov, to be allocated here - * @cb: Completion function - * @opaque: User data for completion function * * This function reads qiov->size bytes starting at pos from the backing f= ile. * If there is no backing file then zeroes are read. */ static int coroutine_fn qed_read_backing_file(BDRVQEDState *s, uint64_t po= s, - QEMUIOVector *qiov, - QEMUIOVector **backing_qiov) + QEMUIOVector *qiov) { - uint64_t backing_length =3D 0; - size_t size; - int ret; - - /* If there is a backing file, get its length. Treat the absence of a - * backing file like a zero length backing file. - */ if (s->bs->backing) { - int64_t l =3D bdrv_getlength(s->bs->backing->bs); - if (l < 0) { - return l; - } - backing_length =3D l; - } - - /* Zero all sectors if reading beyond the end of the backing file */ - if (pos >=3D backing_length || - pos + qiov->size > backing_length) { - qemu_iovec_memset(qiov, 0, 0, qiov->size); - } - - /* Complete now if there are no backing file sectors to read */ - if (pos >=3D backing_length) { - return 0; - } - - /* If the read straddles the end of the backing file, shorten it */ - size =3D MIN((uint64_t)backing_length - pos, qiov->size); - - assert(*backing_qiov =3D=3D NULL); - *backing_qiov =3D g_new(QEMUIOVector, 1); - qemu_iovec_init(*backing_qiov, qiov->niov); - qemu_iovec_concat(*backing_qiov, qiov, 0, size); - - BLKDBG_EVENT(s->bs->file, BLKDBG_READ_BACKING_AIO); - ret =3D bdrv_co_preadv(s->bs->backing, pos, size, *backing_qiov, 0); - if (ret < 0) { - return ret; + BLKDBG_EVENT(s->bs->file, BLKDBG_READ_BACKING_AIO); + return bdrv_co_preadv(s->bs->backing, pos, qiov->size, qiov, 0); } + qemu_iovec_memset(qiov, 0, 0, qiov->size); return 0; } =20 @@ -915,7 +877,6 @@ static int coroutine_fn qed_copy_from_backing_file(BDRV= QEDState *s, uint64_t offset) { QEMUIOVector qiov; - QEMUIOVector *backing_qiov =3D NULL; int ret; =20 /* Skip copy entirely if there is no work to do */ @@ -925,13 +886,7 @@ static int coroutine_fn qed_copy_from_backing_file(BDR= VQEDState *s, =20 qemu_iovec_init_buf(&qiov, qemu_blockalign(s->bs, len), len); =20 - ret =3D qed_read_backing_file(s, pos, &qiov, &backing_qiov); - - if (backing_qiov) { - qemu_iovec_destroy(backing_qiov); - g_free(backing_qiov); - backing_qiov =3D NULL; - } + ret =3D qed_read_backing_file(s, pos, &qiov); =20 if (ret) { goto out; @@ -1339,8 +1294,7 @@ static int coroutine_fn qed_aio_read_data(void *opaqu= e, int ret, qemu_iovec_memset(&acb->cur_qiov, 0, 0, acb->cur_qiov.size); r =3D 0; } else if (ret !=3D QED_CLUSTER_FOUND) { - r =3D qed_read_backing_file(s, acb->cur_pos, &acb->cur_qiov, - &acb->backing_qiov); + r =3D qed_read_backing_file(s, acb->cur_pos, &acb->cur_qiov); } else { BLKDBG_EVENT(bs->file, BLKDBG_READ_AIO); r =3D bdrv_co_preadv(bs->file, offset, acb->cur_qiov.size, @@ -1365,12 +1319,6 @@ static int coroutine_fn qed_aio_next_io(QEDAIOCB *ac= b) while (1) { trace_qed_aio_next_io(s, acb, 0, acb->cur_pos + acb->cur_qiov.size= ); =20 - if (acb->backing_qiov) { - qemu_iovec_destroy(acb->backing_qiov); - g_free(acb->backing_qiov); - acb->backing_qiov =3D NULL; - } - acb->qiov_offset +=3D acb->cur_qiov.size; acb->cur_pos +=3D acb->cur_qiov.size; qemu_iovec_reset(&acb->cur_qiov); --=20 2.26.2