zfs_mgmt 0.4.7 → 0.4.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f291d60850dca4bda6a4e388d17cd18700406522f159eb1a3489215d0332fdb3
4
- data.tar.gz: 3e8bc46616b93dbc119a5ff6e7e24c5e44d579bd330bf18b5a3658fe368ebc15
3
+ metadata.gz: 97a0bda8881608e6e7fae8a94103e2867d199923f2df9ca9d1776ad6d4626fbe
4
+ data.tar.gz: 1851e69229905792ace9c998a3f6e88129c4d2f3d45440e8e2c3f7c07626c147
5
5
  SHA512:
6
- metadata.gz: 1cb48795d7c1d0f9f5499b65149c555aa633e6db1f357c451dba90c5264cc26a81acb62e552b5bea6c241a79bcde488b50eab445f4214be68aa322d91d2d7dab
7
- data.tar.gz: 3c5a1b003771b5481ac5419facf28ecbd25c92cf1095fa173a8f0ff4e2b326f2ffdd31bcc9ad4fa0978dd6c5ca583215228f43ec9da69540ce5c6ea28a73c467
6
+ metadata.gz: 74fc7184eaf7b95edbe8d28dc804230c63c30ff3db0a495e4f86d395006d85ec29e3f2a7ce73d891c0d76627ee47004443d0c81819ece352933dde2a2115c844
7
+ data.tar.gz: 3437621f4c6ba8e52254c48d0496685efb530f31bfc96d5b73c396fd275161aae02aeef8714ace50682c086f748b5fe787324372b5994947e69ec6c40ab988a6
data/Gemfile CHANGED
@@ -7,4 +7,5 @@ gem "thor"
7
7
  gem "text-table"
8
8
  gem "filesize"
9
9
  gem "json"
10
+ gem "timeout"
10
11
  gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zfs_mgmt (0.4.7)
4
+ zfs_mgmt (0.4.9)
5
5
  filesize (~> 0.2)
6
6
  text-table (~> 1.2)
7
7
  thor (~> 1.0)
@@ -28,6 +28,7 @@ GEM
28
28
  rspec-support (3.11.0)
29
29
  text-table (1.2.4)
30
30
  thor (1.2.1)
31
+ timeout (0.4.1)
31
32
 
32
33
  PLATFORMS
33
34
  x86_64-linux
@@ -40,6 +41,7 @@ DEPENDENCIES
40
41
  rspec (~> 3.0)
41
42
  text-table
42
43
  thor
44
+ timeout
43
45
  zfs_mgmt!
44
46
 
45
47
  BUNDLED WITH
data/README.md CHANGED
@@ -4,8 +4,8 @@ zfs_mgmt aims to provide some useful helpers for managing zfs
4
4
  snapshots, and eventually send/recv duties via the zfsmgr script in
5
5
  bin/.
6
6
 
7
- Currently only snapshot destruction is implemented by a policy
8
- specification stored in zfs properties.
7
+ Snapshot creation and deletion by policy along with zfs send wrapping
8
+ are implementation by specifications stored in zfs properties.
9
9
 
10
10
  ## Installation
11
11
 
data/bin/zfsmgr CHANGED
@@ -16,6 +16,12 @@ class ZfsMgr < Thor
16
16
  class_option :loglevel, :type => :string, :default => ( $stdout.isatty ? 'info' : 'warn' ),
17
17
  :enum => ['debug','error','fatal','info','warn'],
18
18
  :desc => 'set logging level to specified severity'
19
+ class_option :lock, :type => :boolean, :default => false,
20
+ :desc => 'lock before running'
21
+ class_option :lock_file, :type => :string, :default => '/run/zfsmgr.lock',
22
+ :desc => 'lock file'
23
+ class_option :lock_wait, :type => :numeric, :default => 0,
24
+ :desc => 'wait N seconds for lock'
19
25
  desc "zfsget [ZFS]", "execute zfs get for the given properties and types and parse the output into a nested hash"
20
26
  method_option :properties, :type => :string, :default => ['name'], :desc => "List of properties passed to zfs get", repeatable: true
21
27
  method_option :types, :type => :array, :default => ['filesystem','volume'], enum: ['filesystem','volume','snapshot'], :desc => "list of types"
@@ -1,3 +1,3 @@
1
1
  module ZfsMgmt
2
- VERSION = "0.4.7"
2
+ VERSION = "0.4.9"
3
3
  end
@@ -34,7 +34,9 @@ class ZfsMgmt::ZfsMgr::Send < Thor
34
34
  def all()
35
35
  ZfsMgmt.set_log_level(options[:loglevel])
36
36
  ZfsMgmt.global_options = options
37
+ lock = ZfsMgmt.lock(options)
37
38
 
38
39
  ZfsMgmt.zfs_send_all(options)
