Created
September 27, 2016 20:37
-
-
Save zaa/b957be41ca37bf1af82b33d47593d9fd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/pkg/volume/fc/fc_util.go b/pkg/volume/fc/fc_util.go | |
index 3da5396..1b22450 100644 | |
--- a/pkg/volume/fc/fc_util.go | |
+++ b/pkg/volume/fc/fc_util.go | |
@@ -127,53 +127,65 @@ func (util *FCUtil) MakeGlobalPDName(fc fcDisk) string { | |
return makePDNameInternal(fc.plugin.host, fc.wwns, fc.lun) | |
} | |
-func searchDisk(wwns []string, lun string, io ioHandler) (string, string) { | |
- disk := "" | |
- dm := "" | |
- | |
- rescaned := false | |
- // two-phase search: | |
- // first phase, search existing device path, if a multipath dm is found, exit loop | |
- // otherwise, in second phase, rescan scsi bus and search again, return with any findings | |
- for true { | |
- for _, wwn := range wwns { | |
- disk, dm = findDisk(wwn, lun, io) | |
- // if multipath device is found, break | |
- if dm != "" { | |
- break | |
- } | |
+// Try to find a device-mapper multipath-backed FC disk or, as a fallback, | |
+// plain old /dev/sd* device. | |
+func searchDisk(wwns []string, lun string, io ioHandler) string { | |
+ glog.Infof("fc: searchDisk. Trying to find a matching device for wwns: %v; lun: %v", wwns, lun) | |
+ // first, try to find a device-mapper device with a path to a WWN from the list | |
+ for _, wwn := range wwns { | |
+ glog.Infof("fc: looking for wwn: %v; lun: %v", wwn, lun) | |
+ _, dm := findDisk(wwn, lun, io) | |
+ if dm != "" { | |
+ glog.Infof("fc: found DM multipath device: %v for wwn: %v; lun: %v", dm, wwn, lun) | |
+ return dm | |
+ } | |
+ } | |
+ | |
+ // No luck, let's rescan scsi bus and try one more time | |
+ glog.Infof("fc: No luck finding DM multipath device for wwns: %v; lun: %v, let's try scsi bus rescan", wwns, lun) | |
+ | |
+ // create multipath conf if it is not there | |
+ createMultipathConf("/etc/multipath.conf", io) | |
+ | |
+ // rescan scsi bus | |
+ scsiHostRescan(io) | |
+ | |
+ // one more attempt to find device-mapper disk after scsi bus rescan | |
+ disks := []string{} | |
+ for _, wwn := range wwns { | |
+ glog.Infof("fc: looking for wwn: %v; lun: %v", wwn, lun) | |
+ disk, dm := findDisk(wwn, lun, io) | |
+ if dm != "" { | |
+ glog.Infof("fc: found DM multipath device: %v for wwn: %v; lun: %v", dm, wwn, lun) | |
+ return dm | |
} | |
- // if a dm is found, exit loop | |
- if rescaned || dm != "" { | |
- break | |
+ if disk != "" { | |
+ glog.Infof("fc: found plain old /dev/sd* disk: %v for wwn: %v; lun: %v", disk, wwn, lun) | |
+ disks = append(disks, disk) | |
} | |
- // rescan and search again | |
- // create multipath conf if it is not there | |
- createMultipathConf("/etc/multipath.conf", io) | |
- // rescan scsi bus | |
- scsiHostRescan(io) | |
- rescaned = true | |
} | |
- return disk, dm | |
+ | |
+ // fallback to regular /dev/sd* disk if we found one | |
+ if len(disks) > 0 { | |
+ glog.Infof("fc: found plain old /dev/sd* disks: %v. Returning: %v", disks, disks[0]) | |
+ return disks[0] | |
+ } | |
+ | |
+ glog.Infof("fc: failed to find any matching disks for wwns: %v; lun %v", wwns, lun) | |
+ return "" | |
} | |
func (util *FCUtil) AttachDisk(b fcDiskMounter) error { | |
- devicePath := "" | |
wwns := b.wwns | |
lun := b.lun | |
io := b.io | |
- disk, dm := searchDisk(wwns, lun, io) | |
+ | |
+ devicePath := searchDisk(wwns, lun, io) | |
// if no disk matches input wwn and lun, exit | |
- if disk == "" && dm == "" { | |
- return fmt.Errorf("no fc disk found") | |
+ if devicePath == "" { | |
+ return fmt.Errorf("fc: failed to find a device with matching target WWNs and LUN") | |
} | |
- // if multipath devicemapper device is found, use it; otherwise use raw disk | |
- if dm != "" { | |
- devicePath = dm | |
- } else { | |
- devicePath = disk | |
- } | |
// mount it | |
globalPDPath := b.manager.MakeGlobalPDName(*b.fcDisk) | |
noMnt, err := b.mounter.IsLikelyNotMountPoint(globalPDPath) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment