Skip to content

Commit

Permalink
Check if a given ZFS attribute is already set on the filesystem befor…
Browse files Browse the repository at this point in the history
…e calling 'zfs set ...'. This is necessary because zfs set will attempt to set, for example, mountpoint even if the filesystem is already mounted at the correct location.
  • Loading branch information
Ron Ellis committed Apr 23, 2018
1 parent c27dd86 commit 6ba0409
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions resources/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,21 @@ def zfs_get_properties(name)
cmd.stdout
end

# Helper method to check if a filesystem property is already set
# so that we don't call zfs set when it's unnecessary.
# @param [String] ZFS Name
# @param [Hash] ZFS Property => value
# @return [Boolean]
def zfs_property_already_set?(fs, property)
key = property.keys[0]
new_value = property[property.keys[0]]
cmd = Mixlib::ShellOut.new('zfs', 'get', key.to_s, fs)
cmd.run_command
existing_property = parse_zfs_properties(cmd.stdout)[0]
existing_value = existing_property[existing_property.keys[0]]
existing_value == new_value ? true : false
end

# TODO: Add support for setting inheritance from parent filesystems.
# @param [String] ZFS Name
# @param [Hash] ZFS Property => value
Expand All @@ -102,6 +117,7 @@ def zfs_set_properties(fs, properties)

configurable_properties.each do |setting|
next if PROPERTIES_VALID_ONLY_AT_CREATE.include?(setting.keys[0])
next if zfs_property_already_set?(fs, setting)
cmd = Mixlib::ShellOut.new('zfs', 'set', "#{setting.keys[0]}=#{setting[setting.keys[0]]}", fs)
cmd.environment['PATH'] = "/usr/sbin:#{ENV['PATH']}" if platform_family?('solaris2')
cmd.run_command
Expand Down

0 comments on commit 6ba0409

Please sign in to comment.