From b7ad0079c7b68733b52d84b5e9f32a68e0f0902b Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Wed, 10 Aug 2022 21:45:21 +0100 Subject: [PATCH] Fix detection of pass through disks on megaraid controllers --- .../hardware/templates/default/ohai.rb.erb | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/cookbooks/hardware/templates/default/ohai.rb.erb b/cookbooks/hardware/templates/default/ohai.rb.erb index c7d245b94..661a6833d 100644 --- a/cookbooks/hardware/templates/default/ohai.rb.erb +++ b/cookbooks/hardware/templates/default/ohai.rb.erb @@ -426,6 +426,7 @@ Ohai.plugin(:Hardware) do def find_megaraid_disks(devices) controllers = [] arrays = [] + disks = [] controller = nil array = nil @@ -496,6 +497,8 @@ Ohai.plugin(:Hardware) do devices[:disks] << disk controller[:disks] << disk[:id] array[:disks] << disk[:id] + + disks << disk elsif disk && line =~ /^Firmware state:\s+(\S.*)$/ status, state = Regexp.last_match(1).split(/,\s*/) case status @@ -546,7 +549,8 @@ Ohai.plugin(:Hardware) do controller = controllers[Regexp.last_match(1).to_i] elsif controller && line =~ /^Enclosure Device ID: \d+$/ disk = { - :controller => controller[:id] + :controller => controller[:id], + :arrays => [] } elsif disk && line =~ /^WWN:\s+(\S+)$/ unless devices[:disks].find { |d| d[:wwn] == Regexp.last_match(1) } @@ -554,6 +558,8 @@ Ohai.plugin(:Hardware) do disk[:wwn] = Regexp.last_match(1) devices[:disks] << disk + + disks << disk end elsif disk && line =~ /^Firmware state:\s+(\S.*)$/ status, state = Regexp.last_match(1).split(/,\s*/) @@ -575,7 +581,7 @@ Ohai.plugin(:Hardware) do end elsif disk && line =~ /^(\S.*\S)\s*:\s+(\S.*)$/ case Regexp.last_match(1) - when "Device Id" then disk[:smart_device] = "megaraid,#{Regexp.last_match(2)}" + when "Device Id" then disk[:device_id] = Regexp.last_match(2) when "PD Type" then disk[:interface] = Regexp.last_match(2) when "Raw Size" then disk[:size] = memory_to_disk_size(Regexp.last_match(2).sub(/\s*\[.*\]$/, "")) when "Inquiry Data" then disk[:vendor], disk[:model], disk[:serial_number] = Regexp.last_match(2).split @@ -588,6 +594,17 @@ Ohai.plugin(:Hardware) do controller[:device] = "/dev/#{File.basename(device)}" end end + + disks.each do |disk| + controller = devices[:controllers][disk[:controller]] + id = disk.delete(:device_id) + + if device = Dir.glob("/sys/bus/pci/devices/#{controller[:pci_slot]}/host*/target0:0:#{id}/0:0:#{id}:0/block/sd*").first + disk[:device] = "/dev/#{File.basename(device)}" + else + disk[:smart_device] = "megaraid,#{id}" + end + end end def find_mpt1_disks(devices) -- 2.39.5