Skip to content

Commit

Permalink
Merge pull request #88 from hadfl/privs
Browse files Browse the repository at this point in the history
setting volsize requires sys_mount
  • Loading branch information
citrus-it authored Oct 24, 2021
2 parents bc2beca + bee7921 commit c15771f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 0 additions & 2 deletions lib/Zadm/Schema/KVM.pm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ $SCHEMA = sub($self) {
},
size => {
optional => 1,
default => '10G',
description => 'zvol disk size. according to zfs syntax',
example => '"size" : "10G"',
validator => $self->sv->regexp(qr/^\d+[bkmgtpe]$/i),
Expand Down Expand Up @@ -98,7 +97,6 @@ $SCHEMA = sub($self) {
},
size => {
optional => 1,
default => '10G',
description => 'zvol disk size. according to zfs syntax',
example => '"size" : "10G"',
validator => $self->sv->regexp(qr/^\d+[bkmgtpe]$/i),
Expand Down
12 changes: 9 additions & 3 deletions lib/Zadm/Validator.pm
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,19 @@ sub fileOrZvol($self) {
else {
my $props = $self->utils->getZfsProp($path, [ qw(volsize volblocksize refreservation) ]);

# TODO: this is done in the transformer for size, still we don't know about the execution order
$disk->{size} = $self->toInt->($disk->{size});

$self->log->warn("WARNING: block size cannot be changed for existing disk '$path'")
if $disk->{blocksize} && $toBytes->($disk->{blocksize}) != $toBytes->($props->{volblocksize});
$self->log->warn("WARNING: sparse attribute cannot be changed for existing disk '$path'")
if $props->{refreservation} eq 'none' && !$self->utils->boolIsTrue($disk->{sparse})
|| $props->{refreservation} ne 'none' && $self->utils->boolIsTrue($disk->{sparse});

# if size is not set we'll keep the current zvol size
return undef if !$disk->{size};

# TODO: this is done in the transformer for size; since we don't know about the execution order
# we run the transformation here, too
$disk->{size} = $self->toInt->($disk->{size});

my $diskSize = $toBytes->($props->{volsize});
my $newDiskSize = $toBytes->($disk->{size});

Expand All @@ -280,7 +284,9 @@ sub fileOrZvol($self) {
elsif ($newDiskSize > $diskSize) {
$self->log->debug("enlarging disk '$path' to $disk->{size}");

privSet({ add => 1, inherit => 1 }, PRIV_SYS_MOUNT);
$self->utils->exec('zfs', [ 'set', "volsize=$disk->{size}", $path ]);
privSet({ remove => 1, inherit => 1 }, PRIV_SYS_MOUNT);
}
}

Expand Down

0 comments on commit c15771f

Please sign in to comment.