From nobody Fri May 17 05:54:49 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1625564701815541.9889858211084; Tue, 6 Jul 2021 02:45:01 -0700 (PDT) Received: from localhost ([::1]:41526 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0hdU-0000D2-DR for importer@patchew.org; Tue, 06 Jul 2021 05:45:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36152) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0hTE-0000m7-VW; Tue, 06 Jul 2021 05:34:24 -0400 Received: from wout1-smtp.messagingengine.com ([64.147.123.24]:43323) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0hT1-0000dG-4n; Tue, 06 Jul 2021 05:34:24 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id D01A13200978; Tue, 6 Jul 2021 05:34:05 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Tue, 06 Jul 2021 05:34:06 -0400 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 6 Jul 2021 05:34:04 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=irrelevant.dk; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm3; bh=+Jh+0m+XuAsq5 5neFvCxnMdPNlH3OZPB+bgtvoEg4xU=; b=lKlzge3SvJkk+LizzouONiXZkz3ld vIcWivnt/iMCfXXbVkmcKkuGMQm4fn7seipZx8D9wQCM1PIuAreZ+qsZ31/pOg1d 34yqN9eVO78cDlYFIaJLnON1Fk36N+XtgrqijGNM5xoPYcKRH/Jy+N2Sf+yb5CI8 Bt9WkJaXWbaT5qHT8DMZ0XGvcnAlzWS6yTYl5krAZWuQd2JKqXCP+FUhZ5SL7L/G xKLvUFlO6p3sK7M8if71rR/i4xxxZKhz+m3gd0mw0MkTUN7NO5nrwFm/0SDauUWU oPfClzWM2ahnGv+ZQZvU1EZHJ9piDcfEBtkUnQRocoPw1MxXk9Ax9EI2g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=+Jh+0m+XuAsq55neFvCxnMdPNlH3OZPB+bgtvoEg4xU=; b=Hr1U3cCr maGq0YOEX2yI0/ctD3pWt0bURd8RdkFUmXwv22DPUtciH7SfHdjxcgihhiFkiGV/ y5yV+tBRdU44vgXZjLAlQTGQIvXdIHZK2Ux2lnQtmwKkIovrSrZhRqDVfwCKHnyw GZfLluR/uP8lmna7rGW82K5xrnTdLwkODnVpzMp9UmVg5cNe58Sre8QOi99whNuj ydEYoqkHQJw6LQq6fJqM+xGMIJiP7FxU07fBXoujMwAGC+F3Y1YQVTIaKH3DEIw5 KShtoUOSllqnjIZMRtTZc+r2q3/S5VX0WnqDijxsWIWm8AXyumfX7LUkv8ApGcxW ulrBDxoGMOa1ag== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrfeejiedgudehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefmlhgruhhs ucflvghnshgvnhcuoehithhssehirhhrvghlvghvrghnthdrughkqeenucggtffrrghtth gvrhhnpeeuleetgeeiuefhgfekfefgveejiefgteekiedtgfdtieefhfdthfefueffvefg keenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehith hssehirhhrvghlvghvrghnthdrughk X-ME-Proxy: From: Klaus Jensen To: qemu-devel@nongnu.org Subject: [PATCH 1/4] hw/nvme: remove NvmeCtrl parameter from ns setup/check functions Date: Tue, 6 Jul 2021 11:33:55 +0200 Message-Id: <20210706093358.1036387-2-its@irrelevant.dk> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210706093358.1036387-1-its@irrelevant.dk> References: <20210706093358.1036387-1-its@irrelevant.dk> MIME-Version: 1.0 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=64.147.123.24; envelope-from=its@irrelevant.dk; helo=wout1-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-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: Klaus Jensen , Keith Busch , Hannes Reinecke , qemu-block@nongnu.org, Klaus Jensen Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1625564709642100001 Content-Type: text/plain; charset="utf-8" From: Klaus Jensen The nvme_ns_setup and nvme_ns_check_constraints should not depend on the controller state. Refactor and remove it. Signed-off-by: Klaus Jensen Reviewed-by: Hannes Reinecke --- hw/nvme/nvme.h | 2 +- hw/nvme/ctrl.c | 2 +- hw/nvme/ns.c | 37 ++++++++++++++++++------------------- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/hw/nvme/nvme.h b/hw/nvme/nvme.h index 56f8eceed2ad..0868359a1e86 100644 --- a/hw/nvme/nvme.h +++ b/hw/nvme/nvme.h @@ -246,7 +246,7 @@ static inline void nvme_aor_dec_active(NvmeNamespace *n= s) } =20 void nvme_ns_init_format(NvmeNamespace *ns); -int nvme_ns_setup(NvmeCtrl *n, NvmeNamespace *ns, Error **errp); +int nvme_ns_setup(NvmeNamespace *ns, Error **errp); void nvme_ns_drain(NvmeNamespace *ns); void nvme_ns_shutdown(NvmeNamespace *ns); void nvme_ns_cleanup(NvmeNamespace *ns); diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index 629b0d38c2a2..dd1801510032 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -6498,7 +6498,7 @@ static void nvme_realize(PCIDevice *pci_dev, Error **= errp) ns =3D &n->namespace; ns->params.nsid =3D 1; =20 - if (nvme_ns_setup(n, ns, errp)) { + if (nvme_ns_setup(ns, errp)) { return; } =20 diff --git a/hw/nvme/ns.c b/hw/nvme/ns.c index 4275c3db6301..3c4f5b8c714a 100644 --- a/hw/nvme/ns.c +++ b/hw/nvme/ns.c @@ -346,8 +346,7 @@ static void nvme_zoned_ns_shutdown(NvmeNamespace *ns) assert(ns->nr_open_zones =3D=3D 0); } =20 -static int nvme_ns_check_constraints(NvmeCtrl *n, NvmeNamespace *ns, - Error **errp) +static int nvme_ns_check_constraints(NvmeNamespace *ns, Error **errp) { if (!ns->blkconf.blk) { error_setg(errp, "block backend not configured"); @@ -366,20 +365,6 @@ static int nvme_ns_check_constraints(NvmeCtrl *n, Nvme= Namespace *ns, return -1; } =20 - if (!n->subsys) { - if (ns->params.detached) { - error_setg(errp, "detached requires that the nvme device is " - "linked to an nvme-subsys device"); - return -1; - } - - if (ns->params.shared) { - error_setg(errp, "shared requires that the nvme device is " - "linked to an nvme-subsys device"); - return -1; - } - } - if (ns->params.zoned) { if (ns->params.max_active_zones) { if (ns->params.max_open_zones > ns->params.max_active_zones) { @@ -411,9 +396,9 @@ static int nvme_ns_check_constraints(NvmeCtrl *n, NvmeN= amespace *ns, return 0; } =20 -int nvme_ns_setup(NvmeCtrl *n, NvmeNamespace *ns, Error **errp) +int nvme_ns_setup(NvmeNamespace *ns, Error **errp) { - if (nvme_ns_check_constraints(n, ns, errp)) { + if (nvme_ns_check_constraints(ns, errp)) { return -1; } =20 @@ -465,7 +450,21 @@ static void nvme_ns_realize(DeviceState *dev, Error **= errp) uint32_t nsid =3D ns->params.nsid; int i; =20 - if (nvme_ns_setup(n, ns, errp)) { + if (!n->subsys) { + if (ns->params.detached) { + error_setg(errp, "detached requires that the nvme device is " + "linked to an nvme-subsys device"); + return; + } + + if (ns->params.shared) { + error_setg(errp, "shared requires that the nvme device is " + "linked to an nvme-subsys device"); + return; + } + } + + if (nvme_ns_setup(ns, errp)) { return; } =20 --=20 2.32.0 From nobody Fri May 17 05:54:49 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162556436158442.30209830566946; Tue, 6 Jul 2021 02:39:21 -0700 (PDT) Received: from localhost ([::1]:34942 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0hXz-00045N-E9 for importer@patchew.org; Tue, 06 Jul 2021 05:39:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36114) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0hT7-0000fT-Tk; Tue, 06 Jul 2021 05:34:18 -0400 Received: from wout1-smtp.messagingengine.com ([64.147.123.24]:37797) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0hT1-0000f3-Bf; Tue, 06 Jul 2021 05:34:17 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 13F693200035; Tue, 6 Jul 2021 05:34:08 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Tue, 06 Jul 2021 05:34:08 -0400 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 6 Jul 2021 05:34:06 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=irrelevant.dk; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm3; bh=ddr37AxnCS03P 2tLnWUS5hmlbD26l68AX/D5LAEdKJI=; b=lStchnYxZygCj2ByKaW/K64/aoDV2 ypVO7asTh108aH8rFZyJc+f1bxC7YqUNHAChG58H3s1wDfDmOXxsJZ9lSF+cYjWr QXSa9w1eXfN/6TRPPCF3GhPybw8Kwz+erC+z9KWvsvN0o15YxU6LlSYJvTMkzYCM FG/m53fQ+AnMLcDrQzDxVdnTLktvUWFHuUFIceZmthMirGvH78gc0QntcVwpQRY3 fS5fsZDkuvPntgNhkx/ecCeZHjOFaP8Jo9WOKnHEjt4HZ2cWr9MmNGYd8odbzrTu 2F3kvr5Gbp18jbRFd582iMfph7p4rPpVZhIVjwJpfptwfB6VTnq1owFTw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=ddr37AxnCS03P2tLnWUS5hmlbD26l68AX/D5LAEdKJI=; b=ACVpVSGx byLLknJsBIMMgVW23YuNg0h8He/OkpE28d4Im4DdEtF5qbWCBRZsQYhCASZ0DSZ4 0DQn4BMxLzI9VTMy9PXb6F0o2h2uJzj/XPDIyVpHwC+WAkk5jHStp9HhJ51BySi9 aHuDfwwjGjlxY+N7Km+B/8bnXX78m1cu3ChDe2x9oB+M6AtKobMaqXEU3MeInpJ7 qT9czw7YLSxmn3xlc6jxpIvigNsFoEuplQ34Am0cmA9YWyLZUeZbKXjQ3cQtF1mo vL9CUoA3vKhm/kVTakbnRmw6xP1b6jpfD3QvQojYafITrJPKfQKmc5K1CaIhDs2a /R9+6U+hKjr24Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrfeejiedgudehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefmlhgruhhs ucflvghnshgvnhcuoehithhssehirhhrvghlvghvrghnthdrughkqeenucggtffrrghtth gvrhhnpeeuleetgeeiuefhgfekfefgveejiefgteekiedtgfdtieefhfdthfefueffvefg keenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehith hssehirhhrvghlvghvrghnthdrughk X-ME-Proxy: From: Klaus Jensen To: qemu-devel@nongnu.org Subject: [PATCH 2/4] hw/nvme: mark nvme-subsys non-hotpluggable Date: Tue, 6 Jul 2021 11:33:56 +0200 Message-Id: <20210706093358.1036387-3-its@irrelevant.dk> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210706093358.1036387-1-its@irrelevant.dk> References: <20210706093358.1036387-1-its@irrelevant.dk> MIME-Version: 1.0 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=64.147.123.24; envelope-from=its@irrelevant.dk; helo=wout1-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-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: Klaus Jensen , Keith Busch , Hannes Reinecke , qemu-block@nongnu.org, Klaus Jensen Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1625564366664100001 Content-Type: text/plain; charset="utf-8" From: Klaus Jensen We currently lack the infrastructure to handle subsystem hotplugging, so disable it. Signed-off-by: Klaus Jensen Reviewed-by: Hannes Reinecke --- hw/nvme/subsys.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/nvme/subsys.c b/hw/nvme/subsys.c index 192223d17ca1..dc7a96862f37 100644 --- a/hw/nvme/subsys.c +++ b/hw/nvme/subsys.c @@ -61,6 +61,7 @@ static void nvme_subsys_class_init(ObjectClass *oc, void = *data) =20 dc->realize =3D nvme_subsys_realize; dc->desc =3D "Virtual NVMe subsystem"; + dc->hotpluggable =3D false; =20 device_class_set_props(dc, nvme_subsystem_props); } --=20 2.32.0 From nobody Fri May 17 05:54:49 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162556497141152.94404761918361; Tue, 6 Jul 2021 02:49:31 -0700 (PDT) Received: from localhost ([::1]:48678 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0hhp-0005DX-V2 for importer@patchew.org; Tue, 06 Jul 2021 05:49:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36160) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0hTI-0000o2-Bt; Tue, 06 Jul 2021 05:34:28 -0400 Received: from wout1-smtp.messagingengine.com ([64.147.123.24]:35723) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0hT6-0000hX-OA; Tue, 06 Jul 2021 05:34:28 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 101CC3200957; Tue, 6 Jul 2021 05:34:10 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Tue, 06 Jul 2021 05:34:10 -0400 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 6 Jul 2021 05:34:08 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=irrelevant.dk; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm3; bh=XMXOaewPT5IBD 3TV5oW0AHys5ixknygn+zoTN/HKF6w=; b=DVkxywXzOGyzm0xX+0oNPyopDJDA4 TAA6UoQnQntnzsq8jGVrYVCPtLvUhvsv3wFdnaEKXtxI/sM5CU1WJ4bBMLC0lH9y RHPbXZ0r6gvdHtN0Zi5/aJUkNWxjiWmrEjdGzeYPkuXXEI0efZ1HW4rqzWrg6H28 u126Of+ogvz6FBXmk3rlPtlTkk7sgASlGC7L6P49UTODoIshn+bfGV8Y8Qb56QMi 4Lgf2mGP1pi0Mz2lnRk/13sEDMfTCNV/YO4ALwFZ7JKyql8CknomJBRMF7HIFv5Q F3FBPE/K4WeNB+SZhEpfotTejT5H6+OhV3TOlxFAq/s8k2ui7jXy0SFkQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=XMXOaewPT5IBD3TV5oW0AHys5ixknygn+zoTN/HKF6w=; b=o8R715xb Iz9k20Gjr/3109WRRnUwIwhRhicSWmyT/BTZ82OGwmWwVfk0BPqiY3EaoChGUg04 cYd4KoybZPDYNWtdncMHU9AALs1otRtiPLs1mPxT9VXPYA/KR2+A965sf62tRKbK odkBdqSvVMBRbos13RBI33sHVWAMopVt233pdctsC8u48UR6al9BBw9NX7z25foG FkO7nXcMi/jeL8eeaX/JeG3XLRFNRG7vTkxLkUWb2g0li8osV1lsqDwF8eIZs4o3 A3SXlO4IIemf9Qh9SHcOZc0yBibs0PbLacMf0DNIQwDlb16K/YA1saparyZAg1sB GJglU2i1li7hRg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrfeejiedgudehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefmlhgruhhs ucflvghnshgvnhcuoehithhssehirhhrvghlvghvrghnthdrughkqeenucggtffrrghtth gvrhhnpeeuleetgeeiuefhgfekfefgveejiefgteekiedtgfdtieefhfdthfefueffvefg keenucevlhhushhtvghrufhiiigvpedvnecurfgrrhgrmhepmhgrihhlfhhrohhmpehith hssehirhhrvghlvghvrghnthdrughk X-ME-Proxy: From: Klaus Jensen To: qemu-devel@nongnu.org Subject: [PATCH 3/4] hw/nvme: unregister controller with subsystem at exit Date: Tue, 6 Jul 2021 11:33:57 +0200 Message-Id: <20210706093358.1036387-4-its@irrelevant.dk> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210706093358.1036387-1-its@irrelevant.dk> References: <20210706093358.1036387-1-its@irrelevant.dk> MIME-Version: 1.0 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=64.147.123.24; envelope-from=its@irrelevant.dk; helo=wout1-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-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: Klaus Jensen , Keith Busch , Hannes Reinecke , qemu-block@nongnu.org, Klaus Jensen Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1625564979777100001 Content-Type: text/plain; charset="utf-8" From: Klaus Jensen Make sure the controller is unregistered from the subsystem when device is removed. Signed-off-by: Klaus Jensen Reviewed-by: Hannes Reinecke --- hw/nvme/nvme.h | 1 + hw/nvme/ctrl.c | 4 ++++ hw/nvme/subsys.c | 5 +++++ 3 files changed, 10 insertions(+) diff --git a/hw/nvme/nvme.h b/hw/nvme/nvme.h index 0868359a1e86..c4065467d877 100644 --- a/hw/nvme/nvme.h +++ b/hw/nvme/nvme.h @@ -50,6 +50,7 @@ typedef struct NvmeSubsystem { } NvmeSubsystem; =20 int nvme_subsys_register_ctrl(NvmeCtrl *n, Error **errp); +void nvme_subsys_unregister_ctrl(NvmeSubsystem *subsys, NvmeCtrl *n); =20 static inline NvmeCtrl *nvme_subsys_ctrl(NvmeSubsystem *subsys, uint32_t cntlid) diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index dd1801510032..90e3ee2b70ee 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -6523,6 +6523,10 @@ static void nvme_exit(PCIDevice *pci_dev) nvme_ns_cleanup(ns); } =20 + if (n->subsys) { + nvme_subsys_unregister_ctrl(n->subsys, n); + } + g_free(n->cq); g_free(n->sq); g_free(n->aer_reqs); diff --git a/hw/nvme/subsys.c b/hw/nvme/subsys.c index dc7a96862f37..92caa604a280 100644 --- a/hw/nvme/subsys.c +++ b/hw/nvme/subsys.c @@ -32,6 +32,11 @@ int nvme_subsys_register_ctrl(NvmeCtrl *n, Error **errp) return cntlid; } =20 +void nvme_subsys_unregister_ctrl(NvmeSubsystem *subsys, NvmeCtrl *n) +{ + subsys->ctrls[n->cntlid] =3D NULL; +} + static void nvme_subsys_setup(NvmeSubsystem *subsys) { const char *nqn =3D subsys->params.nqn ? --=20 2.32.0 From nobody Fri May 17 05:54:49 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1625564903370514.9476555361136; Tue, 6 Jul 2021 02:48:23 -0700 (PDT) Received: from localhost ([::1]:46550 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0hgk-0003lj-9E for importer@patchew.org; Tue, 06 Jul 2021 05:48:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36150) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0hTC-0000ik-BN; Tue, 06 Jul 2021 05:34:22 -0400 Received: from wout1-smtp.messagingengine.com ([64.147.123.24]:43991) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0hT7-0000iF-B7; Tue, 06 Jul 2021 05:34:22 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 1981F320097A; Tue, 6 Jul 2021 05:34:12 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Tue, 06 Jul 2021 05:34:12 -0400 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 6 Jul 2021 05:34:10 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=irrelevant.dk; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm3; bh=SL3y1mMpJjfyY hN5UakgCbwsfdHKdoKGx0LJ4YmG/cE=; b=Xqg56m0DnxLAUX0NiHwCLouRW7Y7X Ya6ACd3K9ow9LWVizLGgxV0IvmeH2Nvpg0Nt45EvO8XYrqo2nyX6ptnZM5jFlakK iSkkU33D3Zrm1SEOuTHciRhUc34dyoPoNDXoFhnOgpkl0oKXPpHvglP9pv0vCJdD cben2EZBlBp43/HmuEQ+3w4qK/0qLnZI16yRfaPk5C78f/d8KDf7z1pqeMqdILqk wGOtRXlAzhjgUYsEyeWe/jyPtQVMMZwHhWXmt7NED5JveZ2w/7yTGUdMnIU7Mhhz ZzEEFoijAveww6gUwBhApW8HCpqQoRttEiUggP8cfZY1pMKAKuCnCLLmw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=SL3y1mMpJjfyYhN5UakgCbwsfdHKdoKGx0LJ4YmG/cE=; b=I2QMPhpA rWov7vBlvSB7L9YoHFk5GAAhepW6YivPaBINnShaXCWeRGwWdMkTULTSQD79KzrU IV1Rr1oLRolJ4C0xvO9ye0khVSFHzvO/SqmW/BzDheq+1HQzX+ltbxZUGzdR4mCw +/U1I+S06FIe1k9gQTgsTlIHAxRnkWfDbXkc7VeJWK2Jd/uFTOl9myvtEz7jAZ1h crb4uzCyeSOP2mxvb1955tlDfLFEGAdxYme4cPwLo54PHelmK4r4Gh1MaF+Slul/ 9mTcz9JPTWt4FsyX/n2ZnTspsobyLZq1z4IDuFpb4luyBwQsF5XSj2gyjrovQlle h24zZtURsguL4w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrfeejiedgudehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefmlhgruhhs ucflvghnshgvnhcuoehithhssehirhhrvghlvghvrghnthdrughkqeenucggtffrrghtth gvrhhnpeeuleetgeeiuefhgfekfefgveejiefgteekiedtgfdtieefhfdthfefueffvefg keenucevlhhushhtvghrufhiiigvpedvnecurfgrrhgrmhepmhgrihhlfhhrohhmpehith hssehirhhrvghlvghvrghnthdrughk X-ME-Proxy: From: Klaus Jensen To: qemu-devel@nongnu.org Subject: [PATCH 4/4] hw/nvme: fix controller hot unplugging Date: Tue, 6 Jul 2021 11:33:58 +0200 Message-Id: <20210706093358.1036387-5-its@irrelevant.dk> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210706093358.1036387-1-its@irrelevant.dk> References: <20210706093358.1036387-1-its@irrelevant.dk> MIME-Version: 1.0 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=64.147.123.24; envelope-from=its@irrelevant.dk; helo=wout1-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-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: Klaus Jensen , Keith Busch , Hannes Reinecke , qemu-block@nongnu.org, Klaus Jensen Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1625564912268100001 Content-Type: text/plain; charset="utf-8" From: Klaus Jensen Prior to this patch the nvme-ns devices are always children of the NvmeBus owned by the NvmeCtrl. This causes the namespaces to be unrealized when the parent device is removed. However, when subsystems are involved, this is not what we want since the namespaces may be attached to other controllers as well. This patch adds an additional NvmeBus on the subsystem device. When nvme-ns devices are realized, if the parent controller device is linked to a subsystem, the parent bus is set to the subsystem one instead. This makes sure that namespaces are kept alive and not unrealized. Signed-off-by: Klaus Jensen --- hw/nvme/nvme.h | 18 ++++++++++-------- hw/nvme/ctrl.c | 8 +++++--- hw/nvme/ns.c | 32 +++++++++++++++++++++++++------- hw/nvme/subsys.c | 4 ++++ 4 files changed, 44 insertions(+), 18 deletions(-) diff --git a/hw/nvme/nvme.h b/hw/nvme/nvme.h index c4065467d877..9401e212f9f7 100644 --- a/hw/nvme/nvme.h +++ b/hw/nvme/nvme.h @@ -33,12 +33,21 @@ QEMU_BUILD_BUG_ON(NVME_MAX_NAMESPACES > NVME_NSID_BROAD= CAST - 1); typedef struct NvmeCtrl NvmeCtrl; typedef struct NvmeNamespace NvmeNamespace; =20 +#define TYPE_NVME_BUS "nvme-bus" +OBJECT_DECLARE_SIMPLE_TYPE(NvmeBus, NVME_BUS) + +typedef struct NvmeBus { + BusState parent_bus; + bool is_subsys; +} NvmeBus; + #define TYPE_NVME_SUBSYS "nvme-subsys" #define NVME_SUBSYS(obj) \ OBJECT_CHECK(NvmeSubsystem, (obj), TYPE_NVME_SUBSYS) =20 typedef struct NvmeSubsystem { DeviceState parent_obj; + NvmeBus bus; uint8_t subnqn[256]; =20 NvmeCtrl *ctrls[NVME_MAX_CONTROLLERS]; @@ -365,13 +374,6 @@ typedef struct NvmeCQueue { QTAILQ_HEAD(, NvmeRequest) req_list; } NvmeCQueue; =20 -#define TYPE_NVME_BUS "nvme-bus" -#define NVME_BUS(obj) OBJECT_CHECK(NvmeBus, (obj), TYPE_NVME_BUS) - -typedef struct NvmeBus { - BusState parent_bus; -} NvmeBus; - #define TYPE_NVME "nvme" #define NVME(obj) \ OBJECT_CHECK(NvmeCtrl, (obj), TYPE_NVME) @@ -463,7 +465,7 @@ typedef struct NvmeCtrl { =20 static inline NvmeNamespace *nvme_ns(NvmeCtrl *n, uint32_t nsid) { - if (!nsid || nsid > NVME_MAX_NAMESPACES) { + if (!n || !nsid || nsid > NVME_MAX_NAMESPACES) { return NULL; } =20 diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c index 90e3ee2b70ee..7c8fca36d9a5 100644 --- a/hw/nvme/ctrl.c +++ b/hw/nvme/ctrl.c @@ -6516,11 +6516,13 @@ static void nvme_exit(PCIDevice *pci_dev) =20 for (i =3D 1; i <=3D NVME_MAX_NAMESPACES; i++) { ns =3D nvme_ns(n, i); - if (!ns) { - continue; + if (ns) { + ns->attached--; } + } =20 - nvme_ns_cleanup(ns); + if (n->subsys) { + nvme_subsys_unregister_ctrl(n->subsys, n); } =20 if (n->subsys) { diff --git a/hw/nvme/ns.c b/hw/nvme/ns.c index 3c4f5b8c714a..612a2786d75d 100644 --- a/hw/nvme/ns.c +++ b/hw/nvme/ns.c @@ -444,13 +444,29 @@ void nvme_ns_cleanup(NvmeNamespace *ns) static void nvme_ns_realize(DeviceState *dev, Error **errp) { NvmeNamespace *ns =3D NVME_NS(dev); - BusState *s =3D qdev_get_parent_bus(dev); - NvmeCtrl *n =3D NVME(s->parent); - NvmeSubsystem *subsys =3D n->subsys; + BusState *qbus =3D qdev_get_parent_bus(dev); + NvmeBus *bus =3D NVME_BUS(qbus); + NvmeCtrl *n =3D NULL; + NvmeSubsystem *subsys =3D NULL; uint32_t nsid =3D ns->params.nsid; int i; =20 - if (!n->subsys) { + if (bus->is_subsys) { + subsys =3D NVME_SUBSYS(qbus->parent); + } else { + n =3D NVME(qbus->parent); + subsys =3D n->subsys; + } + + if (subsys) { + /* + * If this namespace belongs to a subsystem (through a link on the + * controller device), reparent the device. + */ + if (!qdev_set_parent_bus(dev, &subsys->bus.parent_bus, errp)) { + return; + } + } else { if (ns->params.detached) { error_setg(errp, "detached requires that the nvme device is " "linked to an nvme-subsys device"); @@ -470,7 +486,7 @@ static void nvme_ns_realize(DeviceState *dev, Error **e= rrp) =20 if (!nsid) { for (i =3D 1; i <=3D NVME_MAX_NAMESPACES; i++) { - if (nvme_ns(n, i) || nvme_subsys_ns(subsys, i)) { + if (nvme_subsys_ns(subsys, i) || nvme_ns(n, i)) { continue; } =20 @@ -483,7 +499,7 @@ static void nvme_ns_realize(DeviceState *dev, Error **e= rrp) return; } } else { - if (nvme_ns(n, nsid) || nvme_subsys_ns(subsys, nsid)) { + if (nvme_subsys_ns(subsys, nsid) || nvme_ns(n, nsid)) { error_setg(errp, "namespace id '%d' already allocated", nsid); return; } @@ -509,7 +525,9 @@ static void nvme_ns_realize(DeviceState *dev, Error **e= rrp) } } =20 - nvme_attach_ns(n, ns); + if (n) { + nvme_attach_ns(n, ns); + } } =20 static Property nvme_ns_props[] =3D { diff --git a/hw/nvme/subsys.c b/hw/nvme/subsys.c index 92caa604a280..fb7c3a7c55fc 100644 --- a/hw/nvme/subsys.c +++ b/hw/nvme/subsys.c @@ -50,6 +50,10 @@ static void nvme_subsys_realize(DeviceState *dev, Error = **errp) { NvmeSubsystem *subsys =3D NVME_SUBSYS(dev); =20 + qbus_create_inplace(&subsys->bus, sizeof(NvmeBus), TYPE_NVME_BUS, dev, + dev->id); + subsys->bus.is_subsys =3D true; + nvme_subsys_setup(subsys); } =20 --=20 2.32.0