code cleanup
This commit is contained in:
2
Makefile
2
Makefile
@ -1,4 +1,4 @@
|
|||||||
RELEASE=2.1
|
RELEASE=2.2
|
||||||
|
|
||||||
VERSION=2.0
|
VERSION=2.0
|
||||||
PACKAGE=libpve-storage-perl
|
PACKAGE=libpve-storage-perl
|
||||||
|
|||||||
@ -11,7 +11,7 @@ use Data::Dumper;
|
|||||||
|
|
||||||
use base qw(PVE::SectionConfig);
|
use base qw(PVE::SectionConfig);
|
||||||
|
|
||||||
cfs_register_file ('storage.cfg',
|
cfs_register_file ('storage.cfg',
|
||||||
sub { __PACKAGE__->parse_config(@_); },
|
sub { __PACKAGE__->parse_config(@_); },
|
||||||
sub { __PACKAGE__->write_config(@_); });
|
sub { __PACKAGE__->write_config(@_); });
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ my $defaultData = {
|
|||||||
type => 'boolean',
|
type => 'boolean',
|
||||||
optional => 1,
|
optional => 1,
|
||||||
},
|
},
|
||||||
'format' => {
|
'format' => {
|
||||||
description => "Default Image format.",
|
description => "Default Image format.",
|
||||||
type => 'string', format => 'pve-storage-format',
|
type => 'string', format => 'pve-storage-format',
|
||||||
optional => 1,
|
optional => 1,
|
||||||
@ -55,7 +55,7 @@ sub content_hash_to_string {
|
|||||||
my @cta;
|
my @cta;
|
||||||
foreach my $ct (keys %$hash) {
|
foreach my $ct (keys %$hash) {
|
||||||
push @cta, $ct if $hash->{$ct};
|
push @cta, $ct if $hash->{$ct};
|
||||||
}
|
}
|
||||||
|
|
||||||
return join(',', @cta);
|
return join(',', @cta);
|
||||||
}
|
}
|
||||||
@ -75,7 +75,7 @@ sub default_format {
|
|||||||
|
|
||||||
my $type = $scfg->{type};
|
my $type = $scfg->{type};
|
||||||
my $def = $defaultData->{plugindata}->{$type};
|
my $def = $defaultData->{plugindata}->{$type};
|
||||||
|
|
||||||
my $def_format = 'raw';
|
my $def_format = 'raw';
|
||||||
my $valid_formats = [ $def_format ];
|
my $valid_formats = [ $def_format ];
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ sub default_format {
|
|||||||
$def_format = $scfg->{format} || $def->{format}->[1];
|
$def_format = $scfg->{format} || $def->{format}->[1];
|
||||||
$valid_formats = [ sort keys %{$def->{format}->[0]} ];
|
$valid_formats = [ sort keys %{$def->{format}->[0]} ];
|
||||||
}
|
}
|
||||||
|
|
||||||
return wantarray ? ($def_format, $valid_formats) : $def_format;
|
return wantarray ? ($def_format, $valid_formats) : $def_format;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,7 +143,7 @@ sub verify_content {
|
|||||||
my ($ct, $noerr) = @_;
|
my ($ct, $noerr) = @_;
|
||||||
|
|
||||||
my $valid_content = valid_content_types('dir'); # dir includes all types
|
my $valid_content = valid_content_types('dir'); # dir includes all types
|
||||||
|
|
||||||
if (!$valid_content->{$ct}) {
|
if (!$valid_content->{$ct}) {
|
||||||
return undef if $noerr;
|
return undef if $noerr;
|
||||||
die "invalid content type '$ct'\n";
|
die "invalid content type '$ct'\n";
|
||||||
@ -203,7 +203,7 @@ sub decode_value {
|
|||||||
|
|
||||||
if ($key eq 'content') {
|
if ($key eq 'content') {
|
||||||
my $valid_content = $def->{content}->[0];
|
my $valid_content = $def->{content}->[0];
|
||||||
|
|
||||||
my $res = {};
|
my $res = {};
|
||||||
|
|
||||||
foreach my $c (PVE::Tools::split_list($value)) {
|
foreach my $c (PVE::Tools::split_list($value)) {
|
||||||
@ -211,7 +211,7 @@ sub decode_value {
|
|||||||
die "storage does not support content type '$c'\n";
|
die "storage does not support content type '$c'\n";
|
||||||
}
|
}
|
||||||
$res->{$c} = 1;
|
$res->{$c} = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($res->{none} && scalar (keys %$res) > 1) {
|
if ($res->{none} && scalar (keys %$res) > 1) {
|
||||||
die "unable to combine 'none' with other content types\n";
|
die "unable to combine 'none' with other content types\n";
|
||||||
@ -278,7 +278,7 @@ sub parse_config {
|
|||||||
content => { images => 1, rootdir => 1, vztmpl => 1, iso => 1},
|
content => { images => 1, rootdir => 1, vztmpl => 1, iso => 1},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
# we always need this for OpenVZ
|
# we always need this for OpenVZ
|
||||||
$ids->{local}->{content}->{rootdir} = 1;
|
$ids->{local}->{content}->{rootdir} = 1;
|
||||||
$ids->{local}->{content}->{vztmpl} = 1;
|
$ids->{local}->{content}->{vztmpl} = 1;
|
||||||
@ -318,12 +318,12 @@ sub cluster_lock_storage {
|
|||||||
my $lockid = "pve-storage-$storeid";
|
my $lockid = "pve-storage-$storeid";
|
||||||
my $lockdir = "/var/lock/pve-manager";
|
my $lockdir = "/var/lock/pve-manager";
|
||||||
mkdir $lockdir;
|
mkdir $lockdir;
|
||||||
$res = PVE::Tools::lock_file("$lockdir/$lockid", $timeout, $func, @param);
|
$res = PVE::Tools::lock_file("$lockdir/$lockid", $timeout, $func, @param);
|
||||||
die $@ if $@;
|
die $@ if $@;
|
||||||
} else {
|
} else {
|
||||||
$res = PVE::Cluster::cfs_lock_storage($storeid, $timeout, $func, @param);
|
$res = PVE::Cluster::cfs_lock_storage($storeid, $timeout, $func, @param);
|
||||||
die $@ if $@;
|
die $@ if $@;
|
||||||
}
|
}
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -361,7 +361,7 @@ sub parse_volname {
|
|||||||
die "unable to parse directory volume name '$volname'\n";
|
die "unable to parse directory volume name '$volname'\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
my $vtype_subdirs = {
|
my $vtype_subdirs = {
|
||||||
images => 'images',
|
images => 'images',
|
||||||
rootdir => 'private',
|
rootdir => 'private',
|
||||||
iso => 'template/iso',
|
iso => 'template/iso',
|
||||||
@ -380,7 +380,7 @@ sub get_subdir {
|
|||||||
|
|
||||||
die "unknown vtype '$vtype'\n" if !defined($subdir);
|
die "unknown vtype '$vtype'\n" if !defined($subdir);
|
||||||
|
|
||||||
return "$path/$subdir";
|
return "$path/$subdir";
|
||||||
}
|
}
|
||||||
|
|
||||||
sub path {
|
sub path {
|
||||||
@ -420,18 +420,20 @@ sub alloc_image {
|
|||||||
|
|
||||||
my (undef, $tmpfmt) = parse_name_dir($name);
|
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;
|
if $tmpfmt ne $fmt;
|
||||||
|
|
||||||
my $path = "$imagedir/$name";
|
my $path = "$imagedir/$name";
|
||||||
|
|
||||||
die "disk image '$path' already exists\n" if -e $path;
|
die "disk image '$path' already exists\n" if -e $path;
|
||||||
|
|
||||||
my $options = "";
|
my $cmd = ['/usr/bin/qemu-img', 'create'];
|
||||||
$options = "-o preallocation=metadata" if $fmt eq 'qcow2';
|
|
||||||
|
|
||||||
run_command("/usr/bin/qemu-img create $options -f $fmt '$path' ${size}K",
|
push @$cmd, '-o', 'preallocation=metadata' if $fmt eq 'qcow2';
|
||||||
errmsg => "unable to create image");
|
|
||||||
|
push @$cmd, '-f', $fmt, $path, "${size}K";
|
||||||
|
|
||||||
|
run_command($cmd, errmsg => "unable to create image");
|
||||||
|
|
||||||
return "$vmid/$name";
|
return "$vmid/$name";
|
||||||
}
|
}
|
||||||
@ -559,7 +561,7 @@ sub list_images {
|
|||||||
my $imagedir = $class->get_subdir($scfg, 'images');
|
my $imagedir = $class->get_subdir($scfg, 'images');
|
||||||
|
|
||||||
my ($defFmt, $vaidFmts) = default_format($scfg);
|
my ($defFmt, $vaidFmts) = default_format($scfg);
|
||||||
my $fmts = join ('|', @$vaidFmts);
|
my $fmts = join ('|', @$vaidFmts);
|
||||||
|
|
||||||
my $res = [];
|
my $res = [];
|
||||||
|
|
||||||
@ -582,7 +584,7 @@ sub list_images {
|
|||||||
my ($size, $format, $used) = file_size_info($fn);
|
my ($size, $format, $used) = file_size_info($fn);
|
||||||
|
|
||||||
if ($format && $size) {
|
if ($format && $size) {
|
||||||
push @$res, {
|
push @$res, {
|
||||||
volid => $volid, format => $format,
|
volid => $volid, format => $format,
|
||||||
size => $size, vmid => $owner, used => $used };
|
size => $size, vmid => $owner, used => $used };
|
||||||
}
|
}
|
||||||
@ -598,7 +600,7 @@ sub status {
|
|||||||
my $path = $scfg->{path};
|
my $path = $scfg->{path};
|
||||||
|
|
||||||
die "storage definintion has no path\n" if !$path;
|
die "storage definintion has no path\n" if !$path;
|
||||||
|
|
||||||
my $timeout = 2;
|
my $timeout = 2;
|
||||||
my $res = PVE::Tools::df($path, $timeout);
|
my $res = PVE::Tools::df($path, $timeout);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user