From nobody Sun Oct 5 17:36:28 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=1603478998; cv=none; d=zohomail.com; s=zohoarc; b=LvcnXB0KwMqWcT3VIXjGcTZy31sZVAizeEcYlsYA8Bo2zaA8sz5+P4uzUNOWfyVRKOs1SS7kag3utR+/d0lxXywI9q8YdKvIu2Uis74W+7QZoU9c8+K4l6aGxOc/rnB3UsS0Lv3fGHjS8iqcrGvfXNo4yENdRTcpt2OJRxVqaME= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603478998; 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=hjlyrNJBhtJZwARkJVhxkHL8wl5BqWygFehP0x3+fuk=; b=WmD9gRZNj6iJMmYm3DVE+yB66KwXrCELodaOSyrWleaptFasdk50yPLn3iAeTunx3SaXIdU6pqV0ZWj3KgnRrLNpch5OXakbopJdfWm3aig1PdAMuxrmwgKmhZWxk+TanbBRypUEz2KCpnW3/6QM+eZifLA4PygCZC+5rrexI7I= 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 160347899815573.47494317465157; Fri, 23 Oct 2020 11:49:58 -0700 (PDT) Received: from localhost ([::1]:54344 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kW28T-0007Ke-1p for importer@patchew.org; Fri, 23 Oct 2020 14:49:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50654) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kW1wV-0001Se-Ia for qemu-devel@nongnu.org; Fri, 23 Oct 2020 14:37:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:35920) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kW1wS-0001aE-RN for qemu-devel@nongnu.org; Fri, 23 Oct 2020 14:37:35 -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-577-7Bvj0BmgNUSdb_ZPRx-m2g-1; Fri, 23 Oct 2020 14:37:29 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AB37A10866B3; Fri, 23 Oct 2020 18:37:28 +0000 (UTC) Received: from blue.redhat.com (ovpn-113-7.phx2.redhat.com [10.3.113.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1C13A60BFA; Fri, 23 Oct 2020 18:37:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603478252; 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=hjlyrNJBhtJZwARkJVhxkHL8wl5BqWygFehP0x3+fuk=; b=eVC1P22ELNVCGMa/5WTW/6kGq/n3eGTqGG7RtuYZ77vmPCYYTLv6TzB/NpatMEreOMRdw6 vDmfZifzuKAtPOs+h1+9VLKcOEt7VdWV/Vb03lN0/1+DxkzBoq/M9mCikaRu8mHIbgLZzm QQutz+c+j+K62RW0xKeaERkENYU0z8I= X-MC-Unique: 7Bvj0BmgNUSdb_ZPRx-m2g-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH v5 11/12] nbd: Expose actual depth in qemu:allocation-depth Date: Fri, 23 Oct 2020 13:36:51 -0500 Message-Id: <20201023183652.478921-12-eblake@redhat.com> In-Reply-To: <20201023183652.478921-1-eblake@redhat.com> References: <20201023183652.478921-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eblake@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=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/23 01:44:00 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: , Cc: kwolf@redhat.com, vsementsov@virtuozzo.com, qemu-block@nongnu.org, rjones@redhat.com, Max Reitz , stefanha@redhat.com 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" Preserve the tri-state encoding in the low bits, as that still remains a valuable way to utilize qemu-img map with x-dirty-bitmap for accessing quick information without needing a third-party NBD client. But now that the block layer gives us an actual depth, we can easily expose it in the remaining bits of our metadata context (leaving two bits reserved, to make it easier to read depth out of a raw hex number). This assumes no one runs a backing chain larger than 256M elements. iotest 309 remains unchanged (an example of the above-mentioned x-dirty-bitmap hack); actually testing the new bits requires libnbd or a similar client, and I didn't want to make iotests depend on libnbd at this point in time; rather, see the libnbd project for interop tests that exercise this new feature. Signed-off-by: Eric Blake --- docs/interop/nbd.txt | 6 +++++- include/block/nbd.h | 2 ++ nbd/server.c | 27 +++++++++++++++------------ 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/docs/interop/nbd.txt b/docs/interop/nbd.txt index 7e948bd42218..d90723ffe991 100644 --- a/docs/interop/nbd.txt +++ b/docs/interop/nbd.txt @@ -34,7 +34,8 @@ the image, with a single metadata context named: qemu:allocation-depth -In the allocation depth context, bits 0 and 1 form a tri-state value: +In the allocation depth context, bits 0 and 1 form a tri-state value, +along with 28 bits giving an actual depth: bits 0-1: 00: NBD_STATE_DEPTH_UNALLOC, the extent is unallocated 01: NBD_STATE_DEPTH_LOCAL, the extent is allocated in the @@ -42,6 +43,9 @@ In the allocation depth context, bits 0 and 1 form a tri-= state value: 10: NBD_STATE_DEPTH_BACKING, the extent is inherited from a backing layer 11: invalid, never returned + bits 2-3: reserved, always 0 + bits 4-31: NBD_STATE_DEPTH_RAW, the backing layer depth (0 if + UNALLOC, 1 for LOCAL, 2 or more for BACKING) For NBD_OPT_LIST_META_CONTEXT the following queries are supported in addition to the specific "qemu:allocation-depth" and diff --git a/include/block/nbd.h b/include/block/nbd.h index 956687f5c368..3c0692aec642 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -264,6 +264,8 @@ enum { #define NBD_STATE_DEPTH_UNALLOC 0x0 #define NBD_STATE_DEPTH_LOCAL 0x1 #define NBD_STATE_DEPTH_BACKING 0x2 +#define NBD_STATE_DEPTH_RAW_MASK 0xfffffff0 +#define NBD_STATE_DEPTH_RAW_SHIFT 4 static inline bool nbd_reply_type_is_error(int type) { diff --git a/nbd/server.c b/nbd/server.c index 53526090b0a2..afa79e63a7a6 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -2037,22 +2037,25 @@ static int blockalloc_to_extents(BlockDriverState *= bs, uint64_t offset, while (bytes) { uint32_t flags; int64_t num; - int ret =3D bdrv_is_allocated(bs, offset, bytes, &num); + int depth =3D bdrv_is_allocated_above(bs, NULL, false, offset, byt= es, + &num); - if (ret < 0) { - return ret; - } - - if (ret =3D=3D 1) { + switch (depth) { + case 0: + flags =3D NBD_STATE_DEPTH_UNALLOC; + break; + case 1: flags =3D NBD_STATE_DEPTH_LOCAL; - } else { - ret =3D bdrv_is_allocated_above(bs, NULL, false, offset, num, - &num); - if (ret < 0) { - return ret; + break; + default: + if (depth < 0) { + return depth; } - flags =3D ret ? NBD_STATE_DEPTH_BACKING : NBD_STATE_DEPTH_UNAL= LOC; + flags =3D NBD_STATE_DEPTH_BACKING; + break; } + assert(depth <=3D UINT32_MAX >> NBD_STATE_DEPTH_RAW_SHIFT); + flags |=3D depth << NBD_STATE_DEPTH_RAW_SHIFT; if (nbd_extent_array_add(ea, num, flags) < 0) { return 0; --=20 2.29.0