rework zfs worker to new slice_quota_(get|set) naming
authorDobrica Pavlinusic <dpavlin@rsync1.maxxo.com>
Mon, 12 Dec 2011 23:53:01 +0000 (00:53 +0100)
committerDobrica Pavlinusic <dpavlin@rsync1.maxxo.com>
Mon, 12 Dec 2011 23:53:01 +0000 (00:53 +0100)
gearman/zfs.pl

index 63bbe55..a07488e 100755 (executable)
@@ -16,30 +16,33 @@ $worker->job_servers('127.0.0.1:4730');
 
 die "missing ZSLICE from env" unless $ENV{ZSLICE};
 
-sub zfs_get {
-       my ($command,$job) = @_;
+sub zfs {
+       my ($fmt,$job) = @_;
        my $work = $job->arg;
        chomp $work;
 
-
-       my $zfs = sprintf 'zfs get -H -p -o value %s@%s %s', $command, $work, $ENV{ZSLICE};
-          $zfs = sprintf 'zfs userspace -H -p -o name,used,quota %s', $ENV{ZSLICE} if $command eq 'userspace';
-
-       warn "# zfs_get $command [$work] -> $zfs\n";
+       my $zfs = sprintf $fmt, split(/ /,$work);
+       warn "# zfs_get [$work] -> $zfs\n";
 
        my $v = `$zfs`;
+       chomp $v;
 
-       warn "# $command $work = $v\n";
+       warn "# $work = $v\n";
 
        return $v;
 }
 
-$worker->register_function( zfs_userused  => sub { zfs_get( 'userused'  => $_[0] ) } );
+my $name = $ENV{ZSLICE};
+$name =~ s/\W+/_/g;
 
-$worker->register_function( zfs_userquota => sub { zfs_get( 'userquota' => $_[0] ) } );
+$worker->register_function( $name . '_quota_get' => sub { zfs( 
+"zfs get -H -p -o value userused\@u%s $ENV{ZSLICE}" => $_[0]
+) } );
 
-$worker->register_function( zfs_userspace => sub { zfs_get( 'userspace' => $_[0] ) } );
+$worker->register_function( $name . '_quota_set' => sub { zfs( 
+"zfs set userquota\@u%s=%s $ENV{ZSLICE}" => $_[0]
+) } );
 
-warn "$0 pid $$ waitng for jobs\n";
+warn "$0 $name pid $$ waitng for jobs ZFS slice $ENV{ZSLICE}\n";
 $worker->work while 1;