Allow enabling of quotas from scratch on Linux

This commit is contained in:
Jamie Cameron
2013-12-07 13:33:59 -08:00
parent d9dfdc1a79
commit 72bb51c751
7 changed files with 95 additions and 18 deletions

View File

@@ -41,3 +41,5 @@ Converted commands in the module's API file to POD format, and added more detail
Added a module access control option to restrict allowed groups by GID range.
---- Changes since 1.530 ----
Added a Module Config option to hide quotas for deleted users and groups.
---- Changes since 1.660 ----
On Linux, all filesystems that can potentially support quotas are now shown, with a link to turn on quota support. This avoids the need to first turn on quotas in the Disk and Network Filesystems module.

View File

@@ -9,15 +9,25 @@ require './quota-lib.pl';
if ($in{'active'} == 0) {
# Turn on quotas
$whatfailed = $text{'activate_eon'};
if ($error = &quotaon($in{'dir'}, $in{'mode'})) {
&error($error);
&error_setup($text{'activate_eon'});
@list = &list_filesystems();
($fs) = grep { $_->[0] eq $in{'dir'} } @list;
if (!$fs->[4] && $fs->[6]) {
# Try to enable in /etc/fstab
$error = &quota_make_possible($in{'dir'}, $fs->[6]);
&error($error) if ($error);
&webmin_log("support", undef, $in{'dir'}, \%in);
}
else {
# Try to turn on
$error = &quotaon($in{'dir'}, $in{'mode'});
&error($error) if ($error);
&webmin_log("activate", undef, $in{'dir'}, \%in);
}
&webmin_log("activate", undef, $in{'dir'}, \%in);
}
else {
# Turn off quotas
$whatfailed = $text{'activate_eoff'};
&error_setup($text{'activate_eoff'});
if ($error = &quotaoff($in{'dir'}, $in{'mode'})) {
&error($error);
}

View File

@@ -28,7 +28,8 @@ if (@list) {
foreach $f (@list) {
$qc = $f->[4];
$qc = $qc&1 if ($access{'gmode'} == 3);
next if (!$qc);
$qs = $f->[6];
next if (!$qc && !$qs);
next if (!&can_edit_filesys($f->[0]));
$qn = $f->[5];
if ($qc == 1) { $msg = $text{'index_quser'}; }
@@ -47,13 +48,20 @@ if (@list) {
}
}
elsif ($qn) {
# Currently active
$msg .= " $text{'index_active'}";
$chg = $text{'index_disable'};
}
else {
elsif ($qc) {
# Not active, but could be
$msg .= " $text{'index_inactive'}";
$chg = $text{'index_enable'};
}
else {
# Not active, and needs setup in /etc/fstab
$msg = $text{'index_supported'};
$chg = $text{'index_enable2'};
}
if ($qn%2 == 1) { $useractive++; }
if ($qn > 1) { $groupactive++; }

View File

@@ -144,13 +144,15 @@ ggraces_esave=Failed to save grace times
ggraces_eedit=You cannot edit grace times on this filesystem
ggraces_enumber='$1' is not a number
index_quser=User Quotas
index_qgroup=Group Quotas
index_qboth=User and Group Quotas
index_active=Active
index_disable=Disable Quotas
index_inactive=Inactive
index_enable=Enable Quotas
index_quser=User quotas
index_qgroup=Group quotas
index_qboth=User and group quotas
index_active=active
index_disable=Disable quotas
index_inactive=inactive
index_enable=Enable quotas
index_supported=Quotas not yet supported
index_enable2=Enable support
index_mountonly=Can only enable at mount
index_title=Disk Quotas
index_fs=Filesystem
@@ -307,6 +309,7 @@ log_grace_g=Changed group grace times on $1
log_check=Checked quotas on $1
log_copy_u=Copied user $1's quotas
log_copy_g=Copied group $1's quotas
log_support=Enabled quota support for $1
email_err=Failed to save email options
email_ecannot=You are not allowed to modify email options

View File

@@ -65,8 +65,9 @@ return @rv;
=head2 quota_can(&mnttab, &fstab)
Can this filesystem type support quotas? Takes array refs from mounted and
mountable filesystems, and returns one of the following :
Can this filesystem support quotas, based on mount options in fstab?
Takes array refs from mounted and mountable filesystems, and returns one of
the following :
=item 0 - No quota support (or not turned on in /etc/fstab).
@@ -181,6 +182,51 @@ if ($_[0]->[4] > 1) {
return $rv;
}
=head2 quota_possible(&fstab)
If quotas cannot be currently enabled, returns 3 if user and group quotas can
be turned on with an /etc/fstab change, 2 for group only, 1 for user only, or
0 if not possible at all.
=cut
sub quota_possible
{
if ($_[0]->[2] =~ /^ext/) {
return 3;
}
return 0;
}
=head2 quota_make_possible(dir, mode)
Edit /etc/fstab to make quotas possible for some dir
=cut
sub quota_make_possible
{
my ($dir, $mode) = @_;
# Update /etc/fstab
my @fstab = &mount::list_mounts();
my ($idx, $f);
for($idx=0; $idx<@fstab; $idx++) {
if ($fstab[$idx]->[0] eq $dir) {
$f = $fstab[$idx];
last;
}
}
return "No /etc/fstab entry found for $dir" if (!$f);
my @opts = grep { $_ ne "defaults" && $_ ne "-" } split(/,/, $f->[3]);
push(@opts, "usrquota", "grpquota");
$f->[3] = join(",", @opts);
&mount::change_mount($idx, @$f);
# Attempt to change live mount options
&mount::os_remount_dir(@$f);
return undef;
}
=head2 supports_status(dir, mode)
Internal function to check if the quotaon -p flag is supported.

View File

@@ -19,6 +19,9 @@ elsif ($action eq 'deactivate') {
$p->{'mode'} == 2 ? 'log_deactivate_g' :
'log_deactivate_ug', "<tt>$object</tt>");
}
elsif ($action eq 'support') {
return &text('log_support', "<tt>$object</tt>");
}
elsif ($action eq 'save') {
return &text('log_save', "<tt>$object</tt>",
"<tt>$p->{'filesys'}</tt>");

View File

@@ -50,10 +50,12 @@ Each is an array ref whose values are :
=item options - Mount options, like rw,usrquota,grpquota
=item quotacan - Can this filesystem type support quotas?
=item quotacan - Can this filesystem support quotas?
=item quotanow - Are quotas enabled right now?
=item quotapossible - Can quotas potentially be enabled?
The values of quotacan and quotanow are :
=item 0 - No quotas
@@ -74,7 +76,10 @@ foreach $f (&mount::list_mounts()) {
}
map { $_->[4] = &quota_can($_, $fmap{$_->[0],$_->[1]}) } @mtab;
map { $_->[5] = &quota_now($_, $fmap{$_->[0],$_->[1]}) } @mtab;
return grep { $_->[4] } @mtab;
if (defined(&quota_possible)) {
map { $_->[6] = &quota_possible($fmap{$_->[0],$_->[1]}) } @mtab;
}
return grep { $_->[4] || $_->[6] } @mtab;
}
=head2 parse_options(type, options)