[pve-devel] [PATCH 2/8] Plugin : add volume_lock && volume_unlock (and also fix backing file regex parsing)

Alexandre Derumier aderumier at odiso.com
Thu Nov 29 10:38:49 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..9bd9137 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_lock {
+    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_unlock {
+    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