@@ -30,6 +30,7 @@ use guestmem::GuestMemory;
30
30
use guid:: Guid ;
31
31
use inspect:: Inspect ;
32
32
use inspect:: InspectMut ;
33
+ use nvme_resources:: fault:: FaultBehaviour ;
33
34
use nvme_resources:: fault:: FaultConfiguration ;
34
35
use parking_lot:: Mutex ;
35
36
use pci_core:: capabilities:: msix:: MsixEmulator ;
@@ -157,7 +158,7 @@ impl NvmeFaultController {
157
158
max_cqs : caps. max_io_queues ,
158
159
qe_sizes : Arc :: clone ( & qe_sizes) ,
159
160
subsystem_id : caps. subsystem_id ,
160
- fault_configuration,
161
+ fault_configuration : fault_configuration . clone ( ) ,
161
162
} ) ;
162
163
163
164
Self {
@@ -166,6 +167,7 @@ impl NvmeFaultController {
166
167
registers : RegState :: new ( ) ,
167
168
workers : admin,
168
169
qe_sizes,
170
+ fault_configuration,
169
171
}
170
172
}
171
173
@@ -343,8 +345,23 @@ impl NvmeFaultController {
343
345
344
346
if cc. en ( ) != self . registers . cc . en ( ) {
345
347
if cc. en ( ) {
346
- // If any, perform the fault at the beginning of the enable sequence.
347
- if
348
+ // If any fault was configured for cc.en() process it here
349
+ match self
350
+ . fault_configuration
351
+ . controller_management_fault
352
+ . controller_management_fault_enable
353
+ {
354
+ FaultBehaviour :: Delay ( duration) => {
355
+ std:: thread:: sleep ( duration) ;
356
+ }
357
+ FaultBehaviour :: Drop => {
358
+ tracelimit:: warn_ratelimited!(
359
+ "Dropping enable command due to fault injection"
360
+ ) ;
361
+ return ;
362
+ }
363
+ _ => { } // Update is not yet configured for this fault. Treat that as a default action for now
364
+ }
348
365
349
366
// Some drivers will write zeros to IOSQES and IOCQES, assuming that the defaults will work.
350
367
if cc. iocqes ( ) == 0 {
@@ -389,8 +406,6 @@ impl NvmeFaultController {
389
406
}
390
407
}
391
408
392
-
393
-
394
409
self . registers . cc = cc;
395
410
* self . qe_sizes . lock ( ) = IoQueueEntrySizes {
396
411
sqe_bits : cc. iosqes ( ) ,
@@ -437,6 +452,7 @@ impl ChangeDeviceState for NvmeFaultController {
437
452
registers,
438
453
qe_sizes,
439
454
workers,
455
+ fault_configuration : _,
440
456
} = self ;
441
457
workers. reset ( ) . await ;
442
458
cfg_space. reset ( ) ;
0 commit comments