[pve-devel] r6377 - in pve-storage/pve2: . PVE

svn-commits at proxmox.com svn-commits at proxmox.com
Thu Jul 28 12:21:04 CEST 2011


Author: dietmar
Date: 2011-07-28 12:21:04 +0200 (Thu, 28 Jul 2011)
New Revision: 6377

Modified:
   pve-storage/pve2/ChangeLog
   pve-storage/pve2/PVE/Storage.pm
Log:
impl. node restrictions


Modified: pve-storage/pve2/ChangeLog
===================================================================
--- pve-storage/pve2/ChangeLog	2011-07-28 09:24:52 UTC (rev 6376)
+++ pve-storage/pve2/ChangeLog	2011-07-28 10:21:04 UTC (rev 6377)
@@ -1,5 +1,10 @@
 2011-07-28  Proxmox Support Team  <support at proxmox.com>
 
+	* PVE/Storage.pm (storage_check_node): check if storage is
+	available on a specific node.
+	(storage_check_enabled): check if storage is
+	available on the local node.
+	
 	* PVE/API2/Storage/Config.pm (create): add 'nodes' options, do not
 	activate storage automatically.
 	

Modified: pve-storage/pve2/PVE/Storage.pm
===================================================================
--- pve-storage/pve2/PVE/Storage.pm	2011-07-28 09:24:52 UTC (rev 6376)
+++ pve-storage/pve2/PVE/Storage.pm	2011-07-28 10:21:04 UTC (rev 6377)
@@ -18,6 +18,7 @@
 use PVE::Cluster qw(cfs_register_file cfs_read_file cfs_write_file cfs_lock_file);
 use PVE::Exception qw(raise_param_exc);
 use PVE::JSONSchema;
+use PVE::INotify;
 
 my $ISCSIADM = '/usr/bin/iscsiadm';
 my $UDEVADM = '/sbin/udevadm';
@@ -630,16 +631,35 @@
     return $scfg;
 }
 
-sub storage_check_enabled {
-    my ($cfg, $storeid) = @_;
+sub storage_check_node {
+    my ($cfg, $storeid, $node, $noerr) = @_;
 
     my $scfg = storage_config ($cfg, $storeid);
 
-    die "storage '$storeid' is disabled\n" if $scfg->{disable};
+    if ($scfg->{nodes}) {
+	$node = PVE::INotify::nodename() if !$node || ($node eq 'localhost');
+	if (!$scfg->{nodes}->{$node}) {
+	    die "storage '$storeid' is not available on node '$node'" if !$noerr;
+	    return undef;
+	}
+    }
 
     return $scfg;
 }
 
+sub storage_check_enabled {
+    my ($cfg, $storeid, $node, $noerr) = @_;
+
+    my $scfg = storage_config ($cfg, $storeid);
+
+    if ($scfg->{disable}) {
+	die "storage '$storeid' is disabled\n" if !$noerr;
+	return undef;
+    }
+
+    return storage_check_node($cfg, $storeid, $node, $noerr);
+}
+
 sub storage_ids {
     my ($cfg) = @_;
 
@@ -1522,7 +1542,7 @@
 
     my $ids = $cfg->{ids};
 
-    storage_check_enabled ($cfg, $storeid) if ($storeid);
+    storage_check_enabled($cfg, $storeid) if ($storeid);
 
     my $res = {};
 
@@ -1534,7 +1554,7 @@
 	my $scfg = $ids->{$sid};
 	my $type = $scfg->{type};
 
-	next if $scfg->{disable};
+	next if !storage_check_enabled($cfg, $sid, undef, 1);
 
 	next if $tt eq 'iso' && !$scfg->{content}->{iso};
 	next if $tt eq 'vztmpl' && !$scfg->{content}->{vztmpl};
@@ -1627,7 +1647,7 @@
 
     my $ids = $cfg->{ids};
 
-    storage_check_enabled ($cfg, $storeid) if ($storeid);
+    storage_check_enabled($cfg, $storeid) if ($storeid);
 
     my $res = {};
 
@@ -1640,15 +1660,14 @@
 	foreach my $volid (@$vollist) {
 	    my ($sid, undef) = parse_volume_id ($volid);
 	    next if !defined ($ids->{$sid});
-	    next if $ids->{$sid}->{disable};
+	    next if !storage_check_enabled($cfg, $sid, undef, 1);
 	    push @$storage_list, $sid;
 	    $stypes->{$ids->{$sid}->{type}} = 1;
 	}
     } else {
 	foreach my $sid (keys %$ids) {
 	    next if $storeid && $storeid ne $sid;
-	    next if $ids->{$sid}->{disable};
-
+	    next if !storage_check_enabled($cfg, $sid, undef, 1);
 	    push @$storage_list, $sid;
 	    $stypes->{$ids->{$sid}->{type}} = 1;
 	}
@@ -1665,7 +1684,7 @@
     foreach my $sid (keys %$ids) {
 	if ($storeid) {
 	    next if $storeid ne $sid;
-	    next if $ids->{$storeid}->{disable};
+	    next if !storage_check_enabled($cfg, $sid, undef, 1);
 	}
 	my $scfg = $ids->{$sid};
 	my $type = $scfg->{type};
@@ -1809,7 +1828,7 @@
 sub __activate_storage_full {
     my ($cfg, $storeid, $session) = @_;
 
-    my $scfg = storage_check_enabled ($cfg, $storeid);
+    my $scfg = storage_check_enabled($cfg, $storeid);
 
     return if $session->{activated}->{$storeid};
 
@@ -2046,7 +2065,7 @@
 
 	next if $content && !$ids->{$storeid}->{content}->{$content};
 
-	next if $ids->{$storeid}->{disable};
+	next if !storage_check_enabled($cfg, $storeid, undef, 1);
 
 	my $type = $ids->{$storeid}->{type};
 



More information about the pve-devel mailing list