test send_file with spaces in both arguments
[cloudstore.git] / gearman / zfs.pl
index 63bbe55..5de977b 100755 (executable)
@@ -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\@%s $ENV{ZSLICE}" => $_[0] );
+       my $quota = zfs( "zfs get -H -p -o value userquota\@%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\@%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;