[pve-devel] r6387 - in pve-storage/pve2: . PVE PVE/API2/Storage
svn-commits at proxmox.com
svn-commits at proxmox.com
Mon Aug 1 11:29:24 CEST 2011
Author: dietmar
Date: 2011-08-01 11:29:24 +0200 (Mon, 01 Aug 2011)
New Revision: 6387
Modified:
pve-storage/pve2/ChangeLog
pve-storage/pve2/PVE/API2/Storage/Config.pm
pve-storage/pve2/PVE/API2/Storage/Scan.pm
pve-storage/pve2/PVE/Storage.pm
Log:
* PVE/Storage.pm (iscsi_test_portal): factor out code to test if
portal in online (use 2 seconds timeout).
(iscsi_discovery): test if portal is online using
iscsi_test_portal(). This avoids that we run int a timeout (iscsi
default timeout is 15 seconds, we now use 2 seconds)
* PVE/API2/Storage/Config.pm: s/resolv_portal_dns/resolv_portal/
(delete) do not call deactivate_storage(), because we likely run
into timeouts.
* PVE/Storage.pm (resolv_portal_dns): remove duplicate (use resolv_portal instead)
(resolv_portal): use resolv_server()
* PVE/API2/Storage/Scan.pm: remove unneccessary call to resolv_portal_dns()
Modified: pve-storage/pve2/ChangeLog
===================================================================
--- pve-storage/pve2/ChangeLog 2011-08-01 06:26:10 UTC (rev 6386)
+++ pve-storage/pve2/ChangeLog 2011-08-01 09:29:24 UTC (rev 6387)
@@ -1,5 +1,20 @@
2011-08-01 Proxmox Support Team <support at proxmox.com>
+ * PVE/Storage.pm (iscsi_test_portal): factor out code to test if
+ portal in online (use 2 seconds timeout).
+ (iscsi_discovery): test if portal is online using
+ iscsi_test_portal(). This avoids that we run int a timeout (iscsi
+ default timeout is 15 seconds, we now use 2 seconds)
+
+ * PVE/API2/Storage/Config.pm: s/resolv_portal_dns/resolv_portal/
+ (delete) do not call deactivate_storage(), because we likely run
+ into timeouts.
+
+ * PVE/Storage.pm (resolv_portal_dns): remove duplicate (use resolv_portal instead)
+ (resolv_portal): use resolv_server()
+
+ * PVE/API2/Storage/Scan.pm: remove unneccessary call to resolv_portal_dns()
+
* PVE/Storage.pm (iscsi_login): use Net::Ping to check portal
availability (avoid long iscsi login timeouts)
Modified: pve-storage/pve2/PVE/API2/Storage/Config.pm
===================================================================
--- pve-storage/pve2/PVE/API2/Storage/Config.pm 2011-08-01 06:26:10 UTC (rev 6386)
+++ pve-storage/pve2/PVE/API2/Storage/Config.pm 2011-08-01 09:29:24 UTC (rev 6387)
@@ -174,7 +174,7 @@
delete $param->{storage};
if ($param->{portal}) {
- $param->{portal} = PVE::Storage::resolv_portal_dns($param->{portal});
+ $param->{portal} = PVE::Storage::resolv_portal($param->{portal});
}
my $opts = PVE::Storage::parse_options($storeid, $type, $param, 1);
@@ -317,9 +317,6 @@
die "can't remove storage - storage is used as base of another storage\n"
if PVE::Storage::storage_is_used ($cfg, $storeid);
- eval { PVE::Storage::deactivate_storage($cfg, $storeid); };
- syslog("info", "unable to deactivate storage '$storeid' - $@") if $@;
-
delete ($cfg->{ids}->{$storeid});
cfs_write_file('storage.cfg', $cfg);
Modified: pve-storage/pve2/PVE/API2/Storage/Scan.pm
===================================================================
--- pve-storage/pve2/PVE/API2/Storage/Scan.pm 2011-08-01 06:26:10 UTC (rev 6386)
+++ pve-storage/pve2/PVE/API2/Storage/Scan.pm 2011-08-01 09:29:24 UTC (rev 6387)
@@ -107,8 +107,7 @@
code => sub {
my ($param) = @_;
- my $portal = PVE::Storage::resolv_portal_dns($param->{portal});
- my $res = PVE::Storage::scan_iscsi($portal);
+ my $res = PVE::Storage::scan_iscsi($param->{portal});
my $data = [];
foreach my $k (keys %$res) {
Modified: pve-storage/pve2/PVE/Storage.pm
===================================================================
--- pve-storage/pve2/PVE/Storage.pm 2011-08-01 06:26:10 UTC (rev 6386)
+++ pve-storage/pve2/PVE/Storage.pm 2011-08-01 09:29:24 UTC (rev 6387)
@@ -277,23 +277,6 @@
return $portal;
}
-sub resolv_portal_dns {
- my ($portal_dns) = @_;
-
- if ($portal_dns =~ m/^([^:]+)(:(\d+))?$/) {
- my $server = $1;
- my $port = $3;
-
- my $packed_ip = gethostbyname($server);
- if (defined $packed_ip) {
- $server = inet_ntoa($packed_ip);
- return $port ? "$server:$port" : $server;
- }
-
- raise_param_exc({ portal => "unable to resolve portal address" });
- }
-}
-
PVE::JSONSchema::register_format('pve-storage-content', \&verify_content);
sub verify_content {
my ($ct, $noerr) = @_;
@@ -802,6 +785,15 @@
return $res;
}
+sub iscsi_test_portal {
+ my ($portal) = @_;
+
+ my ($server, $port) = split(':', $portal);
+ my $p = Net::Ping->new("tcp", 2);
+ $p->port_number($port || 3260);
+ return $p->ping($server);
+}
+
sub iscsi_discovery {
my ($portal) = @_;
@@ -811,6 +803,9 @@
'--portal', $portal];
my $res = {};
+
+ return $res if !iscsi_test_portal($portal); # fixme: raise exception here?
+
run_command ($cmd, outfunc => sub {
my $line = shift;
@@ -834,12 +829,9 @@
my $success = 0;
foreach my $portal (@{$res->{$target}}) {
- my ($server, $port) = split(':', $portal);
my $cmd = [$ISCSIADM, '--mode', 'node', '--portal', $portal,
'--targetname', $target, '--login'];
- my $p = Net::Ping->new("tcp", 2);
- $p->port_number($port);
- if ($p->ping($server)) {
+ if (iscsi_test_portal($portal)) {
eval { run_command ($cmd); $success = 1; };
warn $@ if $@;
}
@@ -2205,20 +2197,21 @@
}
sub resolv_portal {
- my ($portal) = @_;
+ my ($portal, $noerr) = @_;
if ($portal =~ m/^([^:]+)(:(\d+))?$/) {
my $server = $1;
my $port = $3;
- my $packed_ip = gethostbyname($server);
- if (defined $packed_ip) {
- $server = inet_ntoa($packed_ip);
+ if (my $ip = resolv_server($server)) {
+ $server = $ip;
$portal = $port ? "$server:$port" : $server;
return $portal;
}
}
- return undef;
+ return undef if $noerr;
+
+ raise_param_exc({ portal => "unable to resolve portal address '$portal'" });
}
sub scan_iscsi {
More information about the pve-devel
mailing list