Commit 253928ee authored by Sagi Grimberg's avatar Sagi Grimberg Committed by Jens Axboe

nvmet: allow host connect even if no allowed subsystems are exported

It is perfectly valid that a host connects to a discovery subsystem
and gets an empty discovery log page since no subsystems are
provisioned to it. No reason to disallow connecting to the discovery
subsystem all together.
Signed-off-by: default avatarSagi Grimberg <sagi@grimberg.me>
Reviewed-by: default avatarJay Sternberg <jay.e.sternberg@intel.com>
Reviewed-by: default avatarPhil Cayton <phil.cayton@intel.com>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 6a8ec0ac
...@@ -1032,46 +1032,26 @@ u16 nvmet_check_ctrl_status(struct nvmet_req *req, struct nvme_command *cmd) ...@@ -1032,46 +1032,26 @@ u16 nvmet_check_ctrl_status(struct nvmet_req *req, struct nvme_command *cmd)
return 0; return 0;
} }
static bool __nvmet_host_allowed(struct nvmet_subsys *subsys, bool nvmet_host_allowed(struct nvmet_subsys *subsys, const char *hostnqn)
const char *hostnqn)
{ {
struct nvmet_host_link *p; struct nvmet_host_link *p;
lockdep_assert_held(&nvmet_config_sem);
if (subsys->allow_any_host) if (subsys->allow_any_host)
return true; return true;
list_for_each_entry(p, &subsys->hosts, entry) { if (subsys->type == NVME_NQN_DISC) /* allow all access to disc subsys */
if (!strcmp(nvmet_host_name(p->host), hostnqn))
return true; return true;
}
return false;
}
static bool nvmet_host_discovery_allowed(struct nvmet_req *req,
const char *hostnqn)
{
struct nvmet_subsys_link *s;
list_for_each_entry(s, &req->port->subsystems, entry) { list_for_each_entry(p, &subsys->hosts, entry) {
if (__nvmet_host_allowed(s->subsys, hostnqn)) if (!strcmp(nvmet_host_name(p->host), hostnqn))
return true; return true;
} }
return false; return false;
} }
bool nvmet_host_allowed(struct nvmet_req *req, struct nvmet_subsys *subsys,
const char *hostnqn)
{
lockdep_assert_held(&nvmet_config_sem);
if (subsys->type == NVME_NQN_DISC)
return nvmet_host_discovery_allowed(req, hostnqn);
else
return __nvmet_host_allowed(subsys, hostnqn);
}
/* /*
* Note: ctrl->subsys->lock should be held when calling this function * Note: ctrl->subsys->lock should be held when calling this function
*/ */
...@@ -1122,7 +1102,7 @@ u16 nvmet_alloc_ctrl(const char *subsysnqn, const char *hostnqn, ...@@ -1122,7 +1102,7 @@ u16 nvmet_alloc_ctrl(const char *subsysnqn, const char *hostnqn,
status = NVME_SC_CONNECT_INVALID_PARAM | NVME_SC_DNR; status = NVME_SC_CONNECT_INVALID_PARAM | NVME_SC_DNR;
down_read(&nvmet_config_sem); down_read(&nvmet_config_sem);
if (!nvmet_host_allowed(req, subsys, hostnqn)) { if (!nvmet_host_allowed(subsys, hostnqn)) {
pr_info("connect by host %s for subsystem %s not allowed\n", pr_info("connect by host %s for subsystem %s not allowed\n",
hostnqn, subsysnqn); hostnqn, subsysnqn);
req->rsp->result.u32 = IPO_IATTR_CONNECT_DATA(hostnqn); req->rsp->result.u32 = IPO_IATTR_CONNECT_DATA(hostnqn);
......
...@@ -107,7 +107,7 @@ static void nvmet_execute_get_disc_log_page(struct nvmet_req *req) ...@@ -107,7 +107,7 @@ static void nvmet_execute_get_disc_log_page(struct nvmet_req *req)
down_read(&nvmet_config_sem); down_read(&nvmet_config_sem);
list_for_each_entry(p, &req->port->subsystems, entry) { list_for_each_entry(p, &req->port->subsystems, entry) {
if (!nvmet_host_allowed(req, p->subsys, ctrl->hostnqn)) if (!nvmet_host_allowed(p->subsys, ctrl->hostnqn))
continue; continue;
if (residual_len >= entry_size) { if (residual_len >= entry_size) {
char traddr[NVMF_TRADDR_SIZE]; char traddr[NVMF_TRADDR_SIZE];
......
...@@ -468,8 +468,7 @@ extern u32 nvmet_ana_group_enabled[NVMET_MAX_ANAGRPS + 1]; ...@@ -468,8 +468,7 @@ extern u32 nvmet_ana_group_enabled[NVMET_MAX_ANAGRPS + 1];
extern u64 nvmet_ana_chgcnt; extern u64 nvmet_ana_chgcnt;
extern struct rw_semaphore nvmet_ana_sem; extern struct rw_semaphore nvmet_ana_sem;
bool nvmet_host_allowed(struct nvmet_req *req, struct nvmet_subsys *subsys, bool nvmet_host_allowed(struct nvmet_subsys *subsys, const char *hostnqn);
const char *hostnqn);
int nvmet_bdev_ns_enable(struct nvmet_ns *ns); int nvmet_bdev_ns_enable(struct nvmet_ns *ns);
int nvmet_file_ns_enable(struct nvmet_ns *ns); int nvmet_file_ns_enable(struct nvmet_ns *ns);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment