[pve-devel] [PATCH container] Refactor content type check into sub

Fabian Grünbichler f.gruenbichler at proxmox.com
Wed Mar 16 10:53:13 CET 2016


---
Note: left the $used_volids line outside the sub for better readability

 src/PVE/LXC/Config.pm | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/PVE/LXC/Config.pm b/src/PVE/LXC/Config.pm
index ef4c24b..a5c756f 100644
--- a/src/PVE/LXC/Config.pm
+++ b/src/PVE/LXC/Config.pm
@@ -805,6 +805,14 @@ sub update_pct_config {
     }
 
     my $used_volids = {};
+    my $check_content_type = sub {
+	my ($mp) = @_;
+	my $sid = PVE::Storage::parse_volume_id($mp->{volume});
+	my $scfg = PVE::Storage::config();
+	my $storage_config = PVE::Storage::storage_config($scfg, $sid);
+	die "storage '$sid' does not allow content type 'rootdir' (Container)\n"
+	    if !$storage_config->{content}->{rootdir};
+    };
 
     foreach my $opt (keys %$param) {
 	my $value = $param->{$opt};
@@ -850,11 +858,7 @@ sub update_pct_config {
 	    my $old = $conf->{$opt};
 	    my $mp = PVE::LXC::Config->parse_ct_mountpoint($value);
 	    if ($mp->{type} eq 'volume') {
-		my $sid = PVE::Storage::parse_volume_id($mp->{volume});
-		my $scfg = PVE::Storage::config();
-		my $storage_config = PVE::Storage::storage_config($scfg, $sid);
-		die "storage '$sid' does not allow content type 'rootdir' (Container)\n"
-		    if !$storage_config->{content}->{rootdir};
+		&$check_content_type($mp);
 		$used_volids->{$mp->{volume}} = 1;
 	    }
 	    $conf->{$opt} = $value;
@@ -872,11 +876,7 @@ sub update_pct_config {
 	    $conf->{$opt} = $value;
 	    my $mp = PVE::LXC::Config->parse_ct_rootfs($value);
 	    if ($mp->{type} eq 'volume') {
-		my $sid = PVE::Storage::parse_volume_id($mp->{volume});
-		my $scfg = PVE::Storage::config();
-		my $storage_config = PVE::Storage::storage_config($scfg, $sid);
-		die "storage '$sid' does not allow content type 'rootdir' (Container)\n"
-		    if !$storage_config->{content}->{rootdir};
+		&$check_content_type($mp);
 		$used_volids->{$mp->{volume}} = 1;
 	    }
 	    if (defined($old)) {
-- 
2.1.4





More information about the pve-devel mailing list