[pve-devel] r5658 - in pve-common/trunk/data: . PVE

svn-commits at proxmox.com svn-commits at proxmox.com
Wed Mar 9 08:41:51 CET 2011


Author: dietmar
Date: 2011-03-09 08:41:51 +0100 (Wed, 09 Mar 2011)
New Revision: 5658

Modified:
   pve-common/trunk/data/ChangeLog
   pve-common/trunk/data/PVE/Tools.pm
Log:
 implement interruptible version of 'df'


Modified: pve-common/trunk/data/ChangeLog
===================================================================
--- pve-common/trunk/data/ChangeLog	2011-03-08 07:35:02 UTC (rev 5657)
+++ pve-common/trunk/data/ChangeLog	2011-03-09 07:41:51 UTC (rev 5658)
@@ -1,3 +1,8 @@
+2011-03-09  Proxmox Support Team  <support at proxmox.com>
+
+	* PVE/Tools.pm (df): implement interruptible version of 'df'
+	(workd with timeout on NFS)
+
 2011-03-03  Proxmox Support Team  <support at proxmox.com>
 
 	* PVE/ProcFSTools.pm (read_memory_usage): memory usage of current

Modified: pve-common/trunk/data/PVE/Tools.pm
===================================================================
--- pve-common/trunk/data/PVE/Tools.pm	2011-03-08 07:35:02 UTC (rev 5657)
+++ pve-common/trunk/data/PVE/Tools.pm	2011-03-09 07:41:51 UTC (rev 5658)
@@ -431,4 +431,37 @@
     die "unable to find free vnc port";
 };
 
+# NOTE: NFS syscall can't be interrupted, so alarm does 
+# not work to provide timeouts.
+# from 'man nfs': "Only SIGKILL can interrupt a pending NFS operation"
+# So the spawn external 'df' process instead of using
+# Filesys::Df (which uses statfs syscall)
+sub df {
+    my ($path, $timeout) = @_;
+
+    my $cmd = [ 'df', '-P', '-B', '1', $path];
+
+    my $res = {
+	total => 0,
+	used => 0,
+	avail => 0,
+    };
+
+    my $parser = sub {
+	my $line = shift;
+	if (my ($fsid, $total, $used, $avail) = $line =~
+	    m/^(\S+.*)\s+(\d+)\s+(\d+)\s+(\d+)\s+\d+%\s.*$/) {
+	    $res = {
+		total => $total,
+		used => $used,
+		avail => $avail,
+	    };
+	}
+    };
+    eval { run_command($cmd, timeout => $timeout, outfunc => $parser); };
+    warn $@ if $@;
+
+    return $res;
+}
+
 1;




More information about the pve-devel mailing list