Re: [PATCH 6/9] nvme: track subsystems
From: Keith Busch <hidden>
Date: 2017-09-21 22:52:19
Also in:
linux-nvme
On Mon, Sep 18, 2017 at 04:14:50PM -0700, Christoph Hellwig wrote:
+static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
+{
+ struct nvme_subsystem *subsys, *found;
+
+ subsys = kzalloc(sizeof(*subsys), GFP_KERNEL);
+ if (!subsys)
+ return -ENOMEM;
+ INIT_LIST_HEAD(&subsys->ctrls);
+ kref_init(&subsys->ref);
+ nvme_init_subnqn(subsys, ctrl, id);
+ mutex_init(&subsys->lock);
+
+ mutex_lock(&nvme_subsystems_lock);
+ found = __nvme_find_get_subsystem(subsys->subnqn);
+ if (found) {
+ /*
+ * Verify that the subsystem actually supports multiple
+ * controllers, else bail out.
+ */
+ kfree(subsys);
+ if (!(id->cmic & (1 << 1))) {
+ dev_err(ctrl->device,
+ "ignoring ctrl due to duplicate subnqn (%s).\n",
+ found->subnqn);
+ mutex_unlock(&nvme_subsystems_lock);
+ return -EINVAL;
+ }
+
+ subsys = found;
+ } else {
+ list_add_tail(&subsys->entry, &nvme_subsystems);
+ }
+
+ ctrl->subsys = subsys;
+ mutex_unlock(&nvme_subsystems_lock);
+
+ mutex_lock(&subsys->lock);
+ list_add_tail(&ctrl->subsys_entry, &subsys->ctrls);
+ mutex_unlock(&subsys->lock);This function is called every time nvme_init_identify is called, which happens on every controller reset. The controller reset does not remove itself from the subsystem list of controllers, so its entry is getting doubly added after a controller reset.