Skip to content

Commit

Permalink
nvmet: Make cntlid globally unique
Browse files Browse the repository at this point in the history
We usually log the cntlid which is confusing in case
we have multiple subsystems each with it's own cntlid ida.
Instead make cntlid ida globally unique and log the initial
association.

Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Reviewed-by: Max Gurtovoy <maxg@mellanox.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@fb.com>
  • Loading branch information
Sagi Grimberg authored and Jens Axboe committed Feb 22, 2017
1 parent f64935a commit 15fbad9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
10 changes: 4 additions & 6 deletions drivers/nvme/target/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "nvmet.h"

static struct nvmet_fabrics_ops *nvmet_transports[NVMF_TRTYPE_MAX];
static DEFINE_IDA(cntlid_ida);

/*
* This read/write semaphore is used to synchronize access to configuration
Expand Down Expand Up @@ -749,7 +750,7 @@ u16 nvmet_alloc_ctrl(const char *subsysnqn, const char *hostnqn,
if (!ctrl->sqs)
goto out_free_cqs;

ret = ida_simple_get(&subsys->cntlid_ida,
ret = ida_simple_get(&cntlid_ida,
NVME_CNTLID_MIN, NVME_CNTLID_MAX,
GFP_KERNEL);
if (ret < 0) {
Expand Down Expand Up @@ -819,7 +820,7 @@ static void nvmet_ctrl_free(struct kref *ref)
flush_work(&ctrl->async_event_work);
cancel_work_sync(&ctrl->fatal_err_work);

ida_simple_remove(&subsys->cntlid_ida, ctrl->cntlid);
ida_simple_remove(&cntlid_ida, ctrl->cntlid);
nvmet_subsys_put(subsys);

kfree(ctrl->sqs);
Expand Down Expand Up @@ -918,9 +919,6 @@ struct nvmet_subsys *nvmet_subsys_alloc(const char *subsysnqn,
mutex_init(&subsys->lock);
INIT_LIST_HEAD(&subsys->namespaces);
INIT_LIST_HEAD(&subsys->ctrls);

ida_init(&subsys->cntlid_ida);

INIT_LIST_HEAD(&subsys->hosts);

return subsys;
Expand All @@ -933,7 +931,6 @@ static void nvmet_subsys_free(struct kref *ref)

WARN_ON_ONCE(!list_empty(&subsys->namespaces));

ida_destroy(&subsys->cntlid_ida);
kfree(subsys->subsysnqn);
kfree(subsys);
}
Expand Down Expand Up @@ -976,6 +973,7 @@ static void __exit nvmet_exit(void)
{
nvmet_exit_configfs();
nvmet_exit_discovery();
ida_destroy(&cntlid_ida);

BUILD_BUG_ON(sizeof(struct nvmf_disc_rsp_page_entry) != 1024);
BUILD_BUG_ON(sizeof(struct nvmf_disc_rsp_page_hdr) != 1024);
Expand Down
4 changes: 2 additions & 2 deletions drivers/nvme/target/fabrics-cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ static void nvmet_execute_admin_connect(struct nvmet_req *req)
goto out;
}

pr_info("creating controller %d for NQN %s.\n",
ctrl->cntlid, ctrl->hostnqn);
pr_info("creating controller %d for subsystem %s for NQN %s.\n",
ctrl->cntlid, ctrl->subsys->subsysnqn, ctrl->hostnqn);
req->rsp->result.u16 = cpu_to_le16(ctrl->cntlid);

out:
Expand Down
1 change: 0 additions & 1 deletion drivers/nvme/target/nvmet.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ struct nvmet_subsys {
unsigned int max_nsid;

struct list_head ctrls;
struct ida cntlid_ida;

struct list_head hosts;
bool allow_any_host;
Expand Down

0 comments on commit 15fbad9

Please sign in to comment.