From 50815f90680f839c934a9764797020f1c9490b23 Mon Sep 17 00:00:00 2001 From: Kumar Amit Date: Mon, 21 Oct 2024 06:52:43 -0700 Subject: [PATCH] Facebook: [hypernode][oly2] Add a helper function to check if T10DIX is enabled Summary: This diff adds a helper function to check if T10DIX is enabled on a device. The check has 3 main parts: - Device is formatted with a LBAF with metadata size 64 bytes and LBA size 4KB - Extended LBA is NOT enabled (metadata is transferred as a separate buffer) - PI type 3 is enabled and is transferred as last 8 bytes of metadata Differential Revision: D64488433 fbshipit-source-id: 6c5af1d6282dccc25b2d968a496ba60a4299c5e0 --- cookbooks/fb_storage/libraries/storage.rb | 32 +++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/cookbooks/fb_storage/libraries/storage.rb b/cookbooks/fb_storage/libraries/storage.rb index 5fb38b62..ca9025c9 100644 --- a/cookbooks/fb_storage/libraries/storage.rb +++ b/cookbooks/fb_storage/libraries/storage.rb @@ -1376,6 +1376,38 @@ def self.get_t10dix_lbaf(device) end end + def self.t10dix_enabled?(device) + nsid_out = Mixlib::ShellOut.new("nvme id-ns #{device} -ojson").run_command + nsid_out.error! + nsid_json = JSON.parse(nsid_out.stdout) + + # Details about output of the nvme id-ns command and it's associated structures/sub-structures can be found here: + # https://manpages.ubuntu.com/manpages/oracular/en/man2/nvme_id_ns.2.html + # More details about the bitmask values used can be bound here: + # https://github.com/torvalds/linux/blob/master/include/linux/nvme.h + + # Check if the drive is formatted with the expected LBAF, if supported: metadata size 64 bytes and data size 4KB + current_lbaf = (nsid_json['flbas'] & 0xf) | ((nsid_json['flbas'] & 0x60) >> 1) + expected_lbaf = nsid_json['lbafs'].find_index { |item| item['ms'] == 64 && item['ds'] == 12 } + if current_lbaf != expected_lbaf + return false + end + + # Ensure LBA is not extended i.e. metadata is transferred as a separate buffer and not at the end of data buffer + extended_data_lba = nsid_json['flbas'] & (1 << 5) != 0 + if extended_data_lba + return false + end + + # Ensure Protection Information (PI) Type 3 is enabled and PI is transferred as the last 8 bytes of metadata + dps_valid = (nsid_json['dps'] & 0x7 == 3 && nsid_json['dps'] & (1 << 3) == 0) + if !dps_valid + return false + end + + return true + end + private # we make an instance method that calls a class method for easier testing