[pve-devel] [PATCH 02/31] Plugin : add volume_protect

2013-01-22 Thread Alexandre Derumier
(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 |   20 +---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm
index 25e012c..6f1cac9 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*$/) {
@@ -576,6 +575,21 @@ sub volume_has_feature {
 return undef;
 }
 
+sub volume_protect {
+my ($class, $scfg, $storeid, $volname, $snap, $read_only) = @_;
+
+return if $snap;
+
+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


[pve-devel] [PATCH 02/31] Plugin : add volume_protect

2013-01-08 Thread Alexandre Derumier
(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 |   20 +---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm
index 25e012c..6f1cac9 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*$/) {
@@ -576,6 +575,21 @@ sub volume_has_feature {
 return undef;
 }
 
+sub volume_protect {
+my ($class, $scfg, $storeid, $volname, $snap, $read_only) = @_;
+
+return if $snap;
+
+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