Skip to content

Instantly share code, notes, and snippets.

@bdha
Created January 12, 2012 02:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bdha/1598118 to your computer and use it in GitHub Desktop.
Save bdha/1598118 to your computer and use it in GitHub Desktop.
# Grab any zfs data from "zfs get"
#zfs = Mash.new
#popen4("zfs get -p -H all") do |pid, stdin, stdout, stderr|
# stdin.close
# stdout.each do |line|
# next unless (line =~ /^([^\t]+)\t([^\t]+)\t([^\t]+)\t([^\t]+)$/)
# filesystem = $1
# zfs[filesystem] = Mash.new unless zfs.has_key?(filesystem)
# zfs[filesystem][:values] = Mash.new unless zfs[filesystem].has_key?('values')
# zfs[filesystem][:sources] = Mash.new unless zfs[filesystem].has_key?('sources')
# zfs[filesystem][:values][$2] = $3
# zfs[filesystem][:sources][$2] = $4.chomp
# end
#end
#zfs.each { |filesystem, attributes|
# fs[filesystem] = Mash.new unless fs.has_key?(filesystem)
# fs[filesystem][:fs_type] = 'zfs'
# fs[filesystem][:mount] = attributes[:values][:mountpoint] if attributes[:values].has_key?('mountpoint')
# fs[filesystem][:zfs_values] = attributes[:values]
# fs[filesystem][:zfs_sources] = attributes[:sources]
# # find all zfs parents
# parents = filesystem.split('/')
# zfs_parents = []
# (0 .. parents.length - 1).to_a.each { |parent_indexes|
# next_parent = parents[0 .. parent_indexes].join('/')
# zfs_parents.push(next_parent)
# }
# zfs_parents.pop
# fs[filesystem][:zfs_parents] = zfs_parents
# fs[filesystem][:zfs_zpool] = (zfs_parents.length == 0)
#}
The above code (as you can see, commented out) does really bad things when you have a setup like, say...
# zfs list -t snapshot | wc -l
28518
ohai goes down the rabbit hole and never comes back.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment