Skip to content

Commit b28c92e

Browse files
mayastor-borstiagolobocastro
andcommitted
Merge #1933
1933: fix(nvmf/hosts): handle existing allowed host einval r=tiagolobocastro a=tiagolobocastro 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. --- fix(nvmf/hosts): handle existing allowed host einval On the latest spdk, we cannot add the same host back as it's now rejecting it with einval. Instead, we check the existing hosts and add only the new ones. Co-authored-by: Tiago Castro <[email protected]>
2 parents 3ecf873 + d73a137 commit b28c92e

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

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

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -599,37 +599,28 @@ impl NvmfSubsystem {
599599
}
600600

601601
let hosts = hosts.iter().map(AsRef::as_ref).collect::<Vec<&str>>();
602-
self.allow_hosts(&hosts)?;
603602

604-
let mut host = unsafe { spdk_nvmf_subsystem_get_first_host(self.0.as_ptr()) };
603+
let connected_hosts = self.allowed_hosts();
604+
let allow_hosts = hosts
605+
.iter()
606+
.filter(|h| !connected_hosts.iter().any(|ref ch| ch == h));
607+
self.allow_hosts(allow_hosts.cloned())?;
605608

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

628619
Ok(())
629620
}
630621

631622
/// Allows the specified hosts to connect to the subsystem.
632-
pub fn allow_hosts(&self, hosts: &[&str]) -> Result<(), Error> {
623+
pub fn allow_hosts<'a, T: Iterator<Item = &'a str>>(&'a self, hosts: T) -> Result<(), Error> {
633624
for host in hosts {
634625
self.allow_host(host)?;
635626
}

0 commit comments

Comments
 (0)