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

svn-commits at proxmox.com svn-commits at proxmox.com
Wed Mar 9 10:38:04 CET 2011


Author: dietmar
Date: 2011-03-09 10:38:04 +0100 (Wed, 09 Mar 2011)
New Revision: 5659

Modified:
   pve-storage/pve2/ChangeLog
   pve-storage/pve2/PVE/Storage.pm
   pve-storage/pve2/control.in
   pve-storage/pve2/pvesm
Log:
	* PVE/Storage.pm (file_size_info): allow to pass timeout
	(important when NFS server is down)
	(__activate_storage_full): avoid call to mkpath if not necessary
	- avoid hang when NFS server is offline
	(storage_info): return sizes in bytes
	(storage_info): use PVE::Tools::df with timeout
	(lvm_vgs): use '--units b' (report size in bytes)
	(lvm_lvs): use '--units b' (report size in bytes)
	(file_size_info): report size in bytes

	* control.in (Depends): remove libfilesys-df-perl



Modified: pve-storage/pve2/ChangeLog
===================================================================
--- pve-storage/pve2/ChangeLog	2011-03-09 07:41:51 UTC (rev 5658)
+++ pve-storage/pve2/ChangeLog	2011-03-09 09:38:04 UTC (rev 5659)
@@ -1,3 +1,17 @@
+2011-03-09  Proxmox Support Team  <support at proxmox.com>
+
+	* PVE/Storage.pm (file_size_info): allow to pass timeout
+	(important when NFS server is down)
+	(__activate_storage_full): avoid call to mkpath if not necessary
+	- avoid hang when NFS server is offline
+	(storage_info): return sizes in bytes
+	(storage_info): use PVE::Tools::df with timeout
+	(lvm_vgs): use '--units b' (report size in bytes)
+	(lvm_lvs): use '--units b' (report size in bytes)
+	(file_size_info): report size in bytes
+
+	* control.in (Depends): remove libfilesys-df-perl
+
 2011-03-08  Proxmox Support Team  <support at proxmox.com>
 
 	* PVE/Storage.pm (__activate_storage_full): avoid to create empty

Modified: pve-storage/pve2/PVE/Storage.pm
===================================================================
--- pve-storage/pve2/PVE/Storage.pm	2011-03-09 07:41:51 UTC (rev 5658)
+++ pve-storage/pve2/PVE/Storage.pm	2011-03-09 09:38:04 UTC (rev 5659)
@@ -10,7 +10,6 @@
 use File::Basename;
 use File::Path;
 use IPC::Open2;
-use Filesys::Df;
 use Cwd 'abs_path';
 use Getopt::Long qw(GetOptionsFromArray);
 use Socket;
