(and also fix backing file regex parsing)

for files, we protect  the volume file with chattr.
So we can only read it, but can't delete or move it.

Signed-off-by: Alexandre Derumier <aderum...@odiso.com>
---
 PVE/Storage/Plugin.pm |   18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm
index c7c17e1..a46581b 100644
--- a/PVE/Storage/Plugin.pm
+++ b/PVE/Storage/Plugin.pm
@@ -465,11 +465,10 @@ sub file_size_info {
     eval {
        run_command($cmd, timeout => $timeout, outfunc => sub {
            my $line = shift;
-
            if ($line =~ m/^file format:\s+(\S+)\s*$/) {
                $format = $1;
-           } elsif ($line =~ m/^backing file:\s(\S+)\s/) {
-               $parent = $1;
+           } elsif ($line =~ m!^backing file:\s(\S+)/(\d+)/(\S+)$!) {
+               $parent = $2."/".$3;
            } elsif ($line =~ m/^virtual size:\s\S+\s+\((\d+)\s+bytes\)$/) {
                $size = int($1);
            } elsif ($line =~ m/^disk size:\s+(\d+(.\d+)?)([KMGT])\s*$/) {
@@ -558,6 +557,19 @@ sub volume_snapshot_delete {
     return undef;
 }
 
+sub volume_protect {
+    my ($class, $scfg, $storeid, $volname, $snap, $read_only) = @_;
+
+    my $path = $class->path($scfg, $volname);
+
+    my $action = $read_only ? "+i":"-i";
+
+    my $cmd = ['/usr/bin/chattr', $action, $path];
+    run_command($cmd);
+
+    return undef;
+}
+
 sub list_images {
     my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
 
-- 
1.7.10.4

_______________________________________________
pve-devel mailing list
pve-devel@pve.proxmox.com
http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to