Skip to content

Commit 04d7baa

Browse files
authored
nvme_driver: Added the qid field to the pending commands (#1688) (#1694)
Adding the qid field to the assert output during failures (Mismatched completion ids). Fixes: #1685. Cherry-picked changes from c765316
1 parent 4cbc184 commit 04d7baa

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

vm/devices/storage/disk_nvme/nvme_driver/src/queue_pair.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,11 @@ impl PendingCommands {
7676
const MAX_CIDS: usize = 1 << Self::CID_KEY_BITS;
7777
const CID_SEQ_OFFSET: Wrapping<u16> = Wrapping(1 << Self::CID_KEY_BITS);
7878

79-
fn new() -> Self {
79+
fn new(qid: u16) -> Self {
8080
Self {
8181
commands: Slab::new(),
8282
next_cid_high_bits: Wrapping(0),
83+
qid,
8384
}
8485
}
8586

@@ -109,11 +110,13 @@ impl PendingCommands {
109110
let command = self
110111
.commands
111112
.try_remove((cid & Self::CID_KEY_MASK) as usize)
112-
.expect("completion for unknown cid");
113+
.unwrap_or_else(|| panic!("completion for unknown cid: qid={}, cid={}", self.qid, cid));
113114
assert_eq!(
114115
command.command.cdw0.cid(),
115116
cid,
116-
"cid sequence number mismatch"
117+
"cid sequence number mismatch: qid={}, command_opcode={:#x}",
118+
self.qid,
119+
command.command.cdw0.opcode(),
117120
);
118121
command.respond
119122
}
@@ -136,7 +139,7 @@ impl PendingCommands {
136139
}
137140

138141
/// Restore pending commands from the saved state.
139-
pub fn restore(saved_state: &PendingCommandsSavedState) -> anyhow::Result<Self> {
142+
pub fn restore(saved_state: &PendingCommandsSavedState, qid: u16) -> anyhow::Result<Self> {
140143
let PendingCommandsSavedState {
141144
commands,
142145
next_cid_high_bits,
@@ -161,6 +164,7 @@ impl PendingCommands {
161164
})
162165
.collect::<Slab<PendingCommand>>(),
163166
next_cid_high_bits: Wrapping(*next_cid_high_bits),
167+
qid,
164168
})
165169
}
166170
}
@@ -241,7 +245,7 @@ impl QueuePair {
241245
QueueHandler {
242246
sq: SubmissionQueue::new(qid, sq_entries, sq_mem_block),
243247
cq: CompletionQueue::new(qid, cq_entries, cq_mem_block),
244-
commands: PendingCommands::new(),
248+
commands: PendingCommands::new(qid),
245249
stats: Default::default(),
246250
drain_after_restore: false,
247251
}
@@ -609,6 +613,7 @@ struct PendingCommands {
609613
commands: Slab<PendingCommand>,
610614
#[inspect(hex)]
611615
next_cid_high_bits: Wrapping<u16>,
616+
qid: u16,
612617
}
613618

614619
#[derive(Inspect)]
@@ -749,7 +754,7 @@ impl QueueHandler {
749754
Ok(Self {
750755
sq: SubmissionQueue::restore(sq_mem_block, sq_state)?,
751756
cq: CompletionQueue::restore(cq_mem_block, cq_state)?,
752-
commands: PendingCommands::restore(pending_cmds)?,
757+
commands: PendingCommands::restore(pending_cmds, sq_state.sqid)?,
753758
stats: Default::default(),
754759
// Only drain pending commands for I/O queues.
755760
// Admin queue is expected to have pending Async Event requests.

0 commit comments

Comments
 (0)