X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=PVE%2FStorage.pm;h=f1181cc9c5bbc070107dc387ceed8e86fa7275c6;hb=e34afeb11724b705766c0581a66cc4c4b26303c0;hp=2a8deaf29dd446832d19783d08b778ed8baa90cb;hpb=4b26f8140df562008176fa19bd80ca8ea33593f2;p=pve-storage.git diff --git a/PVE/Storage.pm b/PVE/Storage.pm index 2a8deaf..f1181cc 100755 --- a/PVE/Storage.pm +++ b/PVE/Storage.pm @@ -12,6 +12,7 @@ use File::Basename; use File::Path; use Cwd 'abs_path'; use Socket; +use Time::Local qw(timelocal); use PVE::Tools qw(run_command file_read_firstline dir_glob_foreach $IPV6RE); use PVE::Cluster qw(cfs_read_file cfs_write_file cfs_lock_file); @@ -619,11 +620,6 @@ sub storage_migrate { my $tcfg = storage_config($cfg, $target_storeid); - my $vtype = (parse_volname($cfg, $volid))[0]; - - die "content type '$vtype' is not available on storage '$target_storeid'\n" - if !$tcfg->{content}->{$vtype}; - my $target_volname; if ($opts->{target_volname}) { $target_volname = $opts->{target_volname}; @@ -1394,15 +1390,24 @@ sub archive_info { my $info; my $volid = basename($archive); - if ($volid =~ /\.(tgz$|tar|vma)(?:\.(${\PVE::Storage::Plugin::COMPRESSOR_RE}))?$/) { - $info = decompressor_info($1, $2); - $info->{type} = 'unknown'; - - if ($volid =~ /vzdump-(lxc|openvz|qemu)-\d+-(?:\d{4})_(?:\d{2})_(?:\d{2})-(?:\d{2})_(?:\d{2})_(?:\d{2})/) { - $info->{type} = $1; + if ($volid =~ /^(vzdump-(lxc|openvz|qemu)-\d+-.+\.(tgz$|tar|vma)(?:\.(${\PVE::Storage::Plugin::COMPRESSOR_RE}))?)$/) { + my $filename = "$1"; # untaint + my ($type, $format, $comp) = ($2, $3, $4); + my $format_re = defined($comp) ? "$format.$comp" : "$format"; + $info = decompressor_info($format, $comp); + $info->{filename} = $filename; + $info->{type} = $type; + + if ($volid =~ /^(vzdump-${type}-([1-9][0-9]{2,8})-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2}))\.${format_re}$/) { + $info->{logfilename} = "$1.log"; + $info->{vmid} = int($2); + $info->{ctime} = timelocal($8, $7, $6, $5, $4 - 1, $3 - 1900); + $info->{is_std_name} = 1; + } else { + $info->{is_std_name} = 0; } } else { - die "ERROR: couldn't determine format and compression type\n"; + die "ERROR: couldn't determine archive info from '$archive'\n"; } return $info; @@ -1437,7 +1442,7 @@ sub extract_vzdump_config_tar { $raw .= "$output\n"; }; - PVE::Tools::run_command(['tar', '-xpOf', $archive, $file, '--occurrence'], outfunc => $out); + run_command(['tar', '-xpOf', $archive, $file, '--occurrence'], outfunc => $out); return wantarray ? ($raw, $file) : $raw; } @@ -1445,23 +1450,17 @@ sub extract_vzdump_config_tar { sub extract_vzdump_config_vma { my ($archive, $comp) = @_; - my $cmd; my $raw = ''; - my $out = sub { - my $output = shift; - $raw .= "$output\n"; - }; - + my $out = sub { $raw .= "$_[0]\n"; }; my $info = archive_info($archive); $comp //= $info->{compression}; my $decompressor = $info->{decompressor}; if ($comp) { - $cmd = [ [@$decompressor, $archive], ["vma", "config", "-"] ]; + my $cmd = [ [@$decompressor, $archive], ["vma", "config", "-"] ]; - # in some cases, lzop/zcat exits with 1 when its stdout pipe is - # closed early by vma, detect this and ignore the exit code later + # lzop/zcat exits with 1 when the pipe is closed early by vma, detect this and ignore the exit code later my $broken_pipe; my $errstring; my $err = sub { @@ -1473,23 +1472,18 @@ sub extract_vzdump_config_vma { } }; - # in other cases, the pipeline will exit with exit code 141 - # because of the broken pipe, handle / ignore this as well - my $rc; - eval { - $rc = PVE::Tools::run_command($cmd, outfunc => $out, errfunc => $err, noerr => 1); - }; + my $rc = eval { run_command($cmd, outfunc => $out, errfunc => $err, noerr => 1) }; my $rerr = $@; - # use exit code if no stderr output and not just broken pipe - if (!$errstring && !$broken_pipe && $rc != 0 && $rc != 141) { + $broken_pipe ||= $rc == 141; # broken pipe from vma POV + + if (!$errstring && !$broken_pipe && $rc != 0) { die "$rerr\n" if $rerr; die "config extraction failed with exit code $rc\n"; } die "$errstring\n" if $errstring; } else { - # simple case without compression and weird piping behaviour - PVE::Tools::run_command(["vma", "config", $archive], outfunc => $out); + run_command(["vma", "config", $archive], outfunc => $out); } return wantarray ? ($raw, undef) : $raw;