[PATCH] scsi/mptsas: add RAID devices in ascending ID order

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Martin Wilck <Martin.Wilck@xxxxxxxxxxxxxxxxxxx>

    [SCSI] mptsas: add RAID devices in ascending ID order
    
    This patch fixes the order in which mptsas registers
    RAID devices with the SCSI mid layer. The VolumeID field
    is not in ascending order. This leads to situations where
    e.g. device 2:8:2:0 is registered before 2:8:0:0.
    
    That may lead to an unbootable system e.g. if a user installs
    on a two-disk RAID1 array and adds another 2-disk RAID1 later
    (the new array will be detected as sda, the old one as sdb).
    
    The patch makes sure that arrays are added in ascending
    VolumeID order.

Signed-off-by: Martin Wilck <Martin.Wilck@xxxxxxxxxxxxxxxxxxx>

diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
index b752a47..3f01f03 100644
--- a/drivers/message/fusion/mptsas.c
+++ b/drivers/message/fusion/mptsas.c
@@ -1962,6 +1962,7 @@ mptsas_scan_sas_topology(MPT_ADAPTER *io
 {
 	u32 handle = 0xFFFF;
 	int i;
+	int last_added_id;
 
 	mutex_lock(&ioc->sas_discovery_mutex);
 	mptsas_probe_hba_phys(ioc);
@@ -1974,9 +1975,24 @@ mptsas_scan_sas_topology(MPT_ADAPTER *io
 		goto out;
 	if (!ioc->raid_data.pIocPg2->NumActiveVolumes)
 		goto out;
-	for (i=0; i<ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
+
+	/* Add logical volumes in the usual SCSI scan sequence (ascending VolumeID) */
+	for (last_added_id = -1;;) {
+		int idx = -1;
+		int smallest_id = 256; /* VolumeID is u8 */
+
+		for (i=0; i<ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
+			int id = ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID;
+			if (id > last_added_id && id < smallest_id) {
+				smallest_id = id;
+				idx = i;
+			}
+		}
+		if (idx == -1)
+			break;
+		last_added_id = smallest_id;
 		scsi_add_device(ioc->sh, MPTSAS_RAID_CHANNEL,
-		    ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID, 0);
+		    ioc->raid_data.pIocPg2->RaidVolume[idx].VolumeID, 0);
 	}
  out:
 	mutex_unlock(&ioc->sas_discovery_mutex);
-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]
  Powered by Linux