From nobody Wed Dec 17 05:38:50 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1635869335; cv=none; d=zohomail.com; s=zohoarc; b=VhlixzEpnidcqifXcOwuEcz6LUXRTW1+/GYUme/+pjjlUJfRxlrHa1FqqLDHYzWVLVrQs29QPPEIo8fyyVEo/L+m/jRRtBjcwbKzD3VHouQrAOpmVZWkDahAa6yr2PHd9afiWokPs0a3JGcre/zibajFwe0Qp1nN6jcSmwq4h5I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635869335; 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=yfwzWg6ueDWabhvksK185iH6eoYrszv774E3cumhje0=; b=IkYK+/qra+1aZzgvMKQXqO7z3yancGCdKt5foGUjEzUW3H3LGMx9r/dS//2Am5Wbbt0ejultdJZn3+6suA9ATpv+DBmu9UVXGXKrVvThcezpWJlqT1P6zBxRx3ozvb7oWaYqVzrz0U4ksep2hXaLvd3OEA/llR0S/TUsBVvLDFI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1635869335322198.29241010908413; Tue, 2 Nov 2021 09:08:55 -0700 (PDT) Received: from localhost ([::1]:59342 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mhwLG-00038E-3v for importer@patchew.org; Tue, 02 Nov 2021 12:08:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53322) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mhwIY-0007eV-5f for qemu-devel@nongnu.org; Tue, 02 Nov 2021 12:06:06 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:47796) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mhwIN-0004Gd-U0 for qemu-devel@nongnu.org; Tue, 02 Nov 2021 12:06:05 -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-267-XRQxnHNZODC0UTXo251Aag-1; Tue, 02 Nov 2021 12:05:50 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1CB7E802B61; Tue, 2 Nov 2021 16:05:49 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.81]) by smtp.corp.redhat.com (Postfix) with ESMTP id 273BD5D9D5; Tue, 2 Nov 2021 16:05:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635869155; 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=yfwzWg6ueDWabhvksK185iH6eoYrszv774E3cumhje0=; b=Wu2S0v4m7uvndRxmbYSQ75y7RsEHhlyjHMTTEtHdGDvK9O3bD1nY7tXMtFhRfrGMqcSVVv JT/h37rBBGs8cIfQ4z3+i+LBHMNmQy+ZB/zKUCyiBGwNkBKic1ifuf3rBQ/OPX0sVKZ1MN K+61nEpewGU2yl1JddpZ3FIq4i35Y9I= X-MC-Unique: XRQxnHNZODC0UTXo251Aag-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 03/12] block/rbd: implement bdrv_co_block_status Date: Tue, 2 Nov 2021 17:05:19 +0100 Message-Id: <20211102160528.206766-4-kwolf@redhat.com> In-Reply-To: <20211102160528.206766-1-kwolf@redhat.com> References: <20211102160528.206766-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@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=216.205.24.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.702, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1635869337019100001 Content-Type: text/plain; charset="utf-8" From: Peter Lieven the qemu rbd driver currently lacks support for bdrv_co_block_status. This results mainly in incorrect progress during block operations (e.g. qemu-img convert with an rbd image as source). This patch utilizes the rbd_diff_iterate2 call from librbd to detect allocated and unallocated (all zero areas). To avoid querying the ceph OSDs for the answer this is only done if the image has the fast-diff feature which depends on the object-map and exclusive-lock features. In this case it is guaranteed that the information is present in memory in the librbd client and thus very fast. If fast-diff is not available all areas are reported to be allocated which is the current behaviour if bdrv_co_block_status is not implemented. Signed-off-by: Peter Lieven Message-Id: <20211012152231.24868-1-pl@kamp.de> Reviewed-by: Ilya Dryomov Signed-off-by: Kevin Wolf --- block/rbd.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/block/rbd.c b/block/rbd.c index 701fbf2b0c..def96292e0 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -97,6 +97,12 @@ typedef struct RBDTask { int64_t ret; } RBDTask; =20 +typedef struct RBDDiffIterateReq { + uint64_t offs; + uint64_t bytes; + bool exists; +} RBDDiffIterateReq; + static int qemu_rbd_connect(rados_t *cluster, rados_ioctx_t *io_ctx, BlockdevOptionsRbd *opts, bool cache, const char *keypairs, const char *secretid, @@ -1259,6 +1265,111 @@ static ImageInfoSpecific *qemu_rbd_get_specific_inf= o(BlockDriverState *bs, return spec_info; } =20 +/* + * rbd_diff_iterate2 allows to interrupt the exection by returning a negat= ive + * value in the callback routine. Choose a value that does not conflict wi= th + * an existing exitcode and return it if we want to prematurely stop the + * execution because we detected a change in the allocation status. + */ +#define QEMU_RBD_EXIT_DIFF_ITERATE2 -9000 + +static int qemu_rbd_diff_iterate_cb(uint64_t offs, size_t len, + int exists, void *opaque) +{ + RBDDiffIterateReq *req =3D opaque; + + assert(req->offs + req->bytes <=3D offs); + /* + * we do not diff against a snapshot so we should never receive a call= back + * for a hole. + */ + assert(exists); + + if (!req->exists && offs > req->offs) { + /* + * we started in an unallocated area and hit the first allocated + * block. req->bytes must be set to the length of the unallocated = area + * before the allocated area. stop further processing. + */ + req->bytes =3D offs - req->offs; + return QEMU_RBD_EXIT_DIFF_ITERATE2; + } + + if (req->exists && offs > req->offs + req->bytes) { + /* + * we started in an allocated area and jumped over an unallocated = area, + * req->bytes contains the length of the allocated area before the + * unallocated area. stop further processing. + */ + return QEMU_RBD_EXIT_DIFF_ITERATE2; + } + + req->bytes +=3D len; + req->exists =3D true; + + return 0; +} + +static int coroutine_fn qemu_rbd_co_block_status(BlockDriverState *bs, + bool want_zero, int64_t o= ffset, + int64_t bytes, int64_t *p= num, + int64_t *map, + BlockDriverState **file) +{ + BDRVRBDState *s =3D bs->opaque; + int status, r; + RBDDiffIterateReq req =3D { .offs =3D offset }; + uint64_t features, flags; + + assert(offset + bytes <=3D s->image_size); + + /* default to all sectors allocated */ + status =3D BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID; + *map =3D offset; + *file =3D bs; + *pnum =3D bytes; + + /* check if RBD image supports fast-diff */ + r =3D rbd_get_features(s->image, &features); + if (r < 0) { + return status; + } + if (!(features & RBD_FEATURE_FAST_DIFF)) { + return status; + } + + /* check if RBD fast-diff result is valid */ + r =3D rbd_get_flags(s->image, &flags); + if (r < 0) { + return status; + } + if (flags & RBD_FLAG_FAST_DIFF_INVALID) { + return status; + } + + r =3D rbd_diff_iterate2(s->image, NULL, offset, bytes, true, true, + qemu_rbd_diff_iterate_cb, &req); + if (r < 0 && r !=3D QEMU_RBD_EXIT_DIFF_ITERATE2) { + return status; + } + assert(req.bytes <=3D bytes); + if (!req.exists) { + if (r =3D=3D 0) { + /* + * rbd_diff_iterate2 does not invoke callbacks for unallocated + * areas. This here catches the case where no callback was + * invoked at all (req.bytes =3D=3D 0). + */ + assert(req.bytes =3D=3D 0); + req.bytes =3D bytes; + } + status =3D BDRV_BLOCK_ZERO | BDRV_BLOCK_OFFSET_VALID; + } + + *pnum =3D req.bytes; + return status; +} + static int64_t qemu_rbd_getlength(BlockDriverState *bs) { BDRVRBDState *s =3D bs->opaque; @@ -1494,6 +1605,7 @@ static BlockDriver bdrv_rbd =3D { #ifdef LIBRBD_SUPPORTS_WRITE_ZEROES .bdrv_co_pwrite_zeroes =3D qemu_rbd_co_pwrite_zeroes, #endif + .bdrv_co_block_status =3D qemu_rbd_co_block_status, =20 .bdrv_snapshot_create =3D qemu_rbd_snap_create, .bdrv_snapshot_delete =3D qemu_rbd_snap_remove, --=20 2.31.1