@@ -98,6 +98,15 @@ func (v *VolumePublishManager) readTrackingInfo(
9898 }
9999
100100 Logc (ctx ).WithField ("volumeTrackingInfo" , volumeTrackingInfo ).Debug ("Volume tracking info found." )
101+
102+ // Given upgrade logic in volume_publish_manager, this should not
103+ // be the case but adding an extra check here to move the
104+ // rawDevicePath value to devicePath.
105+ if volumeTrackingInfo .RawDevicePath != "" && volumeTrackingInfo .DevicePath == "" {
106+ volumeTrackingInfo .DevicePath = volumeTrackingInfo .RawDevicePath
107+ volumeTrackingInfo .RawDevicePath = ""
108+ }
109+
101110 return & volumeTrackingInfo , nil
102111}
103112
@@ -153,7 +162,7 @@ func (v *VolumePublishManager) DeleteTrackingInfo(ctx context.Context, volumeID
153162// stagedDeviceInfo or legacy tracking file do not exist, or are unable to be unmarshalled, then an upgrade is not
154163// possible, and we must delete the tracking file because it no longer has any value.
155164func (v * VolumePublishManager ) UpgradeVolumeTrackingFile (
156- ctx context.Context , volumeId string , publishedPaths map [string ]struct {},
165+ ctx context.Context , volumeId string , publishedPaths map [string ]struct {}, pvToDeviceMappings map [ string ] string ,
157166) (bool , error ) {
158167 var err error
159168 fields := LogFields {"volumeId" : volumeId }
@@ -178,8 +187,81 @@ func (v *VolumePublishManager) UpgradeVolumeTrackingFile(
178187 // upon unmarshalling the json.
179188 if volumeTrackingInfo .VolumePublishInfo .FilesystemType != "" {
180189 Logc (ctx ).Debug ("Volume tracking method did not need to be upgraded." )
190+
191+ // For iSCSI case confirm iSCSI `devicePath` exists, if not check
192+ // `rawDevicePath` exist, if yes then copy the value else log an
193+ // error message in logs.
194+ if volumeTrackingInfo .VolumePublishInfo .IscsiTargetPortal == "" {
195+ Logc (ctx ).Debug ("IscsiTargetPortal was empty in volume publish info." )
196+ return false , nil
197+ }
198+
199+ Logc (ctx ).Debug ("Ensuring devicePath is present if not then attempting to recover it." )
200+
201+ // In 23.01 devicePath was changed to rawDevicePath, which led to missing devicePath for
202+ // attached volumes from pre-23.01 and newly created volumes instead of devicePath would
203+ // rawDevicePath. Starting 23.07, devicePath has been re-introduced, below effort ensures
204+ // devicePath value is populated based on rawDevicePath, if both are missing Trident
205+ // tries to identify the correct device based on the published paths.
206+ if volumeTrackingInfo .DevicePath == "" {
207+ if volumeTrackingInfo .RawDevicePath != "" {
208+ volumeTrackingInfo .DevicePath = volumeTrackingInfo .RawDevicePath
209+ volumeTrackingInfo .RawDevicePath = ""
210+
211+ Logc (ctx ).WithFields (LogFields {
212+ "volumeID" : volumeId ,
213+ "devicePath" : volumeTrackingInfo .DevicePath ,
214+ "iscsiTargetPortal" : volumeTrackingInfo .IscsiTargetPortal ,
215+ "lun" : volumeTrackingInfo .IscsiLunNumber ,
216+ }).Debug ("Updating new publish info records." )
217+ } else if len (volumeTrackingInfo .PublishedPaths ) > 0 {
218+ // This is a best-effort to identify a missing device path
219+ for publishedPath := range volumeTrackingInfo .PublishedPaths {
220+ if device , ok := pvToDeviceMappings [publishedPath ]; ok {
221+ volumeTrackingInfo .DevicePath = device
222+ Logc (ctx ).WithFields (LogFields {
223+ "volumeID" : volumeId ,
224+ "devicePath" : volumeTrackingInfo .DevicePath ,
225+ "iscsiTargetPortal" : volumeTrackingInfo .IscsiTargetPortal ,
226+ "lun" : volumeTrackingInfo .IscsiLunNumber ,
227+ }).Debug ("Updating new publish info records based on published paths." )
228+ }
229+ }
230+ }
231+
232+ if volumeTrackingInfo .DevicePath != "" {
233+ err = v .WriteTrackingInfo (ctx , volumeId , volumeTrackingInfo )
234+ if err != nil {
235+ Logc (ctx ).WithFields (LogFields {
236+ "volumeID" : volumeId ,
237+ "devicePath" : volumeTrackingInfo .DevicePath ,
238+ "iscsiTargetPortal" : volumeTrackingInfo .IscsiTargetPortal ,
239+ "lun" : volumeTrackingInfo .IscsiLunNumber ,
240+ }).Error ("Failed to update tracking file with device path information." )
241+ }
242+ } else {
243+ Logc (ctx ).WithFields (LogFields {
244+ "volumeID" : volumeId ,
245+ "iscsiTargetPortal" : volumeTrackingInfo .IscsiTargetPortal ,
246+ "lun" : volumeTrackingInfo .IscsiLunNumber ,
247+ }).Error ("New publish info is missing device path." )
248+ }
249+ } else if volumeTrackingInfo .RawDevicePath != "" {
250+ Logc (ctx ).WithFields (LogFields {
251+ "volumeID" : volumeId ,
252+ "iscsiTargetPortal" : volumeTrackingInfo .IscsiTargetPortal ,
253+ "lun" : volumeTrackingInfo .IscsiLunNumber ,
254+ "devicePath" : volumeTrackingInfo .DevicePath ,
255+ "rawDevicePath" : volumeTrackingInfo .RawDevicePath ,
256+ }).Warn ("Found both devices." )
257+
258+ // No need to have two sources of device path information
259+ volumeTrackingInfo .RawDevicePath = ""
260+ }
261+
181262 return false , nil
182263 }
264+
183265 file = path .Join (volumeTrackingInfo .StagingTargetPath , volumePublishInfoFilename )
184266 err = utils .JsonReaderWriter .ReadJSONFile (ctx , publishInfo , file , "publish info" )
185267 if err != nil {
@@ -202,6 +284,41 @@ func (v *VolumePublishManager) UpgradeVolumeTrackingFile(
202284 volumeTrackingInfo .VolumePublishInfo = * publishInfo
203285 volumeTrackingInfo .PublishedPaths = publishedPaths
204286
287+ // (arorar): I do not think this condition will ever be true since `rawDevicePath`
288+ // was introduced after this migration logic and `devicePath` has been re-introduced.
289+ if volumeTrackingInfo .VolumePublishInfo .IscsiTargetPortal != "" {
290+ if volumeTrackingInfo .DevicePath == "" {
291+ if volumeTrackingInfo .RawDevicePath != "" {
292+ volumeTrackingInfo .DevicePath = volumeTrackingInfo .RawDevicePath
293+ volumeTrackingInfo .RawDevicePath = ""
294+
295+ Logc (ctx ).WithFields (LogFields {
296+ "volumeID" : volumeId ,
297+ "devicePath" : volumeTrackingInfo .DevicePath ,
298+ "iscsiTargetPortal" : volumeTrackingInfo .IscsiTargetPortal ,
299+ "lun" : volumeTrackingInfo .IscsiLunNumber ,
300+ }).Debug ("Updating publish info records." )
301+ } else {
302+ Logc (ctx ).WithFields (LogFields {
303+ "volumeID" : volumeId ,
304+ "iscsiTargetPortal" : volumeTrackingInfo .IscsiTargetPortal ,
305+ "lun" : volumeTrackingInfo .IscsiLunNumber ,
306+ }).Errorf ("Publish info is missing device path." )
307+ }
308+ } else if volumeTrackingInfo .RawDevicePath != "" {
309+ Logc (ctx ).WithFields (LogFields {
310+ "volumeID" : volumeId ,
311+ "iscsiTargetPortal" : volumeTrackingInfo .IscsiTargetPortal ,
312+ "lun" : volumeTrackingInfo .IscsiLunNumber ,
313+ "devicePath" : volumeTrackingInfo .DevicePath ,
314+ "rawDevicePath" : volumeTrackingInfo .RawDevicePath ,
315+ }).Warn ("Found both devices." )
316+
317+ // No need to have two sources of device path information
318+ volumeTrackingInfo .RawDevicePath = ""
319+ }
320+ }
321+
205322 Logc (ctx ).WithField ("publishInfoLocation" , volumeTrackingInfo ).Debug ("Publish info location found." )
206323 err = v .WriteTrackingInfo (ctx , volumeId , volumeTrackingInfo )
207324 if err != nil {
0 commit comments