From nobody Mon Nov 17 03:45:21 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1602525053; cv=none; d=zohomail.com; s=zohoarc; b=SeNjG/0F2GfX0axMlwMOKnSYxFURFUwYP+osf2hFF0FAL1iSEN7gm6o7mbzhaYsfluV4wxmcD0BTKRsJ9ua2eCBESulSDcw7r951vBwg4oe1uYu3kZeTCHFGTwRe1LLpU6WC58QY3QAUvhpUhpSe7pkRsv8/iwjMXFB1PV8Z974= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602525053; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=Cdc5xsgGNfFyVZ1YyreUxz1KqcTNTrTVaA6YY7yL2ss=; b=fPEbJpRHPU7AVRf/fdX1CPRQkPLONgKoBTjf7jM+47rvJJesdU1fzpegc3ckNF7f2+osyg685WvnaHmvKfF51ArJSJXGNoxCzrAC7RBDOWtWMvjpDzpeiO7579Xo+bgdnh0CSNM2JII7+yClkzGuEDIXzkae+fDrtU0Gn+sQf/E= ARC-Authentication-Results: i=1; mx.zohomail.com; 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=pass 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 160252505328449.893435695263975; Mon, 12 Oct 2020 10:50:53 -0700 (PDT) Received: from localhost ([::1]:39278 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kS1yG-0004e6-28 for importer@patchew.org; Mon, 12 Oct 2020 13:50:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59268) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kS1vm-0002fC-IF; Mon, 12 Oct 2020 13:48:18 -0400 Received: from relay.sw.ru ([185.231.240.75]:33448 helo=relay3.sw.ru) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kS1vk-0007go-Sz; Mon, 12 Oct 2020 13:48:18 -0400 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.94) (envelope-from ) id 1kS1un-0047iC-N9; Mon, 12 Oct 2020 20:47:17 +0300 To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, mreitz@redhat.com, fam@euphon.net, stefanha@redhat.com, armbru@redhat.com, jsnow@redhat.com, libvir-list@redhat.com, eblake@redhat.com, den@openvz.org, vsementsov@virtuozzo.com, andrey.shinkevich@virtuozzo.com Subject: [PATCH v11 05/13] copy-on-read: limit COR operations to base in COR driver Date: Mon, 12 Oct 2020 20:43:17 +0300 Message-Id: <1602524605-481160-6-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1602524605-481160-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1602524605-481160-1-git-send-email-andrey.shinkevich@virtuozzo.com> 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=185.231.240.75; envelope-from=andrey.shinkevich@virtuozzo.com; helo=relay3.sw.ru X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/12 13:44:17 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Reply-to: Andrey Shinkevich From: Andrey Shinkevich via Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Limit COR operations by the base node in the backing chain when the overlay base node name is given. It will be useful for a block stream job when the COR-filter is applied. The overlay base node is passed as the base itself may change due to concurrent commit jobs on the same backing chain. Signed-off-by: Andrey Shinkevich --- block/copy-on-read.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/block/copy-on-read.c b/block/copy-on-read.c index c578b1b..dfbd6ad 100644 --- a/block/copy-on-read.c +++ b/block/copy-on-read.c @@ -122,8 +122,43 @@ static int coroutine_fn cor_co_preadv_part(BlockDriver= State *bs, size_t qiov_offset, int flags) { - return bdrv_co_preadv_part(bs->file, offset, bytes, qiov, qiov_offset, - flags | BDRV_REQ_COPY_ON_READ); + int64_t n =3D 0; + int64_t size =3D offset + bytes; + int local_flags; + int ret; + BDRVStateCOR *state =3D bs->opaque; + + if (!state->base_overlay) { + return bdrv_co_preadv_part(bs->file, offset, bytes, qiov, qiov_off= set, + flags | BDRV_REQ_COPY_ON_READ); + } + + while (offset < size) { + local_flags =3D flags; + + /* In case of failure, try to copy-on-read anyway */ + ret =3D bdrv_is_allocated(bs->file->bs, offset, bytes, &n); + if (!ret) { + ret =3D bdrv_is_allocated_above(bdrv_cow_bs(bs->file->bs), + state->base_overlay, true, offse= t, + n, &n); + if (ret) { + local_flags |=3D BDRV_REQ_COPY_ON_READ; + } + } + + ret =3D bdrv_co_preadv_part(bs->file, offset, n, qiov, qiov_offset, + local_flags); + if (ret < 0) { + return ret; + } + + offset +=3D n; + qiov_offset +=3D n; + bytes -=3D n; + } + + return 0; } =20 =20 --=20 1.8.3.1