sparse => { optional => 1 },
nodes => { optional => 1 },
disable => { optional => 1 },
- maxfiles => { optional => 1 },
content => { optional => 1 },
};
}
my $zvol = {};
my @parts = split /\//, $dataset;
+ next if scalar(@parts) < 2; # we need pool/name
my $name = pop @parts;
my $pool = join('/', @parts);
next unless $name =~ m!^(vm|base|subvol)-(\d+)-(\S+)$!;
$zvol->{owner} = $2;
- $name = $pool . '/' . $name;
-
$zvol->{pool} = $pool;
$zvol->{name} = $name;
if ($type eq 'filesystem') {
my ($class, $volname) = @_;
if ($volname =~ m/^(((base|vm)-(\d+)-\S+)\/)?((base)?(vm|subvol)?-(\d+)-\S+)$/) {
- return ('images', $5, $8, $2, $4, $6);
+ my $format = $7 && $7 eq 'subvol' ? 'subvol' : 'raw';
+ return ('images', $5, $8, $2, $4, $6, $format);
}
die "unable to parse zfs volume name '$volname'\n";
# virtual zfs methods (subclass can overwrite them)
sub path {
- my ($class, $scfg, $volname) = @_;
+ my ($class, $scfg, $volname, $storeid, $snapname) = @_;
my ($vtype, $name, $vmid) = $class->parse_volname($volname);
if ($vtype eq "images") {
if ($volname =~ m/^subvol-/) {
# fixme: we currently assume standard mount point?!
- $path = "$scfg->{pool}/$volname";
+ $path = "/$scfg->{pool}/$volname";
} else {
$path = "/dev/zvol/$scfg->{pool}/$volname";
}
+ $path .= "\@$snapname" if defined($snapname);
} else {
die "$vtype is not allowed in ZFSPool!";
}
die "illegal name '$volname' - sould be 'vm-$vmid-*'\n"
if $volname && $volname !~ m/^vm-$vmid-/;
- $volname = $class->zfs_find_free_diskname($storeid, $scfg, $vmid)
+ $volname = $class->zfs_find_free_diskname($storeid, $scfg, $vmid, $fmt)
if !$volname;
$class->zfs_create_zvol($scfg, $volname, $size);
system("udevadm settle --timeout 10 --exit-if-exists=${devname}");
} elsif ( $fmt eq 'subvol') {
-
- die "subvolume allocation without name\n" if !$volname;
+
+ die "illegal name '$volname' - sould be 'subvol-$vmid-*'\n"
+ if $volname && $volname !~ m/^subvol-$vmid-/;
+ $volname = $class->zfs_find_free_diskname($storeid, $scfg, $vmid, $fmt)
+ if !$volname;
+
die "illegal name '$volname' - sould be 'subvol-$vmid-*'\n"
if $volname !~ m/^subvol-$vmid-/;
return ($available, $used);
}
-sub zfs_get_zvol_size {
- my ($class, $scfg, $zvol) = @_;
-
- my $text = $class->zfs_request($scfg, undef, 'get', '-Hp', 'volsize', "$scfg->{pool}/$zvol");
-
- if ($text =~ /volsize\s(\d+)/) {
- return $1;
- }
-
- die "Could not get zvol size";
-}
-
sub zfs_create_zvol {
my ($class, $scfg, $zvol, $size) = @_;
my $dataset = "$scfg->{pool}/$volname";
- my $cmd = ['create', '-o', "refquota=${size}k", $dataset];
+ my $cmd = ['create', '-o', 'acltype=posixacl', '-o', 'xattr=sa',
+ '-o', "refquota=${size}k", $dataset];
$class->zfs_request($scfg, undef, @$cmd);
}
if ($err = $@) {
if ($err =~ m/^zfs error:(.*): dataset is busy.*/) {
sleep(1);
+ } elsif ($err =~ m/^zfs error:.*: dataset does not exist.*$/) {
+ $err = undef;
+ last;
} else {
die $err;
}
}
sub zfs_find_free_diskname {
- my ($class, $storeid, $scfg, $vmid) = @_;
+ my ($class, $storeid, $scfg, $vmid, $format) = @_;
my $name = undef;
my $volumes = $class->zfs_list_zvol($scfg);
foreach my $image (keys %$dat) {
my $volname = $dat->{$image}->{name};
- if ($volname =~ m/(vm|base)-$vmid-disk-(\d+)/){
+ if ($volname =~ m/(vm|base|subvol)-$vmid-disk-(\d+)/){
$disk_ids->{$2} = 1;
}
}
for (my $i = 1; $i < 100; $i++) {
if (!$disk_ids->{$i}) {
- return "vm-$vmid-disk-$i";
+ return $format eq 'subvol' ? "subvol-$vmid-disk-$i" : "vm-$vmid-disk-$i";
}
}
# abort rollback if snapshot is not the latest
my @params = ('-t', 'snapshot', '-o', 'name', '-s', 'creation');
- my $text = zfs_request($class, $scfg, undef, 'list', @params);
+ my $text = $class->zfs_request($scfg, undef, 'list', @params);
my @snapshots = split(/\n/, $text);
my $recentsnap;
sub volume_size_info {
my ($class, $scfg, $storeid, $volname, $timeout) = @_;
- return $class->zfs_get_zvol_size($scfg, $volname);
+ my (undef, undef, undef, undef, undef, undef, $format) =
+ $class->parse_volname($volname);
+
+ my $attr = $format eq 'subvol' ? 'refquota' : 'volsize';
+ my $text = $class->zfs_request($scfg, undef, 'get', '-Hp', $attr, "$scfg->{pool}/$volname");
+
+ if ($text =~ /\s$attr\s(\d+)\s/) {
+ return $1;
+ }
+
+ die "Could not get zfs volume size\n";
}
sub volume_snapshot {
- my ($class, $scfg, $storeid, $volname, $snap, $running) = @_;
+ my ($class, $scfg, $storeid, $volname, $snap) = @_;
$class->zfs_request($scfg, undef, 'snapshot', "$scfg->{pool}/$volname\@$snap");
}
sub volume_snapshot_delete {
my ($class, $scfg, $storeid, $volname, $snap, $running) = @_;
+ $class->deactivate_volume($storeid, $scfg, $volname, $snap, {});
$class->zfs_request($scfg, undef, 'destroy', "$scfg->{pool}/$volname\@$snap");
}
sub volume_snapshot_rollback {
my ($class, $scfg, $storeid, $volname, $snap) = @_;
- zfs_request($class, $scfg, undef, 'rollback', "$scfg->{pool}/$volname\@$snap");
+ $class->zfs_request($scfg, undef, 'rollback', "$scfg->{pool}/$volname\@$snap");
}
sub volume_rollback_is_possible {
my @param = ('-o', 'name', '-H');
- my $text = zfs_request($class, $scfg, undef, 'zpool_list', @param);
+ my $text = $class->zfs_request($scfg, undef, 'zpool_list', @param);
# Note: $scfg->{pool} can include dataset <pool>/<dataset>
my $pool = $scfg->{pool};
}
sub activate_volume {
- my ($class, $storeid, $scfg, $volname, $exclusive, $cache) = @_;
+ my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
return 1;
}
sub deactivate_volume {
- my ($class, $storeid, $scfg, $volname, $exclusive, $cache) = @_;
+ my ($class, $storeid, $scfg, $volname, $snapname, $cache) = @_;
return 1;
}
$snap ||= '__base__';
- my ($vtype, $basename, $basevmid, undef, undef, $isBase) =
+ my ($vtype, $basename, $basevmid, undef, undef, $isBase, $format) =
$class->parse_volname($volname);
die "clone_image only works on base images\n" if !$isBase;
- my $name = $class->zfs_find_free_diskname($storeid, $scfg, $vmid);
+ my $name = $class->zfs_find_free_diskname($storeid, $scfg, $vmid, $format);
$class->zfs_request($scfg, undef, 'clone', "$scfg->{pool}/$basename\@$snap", "$scfg->{pool}/$name");
sub volume_resize {
my ($class, $scfg, $storeid, $volname, $size, $running) = @_;
- my $new_size = ($size/1024);
+ my $new_size = int($size/1024);
+
+ my (undef, undef, undef, undef, undef, undef, $format) =
+ $class->parse_volname($volname);
+
+ my $attr = $format eq 'subvol' ? 'refquota' : 'volsize';
- $class->zfs_request($scfg, undef, 'set', 'volsize=' . $new_size . 'k', "$scfg->{pool}/$volname");
+ $class->zfs_request($scfg, undef, 'set', "$attr=${new_size}k", "$scfg->{pool}/$volname");
return $new_size;
}
clone => { base => 1},
template => { current => 1},
copy => { base => 1, current => 1},
+ sparseinit => { base => 1, current => 1},
};
my ($vtype, $name, $vmid, $basename, $basevmid, $isBase) =