Commit 6f53e73b authored by Sagi Grimberg's avatar Sagi Grimberg Committed by Christoph Hellwig
Browse files

nvmet: protect discovery change log event list iteration



When we iterate on the discovery subsystem controllers
we need to protect against concurrent mutations to it.

Signed-off-by: default avatarSagi Grimberg <sagi@grimberg.me>
Reviewed-by: default avatarMinwoo Im <minwoo.im@samsung.com>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
parent 893a74b7
Loading
Loading
Loading
Loading
+5 −0
Original line number Original line Diff line number Diff line
@@ -30,14 +30,17 @@ void nvmet_port_disc_changed(struct nvmet_port *port,
{
{
	struct nvmet_ctrl *ctrl;
	struct nvmet_ctrl *ctrl;


	lockdep_assert_held(&nvmet_config_sem);
	nvmet_genctr++;
	nvmet_genctr++;


	mutex_lock(&nvmet_disc_subsys->lock);
	list_for_each_entry(ctrl, &nvmet_disc_subsys->ctrls, subsys_entry) {
	list_for_each_entry(ctrl, &nvmet_disc_subsys->ctrls, subsys_entry) {
		if (subsys && !nvmet_host_allowed(subsys, ctrl->hostnqn))
		if (subsys && !nvmet_host_allowed(subsys, ctrl->hostnqn))
			continue;
			continue;


		__nvmet_disc_changed(port, ctrl);
		__nvmet_disc_changed(port, ctrl);
	}
	}
	mutex_unlock(&nvmet_disc_subsys->lock);
}
}


static void __nvmet_subsys_disc_changed(struct nvmet_port *port,
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;
	struct nvmet_ctrl *ctrl;


	mutex_lock(&nvmet_disc_subsys->lock);
	list_for_each_entry(ctrl, &nvmet_disc_subsys->ctrls, subsys_entry) {
	list_for_each_entry(ctrl, &nvmet_disc_subsys->ctrls, subsys_entry) {
		if (host && strcmp(nvmet_host_name(host), ctrl->hostnqn))
		if (host && strcmp(nvmet_host_name(host), ctrl->hostnqn))
			continue;
			continue;


		__nvmet_disc_changed(port, ctrl);
		__nvmet_disc_changed(port, ctrl);
	}
	}
	mutex_unlock(&nvmet_disc_subsys->lock);
}
}


void nvmet_subsys_disc_changed(struct nvmet_subsys *subsys,
void nvmet_subsys_disc_changed(struct nvmet_subsys *subsys,