From nobody Mon Feb 9 12:26:21 2026 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=1600964378; cv=none; d=zohomail.com; s=zohoarc; b=lhbMhBRgvcbfFOlElQWXHGUqH3Zm1nMy+cHp3a/NhGfOSilb/GxkWjTX7rv/30sPov0AIY12m9IVhLGjRij5ZZU4lzcWFGzM7twxev/onFv1zDs5eqaElKsTlHjWKIhsn8KF1MFos/f5hlTpN1sKM+54cuzKyalyfHWKqaFL4zA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600964378; 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=a1TZ9dN2myeC8AcQFU8fybkeRvbP+s/Dsf6tiiuRN8E=; b=RPhMZwSQu/PZr04ZRgMIU8IUCfffaVmwWSKWUCZBhsgVv3pVaFviqoRKkgqLhVLqpzvFDlYEAxAmBXVZfNsGZ1YKXZaMTYh8o2aRuL7cDi16xXf1p3iG7ARJotPJqD7oky0qOg1NptnM8SWgSQHTHNRVWpN59oFarUpmr9AAz60= 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 1600964378468601.6187823266758; Thu, 24 Sep 2020 09:19:38 -0700 (PDT) Received: from localhost ([::1]:37908 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kLTy5-0005n1-NP for importer@patchew.org; Thu, 24 Sep 2020 12:19:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49274) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kLTAU-0001zO-8e for qemu-devel@nongnu.org; Thu, 24 Sep 2020 11:28:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:59548) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kLTAP-0005aY-68 for qemu-devel@nongnu.org; Thu, 24 Sep 2020 11:28:21 -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-407-jsBLOx0bPqer4uUzISSNFg-1; Thu, 24 Sep 2020 11:28:14 -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 620F9188C128; Thu, 24 Sep 2020 15:28:13 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-114-72.ams2.redhat.com [10.36.114.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id 222AC60C04; Thu, 24 Sep 2020 15:28:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600961296; 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=a1TZ9dN2myeC8AcQFU8fybkeRvbP+s/Dsf6tiiuRN8E=; b=bdjZIgVAbYpXA7JS8AA/kWEhbkOGbtHwRbxnhGCumDjCgRJtKHYRJRA8ZRyDHjlSrlyrTb cNSekw0NLtSp0vrywNqIsKvk0MWW/5JtQRAYpJWAv2mXh9G1wevO5yc505I6rWHgmL22QP T+gQnenkSU7MXmCQPQ4EneMZ9gSG4Fs= X-MC-Unique: jsBLOx0bPqer4uUzISSNFg-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH v2 25/31] block/export: Move writable to BlockExportOptions Date: Thu, 24 Sep 2020 17:27:11 +0200 Message-Id: <20200924152717.287415-26-kwolf@redhat.com> In-Reply-To: <20200924152717.287415-1-kwolf@redhat.com> References: <20200924152717.287415-1-kwolf@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=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-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 23:02:20 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -32 X-Spam_score: -3.3 X-Spam_bar: --- X-Spam_report: (-3.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.199, 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_H5=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, qemu-devel@nongnu.org, stefanha@redhat.com, mreitz@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" The 'writable' option is a basic option that will probably be applicable to most if not all export types that we will implement. Move it from NBD to the generic BlockExport layer. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- qapi/block-export.json | 15 ++++++++++----- block/export/export.c | 16 +++++++++++++++- blockdev-nbd.c | 18 +++++------------- nbd/server.c | 5 ----- qemu-nbd.c | 4 ++-- 5 files changed, 32 insertions(+), 26 deletions(-) diff --git a/qapi/block-export.json b/qapi/block-export.json index 28d4766215..ad01e9f8aa 100644 --- a/qapi/block-export.json +++ b/qapi/block-export.json @@ -74,9 +74,6 @@ # @description: Free-form description of the export, up to 4096 bytes. # (Since 5.0) # -# @writable: Whether clients should be able to write to the device via the -# NBD connection (default false). -# # @bitmap: Also export the dirty bitmap reachable from @device, so the # NBD client can use NBD_OPT_SET_META_CONTEXT with # "qemu:dirty-bitmap:NAME" to inspect the bitmap. (since 4.0) @@ -85,7 +82,7 @@ ## { 'struct': 'BlockExportOptionsNbd', 'data': { '*name': 'str', '*description': 'str', - '*writable': 'bool', '*bitmap': 'str' } } + '*bitmap': 'str' } } =20 ## # @NbdServerAddOptions: @@ -94,11 +91,15 @@ # # @device: The device name or node name of the node to be exported # +# @writable: Whether clients should be able to write to the device via the +# NBD connection (default false). +# # Since: 5.0 ## { 'struct': 'NbdServerAddOptions', 'base': 'BlockExportOptionsNbd', - 'data': { 'device': 'str' } } + 'data': { 'device': 'str', + '*writable': 'bool' } } =20 ## # @nbd-server-add: @@ -188,6 +189,9 @@ # # @node-name: The node name of the block node to be exported (since: 5.2) # +# @writable: True if clients should be able to write to the export +# (default false) +# # @writethrough: If true, caches are flushed after every write request to = the # export before completion is signalled. (since: 5.2; # default: false) @@ -198,6 +202,7 @@ 'base': { 'type': 'BlockExportType', 'id': 'str', 'node-name': 'str', + '*writable': 'bool', '*writethrough': 'bool' }, 'discriminator': 'type', 'data': { diff --git a/block/export/export.c b/block/export/export.c index 657bb58b51..f2c00d13bf 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -62,6 +62,7 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Erro= r **errp) BlockDriverState *bs; BlockBackend *blk; AioContext *ctx; + uint64_t perm; int ret; =20 if (!id_wellformed(export->id)) { @@ -84,6 +85,14 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Err= or **errp) return NULL; } =20 + if (!export->has_writable) { + export->writable =3D false; + } + if (bdrv_is_read_only(bs) && export->writable) { + error_setg(errp, "Cannot export read-only node as writable"); + return NULL; + } + ctx =3D bdrv_get_aio_context(bs); aio_context_acquire(ctx); =20 @@ -95,7 +104,12 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Er= ror **errp) */ bdrv_invalidate_cache(bs, NULL); =20 - blk =3D blk_new(ctx, BLK_PERM_CONSISTENT_READ, BLK_PERM_ALL); + perm =3D BLK_PERM_CONSISTENT_READ; + if (export->writable) { + perm |=3D BLK_PERM_WRITE; + } + + blk =3D blk_new(ctx, perm, BLK_PERM_ALL); ret =3D blk_insert_bs(blk, bs, errp); if (ret < 0) { goto fail; diff --git a/blockdev-nbd.c b/blockdev-nbd.c index cdbbcdb958..30e165c23f 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -204,16 +204,8 @@ int nbd_export_create(BlockExport *exp, BlockExportOpt= ions *exp_args, return -EEXIST; } =20 - if (!arg->has_writable) { - arg->writable =3D false; - } - if (blk_is_read_only(exp->blk) && arg->writable) { - error_setg(errp, "Cannot export read-only node as writable"); - return -EINVAL; - } - return nbd_export_new(exp, arg->name, arg->description, arg->bitmap, - !arg->writable, !arg->writable, errp); + !exp_args->writable, !exp_args->writable, errp); } =20 void qmp_nbd_server_add(NbdServerAddOptions *arg, Error **errp) @@ -241,13 +233,13 @@ void qmp_nbd_server_add(NbdServerAddOptions *arg, Err= or **errp) .type =3D BLOCK_EXPORT_TYPE_NBD, .id =3D g_strdup(arg->name), .node_name =3D g_strdup(bdrv_get_node_name(bs)), + .has_writable =3D arg->has_writable, + .writable =3D arg->writable, .u.nbd =3D { .has_name =3D true, .name =3D g_strdup(arg->name), .has_description =3D arg->has_description, .description =3D g_strdup(arg->description), - .has_writable =3D arg->has_writable, - .writable =3D arg->writable, .has_bitmap =3D arg->has_bitmap, .bitmap =3D g_strdup(arg->bitmap), }, @@ -259,8 +251,8 @@ void qmp_nbd_server_add(NbdServerAddOptions *arg, Error= **errp) * block-export-add. */ if (bdrv_is_read_only(bs)) { - export_opts->u.nbd.has_writable =3D true; - export_opts->u.nbd.writable =3D false; + export_opts->has_writable =3D true; + export_opts->writable =3D false; } =20 export =3D blk_exp_add(export_opts, errp); diff --git a/nbd/server.c b/nbd/server.c index 6c8532de23..465ec9e762 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1530,11 +1530,6 @@ int nbd_export_new(BlockExport *blk_exp, /* Don't allow resize while the NBD server is running, otherwise we do= n't * care what happens with the node. */ blk_get_perm(blk, &perm, &shared_perm); - - if (!readonly) { - perm |=3D BLK_PERM_WRITE; - } - ret =3D blk_set_perm(blk, perm, shared_perm & ~BLK_PERM_RESIZE, errp); if (ret < 0) { return ret; diff --git a/qemu-nbd.c b/qemu-nbd.c index ac82acb4ac..6d7ac7490f 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -1068,13 +1068,13 @@ int main(int argc, char **argv) .node_name =3D g_strdup(bdrv_get_node_name(bs)), .has_writethrough =3D true, .writethrough =3D writethrough, + .has_writable =3D true, + .writable =3D !readonly, .u.nbd =3D { .has_name =3D true, .name =3D g_strdup(export_name), .has_description =3D !!export_description, .description =3D g_strdup(export_description), - .has_writable =3D true, - .writable =3D !readonly, .has_bitmap =3D !!bitmap, .bitmap =3D g_strdup(bitmap), }, --=20 2.25.4