40
+ ZfsMgmt.unlock(lock)
39
41
  end
40
42
  end
@@ -11,7 +11,9 @@ class ZfsMgmt::ZfsMgr::Snapshot < Thor
11
11
  def destroy()
12
12
  ZfsMgmt.set_log_level(options[:loglevel])
13
13
  ZfsMgmt.global_options = options
14
+ lock = ZfsMgmt.lock(options)
14
15
  ZfsMgmt.snapshot_destroy(noop: options[:noop], verbose: options[:verbose], filter: options[:filter])
16
+ ZfsMgmt.unlock(lock)
15
17
  end
16
18
  desc "policy", "print the policy table for zfs"
17
19
  def policy()
@@ -25,6 +27,7 @@ class ZfsMgmt::ZfsMgr::Snapshot < Thor
25
27
  def create()
26
28
  ZfsMgmt.set_log_level(options[:loglevel])
27
29
  ZfsMgmt.global_options = options
30
+ lock = ZfsMgmt.lock(options)
28
31
  ZfsMgmt.snapshot_create(noop: options[:noop], filter: options[:filter])
29
32
  end
30
33
  end
data/lib/zfs_mgmt.rb CHANGED
@@ -8,6 +8,7 @@ require 'logger'
8
8
  require 'text-table'
9
9
  require 'open3'
10
10
  require 'filesize'
11
+ require 'timeout'
11
12
 
12
13
  $logger = Logger.new(STDERR, progname: 'zfs_mgmt')
13
14
 
@@ -37,6 +38,8 @@ $properties_xlate = {
37
38
  'creation' => ->(x) { x.to_i },
38
39
  }
39
40
 
41
+ $lock = nil
42
+
40
43
  module ZfsMgmt
41
44
  class << self
42
45
  attr_accessor :global_options
@@ -254,7 +257,7 @@ module ZfsMgmt
254
257
  next unless managed
255
258
  snaps = self.zfsget(properties: ['name','creation','userrefs','used','written','referenced'],types: ['snapshot'], zfs: zfs)
256
259
  if snaps.length == 0
257
- $logger.warn("unable to process this zfs, no snapshots at all: #{zfs}")
260
+ $logger.debug("not processing #{zfs} as there are no snapshots")
258
261
  next
259
262
  end
260
263
  zfss.push([zfs,props,snaps])
@@ -688,4 +691,47 @@ module ZfsMgmt
688
691
  zfs_send(options,zfs,props,snaps)
689
692
  end
690
693
  end
694
+ def self.lock(options)
695
+ # open lock file, try to lock file until lock_wait has expired or
696
+ # lock is obtained, write pid?
697
+ return nil unless options[:lock]
698
+ begin
699
+ lock = File.open(options[:lock_file], File::RDWR|File::CREAT, 0644)
700
+ rescue Errno::ENOENT => error
701
+ $logger.error("unable to open lock file (#{options[:lock_file]}), possibly the directory doesn't exist")
702
+ raise
703
+ end
704
+ if lock.flock(File::LOCK_EX|File::LOCK_NB)
705
+ lock.flock(File::LOCK_UN)
706
+ else
707
+ # we failed to lock so locked without NB is likely to block for some amount of time
708
+ $logger.info("attempting to lock control file, this may block")
709
+ end
710
+
711
+ if options[:lock_wait] > 0
712
+ begin
713
+ status = Timeout::timeout(options[:lock_wait]) do
714
+ return lock if lock.flock(File::LOCK_EX)
715
+ $logger.error("flock of #{options[:lock_file]} failed")
716
+ raise "flock failed"
717
+ end
718
+ rescue Timeout::Error => error
719
+ $logger.error("timed out waiting to lock")
720
+ raise
721
+ end
722
+ else
723
+ # zero is wait forever!
724
+ return lock if lock.flock(File::LOCK_EX)
725
+ $logger.error("flock of #{options[:lock_file]} failed")
726
+ raise "flock failed"
727
+ end
728
+ $logger.error("unable to obtain lock")
729
+ raise "unknown failure in locking file"
730
+ end
731
+ def self.unlock(lock)
732
+ unless lock.nil?
733
+ lock.flock(File::LOCK_UN)
734
+ lock.close()
735
+ end
736
+ end
691
737
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zfs_mgmt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.7
4
+ version: 0.4.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aran Cox
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-12 00:00:00.000000000 Z
11
+ date: 2025-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -155,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
155
  - !ruby/object:Gem::Version
156
156
  version: '0'
157
157
  requirements: []
158
- rubygems_version: 3.3.7
158
+ rubygems_version: 3.4.20
159
159
  signing_key:
160
160
  specification_version: 4
161
161
  summary: Misc. helpers regarding snapshots and send/recv.