From nobody Tue Nov 18 02:54:15 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=1606934113; cv=none; d=zohomail.com; s=zohoarc; b=Bxhu79PEWCvlXUgdKceg4pJBWbH5LC0Y6cacqZ5IW+3o4gTG7Bz0HGS7AclDhynn/GdyIHI6z4R3AIuctkMvCA3kS6CkgwsM74t+iwboaGI4Hg5ZNvAF3cCwJvCQxoiz/7jO+xoO6oo26TIrF37oVTsefM5Azg66Zu0IeCnR5SM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606934113; 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=f3aoHB95IMympiIKrPvuWkmGui0rI4fAD4Z4HFwnVPA=; b=N9/cCTNWSOoSOJxC8IP7uUBoTwIspKurN7x83SufWzW/MWUqONWFHvRrSK4+tOdeAFcxdjSpO9TJbNj4m/NuRAA5rniFtMTDco/SFUvbfwcAa8JfWi1e6uJGc9aLFYMHO1kFBmyGCzjVUNa9/FBUfQ8P3RygIWTDjU8yJ4ZTC9o= 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 1606934113830255.76536444319015; Wed, 2 Dec 2020 10:35:13 -0800 (PST) Received: from localhost ([::1]:51854 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kkWy8-0006oA-Mb for importer@patchew.org; Wed, 02 Dec 2020 13:35:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50248) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kkWuH-0001cs-Mu; Wed, 02 Dec 2020 13:31:13 -0500 Received: from relay.sw.ru ([185.231.240.75]:49918 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 1kkWuB-0000zz-52; Wed, 02 Dec 2020 13:31:13 -0500 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.94) (envelope-from ) id 1kkWtu-00BTPZ-Ct; Wed, 02 Dec 2020 21:30:50 +0300 To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, mreitz@redhat.com, stefanha@redhat.com, fam@euphon.net, armbru@redhat.com, jsnow@redhat.com, eblake@redhat.com, den@openvz.org, vsementsov@virtuozzo.com, andrey.shinkevich@virtuozzo.com Subject: [PATCH v13 05/10] qapi: create BlockdevOptionsCor structure for COR driver Date: Wed, 2 Dec 2020 21:30:56 +0300 Message-Id: <1606933861-297777-6-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1606933861-297777-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1606933861-297777-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-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" Create the BlockdevOptionsCor structure for COR driver specific options splitting it off form the BlockdevOptionsGenericFormat. The only option 'bottom' node in the structure denotes an image file that limits the COR operations in the backing chain. We are going to use the COR-filter for a block-stream job and will pass a bottom node name to the COR driver. The bottom node is the first non-filter overlay of the base. It was introduced because the base node itself may change due to possible concurrent jobs. Suggested-by: Max Reitz Suggested-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Andrey Shinkevich Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/copy-on-read.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++= ++-- qapi/block-core.json | 21 ++++++++++++++++++- 2 files changed, 75 insertions(+), 3 deletions(-) diff --git a/block/copy-on-read.c b/block/copy-on-read.c index 618c4c4..2cddc96 100644 --- a/block/copy-on-read.c +++ b/block/copy-on-read.c @@ -24,18 +24,23 @@ #include "block/block_int.h" #include "qemu/module.h" #include "qapi/error.h" +#include "qapi/qmp/qdict.h" #include "block/copy-on-read.h" =20 =20 typedef struct BDRVStateCOR { bool active; + BlockDriverState *bottom_bs; } BDRVStateCOR; =20 =20 static int cor_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { + BlockDriverState *bottom_bs =3D NULL; BDRVStateCOR *state =3D bs->opaque; + /* Find a bottom node name, if any */ + const char *bottom_node =3D qdict_get_try_str(options, "bottom"); =20 bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_of_bds, BDRV_CHILD_FILTERED | BDRV_CHILD_PRIMARY, @@ -51,7 +56,17 @@ static int cor_open(BlockDriverState *bs, QDict *options= , int flags, ((BDRV_REQ_FUA | BDRV_REQ_MAY_UNMAP | BDRV_REQ_NO_FALLBACK) & bs->file->bs->supported_zero_flags); =20 + if (bottom_node) { + bottom_bs =3D bdrv_lookup_bs(NULL, bottom_node, errp); + if (!bottom_bs) { + error_setg(errp, "Bottom node '%s' not found", bottom_node); + qdict_del(options, "bottom"); + return -EINVAL; + } + qdict_del(options, "bottom"); + } state->active =3D true; + state->bottom_bs =3D bottom_bs; =20 /* * We don't need to call bdrv_child_refresh_perms() now as the permiss= ions @@ -107,8 +122,46 @@ 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; + int local_flags; + int ret; + BDRVStateCOR *state =3D bs->opaque; + + if (!state->bottom_bs) { + return bdrv_co_preadv_part(bs->file, offset, bytes, qiov, qiov_off= set, + flags | BDRV_REQ_COPY_ON_READ); + } + + while (bytes) { + 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 <=3D 0) { + ret =3D bdrv_is_allocated_above(bdrv_backing_chain_next(bs->fi= le->bs), + state->bottom_bs, true, offset, + n, &n); + if (ret =3D=3D 1 || ret < 0) { + local_flags |=3D BDRV_REQ_COPY_ON_READ; + } + /* Finish earlier if the end of a backing file has been reache= d */ + if (n =3D=3D 0) { + break; + } + } + + 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 diff --git a/qapi/block-core.json b/qapi/block-core.json index 8ef3df6..04055ef 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -3942,6 +3942,25 @@ 'data': { 'throttle-group': 'str', 'file' : 'BlockdevRef' } } + +## +# @BlockdevOptionsCor: +# +# Driver specific block device options for the copy-on-read driver. +# +# @bottom: the name of a non-filter node (allocation-bearing layer) that l= imits +# the COR operations in the backing chain (inclusive). +# For the block-stream job, it will be the first non-filter overl= ay of +# the base node. We do not involve the base node into the COR +# operations because the base may change due to a concurrent +# block-commit job on the same backing chain. +# +# Since: 5.2 +## +{ 'struct': 'BlockdevOptionsCor', + 'base': 'BlockdevOptionsGenericFormat', + 'data': { '*bottom': 'str' } } + ## # @BlockdevOptions: # @@ -3994,7 +4013,7 @@ 'bochs': 'BlockdevOptionsGenericFormat', 'cloop': 'BlockdevOptionsGenericFormat', 'compress': 'BlockdevOptionsGenericFormat', - 'copy-on-read':'BlockdevOptionsGenericFormat', + 'copy-on-read':'BlockdevOptionsCor', 'dmg': 'BlockdevOptionsGenericFormat', 'file': 'BlockdevOptionsFile', 'ftp': 'BlockdevOptionsCurlFtp', --=20 1.8.3.1