Skip to content

Commit fe0d755

Browse files
Fix the issue with stale tvols and node pod reboots in FCP
1 parent d3222d5 commit fe0d755

File tree

1 file changed

+52
-2
lines changed

1 file changed

+52
-2
lines changed

frontend/csi/node_server.go

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

0 commit comments

Comments
 (0)