[pve-devel] [PATCH 02/20] Plugin : add volume_protect && volume_unprotect (and also fix backing file regex parsing)

Alexandre Derumier aderumier at odiso.com
Mon Dec 3 14:32:27 CET 2012


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 <aderumier at odiso.com>
---
 PVE/Storage/Plugin.pm |   27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm
index c7c17e1..7648863 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,28 @@ sub volume_snapshot_delete {
     return undef;
 }
 
+sub volume_protect {
+    my ($class, $scfg, $storeid, $volname, $snap) = @_;
+
+    my $path = $class->path($scfg, $volname);
+
+    my $cmd = ['/usr/bin/chattr', '+i', $path];
+    run_command($cmd);
+
+    return undef;
+}
+
+sub volume_unprotect {
+    my ($class, $scfg, $storeid, $volname, $snap) = @_;
+
+    my $path = $class->path($scfg, $volname);
+
+    my $cmd = ['/usr/bin/chattr', '-i', $path];
+    run_command($cmd);
+
+    return undef;
+}
+
 sub list_images {
     my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
 
-- 
1.7.10.4




More information about the pve-devel mailing list