Skip to content

Commit d73a137

Browse files
refactor(nvmf/hosts): reuse existing connected_hosts
Rather than re-loop the hosts, simply reuse the connected hosts, and disconnect any which is not on the new allowed list. Signed-off-by: Tiago Castro <[email protected]>
1 parent 8d11680 commit d73a137

File tree

1 file changed

+5
-19
lines changed

1 file changed

+5
-19
lines changed

io-engine/src/subsys/nvmf/subsystem.rs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -606,28 +606,14 @@ impl NvmfSubsystem {
606606
.filter(|h| !connected_hosts.iter().any(|ref ch| ch == h));
607607
self.allow_hosts(allow_hosts.cloned())?;
608608

609-
let mut host = unsafe { spdk_nvmf_subsystem_get_first_host(self.0.as_ptr()) };
610-
611-
let mut hosts_to_disconnect = vec![];
609+
for host in connected_hosts
610+
.iter()
611+
.filter(|h| !hosts.iter().any(|ch| ch == h))
612612
{
613-
// must first "clone" the host's nqn as the disallow_host fn will
614-
// actually free the spdk_nvmf_host memory as it's not ref counted.
615-
// this also means we better not call any async code within this
616-
// "clone".
617-
while !host.is_null() {
618-
let host_str = unsafe { (*host).nqn.as_str() };
619-
if !hosts.contains(&host_str) {
620-
hosts_to_disconnect.push(host_str.to_string());
621-
}
622-
host = unsafe { spdk_nvmf_subsystem_get_next_host(self.0.as_ptr(), host) };
623-
}
624-
}
625-
626-
for host in hosts_to_disconnect {
627-
self.disallow_host(&host)?;
613+
self.disallow_host(host)?;
628614
// note this only disconnects previously registered hosts
629615
// todo: disconnect any connected host which is not allowed
630-
self.disconnect_host(&host).await?;
616+
self.disconnect_host(host).await?;
631617
}
632618

633619
Ok(())

0 commit comments

Comments
 (0)