nvmet: protect discovery change log event list iteration
authorSagi Grimberg <sagi@grimberg.me>
Mon, 29 Apr 2019 23:28:19 +0000 (16:28 -0700)
committerChristoph Hellwig <hch@lst.de>
Wed, 1 May 2019 13:18:47 +0000 (09:18 -0400)
When we iterate on the discovery subsystem controllers
we need to protect against concurrent mutations to it.

Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Minwoo Im <minwoo.im@samsung.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
drivers/nvme/target/discovery.c

index e8e09266bfa5ff3594bde9a3a78f4815c7a0c232..5baf269f3f8a055705357f190127e3649f9026e8 100644 (file)
@@ -30,14 +30,17 @@ void nvmet_port_disc_changed(struct nvmet_port *port,
 {
        struct nvmet_ctrl *ctrl;
 
+       lockdep_assert_held(&nvmet_config_sem);
        nvmet_genctr++;
 
+       mutex_lock(&nvmet_disc_subsys->lock);
        list_for_each_entry(ctrl, &nvmet_disc_subsys->ctrls, subsys_entry) {
                if (subsys && !nvmet_host_allowed(subsys, ctrl->hostnqn))
                        continue;
 
                __nvmet_disc_changed(port, ctrl);
        }
+       mutex_unlock(&nvmet_disc_subsys->lock);
 }
 
 static void __nvmet_subsys_disc_changed(struct nvmet_port *port,
@@ -46,12 +49,14 @@ static void __nvmet_subsys_disc_changed(struct nvmet_port *port,
 {
        struct nvmet_ctrl *ctrl;
 
+       mutex_lock(&nvmet_disc_subsys->lock);
        list_for_each_entry(ctrl, &nvmet_disc_subsys->ctrls, subsys_entry) {
                if (host && strcmp(nvmet_host_name(host), ctrl->hostnqn))
                        continue;
 
                __nvmet_disc_changed(port, ctrl);
        }
+       mutex_unlock(&nvmet_disc_subsys->lock);
 }
 
 void nvmet_subsys_disc_changed(struct nvmet_subsys *subsys,