test send_file with spaces in both arguments
[cloudstore.git] / gearman / zfs.pl
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4
5 use Data::Dump qw(dump);
6
7 sub home_dir {
8         my $login = shift;
9         my ( undef, undef, $uid, $gid, undef, undef, $email, $dir, $shell ) = getpwnam $login;
10         return $dir;
11 }
12
13 use Gearman::Worker;
14 my $worker = Gearman::Worker->new;
15 $worker->job_servers('127.0.0.1:4730');
16
17 die "missing ZSLICE from env" unless $ENV{ZSLICE};
18
19 sub zfs {
20         my ($fmt,$job) = @_;
21         my $work = $job->arg;
22         chomp $work;
23
24         my $zfs = sprintf $fmt, split(/ /,$work);
25         warn "# zfs_get [$work] -> $zfs\n";
26
27         my $v = `$zfs`;
28         chomp $v;
29
30         warn "# $work = $v\n";
31
32         return $v;
33 }
34
35 my $name = $ENV{ZSLICE};
36 $name =~ s/\W+/_/g;
37
38 $worker->register_function( $name . '_quota_get' => sub {
39         my $used = zfs( "zfs get -H -p -o value userused\@%s $ENV{ZSLICE}" => $_[0] );
40         my $quota = zfs( "zfs get -H -p -o value userquota\@%s $ENV{ZSLICE}" => $_[0] );
41         return "$used $quota";
42 } );
43
44 $worker->register_function( $name . '_quota_set' => sub { zfs( 
45 "zfs set userquota\@%s=%s $ENV{ZSLICE}" => $_[0]
46 ) } );
47
48 warn "$0 $name pid $$ waitng for jobs ZFS slice $ENV{ZSLICE}\n";
49 $worker->work while 1;
50