From nobody Tue Feb 10 04:03:46 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1597336736; cv=none; d=zohomail.com; s=zohoarc; b=kwya42lavbTOp3pWwJX4SWOYOK3VnM4fB193DITa3pLAwsXeBOvWv5Srs96n1SMNycdOS6jysOAdxi/PUaJChzlr7sJzRV2ItiID8GBbnvbXA4w64VmPDyq2ujw0+pqL2Us9G6A3tu3eStK5TVjL+UgU1EGgNlU7oS+iKsKjvd4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597336736; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=YXn53EsmWf/+7NHPAoFuqEH3vFShL3ZRTa7pelF9T9A=; b=QCTE7aXCs0763i5b39f1S15jg+ueRAhnn8vWWRQDL3HUZkG3a59bG6DSCzGSmhTp5V6WXPBMaHpnkwJKF+AWB+AmGZfuwqvrwttQOJ/Swx3rPwl7Qys6So6uU2MWkaLMochVNIqircU8njhZJvDblnwot0y2ylb5n4GpQwaILv0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1597336736704326.7371347110077; Thu, 13 Aug 2020 09:38:56 -0700 (PDT) Received: from localhost ([::1]:53812 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k6GFj-0001JM-D8 for importer@patchew.org; Thu, 13 Aug 2020 12:38:55 -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 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 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) 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= X-MC-Unique: 638O3ZJ_NkaX3cZGVUAojQ-1 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The 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; =20 + /* + * True if one of the references in refcount belongs to the user. Afte= r the + * user has dropped their reference, they may not e.g. remove the same + * export a second time (which would decrease the refcount without hav= ing + * 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, Erro= r **errp) *exp =3D (BlockExport) { .drv =3D &blk_exp_nbd, .refcount =3D 1, + .user_owned =3D true, .id =3D g_strdup(export->id), }; =20 @@ -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 =3D false; + blk_exp_unref(exp); } =20 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, BlockExportOpt= ions *exp_args, goto out; } =20 - /* 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 ca= n drop - * the strong reference that is @exp. */ - blk_exp_unref((BlockExport*) exp); - ret =3D 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, BlockDriverS= tate *bs, =20 blk_add_aio_context_notifier(blk, blk_aio_attached, blk_aio_detach, ex= p); =20 - blk_exp_ref(&exp->common); QTAILQ_INSERT_TAIL(&exports, exp, next); =20 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 =3D NULL; QTAILQ_REMOVE(&exports, exp, next); --=20 2.25.4