From patchwork Thu Aug 13 16:29:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11712663 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1EC9616B1 for ; Thu, 13 Aug 2020 16:31:08 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E3D9D205CB for ; Thu, 13 Aug 2020 16:31:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HarhHbvF" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E3D9D205CB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:46204 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k6G8A-0003YC-Rj for patchwork-qemu-devel@patchwork.kernel.org; Thu, 13 Aug 2020 12:31:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55202) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k6G70-0001c7-2H for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:29:54 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:57453 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1k6G6x-0001Bx-VV for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:29:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597336190; 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=RZv40vn5+MgfdLcaYKzNFB3/feCmRyosDbRQJrLEC4o=; b=HarhHbvFh6gJ8WfpPVtkeWWr3CQ7FN3V+o5k6/9MScwQ2/P+/waq7/4tcem5Nu+zEuGMY5 8zyzxuFbiS7OmRODv0sZSkAijhH0l8zaB7fNt9LGpDenhkgmERY1yVgcKkJdwHsNSxHYuM XYeLML1+510pfkSx3G3ZyR7s3HImUhc= 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-427-xYQhjvoRNdqP6kVFyl_vig-1; Thu, 13 Aug 2020 12:29:49 -0400 X-MC-Unique: xYQhjvoRNdqP6kVFyl_vig-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2B677183586D; Thu, 13 Aug 2020 16:29:48 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-113-97.ams2.redhat.com [10.36.113.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0BA0A5C1A3; Thu, 13 Aug 2020 16:29:46 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 01/22] nbd: Remove unused nbd_export_get_blockdev() Date: Thu, 13 Aug 2020 18:29:14 +0200 Message-Id: <20200813162935.210070-2-kwolf@redhat.com> In-Reply-To: <20200813162935.210070-1-kwolf@redhat.com> References: <20200813162935.210070-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=207.211.31.120; envelope-from=kwolf@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/13 03:45:42 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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: , Cc: kwolf@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz Reviewed-by: Eric Blake --- include/block/nbd.h | 2 -- nbd/server.c | 5 ----- 2 files changed, 7 deletions(-) diff --git a/include/block/nbd.h b/include/block/nbd.h index 9bc3bfaeec..0451683d03 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -338,8 +338,6 @@ void nbd_export_remove(NBDExport *exp, NbdServerRemoveMode mode, Error **errp); void nbd_export_get(NBDExport *exp); void nbd_export_put(NBDExport *exp); -BlockBackend *nbd_export_get_blockdev(NBDExport *exp); - AioContext *nbd_export_aio_context(NBDExport *exp); NBDExport *nbd_export_find(const char *name); void nbd_export_close_all(void); diff --git a/nbd/server.c b/nbd/server.c index 4752a6c8bc..bee2ef8bd1 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1731,11 +1731,6 @@ void nbd_export_put(NBDExport *exp) } } -BlockBackend *nbd_export_get_blockdev(NBDExport *exp) -{ - return exp->blk; -} - void nbd_export_close_all(void) { NBDExport *exp, *next; From patchwork Thu Aug 13 16:29:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11712669 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 33CC5722 for ; Thu, 13 Aug 2020 16:32:56 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EDF5A206A4 for ; Thu, 13 Aug 2020 16:32:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="AHpDSddj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EDF5A206A4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:54512 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k6G9v-0006vj-6T for patchwork-qemu-devel@patchwork.kernel.org; Thu, 13 Aug 2020 12:32:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55270) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k6G71-0001d8-N0 for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:29:55 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:51439 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1k6G6z-0001C9-13 for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:29:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597336192; 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=ndPcjpwoAM/JzDAfgWy554SdcHxBbhEn5xoFA7I7uZ4=; b=AHpDSddj5cEmCegwLfDuKj08+Pz7E4zstO8SHOC7pDc1Bo9pDvipmHHPetf5Sde2VC+G2F g/1nyx5WvJlTRrQ9L4DOZHI2baZ18Zih+jDElKEzTvvBNQqEnXZIWjsKE70N3kFkn62/zl 2/5dzyL3zmt8TUgqYGATYR2UtWv/7AY= 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-282-CGTSaX2SNvWmZVsnQwSBaw-1; Thu, 13 Aug 2020 12:29:50 -0400 X-MC-Unique: CGTSaX2SNvWmZVsnQwSBaw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 972531835865; Thu, 13 Aug 2020 16:29:49 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-113-97.ams2.redhat.com [10.36.113.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7511F5C1A3; Thu, 13 Aug 2020 16:29:48 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 02/22] qapi: Create block-export module Date: Thu, 13 Aug 2020 18:29:15 +0200 Message-Id: <20200813162935.210070-3-kwolf@redhat.com> In-Reply-To: <20200813162935.210070-1-kwolf@redhat.com> References: <20200813162935.210070-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=205.139.110.61; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/13 12:29:49 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -40 X-Spam_score: -4.1 X-Spam_bar: ---- X-Spam_report: (-4.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, 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_H2=-1, 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: , Cc: kwolf@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Move all block export related types and commands from block-core to the new QAPI module block-export. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz Reviewed-by: Eric Blake --- qapi/block-core.json | 166 -------------------------- qapi/block-export.json | 172 +++++++++++++++++++++++++++ qapi/qapi-schema.json | 1 + include/block/nbd.h | 2 +- block/monitor/block-hmp-cmds.c | 1 + blockdev-nbd.c | 2 +- qemu-storage-daemon.c | 2 +- qapi/Makefile.objs | 5 +- storage-daemon/qapi/qapi-schema.json | 1 + 9 files changed, 181 insertions(+), 171 deletions(-) create mode 100644 qapi/block-export.json diff --git a/qapi/block-core.json b/qapi/block-core.json index ab7bf3c612..5c491d4cbd 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -5176,172 +5176,6 @@ 'iothread': 'StrOrNull', '*force': 'bool' } } -## -# @NbdServerOptions: -# -# @addr: Address on which to listen. -# @tls-creds: ID of the TLS credentials object (since 2.6). -# @tls-authz: ID of the QAuthZ authorization object used to validate -# the client's x509 distinguished name. This object is -# is only resolved at time of use, so can be deleted and -# recreated on the fly while the NBD server is active. -# If missing, it will default to denying access (since 4.0). -# -# Keep this type consistent with the nbd-server-start arguments. The only -# intended difference is using SocketAddress instead of SocketAddressLegacy. -# -# Since: 4.2 -## -{ 'struct': 'NbdServerOptions', - 'data': { 'addr': 'SocketAddress', - '*tls-creds': 'str', - '*tls-authz': 'str'} } - -## -# @nbd-server-start: -# -# Start an NBD server listening on the given host and port. Block -# devices can then be exported using @nbd-server-add. The NBD -# server will present them as named exports; for example, another -# QEMU instance could refer to them as "nbd:HOST:PORT:exportname=NAME". -# -# @addr: Address on which to listen. -# @tls-creds: ID of the TLS credentials object (since 2.6). -# @tls-authz: ID of the QAuthZ authorization object used to validate -# the client's x509 distinguished name. This object is -# is only resolved at time of use, so can be deleted and -# recreated on the fly while the NBD server is active. -# If missing, it will default to denying access (since 4.0). -# -# Returns: error if the server is already running. -# -# Keep this type consistent with the NbdServerOptions type. The only intended -# difference is using SocketAddressLegacy instead of SocketAddress. -# -# Since: 1.3.0 -## -{ 'command': 'nbd-server-start', - 'data': { 'addr': 'SocketAddressLegacy', - '*tls-creds': 'str', - '*tls-authz': 'str'} } - -## -# @BlockExportNbd: -# -# An NBD block export. -# -# @device: The device name or node name of the node to be exported -# -# @name: Export name. If unspecified, the @device parameter is used as the -# export name. (Since 2.12) -# -# @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) -# -# Since: 5.0 -## -{ 'struct': 'BlockExportNbd', - 'data': {'device': 'str', '*name': 'str', '*description': 'str', - '*writable': 'bool', '*bitmap': 'str' } } - -## -# @nbd-server-add: -# -# Export a block node to QEMU's embedded NBD server. -# -# Returns: error if the server is not running, or export with the same name -# already exists. -# -# Since: 1.3.0 -## -{ 'command': 'nbd-server-add', - 'data': 'BlockExportNbd', 'boxed': true } - -## -# @NbdServerRemoveMode: -# -# Mode for removing an NBD export. -# -# @safe: Remove export if there are no existing connections, fail otherwise. -# -# @hard: Drop all connections immediately and remove export. -# -# Potential additional modes to be added in the future: -# -# hide: Just hide export from new clients, leave existing connections as is. -# Remove export after all clients are disconnected. -# -# soft: Hide export from new clients, answer with ESHUTDOWN for all further -# requests from existing clients. -# -# Since: 2.12 -## -{'enum': 'NbdServerRemoveMode', 'data': ['safe', 'hard']} - -## -# @nbd-server-remove: -# -# Remove NBD export by name. -# -# @name: Export name. -# -# @mode: Mode of command operation. See @NbdServerRemoveMode description. -# Default is 'safe'. -# -# Returns: error if -# - the server is not running -# - export is not found -# - mode is 'safe' and there are existing connections -# -# Since: 2.12 -## -{ 'command': 'nbd-server-remove', - 'data': {'name': 'str', '*mode': 'NbdServerRemoveMode'} } - -## -# @nbd-server-stop: -# -# Stop QEMU's embedded NBD server, and unregister all devices previously -# added via @nbd-server-add. -# -# Since: 1.3.0 -## -{ 'command': 'nbd-server-stop' } - -## -# @BlockExportType: -# -# An enumeration of block export types -# -# @nbd: NBD export -# -# Since: 4.2 -## -{ 'enum': 'BlockExportType', - 'data': [ 'nbd' ] } - -## -# @BlockExport: -# -# Describes a block export, i.e. how single node should be exported on an -# external interface. -# -# Since: 4.2 -## -{ 'union': 'BlockExport', - 'base': { 'type': 'BlockExportType' }, - 'discriminator': 'type', - 'data': { - 'nbd': 'BlockExportNbd' - } } - ## # @QuorumOpType: # diff --git a/qapi/block-export.json b/qapi/block-export.json new file mode 100644 index 0000000000..62f4938e83 --- /dev/null +++ b/qapi/block-export.json @@ -0,0 +1,172 @@ +## +# == Block device exports +## + +{ 'include': 'sockets.json' } + +## +# @NbdServerOptions: +# +# @addr: Address on which to listen. +# @tls-creds: ID of the TLS credentials object (since 2.6). +# @tls-authz: ID of the QAuthZ authorization object used to validate +# the client's x509 distinguished name. This object is +# is only resolved at time of use, so can be deleted and +# recreated on the fly while the NBD server is active. +# If missing, it will default to denying access (since 4.0). +# +# Keep this type consistent with the nbd-server-start arguments. The only +# intended difference is using SocketAddress instead of SocketAddressLegacy. +# +# Since: 4.2 +## +{ 'struct': 'NbdServerOptions', + 'data': { 'addr': 'SocketAddress', + '*tls-creds': 'str', + '*tls-authz': 'str'} } + +## +# @nbd-server-start: +# +# Start an NBD server listening on the given host and port. Block +# devices can then be exported using @nbd-server-add. The NBD +# server will present them as named exports; for example, another +# QEMU instance could refer to them as "nbd:HOST:PORT:exportname=NAME". +# +# @addr: Address on which to listen. +# @tls-creds: ID of the TLS credentials object (since 2.6). +# @tls-authz: ID of the QAuthZ authorization object used to validate +# the client's x509 distinguished name. This object is +# is only resolved at time of use, so can be deleted and +# recreated on the fly while the NBD server is active. +# If missing, it will default to denying access (since 4.0). +# +# Returns: error if the server is already running. +# +# Keep this type consistent with the NbdServerOptions type. The only intended +# difference is using SocketAddressLegacy instead of SocketAddress. +# +# Since: 1.3.0 +## +{ 'command': 'nbd-server-start', + 'data': { 'addr': 'SocketAddressLegacy', + '*tls-creds': 'str', + '*tls-authz': 'str'} } + +## +# @BlockExportNbd: +# +# An NBD block export. +# +# @device: The device name or node name of the node to be exported +# +# @name: Export name. If unspecified, the @device parameter is used as the +# export name. (Since 2.12) +# +# @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) +# +# Since: 5.0 +## +{ 'struct': 'BlockExportNbd', + 'data': {'device': 'str', '*name': 'str', '*description': 'str', + '*writable': 'bool', '*bitmap': 'str' } } + +## +# @nbd-server-add: +# +# Export a block node to QEMU's embedded NBD server. +# +# Returns: error if the server is not running, or export with the same name +# already exists. +# +# Since: 1.3.0 +## +{ 'command': 'nbd-server-add', + 'data': 'BlockExportNbd', 'boxed': true } + +## +# @NbdServerRemoveMode: +# +# Mode for removing an NBD export. +# +# @safe: Remove export if there are no existing connections, fail otherwise. +# +# @hard: Drop all connections immediately and remove export. +# +# Potential additional modes to be added in the future: +# +# hide: Just hide export from new clients, leave existing connections as is. +# Remove export after all clients are disconnected. +# +# soft: Hide export from new clients, answer with ESHUTDOWN for all further +# requests from existing clients. +# +# Since: 2.12 +## +{'enum': 'NbdServerRemoveMode', 'data': ['safe', 'hard']} + +## +# @nbd-server-remove: +# +# Remove NBD export by name. +# +# @name: Export name. +# +# @mode: Mode of command operation. See @NbdServerRemoveMode description. +# Default is 'safe'. +# +# Returns: error if +# - the server is not running +# - export is not found +# - mode is 'safe' and there are existing connections +# +# Since: 2.12 +## +{ 'command': 'nbd-server-remove', + 'data': {'name': 'str', '*mode': 'NbdServerRemoveMode'} } + +## +# @nbd-server-stop: +# +# Stop QEMU's embedded NBD server, and unregister all devices previously +# added via @nbd-server-add. +# +# Since: 1.3.0 +## +{ 'command': 'nbd-server-stop' } + +## +# @BlockExportType: +# +# An enumeration of block export types +# +# @nbd: NBD export +# +# Since: 4.2 +## +{ 'enum': 'BlockExportType', + 'data': [ 'nbd' ] } + +## +# @BlockExport: +# +# Describes a block export, i.e. how single node should be exported on an +# external interface. +# +# Since: 4.2 +## +{ 'union': 'BlockExport', + 'base': { 'type': 'BlockExportType' }, + 'discriminator': 'type', + 'data': { + 'nbd': 'BlockExportNbd' + } } + diff --git a/qapi/qapi-schema.json b/qapi/qapi-schema.json index 43b0ba0dea..2b37f6eb88 100644 --- a/qapi/qapi-schema.json +++ b/qapi/qapi-schema.json @@ -63,6 +63,7 @@ { 'include': 'run-state.json' } { 'include': 'crypto.json' } { 'include': 'block.json' } +{ 'include': 'block-export.json' } { 'include': 'char.json' } { 'include': 'dump.json' } { 'include': 'job.json' } diff --git a/include/block/nbd.h b/include/block/nbd.h index 0451683d03..262f6da2ce 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -20,7 +20,7 @@ #ifndef NBD_H #define NBD_H -#include "qapi/qapi-types-block.h" +#include "qapi/qapi-types-block-export.h" #include "io/channel-socket.h" #include "crypto/tlscreds.h" #include "qapi/error.h" diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c index 4c8c375172..fb9d87ee89 100644 --- a/block/monitor/block-hmp-cmds.c +++ b/block/monitor/block-hmp-cmds.c @@ -40,6 +40,7 @@ #include "sysemu/block-backend.h" #include "sysemu/blockdev.h" #include "qapi/qapi-commands-block.h" +#include "qapi/qapi-commands-block-export.h" #include "qapi/qmp/qdict.h" #include "qapi/error.h" #include "qapi/qmp/qerror.h" diff --git a/blockdev-nbd.c b/blockdev-nbd.c index 1a95d89f00..0f6b80c58f 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -14,7 +14,7 @@ #include "sysemu/block-backend.h" #include "hw/block/block.h" #include "qapi/error.h" -#include "qapi/qapi-commands-block.h" +#include "qapi/qapi-commands-block-export.h" #include "block/nbd.h" #include "io/channel-socket.h" #include "io/net-listener.h" diff --git a/qemu-storage-daemon.c b/qemu-storage-daemon.c index 7e9b0e0d3f..ed9d2afcf3 100644 --- a/qemu-storage-daemon.c +++ b/qemu-storage-daemon.c @@ -35,8 +35,8 @@ #include "monitor/monitor-internal.h" #include "qapi/error.h" -#include "qapi/qapi-visit-block.h" #include "qapi/qapi-visit-block-core.h" +#include "qapi/qapi-visit-block-export.h" #include "qapi/qapi-visit-control.h" #include "qapi/qmp/qdict.h" #include "qapi/qmp/qstring.h" diff --git a/qapi/Makefile.objs b/qapi/Makefile.objs index 4673ab7490..c5093b4d61 100644 --- a/qapi/Makefile.objs +++ b/qapi/Makefile.objs @@ -5,7 +5,8 @@ util-obj-y += opts-visitor.o qapi-clone-visitor.o util-obj-y += qmp-event.o util-obj-y += qapi-util.o -QAPI_COMMON_MODULES = audio authz block-core block char common control crypto +QAPI_COMMON_MODULES = audio authz block-core block-export block char common +QAPI_COMMON_MODULES += control crypto QAPI_COMMON_MODULES += dump error introspect job machine migration misc QAPI_COMMON_MODULES += net pragma qdev qom rdma rocker run-state sockets tpm QAPI_COMMON_MODULES += trace transaction ui @@ -32,7 +33,7 @@ obj-y += $(QAPI_TARGET_MODULES:%=qapi-commands-%.o) obj-y += qapi-commands.o obj-y += qapi-init-commands.o -QAPI_MODULES_STORAGE_DAEMON = block-core char common control crypto +QAPI_MODULES_STORAGE_DAEMON = block-core block-export char common control crypto QAPI_MODULES_STORAGE_DAEMON += introspect job qom sockets pragma transaction storage-daemon-obj-y += $(QAPI_MODULES_STORAGE_DAEMON:%=qapi-commands-%.o) diff --git a/storage-daemon/qapi/qapi-schema.json b/storage-daemon/qapi/qapi-schema.json index 14f4f8fe61..9c7133724a 100644 --- a/storage-daemon/qapi/qapi-schema.json +++ b/storage-daemon/qapi/qapi-schema.json @@ -15,6 +15,7 @@ { 'include': '../../qapi/pragma.json' } { 'include': '../../qapi/block-core.json' } +{ 'include': '../../qapi/block-export.json' } { 'include': '../../qapi/char.json' } { 'include': '../../qapi/common.json' } { 'include': '../../qapi/control.json' } From patchwork Thu Aug 13 16:29:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11712671 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1AE2B722 for ; Thu, 13 Aug 2020 16:32:57 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E5607206A4 for ; Thu, 13 Aug 2020 16:32:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="FLFt2n5n" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E5607206A4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:54682 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k6G9w-0006zp-5i for patchwork-qemu-devel@patchwork.kernel.org; Thu, 13 Aug 2020 12:32:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55274) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k6G72-0001eW-CR for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:29:56 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:37481 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1k6G70-0001CW-BN for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:29:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597336193; 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=7UtbIIB/8AW+Dzn5uvnP3+ycZ/DiyZJ0vPwihVSFY1Q=; b=FLFt2n5n76rgwchFh/zhhYOq9/f3GDswv38EMNEuACoTnj4BczxRZdgUoRH5nP9XX8XI6v wXZ+3XaWdGPQLsxem4cLP48T9bsld//fe6pFzg8SO4bg8ThgYVOBA4fSajZkI+rKu8KXpI Lcd+tGqiJ3HpdrK9nf1LxrjdaChWhvo= 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-365-270Wm3eHNeGL-yUHkql1kA-1; Thu, 13 Aug 2020 12:29:52 -0400 X-MC-Unique: 270Wm3eHNeGL-yUHkql1kA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0DAEF1005504; Thu, 13 Aug 2020 16:29:51 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-113-97.ams2.redhat.com [10.36.113.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id E16B05C1A3; Thu, 13 Aug 2020 16:29:49 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 03/22] qapi: Rename BlockExport to BlockExportOptions Date: Thu, 13 Aug 2020 18:29:16 +0200 Message-Id: <20200813162935.210070-4-kwolf@redhat.com> In-Reply-To: <20200813162935.210070-1-kwolf@redhat.com> References: <20200813162935.210070-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=207.211.31.120; envelope-from=kwolf@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/13 03:45:42 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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: , Cc: kwolf@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" The name BlockExport will be used for the struct containing the runtime state of block exports, so change the name of export creation options. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz Reviewed-by: Eric Blake --- qapi/block-export.json | 12 ++++++------ block/monitor/block-hmp-cmds.c | 6 +++--- blockdev-nbd.c | 2 +- qemu-storage-daemon.c | 8 ++++---- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/qapi/block-export.json b/qapi/block-export.json index 62f4938e83..9332076a05 100644 --- a/qapi/block-export.json +++ b/qapi/block-export.json @@ -54,7 +54,7 @@ '*tls-authz': 'str'} } ## -# @BlockExportNbd: +# @BlockExportOptionsNbd: # # An NBD block export. # @@ -75,7 +75,7 @@ # # Since: 5.0 ## -{ 'struct': 'BlockExportNbd', +{ 'struct': 'BlockExportOptionsNbd', 'data': {'device': 'str', '*name': 'str', '*description': 'str', '*writable': 'bool', '*bitmap': 'str' } } @@ -90,7 +90,7 @@ # Since: 1.3.0 ## { 'command': 'nbd-server-add', - 'data': 'BlockExportNbd', 'boxed': true } + 'data': 'BlockExportOptionsNbd', 'boxed': true } ## # @NbdServerRemoveMode: @@ -156,17 +156,17 @@ 'data': [ 'nbd' ] } ## -# @BlockExport: +# @BlockExportOptions: # # Describes a block export, i.e. how single node should be exported on an # external interface. # # Since: 4.2 ## -{ 'union': 'BlockExport', +{ 'union': 'BlockExportOptions', 'base': { 'type': 'BlockExportType' }, 'discriminator': 'type', 'data': { - 'nbd': 'BlockExportNbd' + 'nbd': 'BlockExportOptionsNbd' } } diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c index fb9d87ee89..56bc83ac97 100644 --- a/block/monitor/block-hmp-cmds.c +++ b/block/monitor/block-hmp-cmds.c @@ -398,7 +398,7 @@ void hmp_nbd_server_start(Monitor *mon, const QDict *qdict) Error *local_err = NULL; BlockInfoList *block_list, *info; SocketAddress *addr; - BlockExportNbd export; + BlockExportOptionsNbd export; if (writable && !all) { error_setg(&local_err, "-w only valid together with -a"); @@ -431,7 +431,7 @@ void hmp_nbd_server_start(Monitor *mon, const QDict *qdict) continue; } - export = (BlockExportNbd) { + export = (BlockExportOptionsNbd) { .device = info->value->device, .has_writable = true, .writable = writable, @@ -458,7 +458,7 @@ void hmp_nbd_server_add(Monitor *mon, const QDict *qdict) bool writable = qdict_get_try_bool(qdict, "writable", false); Error *local_err = NULL; - BlockExportNbd export = { + BlockExportOptionsNbd export = { .device = (char *) device, .has_name = !!name, .name = (char *) name, diff --git a/blockdev-nbd.c b/blockdev-nbd.c index 0f6b80c58f..98ee1b6170 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -148,7 +148,7 @@ void qmp_nbd_server_start(SocketAddressLegacy *addr, qapi_free_SocketAddress(addr_flat); } -void qmp_nbd_server_add(BlockExportNbd *arg, Error **errp) +void qmp_nbd_server_add(BlockExportOptionsNbd *arg, Error **errp) { BlockDriverState *bs = NULL; BlockBackend *on_eject_blk; diff --git a/qemu-storage-daemon.c b/qemu-storage-daemon.c index ed9d2afcf3..ed26097254 100644 --- a/qemu-storage-daemon.c +++ b/qemu-storage-daemon.c @@ -150,7 +150,7 @@ static void init_qmp_commands(void) qmp_marshal_qmp_capabilities, QCO_ALLOW_PRECONFIG); } -static void init_export(BlockExport *export, Error **errp) +static void init_export(BlockExportOptions *export, Error **errp) { switch (export->type) { case BLOCK_EXPORT_TYPE_NBD: @@ -235,14 +235,14 @@ static void process_options(int argc, char *argv[]) case OPTION_EXPORT: { Visitor *v; - BlockExport *export; + BlockExportOptions *export; v = qobject_input_visitor_new_str(optarg, "type", &error_fatal); - visit_type_BlockExport(v, NULL, &export, &error_fatal); + visit_type_BlockExportOptions(v, NULL, &export, &error_fatal); visit_free(v); init_export(export, &error_fatal); - qapi_free_BlockExport(export); + qapi_free_BlockExportOptions(export); break; } case OPTION_MONITOR: From patchwork Thu Aug 13 16:29:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11712679 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9D99D722 for ; Thu, 13 Aug 2020 16:34:37 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 64948206A4 for ; Thu, 13 Aug 2020 16:34:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="P6IFHd84" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 64948206A4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:35402 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k6GBY-0002Bu-KI for patchwork-qemu-devel@patchwork.kernel.org; Thu, 13 Aug 2020 12:34:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55346) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k6G75-0001ng-RM for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:29:59 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:40824 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1k6G72-0001D0-8a for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:29:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597336195; 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=ds+x3uGjKOJoiQrFgVPKmat43BWVK5iXn4eoYFhvg0o=; b=P6IFHd843xv/tCOUn29cek20xOgCLgUotCSVUDjeqSeDWgujDqmKXCBBOgHMraErR4dLSz 0jftBSkmQCDOlLcD6FkumEZuEc4BGiW4FMTg9v7EgtLQ5K3m+Pje2myLtsHZOZPqaIIZEA x7Cw4K5XF6wZv2VeDTR5Kpq7nc1Dw5M= 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-347-PCTvLbY8NHC4H-MSMbNnPg-1; Thu, 13 Aug 2020 12:29:53 -0400 X-MC-Unique: PCTvLbY8NHC4H-MSMbNnPg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7AA631015DC5; Thu, 13 Aug 2020 16:29:52 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-113-97.ams2.redhat.com [10.36.113.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 57E635C1A3; Thu, 13 Aug 2020 16:29:51 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 04/22] block/export: Add BlockExport infrastructure and block-export-add Date: Thu, 13 Aug 2020 18:29:17 +0200 Message-Id: <20200813162935.210070-5-kwolf@redhat.com> In-Reply-To: <20200813162935.210070-1-kwolf@redhat.com> References: <20200813162935.210070-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=207.211.31.81; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/13 02:03:30 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -40 X-Spam_score: -4.1 X-Spam_bar: ---- X-Spam_report: (-4.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, 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_H2=-1, 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, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" We want to have a common set of commands for all types of block exports. Currently, this is only NBD, but we're going to add more types. This patch adds the basic BlockExport and BlockExportDriver structs and a QMP command block-export-add that creates a new export based on the given BlockExportOptions. qmp_nbd_server_add() becomes a wrapper around qmp_block_export_add(). Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- qapi/block-export.json | 9 ++++++ include/block/export.h | 32 +++++++++++++++++++++ include/block/nbd.h | 3 +- block/export/export.c | 57 ++++++++++++++++++++++++++++++++++++++ blockdev-nbd.c | 19 ++++++++----- nbd/server.c | 15 +++++++++- Makefile.objs | 6 ++-- block/Makefile.objs | 2 ++ block/export/Makefile.objs | 1 + 9 files changed, 132 insertions(+), 12 deletions(-) create mode 100644 include/block/export.h create mode 100644 block/export/export.c create mode 100644 block/export/Makefile.objs diff --git a/qapi/block-export.json b/qapi/block-export.json index 9332076a05..40369814b4 100644 --- a/qapi/block-export.json +++ b/qapi/block-export.json @@ -170,3 +170,12 @@ 'nbd': 'BlockExportOptionsNbd' } } +## +# @block-export-add: +# +# Creates a new block export. +# +# Since: 5.2 +## +{ 'command': 'block-export-add', + 'data': 'BlockExportOptions', 'boxed': true } diff --git a/include/block/export.h b/include/block/export.h new file mode 100644 index 0000000000..b1d7325403 --- /dev/null +++ b/include/block/export.h @@ -0,0 +1,32 @@ +/* + * Declarations for block exports + * + * Copyright (c) 2012, 2020 Red Hat, Inc. + * + * Authors: + * Paolo Bonzini + * Kevin Wolf + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * later. See the COPYING file in the top-level directory. + */ + +#ifndef BLOCK_EXPORT_H +#define BLOCK_EXPORT_H + +#include "qapi/qapi-types-block-export.h" + +typedef struct BlockExport BlockExport; + +typedef struct BlockExportDriver { + BlockExportType type; + BlockExport *(*create)(BlockExportOptions *, Error **); +} BlockExportDriver; + +struct BlockExport { + const BlockExportDriver *drv; +}; + +extern const BlockExportDriver blk_exp_nbd; + +#endif diff --git a/include/block/nbd.h b/include/block/nbd.h index 262f6da2ce..c8c5cb6b61 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -20,7 +20,7 @@ #ifndef NBD_H #define NBD_H -#include "qapi/qapi-types-block-export.h" +#include "block/export.h" #include "io/channel-socket.h" #include "crypto/tlscreds.h" #include "qapi/error.h" @@ -328,6 +328,7 @@ int nbd_errno_to_system_errno(int err); typedef struct NBDExport NBDExport; typedef struct NBDClient NBDClient; +BlockExport *nbd_export_create(BlockExportOptions *exp_args, Error **errp); NBDExport *nbd_export_new(BlockDriverState *bs, uint64_t dev_offset, uint64_t size, const char *name, const char *desc, const char *bitmap, bool readonly, bool shared, diff --git a/block/export/export.c b/block/export/export.c new file mode 100644 index 0000000000..3d0dacb3f2 --- /dev/null +++ b/block/export/export.c @@ -0,0 +1,57 @@ +/* + * Common block export infrastructure + * + * Copyright (c) 2012, 2020 Red Hat, Inc. + * + * Authors: + * Paolo Bonzini + * Kevin Wolf + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * later. See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" + +#include "block/export.h" +#include "block/nbd.h" +#include "qapi/error.h" +#include "qapi/qapi-commands-block-export.h" + +static const BlockExportDriver* blk_exp_drivers[] = { + &blk_exp_nbd, +}; + +static const BlockExportDriver *blk_exp_find_driver(BlockExportType type) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(blk_exp_drivers); i++) { + if (blk_exp_drivers[i]->type == type) { + return blk_exp_drivers[i]; + } + } + return NULL; +} + +void qmp_block_export_add(BlockExportOptions *export, Error **errp) +{ + const BlockExportDriver *drv; + + drv = blk_exp_find_driver(export->type); + if (!drv) { + error_setg(errp, "No driver found for the requested export type"); + return; + } + + drv->create(export, errp); +} + +void qmp_nbd_server_add(BlockExportOptionsNbd *arg, Error **errp) +{ + BlockExportOptions export = { + .type = BLOCK_EXPORT_TYPE_NBD, + .u.nbd = *arg, + }; + qmp_block_export_add(&export, errp); +} diff --git a/blockdev-nbd.c b/blockdev-nbd.c index 98ee1b6170..a1dc11bdd7 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -148,17 +148,20 @@ void qmp_nbd_server_start(SocketAddressLegacy *addr, qapi_free_SocketAddress(addr_flat); } -void qmp_nbd_server_add(BlockExportOptionsNbd *arg, Error **errp) +BlockExport *nbd_export_create(BlockExportOptions *exp_args, Error **errp) { + BlockExportOptionsNbd *arg = &exp_args->u.nbd; BlockDriverState *bs = NULL; BlockBackend *on_eject_blk; - NBDExport *exp; + NBDExport *exp = NULL; int64_t len; AioContext *aio_context; + assert(exp_args->type == BLOCK_EXPORT_TYPE_NBD); + if (!nbd_server) { error_setg(errp, "NBD server not running"); - return; + return NULL; } if (!arg->has_name) { @@ -167,24 +170,24 @@ void qmp_nbd_server_add(BlockExportOptionsNbd *arg, Error **errp) if (strlen(arg->name) > NBD_MAX_STRING_SIZE) { error_setg(errp, "export name '%s' too long", arg->name); - return; + return NULL; } if (arg->description && strlen(arg->description) > NBD_MAX_STRING_SIZE) { error_setg(errp, "description '%s' too long", arg->description); - return; + return NULL; } if (nbd_export_find(arg->name)) { error_setg(errp, "NBD server already has export named '%s'", arg->name); - return; + return NULL; } on_eject_blk = blk_by_name(arg->device); bs = bdrv_lookup_bs(arg->device, arg->device, errp); if (!bs) { - return; + return NULL; } aio_context = bdrv_get_aio_context(bs); @@ -217,6 +220,8 @@ void qmp_nbd_server_add(BlockExportOptionsNbd *arg, Error **errp) out: aio_context_release(aio_context); + /* TODO Remove the cast: Move to server.c which can access fields of exp */ + return (BlockExport*) exp; } void qmp_nbd_server_remove(const char *name, diff --git a/nbd/server.c b/nbd/server.c index bee2ef8bd1..774325dbe5 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -18,6 +18,8 @@ */ #include "qemu/osdep.h" + +#include "block/export.h" #include "qapi/error.h" #include "qemu/queue.h" #include "trace.h" @@ -80,6 +82,7 @@ struct NBDRequestData { }; struct NBDExport { + BlockExport common; int refcount; void (*close)(NBDExport *exp); @@ -1512,10 +1515,15 @@ NBDExport *nbd_export_new(BlockDriverState *bs, uint64_t dev_offset, { AioContext *ctx; BlockBackend *blk; - NBDExport *exp = g_new0(NBDExport, 1); + NBDExport *exp; uint64_t perm; int ret; + exp = g_new0(NBDExport, 1); + exp->common = (BlockExport) { + .drv = &blk_exp_nbd, + }; + /* * NBD exports are used for non-shared storage migration. Make sure * that BDRV_O_INACTIVE is cleared and the image is ready for write @@ -1731,6 +1739,11 @@ void nbd_export_put(NBDExport *exp) } } +const BlockExportDriver blk_exp_nbd = { + .type = BLOCK_EXPORT_TYPE_NBD, + .create = nbd_export_create, +}; + void nbd_export_close_all(void) { NBDExport *exp, *next; diff --git a/Makefile.objs b/Makefile.objs index d22b3b45d7..9b864ca046 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -14,7 +14,7 @@ chardev-obj-y = chardev/ authz-obj-y = authz/ block-obj-y = block/ nbd/ scsi/ -block-obj-y += block.o blockjob.o job.o +block-obj-y += block.o blockjob.o job.o blockdev-nbd.o block-obj-y += qemu-io-cmds.o block-obj-$(CONFIG_REPLICATION) += replication.o @@ -31,7 +31,7 @@ endif # CONFIG_SOFTMMU or CONFIG_TOOLS # used for system emulation, too, but specified separately there) storage-daemon-obj-y = block/ monitor/ qapi/ qom/ storage-daemon/ -storage-daemon-obj-y += blockdev.o blockdev-nbd.o iothread.o job-qmp.o +storage-daemon-obj-y += blockdev.o iothread.o job-qmp.o storage-daemon-obj-$(CONFIG_WIN32) += os-win32.o storage-daemon-obj-$(CONFIG_POSIX) += os-posix.o @@ -41,7 +41,7 @@ storage-daemon-obj-$(CONFIG_POSIX) += os-posix.o # single QEMU executable should support all CPUs and machines. ifeq ($(CONFIG_SOFTMMU),y) -common-obj-y = blockdev.o blockdev-nbd.o block/ +common-obj-y = blockdev.o block/ common-obj-y += bootdevice.o iothread.o common-obj-y += dump/ common-obj-y += job-qmp.o diff --git a/block/Makefile.objs b/block/Makefile.objs index 19c6f371c9..55b45c2f7d 100644 --- a/block/Makefile.objs +++ b/block/Makefile.objs @@ -44,6 +44,8 @@ block-obj-y += crypto.o block-obj-y += aio_task.o block-obj-y += backup-top.o block-obj-y += filter-compress.o + +block-obj-y += export/ common-obj-y += monitor/ block-obj-y += monitor/ diff --git a/block/export/Makefile.objs b/block/export/Makefile.objs new file mode 100644 index 0000000000..0c170ee6f1 --- /dev/null +++ b/block/export/Makefile.objs @@ -0,0 +1 @@ +block-obj-y += export.o From patchwork Thu Aug 13 16:29:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11712665 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0A01D722 for ; Thu, 13 Aug 2020 16:31:34 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D307120855 for ; Thu, 13 Aug 2020 16:31:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="KVqCqXfR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D307120855 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:47546 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k6G8b-00046n-1x for patchwork-qemu-devel@patchwork.kernel.org; Thu, 13 Aug 2020 12:31:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55362) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k6G76-0001pD-HN for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:30:00 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:41169 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1k6G74-0001Dg-W9 for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:30:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597336198; 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=zk7z5h8S3NWxmmAkCxBtINH2cvSr9u+MxB0Ck8Ngt4Q=; b=KVqCqXfR/NN8ows3twrAL77odTVOIjuKfNUCzEUWwvFNi+rRtWNQNy9nniLXZcoHADRycn vjhzEUu7a04o706dl9fGYt6LVKDnOwdkSq1fZaYInxKpyzvL3d5lEaQqkH7eP3gFO6YIPD 47widmPDHn/1ujxFjjslOcr2GSUQeTk= 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-566-1hKB9V1aOGONraYORSqLww-1; Thu, 13 Aug 2020 12:29:54 -0400 X-MC-Unique: 1hKB9V1aOGONraYORSqLww-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E2F551DDE8; Thu, 13 Aug 2020 16:29:53 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-113-97.ams2.redhat.com [10.36.113.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id C37975C1A3; Thu, 13 Aug 2020 16:29:52 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 05/22] qemu-storage-daemon: Use qmp_block_export_add() Date: Thu, 13 Aug 2020 18:29:18 +0200 Message-Id: <20200813162935.210070-6-kwolf@redhat.com> In-Reply-To: <20200813162935.210070-1-kwolf@redhat.com> References: <20200813162935.210070-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=205.139.110.61; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/13 12:29:49 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -40 X-Spam_score: -4.1 X-Spam_bar: ---- X-Spam_report: (-4.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, 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_H2=-1, 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, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" No reason to duplicate the functionality locally, we can now just reuse the QMP command block-export-add for --export. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz Reviewed-by: Eric Blake --- qemu-storage-daemon.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/qemu-storage-daemon.c b/qemu-storage-daemon.c index ed26097254..b6f678d3ab 100644 --- a/qemu-storage-daemon.c +++ b/qemu-storage-daemon.c @@ -150,17 +150,6 @@ static void init_qmp_commands(void) qmp_marshal_qmp_capabilities, QCO_ALLOW_PRECONFIG); } -static void init_export(BlockExportOptions *export, Error **errp) -{ - switch (export->type) { - case BLOCK_EXPORT_TYPE_NBD: - qmp_nbd_server_add(&export->u.nbd, errp); - break; - default: - g_assert_not_reached(); - } -} - static void process_options(int argc, char *argv[]) { int c; @@ -241,7 +230,7 @@ static void process_options(int argc, char *argv[]) visit_type_BlockExportOptions(v, NULL, &export, &error_fatal); visit_free(v); - init_export(export, &error_fatal); + qmp_block_export_add(export, &error_fatal); qapi_free_BlockExportOptions(export); break; } From patchwork Thu Aug 13 16:29:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11712685 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EF4971744 for ; Thu, 13 Aug 2020 16:36:09 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 757EB20675 for ; Thu, 13 Aug 2020 16:36:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="e1JaKW9e" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 757EB20675 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:43936 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k6GD2-0005ja-GQ for patchwork-qemu-devel@patchwork.kernel.org; Thu, 13 Aug 2020 12:36:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55392) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k6G78-0001tI-Dc for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:30:02 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:36574 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1k6G74-0001De-Ux for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:30:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597336198; 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=kqdBbaOtebg9k+ULyF6nrjBnTlCFNvvQpw6nVjvsUcM=; b=e1JaKW9eQqaFZibiuatyPZ90T+U5vwYxOJuqTsCo3ftynIbpam4TXzBZ4vbpvOtTbd8tUe knhAKOljONYIFrxKYQOFR51P7vGQaKeHWuWOrVJaPsD1iYmR2eQ8E3Yj/JInHVezWSJZaM owlT6oztUiIh0d9CPNxG5zVdTH1kaK8= 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-39-zoftNvpHPxikNw78TAVbXg-1; Thu, 13 Aug 2020 12:29:56 -0400 X-MC-Unique: zoftNvpHPxikNw78TAVbXg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5D4D91DDE0; Thu, 13 Aug 2020 16:29:55 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-113-97.ams2.redhat.com [10.36.113.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 38E7B5C1A3; Thu, 13 Aug 2020 16:29:54 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 06/22] qemu-nbd: Use raw block driver for --offset Date: Thu, 13 Aug 2020 18:29:19 +0200 Message-Id: <20200813162935.210070-7-kwolf@redhat.com> In-Reply-To: <20200813162935.210070-1-kwolf@redhat.com> References: <20200813162935.210070-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=207.211.31.81; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/13 02:03:30 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -40 X-Spam_score: -4.1 X-Spam_bar: ---- X-Spam_report: (-4.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, 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_H2=-1, 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: , Cc: kwolf@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Instead of implementing qemu-nbd --offset in the NBD code, just put a raw block node with the requested offset on top of the user image and rely on that doing the job. This does not only simplify the nbd_export_new() interface and bring it closer to the set of options that the nbd-server-add QMP command offers, but in fact it also eliminates a potential source for bugs in the NBD code which previously had to add the offset manually in all relevant places. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- include/block/nbd.h | 4 ++-- blockdev-nbd.c | 9 +-------- nbd/server.c | 34 +++++++++++++++++----------------- qemu-nbd.c | 27 ++++++++++++--------------- 4 files changed, 32 insertions(+), 42 deletions(-) diff --git a/include/block/nbd.h b/include/block/nbd.h index c8c5cb6b61..3846d2bac8 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -329,8 +329,8 @@ typedef struct NBDExport NBDExport; typedef struct NBDClient NBDClient; BlockExport *nbd_export_create(BlockExportOptions *exp_args, Error **errp); -NBDExport *nbd_export_new(BlockDriverState *bs, uint64_t dev_offset, - uint64_t size, const char *name, const char *desc, +NBDExport *nbd_export_new(BlockDriverState *bs, + const char *name, const char *desc, const char *bitmap, bool readonly, bool shared, void (*close)(NBDExport *), bool writethrough, BlockBackend *on_eject_blk, Error **errp); diff --git a/blockdev-nbd.c b/blockdev-nbd.c index a1dc11bdd7..16cda3b052 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -154,7 +154,6 @@ BlockExport *nbd_export_create(BlockExportOptions *exp_args, Error **errp) BlockDriverState *bs = NULL; BlockBackend *on_eject_blk; NBDExport *exp = NULL; - int64_t len; AioContext *aio_context; assert(exp_args->type == BLOCK_EXPORT_TYPE_NBD); @@ -192,12 +191,6 @@ BlockExport *nbd_export_create(BlockExportOptions *exp_args, Error **errp) aio_context = bdrv_get_aio_context(bs); aio_context_acquire(aio_context); - len = bdrv_getlength(bs); - if (len < 0) { - error_setg_errno(errp, -len, - "Failed to determine the NBD export's length"); - goto out; - } if (!arg->has_writable) { arg->writable = false; @@ -206,7 +199,7 @@ BlockExport *nbd_export_create(BlockExportOptions *exp_args, Error **errp) arg->writable = false; } - exp = nbd_export_new(bs, 0, len, arg->name, arg->description, arg->bitmap, + exp = nbd_export_new(bs, arg->name, arg->description, arg->bitmap, !arg->writable, !arg->writable, NULL, false, on_eject_blk, errp); if (!exp) { diff --git a/nbd/server.c b/nbd/server.c index 774325dbe5..92360d1f08 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -89,7 +89,6 @@ struct NBDExport { BlockBackend *blk; char *name; char *description; - uint64_t dev_offset; uint64_t size; uint16_t nbdflags; QTAILQ_HEAD(, NBDClient) clients; @@ -1507,8 +1506,8 @@ static void nbd_eject_notifier(Notifier *n, void *data) aio_context_release(aio_context); } -NBDExport *nbd_export_new(BlockDriverState *bs, uint64_t dev_offset, - uint64_t size, const char *name, const char *desc, +NBDExport *nbd_export_new(BlockDriverState *bs, + const char *name, const char *desc, const char *bitmap, bool readonly, bool shared, void (*close)(NBDExport *), bool writethrough, BlockBackend *on_eject_blk, Error **errp) @@ -1516,9 +1515,17 @@ NBDExport *nbd_export_new(BlockDriverState *bs, uint64_t dev_offset, AioContext *ctx; BlockBackend *blk; NBDExport *exp; + int64_t size; uint64_t perm; int ret; + size = bdrv_getlength(bs); + if (size < 0) { + error_setg_errno(errp, -size, + "Failed to determine the NBD export's length"); + return NULL; + } + exp = g_new0(NBDExport, 1); exp->common = (BlockExport) { .drv = &blk_exp_nbd, @@ -1553,8 +1560,6 @@ NBDExport *nbd_export_new(BlockDriverState *bs, uint64_t dev_offset, exp->refcount = 1; QTAILQ_INIT(&exp->clients); exp->blk = blk; - assert(dev_offset <= INT64_MAX); - exp->dev_offset = dev_offset; exp->name = g_strdup(name); assert(!desc || strlen(desc) <= NBD_MAX_STRING_SIZE); exp->description = g_strdup(desc); @@ -1569,7 +1574,7 @@ NBDExport *nbd_export_new(BlockDriverState *bs, uint64_t dev_offset, exp->nbdflags |= (NBD_FLAG_SEND_TRIM | NBD_FLAG_SEND_WRITE_ZEROES | NBD_FLAG_SEND_FAST_ZERO); } - assert(size <= INT64_MAX - dev_offset); + assert(size <= INT64_MAX); exp->size = QEMU_ALIGN_DOWN(size, BDRV_SECTOR_SIZE); if (bitmap) { @@ -1928,8 +1933,7 @@ static int coroutine_fn nbd_co_send_sparse_read(NBDClient *client, stl_be_p(&chunk.length, pnum); ret = nbd_co_send_iov(client, iov, 1, errp); } else { - ret = blk_pread(exp->blk, offset + progress + exp->dev_offset, - data + progress, pnum); + ret = blk_pread(exp->blk, offset + progress, data + progress, pnum); if (ret < 0) { error_setg_errno(errp, -ret, "reading from file failed"); break; @@ -2303,8 +2307,7 @@ static coroutine_fn int nbd_do_cmd_read(NBDClient *client, NBDRequest *request, data, request->len, errp); } - ret = blk_pread(exp->blk, request->from + exp->dev_offset, data, - request->len); + ret = blk_pread(exp->blk, request->from, data, request->len); if (ret < 0) { return nbd_send_generic_reply(client, request->handle, ret, "reading from file failed", errp); @@ -2339,7 +2342,7 @@ static coroutine_fn int nbd_do_cmd_cache(NBDClient *client, NBDRequest *request, assert(request->type == NBD_CMD_CACHE); - ret = blk_co_preadv(exp->blk, request->from + exp->dev_offset, request->len, + ret = blk_co_preadv(exp->blk, request->from, request->len, NULL, BDRV_REQ_COPY_ON_READ | BDRV_REQ_PREFETCH); return nbd_send_generic_reply(client, request->handle, ret, @@ -2370,8 +2373,7 @@ static coroutine_fn int nbd_handle_request(NBDClient *client, if (request->flags & NBD_CMD_FLAG_FUA) { flags |= BDRV_REQ_FUA; } - ret = blk_pwrite(exp->blk, request->from + exp->dev_offset, - data, request->len, flags); + ret = blk_pwrite(exp->blk, request->from, data, request->len, flags); return nbd_send_generic_reply(client, request->handle, ret, "writing to file failed", errp); @@ -2386,8 +2388,7 @@ static coroutine_fn int nbd_handle_request(NBDClient *client, if (request->flags & NBD_CMD_FLAG_FAST_ZERO) { flags |= BDRV_REQ_NO_FALLBACK; } - ret = blk_pwrite_zeroes(exp->blk, request->from + exp->dev_offset, - request->len, flags); + ret = blk_pwrite_zeroes(exp->blk, request->from, request->len, flags); return nbd_send_generic_reply(client, request->handle, ret, "writing to file failed", errp); @@ -2401,8 +2402,7 @@ static coroutine_fn int nbd_handle_request(NBDClient *client, "flush failed", errp); case NBD_CMD_TRIM: - ret = blk_co_pdiscard(exp->blk, request->from + exp->dev_offset, - request->len); + ret = blk_co_pdiscard(exp->blk, request->from, request->len); if (ret == 0 && request->flags & NBD_CMD_FLAG_FUA) { ret = blk_co_flush(exp->blk); } diff --git a/qemu-nbd.c b/qemu-nbd.c index d2657b8db5..818c3f5d46 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -523,7 +523,6 @@ int main(int argc, char **argv) const char *port = NULL; char *sockpath = NULL; char *device = NULL; - int64_t fd_size; QemuOpts *sn_opts = NULL; const char *sn_id_or_name = NULL; const char *sopt = "hVb:o:p:rsnc:dvk:e:f:tl:x:T:D:B:L"; @@ -1028,6 +1027,17 @@ int main(int argc, char **argv) } bs = blk_bs(blk); + if (dev_offset) { + QDict *raw_opts = qdict_new(); + qdict_put_str(raw_opts, "driver", "raw"); + qdict_put_str(raw_opts, "file", bs->node_name); + qdict_put_int(raw_opts, "offset", dev_offset); + bs = bdrv_open(NULL, NULL, raw_opts, flags, &error_fatal); + blk_remove_bs(blk); + blk_insert_bs(blk, bs, &error_fatal); + bdrv_unref(bs); + } + blk_set_enable_write_cache(blk, !writethrough); if (sn_opts) { @@ -1045,21 +1055,8 @@ int main(int argc, char **argv) } bs->detect_zeroes = detect_zeroes; - fd_size = blk_getlength(blk); - if (fd_size < 0) { - error_report("Failed to determine the image length: %s", - strerror(-fd_size)); - exit(EXIT_FAILURE); - } - - if (dev_offset >= fd_size) { - error_report("Offset (%" PRIu64 ") has to be smaller than the image " - "size (%" PRId64 ")", dev_offset, fd_size); - exit(EXIT_FAILURE); - } - fd_size -= dev_offset; - export = nbd_export_new(bs, dev_offset, fd_size, export_name, + export = nbd_export_new(bs, export_name, export_description, bitmap, readonly, shared > 1, nbd_export_closed, writethrough, NULL, &error_fatal); From patchwork Thu Aug 13 16:29:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11712677 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EB3FD16B1 for ; Thu, 13 Aug 2020 16:34:33 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C1939206A4 for ; Thu, 13 Aug 2020 16:34:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="W11YUwnQ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C1939206A4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:34954 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k6GBV-00020x-0J for patchwork-qemu-devel@patchwork.kernel.org; Thu, 13 Aug 2020 12:34:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55414) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k6G79-0001vK-IZ for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:30:03 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:48518 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1k6G76-0001E1-DD for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:30:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597336199; 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=E3ar3RgcXyL0pJSnGP3isZDNUlYNQKVhVvWZOsntFy4=; b=W11YUwnQkyhrByrvSGz+J0zVxVnkAP5w9e8ykic+6iGJMA5Wi+GfsOdll4qn1KDSfVQ5nh BwF1YEHpWQdy3ml3WoGerRvBNFwaNBGYDbE7bvBUZp1/+jGe95TXPBRaQyvezQvCQmelZg apeIe4bEVvUFp+CpqzyNmfeGH+o3E58= 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-136-Co6I81CsOmuSMJn2-VhMBg-1; Thu, 13 Aug 2020 12:29:57 -0400 X-MC-Unique: Co6I81CsOmuSMJn2-VhMBg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C7CE21015DBF; Thu, 13 Aug 2020 16:29:56 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-113-97.ams2.redhat.com [10.36.113.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id A7AFF5C1A3; Thu, 13 Aug 2020 16:29:55 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 07/22] block/export: Remove magic from block-export-add Date: Thu, 13 Aug 2020 18:29:20 +0200 Message-Id: <20200813162935.210070-8-kwolf@redhat.com> In-Reply-To: <20200813162935.210070-1-kwolf@redhat.com> References: <20200813162935.210070-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=205.139.110.61; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/13 12:29:49 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -40 X-Spam_score: -4.1 X-Spam_bar: ---- X-Spam_report: (-4.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, 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_H2=-1, 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, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" nbd-server-add tries to be convenient and adds two questionable features that we don't want to share in block-export-add, even for NBD exports: 1. When requesting a writable export of a read-only device, the export is silently downgraded to read-only. This should be an error in the context of block-export-add. 2. When using a BlockBackend name, unplugging the device from the guest will automatically stop the NBD server, too. This may sometimes be what you want, but it could also be very surprising. Let's keep things explicit with block-export-add. If the user wants to stop the export, they should tell us so. Move these things into the nbd-server-add QMP command handler so that they apply only there. Signed-off-by: Kevin Wolf --- include/block/nbd.h | 3 ++- block/export/export.c | 44 ++++++++++++++++++++++++++++++++++++++----- blockdev-nbd.c | 10 ++++------ nbd/server.c | 19 ++++++++++++------- qemu-nbd.c | 3 +-- 5 files changed, 58 insertions(+), 21 deletions(-) diff --git a/include/block/nbd.h b/include/block/nbd.h index 3846d2bac8..ffca3be78f 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -333,7 +333,8 @@ NBDExport *nbd_export_new(BlockDriverState *bs, const char *name, const char *desc, const char *bitmap, bool readonly, bool shared, void (*close)(NBDExport *), bool writethrough, - BlockBackend *on_eject_blk, Error **errp); + Error **errp); +void nbd_export_set_on_eject_blk(BlockExport *exp, BlockBackend *blk); void nbd_export_close(NBDExport *exp); void nbd_export_remove(NBDExport *exp, NbdServerRemoveMode mode, Error **errp); void nbd_export_get(NBDExport *exp); diff --git a/block/export/export.c b/block/export/export.c index 3d0dacb3f2..2d5f92861c 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -13,6 +13,8 @@ #include "qemu/osdep.h" +#include "block/block.h" +#include "sysemu/block-backend.h" #include "block/export.h" #include "block/nbd.h" #include "qapi/error.h" @@ -34,24 +36,56 @@ static const BlockExportDriver *blk_exp_find_driver(BlockExportType type) return NULL; } -void qmp_block_export_add(BlockExportOptions *export, Error **errp) +static BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp) { const BlockExportDriver *drv; drv = blk_exp_find_driver(export->type); if (!drv) { error_setg(errp, "No driver found for the requested export type"); - return; + return NULL; } - drv->create(export, errp); + return drv->create(export, errp); +} + +void qmp_block_export_add(BlockExportOptions *export, Error **errp) +{ + blk_exp_add(export, errp); } void qmp_nbd_server_add(BlockExportOptionsNbd *arg, Error **errp) { - BlockExportOptions export = { + BlockExport *export; + BlockDriverState *bs; + BlockBackend *on_eject_blk; + + BlockExportOptions export_opts = { .type = BLOCK_EXPORT_TYPE_NBD, .u.nbd = *arg, }; - qmp_block_export_add(&export, errp); + + /* + * nbd-server-add doesn't complain when a read-only device should be + * exported as writable, but simply downgrades it. This is an error with + * block-export-add. + */ + bs = bdrv_lookup_bs(arg->device, arg->device, NULL); + if (bs && bdrv_is_read_only(bs)) { + arg->writable = false; + } + + export = blk_exp_add(&export_opts, errp); + if (!export) { + return; + } + + /* + * nbd-server-add removes the export when the named BlockBackend used for + * @device goes away. + */ + on_eject_blk = blk_by_name(arg->device); + if (on_eject_blk) { + nbd_export_set_on_eject_blk(export, on_eject_blk); + } } diff --git a/blockdev-nbd.c b/blockdev-nbd.c index 16cda3b052..019c37c0bc 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -152,7 +152,6 @@ BlockExport *nbd_export_create(BlockExportOptions *exp_args, Error **errp) { BlockExportOptionsNbd *arg = &exp_args->u.nbd; BlockDriverState *bs = NULL; - BlockBackend *on_eject_blk; NBDExport *exp = NULL; AioContext *aio_context; @@ -182,8 +181,6 @@ BlockExport *nbd_export_create(BlockExportOptions *exp_args, Error **errp) return NULL; } - on_eject_blk = blk_by_name(arg->device); - bs = bdrv_lookup_bs(arg->device, arg->device, errp); if (!bs) { return NULL; @@ -195,13 +192,14 @@ BlockExport *nbd_export_create(BlockExportOptions *exp_args, Error **errp) if (!arg->has_writable) { arg->writable = false; } - if (bdrv_is_read_only(bs)) { - arg->writable = false; + if (bdrv_is_read_only(bs) && arg->writable) { + error_setg(errp, "Cannot export read-only node as writable"); + goto out; } exp = nbd_export_new(bs, arg->name, arg->description, arg->bitmap, !arg->writable, !arg->writable, - NULL, false, on_eject_blk, errp); + NULL, false, errp); if (!exp) { goto out; } diff --git a/nbd/server.c b/nbd/server.c index 92360d1f08..0b84fd30e2 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1506,11 +1506,22 @@ static void nbd_eject_notifier(Notifier *n, void *data) aio_context_release(aio_context); } +void nbd_export_set_on_eject_blk(BlockExport *exp, BlockBackend *blk) +{ + NBDExport *nbd_exp = container_of(exp, NBDExport, common); + assert(exp->drv == &blk_exp_nbd); + + blk_ref(blk); + nbd_exp->eject_notifier_blk = blk; + nbd_exp->eject_notifier.notify = nbd_eject_notifier; + blk_add_remove_bs_notifier(blk, &nbd_exp->eject_notifier); +} + NBDExport *nbd_export_new(BlockDriverState *bs, const char *name, const char *desc, const char *bitmap, bool readonly, bool shared, void (*close)(NBDExport *), bool writethrough, - BlockBackend *on_eject_blk, Error **errp) + Error **errp) { AioContext *ctx; BlockBackend *blk; @@ -1618,12 +1629,6 @@ NBDExport *nbd_export_new(BlockDriverState *bs, exp->ctx = ctx; blk_add_aio_context_notifier(blk, blk_aio_attached, blk_aio_detach, exp); - if (on_eject_blk) { - blk_ref(on_eject_blk); - exp->eject_notifier_blk = on_eject_blk; - exp->eject_notifier.notify = nbd_eject_notifier; - blk_add_remove_bs_notifier(on_eject_blk, &exp->eject_notifier); - } QTAILQ_INSERT_TAIL(&exports, exp, next); nbd_export_get(exp); return exp; diff --git a/qemu-nbd.c b/qemu-nbd.c index 818c3f5d46..e348d5d6d8 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -1058,8 +1058,7 @@ int main(int argc, char **argv) export = nbd_export_new(bs, export_name, export_description, bitmap, readonly, shared > 1, - nbd_export_closed, writethrough, NULL, - &error_fatal); + nbd_export_closed, writethrough, &error_fatal); if (device) { #if HAVE_NBD_DEVICE From patchwork Thu Aug 13 16:29:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11712667 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9D1A3722 for ; Thu, 13 Aug 2020 16:31:55 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 73BEB206A4 for ; Thu, 13 Aug 2020 16:31:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Ehk83Rnn" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 73BEB206A4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:49220 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k6G8w-0004mC-Jo for patchwork-qemu-devel@patchwork.kernel.org; Thu, 13 Aug 2020 12:31:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55422) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k6G7A-0001x0-7G for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:30:04 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:34131 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1k6G77-0001EE-Kz for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:30:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597336201; 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=AfqQ+rA+QU47hCv+fgERdM5S2is2RvTloiHcD5kJKzc=; b=Ehk83Rnnazl/pViWh6YZijoVamoTMtpW1lT39TQFcQ/DqZZ3XSoDjkGu1lOo5mAooAR+Rr lFPD+mu3GuXJVRycLWxOoW4gbfREgXwpSjl3x6IWRP59N+YvlhrdTa+ZUiRjP4TONf2QBk soCEUyDDFxZ5dj0FuausqLEWdPamH1E= 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-202-rtV3Yq1sMzmtJCuMQ52w5Q-1; Thu, 13 Aug 2020 12:29:59 -0400 X-MC-Unique: rtV3Yq1sMzmtJCuMQ52w5Q-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3AA991015DC0; Thu, 13 Aug 2020 16:29:58 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-113-97.ams2.redhat.com [10.36.113.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1D40F5C1BB; Thu, 13 Aug 2020 16:29:56 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 08/22] nbd: Add max-connections to nbd-server-start Date: Thu, 13 Aug 2020 18:29:21 +0200 Message-Id: <20200813162935.210070-9-kwolf@redhat.com> In-Reply-To: <20200813162935.210070-1-kwolf@redhat.com> References: <20200813162935.210070-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=205.139.110.120; envelope-from=kwolf@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/13 03:44:21 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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: , Cc: kwolf@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" This is a QMP equivalent of qemu-nbd's --share option, limiting the maximum number of clients that can attach at the same time. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz Reviewed-by: Eric Blake --- qapi/block-export.json | 10 ++++++++-- include/block/nbd.h | 3 ++- block/monitor/block-hmp-cmds.c | 2 +- blockdev-nbd.c | 33 ++++++++++++++++++++++++++------- qemu-storage-daemon.c | 4 ++-- 5 files changed, 39 insertions(+), 13 deletions(-) diff --git a/qapi/block-export.json b/qapi/block-export.json index 40369814b4..1fdc55c53a 100644 --- a/qapi/block-export.json +++ b/qapi/block-export.json @@ -14,6 +14,8 @@ # is only resolved at time of use, so can be deleted and # recreated on the fly while the NBD server is active. # If missing, it will default to denying access (since 4.0). +# @max-connections: The maximum number of connections to allow at the same +# time, 0 for unlimited. (since 5.2; default: 0) # # Keep this type consistent with the nbd-server-start arguments. The only # intended difference is using SocketAddress instead of SocketAddressLegacy. @@ -23,7 +25,8 @@ { 'struct': 'NbdServerOptions', 'data': { 'addr': 'SocketAddress', '*tls-creds': 'str', - '*tls-authz': 'str'} } + '*tls-authz': 'str', + '*max-connections': 'uint32' } } ## # @nbd-server-start: @@ -40,6 +43,8 @@ # is only resolved at time of use, so can be deleted and # recreated on the fly while the NBD server is active. # If missing, it will default to denying access (since 4.0). +# @max-connections: The maximum number of connections to allow at the same +# time, 0 for unlimited. (since 5.2; default: 0) # # Returns: error if the server is already running. # @@ -51,7 +56,8 @@ { 'command': 'nbd-server-start', 'data': { 'addr': 'SocketAddressLegacy', '*tls-creds': 'str', - '*tls-authz': 'str'} } + '*tls-authz': 'str', + '*max-connections': 'uint32' } } ## # @BlockExportOptionsNbd: diff --git a/include/block/nbd.h b/include/block/nbd.h index ffca3be78f..6fc1f05ef4 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -352,7 +352,8 @@ void nbd_client_get(NBDClient *client); void nbd_client_put(NBDClient *client); void nbd_server_start(SocketAddress *addr, const char *tls_creds, - const char *tls_authz, Error **errp); + const char *tls_authz, uint32_t max_connections, + Error **errp); void nbd_server_start_options(NbdServerOptions *arg, Error **errp); /* nbd_read diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c index 56bc83ac97..a651954e16 100644 --- a/block/monitor/block-hmp-cmds.c +++ b/block/monitor/block-hmp-cmds.c @@ -411,7 +411,7 @@ void hmp_nbd_server_start(Monitor *mon, const QDict *qdict) goto exit; } - nbd_server_start(addr, NULL, NULL, &local_err); + nbd_server_start(addr, NULL, NULL, 0, &local_err); qapi_free_SocketAddress(addr); if (local_err != NULL) { goto exit; diff --git a/blockdev-nbd.c b/blockdev-nbd.c index 019c37c0bc..28159a92b2 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -23,23 +23,41 @@ typedef struct NBDServerData { QIONetListener *listener; QCryptoTLSCreds *tlscreds; char *tlsauthz; + uint32_t max_connections; + uint32_t connections; } NBDServerData; static NBDServerData *nbd_server; +static void nbd_update_server_watch(NBDServerData *s); + static void nbd_blockdev_client_closed(NBDClient *client, bool ignored) { nbd_client_put(client); + assert(nbd_server->connections > 0); + nbd_server->connections--; + nbd_update_server_watch(nbd_server); } static void nbd_accept(QIONetListener *listener, QIOChannelSocket *cioc, gpointer opaque) { + nbd_server->connections++; + nbd_update_server_watch(nbd_server); + qio_channel_set_name(QIO_CHANNEL(cioc), "nbd-server"); nbd_client_new(cioc, nbd_server->tlscreds, nbd_server->tlsauthz, nbd_blockdev_client_closed); } +static void nbd_update_server_watch(NBDServerData *s) +{ + if (!s->max_connections || s->connections < s->max_connections) { + qio_net_listener_set_client_func(s->listener, nbd_accept, NULL, NULL); + } else { + qio_net_listener_set_client_func(s->listener, NULL, NULL, NULL); + } +} static void nbd_server_free(NBDServerData *server) { @@ -88,7 +106,8 @@ static QCryptoTLSCreds *nbd_get_tls_creds(const char *id, Error **errp) void nbd_server_start(SocketAddress *addr, const char *tls_creds, - const char *tls_authz, Error **errp) + const char *tls_authz, uint32_t max_connections, + Error **errp) { if (nbd_server) { error_setg(errp, "NBD server already running"); @@ -96,6 +115,7 @@ void nbd_server_start(SocketAddress *addr, const char *tls_creds, } nbd_server = g_new0(NBDServerData, 1); + nbd_server->max_connections = max_connections; nbd_server->listener = qio_net_listener_new(); qio_net_listener_set_name(nbd_server->listener, @@ -120,10 +140,7 @@ void nbd_server_start(SocketAddress *addr, const char *tls_creds, nbd_server->tlsauthz = g_strdup(tls_authz); - qio_net_listener_set_client_func(nbd_server->listener, - nbd_accept, - NULL, - NULL); + nbd_update_server_watch(nbd_server); return; @@ -134,17 +151,19 @@ void nbd_server_start(SocketAddress *addr, const char *tls_creds, void nbd_server_start_options(NbdServerOptions *arg, Error **errp) { - nbd_server_start(arg->addr, arg->tls_creds, arg->tls_authz, errp); + nbd_server_start(arg->addr, arg->tls_creds, arg->tls_authz, + arg->max_connections, errp); } void qmp_nbd_server_start(SocketAddressLegacy *addr, bool has_tls_creds, const char *tls_creds, bool has_tls_authz, const char *tls_authz, + bool has_max_connections, uint32_t max_connections, Error **errp) { SocketAddress *addr_flat = socket_address_flatten(addr); - nbd_server_start(addr_flat, tls_creds, tls_authz, errp); + nbd_server_start(addr_flat, tls_creds, tls_authz, max_connections, errp); qapi_free_SocketAddress(addr_flat); } diff --git a/qemu-storage-daemon.c b/qemu-storage-daemon.c index b6f678d3ab..0fcab6ed2d 100644 --- a/qemu-storage-daemon.c +++ b/qemu-storage-daemon.c @@ -101,9 +101,9 @@ static void help(void) " configure a QMP monitor\n" "\n" " --nbd-server addr.type=inet,addr.host=,addr.port=\n" -" [,tls-creds=][,tls-authz=]\n" +" [,tls-creds=][,tls-authz=][,max-connections=]\n" " --nbd-server addr.type=unix,addr.path=\n" -" [,tls-creds=][,tls-authz=]\n" +" [,tls-creds=][,tls-authz=][,max-connections=]\n" " start an NBD server for exporting block nodes\n" "\n" " --object help list object types that can be added\n" From patchwork Thu Aug 13 16:29:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11712703 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5D89A739 for ; Thu, 13 Aug 2020 16:42:26 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 32C2A20855 for ; Thu, 13 Aug 2020 16:42:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZF0zr6i4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 32C2A20855 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:44694 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k6GJ7-0000jx-FJ for patchwork-qemu-devel@patchwork.kernel.org; Thu, 13 Aug 2020 12:42:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56242) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k6G97-0005AG-38 for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:32:05 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:30877 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1k6G94-0001dz-KJ for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:32:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597336321; 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=C8SgDTwlgkg5p1J3JQ9ls3CbSfFYP8z+m2nDCnM2oXk=; b=ZF0zr6i4hBSMsfQAEpEwnXf8BJb8NQ61XlxydvVf1SfMRwbedeTarZ2naSQ5Bl/BFnELjr maoqTL5kuP46E4zdLifttsbK37Gy9ObYa7ve/pBvF5oqwVFUDQHUx+jXQqkVXTxWV1zoHR m+Qh0mTT+14KZyK34lNWRClZ4fzaPrs= 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-435-Hnwv18d_PL-Sex7cEPoggQ-1; Thu, 13 Aug 2020 12:30:00 -0400 X-MC-Unique: Hnwv18d_PL-Sex7cEPoggQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A2EC0800050; Thu, 13 Aug 2020 16:29:59 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-113-97.ams2.redhat.com [10.36.113.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8460C5C1A3; Thu, 13 Aug 2020 16:29:58 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 09/22] nbd: Add writethrough to block-export-add Date: Thu, 13 Aug 2020 18:29:22 +0200 Message-Id: <20200813162935.210070-10-kwolf@redhat.com> In-Reply-To: <20200813162935.210070-1-kwolf@redhat.com> References: <20200813162935.210070-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=205.139.110.120; envelope-from=kwolf@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/13 03:44:21 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" qemu-nbd allows use of writethrough cache modes, which mean that write requests made through NBD will cause a flush before they complete. Expose the same functionality in block-export-add. Signed-off-by: Kevin Wolf --- qapi/block-export.json | 7 ++++++- blockdev-nbd.c | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/qapi/block-export.json b/qapi/block-export.json index 1fdc55c53a..4ce163411f 100644 --- a/qapi/block-export.json +++ b/qapi/block-export.json @@ -167,10 +167,15 @@ # Describes a block export, i.e. how single node should be exported on an # external interface. # +# @writethrough: If true, caches are flushed after every write request to the +# export before completion is signalled. (since: 5.2; +# default: false) +# # Since: 4.2 ## { 'union': 'BlockExportOptions', - 'base': { 'type': 'BlockExportType' }, + 'base': { 'type': 'BlockExportType', + '*writethrough': 'bool' }, 'discriminator': 'type', 'data': { 'nbd': 'BlockExportOptionsNbd' diff --git a/blockdev-nbd.c b/blockdev-nbd.c index 28159a92b2..17417c1b6b 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -218,7 +218,7 @@ BlockExport *nbd_export_create(BlockExportOptions *exp_args, Error **errp) exp = nbd_export_new(bs, arg->name, arg->description, arg->bitmap, !arg->writable, !arg->writable, - NULL, false, errp); + NULL, exp_args->writethrough, errp); if (!exp) { goto out; } From patchwork Thu Aug 13 16:29:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11712673 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8B627722 for ; Thu, 13 Aug 2020 16:33:09 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6269B206A4 for ; Thu, 13 Aug 2020 16:33:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="gC7bt3ro" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6269B206A4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:55886 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k6GA8-0007Vb-Iq for patchwork-qemu-devel@patchwork.kernel.org; Thu, 13 Aug 2020 12:33:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55452) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k6G7C-00022V-Mn for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:30:06 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:57604 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1k6G7A-0001Gu-NR for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:30:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597336203; 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=KgmtOfPHUtpRrXWlGz7u5in3FO/VtA6SKFE+c+MqFIU=; b=gC7bt3roTzZZd6zPbFkOTzQxS2mvy8/H8KiRfV7gAbOTmCpBrxwvUbnolaRhlfHrN136Am H2yZLfkWfKuOLF5bKejn/nN/Exi1JQZVxKeXtsVth3pH+f+pqydcGoOGKWRiZ7/qWB54/e MEZeBYpbfiY4vI32kWDzHJ+iQhwYF04= 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-65-GrBkc5DNM_irM_H40jnTfw-1; Thu, 13 Aug 2020 12:30:02 -0400 X-MC-Unique: GrBkc5DNM_irM_H40jnTfw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1A56B1835870; Thu, 13 Aug 2020 16:30:01 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-113-97.ams2.redhat.com [10.36.113.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id EC3D55C1A3; Thu, 13 Aug 2020 16:29:59 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 10/22] nbd: Remove NBDExport.close callback Date: Thu, 13 Aug 2020 18:29:23 +0200 Message-Id: <20200813162935.210070-11-kwolf@redhat.com> In-Reply-To: <20200813162935.210070-1-kwolf@redhat.com> References: <20200813162935.210070-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=207.211.31.81; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/13 02:03:30 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -40 X-Spam_score: -4.1 X-Spam_bar: ---- X-Spam_report: (-4.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, 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_H2=-1, 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: , Cc: kwolf@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" The export close callback is unused by the built-in NBD server. qemu-nbd uses it only during shutdown to wait for the unrefed export to actually go away. It can just use nbd_export_close_all() instead and do without the callback. This removes the close callback from nbd_export_new() and makes both callers of it more similar. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz Reviewed-by: Eric Blake --- include/block/nbd.h | 3 +-- blockdev-nbd.c | 2 +- nbd/server.c | 9 +-------- qemu-nbd.c | 14 ++++---------- 4 files changed, 7 insertions(+), 21 deletions(-) diff --git a/include/block/nbd.h b/include/block/nbd.h index 6fc1f05ef4..50e1a46075 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -332,8 +332,7 @@ BlockExport *nbd_export_create(BlockExportOptions *exp_args, Error **errp); NBDExport *nbd_export_new(BlockDriverState *bs, const char *name, const char *desc, const char *bitmap, bool readonly, bool shared, - void (*close)(NBDExport *), bool writethrough, - Error **errp); + bool writethrough, Error **errp); void nbd_export_set_on_eject_blk(BlockExport *exp, BlockBackend *blk); void nbd_export_close(NBDExport *exp); void nbd_export_remove(NBDExport *exp, NbdServerRemoveMode mode, Error **errp); diff --git a/blockdev-nbd.c b/blockdev-nbd.c index 17417c1b6b..d5b084acc2 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -218,7 +218,7 @@ BlockExport *nbd_export_create(BlockExportOptions *exp_args, Error **errp) exp = nbd_export_new(bs, arg->name, arg->description, arg->bitmap, !arg->writable, !arg->writable, - NULL, exp_args->writethrough, errp); + exp_args->writethrough, errp); if (!exp) { goto out; } diff --git a/nbd/server.c b/nbd/server.c index 0b84fd30e2..eadc5b9804 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -84,7 +84,6 @@ struct NBDRequestData { struct NBDExport { BlockExport common; int refcount; - void (*close)(NBDExport *exp); BlockBackend *blk; char *name; @@ -1520,8 +1519,7 @@ void nbd_export_set_on_eject_blk(BlockExport *exp, BlockBackend *blk) NBDExport *nbd_export_new(BlockDriverState *bs, const char *name, const char *desc, const char *bitmap, bool readonly, bool shared, - void (*close)(NBDExport *), bool writethrough, - Error **errp) + bool writethrough, Error **errp) { AioContext *ctx; BlockBackend *blk; @@ -1625,7 +1623,6 @@ NBDExport *nbd_export_new(BlockDriverState *bs, assert(strlen(exp->export_bitmap_context) < NBD_MAX_STRING_SIZE); } - exp->close = close; exp->ctx = ctx; blk_add_aio_context_notifier(blk, blk_aio_attached, blk_aio_detach, exp); @@ -1723,10 +1720,6 @@ void nbd_export_put(NBDExport *exp) assert(exp->name == NULL); assert(exp->description == NULL); - if (exp->close) { - exp->close(exp); - } - if (exp->blk) { if (exp->eject_notifier_blk) { notifier_remove(&exp->eject_notifier); diff --git a/qemu-nbd.c b/qemu-nbd.c index e348d5d6d8..48aa8a9d46 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -70,7 +70,7 @@ static int verbose; static char *srcpath; static SocketAddress *saddr; static int persistent = 0; -static enum { RUNNING, TERMINATE, TERMINATING, TERMINATED } state; +static enum { RUNNING, TERMINATE, TERMINATED } state; static int shared = 1; static int nb_fds; static QIONetListener *server; @@ -331,12 +331,6 @@ static int nbd_can_accept(void) return state == RUNNING && nb_fds < shared; } -static void nbd_export_closed(NBDExport *export) -{ - assert(state == TERMINATING); - state = TERMINATED; -} - static void nbd_update_server_watch(void); static void nbd_client_closed(NBDClient *client, bool negotiated) @@ -1058,7 +1052,7 @@ int main(int argc, char **argv) export = nbd_export_new(bs, export_name, export_description, bitmap, readonly, shared > 1, - nbd_export_closed, writethrough, &error_fatal); + writethrough, &error_fatal); if (device) { #if HAVE_NBD_DEVICE @@ -1098,10 +1092,10 @@ int main(int argc, char **argv) do { main_loop_wait(false); if (state == TERMINATE) { - state = TERMINATING; - nbd_export_close(export); nbd_export_put(export); + nbd_export_close_all(); export = NULL; + state = TERMINATED; } } while (state != TERMINATED); From patchwork Thu Aug 13 16:29:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11712693 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DC92F739 for ; Thu, 13 Aug 2020 16:39:05 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B2AC1206A4 for ; Thu, 13 Aug 2020 16:39:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="hjMjLuwY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B2AC1206A4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:56198 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k6GFs-0002G5-US for patchwork-qemu-devel@patchwork.kernel.org; Thu, 13 Aug 2020 12:39:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55500) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k6G7I-0002E9-Gl for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:30:12 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:43448 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1k6G7G-0001Hd-Op for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:30:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597336210; 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=/gjTbZYrXoIR0MeHZ6tOs7rNuhtSlvwBUk2TO+CPIQU=; b=hjMjLuwYEd27Lxwd1Jh+siXLBXBkG9tK7jnhbgFSFIJ3CW3Hg1p+dxaQLeKnxxWAOID/TG NFeEFUOpp0Kgb/WfCt59991xAf2vA5kHZ+irx1y+t8gHylOOebhN/ABJcShi5bwnIG+ck1 vhhph1j+ogAMlyQ35e+Px2JwRj1Gwjo= 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-476-JAQyawrDPUOIBYEK57JbGA-1; Thu, 13 Aug 2020 12:30:06 -0400 X-MC-Unique: JAQyawrDPUOIBYEK57JbGA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 715AB1835865; Thu, 13 Aug 2020 16:30:05 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-113-97.ams2.redhat.com [10.36.113.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 632BE5C1BB; Thu, 13 Aug 2020 16:30:01 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 11/22] qemu-nbd: Use blk_exp_add() to create the export Date: Thu, 13 Aug 2020 18:29:24 +0200 Message-Id: <20200813162935.210070-12-kwolf@redhat.com> In-Reply-To: <20200813162935.210070-1-kwolf@redhat.com> References: <20200813162935.210070-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=205.139.110.120; envelope-from=kwolf@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/13 03:44:21 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" With this change, NBD exports are only created through the BlockExport interface any more. This allows us finally to move things from the NBD layer to the BlockExport layer if they make sense for other export types, too. blk_exp_add() returns only a weak reference, so the explicit nbd_export_put() goes away. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- include/block/export.h | 2 ++ include/block/nbd.h | 1 + block/export/export.c | 2 +- blockdev-nbd.c | 8 +++++++- qemu-nbd.c | 28 ++++++++++++++++++++++------ 5 files changed, 33 insertions(+), 8 deletions(-) diff --git a/include/block/export.h b/include/block/export.h index b1d7325403..5424bdc85d 100644 --- a/include/block/export.h +++ b/include/block/export.h @@ -29,4 +29,6 @@ struct BlockExport { extern const BlockExportDriver blk_exp_nbd; +BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp); + #endif diff --git a/include/block/nbd.h b/include/block/nbd.h index 50e1a46075..23030db3f1 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -350,6 +350,7 @@ void nbd_client_new(QIOChannelSocket *sioc, void nbd_client_get(NBDClient *client); void nbd_client_put(NBDClient *client); +void nbd_server_is_qemu_nbd(bool value); void nbd_server_start(SocketAddress *addr, const char *tls_creds, const char *tls_authz, uint32_t max_connections, Error **errp); diff --git a/block/export/export.c b/block/export/export.c index 2d5f92861c..12672228c7 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -36,7 +36,7 @@ static const BlockExportDriver *blk_exp_find_driver(BlockExportType type) return NULL; } -static BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp) +BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp) { const BlockExportDriver *drv; diff --git a/blockdev-nbd.c b/blockdev-nbd.c index d5b084acc2..8dd127af52 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -28,9 +28,15 @@ typedef struct NBDServerData { } NBDServerData; static NBDServerData *nbd_server; +static bool is_qemu_nbd; static void nbd_update_server_watch(NBDServerData *s); +void nbd_server_is_qemu_nbd(bool value) +{ + is_qemu_nbd = value; +} + static void nbd_blockdev_client_closed(NBDClient *client, bool ignored) { nbd_client_put(client); @@ -176,7 +182,7 @@ BlockExport *nbd_export_create(BlockExportOptions *exp_args, Error **errp) assert(exp_args->type == BLOCK_EXPORT_TYPE_NBD); - if (!nbd_server) { + if (!nbd_server && !is_qemu_nbd) { error_setg(errp, "NBD server not running"); return NULL; } diff --git a/qemu-nbd.c b/qemu-nbd.c index 48aa8a9d46..d967b8fcb9 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -65,7 +65,6 @@ #define MBR_SIZE 512 -static NBDExport *export; static int verbose; static char *srcpath; static SocketAddress *saddr; @@ -579,6 +578,7 @@ int main(int argc, char **argv) int old_stderr = -1; unsigned socket_activation; const char *pid_file_name = NULL; + BlockExportOptions *export_opts; /* The client thread uses SIGTERM to interrupt the server. A signal * handler ensures that "qemu-nbd -v -c" exits with a nice status code. @@ -1050,9 +1050,27 @@ int main(int argc, char **argv) bs->detect_zeroes = detect_zeroes; - export = nbd_export_new(bs, export_name, - export_description, bitmap, readonly, shared > 1, - writethrough, &error_fatal); + nbd_server_is_qemu_nbd(true); + + export_opts = g_new(BlockExportOptions, 1); + *export_opts = (BlockExportOptions) { + .type = BLOCK_EXPORT_TYPE_NBD, + .has_writethrough = true, + .writethrough = writethrough, + .u.nbd = { + .device = g_strdup(bdrv_get_node_name(bs)), + .has_name = true, + .name = g_strdup(export_name), + .has_description = !!export_description, + .description = g_strdup(export_description), + .has_writable = true, + .writable = !readonly, + .has_bitmap = !!bitmap, + .bitmap = g_strdup(bitmap), + }, + }; + blk_exp_add(export_opts, &error_fatal); + qapi_free_BlockExportOptions(export_opts); if (device) { #if HAVE_NBD_DEVICE @@ -1092,9 +1110,7 @@ int main(int argc, char **argv) do { main_loop_wait(false); if (state == TERMINATE) { - nbd_export_put(export); nbd_export_close_all(); - export = NULL; state = TERMINATED; } } while (state != TERMINATED); From patchwork Thu Aug 13 16:29:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11712701 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 84387109B for ; Thu, 13 Aug 2020 16:41:53 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5819520855 for ; Thu, 13 Aug 2020 16:41:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="OQTIR83k" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5819520855 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:43338 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k6GIa-00008n-IL for patchwork-qemu-devel@patchwork.kernel.org; Thu, 13 Aug 2020 12:41:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56228) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k6G95-00057f-SL for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:32:03 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:41232 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1k6G94-0001du-98 for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:32:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597336321; 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=0kP3JW4cQeIixcwieAnD96+eq8w2AIytt1Mm9Uer6yc=; b=OQTIR83kY7KDOzUKq1BqWa68vp+EEfasYAeY44s05fq+lPVPj1QrDhmvoKu7zZmCSvD5kA JP2bsT8dmTlpSK6U0KMfS6XhomlgIN4+c+W91jDuwi4eLG/+RR2hkC6SgnH969quMF+Jmn 5PUHKVSzgNr3rAG0hCC0ItoJ/6lNAJo= 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-529-Rd_s3Bp8PomMAHaUfz7YjQ-1; Thu, 13 Aug 2020 12:30:10 -0400 X-MC-Unique: Rd_s3Bp8PomMAHaUfz7YjQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0874C1DDE9; Thu, 13 Aug 2020 16:30:09 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-113-97.ams2.redhat.com [10.36.113.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id BD7CF5C1C2; Thu, 13 Aug 2020 16:30:05 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 12/22] nbd/server: Simplify export shutdown Date: Thu, 13 Aug 2020 18:29:25 +0200 Message-Id: <20200813162935.210070-13-kwolf@redhat.com> In-Reply-To: <20200813162935.210070-1-kwolf@redhat.com> References: <20200813162935.210070-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0.0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=207.211.31.81; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/13 02:03:30 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -40 X-Spam_score: -4.1 X-Spam_bar: ---- X-Spam_report: (-4.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, 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_H2=-1, 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, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Closing export is somewhat convoluted because nbd_export_close() and nbd_export_put() call each other and the ways they actually end up being nested is not necessarily obvious. However, it is not really necessary to call nbd_export_close() from nbd_export_put() when putting the last reference because it only does three things: 1. Close all clients. We're going to refcount 0 and all clients hold a reference, so we know there is no active client any more. 2. Close the user reference (represented by exp->name being non-NULL). The same argument applies: If the export were still named, we would still have a reference. 3. Freeing exp->description. This is really cleanup work to be done when the export is finally freed. There is no reason to already clear it while clients are still in the process of shutting down. So after moving the cleanup of exp->description, the code can be simplified so that only nbd_export_close() calls nbd_export_put(), but never the other way around. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz Reviewed-by: Eric Blake --- nbd/server.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index eadc5b9804..4c594e6558 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1678,8 +1678,6 @@ void nbd_export_close(NBDExport *exp) QTAILQ_REMOVE(&exports, exp, next); QTAILQ_INSERT_TAIL(&closed_exports, exp, next); } - g_free(exp->description); - exp->description = NULL; nbd_export_put(exp); } @@ -1706,19 +1704,12 @@ void nbd_export_get(NBDExport *exp) void nbd_export_put(NBDExport *exp) { assert(exp->refcount > 0); - if (exp->refcount == 1) { - nbd_export_close(exp); - } - - /* nbd_export_close() may theoretically reduce refcount to 0. It may happen - * if someone calls nbd_export_put() on named export not through - * nbd_export_set_name() when refcount is 1. So, let's assert that - * it is > 0. - */ - assert(exp->refcount > 0); if (--exp->refcount == 0) { assert(exp->name == NULL); - assert(exp->description == NULL); + assert(QTAILQ_EMPTY(&exp->clients)); + + g_free(exp->description); + exp->description = NULL; if (exp->blk) { if (exp->eject_notifier_blk) { From patchwork Thu Aug 13 16:29:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11712675 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ECDEE16B1 for ; Thu, 13 Aug 2020 16:33:52 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C0451206A4 for ; Thu, 13 Aug 2020 16:33:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EQvZJ2rZ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C0451206A4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:59182 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k6GAq-0000Od-0Z for patchwork-qemu-devel@patchwork.kernel.org; Thu, 13 Aug 2020 12:33:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55578) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k6G7R-0002UL-73 for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:30:21 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:21028 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1k6G7O-0001KT-S5 for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:30:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597336218; 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=Whh0GMguYYR2iSJ9DCBI9aUiaI5Mf2N4woVzcRw4FBE=; b=EQvZJ2rZQS2RbDSkBHhjHL2h+Apkyu90sSkzi6FltKnEiFNpkmczUOTzhJnmrc4TYtJnnM DimrD/S4PfBX+3LLsJ6ILhfe3uCdXB1dcBIM8mTWvTiYlh4Ie6oICf1CnyoVjHRsSwgynq aqdEkjiWyGjSqS3rgOeXCn14QUqysPE= 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-468-KD4TaV2oN2uvoboU6uq3Hg-1; Thu, 13 Aug 2020 12:30:16 -0400 X-MC-Unique: KD4TaV2oN2uvoboU6uq3Hg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4911410066FA; Thu, 13 Aug 2020 16:30:15 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-113-97.ams2.redhat.com [10.36.113.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 514025C1A3; Thu, 13 Aug 2020 16:30:09 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 13/22] block/export: Move refcount from NBDExport to BlockExport Date: Thu, 13 Aug 2020 18:29:26 +0200 Message-Id: <20200813162935.210070-14-kwolf@redhat.com> In-Reply-To: <20200813162935.210070-1-kwolf@redhat.com> References: <20200813162935.210070-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=205.139.110.61; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/13 12:29:49 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -40 X-Spam_score: -4.1 X-Spam_bar: ---- X-Spam_report: (-4.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, 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_H2=-1, 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: , Cc: kwolf@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Having a refcount makes sense for all types of block exports. It is also a prerequisite for keeping a list of all exports at the BlockExport level. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- include/block/export.h | 10 ++++++ include/block/nbd.h | 2 -- block/export/export.c | 14 ++++++++ blockdev-nbd.c | 2 +- nbd/server.c | 72 +++++++++++++++++++----------------------- 5 files changed, 58 insertions(+), 42 deletions(-) diff --git a/include/block/export.h b/include/block/export.h index 5424bdc85d..f44290a4a2 100644 --- a/include/block/export.h +++ b/include/block/export.h @@ -21,14 +21,24 @@ typedef struct BlockExport BlockExport; typedef struct BlockExportDriver { BlockExportType type; BlockExport *(*create)(BlockExportOptions *, Error **); + void (*delete)(BlockExport *); } BlockExportDriver; struct BlockExport { const BlockExportDriver *drv; + + /* + * Reference count for this block export. This includes strong references + * both from the owner (qemu-nbd or the monitor) and clients connected to + * the export. + */ + int refcount; }; extern const BlockExportDriver blk_exp_nbd; BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp); +void blk_exp_ref(BlockExport *exp); +void blk_exp_unref(BlockExport *exp); #endif diff --git a/include/block/nbd.h b/include/block/nbd.h index 23030db3f1..af8509ab70 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -336,8 +336,6 @@ NBDExport *nbd_export_new(BlockDriverState *bs, void nbd_export_set_on_eject_blk(BlockExport *exp, BlockBackend *blk); void nbd_export_close(NBDExport *exp); void nbd_export_remove(NBDExport *exp, NbdServerRemoveMode mode, Error **errp); -void nbd_export_get(NBDExport *exp); -void nbd_export_put(NBDExport *exp); AioContext *nbd_export_aio_context(NBDExport *exp); NBDExport *nbd_export_find(const char *name); diff --git a/block/export/export.c b/block/export/export.c index 12672228c7..1d5de564c7 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -49,6 +49,20 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp) return drv->create(export, errp); } +void blk_exp_ref(BlockExport *exp) +{ + assert(exp->refcount > 0); + exp->refcount++; +} + +void blk_exp_unref(BlockExport *exp) +{ + assert(exp->refcount > 0); + if (--exp->refcount == 0) { + exp->drv->delete(exp); + } +} + void qmp_block_export_add(BlockExportOptions *export, Error **errp) { blk_exp_add(export, errp); diff --git a/blockdev-nbd.c b/blockdev-nbd.c index 8dd127af52..a8b7b785e7 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -232,7 +232,7 @@ BlockExport *nbd_export_create(BlockExportOptions *exp_args, Error **errp) /* The list of named exports has a strong reference to this export now and * our only way of accessing it is through nbd_export_find(), so we can drop * the strong reference that is @exp. */ - nbd_export_put(exp); + blk_exp_unref((BlockExport*) exp); out: aio_context_release(aio_context); diff --git a/nbd/server.c b/nbd/server.c index 4c594e6558..2bf30bb731 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -83,7 +83,6 @@ struct NBDRequestData { struct NBDExport { BlockExport common; - int refcount; BlockBackend *blk; char *name; @@ -499,7 +498,7 @@ static int nbd_negotiate_handle_export_name(NBDClient *client, bool no_zeroes, } QTAILQ_INSERT_TAIL(&client->exp->clients, client, next); - nbd_export_get(client->exp); + blk_exp_ref(&client->exp->common); nbd_check_meta_export(client); return 0; @@ -707,7 +706,7 @@ static int nbd_negotiate_handle_info(NBDClient *client, Error **errp) client->exp = exp; client->check_align = check_align; QTAILQ_INSERT_TAIL(&client->exp->clients, client, next); - nbd_export_get(client->exp); + blk_exp_ref(&client->exp->common); nbd_check_meta_export(client); rc = 1; } @@ -1406,7 +1405,7 @@ void nbd_client_put(NBDClient *client) g_free(client->tlsauthz); if (client->exp) { QTAILQ_REMOVE(&client->exp->clients, client, next); - nbd_export_put(client->exp); + blk_exp_unref(&client->exp->common); } g_free(client); } @@ -1537,7 +1536,8 @@ NBDExport *nbd_export_new(BlockDriverState *bs, exp = g_new0(NBDExport, 1); exp->common = (BlockExport) { - .drv = &blk_exp_nbd, + .drv = &blk_exp_nbd, + .refcount = 1, }; /* @@ -1566,7 +1566,6 @@ NBDExport *nbd_export_new(BlockDriverState *bs, blk_set_enable_write_cache(blk, !writethrough); blk_set_allow_aio_context_change(blk, true); - exp->refcount = 1; QTAILQ_INIT(&exp->clients); exp->blk = blk; exp->name = g_strdup(name); @@ -1626,8 +1625,9 @@ NBDExport *nbd_export_new(BlockDriverState *bs, exp->ctx = ctx; blk_add_aio_context_notifier(blk, blk_aio_attached, blk_aio_detach, exp); + blk_exp_ref(&exp->common); QTAILQ_INSERT_TAIL(&exports, exp, next); - nbd_export_get(exp); + return exp; fail: @@ -1660,7 +1660,7 @@ void nbd_export_close(NBDExport *exp) { NBDClient *client, *next; - nbd_export_get(exp); + blk_exp_ref(&exp->common); /* * TODO: Should we expand QMP NbdServerRemoveNode enum to allow a * close mode that stops advertising the export to new clients but @@ -1672,13 +1672,13 @@ void nbd_export_close(NBDExport *exp) client_close(client, true); } if (exp->name) { - nbd_export_put(exp); + blk_exp_unref(&exp->common); g_free(exp->name); exp->name = NULL; QTAILQ_REMOVE(&exports, exp, next); QTAILQ_INSERT_TAIL(&closed_exports, exp, next); } - nbd_export_put(exp); + blk_exp_unref(&exp->common); } void nbd_export_remove(NBDExport *exp, NbdServerRemoveMode mode, Error **errp) @@ -1695,47 +1695,41 @@ void nbd_export_remove(NBDExport *exp, NbdServerRemoveMode mode, Error **errp) error_append_hint(errp, "Use mode='hard' to force client disconnect\n"); } -void nbd_export_get(NBDExport *exp) -{ - assert(exp->refcount > 0); - exp->refcount++; -} - -void nbd_export_put(NBDExport *exp) +static void nbd_export_delete(BlockExport *blk_exp) { - assert(exp->refcount > 0); - if (--exp->refcount == 0) { - assert(exp->name == NULL); - assert(QTAILQ_EMPTY(&exp->clients)); + NBDExport *exp = container_of(blk_exp, NBDExport, common); - g_free(exp->description); - exp->description = NULL; + assert(exp->name == NULL); + assert(QTAILQ_EMPTY(&exp->clients)); - if (exp->blk) { - if (exp->eject_notifier_blk) { - notifier_remove(&exp->eject_notifier); - blk_unref(exp->eject_notifier_blk); - } - blk_remove_aio_context_notifier(exp->blk, blk_aio_attached, - blk_aio_detach, exp); - blk_unref(exp->blk); - exp->blk = NULL; - } + g_free(exp->description); + exp->description = NULL; - if (exp->export_bitmap) { - bdrv_dirty_bitmap_set_busy(exp->export_bitmap, false); - g_free(exp->export_bitmap_context); + if (exp->blk) { + if (exp->eject_notifier_blk) { + notifier_remove(&exp->eject_notifier); + blk_unref(exp->eject_notifier_blk); } + blk_remove_aio_context_notifier(exp->blk, blk_aio_attached, + blk_aio_detach, exp); + blk_unref(exp->blk); + exp->blk = NULL; + } - QTAILQ_REMOVE(&closed_exports, exp, next); - g_free(exp); - aio_wait_kick(); + if (exp->export_bitmap) { + bdrv_dirty_bitmap_set_busy(exp->export_bitmap, false); + g_free(exp->export_bitmap_context); } + + QTAILQ_REMOVE(&closed_exports, exp, next); + g_free(exp); + aio_wait_kick(); } const BlockExportDriver blk_exp_nbd = { .type = BLOCK_EXPORT_TYPE_NBD, .create = nbd_export_create, + .delete = nbd_export_delete, }; void nbd_export_close_all(void) From patchwork Thu Aug 13 16:29:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11712681 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 98B5A16B1 for ; Thu, 13 Aug 2020 16:34:56 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6EEEB206A4 for ; Thu, 13 Aug 2020 16:34:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TE0j4/NU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6EEEB206A4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:37336 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k6GBr-0002xk-OE for patchwork-qemu-devel@patchwork.kernel.org; Thu, 13 Aug 2020 12:34:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55630) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k6G7T-0002Xl-6D for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:30:23 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:60727 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1k6G7R-0001N9-3k for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:30:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597336220; 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=N5n33koo/nU4AJfebC0/VU2gJKoJYZDYyejA0Hlgalo=; b=TE0j4/NUnOxk0W0m2JKI5+q+osd5DBlQREGduf4+xwLIGZQS0vbwleAMQ0ljae2g0n3mx4 KkWCsAq+0hqPnA8Gjs2WIh9VzTBm0IZ+aZuQfoV0+SRYvbIKGPAaktZND2RNIeYBM6muaw vInaXOEtsR3DA6bOYIh6uyFORLYlzOc= 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-488-4vHalRXDMmG3pZA2aZ8WEQ-1; Thu, 13 Aug 2020 12:30:17 -0400 X-MC-Unique: 4vHalRXDMmG3pZA2aZ8WEQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B6A481014DEC; Thu, 13 Aug 2020 16:30:16 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-113-97.ams2.redhat.com [10.36.113.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 933365C1A3; Thu, 13 Aug 2020 16:30:15 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 14/22] block/export: Move AioContext from NBDExport to BlockExport Date: Thu, 13 Aug 2020 18:29:27 +0200 Message-Id: <20200813162935.210070-15-kwolf@redhat.com> In-Reply-To: <20200813162935.210070-1-kwolf@redhat.com> References: <20200813162935.210070-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=205.139.110.120; envelope-from=kwolf@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/13 03:44:21 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- include/block/export.h | 6 ++++++ nbd/server.c | 26 +++++++++++++------------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/include/block/export.h b/include/block/export.h index f44290a4a2..5459f79469 100644 --- a/include/block/export.h +++ b/include/block/export.h @@ -33,6 +33,12 @@ struct BlockExport { * the export. */ int refcount; + + /* + * The AioContex whose lock needs to be held while calling + * BlockExportDriver callbacks. + */ + AioContext *ctx; }; extern const BlockExportDriver blk_exp_nbd; diff --git a/nbd/server.c b/nbd/server.c index 2bf30bb731..b735a68429 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -92,8 +92,6 @@ struct NBDExport { QTAILQ_HEAD(, NBDClient) clients; QTAILQ_ENTRY(NBDExport) next; - AioContext *ctx; - BlockBackend *eject_notifier_blk; Notifier eject_notifier; @@ -1333,8 +1331,8 @@ static coroutine_fn int nbd_negotiate(NBDClient *client, Error **errp) } /* Attach the channel to the same AioContext as the export */ - if (client->exp && client->exp->ctx) { - qio_channel_attach_aio_context(client->ioc, client->exp->ctx); + if (client->exp && client->exp->common.ctx) { + qio_channel_attach_aio_context(client->ioc, client->exp->common.ctx); } assert(!client->optlen); @@ -1466,7 +1464,7 @@ static void blk_aio_attached(AioContext *ctx, void *opaque) trace_nbd_blk_aio_attached(exp->name, ctx); - exp->ctx = ctx; + exp->common.ctx = ctx; QTAILQ_FOREACH(client, &exp->clients, next) { qio_channel_attach_aio_context(client->ioc, ctx); @@ -1484,13 +1482,13 @@ static void blk_aio_detach(void *opaque) NBDExport *exp = opaque; NBDClient *client; - trace_nbd_blk_aio_detach(exp->name, exp->ctx); + trace_nbd_blk_aio_detach(exp->name, exp->common.ctx); QTAILQ_FOREACH(client, &exp->clients, next) { qio_channel_detach_aio_context(client->ioc); } - exp->ctx = NULL; + exp->common.ctx = NULL; } static void nbd_eject_notifier(Notifier *n, void *data) @@ -1498,7 +1496,7 @@ static void nbd_eject_notifier(Notifier *n, void *data) NBDExport *exp = container_of(n, NBDExport, eject_notifier); AioContext *aio_context; - aio_context = exp->ctx; + aio_context = exp->common.ctx; aio_context_acquire(aio_context); nbd_export_close(exp); aio_context_release(aio_context); @@ -1534,10 +1532,13 @@ NBDExport *nbd_export_new(BlockDriverState *bs, return NULL; } + ctx = bdrv_get_aio_context(bs); + exp = g_new0(NBDExport, 1); exp->common = (BlockExport) { .drv = &blk_exp_nbd, .refcount = 1, + .ctx = ctx, }; /* @@ -1547,7 +1548,7 @@ NBDExport *nbd_export_new(BlockDriverState *bs, * ctx was acquired in the caller. */ assert(name && strlen(name) <= NBD_MAX_STRING_SIZE); - ctx = bdrv_get_aio_context(bs); + bdrv_invalidate_cache(bs, NULL); /* Don't allow resize while the NBD server is running, otherwise we don't @@ -1622,7 +1623,6 @@ NBDExport *nbd_export_new(BlockDriverState *bs, assert(strlen(exp->export_bitmap_context) < NBD_MAX_STRING_SIZE); } - exp->ctx = ctx; blk_add_aio_context_notifier(blk, blk_aio_attached, blk_aio_detach, exp); blk_exp_ref(&exp->common); @@ -1653,7 +1653,7 @@ NBDExport *nbd_export_find(const char *name) AioContext * nbd_export_aio_context(NBDExport *exp) { - return exp->ctx; + return exp->common.ctx; } void nbd_export_close(NBDExport *exp) @@ -1738,7 +1738,7 @@ void nbd_export_close_all(void) AioContext *aio_context; QTAILQ_FOREACH_SAFE(exp, &exports, next, next) { - aio_context = exp->ctx; + aio_context = exp->common.ctx; aio_context_acquire(aio_context); nbd_export_close(exp); aio_context_release(aio_context); @@ -2519,7 +2519,7 @@ static void nbd_client_receive_next_request(NBDClient *client) if (!client->recv_coroutine && client->nb_requests < MAX_NBD_REQUESTS) { nbd_client_get(client); client->recv_coroutine = qemu_coroutine_create(nbd_trip, client); - aio_co_schedule(client->exp->ctx, client->recv_coroutine); + aio_co_schedule(client->exp->common.ctx, client->recv_coroutine); } } From patchwork Thu Aug 13 16:29:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11712683 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 33A691744 for ; Thu, 13 Aug 2020 16:35:20 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0A1FE206A4 for ; Thu, 13 Aug 2020 16:35:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="BWOhzEdd" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0A1FE206A4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:39454 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k6GCF-0003qX-77 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 13 Aug 2020 12:35:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55662) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k6G7U-0002aP-Dr for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:30:24 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:40683 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1k6G7R-0001Nl-Kd for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:30:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597336220; 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=q0lAlwo7ZayN2MMSO99xG+h7JK21Naz46hLLYxuJFGc=; b=BWOhzEddfm0FQDwLBDfkXOcQWvTAIpuc+nXHxhtHeX6hNQsbX91qWEipssV6/mmQtHb7Hj 4E115StGurQJWy3SJDQf+iqNXEGVtBbXXhE1x2RkY7l58PUdT1dr1qljiphiKyIi7XluUy HplKVYCTmMP7NJDt48EdccUjQC9Toy0= 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-42-O6TNwfvMM1OeMae9KsW_YA-1; Thu, 13 Aug 2020 12:30:19 -0400 X-MC-Unique: O6TNwfvMM1OeMae9KsW_YA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2FAA2802B4C; Thu, 13 Aug 2020 16:30:18 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-113-97.ams2.redhat.com [10.36.113.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0A7615C1A3; Thu, 13 Aug 2020 16:30:16 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 15/22] block/export: Move device to BlockExportOptions Date: Thu, 13 Aug 2020 18:29:28 +0200 Message-Id: <20200813162935.210070-16-kwolf@redhat.com> In-Reply-To: <20200813162935.210070-1-kwolf@redhat.com> References: <20200813162935.210070-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=205.139.110.120; envelope-from=kwolf@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/13 03:44:21 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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: , Cc: kwolf@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Every block export needs a block node to export, so move the 'device' option from BlockExportOptionsNbd to BlockExportOptions. To maintain compatibility in nbd-server-add, BlockExportOptionsNbd needs to be wrapped by a new type NbdServerAddOptions that adds 'device' back because nbd-server-add doesn't use the BlockExportOptions base type. Signed-off-by: Kevin Wolf --- qapi/block-export.json | 27 +++++++++++++++++++++------ block/export/export.c | 26 ++++++++++++++++++++------ block/monitor/block-hmp-cmds.c | 6 +++--- blockdev-nbd.c | 4 ++-- qemu-nbd.c | 2 +- 5 files changed, 47 insertions(+), 18 deletions(-) diff --git a/qapi/block-export.json b/qapi/block-export.json index 4ce163411f..d68f3bf87e 100644 --- a/qapi/block-export.json +++ b/qapi/block-export.json @@ -62,9 +62,8 @@ ## # @BlockExportOptionsNbd: # -# An NBD block export. -# -# @device: The device name or node name of the node to be exported +# An NBD block export (options shared between nbd-server-add and the NBD branch +# of block-export-add). # # @name: Export name. If unspecified, the @device parameter is used as the # export name. (Since 2.12) @@ -82,8 +81,21 @@ # Since: 5.0 ## { 'struct': 'BlockExportOptionsNbd', - 'data': {'device': 'str', '*name': 'str', '*description': 'str', - '*writable': 'bool', '*bitmap': 'str' } } + 'data': { '*name': 'str', '*description': 'str', + '*writable': 'bool', '*bitmap': 'str' } } + +## +# @NbdServerAddOptions: +# +# An NBD block export. +# +# @device: The device name or node name of the node to be exported +# +# Since: 5.0 +## +{ 'struct': 'NbdServerAddOptions', + 'base': 'BlockExportOptionsNbd', + 'data': { 'device': 'str' } } ## # @nbd-server-add: @@ -96,7 +108,7 @@ # Since: 1.3.0 ## { 'command': 'nbd-server-add', - 'data': 'BlockExportOptionsNbd', 'boxed': true } + 'data': 'NbdServerAddOptions', 'boxed': true } ## # @NbdServerRemoveMode: @@ -167,6 +179,8 @@ # Describes a block export, i.e. how single node should be exported on an # external interface. # +# @device: The device name or node name of the node to be exported +# # @writethrough: If true, caches are flushed after every write request to the # export before completion is signalled. (since: 5.2; # default: false) @@ -175,6 +189,7 @@ ## { 'union': 'BlockExportOptions', 'base': { 'type': 'BlockExportType', + 'device': 'str', '*writethrough': 'bool' }, 'discriminator': 'type', 'data': { diff --git a/block/export/export.c b/block/export/export.c index 1d5de564c7..ef86bf892b 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -68,15 +68,26 @@ void qmp_block_export_add(BlockExportOptions *export, Error **errp) blk_exp_add(export, errp); } -void qmp_nbd_server_add(BlockExportOptionsNbd *arg, Error **errp) +void qmp_nbd_server_add(NbdServerAddOptions *arg, Error **errp) { BlockExport *export; BlockDriverState *bs; BlockBackend *on_eject_blk; - BlockExportOptions export_opts = { - .type = BLOCK_EXPORT_TYPE_NBD, - .u.nbd = *arg, + BlockExportOptions *export_opts = g_new(BlockExportOptions, 1); + *export_opts = (BlockExportOptions) { + .type = BLOCK_EXPORT_TYPE_NBD, + .device = g_strdup(arg->device), + .u.nbd = { + .has_name = arg->has_name, + .name = g_strdup(arg->name), + .has_description = arg->has_description, + .description = g_strdup(arg->description), + .has_writable = arg->has_writable, + .writable = arg->writable, + .has_bitmap = arg->has_bitmap, + .bitmap = g_strdup(arg->bitmap), + }, }; /* @@ -89,9 +100,9 @@ void qmp_nbd_server_add(BlockExportOptionsNbd *arg, Error **errp) arg->writable = false; } - export = blk_exp_add(&export_opts, errp); + export = blk_exp_add(export_opts, errp); if (!export) { - return; + goto fail; } /* @@ -102,4 +113,7 @@ void qmp_nbd_server_add(BlockExportOptionsNbd *arg, Error **errp) if (on_eject_blk) { nbd_export_set_on_eject_blk(export, on_eject_blk); } + +fail: + qapi_free_BlockExportOptions(export_opts); } diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c index a651954e16..6c823234a9 100644 --- a/block/monitor/block-hmp-cmds.c +++ b/block/monitor/block-hmp-cmds.c @@ -398,7 +398,7 @@ void hmp_nbd_server_start(Monitor *mon, const QDict *qdict) Error *local_err = NULL; BlockInfoList *block_list, *info; SocketAddress *addr; - BlockExportOptionsNbd export; + NbdServerAddOptions export; if (writable && !all) { error_setg(&local_err, "-w only valid together with -a"); @@ -431,7 +431,7 @@ void hmp_nbd_server_start(Monitor *mon, const QDict *qdict) continue; } - export = (BlockExportOptionsNbd) { + export = (NbdServerAddOptions) { .device = info->value->device, .has_writable = true, .writable = writable, @@ -458,7 +458,7 @@ void hmp_nbd_server_add(Monitor *mon, const QDict *qdict) bool writable = qdict_get_try_bool(qdict, "writable", false); Error *local_err = NULL; - BlockExportOptionsNbd export = { + NbdServerAddOptions export = { .device = (char *) device, .has_name = !!name, .name = (char *) name, diff --git a/blockdev-nbd.c b/blockdev-nbd.c index a8b7b785e7..5e97975c80 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -188,7 +188,7 @@ BlockExport *nbd_export_create(BlockExportOptions *exp_args, Error **errp) } if (!arg->has_name) { - arg->name = arg->device; + arg->name = exp_args->device; } if (strlen(arg->name) > NBD_MAX_STRING_SIZE) { @@ -206,7 +206,7 @@ BlockExport *nbd_export_create(BlockExportOptions *exp_args, Error **errp) return NULL; } - bs = bdrv_lookup_bs(arg->device, arg->device, errp); + bs = bdrv_lookup_bs(exp_args->device, exp_args->device, errp); if (!bs) { return NULL; } diff --git a/qemu-nbd.c b/qemu-nbd.c index d967b8fcb9..f31868708c 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -1055,10 +1055,10 @@ int main(int argc, char **argv) export_opts = g_new(BlockExportOptions, 1); *export_opts = (BlockExportOptions) { .type = BLOCK_EXPORT_TYPE_NBD, + .device = g_strdup(bdrv_get_node_name(bs)), .has_writethrough = true, .writethrough = writethrough, .u.nbd = { - .device = g_strdup(bdrv_get_node_name(bs)), .has_name = true, .name = g_strdup(export_name), .has_description = !!export_description, From patchwork Thu Aug 13 16:29:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11712687 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 367441744 for ; Thu, 13 Aug 2020 16:36:24 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0CE1920675 for ; Thu, 13 Aug 2020 16:36:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="UcW9uS5H" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0CE1920675 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:45486 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k6GDH-0006LP-89 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 13 Aug 2020 12:36:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55684) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k6G7V-0002cg-Jd for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:30:25 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:52262 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1k6G7T-0001OJ-1u for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:30:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597336222; 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=kEGx+KPcTlaXBRNwmivDGLy9B4IdsJsvz0H5MbS0GGI=; b=UcW9uS5HaTVKyytB4PTsIwFIt4gUA9E7O6IWBKWqoOt31W3M+iXmB8fbwAtyxMAVmaTZTR tyCm7OZnuTDF/9cqIl16HDmCEr8oEFzuQVJpzyPrS/GNKCAk+BX8ouBlObLTgc4LenLhQQ YoJj1IXHyxI/MFqXs5N58/5eMrlTEH4= 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-147-4QujbiJUM3akIKyn0-gHBw-1; Thu, 13 Aug 2020 12:30:20 -0400 X-MC-Unique: 4QujbiJUM3akIKyn0-gHBw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9AB761005504; Thu, 13 Aug 2020 16:30:19 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-113-97.ams2.redhat.com [10.36.113.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 79EB85C1A3; Thu, 13 Aug 2020 16:30:18 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 16/22] block/export: Allocate BlockExport in blk_exp_add() Date: Thu, 13 Aug 2020 18:29:29 +0200 Message-Id: <20200813162935.210070-17-kwolf@redhat.com> In-Reply-To: <20200813162935.210070-1-kwolf@redhat.com> References: <20200813162935.210070-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=207.211.31.120; envelope-from=kwolf@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/13 03:45:42 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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: , Cc: kwolf@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Instead of letting the driver allocate and return the BlockExport object, allocate it already in blk_exp_add() and pass it. This allows us to initialise the generic part before calling into the driver so that the driver can just use these values instead of having to parse the options a second time. For symmetry, move freeing the BlockExport to blk_exp_unref(). Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- include/block/export.h | 3 ++- include/block/nbd.h | 11 ++++++----- block/export/export.c | 17 ++++++++++++++++- blockdev-nbd.c | 24 +++++++++++++----------- nbd/server.c | 30 +++++++++++++----------------- 5 files changed, 50 insertions(+), 35 deletions(-) diff --git a/include/block/export.h b/include/block/export.h index 5459f79469..597fc58245 100644 --- a/include/block/export.h +++ b/include/block/export.h @@ -20,7 +20,8 @@ typedef struct BlockExport BlockExport; typedef struct BlockExportDriver { BlockExportType type; - BlockExport *(*create)(BlockExportOptions *, Error **); + size_t instance_size; + int (*create)(BlockExport *, BlockExportOptions *, Error **); void (*delete)(BlockExport *); } BlockExportDriver; diff --git a/include/block/nbd.h b/include/block/nbd.h index af8509ab70..602536feb2 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -328,11 +328,12 @@ int nbd_errno_to_system_errno(int err); typedef struct NBDExport NBDExport; typedef struct NBDClient NBDClient; -BlockExport *nbd_export_create(BlockExportOptions *exp_args, Error **errp); -NBDExport *nbd_export_new(BlockDriverState *bs, - const char *name, const char *desc, - const char *bitmap, bool readonly, bool shared, - bool writethrough, Error **errp); +int nbd_export_create(BlockExport *exp, BlockExportOptions *exp_args, + Error **errp); +int nbd_export_new(BlockExport *blk_exp, BlockDriverState *bs, + const char *name, const char *desc, + const char *bitmap, bool readonly, bool shared, + bool writethrough, Error **errp); void nbd_export_set_on_eject_blk(BlockExport *exp, BlockBackend *blk); void nbd_export_close(NBDExport *exp); void nbd_export_remove(NBDExport *exp, NbdServerRemoveMode mode, Error **errp); diff --git a/block/export/export.c b/block/export/export.c index ef86bf892b..9de108cbc1 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -39,6 +39,8 @@ static const BlockExportDriver *blk_exp_find_driver(BlockExportType type) BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp) { const BlockExportDriver *drv; + BlockExport *exp; + int ret; drv = blk_exp_find_driver(export->type); if (!drv) { @@ -46,7 +48,19 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp) return NULL; } - return drv->create(export, errp); + exp = g_malloc0(drv->instance_size); + *exp = (BlockExport) { + .drv = &blk_exp_nbd, + .refcount = 1, + }; + + ret = drv->create(exp, export, errp); + if (ret < 0) { + g_free(exp); + return NULL; + } + + return exp; } void blk_exp_ref(BlockExport *exp) @@ -60,6 +74,7 @@ void blk_exp_unref(BlockExport *exp) assert(exp->refcount > 0); if (--exp->refcount == 0) { exp->drv->delete(exp); + g_free(exp); } } diff --git a/blockdev-nbd.c b/blockdev-nbd.c index 5e97975c80..f97deba424 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -173,18 +173,19 @@ void qmp_nbd_server_start(SocketAddressLegacy *addr, qapi_free_SocketAddress(addr_flat); } -BlockExport *nbd_export_create(BlockExportOptions *exp_args, Error **errp) +int nbd_export_create(BlockExport *exp, BlockExportOptions *exp_args, + Error **errp) { BlockExportOptionsNbd *arg = &exp_args->u.nbd; BlockDriverState *bs = NULL; - NBDExport *exp = NULL; AioContext *aio_context; + int ret; assert(exp_args->type == BLOCK_EXPORT_TYPE_NBD); if (!nbd_server && !is_qemu_nbd) { error_setg(errp, "NBD server not running"); - return NULL; + return -EINVAL; } if (!arg->has_name) { @@ -193,22 +194,22 @@ BlockExport *nbd_export_create(BlockExportOptions *exp_args, Error **errp) if (strlen(arg->name) > NBD_MAX_STRING_SIZE) { error_setg(errp, "export name '%s' too long", arg->name); - return NULL; + return -EINVAL; } if (arg->description && strlen(arg->description) > NBD_MAX_STRING_SIZE) { error_setg(errp, "description '%s' too long", arg->description); - return NULL; + return -EINVAL; } if (nbd_export_find(arg->name)) { error_setg(errp, "NBD server already has export named '%s'", arg->name); - return NULL; + return -EEXIST; } bs = bdrv_lookup_bs(exp_args->device, exp_args->device, errp); if (!bs) { - return NULL; + return -ENOENT; } aio_context = bdrv_get_aio_context(bs); @@ -218,14 +219,15 @@ BlockExport *nbd_export_create(BlockExportOptions *exp_args, Error **errp) arg->writable = false; } if (bdrv_is_read_only(bs) && arg->writable) { + ret = -EINVAL; error_setg(errp, "Cannot export read-only node as writable"); goto out; } - exp = nbd_export_new(bs, arg->name, arg->description, arg->bitmap, + ret = nbd_export_new(exp, bs, arg->name, arg->description, arg->bitmap, !arg->writable, !arg->writable, exp_args->writethrough, errp); - if (!exp) { + if (ret < 0) { goto out; } @@ -234,10 +236,10 @@ BlockExport *nbd_export_create(BlockExportOptions *exp_args, Error **errp) * the strong reference that is @exp. */ blk_exp_unref((BlockExport*) exp); + ret = 0; out: aio_context_release(aio_context); - /* TODO Remove the cast: Move to server.c which can access fields of exp */ - return (BlockExport*) exp; + return ret; } void qmp_nbd_server_remove(const char *name, diff --git a/nbd/server.c b/nbd/server.c index b735a68429..6a58297557 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1513,14 +1513,14 @@ void nbd_export_set_on_eject_blk(BlockExport *exp, BlockBackend *blk) blk_add_remove_bs_notifier(blk, &nbd_exp->eject_notifier); } -NBDExport *nbd_export_new(BlockDriverState *bs, - const char *name, const char *desc, - const char *bitmap, bool readonly, bool shared, - bool writethrough, Error **errp) +int nbd_export_new(BlockExport *blk_exp, BlockDriverState *bs, + const char *name, const char *desc, + const char *bitmap, bool readonly, bool shared, + bool writethrough, Error **errp) { + NBDExport *exp = container_of(blk_exp, NBDExport, common); AioContext *ctx; BlockBackend *blk; - NBDExport *exp; int64_t size; uint64_t perm; int ret; @@ -1529,17 +1529,11 @@ NBDExport *nbd_export_new(BlockDriverState *bs, if (size < 0) { error_setg_errno(errp, -size, "Failed to determine the NBD export's length"); - return NULL; + return size; } ctx = bdrv_get_aio_context(bs); - - exp = g_new0(NBDExport, 1); - exp->common = (BlockExport) { - .drv = &blk_exp_nbd, - .refcount = 1, - .ctx = ctx, - }; + blk_exp->ctx = ctx; /* * NBD exports are used for non-shared storage migration. Make sure @@ -1599,16 +1593,19 @@ NBDExport *nbd_export_new(BlockDriverState *bs, } if (bm == NULL) { + ret = -ENOENT; error_setg(errp, "Bitmap '%s' is not found", bitmap); goto fail; } if (bdrv_dirty_bitmap_check(bm, BDRV_BITMAP_ALLOW_RO, errp)) { + ret = -EINVAL; goto fail; } if (readonly && bdrv_is_writable(bs) && bdrv_dirty_bitmap_enabled(bm)) { + ret = -EINVAL; error_setg(errp, "Enabled bitmap '%s' incompatible with readonly export", bitmap); @@ -1628,14 +1625,13 @@ NBDExport *nbd_export_new(BlockDriverState *bs, blk_exp_ref(&exp->common); QTAILQ_INSERT_TAIL(&exports, exp, next); - return exp; + return 0; fail: blk_unref(blk); g_free(exp->name); g_free(exp->description); - g_free(exp); - return NULL; + return ret; } NBDExport *nbd_export_find(const char *name) @@ -1722,12 +1718,12 @@ static void nbd_export_delete(BlockExport *blk_exp) } QTAILQ_REMOVE(&closed_exports, exp, next); - g_free(exp); aio_wait_kick(); } const BlockExportDriver blk_exp_nbd = { .type = BLOCK_EXPORT_TYPE_NBD, + .instance_size = sizeof(NBDExport), .create = nbd_export_create, .delete = nbd_export_delete, }; From patchwork Thu Aug 13 16:29:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11712699 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0CD4B109B for ; Thu, 13 Aug 2020 16:40:37 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D769B20829 for ; Thu, 13 Aug 2020 16:40:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EBzF6YnZ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D769B20829 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36876 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k6GHM-0005yI-40 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 13 Aug 2020 12:40:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55740) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k6G7Y-0002hj-5k for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:30:28 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:59691 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1k6G7V-0001Os-L4 for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:30:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597336224; 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=1VPRQm1UXA5+fW8O1I3o7UEA748AQPBgncNTscJTZMA=; b=EBzF6YnZrUjoarLBWGi30QwwKS0cnBhOGGIaB5bfg03Ra5tipw2a3FZNfhSpcrlWzunsmP HFKI2p3gHPaMhoVtHaILpZxwB0ALS2A5Q55vTGkgKnXJbZgc8uxkPJA6eJIdafIj3B5ilL fI1AhZDzdv3ACLW9MW8j9UJjq6k6oMs= 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-315-B___ZwCDPk-UhFkaCkR8Kg-1; Thu, 13 Aug 2020 12:30:22 -0400 X-MC-Unique: B___ZwCDPk-UhFkaCkR8Kg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 115AB1006709; Thu, 13 Aug 2020 16:30:21 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-113-97.ams2.redhat.com [10.36.113.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id E4A005C1A3; Thu, 13 Aug 2020 16:30:19 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 17/22] block/export: Add blk_exp_close_all(_type) Date: Thu, 13 Aug 2020 18:29:30 +0200 Message-Id: <20200813162935.210070-18-kwolf@redhat.com> In-Reply-To: <20200813162935.210070-1-kwolf@redhat.com> References: <20200813162935.210070-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=207.211.31.120; envelope-from=kwolf@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/13 03:45:42 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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: , Cc: kwolf@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" This adds a function to shut down all block exports, and another one to shut down the block exports of a single type. The latter is used for now when stopping the NBD server. As soon as we implement support for multiple NBD servers, we'll need a per-server list of exports and it will be replaced by a function using that. As a side effect, the BlockExport layer has a list tracking all existing exports now. closed_exports loses its only user and can go away. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- include/block/export.h | 8 +++++++ include/block/nbd.h | 2 -- block.c | 2 +- block/export/export.c | 52 ++++++++++++++++++++++++++++++++++++++++++ blockdev-nbd.c | 2 +- nbd/server.c | 34 ++++----------------------- qemu-nbd.c | 2 +- 7 files changed, 68 insertions(+), 34 deletions(-) diff --git a/include/block/export.h b/include/block/export.h index 597fc58245..1698b68f09 100644 --- a/include/block/export.h +++ b/include/block/export.h @@ -15,6 +15,7 @@ #define BLOCK_EXPORT_H #include "qapi/qapi-types-block-export.h" +#include "qemu/queue.h" typedef struct BlockExport BlockExport; @@ -23,6 +24,7 @@ typedef struct BlockExportDriver { size_t instance_size; int (*create)(BlockExport *, BlockExportOptions *, Error **); void (*delete)(BlockExport *); + void (*request_shutdown)(BlockExport *); } BlockExportDriver; struct BlockExport { @@ -40,6 +42,9 @@ struct BlockExport { * BlockExportDriver callbacks. */ AioContext *ctx; + + /* List entry for block_exports */ + QLIST_ENTRY(BlockExport) next; }; extern const BlockExportDriver blk_exp_nbd; @@ -47,5 +52,8 @@ extern const BlockExportDriver blk_exp_nbd; BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp); void blk_exp_ref(BlockExport *exp); void blk_exp_unref(BlockExport *exp); +void blk_exp_request_shutdown(BlockExport *exp); +void blk_exp_close_all(void); +void blk_exp_close_all_type(BlockExportType type); #endif diff --git a/include/block/nbd.h b/include/block/nbd.h index 602536feb2..91a9d4f96d 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -335,12 +335,10 @@ int nbd_export_new(BlockExport *blk_exp, BlockDriverState *bs, const char *bitmap, bool readonly, bool shared, bool writethrough, Error **errp); void nbd_export_set_on_eject_blk(BlockExport *exp, BlockBackend *blk); -void nbd_export_close(NBDExport *exp); void nbd_export_remove(NBDExport *exp, NbdServerRemoveMode mode, Error **errp); AioContext *nbd_export_aio_context(NBDExport *exp); NBDExport *nbd_export_find(const char *name); -void nbd_export_close_all(void); void nbd_client_new(QIOChannelSocket *sioc, QCryptoTLSCreds *tlscreds, diff --git a/block.c b/block.c index d9ac0e07eb..357c72846e 100644 --- a/block.c +++ b/block.c @@ -4424,7 +4424,7 @@ static void bdrv_close(BlockDriverState *bs) void bdrv_close_all(void) { assert(job_next(NULL) == NULL); - nbd_export_close_all(); + blk_exp_close_all(); /* Drop references from requests still in flight, such as canceled block * jobs whose AIO context has not been polled yet */ diff --git a/block/export/export.c b/block/export/export.c index 9de108cbc1..675db9a8b9 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -24,6 +24,9 @@ static const BlockExportDriver* blk_exp_drivers[] = { &blk_exp_nbd, }; +static QLIST_HEAD(, BlockExport) block_exports = + QLIST_HEAD_INITIALIZER(block_exports); + static const BlockExportDriver *blk_exp_find_driver(BlockExportType type) { int i; @@ -60,6 +63,7 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp) return NULL; } + QLIST_INSERT_HEAD(&block_exports, exp, next); return exp; } @@ -73,11 +77,59 @@ void blk_exp_unref(BlockExport *exp) { assert(exp->refcount > 0); if (--exp->refcount == 0) { + QLIST_REMOVE(exp, next); exp->drv->delete(exp); g_free(exp); + aio_wait_kick(); } } +void blk_exp_request_shutdown(BlockExport *exp) +{ + AioContext *aio_context = exp->ctx; + + aio_context_acquire(aio_context); + exp->drv->request_shutdown(exp); + aio_context_release(aio_context); +} + +static bool blk_exp_has_type(BlockExportType type) +{ + BlockExport *exp; + + if (type == BLOCK_EXPORT_TYPE__MAX) { + return !QLIST_EMPTY(&block_exports); + } + + QLIST_FOREACH(exp, &block_exports, next) { + if (exp->drv->type == type) { + return true; + } + } + + return false; +} + +/* type == BLOCK_EXPORT_TYPE__MAX for all types */ +void blk_exp_close_all_type(BlockExportType type) +{ + BlockExport *exp, *next; + + QLIST_FOREACH_SAFE(exp, &block_exports, next, next) { + if (type != BLOCK_EXPORT_TYPE__MAX && exp->drv->type != type) { + continue; + } + blk_exp_request_shutdown(exp); + } + + AIO_WAIT_WHILE(NULL, blk_exp_has_type(type)); +} + +void blk_exp_close_all(void) +{ + blk_exp_close_all_type(BLOCK_EXPORT_TYPE__MAX); +} + void qmp_block_export_add(BlockExportOptions *export, Error **errp) { blk_exp_add(export, errp); diff --git a/blockdev-nbd.c b/blockdev-nbd.c index f97deba424..1c7aa874ee 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -277,7 +277,7 @@ void qmp_nbd_server_stop(Error **errp) return; } - nbd_export_close_all(); + blk_exp_close_all_type(BLOCK_EXPORT_TYPE_NBD); nbd_server_free(nbd_server); nbd_server = NULL; diff --git a/nbd/server.c b/nbd/server.c index 6a58297557..7e2976b81d 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -100,8 +100,6 @@ struct NBDExport { }; static QTAILQ_HEAD(, NBDExport) exports = QTAILQ_HEAD_INITIALIZER(exports); -static QTAILQ_HEAD(, NBDExport) closed_exports = - QTAILQ_HEAD_INITIALIZER(closed_exports); /* NBDExportMetaContexts represents a list of contexts to be exported, * as selected by NBD_OPT_SET_META_CONTEXT. Also used for @@ -1494,12 +1492,8 @@ static void blk_aio_detach(void *opaque) static void nbd_eject_notifier(Notifier *n, void *data) { NBDExport *exp = container_of(n, NBDExport, eject_notifier); - AioContext *aio_context; - aio_context = exp->common.ctx; - aio_context_acquire(aio_context); - nbd_export_close(exp); - aio_context_release(aio_context); + blk_exp_request_shutdown(&exp->common); } void nbd_export_set_on_eject_blk(BlockExport *exp, BlockBackend *blk) @@ -1652,8 +1646,9 @@ nbd_export_aio_context(NBDExport *exp) return exp->common.ctx; } -void nbd_export_close(NBDExport *exp) +static void nbd_export_request_shutdown(BlockExport *blk_exp) { + NBDExport *exp = container_of(blk_exp, NBDExport, common); NBDClient *client, *next; blk_exp_ref(&exp->common); @@ -1672,7 +1667,6 @@ void nbd_export_close(NBDExport *exp) g_free(exp->name); exp->name = NULL; QTAILQ_REMOVE(&exports, exp, next); - QTAILQ_INSERT_TAIL(&closed_exports, exp, next); } blk_exp_unref(&exp->common); } @@ -1681,7 +1675,7 @@ void nbd_export_remove(NBDExport *exp, NbdServerRemoveMode mode, Error **errp) { ERRP_GUARD(); if (mode == NBD_SERVER_REMOVE_MODE_HARD || QTAILQ_EMPTY(&exp->clients)) { - nbd_export_close(exp); + nbd_export_request_shutdown(&exp->common); return; } @@ -1716,9 +1710,6 @@ static void nbd_export_delete(BlockExport *blk_exp) bdrv_dirty_bitmap_set_busy(exp->export_bitmap, false); g_free(exp->export_bitmap_context); } - - QTAILQ_REMOVE(&closed_exports, exp, next); - aio_wait_kick(); } const BlockExportDriver blk_exp_nbd = { @@ -1726,24 +1717,9 @@ const BlockExportDriver blk_exp_nbd = { .instance_size = sizeof(NBDExport), .create = nbd_export_create, .delete = nbd_export_delete, + .request_shutdown = nbd_export_request_shutdown, }; -void nbd_export_close_all(void) -{ - NBDExport *exp, *next; - AioContext *aio_context; - - QTAILQ_FOREACH_SAFE(exp, &exports, next, next) { - aio_context = exp->common.ctx; - aio_context_acquire(aio_context); - nbd_export_close(exp); - aio_context_release(aio_context); - } - - AIO_WAIT_WHILE(NULL, !(QTAILQ_EMPTY(&exports) && - QTAILQ_EMPTY(&closed_exports))); -} - static int coroutine_fn nbd_co_send_iov(NBDClient *client, struct iovec *iov, unsigned niov, Error **errp) { diff --git a/qemu-nbd.c b/qemu-nbd.c index f31868708c..939a08902a 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -1110,7 +1110,7 @@ int main(int argc, char **argv) do { main_loop_wait(false); if (state == TERMINATE) { - nbd_export_close_all(); + blk_exp_close_all(); state = TERMINATED; } } while (state != TERMINATED); From patchwork Thu Aug 13 16:29:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11712689 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9DAC3739 for ; Thu, 13 Aug 2020 16:36:46 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 744A920675 for ; Thu, 13 Aug 2020 16:36:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="D5MUrJnC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 744A920675 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:47098 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k6GDd-0006za-Ov for patchwork-qemu-devel@patchwork.kernel.org; Thu, 13 Aug 2020 12:36:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55766) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k6G7Z-0002ju-84 for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:30:29 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:49180 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1k6G7W-0001P4-0E for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:30:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597336225; 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=wAHKs+08P/vSTz3lirDXGKErXF8MzB0H4yvSv1GYU5w=; b=D5MUrJnCCZfd5sEoAt8UyL589kjzyc0dqTFsVNFITGo8yLayKWwjoHTv8m4IugUduSMoLe mk3gANJornocKLYkDLFozHGSXICjnXrygEO8oLfpXQPy/9rHFaUaYmWvvp94AD7qll71pJ 3gWcOHQ3P8H+qBZKmB8M56zPVOfeH/g= 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-204-_uL5vCJ6OQ-20QuuUf5eLA-1; Thu, 13 Aug 2020 12:30:23 -0400 X-MC-Unique: _uL5vCJ6OQ-20QuuUf5eLA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7BC481853DB9; Thu, 13 Aug 2020 16:30:22 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-113-97.ams2.redhat.com [10.36.113.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5B8385C1A3; Thu, 13 Aug 2020 16:30:21 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 18/22] block/export: Add 'id' option to block-export-add Date: Thu, 13 Aug 2020 18:29:31 +0200 Message-Id: <20200813162935.210070-19-kwolf@redhat.com> In-Reply-To: <20200813162935.210070-1-kwolf@redhat.com> References: <20200813162935.210070-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=205.139.110.61; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/13 12:29:49 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -40 X-Spam_score: -4.1 X-Spam_bar: ---- X-Spam_report: (-4.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, 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_H2=-1, 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, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" We'll need an id to identify block exports in monitor commands. This adds one. Note that this is different from the 'name' option in the NBD server, which is the externally visible export name. While block export ids need to be unique in the whole process, export names must be unique only for the same server. Different export types or (potentially in the future) multiple NBD servers can have the same export name externally, but still need different block export ids internally. Signed-off-by: Kevin Wolf --- qapi/block-export.json | 3 +++ include/block/export.h | 3 +++ block/export/export.c | 27 +++++++++++++++++++++++++++ qemu-nbd.c | 1 + 4 files changed, 34 insertions(+) diff --git a/qapi/block-export.json b/qapi/block-export.json index d68f3bf87e..0d0db9ca1b 100644 --- a/qapi/block-export.json +++ b/qapi/block-export.json @@ -179,6 +179,8 @@ # Describes a block export, i.e. how single node should be exported on an # external interface. # +# @id: A unique identifier for the block export (across all export types) +# # @device: The device name or node name of the node to be exported # # @writethrough: If true, caches are flushed after every write request to the @@ -189,6 +191,7 @@ ## { 'union': 'BlockExportOptions', 'base': { 'type': 'BlockExportType', + 'id': 'str', 'device': 'str', '*writethrough': 'bool' }, 'discriminator': 'type', diff --git a/include/block/export.h b/include/block/export.h index 1698b68f09..43229857b0 100644 --- a/include/block/export.h +++ b/include/block/export.h @@ -30,6 +30,9 @@ typedef struct BlockExportDriver { struct BlockExport { const BlockExportDriver *drv; + /* Unique identifier for the export */ + char *id; + /* * Reference count for this block export. This includes strong references * both from the owner (qemu-nbd or the monitor) and clients connected to diff --git a/block/export/export.c b/block/export/export.c index 675db9a8b9..72f1fab975 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -19,6 +19,7 @@ #include "block/nbd.h" #include "qapi/error.h" #include "qapi/qapi-commands-block-export.h" +#include "qemu/id.h" static const BlockExportDriver* blk_exp_drivers[] = { &blk_exp_nbd, @@ -27,6 +28,19 @@ static const BlockExportDriver* blk_exp_drivers[] = { static QLIST_HEAD(, BlockExport) block_exports = QLIST_HEAD_INITIALIZER(block_exports); +static BlockExport *blk_exp_find(const char *id) +{ + BlockExport *exp; + + QLIST_FOREACH(exp, &block_exports, next) { + if (strcmp(id, exp->id) == 0) { + return exp; + } + } + + return NULL; +} + static const BlockExportDriver *blk_exp_find_driver(BlockExportType type) { int i; @@ -45,6 +59,15 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp) BlockExport *exp; int ret; + if (!id_wellformed(export->id)) { + error_setg(errp, "Invalid block export id"); + return NULL; + } + if (blk_exp_find(export->id)) { + error_setg(errp, "Block export id '%s' is already in use", export->id); + return NULL; + } + drv = blk_exp_find_driver(export->type); if (!drv) { error_setg(errp, "No driver found for the requested export type"); @@ -55,10 +78,12 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp) *exp = (BlockExport) { .drv = &blk_exp_nbd, .refcount = 1, + .id = g_strdup(export->id), }; ret = drv->create(exp, export, errp); if (ret < 0) { + g_free(exp->id); g_free(exp); return NULL; } @@ -79,6 +104,7 @@ void blk_exp_unref(BlockExport *exp) if (--exp->refcount == 0) { QLIST_REMOVE(exp, next); exp->drv->delete(exp); + g_free(exp->id); g_free(exp); aio_wait_kick(); } @@ -144,6 +170,7 @@ void qmp_nbd_server_add(NbdServerAddOptions *arg, Error **errp) BlockExportOptions *export_opts = g_new(BlockExportOptions, 1); *export_opts = (BlockExportOptions) { .type = BLOCK_EXPORT_TYPE_NBD, + .id = g_strdup(arg->name ?: arg->device), .device = g_strdup(arg->device), .u.nbd = { .has_name = arg->has_name, diff --git a/qemu-nbd.c b/qemu-nbd.c index 939a08902a..c6fc0581c1 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -1055,6 +1055,7 @@ int main(int argc, char **argv) export_opts = g_new(BlockExportOptions, 1); *export_opts = (BlockExportOptions) { .type = BLOCK_EXPORT_TYPE_NBD, + .id = g_strdup("qemu-nbd-export"), .device = g_strdup(bdrv_get_node_name(bs)), .has_writethrough = true, .writethrough = writethrough, From patchwork Thu Aug 13 16:29:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11712691 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 770E5109B for ; Thu, 13 Aug 2020 16:38:39 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4DB4E206A4 for ; Thu, 13 Aug 2020 16:38:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="GhfYaguf" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4DB4E206A4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:53812 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k6GFS-0001JM-H8 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 13 Aug 2020 12:38:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55824) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k6G7c-0002qr-4C for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:30:32 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:41854 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1k6G7a-0001Qj-BC for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:30:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597336229; 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=YXn53EsmWf/+7NHPAoFuqEH3vFShL3ZRTa7pelF9T9A=; b=GhfYagufcM4fBZOyzoCfMWCBTiOmZrkSoXtCBDo7iyk6RIhnBS48ZG7ZIyrgjqlDmK8MVC g3yDEn2YkqURjWaYmMp5c7IO/6RrEUs9OFO1oJsFVghJNlq9enGUzqXc9hQ7wG1CD7mPVT g0cpDrvmdU83BbJq2+MJggsZCHoy7PA= 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-554-638O3ZJ_NkaX3cZGVUAojQ-1; Thu, 13 Aug 2020 12:30:25 -0400 X-MC-Unique: 638O3ZJ_NkaX3cZGVUAojQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E619B1853DBC; Thu, 13 Aug 2020 16:30:23 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-113-97.ams2.redhat.com [10.36.113.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id C574B5C1A3; Thu, 13 Aug 2020 16:30:22 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 19/22] block/export: Move strong user reference to block_exports Date: Thu, 13 Aug 2020 18:29:32 +0200 Message-Id: <20200813162935.210070-20-kwolf@redhat.com> In-Reply-To: <20200813162935.210070-1-kwolf@redhat.com> References: <20200813162935.210070-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=205.139.110.120; envelope-from=kwolf@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/13 03:44:21 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" The reference owned by the user/monitor that is created when adding the export and dropped when removing it was tied to the 'exports' list in nbd/server.c. Every block export will have a user reference, so move it to the block export level and tie it to the 'block_exports' list in block/export/export.c instead. This is necessary for introducing a QMP command for removing exports. Note that exports are present in block_exports even after the user has requested shutdown. This is different from NBD's exports where exports are immediately removed on a shutdown request, even if they are still in the process of shutting down. In order to avoid that the user still interacts with an export that is shutting down (and possibly removes it a second time), we need to remember if the user actually still owns it. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- include/block/export.h | 8 ++++++++ block/export/export.c | 4 ++++ blockdev-nbd.c | 5 ----- nbd/server.c | 2 -- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/include/block/export.h b/include/block/export.h index 43229857b0..83f554b745 100644 --- a/include/block/export.h +++ b/include/block/export.h @@ -40,6 +40,14 @@ struct BlockExport { */ int refcount; + /* + * True if one of the references in refcount belongs to the user. After the + * user has dropped their reference, they may not e.g. remove the same + * export a second time (which would decrease the refcount without having + * it incremented first). + */ + bool user_owned; + /* * The AioContex whose lock needs to be held while calling * BlockExportDriver callbacks. diff --git a/block/export/export.c b/block/export/export.c index 72f1fab975..f94a81258a 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -78,6 +78,7 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp) *exp = (BlockExport) { .drv = &blk_exp_nbd, .refcount = 1, + .user_owned = true, .id = g_strdup(export->id), }; @@ -117,6 +118,9 @@ void blk_exp_request_shutdown(BlockExport *exp) aio_context_acquire(aio_context); exp->drv->request_shutdown(exp); aio_context_release(aio_context); + + exp->user_owned = false; + blk_exp_unref(exp); } static bool blk_exp_has_type(BlockExportType type) diff --git a/blockdev-nbd.c b/blockdev-nbd.c index 1c7aa874ee..40013b7d64 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -231,11 +231,6 @@ int nbd_export_create(BlockExport *exp, BlockExportOptions *exp_args, goto out; } - /* The list of named exports has a strong reference to this export now and - * our only way of accessing it is through nbd_export_find(), so we can drop - * the strong reference that is @exp. */ - blk_exp_unref((BlockExport*) exp); - ret = 0; out: aio_context_release(aio_context); diff --git a/nbd/server.c b/nbd/server.c index 7e2976b81d..e3ac7f548b 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1616,7 +1616,6 @@ int nbd_export_new(BlockExport *blk_exp, BlockDriverState *bs, blk_add_aio_context_notifier(blk, blk_aio_attached, blk_aio_detach, exp); - blk_exp_ref(&exp->common); QTAILQ_INSERT_TAIL(&exports, exp, next); return 0; @@ -1663,7 +1662,6 @@ static void nbd_export_request_shutdown(BlockExport *blk_exp) client_close(client, true); } if (exp->name) { - blk_exp_unref(&exp->common); g_free(exp->name); exp->name = NULL; QTAILQ_REMOVE(&exports, exp, next); From patchwork Thu Aug 13 16:29:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11712695 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7E3EB109B for ; Thu, 13 Aug 2020 16:39:12 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 54DEC206A4 for ; Thu, 13 Aug 2020 16:39:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="efHPQSkd" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 54DEC206A4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:56736 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k6GFz-0002Un-Fd for patchwork-qemu-devel@patchwork.kernel.org; Thu, 13 Aug 2020 12:39:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55820) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k6G7c-0002qi-2D for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:30:32 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:59611 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1k6G7Z-0001QO-Aq for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:30:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597336228; 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=hteBVefx1cKiiMbxnynTnOE91AMKJvVatWhPz906JBM=; b=efHPQSkd6KarXguXB3Qpd/2jErDqNEww4BELxryq0EotGECMpUPYnLc2xRx8Xt7ze41q2i TSk6qDhENMuIJPSRKoZwlWehxEliyyQLXKa0pVesQtXCq56SceZhJh8o3jzVCdSfKWFBZB 4fId92V1tn1KUulODBxI/XV4EVolX7A= 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-104-e4PrP72lP2yzU5G569-Muw-1; Thu, 13 Aug 2020 12:30:26 -0400 X-MC-Unique: e4PrP72lP2yzU5G569-Muw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5D830801AC3; Thu, 13 Aug 2020 16:30:25 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-113-97.ams2.redhat.com [10.36.113.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3B8F65C1A3; Thu, 13 Aug 2020 16:30:24 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 20/22] block/export: Add block-export-del Date: Thu, 13 Aug 2020 18:29:33 +0200 Message-Id: <20200813162935.210070-21-kwolf@redhat.com> In-Reply-To: <20200813162935.210070-1-kwolf@redhat.com> References: <20200813162935.210070-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=205.139.110.120; envelope-from=kwolf@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/13 03:44:21 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Implement a new QMP command block-export-del and make nbd-server-remove a wrapper around it. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- qapi/block-export.json | 30 +++++++++++++++---- include/block/nbd.h | 1 - block/export/export.c | 54 ++++++++++++++++++++++++++++++++++ block/monitor/block-hmp-cmds.c | 2 +- blockdev-nbd.c | 28 ------------------ nbd/server.c | 14 --------- 6 files changed, 79 insertions(+), 50 deletions(-) diff --git a/qapi/block-export.json b/qapi/block-export.json index 0d0db9ca1b..a067de2ba3 100644 --- a/qapi/block-export.json +++ b/qapi/block-export.json @@ -111,9 +111,9 @@ 'data': 'NbdServerAddOptions', 'boxed': true } ## -# @NbdServerRemoveMode: +# @BlockExportRemoveMode: # -# Mode for removing an NBD export. +# Mode for removing a block export. # # @safe: Remove export if there are no existing connections, fail otherwise. # @@ -129,16 +129,16 @@ # # Since: 2.12 ## -{'enum': 'NbdServerRemoveMode', 'data': ['safe', 'hard']} +{'enum': 'BlockExportRemoveMode', 'data': ['safe', 'hard']} ## # @nbd-server-remove: # # Remove NBD export by name. # -# @name: Export name. +# @name: Block export id. # -# @mode: Mode of command operation. See @NbdServerRemoveMode description. +# @mode: Mode of command operation. See @BlockExportRemoveMode description. # Default is 'safe'. # # Returns: error if @@ -149,7 +149,7 @@ # Since: 2.12 ## { 'command': 'nbd-server-remove', - 'data': {'name': 'str', '*mode': 'NbdServerRemoveMode'} } + 'data': {'name': 'str', '*mode': 'BlockExportRemoveMode'} } ## # @nbd-server-stop: @@ -208,3 +208,21 @@ ## { 'command': 'block-export-add', 'data': 'BlockExportOptions', 'boxed': true } + +## +# @block-export-del: +# +# Remove a block export. +# +# @id: Block export id. +# +# @mode: Mode of command operation. See @BlockExportRemoveMode description. +# Default is 'safe'. +# +# Returns: Error if the export is not found or @mode is 'safe' and the export +# is still in use (e.g. by existing client connections) +# +# Since: 5.2 +## +{ 'command': 'block-export-del', + 'data': { 'id': 'str', '*mode': 'BlockExportRemoveMode' } } diff --git a/include/block/nbd.h b/include/block/nbd.h index 91a9d4f96d..7982a63f96 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -335,7 +335,6 @@ int nbd_export_new(BlockExport *blk_exp, BlockDriverState *bs, const char *bitmap, bool readonly, bool shared, bool writethrough, Error **errp); void nbd_export_set_on_eject_blk(BlockExport *exp, BlockBackend *blk); -void nbd_export_remove(NBDExport *exp, NbdServerRemoveMode mode, Error **errp); AioContext *nbd_export_aio_context(NBDExport *exp); NBDExport *nbd_export_find(const char *name); diff --git a/block/export/export.c b/block/export/export.c index f94a81258a..1255f3fc80 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -115,6 +115,15 @@ void blk_exp_request_shutdown(BlockExport *exp) { AioContext *aio_context = exp->ctx; + /* + * If the user doesn't own the export any more, it is already shutting + * down. We must not call .request_shutdown and decrease the refcount a + * second time. + */ + if (!exp->user_owned) { + return; + } + aio_context_acquire(aio_context); exp->drv->request_shutdown(exp); aio_context_release(aio_context); @@ -215,3 +224,48 @@ void qmp_nbd_server_add(NbdServerAddOptions *arg, Error **errp) fail: qapi_free_BlockExportOptions(export_opts); } + +void qmp_block_export_del(const char *id, + bool has_mode, BlockExportRemoveMode mode, + Error **errp) +{ + ERRP_GUARD(); + BlockExport *exp; + + exp = blk_exp_find(id); + if (exp == NULL) { + error_setg(errp, "Export '%s' is not found", id); + return; + } + if (!exp->user_owned) { + error_setg(errp, "Export '%s' is already shutting down", id); + return; + } + + if (!has_mode) { + mode = BLOCK_EXPORT_REMOVE_MODE_SAFE; + } + if (mode == BLOCK_EXPORT_REMOVE_MODE_SAFE && exp->refcount > 1) { + error_setg(errp, "export '%s' still in use", exp->id); + error_append_hint(errp, "Use mode='hard' to force client " + "disconnect\n"); + return; + } + + blk_exp_request_shutdown(exp); +} + +void qmp_nbd_server_remove(const char *name, + bool has_mode, BlockExportRemoveMode mode, + Error **errp) +{ + BlockExport *exp; + + exp = blk_exp_find(name); + if (exp && exp->drv->type != BLOCK_EXPORT_TYPE_NBD) { + error_setg(errp, "Block export '%s' is not an NBD export", name); + return; + } + + qmp_block_export_del(name, has_mode, mode, errp); +} diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c index 6c823234a9..10165252cf 100644 --- a/block/monitor/block-hmp-cmds.c +++ b/block/monitor/block-hmp-cmds.c @@ -477,7 +477,7 @@ void hmp_nbd_server_remove(Monitor *mon, const QDict *qdict) Error *err = NULL; /* Rely on NBD_SERVER_REMOVE_MODE_SAFE being the default */ - qmp_nbd_server_remove(name, force, NBD_SERVER_REMOVE_MODE_HARD, &err); + qmp_nbd_server_remove(name, force, BLOCK_EXPORT_REMOVE_MODE_HARD, &err); hmp_handle_error(mon, err); } diff --git a/blockdev-nbd.c b/blockdev-nbd.c index 40013b7d64..5ec21045a8 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -237,34 +237,6 @@ int nbd_export_create(BlockExport *exp, BlockExportOptions *exp_args, return ret; } -void qmp_nbd_server_remove(const char *name, - bool has_mode, NbdServerRemoveMode mode, - Error **errp) -{ - NBDExport *exp; - AioContext *aio_context; - - if (!nbd_server) { - error_setg(errp, "NBD server not running"); - return; - } - - exp = nbd_export_find(name); - if (exp == NULL) { - error_setg(errp, "Export '%s' is not found", name); - return; - } - - if (!has_mode) { - mode = NBD_SERVER_REMOVE_MODE_SAFE; - } - - aio_context = nbd_export_aio_context(exp); - aio_context_acquire(aio_context); - nbd_export_remove(exp, mode, errp); - aio_context_release(aio_context); -} - void qmp_nbd_server_stop(Error **errp) { if (!nbd_server) { diff --git a/nbd/server.c b/nbd/server.c index e3ac7f548b..899d00782f 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1669,20 +1669,6 @@ static void nbd_export_request_shutdown(BlockExport *blk_exp) blk_exp_unref(&exp->common); } -void nbd_export_remove(NBDExport *exp, NbdServerRemoveMode mode, Error **errp) -{ - ERRP_GUARD(); - if (mode == NBD_SERVER_REMOVE_MODE_HARD || QTAILQ_EMPTY(&exp->clients)) { - nbd_export_request_shutdown(&exp->common); - return; - } - - assert(mode == NBD_SERVER_REMOVE_MODE_SAFE); - - error_setg(errp, "export '%s' still in use", exp->name); - error_append_hint(errp, "Use mode='hard' to force client disconnect\n"); -} - static void nbd_export_delete(BlockExport *blk_exp) { NBDExport *exp = container_of(blk_exp, NBDExport, common); From patchwork Thu Aug 13 16:29:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11712705 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F0BD5739 for ; Thu, 13 Aug 2020 16:43:40 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B26A020855 for ; Thu, 13 Aug 2020 16:43:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="X+1Guwwq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B26A020855 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:48136 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k6GKK-0002As-1B for patchwork-qemu-devel@patchwork.kernel.org; Thu, 13 Aug 2020 12:43:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56240) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k6G96-00059C-JA for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:32:04 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:47844 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1k6G94-0001dy-Jk for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:32:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597336321; 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=BIk7i9h0goB63ZMrR/6zqne/mhsultHKTPd2Tl8s3cw=; b=X+1Guwwqn8jc095LIFv8ITAXU/f3pRwsu9Kc5XzK2gUECGbbGXrU1vLIgMUrBJVXOk069y GutYQZ9PKaPFDuE9oRTUoqFssjg+dGPP/Z2/WZsSujAwWb9p0aMulOZ+eW/Uni4kn3HPpo pTzjOkTVMgg0A37rr41gyX+GSLsgU58= 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-477-Y3rqyoP-OiaThj0dLxRW3A-1; Thu, 13 Aug 2020 12:30:27 -0400 X-MC-Unique: Y3rqyoP-OiaThj0dLxRW3A-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C892A800050; Thu, 13 Aug 2020 16:30:26 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-113-97.ams2.redhat.com [10.36.113.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id A65475C1A3; Thu, 13 Aug 2020 16:30:25 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 21/22] block/export: Move blk to BlockExport Date: Thu, 13 Aug 2020 18:29:34 +0200 Message-Id: <20200813162935.210070-22-kwolf@redhat.com> In-Reply-To: <20200813162935.210070-1-kwolf@redhat.com> References: <20200813162935.210070-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=205.139.110.61; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/13 12:29:49 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -40 X-Spam_score: -4.1 X-Spam_bar: ---- X-Spam_report: (-4.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, 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_H2=-1, 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, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Every block export has a BlockBackend representing the disk that is exported. It should live in BlockExport therefore. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- include/block/export.h | 3 +++ block/export/export.c | 3 +++ nbd/server.c | 44 ++++++++++++++++++++++-------------------- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/include/block/export.h b/include/block/export.h index 83f554b745..53b4163a3b 100644 --- a/include/block/export.h +++ b/include/block/export.h @@ -54,6 +54,9 @@ struct BlockExport { */ AioContext *ctx; + /* The block device to export */ + BlockBackend *blk; + /* List entry for block_exports */ QLIST_ENTRY(BlockExport) next; }; diff --git a/block/export/export.c b/block/export/export.c index 1255f3fc80..3cd448ba72 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -89,6 +89,8 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Error **errp) return NULL; } + assert(exp->blk != NULL); + QLIST_INSERT_HEAD(&block_exports, exp, next); return exp; } @@ -105,6 +107,7 @@ void blk_exp_unref(BlockExport *exp) if (--exp->refcount == 0) { QLIST_REMOVE(exp, next); exp->drv->delete(exp); + blk_unref(exp->blk); g_free(exp->id); g_free(exp); aio_wait_kick(); diff --git a/nbd/server.c b/nbd/server.c index 899d00782f..6ad78203c9 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -84,7 +84,6 @@ struct NBDRequestData { struct NBDExport { BlockExport common; - BlockBackend *blk; char *name; char *description; uint64_t size; @@ -643,7 +642,7 @@ static int nbd_negotiate_handle_info(NBDClient *client, Error **errp) * whether this is OPT_INFO or OPT_GO. */ /* minimum - 1 for back-compat, or actual if client will obey it. */ if (client->opt == NBD_OPT_INFO || blocksize) { - check_align = sizes[0] = blk_get_request_alignment(exp->blk); + check_align = sizes[0] = blk_get_request_alignment(exp->common.blk); } else { sizes[0] = 1; } @@ -652,7 +651,7 @@ static int nbd_negotiate_handle_info(NBDClient *client, Error **errp) * TODO: is blk_bs(blk)->bl.opt_transfer appropriate? */ sizes[1] = MAX(4096, sizes[0]); /* maximum - At most 32M, but smaller as appropriate. */ - sizes[2] = MIN(blk_get_max_transfer(exp->blk), NBD_MAX_BUFFER_SIZE); + sizes[2] = MIN(blk_get_max_transfer(exp->common.blk), NBD_MAX_BUFFER_SIZE); trace_nbd_negotiate_handle_info_block_size(sizes[0], sizes[1], sizes[2]); sizes[0] = cpu_to_be32(sizes[0]); sizes[1] = cpu_to_be32(sizes[1]); @@ -684,7 +683,7 @@ static int nbd_negotiate_handle_info(NBDClient *client, Error **errp) * tolerate all clients, regardless of alignments. */ if (client->opt == NBD_OPT_INFO && !blocksize && - blk_get_request_alignment(exp->blk) > 1) { + blk_get_request_alignment(exp->common.blk) > 1) { return nbd_negotiate_send_rep_err(client, NBD_REP_ERR_BLOCK_SIZE_REQD, errp, @@ -1556,7 +1555,7 @@ int nbd_export_new(BlockExport *blk_exp, BlockDriverState *bs, blk_set_allow_aio_context_change(blk, true); QTAILQ_INIT(&exp->clients); - exp->blk = blk; + exp->common.blk = blk; exp->name = g_strdup(name); assert(!desc || strlen(desc) <= NBD_MAX_STRING_SIZE); exp->description = g_strdup(desc); @@ -1679,15 +1678,13 @@ static void nbd_export_delete(BlockExport *blk_exp) g_free(exp->description); exp->description = NULL; - if (exp->blk) { + if (exp->common.blk) { if (exp->eject_notifier_blk) { notifier_remove(&exp->eject_notifier); blk_unref(exp->eject_notifier_blk); } - blk_remove_aio_context_notifier(exp->blk, blk_aio_attached, + blk_remove_aio_context_notifier(exp->common.blk, blk_aio_attached, blk_aio_detach, exp); - blk_unref(exp->blk); - exp->blk = NULL; } if (exp->export_bitmap) { @@ -1840,7 +1837,7 @@ static int coroutine_fn nbd_co_send_sparse_read(NBDClient *client, while (progress < size) { int64_t pnum; - int status = bdrv_block_status_above(blk_bs(exp->blk), NULL, + int status = bdrv_block_status_above(blk_bs(exp->common.blk), NULL, offset + progress, size - progress, &pnum, NULL, NULL); @@ -1872,7 +1869,8 @@ static int coroutine_fn nbd_co_send_sparse_read(NBDClient *client, stl_be_p(&chunk.length, pnum); ret = nbd_co_send_iov(client, iov, 1, errp); } else { - ret = blk_pread(exp->blk, offset + progress, data + progress, pnum); + ret = blk_pread(exp->common.blk, offset + progress, + data + progress, pnum); if (ret < 0) { error_setg_errno(errp, -ret, "reading from file failed"); break; @@ -2136,7 +2134,8 @@ static int nbd_co_receive_request(NBDRequestData *req, NBDRequest *request, } if (request->type != NBD_CMD_CACHE) { - req->data = blk_try_blockalign(client->exp->blk, request->len); + req->data = blk_try_blockalign(client->exp->common.blk, + request->len); if (req->data == NULL) { error_setg(errp, "No memory"); return -ENOMEM; @@ -2232,7 +2231,7 @@ static coroutine_fn int nbd_do_cmd_read(NBDClient *client, NBDRequest *request, /* XXX: NBD Protocol only documents use of FUA with WRITE */ if (request->flags & NBD_CMD_FLAG_FUA) { - ret = blk_co_flush(exp->blk); + ret = blk_co_flush(exp->common.blk); if (ret < 0) { return nbd_send_generic_reply(client, request->handle, ret, "flush failed", errp); @@ -2246,7 +2245,7 @@ static coroutine_fn int nbd_do_cmd_read(NBDClient *client, NBDRequest *request, data, request->len, errp); } - ret = blk_pread(exp->blk, request->from, data, request->len); + ret = blk_pread(exp->common.blk, request->from, data, request->len); if (ret < 0) { return nbd_send_generic_reply(client, request->handle, ret, "reading from file failed", errp); @@ -2281,7 +2280,7 @@ static coroutine_fn int nbd_do_cmd_cache(NBDClient *client, NBDRequest *request, assert(request->type == NBD_CMD_CACHE); - ret = blk_co_preadv(exp->blk, request->from, request->len, + ret = blk_co_preadv(exp->common.blk, request->from, request->len, NULL, BDRV_REQ_COPY_ON_READ | BDRV_REQ_PREFETCH); return nbd_send_generic_reply(client, request->handle, ret, @@ -2312,7 +2311,8 @@ static coroutine_fn int nbd_handle_request(NBDClient *client, if (request->flags & NBD_CMD_FLAG_FUA) { flags |= BDRV_REQ_FUA; } - ret = blk_pwrite(exp->blk, request->from, data, request->len, flags); + ret = blk_pwrite(exp->common.blk, request->from, data, request->len, + flags); return nbd_send_generic_reply(client, request->handle, ret, "writing to file failed", errp); @@ -2327,7 +2327,8 @@ static coroutine_fn int nbd_handle_request(NBDClient *client, if (request->flags & NBD_CMD_FLAG_FAST_ZERO) { flags |= BDRV_REQ_NO_FALLBACK; } - ret = blk_pwrite_zeroes(exp->blk, request->from, request->len, flags); + ret = blk_pwrite_zeroes(exp->common.blk, request->from, request->len, + flags); return nbd_send_generic_reply(client, request->handle, ret, "writing to file failed", errp); @@ -2336,14 +2337,14 @@ static coroutine_fn int nbd_handle_request(NBDClient *client, abort(); case NBD_CMD_FLUSH: - ret = blk_co_flush(exp->blk); + ret = blk_co_flush(exp->common.blk); return nbd_send_generic_reply(client, request->handle, ret, "flush failed", errp); case NBD_CMD_TRIM: - ret = blk_co_pdiscard(exp->blk, request->from, request->len); + ret = blk_co_pdiscard(exp->common.blk, request->from, request->len); if (ret == 0 && request->flags & NBD_CMD_FLAG_FUA) { - ret = blk_co_flush(exp->blk); + ret = blk_co_flush(exp->common.blk); } return nbd_send_generic_reply(client, request->handle, ret, "discard failed", errp); @@ -2361,7 +2362,8 @@ static coroutine_fn int nbd_handle_request(NBDClient *client, if (client->export_meta.base_allocation) { ret = nbd_co_send_block_status(client, request->handle, - blk_bs(exp->blk), request->from, + blk_bs(exp->common.blk), + request->from, request->len, dont_fragment, !client->export_meta.bitmap, NBD_META_ID_BASE_ALLOCATION, From patchwork Thu Aug 13 16:29:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11712697 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E2E11109B for ; Thu, 13 Aug 2020 16:40:13 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B6E20206A4 for ; Thu, 13 Aug 2020 16:40:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="iBimEdBY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B6E20206A4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:34706 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k6GGy-00051i-VK for patchwork-qemu-devel@patchwork.kernel.org; Thu, 13 Aug 2020 12:40:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55858) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k6G7e-0002yl-UG for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:30:34 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:38488 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1k6G7c-0001R0-05 for qemu-devel@nongnu.org; Thu, 13 Aug 2020 12:30:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597336231; 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=gKRuhYBXPjoqOPnqg2H7rVfLDGMm5mTa/Z1J9mMKyhY=; b=iBimEdBYve6FJ+wfeypk8Y9WivznEiwi2kIy2rfnRjjdKslTeAO7oILK6tc1f/TVyVh1G9 3rGb9GS7zxjpZqVvwaDSS+3Ar33d1RfUZF7ua9nIACmyLehkUqvsQ3dOMZml4lagy/eJp+ NTbMi4UEXPuGnFo1QNqbO3CIGQRJTNE= 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-497-NNZcsbLOOKCz9rx4gKJvdA-1; Thu, 13 Aug 2020 12:30:29 -0400 X-MC-Unique: NNZcsbLOOKCz9rx4gKJvdA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3F1AC1DDE0; Thu, 13 Aug 2020 16:30:28 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-113-97.ams2.redhat.com [10.36.113.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1E3575C1A3; Thu, 13 Aug 2020 16:30:26 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [RFC PATCH 22/22] block/export: Add query-block-exports Date: Thu, 13 Aug 2020 18:29:35 +0200 Message-Id: <20200813162935.210070-23-kwolf@redhat.com> In-Reply-To: <20200813162935.210070-1-kwolf@redhat.com> References: <20200813162935.210070-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=207.211.31.120; envelope-from=kwolf@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/13 03:45:42 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, 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_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" This adds a simple QMP command to query the list of block exports. Signed-off-by: Kevin Wolf --- qapi/block-export.json | 33 +++++++++++++++++++++++++++++++++ block/export/export.c | 23 +++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/qapi/block-export.json b/qapi/block-export.json index a067de2ba3..0b184bbd7c 100644 --- a/qapi/block-export.json +++ b/qapi/block-export.json @@ -226,3 +226,36 @@ ## { 'command': 'block-export-del', 'data': { 'id': 'str', '*mode': 'BlockExportRemoveMode' } } + +## +# @BlockExportInfo: +# +# Information about a single block export. +# +# @id: The unique identifier for the block export +# +# @type: This field is returned only for compatibility reasons, it should +# not be used (always returns 'unknown') +# +# @node-name: The node name of the block node that is exported +# +# @shutting-down: True if the export is shutting down (e.g. after a +# block-export-del command, but before the shutdown has +# completed) +# +# Since: 5.2 +## +{ 'struct': 'BlockExportInfo', + 'data': { 'id': 'str', + 'type': 'BlockExportType', + 'node-name': 'str', + 'shutting-down': 'bool' } } + +## +# @query-block-exports: +# +# Returns: A list of BlockExportInfo describing all block exports +# +# Since: 5.2 +## +{ 'command': 'query-block-exports', 'returns': ['BlockExportInfo'] } diff --git a/block/export/export.c b/block/export/export.c index 3cd448ba72..71d17bd440 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -272,3 +272,26 @@ void qmp_nbd_server_remove(const char *name, qmp_block_export_del(name, has_mode, mode, errp); } + +BlockExportInfoList *qmp_query_block_exports(Error **errp) +{ + BlockExportInfoList *head = NULL, **p_next = &head; + BlockExport *exp; + + QLIST_FOREACH(exp, &block_exports, next) { + BlockExportInfoList *entry = g_new0(BlockExportInfoList, 1); + BlockExportInfo *info = g_new(BlockExportInfo, 1); + *info = (BlockExportInfo) { + .id = g_strdup(exp->id), + .type = exp->drv->type, + .node_name = g_strdup(bdrv_get_node_name(blk_bs(exp->blk))), + .shutting_down = !exp->user_owned, + }; + + entry->value = info; + *p_next = entry; + p_next = &entry->next; + } + + return head; +}