@@ -30,6 +30,19 @@ impl Default for Chipset {
30
30
/// Generates a 20-byte NVMe device serial number from the bytes in a string
31
31
/// slice. If the slice is too short to populate the entire serial number, the
32
32
/// remaining bytes are filled with `pad`.
33
+ ///
34
+ /// NOTE: Version 1.2.1 of the NVMe specification (June 5, 2016) specifies in
35
+ /// section 1.5 that ASCII data fields, including serial numbers, must be
36
+ /// left-justified and must use 0x20 bytes (spaces) as the padding value. This
37
+ /// function allows callers to choose a non-0x20 padding value to preserve the
38
+ /// serial numbers for existing disks, which serial numbers may have been used
39
+ /// previously and persisted into a VM's nonvolatile EFI variables (such as its
40
+ /// boot order variables).
41
+ //
42
+ // TODO(#790): Ideally, this routine would have no `pad` parameter at all and
43
+ // would always pad with spaces, but whether this is ultimately possible depends
44
+ // on whether Omicron can start space-padding serial numbers for disks that were
45
+ // attached to a Propolis VM that zero-padded their serial numbers.
33
46
pub fn nvme_serial_from_str ( s : & str , pad : u8 ) -> [ u8 ; 20 ] {
34
47
let mut sn = [ 0u8 ; 20 ] ;
35
48
@@ -600,5 +613,8 @@ mod test {
600
613
nvme_serial_from_str( "very_long_disk_name_goes_here" , b'?' ) ,
601
614
* expected
602
615
) ;
616
+
617
+ let expected = b"nonvolatile EFI\0 \0 \0 \0 \0 " ;
618
+ assert_eq ! ( nvme_serial_from_str( "nonvolatile EFI" , 0 ) , * expected) ;
603
619
}
604
620
}
0 commit comments