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 Aug 9, 2018
1 parent c27dd86 commit 3483ed4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
license 'Apache-2.0'
description 'Manage ZFS'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '1.0.1'
version '1.0.14'
source_url 'https://github.com/chef-cookbooks/chef_zfs'
issues_url 'https://github.com/chef-cookbooks/chef_zfs/issues'

Expand Down
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
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 3483ed4

Please sign in to comment.