@@ -638,12 +638,12 @@ func (p *Plugin) nodeExpandVolume(
638638 devicePath := publishInfo .DevicePath
639639 if convert .ToBool (publishInfo .LUKSEncryption ) {
640640 if ! luks .IsLegacyDevicePath (devicePath ) {
641- devicePath , err = p .devices .GetLUKSDeviceForMultipathDevice ( devicePath )
641+ devicePath , err = p .devices .GetLUKSDevicePathForVolume ( ctx , volumeId )
642642 if err != nil {
643643 Logc (ctx ).WithFields (LogFields {
644644 "volumeId" : volumeId ,
645645 "publishedPath" : publishInfo .DevicePath ,
646- }).WithError (err ).Error ("Failed to get LUKS device path from device path ." )
646+ }).WithError (err ).Error ("Failed to get LUKS device path for volume ." )
647647 return status .Error (codes .Internal , err .Error ())
648648 }
649649 }
@@ -1465,15 +1465,18 @@ func (p *Plugin) nodeUnstageFCPVolume(
14651465 publishInfo .DevicePath = dmPath
14661466 }
14671467 } else {
1468- // If not using luks legacy device path we need to find the LUKS mapper device
1469- luksMapperPath , err = p .devices .GetLUKSDeviceForMultipathDevice ( publishInfo . DevicePath )
1468+ // If not using luks legacy device path we need to find the LUKS mapper device.
1469+ luksMapperPath , err = p .devices .GetLUKSDevicePathForVolume ( ctx , req . GetVolumeId () )
14701470 if err != nil {
1471- if ! errors .IsNotFoundError (err ) {
1472- Logc (ctx ).WithFields (fields ).WithError (err ).Warn (
1473- "Could not determine LUKS device path from multipath device. " +
1474- "Continuing with device removal." )
1471+ // If the LUKS device is not found, the functional difference is negligible to unstage.
1472+ // But it may be useful to log at different levels for observability.
1473+ log := Logc (ctx ).WithFields (fields ).WithError (err )
1474+ if errors .IsNotFoundError (err ) {
1475+ log .Warn ("Failed to get LUKS device path for volume." )
1476+ } else {
1477+ log .Debug ("Could not determine LUKS device path for volume." )
14751478 }
1476- Logc ( ctx ). WithFields ( fields ). Info ( "No LUKS device path found from multipath device ." )
1479+ log . Debug ( "Continuing with device removal ." )
14771480 }
14781481 }
14791482 err = p .devices .EnsureLUKSDeviceClosedWithMaxWaitLimit (ctx , luksMapperPath )
@@ -1516,11 +1519,10 @@ func (p *Plugin) nodeUnstageFCPVolume(
15161519 "multipathDevice" : deviceInfo .MultipathDevice ,
15171520 }
15181521
1519- luksMapperPath , err = p .devices .GetLUKSDeviceForMultipathDevice ( deviceInfo . MultipathDevice )
1522+ luksMapperPath , err = p .devices .GetLUKSDevicePathForVolume ( ctx , req . GetVolumeId () )
15201523 if err != nil {
15211524 if ! errors .IsNotFoundError (err ) {
1522- Logc (ctx ).WithFields (fields ).
1523- WithError (err ).Error ("Failed to get LUKS device path from multipath device." )
1525+ Logc (ctx ).WithFields (fields ).WithError (err ).Error ("Failed to get LUKS device path from multipath device." )
15241526 return err
15251527 }
15261528 Logc (ctx ).WithFields (fields ).Info ("No LUKS device path found from multipath device." )
@@ -1969,7 +1971,7 @@ func (p *Plugin) nodeUnstageISCSIVolume(
19691971 if convert .ToBool (publishInfo .LUKSEncryption ) {
19701972 var err error
19711973 var luksMapperPath string
1972- fields := LogFields {"device" : publishInfo .DevicePath }
1974+ fields := LogFields {"device" : publishInfo .DevicePath , "volume" : req . GetVolumeId () }
19731975 // Set device path to dm device to correctly verify legacy volumes.
19741976 if luks .IsLegacyDevicePath (publishInfo .DevicePath ) {
19751977 luksMapperPath = publishInfo .DevicePath
@@ -1983,17 +1985,22 @@ func (p *Plugin) nodeUnstageISCSIVolume(
19831985 publishInfo .DevicePath = dmPath
19841986 }
19851987 } else {
1986- // If not using luks legacy device path we need to find the LUKS mapper device
1987- luksMapperPath , err = p .devices .GetLUKSDeviceForMultipathDevice (publishInfo .DevicePath )
1988+ // Use the volume ID to get the LUKS mapper path.
1989+ // This should always work if the mapper is still present.
1990+ luksMapperPath , err = p .devices .GetLUKSDevicePathForVolume (ctx , req .GetVolumeId ())
19881991 if err != nil {
1989- if ! errors .IsNotFoundError (err ) {
1990- Logc (ctx ).WithFields (fields ).WithError (err ).Warn (
1991- "Could not determine LUKS device path from multipath device. " +
1992- "Continuing with device removal." )
1992+ // If the LUKS device is not found, the functional difference is negligible to unstage.
1993+ // But it may be useful to log at different levels for observability.
1994+ log := Logc (ctx ).WithFields (fields ).WithError (err )
1995+ if errors .IsNotFoundError (err ) {
1996+ log .Warn ("Failed to get LUKS device path for volume." )
1997+ } else {
1998+ log .Debug ("Could not determine LUKS device path for volume." )
19931999 }
1994- Logc ( ctx ). WithFields ( fields ). Info ( "No LUKS device path found from multipath device ." )
2000+ log . Debug ( "Continuing with device removal ." )
19952001 }
19962002 }
2003+
19972004 err = p .devices .EnsureLUKSDeviceClosedWithMaxWaitLimit (ctx , luksMapperPath )
19982005 if err != nil {
19992006 Logc (ctx ).WithError (err ).Debug ("Unable to remove LUKS device. Continuing with tracking file removal." )
@@ -2044,7 +2051,7 @@ func (p *Plugin) nodeUnstageISCSIVolume(
20442051 "multipathDevice" : deviceInfo .MultipathDevice ,
20452052 }
20462053
2047- luksMapperPath , err = p .devices .GetLUKSDeviceForMultipathDevice ( deviceInfo . MultipathDevice )
2054+ luksMapperPath , err = p .devices .GetLUKSDevicePathForVolume ( ctx , req . GetVolumeId () )
20482055 if err != nil {
20492056 if ! errors .IsNotFoundError (err ) {
20502057 Logc (ctx ).WithFields (fields ).WithError (err ).Error ("Failed to get LUKS device path from multipath device." )
@@ -3043,7 +3050,7 @@ func (p *Plugin) nodeUnstageNVMeVolume(
30433050 return nil , fmt .Errorf ("failed to get NVMe device; %v" , err )
30443051 }
30453052
3046- var devicePath string
3053+ devicePath := publishInfo . DevicePath
30473054 if nvmeDev != nil {
30483055 devicePath = nvmeDev .GetPath ()
30493056 }
@@ -3056,10 +3063,19 @@ func (p *Plugin) nodeUnstageNVMeVolume(
30563063 "publishedPath" : publishInfo .DevicePath ,
30573064 }
30583065
3059- luksMapperPath , err = p .devices .GetLUKSDeviceForMultipathDevice (devicePath )
3066+ // Use the volume ID to get the LUKS mapper path.
3067+ // This should always work if the mapper is still present.
3068+ luksMapperPath , err = p .devices .GetLUKSDevicePathForVolume (ctx , req .GetVolumeId ())
30603069 if err != nil {
3061- Logc (ctx ).WithFields (fields ).WithError (err ).Debug ("Failed to get LUKS device path from device path. " +
3062- "Device may already be removed." )
3070+ // If the LUKS device is not found, the functional difference is negligible to unstage.
3071+ // But it may be useful to log at different levels for observability.
3072+ log := Logc (ctx ).WithFields (fields ).WithError (err )
3073+ if errors .IsNotFoundError (err ) {
3074+ log .Warn ("Failed to get LUKS device path for volume." )
3075+ } else {
3076+ log .Debug ("Could not determine LUKS device path for volume." )
3077+ }
3078+ log .Debug ("Continuing with device removal." )
30633079 }
30643080
30653081 if luksMapperPath != "" {
0 commit comments