X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=gearman%2Fzfs.pl;h=7ed765afd20974e99ea94b41b356337853b467ef;hb=eaaf66c7ab6e529345899e4cfa8d21f30aa93084;hp=63bbe55d4aa914c30330cad57bcb41558915be91;hpb=ad29dbafea12e7712d99f671adcbbffeafa89ac7;p=cloudstore.git diff --git a/gearman/zfs.pl b/gearman/zfs.pl index 63bbe55..7ed765a 100755 --- a/gearman/zfs.pl +++ b/gearman/zfs.pl @@ -16,30 +16,35 @@ $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 { + my $used = zfs( "zfs get -H -p -o value userused\@u%s $ENV{ZSLICE}" => $_[0] ); + my $quota = zfs( "zfs get -H -p -o value userquota\@u%s $ENV{ZSLICE}" => $_[0] ); + return "$used $quota"; +} ); -$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;