@@ -1377,9 +1377,61 @@ func (p *Plugin) ensureAttachFCPVolume(
13771377func (p * Plugin ) nodeUnstageFCPVolume (
13781378 ctx context.Context , req * csi.NodeUnstageVolumeRequest , publishInfo * models.VolumePublishInfo , force bool ,
13791379) error {
1380+ // TODO: (vhs) This is a temporary fix to handle the case where the device list is empty. We need to
1381+ // refactor nodeUnstageFCPVolume to handle this case more gracefully and not rely on the device list.
13801382 hostSessionMap := fcpUtils .GetFCPHostSessionMapForTarget (ctx , publishInfo .FCTargetWWNN )
1381- if len (hostSessionMap ) == 0 {
1382- Logc (ctx ).Debug ("No host sessions found, nothing to do." )
1383+ paths := fcpUtils .GetSysfsBlockDirsForLUN (int (publishInfo .FCPLunNumber ), hostSessionMap )
1384+ if deviceNames , err := fcpUtils .GetDevicesForLUN (paths ); err != nil {
1385+ return fmt .Errorf ("could not get devices for LUN: %v" , err )
1386+ } else if len (deviceNames ) == 0 {
1387+ // If we are in this block it likely means we have errored or had a pod restart
1388+ // before the tracking file has been removed. We need to ensure the device was removed and remove the tracking
1389+ // file, without going through the rest of the unstage process.
1390+ if convert .ToBool (publishInfo .LUKSEncryption ) {
1391+ var err error
1392+ var luksMapperPath string
1393+ fields := LogFields {"device" : publishInfo .DevicePath }
1394+ // Set device path to dm device to correctly verify legacy volumes.
1395+ if luks .IsLegacyLUKSDevicePath (publishInfo .DevicePath ) {
1396+ luksMapperPath = publishInfo .DevicePath
1397+ dmPath , err := luks .GetDmDevicePathFromLUKSLegacyPath (ctx , p .command ,
1398+ publishInfo .DevicePath )
1399+ if err != nil {
1400+ Logc (ctx ).WithFields (fields ).WithError (err ).Warn (
1401+ "Could not determine dm device path from legacy LUKS device path. " +
1402+ "Continuing with device removal." )
1403+ } else {
1404+ publishInfo .DevicePath = dmPath
1405+ }
1406+ } else {
1407+ // If not using luks legacy device path we need to find the LUKS mapper device
1408+ luksMapperPath , err = p .devices .GetLUKSDeviceForMultipathDevice (publishInfo .DevicePath )
1409+ if err != nil {
1410+ if ! errors .IsNotFoundError (err ) {
1411+ Logc (ctx ).WithFields (fields ).WithError (err ).Warn (
1412+ "Could not determine LUKS device path from multipath device. " +
1413+ "Continuing with device removal." )
1414+ }
1415+ Logc (ctx ).WithFields (fields ).Info ("No LUKS device path found from multipath device." )
1416+ }
1417+ }
1418+ err = p .devices .EnsureLUKSDeviceClosedWithMaxWaitLimit (ctx , luksMapperPath )
1419+ if err != nil {
1420+ Logc (ctx ).WithError (err ).Debug ("Unable to remove LUKS device. Continuing with tracking file removal." )
1421+ }
1422+ }
1423+ if err := p .devices .RemoveMultipathDeviceMappingWithRetries (ctx , publishInfo .DevicePath ,
1424+ removeMultipathDeviceMappingRetries , removeMultipathDeviceMappingRetryDelay ); err != nil {
1425+ Logc (ctx ).Warn ("Unable to remove multipath device. Continuing with tracking file removal." )
1426+ }
1427+ // Ensure the tracking file is removed.
1428+ volumeId , _ , err := p .getVolumeIdAndStagingPath (req )
1429+ if err != nil {
1430+ return err
1431+ }
1432+ if err := p .nodeHelper .DeleteTrackingInfo (ctx , volumeId ); err != nil {
1433+ return status .Error (codes .Internal , err .Error ())
1434+ }
13831435 return nil
13841436 }
13851437
0 commit comments