From: hch@lst.de (Christoph Hellwig)
Subject: [PATCH 07/10] nvmet: track and limit the number of namespaces per subsystem
Date: Wed, 6 Jun 2018 16:33:08 +0200 [thread overview]
Message-ID: <20180606143311.23076-8-hch@lst.de> (raw)
In-Reply-To: <20180606143311.23076-1-hch@lst.de>
TP 4004 introduces a new 'Maximum Number of Allocated Namespaces' field
in the Identify controller data to help the host size resources. Put
an upper limit on the supported namespaces to be able to support this
value as supporting 32-bits worth of namespaces would lead to very
large buffers. The limit is completely arbitrary at this point.
Signed-off-by: Christoph Hellwig <hch at lst.de>
---
drivers/nvme/target/admin-cmd.c | 1 +
drivers/nvme/target/core.c | 8 +++++++-
drivers/nvme/target/nvmet.h | 8 ++++++++
3 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/drivers/nvme/target/admin-cmd.c b/drivers/nvme/target/admin-cmd.c
index 962532842769..6912548eefc3 100644
--- a/drivers/nvme/target/admin-cmd.c
+++ b/drivers/nvme/target/admin-cmd.c
@@ -220,6 +220,7 @@ static void nvmet_execute_identify_ctrl(struct nvmet_req *req)
id->maxcmd = cpu_to_le16(NVMET_MAX_CMD);
id->nn = cpu_to_le32(ctrl->subsys->max_nsid);
+ id->mnan = cpu_to_le32(NVMET_MAX_NAMESPACES);
id->oncs = cpu_to_le16(NVME_CTRL_ONCS_DSM |
NVME_CTRL_ONCS_WRITE_ZEROES);
diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index a03da764ecae..f691ae47c83a 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -332,9 +332,13 @@ static void nvmet_ns_dev_disable(struct nvmet_ns *ns)
int nvmet_ns_enable(struct nvmet_ns *ns)
{
struct nvmet_subsys *subsys = ns->subsys;
- int ret = 0;
+ int ret;
mutex_lock(&subsys->lock);
+ ret = -EMFILE;
+ if (subsys->nr_namespaces == NVMET_MAX_NAMESPACES)
+ goto out_unlock;
+ ret = 0;
if (ns->enabled)
goto out_unlock;
@@ -369,6 +373,7 @@ int nvmet_ns_enable(struct nvmet_ns *ns)
list_add_tail_rcu(&ns->dev_link, &old->dev_link);
}
+ subsys->nr_namespaces++;
nvmet_ns_changed(subsys, ns->nsid);
ns->enabled = true;
@@ -409,6 +414,7 @@ void nvmet_ns_disable(struct nvmet_ns *ns)
percpu_ref_exit(&ns->ref);
mutex_lock(&subsys->lock);
+ subsys->nr_namespaces--;
nvmet_ns_changed(subsys, ns->nsid);
nvmet_ns_dev_disable(ns);
out_unlock:
diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
index 480dfe10fad9..bd24e2b7317d 100644
--- a/drivers/nvme/target/nvmet.h
+++ b/drivers/nvme/target/nvmet.h
@@ -166,6 +166,7 @@ struct nvmet_subsys {
struct kref ref;
struct list_head namespaces;
+ unsigned int nr_namespaces;
unsigned int max_nsid;
struct list_head ctrls;
@@ -357,6 +358,13 @@ u32 nvmet_get_log_page_len(struct nvme_command *cmd);
#define NVMET_QUEUE_SIZE 1024
#define NVMET_NR_QUEUES 128
#define NVMET_MAX_CMD NVMET_QUEUE_SIZE
+
+/*
+ * Nice round number that makes a list of nsids fit into a page.
+ * Should become tunable at some point in the future.
+ */
+#define NVMET_MAX_NAMESPACES 1024
+
#define NVMET_KAS 10
#define NVMET_DISC_KATO 120
--
2.14.2
next prev parent reply other threads:[~2018-06-06 14:33 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-06 14:33 draft ANA support v3 Christoph Hellwig
2018-06-06 14:33 ` [PATCH 01/10] nvme.h: add support for the log specific field Christoph Hellwig
2018-06-07 7:27 ` Johannes Thumshirn
2018-06-07 7:58 ` Hannes Reinecke
2018-06-07 12:34 ` Sagi Grimberg
2018-06-06 14:33 ` [PATCH 02/10] nvme.h: add ANA definitions Christoph Hellwig
2018-06-07 7:59 ` Hannes Reinecke
2018-06-07 8:30 ` Johannes Thumshirn
2018-06-07 12:35 ` Sagi Grimberg
2018-06-06 14:33 ` [PATCH 03/10] nvme: simplify the API for getting log pages Christoph Hellwig
2018-06-07 7:39 ` Johannes Thumshirn
2018-06-07 7:59 ` Hannes Reinecke
2018-06-07 12:35 ` Sagi Grimberg
2018-06-06 14:33 ` [PATCH 04/10] nvme: remove nvme_req_needs_failover Christoph Hellwig
2018-06-07 7:40 ` Johannes Thumshirn
2018-06-07 8:01 ` Hannes Reinecke
2018-06-07 11:57 ` Christoph Hellwig
2018-06-07 12:36 ` Sagi Grimberg
2018-06-06 14:33 ` [PATCH 05/10] nvme: add ANA support Christoph Hellwig
2018-06-07 8:01 ` Hannes Reinecke
2018-06-07 12:49 ` Sagi Grimberg
2018-06-07 13:05 ` Christoph Hellwig
2018-06-07 13:55 ` Christoph Hellwig
2018-06-06 14:33 ` [PATCH 06/10] nvme: don't set gendisks live that don't have an I/O capable path Christoph Hellwig
2018-06-06 14:33 ` Christoph Hellwig [this message]
2018-06-07 7:54 ` [PATCH 07/10] nvmet: track and limit the number of namespaces per subsystem Johannes Thumshirn
2018-06-07 8:02 ` Hannes Reinecke
2018-06-06 14:33 ` [PATCH 08/10] nvmet: add minimal ANA support Christoph Hellwig
2018-06-07 8:03 ` Hannes Reinecke
2018-06-07 12:52 ` Sagi Grimberg
2018-06-06 14:33 ` [PATCH 09/10] nvmet: support configuring ANA groups Christoph Hellwig
2018-06-07 8:09 ` Hannes Reinecke
2018-06-07 12:02 ` Christoph Hellwig
2018-06-07 12:58 ` Sagi Grimberg
2018-06-07 13:08 ` Christoph Hellwig
2018-06-06 14:33 ` [PATCH 10/10] host fold Christoph Hellwig
2018-06-06 14:46 ` Christoph Hellwig
2018-06-06 15:18 ` Hannes Reinecke
2018-06-07 12:34 ` draft ANA support v3 Sagi Grimberg
2018-06-07 13:06 ` Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180606143311.23076-8-hch@lst.de \
--to=hch@lst.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox