Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp818799rdb; Wed, 6 Dec 2023 00:13:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IF2SdskVNg4X/db73b+EUVqSYiMEb0yUyIGm9qgJlbSgNhYryweAXcC1yUP9E3a0sRMiadS X-Received: by 2002:a05:6a00:4189:b0:6cd:fe6e:ac9b with SMTP id ca9-20020a056a00418900b006cdfe6eac9bmr818010pfb.0.1701850412593; Wed, 06 Dec 2023 00:13:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701850412; cv=none; d=google.com; s=arc-20160816; b=wlxfBQGSnDDlETjMkld3CQHzyZS5h+kEbTAyJBr2NZTPfIp22eD3MNcNBuM/CHSw2n t/jTzE/WgSpzo9NO7ZtT1lGMT85VdgpyhF3PH5Str8iTDxvSbigEpKS9AkNbQiL3cVtc x3U8mX+yO1A8ty1YkDaW/nHU5zLay9d2cI5rYYFuvy8lOWZQKIe9ozPohhLo/IcfrMWN ol4U8XTNm+gSepfxzU8ovXUA99FVWHnW0i9n1Efe9UP7JUbmQveSNTiSOIueZDjteruR fp0f3B93W6YccfIg7pejqBvf64FB/AtGTjX7uo9gkghRXyo7Yx/dCZHXDz0RrqKIEVfy S+Gg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=exKo8DIzZ+miKKVL+bdjhfUUSTp5ERmlwY3HNY9Kw6M=; fh=DJbT8ne4Efjik5M2lT8AzCh46QRFyMX3tPkPd3UGLh8=; b=ZoGDrbL03rM1fo5Awanq32MHrl2q7n0JLFzI+z8HBP6uWQPRyGlTRKwpZCEHYSfzW2 nt8QybgJCL0lzT+nc1TV/VRq71WXNqc27CxSg5k4R+LLq0BaEJMxBk/FA36SDp48JIoN +l0iw64Luv3RvvWF7X8eNZWZ30Vv5LfoZYSffIBu/pcCkoppPvSO6zBd1iQ7sS6iYGuL /fpnQomvek7qIlneKVygwzIa0v2Sz2v2xxMdSrpggtq87Gbf/A6QQPK3ohJx6Z8l4E7V TkCA7b230KDfJTshjurfm0TWhNYhMbAOL7Ol9DSY/BbyNXKflgaecl60WpHPClPbWJep 7Z2g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id y33-20020a634961000000b005b896ecd1efsi11296413pgk.172.2023.12.06.00.13.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 00:13:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 8789780BD3A1; Wed, 6 Dec 2023 00:13:20 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377121AbjLFIMu (ORCPT + 99 others); Wed, 6 Dec 2023 03:12:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230412AbjLFIMq (ORCPT ); Wed, 6 Dec 2023 03:12:46 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 203ADD3 for ; Wed, 6 Dec 2023 00:12:52 -0800 (PST) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 4ADB21FCFA; Wed, 6 Dec 2023 08:12:50 +0000 (UTC) Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 378F1133DD; Wed, 6 Dec 2023 08:12:50 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id EekhDAItcGUVHgAAn2gu4w (envelope-from ); Wed, 06 Dec 2023 08:12:50 +0000 From: Daniel Wagner To: linux-nvme@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Keith Busch , Christoph Hellwig , Sagi Grimberg , Hannes Reinecke , Daniel Wagner Subject: [PATCH v3 2/4] nvme: initialize head before namespace Date: Wed, 6 Dec 2023 09:12:42 +0100 Message-ID: <20231206081244.32733-3-dwagner@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231206081244.32733-1-dwagner@suse.de> References: <20231206081244.32733-1-dwagner@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spamd-Bar: +++++++++++ Authentication-Results: smtp-out2.suse.de; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=suse.de (policy=none); spf=softfail (smtp-out2.suse.de: 2a07:de40:b281:104:10:150:64:98 is neither permitted nor denied by domain of dwagner@suse.de) smtp.mailfrom=dwagner@suse.de X-Rspamd-Server: rspamd2 X-Spamd-Result: default: False [11.76 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:98:from]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; NEURAL_SPAM_SHORT(2.97)[0.989]; BROKEN_CONTENT_TYPE(1.50)[]; R_SPF_SOFTFAIL(4.60)[~all:c]; RCVD_COUNT_THREE(0.00)[3]; MX_GOOD(-0.01)[]; RCPT_COUNT_SEVEN(0.00)[7]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(2.20)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%]; DMARC_POLICY_SOFTFAIL(0.10)[suse.de : No valid SPF, No valid DKIM,none] X-Spam-Score: 11.76 X-Rspamd-Queue-Id: 4ADB21FCFA X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 06 Dec 2023 00:13:20 -0800 (PST) In preparation to use struct nvme_ns_head pointers instead of a struct nvme_ns pointers, initialize the head pointer before we create the disk. This allows us to attach the head as private data to the disk object. Signed-off-by: Daniel Wagner --- drivers/nvme/host/core.c | 46 ++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 900c045fcae0..1fabe1b81de0 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -3474,10 +3474,11 @@ static int nvme_global_check_duplicate_ids(struct nvme_subsystem *this, return ret; } -static int nvme_init_ns_head(struct nvme_ns *ns, struct nvme_ns_info *info) +static int nvme_init_ns_head(struct nvme_ctrl *ctrl, + struct nvme_ns_info *info, + struct nvme_ns_head **head) { - struct nvme_ctrl *ctrl = ns->ctrl; - struct nvme_ns_head *head = NULL; + struct nvme_ns_head *h = NULL; int ret; ret = nvme_global_check_duplicate_ids(ctrl->subsys, &info->ids); @@ -3499,8 +3500,8 @@ static int nvme_init_ns_head(struct nvme_ns *ns, struct nvme_ns_info *info) * up at any time. */ nvme_print_device_info(ctrl); - if ((ns->ctrl->ops->flags & NVME_F_FABRICS) || /* !PCIe */ - ((ns->ctrl->subsys->cmic & NVME_CTRL_CMIC_MULTI_CTRL) && + if ((ctrl->ops->flags & NVME_F_FABRICS) || /* !PCIe */ + ((ctrl->subsys->cmic & NVME_CTRL_CMIC_MULTI_CTRL) && info->is_shared)) { dev_err(ctrl->device, "ignoring nsid %d because of duplicate IDs\n", @@ -3519,8 +3520,8 @@ static int nvme_init_ns_head(struct nvme_ns *ns, struct nvme_ns_info *info) } mutex_lock(&ctrl->subsys->lock); - head = nvme_find_ns_head(ctrl, info->nsid); - if (!head) { + h = nvme_find_ns_head(ctrl, info->nsid); + if (!h) { ret = nvme_subsys_check_duplicate_ids(ctrl->subsys, &info->ids); if (ret) { dev_err(ctrl->device, @@ -3528,20 +3529,20 @@ static int nvme_init_ns_head(struct nvme_ns *ns, struct nvme_ns_info *info) info->nsid); goto out_unlock; } - head = nvme_alloc_ns_head(ctrl, info); - if (IS_ERR(head)) { - ret = PTR_ERR(head); + h = nvme_alloc_ns_head(ctrl, info); + if (IS_ERR(h)) { + ret = PTR_ERR(h); goto out_unlock; } } else { ret = -EINVAL; - if (!info->is_shared || !head->shared) { + if (!info->is_shared || !h->shared) { dev_err(ctrl->device, "Duplicate unshared namespace %d\n", info->nsid); goto out_put_ns_head; } - if (!nvme_ns_ids_equal(&head->ids, &info->ids)) { + if (!nvme_ns_ids_equal(&h->ids, &info->ids)) { dev_err(ctrl->device, "IDs don't match for shared namespace %d\n", info->nsid); @@ -3557,13 +3558,12 @@ static int nvme_init_ns_head(struct nvme_ns *ns, struct nvme_ns_info *info) } } - list_add_tail_rcu(&ns->siblings, &head->list); - ns->head = head; + *head = h; mutex_unlock(&ctrl->subsys->lock); return 0; out_put_ns_head: - nvme_put_ns_head(head); + nvme_put_ns_head(h); out_unlock: mutex_unlock(&ctrl->subsys->lock); return ret; @@ -3615,15 +3615,22 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, struct nvme_ns_info *info) if (!ns) return; + if (nvme_init_ns_head(ctrl, info, &ns->head)) + goto out_free_ns; + disk = blk_mq_alloc_disk(ctrl->tagset, ns); if (IS_ERR(disk)) - goto out_free_ns; + goto out_free_head; disk->fops = &nvme_bdev_ops; disk->private_data = ns; ns->disk = disk; ns->queue = disk->queue; + mutex_lock(&ctrl->subsys->lock); + list_add_tail_rcu(&ns->siblings, &ns->head->list); + mutex_unlock(&ctrl->subsys->lock); + if (ctrl->opts && ctrl->opts->data_digest) blk_queue_flag_set(QUEUE_FLAG_STABLE_WRITES, ns->queue); @@ -3635,9 +3642,6 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, struct nvme_ns_info *info) ns->ctrl = ctrl; kref_init(&ns->kref); - if (nvme_init_ns_head(ns, info)) - goto out_cleanup_disk; - /* * If multipathing is enabled, the device name for all disks and not * just those that represent shared namespaces needs to be based on the @@ -3691,9 +3695,9 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, struct nvme_ns_info *info) if (list_empty(&ns->head->list)) list_del_init(&ns->head->entry); mutex_unlock(&ctrl->subsys->lock); - nvme_put_ns_head(ns->head); - out_cleanup_disk: put_disk(disk); + out_free_head: + nvme_put_ns_head(ns->head); out_free_ns: kfree(ns); } -- 2.43.0