@@ -1352,7 +1351,7 @@
 
 sub lvm_vgs {
 
-    my $cmd = ['/sbin/vgs', '--separator', ':', '--noheadings', '--units', 'k',
+    my $cmd = ['/sbin/vgs', '--separator', ':', '--noheadings', '--units', 'b',
 	       '--unbuffered', '--nosuffix', '--options',
 	       'vg_name,vg_size,vg_free'];
 
@@ -1373,7 +1372,7 @@
 sub lvm_lvs {
     my ($vgname) = @_;
 
-    my $cmd = ['/sbin/lvs', '--separator', ':', '--noheadings', '--units', 'k',
+    my $cmd = ['/sbin/lvs', '--separator', ':', '--noheadings', '--units', 'b',
 	       '--unbuffered', '--nosuffix', '--options',
 	       'vg_name,lv_name,lv_size,uuid,tags'];
 
@@ -1531,7 +1530,7 @@
 }
 
 sub file_size_info {
-    my ($filename) = @_;
+    my ($filename, $timeout) = @_;
 
     my $cmd = ['/usr/bin/qemu-img', 'info', $filename];
 
@@ -1540,21 +1539,21 @@
     my $used = 0;
 
     eval {
-	run_command ($cmd, outfunc => sub {
+	run_command ($cmd, timeout => $timeout, outfunc => sub {
 	    my $line = shift;
 
 	    if ($line =~ m/^file format:\s+(\S+)\s*$/) {
 		$format = $1;
 	    } elsif ($line =~ m/^virtual size:\s\S+\s+\((\d+)\s+bytes\)$/) {
-		$size = int ($1/1024);
+		$size = int($1);
 	    } elsif ($line =~ m/^disk size:\s+(\d+(.\d+)?)([KMGT])\s*$/) {
 		$used = $1;
 		my $u = $3;
 
-		$used *= 1 if $u eq 'K';
-		$used *= 1024 if $u eq 'M';
-		$used *= (1024*1024) if $u eq 'G';
-		$used *= (1024*1024*1024) if $u eq 'T';
+		$used *= 1024 if $u eq 'K';
+		$used *= (1024*1024) if $u eq 'M';
+		$used *= (1024*1024*1024) if $u eq 'G';
+		$used *= (1024*1024*1024*1024) if $u eq 'T';
 	    }
 	});
     };
@@ -1726,7 +1725,7 @@
     my $cmd = ['/bin/mount', '-t', 'nfs', $source, $mountpoint];
     if ($options) {
 	push @$cmd, '-o', $options;
-    }
+    } 
 
     run_command ($cmd);
 }
@@ -1768,18 +1767,30 @@
     if ($type eq 'dir' || $type eq 'nfs') {
 
 	my $path = $scfg->{path};
-	mkpath $path;
 
-	die "unable to activate storage '$storeid' - " .
-	    "directory '$path' does not exist\n" if ! -d $path;
-
 	if ($type eq 'nfs') {
 	    my $server = $scfg->{server};
 	    my $export = $scfg->{export};
 
-	    if (!nfs_is_mounted ($server, $export, $path, $mountdata)) {
+	    if (!nfs_is_mounted ($server, $export, $path, $mountdata)) {    
+		    
+		# NOTE: only call mkpath when not mounted (avoid hang 
+		# when NFS server is offline 
+		    
+		mkpath $path;
+
+		die "unable to activate storage '$storeid' - " .
+		    "directory '$path' does not exist\n" if ! -d $path;
+
 		nfs_mount ($server, $export, $path, $scfg->{options});
 	    }
+
+	} else {
+
+	    mkpath $path;
+
+	    die "unable to activate storage '$storeid' - " .
+		"directory '$path' does not exist\n" if ! -d $path;
 	}
 
 	my $imagedir = get_image_dir ($cfg, $storeid);
@@ -1979,7 +1990,6 @@
 	    total => 0, 
 	    avail => 0, 
 	    used => 0, 
-	    free => 0, 
 	    disable => defined ($ids->{$storeid}->{disable}),
 	    active => 0,
 	};
@@ -2008,7 +2018,10 @@
 	$session->{iscsi_sessions} = $iscsi_sessions;
     } 
  
-    eval { activate_storage_list ($cfg, $slist, $session); };
+    foreach my $storeid (@$slist) {
+	eval { __activate_storage_full ($cfg, $storeid, $session); };
+	warn $@ if $@;
+    }
 
     foreach my $storeid (keys %$ids) {
 	my $scfg = $ids->{$storeid};
@@ -2026,17 +2039,14 @@
 		next if !nfs_is_mounted ($server, $export, $path, $mountdata); 
 	    }
 
-	    my $res = df ($path);
+	    my $timeout = 2;
+	    my $res = PVE::Tools::df($path, $timeout);
 
-	    next if !$res;
+	    next if !$res || !$res->{total};
 
-	    # available memory =  total memory - reserved memory
-	    my $bavail = $res->{used}+$res->{bavail};
-
-	    $info->{$storeid}->{total} = $res->{blocks}; 
-	    $info->{$storeid}->{avail} = $bavail; 
+	    $info->{$storeid}->{total} = $res->{total}; 
+	    $info->{$storeid}->{avail} = $res->{used} + $res->{avail}; 
 	    $info->{$storeid}->{used} = $res->{used}; 
-	    $info->{$storeid}->{free} = $bavail - $res->{used}; 
 	    $info->{$storeid}->{active} = 1;
 
 	} elsif ($type eq 'lvm') {
@@ -2053,7 +2063,6 @@
 		$info->{$storeid}->{total} = $total; 
 		$info->{$storeid}->{avail} = $total; 
 		$info->{$storeid}->{used} = $total - $free; 
-		$info->{$storeid}->{free} = $free; 
 		$info->{$storeid}->{active} = 1;
 	    }
 
@@ -2062,7 +2071,6 @@
 	    $info->{$storeid}->{total} = 0; 
 	    $info->{$storeid}->{avail} = 0; 
 	    $info->{$storeid}->{used} = 0; 
-	    $info->{$storeid}->{free} = 0; 
 	    $info->{$storeid}->{active} = 
 		defined ($iscsi_sessions->{$scfg->{target}});
 

Modified: pve-storage/pve2/control.in
===================================================================
--- pve-storage/pve2/control.in	2011-03-09 07:41:51 UTC (rev 5658)
+++ pve-storage/pve2/control.in	2011-03-09 09:38:04 UTC (rev 5659)
@@ -3,7 +3,7 @@
 Section: perl
 Priority: optional
 Architecture: @@ARCH@@
-Depends: perl (>= 5.6.0-16), libfilesys-df-perl, nfs-common, udev, libpve-common-perl
+Depends: perl (>= 5.6.0-16), nfs-common, udev, libpve-common-perl
 Maintainer: Proxmox Support Team <support at proxmox.com>
 Description: Proxmox VE storage management library
  This package contains the storage management library used by Proxmox VE.

Modified: pve-storage/pve2/pvesm
===================================================================
--- pve-storage/pve2/pvesm	2011-03-09 07:41:51 UTC (rev 5658)
+++ pve-storage/pve2/pvesm	2011-03-09 09:38:04 UTC (rev 5659)
@@ -185,11 +185,11 @@
     foreach my $res (sort { $a->{storage} cmp $b->{storage} } @$res) {
 	my $storeid = $res->{storage};
 
-	my $per = $res->{avail} ? int (0.5 + ($res->{used}*100)/$res->{avail}) : 100;
+	my $per = $res->{avail} ? (0.5 + ($res->{used}*100)/$res->{avail}) : 100;
 
-	printf "%-${maxlen}s %5s %1d %1d %10d %10d %2d%%\n", $storeid, 
+	printf "%-${maxlen}s %5s %1d %1d %15d %15d %.2f%%\n", $storeid, 
 	$res->{type},$res->{disable}, $res->{active},
-	$res->{avail}, $res->{used}, $per; 
+	$res->{used}/1024, $res->{avail}/1024, $per; 
     }
 };
 




More information about the pve-devel mailing list