From nobody Tue Feb 10 04:56:01 2026 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 ARC-Seal: i=1; a=rsa-sha256; t=1598633785; cv=none; d=zohomail.com; s=zohoarc; b=BeJ+IXa+6BYC7Z0OSpgR2qkjv56BnR7ek8SKBeMVORHNyVrwbAFByfd1a8G8SozC/w8JX3aUim1xdyk4TNlLMVgBvpWCYwxJtsLHKxPGo41iuqSE/+PDd5p59fW/1cwd8ImSp1wt9ZN7vhWTU7tHTuevNGkcTAnzAr7Tbp5MDHM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598633785; 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=UFkahTJilEJ+6Bj+5rZwwjimCkJSv/iU+min1P94cew=; b=PsfYZYhFxZZeYa+pGUu87UYSPzClPZiV0O9ldSP09d6N3El5+hVH+fJGy0lJrXQpDp3q0MzplXBcX57cZDVDlanLFvxK0wFfVRErKTU0tvLYrWum6NHZTM25aXiwXksg2CCWAFsxuGq2YZgXYKHytdCCfdoSqre8toAkXG1gqzM= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1598633785919166.37652882101224; Fri, 28 Aug 2020 09:56:25 -0700 (PDT) Received: from localhost ([::1]:46364 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kBhft-0006fi-5i for importer@patchew.org; Fri, 28 Aug 2020 12:56:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33804) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kBhex-0004zQ-2v; Fri, 28 Aug 2020 12:55:27 -0400 Received: from relay.sw.ru ([185.231.240.75]:38086 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 1kBhev-0001TZ-GJ; Fri, 28 Aug 2020 12:55:26 -0400 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay3.sw.ru with esmtp (Exim 4.94) (envelope-from ) id 1kBheR-001XPR-6Z; Fri, 28 Aug 2020 19:54:55 +0300 To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, mreitz@redhat.com, armbru@redhat.com, jsnow@redhat.com, eblake@redhat.com, den@openvz.org, vsementsov@virtuozzo.com, andrey.shinkevich@virtuozzo.com Subject: [PATCH v8 5/7] copy-on-read: limit guest writes to base in COR driver Date: Fri, 28 Aug 2020 19:52:57 +0300 Message-Id: <1598633579-221780-6-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1598633579-221780-1-git-send-email-andrey.shinkevich@virtuozzo.com> References: <1598633579-221780-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/08/28 12:53:26 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 the guest's COR operations by the base node in the backing chain during a stream job. Signed-off-by: Andrey Shinkevich --- block/copy-on-read.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/block/copy-on-read.c b/block/copy-on-read.c index 1f858bb..ecbd1f8 100644 --- a/block/copy-on-read.c +++ b/block/copy-on-read.c @@ -57,6 +57,37 @@ static BlockDriverState *get_base_by_name(BlockDriverSta= te *bs, return base_bs; } =20 +/* + * Returns 1 if the block is allocated in a node between cor_filter_bs->fi= le->bs + * and the base_bs in the backing chain. Otherwise, returns 0. + * The COR operation is allowed if the base_bs is not specified - return 1. + * Returns negative errno on failure. + */ +static int node_above_base(BlockDriverState *cor_filter_bs, uint64_t offse= t, + uint64_t bytes) +{ + int ret; + int64_t dummy; + BlockDriverState *file =3D NULL; + BDRVStateCOR *state =3D cor_filter_bs->opaque; + + if (!state->base_bs) { + return 1; + } + + ret =3D bdrv_block_status_above(cor_filter_bs->file->bs, state->base_b= s, + offset, bytes, &dummy, NULL, &file); + if (ret < 0) { + return ret; + } + + if (file) { + return 1; + } + + return 0; +} + static int cor_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { @@ -153,6 +184,12 @@ static int coroutine_fn cor_co_pwritev_part(BlockDrive= rState *bs, QEMUIOVector *qiov, size_t qiov_offset, int flags) { + int ret =3D node_above_base(bs, offset, bytes); + + if (!ret || ret < 0) { + return ret; + } + return bdrv_co_pwritev_part(bs->file, offset, bytes, qiov, qiov_offset, flags); } @@ -162,6 +199,12 @@ static int coroutine_fn cor_co_pwrite_zeroes(BlockDriv= erState *bs, int64_t offset, int bytes, BdrvRequestFlags flags) { + int ret =3D node_above_base(bs, offset, bytes); + + if (!ret || ret < 0) { + return ret; + } + return bdrv_co_pwrite_zeroes(bs->file, offset, bytes, flags); } =20 @@ -178,6 +221,12 @@ static int coroutine_fn cor_co_pwritev_compressed(Bloc= kDriverState *bs, uint64_t bytes, QEMUIOVector *qiov) { + int ret =3D node_above_base(bs, offset, bytes); + + if (!ret || ret < 0) { + return ret; + } + return bdrv_co_pwritev(bs->file, offset, bytes, qiov, BDRV_REQ_WRITE_COMPRESSED); } --=20 1.8.3.1