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

svn-commits at proxmox.com svn-commits at proxmox.com
Mon Apr 4 07:15:21 CEST 2011


Author: dietmar
Date: 2011-04-04 07:15:21 +0200 (Mon, 04 Apr 2011)
New Revision: 5779

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


Modified: pve-storage/pve2/ChangeLog
===================================================================
--- pve-storage/pve2/ChangeLog	2011-04-04 04:59:38 UTC (rev 5778)
+++ pve-storage/pve2/ChangeLog	2011-04-04 05:15:21 UTC (rev 5779)
@@ -1,3 +1,8 @@
+2011-04-04  Proxmox Support Team  <support at proxmox.com>
+
+	* PVE/Storage.pm (load_stable_scsi_paths): only load
+	/dev/disk/by-id once (avoid delays when we have many disks)
+
 2011-03-09  Proxmox Support Team  <support at proxmox.com>
 
 	* pvesm (status): report sizes like 'df'

Modified: pve-storage/pve2/PVE/Storage.pm
===================================================================
--- pve-storage/pve2/PVE/Storage.pm	2011-04-04 04:59:38 UTC (rev 5778)
+++ pve-storage/pve2/PVE/Storage.pm	2011-04-04 05:15:21 UTC (rev 5779)
@@ -51,51 +51,30 @@
     return 1;
 }
 
-sub link_points_to {
-    my ($src, $dest) = @_;
+sub load_stable_scsi_paths {
 
-    my $st1 = stat ($src);
-    my $st2 = stat ($dest);
+    my $stable_paths = {};
 
-    return 0 if !$st1 || !$st2;
+    my $stabledir = "/dev/disk/by-id";
 
-    return $st1->ino == $st2->ino && $st1->dev == $st2->dev;
-}
-
-sub find_stable_path {
-    my ($stabledir, $bdev) = @_;
-
-    my $dh = IO::Dir->new ($stabledir);
-    if ($dh) {
-	while (defined(my $tmp = $dh->read)) {
-	    my $path = "$stabledir/$tmp";
-	    if (link_points_to ($path, $bdev)) {
-		return wantarray ? ($path, $tmp) : $path;
-	    }
-	}
-
-	$dh->close;
+    if (my $dh = IO::Dir->new($stabledir)) {
+       while (defined(my $tmp = $dh->read)) {
+           # exclude filenames with part in name (same disk but partitions)
+           # use only filenames with scsi(with multipath i have the same device 
+	   # with dm-uuid-mpath , dm-name and scsi in name)
+           if($tmp !~ m/-part\d+$/ && $tmp =~ m/^scsi-/) {
+                 my $path = "$stabledir/$tmp";
+                 my $bdevdest = readlink($path);
+		 if ($bdevdest && $bdevdest =~ m|^../../([^/]+)|) {
+		     $stable_paths->{$1}=$tmp;
+		 }
+	   }
+       }
+       $dh->close;
     }
-
-    return wantarray ? () : undef;
+    return $stable_paths;
 }
 
-sub find_dev_by_id {
-    my $bdev = shift;
-
-    my ($full_path, $name) = find_stable_path ("/dev/disk/by-id", $bdev);
-
-    return $name;
-}
-
-sub find_dev_by_path {
-    my $bdev = shift;
-
-    my ($full_path, $name) = find_stable_path ("/dev/disk/by-path", $bdev);
-
-    return $name;
-}
-
 sub dir_glob_regex {
     my ($dir, $regex) = @_;
 
@@ -820,6 +799,8 @@
 
     my $dirname = '/sys/class/iscsi_session';
 
+    my $stable_paths = load_stable_scsi_paths();
+
     dir_glob_foreach ($dirname, 'session(\d+)', sub {
 	my ($ent, $session) = @_;
 
@@ -843,7 +824,7 @@
 	    }
 	    return if !$bdev;
 
-	    my $blockdev = find_dev_by_id ("/dev/$bdev");
+	    my $blockdev = $stable_paths->{$bdev};
 	    return if !$blockdev;
 
 	    my $size = file_read_firstline ("/sys/block/$bdev/size");




More information about the pve-devel mailing list