From: Dobrica Pavlinusic Date: Mon, 12 Dec 2011 23:53:01 +0000 (+0100) Subject: rework zfs worker to new slice_quota_(get|set) naming X-Git-Url: http://git.rot13.org/?a=commitdiff_plain;h=c91f89bb3058cf3a7b431444bec825865b48f584;p=cloudstore.git rework zfs worker to new slice_quota_(get|set) naming --- diff --git a/gearman/zfs.pl b/gearman/zfs.pl index 63bbe55..a07488e 100755 --- a/gearman/zfs.pl +++ b/gearman/zfs.pl @@ -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;