Skip to content

Commit

Permalink
Pair HyperNode partitions by partlabel for T5
Browse files Browse the repository at this point in the history
Differential Revision: D54864378

fbshipit-source-id: e2bedc899e538d45ab0a998db1e08f1a1ecfbf12
  • Loading branch information
Kai-Hsiang Chang authored and facebook-github-bot committed Apr 15, 2024
1 parent 84ecd11 commit 81c1737
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions cookbooks/fb_storage/libraries/storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 81c1737

Please sign in to comment.