allow backup to local storage and code cleanups

This commit is contained in:
Dietmar Maurer
2011-10-18 11:23:31 +02:00
parent 883eeea67d
commit 568de3d125
2 changed files with 35 additions and 25 deletions

View File

@ -66,17 +66,14 @@ __PACKAGE__->register_method ({
my $res = [];
foreach my $ct (@$cts) {
my $data;
if ($ct eq 'images') {
if ($ct eq 'images' || defined($param->{vmid})) {
$data = PVE::Storage::vdisk_list ($cfg, $storeid, $param->{vmid});
} elsif ($ct eq 'iso') {
$data = PVE::Storage::template_list ($cfg, $storeid, 'iso')
if !$param->{vmid};
$data = PVE::Storage::template_list ($cfg, $storeid, 'iso');
} elsif ($ct eq 'vztmpl') {
$data = PVE::Storage::template_list ($cfg, $storeid, 'vztmpl')
if !$param->{vmid};
$data = PVE::Storage::template_list ($cfg, $storeid, 'vztmpl');
} elsif ($ct eq 'backup') {
$data = PVE::Storage::template_list ($cfg, $storeid, 'backup')
if !$param->{vmid};
$data = PVE::Storage::template_list ($cfg, $storeid, 'backup');
}
next if !$data || !$data->{$storeid};

View File

@ -405,12 +405,6 @@ sub check_type {
}
}
# no backup to local storage
if ($storeid && $storeid eq 'local' && $res->{backup}) {
return undef if $noerr;
die "storage 'local' does not support backups\n";
}
return $res;
} elsif ($ct eq 'volume') {
return $value if parse_volume_id ($value, $noerr);
@ -753,6 +747,15 @@ sub get_vztmpl_dir {
return $tmpldir;
}
sub get_backup_dir {
my ($cfg, $storeid) = @_;
my $dir = $cfg->{ids}->{$storeid}->{path};
$dir .= '/dump' if $storeid eq 'local';
return $dir;
}
# iscsi utility functions
sub iscsi_session_list {
@ -1045,9 +1048,10 @@ sub path_to_volume_id {
my $type = $ids->{$sid}->{type};
next if !($type eq 'dir' || $type eq 'nfs');
my $imagedir = $ids->{$sid}->{path} . "/images";
my $imagedir = get_image_dir($cfg, $sid);
my $isodir = get_iso_dir($cfg, $sid);
my $tmpldir = get_vztmpl_dir($cfg, $sid);
my $backupdir = get_backup_dir($cfg, $sid);
if ($path =~ m!^$imagedir/(\d+)/([^/\s]+)$!) {
my $vmid = $1;
@ -1059,6 +1063,9 @@ sub path_to_volume_id {
} elsif ($path =~ m!^$tmpldir/([^/]+\.tar\.gz)$!) {
my $name = $1;
return ('vztmpl', "$sid:vztmpl/$name");
} elsif ($path =~ m!^$backupdir/([^/]+\.(tar|tgz))$!) {
my $name = $1;
return ('iso', "$sid:backup/$name");
}
}
@ -1083,6 +1090,7 @@ sub path {
my $imagedir = get_image_dir($cfg, $storeid, $vmid);
my $isodir = get_iso_dir($cfg, $storeid);
my $tmpldir = get_vztmpl_dir($cfg, $storeid);
my $backupdir = get_backup_dir($cfg, $storeid);
if ($vtype eq 'image') {
$path = "$imagedir/$name";
@ -1090,6 +1098,8 @@ sub path {
$path = "$isodir/$name";
} elsif ($vtype eq 'vztmpl') {
$path = "$tmpldir/$name";
} elsif ($vtype eq 'backup') {
$path = "$backupdir/$name";
} else {
die "should not be reached";
}
@ -1553,7 +1563,7 @@ sub template_list {
} elsif ($tt eq 'vztmpl') {
$path = get_vztmpl_dir($cfg, $sid);
} elsif ($tt eq 'backup') {
$path = $scfg->{path};
$path = get_backup_dir($cfg, $sid);
} else {
die "unknown template type '$tt'\n";
}
@ -1859,6 +1869,7 @@ sub __activate_storage_full {
my $imagedir = get_image_dir($cfg, $storeid);
my $isodir = get_iso_dir($cfg, $storeid);
my $tmpldir = get_vztmpl_dir($cfg, $storeid);
my $backupdir = get_backup_dir($cfg, $storeid);
if (defined($scfg->{content})) {
mkpath $imagedir if $scfg->{content}->{images} &&
@ -1867,6 +1878,8 @@ sub __activate_storage_full {
$isodir ne $path;
mkpath $tmpldir if $scfg->{content}->{vztmpl} &&
$tmpldir ne $path;
mkpath $backupdir if $scfg->{content}->{backup} &&
$backupdir ne $path;
}
} elsif ($type eq 'lvm') {