Commit 3a1dc2a9 authored by Leigh B Stoller's avatar Leigh B Stoller

Add ZFS support to quota checking.

parent ae708861
......@@ -199,18 +199,6 @@ my $user_uid = $this_user->uid();
my $user_name = $this_user->name();
my $user_email = $this_user->email();
#
# Before doing anything else, check for overquota ... lets not waste
# our time. Make sure user sees the error by exiting with 1.
#
if (system("$checkquota $user_uid") != 0) {
tberror({cause => 'user', type => 'primary', severity => SEV_ERROR,
error => ['over_disk_quota', $CONTROL]},
"You are over your disk quota on $CONTROL; ".
"please login there and cleanup!");
exit(1);
}
#
# Lets check to make sure user did not delete their home dir.
# Maybe in the future, when exports_setup does not cause all
......@@ -239,6 +227,18 @@ usage()
usage()
if (defined($tempnsfile) && defined($copyarg));
#
# Before doing anything else, check for overquota ... lets not waste
# our time. Make sure user sees the error by exiting with 1.
#
if (system("$checkquota -p $pid $user_uid") != 0) {
tberror({cause => 'user', type => 'primary', severity => SEV_ERROR,
error => ['over_disk_quota', $CONTROL]},
"You are over your disk quota on $CONTROL; ".
"please login there and cleanup!");
exit(1);
}
if (! -e "$TB/expinfo/$pid") {
die("*** $0:\n".
" $TB/expinfo/$pid has not been created yet!\n".
......
#!/usr/bin/perl -wT
#
# Copyright (c) 2000-2013 University of Utah and the Flux Group.
# Copyright (c) 2000-2014 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -425,7 +425,7 @@ if ($waitmode) {
#
# Check for overquota; we deal with it below, cause of the batch system.
#
my $overquota = system("$checkquota $user_uid");
my $overquota = system("$checkquota -p $pid $user_uid");
if ($overquota) {
tberror({cause => 'user', severity => SEV_WARNING,
......
#!/usr/bin/perl -wT
#!/usr/bin/perl -
#
# Copyright (c) 2000-2005 University of Utah and the Flux Group.
# Copyright (c) 2000-2014 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -34,11 +34,12 @@ use Getopt::Std;
#
sub usage()
{
print STDOUT "Usage: checkquota [-d] <user>\n";
print STDOUT "Usage: checkquota [-d] [-p pid] <user>\n";
exit(-1);
}
my $optlist = "d";
my $optlist = "dp:";
my $debug = 0;
my $pid;
#
# Configure variables
......@@ -47,10 +48,13 @@ my $TB = "@prefix@";
my $TBOPS = "@TBOPSEMAIL@";
my $FS = "@FSNODE@";
my $TESTMODE = @TESTMODE@;
my $WITHZFS = @WITHZFS@;
my $ZFS_ROOT = "@ZFS_ROOT@";
my $FSLIST = "@FS_WITH_QUOTAS@";
my $QUOTACMD = "/usr/bin/quota";
my $SSHTB = "/usr/testbed/bin/sshtb";
my $ZFS = "/sbin/zfs";
# Locals
my $user;
......@@ -77,19 +81,13 @@ if ($EUID != 0) {
" Must be root! Maybe its a development version?\n");
}
# This script is setuid, so please do not run it as root. Hard to track
# what has happened.
if ($UID == 0) {
die("*** $0:\n".
" Please do not run this as root! Its already setuid!\n");
}
#
# Testbed Support libraries
#
use lib "@prefix@/lib";
use libdb;
use libtestbed;
use Project;
#
# Parse command arguments. Once we return from getopts, all that should
......@@ -102,6 +100,9 @@ if (! getopts($optlist, \%options)) {
if (defined($options{"d"})) {
$debug = 1;
}
if (defined($options{"p"})) {
$pid = $options{"p"};
}
if (@ARGV != 1) {
usage();
}
......@@ -116,6 +117,16 @@ if ($user =~ /^([-\w]+)$/) {
else {
die("Bad data in argument: $user");
}
#
# Optional pid check to, as for ZFS.
#
if (defined($pid)) {
my $project = Project->Lookup($pid);
if (!defined($project)) {
fatal("No such project");
}
$pid = $project->pid();
}
#
# Convert to a uid since fs node may not have our user names
......@@ -127,20 +138,52 @@ my $userid = getpwnam($user);
#
$UID = 0;
#
# We invoke the quota command and look at the results.
#
open(QUOTA, "$SSHTB -host $FS $QUOTACMD -q -l $userid |") or
die("*** $0:\n".
" Could not invoke $QUOTACMD on $FS!\n");
if ($WITHZFS) {
my $fsarg = "$ZFS_ROOT/users/$user";
if (defined($pid)) {
$fsarg .= " $ZFS_ROOT/proj/$pid $ZFS_ROOT/groups/$pid ";
}
my $cmd = "$SSHTB -host $FS $ZFS get -H -o name,value available $fsarg";
if ($debug) {
print "$cmd\n";
}
open(QUOTA, " $cmd |") or
die("*** $0:\n".
" Could not invoke $QUOTACMD on $FS!\n");
while (<QUOTA>) {
if ($debug) {
print $_;
}
if ($_ =~ /^([\w\/]*)\s+([\d\.]*)(\w)/) {
if (! ($3 eq "M" || $3 eq "G" || $3 eq "T" ||
($3 eq "K" && $2 >= 1024) ||
($3 eq "B" && $2 < 1024*1024))) {
print STDOUT "*** Disk Quota exceeded on $1\n";
$overquota++;
}
}
else {
print STDERR "*** Disk Quota not recognized: $_";
$overquota++;
}
}
}
else {
#
# We invoke the quota command and look at the results.
#
open(QUOTA, "$SSHTB -host $FS $QUOTACMD -q -l $userid |") or
die("*** $0:\n".
" Could not invoke $QUOTACMD on $FS!\n");
while (<QUOTA>) {
if (($_ =~ /limit reached on ([-\w\/]*)$/) ||
($_ =~ /grace period on ([-\w\/]*)$/) ||
($_ =~ /Over file quota on ([-\w\/]*)$/) ||
($_ =~ /Over block quota on ([-\w\/]*)$/)) {
print STDOUT "*** Disk Quota exceeded on $1\n";
$overquota++;
while (<QUOTA>) {
if (($_ =~ /limit reached on ([-\w\/]*)$/) ||
($_ =~ /grace period on ([-\w\/]*)$/) ||
($_ =~ /Over file quota on ([-\w\/]*)$/) ||
($_ =~ /Over block quota on ([-\w\/]*)$/)) {
print STDOUT "*** Disk Quota exceeded on $1\n";
$overquota++;
}
}
}
close(QUOTA);
......
......@@ -352,15 +352,6 @@ my $user_uid = $this_user->uid();
my $user_name = $this_user->name();
my $user_email = $this_user->email();
#
# Before doing anything else, check for overquota ... lets not waste
# our time. Make sure user sees the error by exiting with 1.
#
if (system("$checkquota $user_uid") != 0) {
die("*** $0:\n".
" You are over your disk quota on $CONTROL; ".
"please login there and cleanup!\n");
}
if ($UID && ! $this_user->IsAdmin()) {
$mereuser = 1;
}
......@@ -385,6 +376,16 @@ if ($mereuser &&
" You do not have permission to use imageid $imageid!\n");
}
#
# Before doing anything else, check for overquota ... lets not waste
# our time. Make sure user sees the error by exiting with 1.
#
if (system("$checkquota -p $imagepid $user_uid") != 0) {
die("*** $0:\n".
" You are over your disk quota on $CONTROL; ".
"please login there and cleanup!\n");
}
#
# See if per-project/per-user provenance feature is set.
#
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment