Skip to content

Commit e42413b

Browse files
committed
nvme: mi: dev: Implement Admin / Identify / Namespace Attached Controller List
Signed-off-by: Andrew Jeffery <andrew@codeconstruct.com.au>
1 parent 6e422cf commit e42413b

3 files changed

Lines changed: 382 additions & 13 deletions

File tree

src/nvme.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ enum AdminIdentifyCnsRequestType {
386386
IdentifyNamespace = 0x08,
387387
AllocatedNamespaceIdList = 0x10,
388388
IdentifyNamespaceForAllocatedNamespaceId = 0x11,
389+
NamespaceAttachedControllerList = 0x12,
389390
NvmSubsystemControllerList = 0x13,
390391
SecondaryControllerList = 0x15,
391392
}

src/nvme/mi/dev.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,6 +1495,50 @@ impl RequestHandler for AdminIdentifyRequest {
14951495
}
14961496
}
14971497
}
1498+
AdminIdentifyCnsRequestType::NamespaceAttachedControllerList => {
1499+
match match NamespaceId(self.nsid).disposition(subsys) {
1500+
NamespaceIdDisposition::Invalid => ControllerListResponse::new()
1501+
.encode()
1502+
.map_err(AdminIoCqeGenericCommandStatus::from),
1503+
NamespaceIdDisposition::Broadcast => {
1504+
Err(AdminIoCqeGenericCommandStatus::InvalidFieldInCommand)
1505+
}
1506+
NamespaceIdDisposition::Unallocated | NamespaceIdDisposition::Inactive(_) => {
1507+
ControllerListResponse::new()
1508+
.encode()
1509+
.map_err(AdminIoCqeGenericCommandStatus::from)
1510+
}
1511+
NamespaceIdDisposition::Active(ns) => {
1512+
let mut clr = ControllerListResponse::new();
1513+
for cid in subsys.ctlrs.iter().filter_map(|c| {
1514+
if c.id.0 >= self.cntid && c.active_ns.contains(&ns.id) {
1515+
Some(c.id)
1516+
} else {
1517+
None
1518+
}
1519+
}) {
1520+
if let Err(id) = clr.ids.push(cid.0) {
1521+
debug!("Failed to push controller ID {id}");
1522+
return Err(ResponseStatus::InternalError);
1523+
}
1524+
}
1525+
clr.update()?;
1526+
clr.encode().map_err(AdminIoCqeGenericCommandStatus::from)
1527+
}
1528+
} {
1529+
Ok(response) => {
1530+
admin_send_response_body(
1531+
resp,
1532+
admin_constrain_body(self.dofst, self.dlen, &response.0)?,
1533+
)
1534+
.await
1535+
}
1536+
Err(status) => {
1537+
admin_send_status(resp, AdminIoCqeStatusType::GenericCommandStatus(status))
1538+
.await
1539+
}
1540+
}
1541+
}
14981542
AdminIdentifyCnsRequestType::NvmSubsystemControllerList => {
14991543
assert!(
15001544
subsys.ctlrs.len() <= 2047,

0 commit comments

Comments
 (0)