root/5100R/trunk/ui/base-disk.mod/glue/handlers/Disk.pm
| Revision 259, 5.5 kB (checked in by shibuya, 5 years ago) | |
|---|---|
| |
| Line | |
|---|---|
| 1 | #!/usr/bin/perl -w -I/usr/sausalito/perl -I/usr/sausalito/handlers/base/disk |
| 2 | # $Id$ |
| 3 | # Copyright 2000, 2001 Sun Microsystems, Inc. All rights reserved. |
| 4 | |
| 5 | package Disk; |
| 6 | use Exporter (); |
| 7 | @ISA = qw(Exporter); |
| 8 | @EXPORT = qw(setquota); |
| 9 | |
| 10 | use vars qw($DEBUG); |
| 11 | $DEBUG = 0; |
| 12 | |
| 13 | use CCE; |
| 14 | use Quota; |
| 15 | use Base::HomeDir; |
| 16 | use DiskInfo; |
| 17 | use Sauce::Util; |
| 18 | |
| 19 | sub setquota |
| 20 | # Set the quota for a user or group. |
| 21 | # Arguments: cce connection, user or group object, and oid |
| 22 | # Side effects: modifies the quota tables |
| 23 | # Returns: 1 for success, a string explaining failure otherwise. |
| 24 | { |
| 25 | my ($cce, $obj, $oid) = @_; |
| 26 | |
| 27 | my $type = $obj->{CLASS}; |
| 28 | my $name = $obj->{name}; |
| 29 | |
| 30 | my ($ok, $disk, $disk_old) = $cce->get($oid, 'Disk'); |
| 31 | my $limit = $disk->{quota}; |
| 32 | |
| 33 | # be explicit about this on destroy to avoid confusion in the future |
| 34 | if ($cce->event_is_destroy()) { |
| 35 | # always set to unlimited on destroy |
| 36 | $limit = -1; |
| 37 | } |
| 38 | |
| 39 | my $id; |
| 40 | my @dirs = (); |
| 41 | my $home = $Base::HomeDir::HOME_ROOT; |
| 42 | my $BlocksPerMB = $DiskInfo::BYTES_PER_BLOCK; |
| 43 | # user or group |
| 44 | if ($type eq 'User') { |
| 45 | $type = 0; |
| 46 | $id = getpwnam($name); |
| 47 | if(! $id) { |
| 48 | $DEBUG && warn 'could not get ID for user ' . $name . |
| 49 | "\n"; |
| 50 | $cce->warn('couldNotGetId', {id => 'UID', |
| 51 | target => $name}); |
| 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | # volume for users lives in main namespace |
| 56 | push @dirs, ($obj->{volume} ? $obj->{volume} : $home); |
| 57 | } else { |
| 58 | $type = 1; |
| 59 | $id = getgrnam($name); |
| 60 | if (! $id) { |
| 61 | $DEBUG && warn 'could not get ID for group' . $name . |
| 62 | "\n"; |
| 63 | $cce->warn('couldNotGetId', |
| 64 | {id => 'GID', target => $name}); |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | # volume for Workgroups and Vsites will be in main namespace |
| 69 | push @dirs, ($obj->{volume} ? $obj->{volume} : $home); |
| 70 | } |
| 71 | |
| 72 | # removed as suggested by thockin for raq550 kernel c35 |
| 73 | #if (Quota::sync() && ($! != 1)) { |
| 74 | # $DEBUG && warn 'Could not sync quota with OS' . "\n"; |
| 75 | # $cce->warn('couldNotSync'); |
| 76 | # return 0; |
| 77 | #} |
| 78 | |
| 79 | for my $dir (@dirs) { |
| 80 | my $softquota = 0; |
| 81 | my $hardquota = 0; |
| 82 | my $softinode = 0; |
| 83 | my $hardinode = 0; |
| 84 | |
| 85 | if ($limit eq 0) { |
| 86 | # no quota is really quota for one file |
| 87 | $softquota = 1; |
| 88 | $hardquota = 1; |
| 89 | $softinode = 1; |
| 90 | $hardinode = 1; |
| 91 | } elsif ($limit gt 0) { |
| 92 | $softquota = $limit * $BlocksPerMB; |
| 93 | $hardquota = $softquota + $BlocksPerMB; |
| 94 | } |
| 95 | |
| 96 | my @args = (Quota::getqcarg($dir), $id, $softquota, $hardquota, |
| 97 | $softinode, $hardinode); |
| 98 | |
| 99 | # harris used extra arg $type here, which is not documented |
| 100 | # to let it set quotas for groups too --pbaltz |
| 101 | if ($type) { |
| 102 | # use 0 (defaults to this anyway), "" still gives error |
| 103 | push @args, 0; |
| 104 | push @args, $type; |
| 105 | } |
| 106 | |
| 107 | #ROLLBACK QUOTA |
| 108 | my $ret = Quota::setqlim(@args); |
| 109 | if ($ret != 0) { |
| 110 | $DEBUG && warn "Quota Error " . Quota::strerr() . "\n"; |
| 111 | $DEBUG && warn "args: ", join(' ', @args), "\n"; |
| 112 | $cce->warn('couldNotSetQuota', {'name' => $name }); |
| 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | # add rollback for quota |
| 117 | my $old_softquota = 0; |
| 118 | my $old_hardquota = 0; |
| 119 | my $old_softinode = 0; |
| 120 | my $old_hardinode = 0; |
| 121 | if ($disk_old->{quota} eq 0) { |
| 122 | # no quota is really quota for one file |
| 123 | $old_softquota = 1; |
| 124 | $old_hardquota = 1; |
| 125 | $old_softinode = 1; |
| 126 | $old_hardinode = 1; |
| 127 | } elsif ($disk_old->{quota} > 0) { |
| 128 | $old_softquota = $disk_old->{quota} * $BlocksPerMB; |
| 129 | $old_hardquota = $old_softquota + $BlocksPerMB; |
| 130 | } |
| 131 | |
| 132 | my $rollback_cmd = "/usr/bin/perl " . |
| 133 | " -e 'use Quota; Quota::sync(); " . |
| 134 | ' my $dev ' . "= Quota::getqcarg(\"$dir\"); " . |
| 135 | ' Quota::setqlim($dev, ' . |
| 136 | "$id, $old_softquota, $old_hardquota, $old_softinode" . |
| 137 | ", $old_hardinode" . |
| 138 | ($type ? ", 0, $type);" : ");") . |
| 139 | " Quota::sync();'"; |
| 140 | |
| 141 | $DEBUG && print STDERR $rollback_cmd, "\n"; |
| 142 | Sauce::Util::addrollbackcommand($rollback_cmd); |
| 143 | } |
| 144 | |
| 145 | # removed as suggested by thockin for raq550 kernel c35 |
| 146 | #if (Quota::sync() && ($! != 1)) { |
| 147 | # $DEBUG && warn 'Could not sync quota with OS' . "\n"; |
| 148 | # $cce->warn('couldNotSync'); |
| 149 | # return 0; |
| 150 | #} |
| 151 | |
| 152 | return 1; |
| 153 | } |
| 154 | |
| 155 | 1; |
| 156 | |
| 157 | # Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. |
| 158 | # |
| 159 | # Redistribution and use in source and binary forms, with or without |
| 160 | # modification, are permitted provided that the following conditions are met: |
| 161 | # |
| 162 | # -Redistribution of source code must retain the above copyright notice, |
| 163 | # this list of conditions and the following disclaimer. |
| 164 | # |
| 165 | # -Redistribution in binary form must reproduce the above copyright notice, |
| 166 | # this list of conditions and the following disclaimer in the documentation |
| 167 | # and/or other materials provided with the distribution. |
| 168 | # |
| 169 | # Neither the name of Sun Microsystems, Inc. or the names of contributors may |
| 170 | # be used to endorse or promote products derived from this software without |
| 171 | # specific prior written permission. |
| 172 | # |
| 173 | # This software is provided "AS IS," without a warranty of any kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. |
| 174 | # |
| 175 | # You acknowledge that this software is not designed or intended for use in the design, construction, operation or maintenance of any nuclear facility. |
| 176 |
Note: See TracBrowser for help on using the browser.
