]> git.proxmox.com Git - pve-storage.git/blobdiff - PVE/Storage.pm
weaken matching for vzdump config extract filename
[pve-storage.git] / PVE / Storage.pm
index 3cf1b2ea50e265b64e8d55c06ff5395675b58493..b9ea42ae9716de87ec303540c4f862a942ce5763 100755 (executable)
@@ -321,6 +321,9 @@ sub parse_vmid {
     return int($vmid);
 }
 
+# NOTE: basename and basevmid are always undef for LVM-thin, where the
+# clone -> base reference is not encoded in the volume ID.
+# see note in PVE::Storage::LvmThinPlugin for details.
 sub parse_volname {
     my ($cfg, $volid) = @_;
 
@@ -341,6 +344,32 @@ sub parse_volume_id {
     return PVE::Storage::Plugin::parse_volume_id($volid, $noerr);
 }
 
+# test if we have read access to volid
+sub check_volume_access {
+    my ($rpcenv, $user, $cfg, $vmid, $volid) = @_;
+
+    my ($sid, $volname) = parse_volume_id($volid, 1);
+    if ($sid) {
+       my ($vtype, undef, $ownervm) = parse_volname($cfg, $volid);
+       if ($vtype eq 'iso' || $vtype eq 'vztmpl') {
+           # we simply allow access
+       } elsif (defined($ownervm) && defined($vmid) && ($ownervm == $vmid)) {
+           # we are owner - allow access
+       } elsif ($vtype eq 'backup' && $ownervm) {
+           $rpcenv->check($user, "/storage/$sid", ['Datastore.AllocateSpace']);
+           $rpcenv->check($user, "/vms/$ownervm", ['VM.Backup']);
+       } else {
+           # allow if we are Datastore administrator
+           $rpcenv->check($user, "/storage/$sid", ['Datastore.Allocate']);
+       }
+    } else {
+       die "Only root can pass arbitrary filesystem paths."
+           if $user ne 'root@pam';
+    }
+
+    return undef;
+}
+
 my $volume_is_base_and_used__no_lock = sub {
     my ($scfg, $storeid, $plugin, $volname) = @_;
 
@@ -367,6 +396,9 @@ my $volume_is_base_and_used__no_lock = sub {
     return 0;
 };
 
+# NOTE: this check does not work for LVM-thin, where the clone -> base
+# reference is not encoded in the volume ID.
+# see note in PVE::Storage::LvmThinPlugin for details.
 sub volume_is_base_and_used {
     my ($cfg, $volid) = @_;
 
@@ -580,12 +612,13 @@ sub storage_migrate {
            eval{
                run_command($send);
            };
-           my $err;
-           if ($err = $@){
-               run_command(['zfs', 'destroy', "$zfspath\@__migration__"]);
-               die $err;
-           }
-           run_command($destroy_target);
+           my $err = $@;
+           warn "zfs send/receive failed, cleaning up snapshot(s)..\n" if $err;
+           eval { run_command(['zfs', 'destroy', "$zfspath\@__migration__"]); };
+           warn "could not remove source snapshot: $@\n" if $@;
+           eval { run_command($destroy_target); };
+           warn "could not remove target snapshot: $@\n" if $@;
+           die $err if $err;
 
        } else {
            die "$errstr - target type $tcfg->{type} is not valid\n";
@@ -607,11 +640,11 @@ sub storage_migrate {
 
            eval {
                if ($tcfg->{type} eq 'lvmthin') {
-                   run_command([["dd", "if=$src"],["/usr/bin/ssh", "root\@${target_host}",
-                             "dd", 'conv=sparse', "of=$dst"]]);
+                   run_command([["dd", "if=$src", "bs=4k"],["/usr/bin/ssh", "root\@${target_host}",
+                             "dd", 'conv=sparse', "of=$dst", "bs=4k"]]);
                } else {
-                   run_command([["dd", "if=$src"],["/usr/bin/ssh", "root\@${target_host}",
-                             "dd", "of=$dst"]]);
+                   run_command([["dd", "if=$src", "bs=4k"],["/usr/bin/ssh", "root\@${target_host}",
+                             "dd", "of=$dst", "bs=4k"]]);
                }
            };
            if (my $err = $@) {
@@ -708,6 +741,7 @@ sub vdisk_free {
 
     # lock shared storage
     $plugin->cluster_lock_storage($storeid, $scfg->{shared}, undef, sub {
+       # LVM-thin allows deletion of still referenced base volumes!
        die "base volume '$volname' is still in use by linked clones\n"
            if &$volume_is_base_and_used__no_lock($scfg, $storeid, $plugin, $volname);
 
@@ -1001,9 +1035,9 @@ sub storage_info {
     my $ids = $cfg->{ids};
 
     my $info = {};
-    
+
     my @ctypes = PVE::Tools::split_list($content);
-    
+
     my $slist = [];
     foreach my $storeid (keys %$ids) {
 
@@ -1019,7 +1053,7 @@ sub storage_info {
            }
            next if !$want_ctype;
        }
-       
+
        my $type = $ids->{$storeid}->{type};
 
        $info->{$storeid} = {
@@ -1052,9 +1086,9 @@ sub storage_info {
        eval { ($total, $avail, $used, $active) = $plugin->status($storeid, $scfg, $cache); };
        warn $@ if $@;
        next if !$active;
-       $info->{$storeid}->{total} = $total;
-       $info->{$storeid}->{avail} = $avail;
-       $info->{$storeid}->{used} = $used;
+       $info->{$storeid}->{total} = int($total);
+       $info->{$storeid}->{avail} = int($avail);
+       $info->{$storeid}->{used} = int($used);
        $info->{$storeid}->{active} = $active;
     }
 
@@ -1379,9 +1413,9 @@ sub extract_vzdump_config {
 
     my $archive = abs_filesystem_path($cfg, $volid);
 
-    if ($volid =~ /\/vzdump-(lxc|openvz)-\d+-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.(tgz|(tar(\.(gz|lzo))?))$/) {
+    if ($volid =~ /vzdump-(lxc|openvz)-\d+-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.(tgz|(tar(\.(gz|lzo))?))$/) {
        return extract_vzdump_config_tar($archive,'^(\./etc/vzdump/(pct|vps)\.conf)$');
-    } elsif ($volid =~ /\/vzdump-qemu-\d+-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.(tgz|((tar|vma)(\.(gz|lzo))?))$/) {
+    } elsif ($volid =~ /vzdump-qemu-\d+-(\d{4})_(\d{2})_(\d{2})-(\d{2})_(\d{2})_(\d{2})\.(tgz|((tar|vma)(\.(gz|lzo))?))$/) {
        my $format;
        my $comp;
        if ($7 eq 'tgz') {