From 81c173733781280994bdcdc1dd8ef2bf5b0d53c6 Mon Sep 17 00:00:00 2001 From: Kai-Hsiang Chang Date: Mon, 15 Apr 2024 13:41:16 -0700 Subject: [PATCH] Pair HyperNode partitions by partlabel for T5 Differential Revision: D54864378 fbshipit-source-id: e2bedc899e538d45ab0a998db1e08f1a1ecfbf12 --- cookbooks/fb_storage/libraries/storage.rb | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/cookbooks/fb_storage/libraries/storage.rb b/cookbooks/fb_storage/libraries/storage.rb index ae75954b3..09cddf8f1 100644 --- a/cookbooks/fb_storage/libraries/storage.rb +++ b/cookbooks/fb_storage/libraries/storage.rb @@ -28,6 +28,7 @@ class Storage FORCE_WRITE_CUSTOM_DISK_ORDER = '/var/chef/storage_force_write_custom_disk_order'.freeze DEV_ID_DIR = '/dev/disk/by-id'.freeze + DEV_PARTLABEL_DIR = '/dev/disk/by-partlabel'.freeze # 'size' from sysfs always assumes 512 byte blocks SECTOR_SIZE = 512 @@ -221,6 +222,31 @@ def self.partition_device_name(device, partnum) "#{device}#{prefix}#{partnum}" end + def self.get_partition_from_partlabel(partlabel) + unless Dir.exist?(DEV_PARTLABEL_DIR) + fail 'Host does not have a by-partlabel directory!' + end + path = File.join(DEV_PARTLABEL_DIR, partlabel.gsub('/', '\x2f')) + partition = File.realpath(path) + return partition + end + + def self.get_partuuid(partition) + cmd = "lsblk -o name,partuuid -J #{partition}" + lsblk = Mixlib::ShellOut.new(cmd).run_command + lsblk.error! + blkinfo = JSON.parse(lsblk.stdout) + blkdevs = blkinfo['blockdevices'] + + fail "Partition #{partition} not found" if blkdevs.empty? + + blkdev = blkdevs.pop + partuuid = blkdev['partuuid'] + Chef::Log.debug("fb_storage: found partuuid #{partuuid} for partition: #{partition}") + + return partuuid + end + # Given a device including a partition, return just the device without # the partition. i.e. # /dev/sda1 -> /dev/sda