Skip to content

Commit

Permalink
[#1830] Check that sysfs directory exists before reading
Browse files Browse the repository at this point in the history
Signed-off-by: David Crosby <[email protected]>
  • Loading branch information
dafyddcrosby committed Aug 7, 2024
1 parent 48e3eef commit d07517f
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions lib/ohai/plugins/filesystem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -276,19 +276,21 @@ def collect_btrfs_data(entry)
if entry[:fs_type] == "btrfs" && entry["uuid"]
uuid = entry["uuid"]
alloc = "/sys/fs/btrfs/#{uuid}/allocation"
%w{data metadata system}.each do |bg_type|
dir = "#{alloc}/#{bg_type}"
%w{single dup}.each do |raid|
if file_exist?("#{dir}/#{raid}")
btrfs["raid"] = raid
if Dir.exist?(alloc)
%w{data metadata system}.each do |bg_type|
dir = "#{alloc}/#{bg_type}"
%w{single dup}.each do |raid|
if file_exist?("#{dir}/#{raid}")
btrfs["raid"] = raid
end
end
logger.trace("Plugin Filesystem: reading btrfs allocation files at #{dir}")
btrfs["allocation"] ||= Mash.new
btrfs["allocation"][bg_type] ||= Mash.new
%w{total_bytes bytes_used}.each do |field|
bytes = file_read("#{dir}/#{field}").chomp.to_i
btrfs["allocation"][bg_type][field] = "#{bytes}"
end
end
logger.trace("Plugin Filesystem: reading btrfs allocation files at #{dir}")
btrfs["allocation"] ||= Mash.new
btrfs["allocation"][bg_type] ||= Mash.new
%w{total_bytes bytes_used}.each do |field|
bytes = file_read("#{dir}/#{field}").chomp.to_i
btrfs["allocation"][bg_type][field] = "#{bytes}"
end
end
end
Expand Down

0 comments on commit d07517f

Please sign in to comment.