use base qw(PVE::SectionConfig);
-cfs_register_file ('storage.cfg',
+cfs_register_file ('storage.cfg',
sub { __PACKAGE__->parse_config(@_); },
sub { __PACKAGE__->write_config(@_); });
type => 'boolean',
optional => 1,
},
- 'format' => {
+ 'format' => {
description => "Default Image format.",
type => 'string', format => 'pve-storage-format',
optional => 1,
my @cta;
foreach my $ct (keys %$hash) {
push @cta, $ct if $hash->{$ct};
- }
+ }
return join(',', @cta);
}
my $type = $scfg->{type};
my $def = $defaultData->{plugindata}->{$type};
-
+
my $def_format = 'raw';
my $valid_formats = [ $def_format ];
$def_format = $scfg->{format} || $def->{format}->[1];
$valid_formats = [ sort keys %{$def->{format}->[0]} ];
}
-
+
return wantarray ? ($def_format, $valid_formats) : $def_format;
}
my ($ct, $noerr) = @_;
my $valid_content = valid_content_types('dir'); # dir includes all types
-
+
if (!$valid_content->{$ct}) {
return undef if $noerr;
die "invalid content type '$ct'\n";
if ($key eq 'content') {
my $valid_content = $def->{content}->[0];
-
+
my $res = {};
foreach my $c (PVE::Tools::split_list($value)) {
die "storage does not support content type '$c'\n";
}
$res->{$c} = 1;
- }
+ }
if ($res->{none} && scalar (keys %$res) > 1) {
die "unable to combine 'none' with other content types\n";
content => { images => 1, rootdir => 1, vztmpl => 1, iso => 1},
};
}
-
+
# we always need this for OpenVZ
$ids->{local}->{content}->{rootdir} = 1;
$ids->{local}->{content}->{vztmpl} = 1;
my $lockid = "pve-storage-$storeid";
my $lockdir = "/var/lock/pve-manager";
mkdir $lockdir;
- $res = PVE::Tools::lock_file("$lockdir/$lockid", $timeout, $func, @param);
+ $res = PVE::Tools::lock_file("$lockdir/$lockid", $timeout, $func, @param);
die $@ if $@;
} else {
$res = PVE::Cluster::cfs_lock_storage($storeid, $timeout, $func, @param);
die $@ if $@;
- }
+ }
return $res;
}
die "unable to parse directory volume name '$volname'\n";
}
-my $vtype_subdirs = {
+my $vtype_subdirs = {
images => 'images',
rootdir => 'private',
iso => 'template/iso',
die "unknown vtype '$vtype'\n" if !defined($subdir);
- return "$path/$subdir";
+ return "$path/$subdir";
}
sub path {
my (undef, $tmpfmt) = parse_name_dir($name);
- die "illegal name '$name' - wrong extension for format ('$tmpfmt != '$fmt')\n"
+ die "illegal name '$name' - wrong extension for format ('$tmpfmt != '$fmt')\n"
if $tmpfmt ne $fmt;
my $path = "$imagedir/$name";
die "disk image '$path' already exists\n" if -e $path;
- run_command("/usr/bin/qemu-img create -f $fmt '$path' ${size}K",
- errmsg => "unable to create image");
+ my $cmd = ['/usr/bin/qemu-img', 'create'];
+
+ push @$cmd, '-o', 'preallocation=metadata' if $fmt eq 'qcow2';
+
+ push @$cmd, '-f', $fmt, $path, "${size}K";
+
+ run_command($cmd, errmsg => "unable to create image");
return "$vmid/$name";
}
my $cmd = ['/usr/bin/qemu-img', 'resize', $path , $size];
- run_command($cmd, timeout => 1);
+ run_command($cmd, timeout => 10);
return undef;
}
my $cmd = ['/usr/bin/qemu-img', 'snapshot','-c', $snap, $path];
- run_command($cmd, timeout => 1);
+ run_command($cmd);
return undef;
}
my $cmd = ['/usr/bin/qemu-img', 'snapshot','-a', $snap, $path];
- run_command($cmd, timeout => 1);
+ run_command($cmd);
+
+ return undef;
+}
+
+sub volume_snapshot_delete {
+ my ($class, $scfg, $storeid, $volname, $snap, $running) = @_;
+
+ die "can't delete snapshot for this image format" if $volname !~ m/\.(qcow2|qed)$/;
+
+ return 1 if $running;
+
+ my $path = $class->path($scfg, $volname);
+
+ my $cmd = ['/usr/bin/qemu-img', 'snapshot','-d', $snap, $path];
+
+ run_command($cmd);
return undef;
}
my $imagedir = $class->get_subdir($scfg, 'images');
my ($defFmt, $vaidFmts) = default_format($scfg);
- my $fmts = join ('|', @$vaidFmts);
+ my $fmts = join ('|', @$vaidFmts);
my $res = [];
my ($size, $format, $used) = file_size_info($fn);
if ($format && $size) {
- push @$res, {
+ push @$res, {
volid => $volid, format => $format,
size => $size, vmid => $owner, used => $used };
}
my $path = $scfg->{path};
die "storage definintion has no path\n" if !$path;
-
+
my $timeout = 2;
my $res = PVE::Tools::df($path, $timeout);
if (defined($scfg->{content})) {
foreach my $vtype (keys %$vtype_subdirs) {
- next if !defined($scfg->{content}->{$vtype});
- my $subdir = $class->get_subdir($scfg, $vtype);
- mkpath $subdir if $subdir ne $path;
+ # OpenVZMigrate uses backup (dump) dir
+ if (defined($scfg->{content}->{$vtype}) ||
+ ($vtype eq 'backup' && defined($scfg->{content}->{'rootdir'}))) {
+ my $subdir = $class->get_subdir($scfg, $vtype);
+ mkpath $subdir if $subdir ne $path;
+ }
}
}
}