@@ -219,22 +219,25 @@ func (m *deviceUtils) VerifyDevicePath(devicePaths []string, deviceName string)
219219 if err != nil {
220220 return "" , err
221221 }
222-
223222 err = wait .Poll (pollInterval , pollTimeout , func () (bool , error ) {
224223 var innerErr error
225-
226224 devicePath , innerErr = existingDevicePath (devicePaths )
227225 if innerErr != nil {
228- return false , fmt .Errorf ("failed to check for existing device path: %w" , innerErr )
226+ e := fmt .Errorf ("for disk %s failed to check for existing device path: %w" , deviceName , innerErr )
227+ klog .Errorf (e .Error ())
228+ return false , e
229229 }
230230
231231 if len (devicePath ) == 0 {
232232 // Couldn't find a /dev/disk/by-id path for this deviceName, so we need to
233233 // find a /dev/* with a serial that matches deviceName. Then we attempt
234234 // to repair the symlink.
235+ klog .Warningf ("For disk %s couldn't find a device path, calling udevadmTriggerForDiskIfExists" , deviceName )
235236 innerErr := udevadmTriggerForDiskIfExists (deviceName )
236237 if innerErr != nil {
237- return false , fmt .Errorf ("failed to trigger udevadm fix of non existent disk for %q: %w" , deviceName , innerErr )
238+ e := fmt .Errorf ("for disk %s failed to trigger udevadm fix of non existent device path: %w" , deviceName , innerErr )
239+ klog .Errorf (e .Error ())
240+ return false , e
238241 }
239242 // Go to next retry loop to get the deviceName again after
240243 // potentially fixing it with the udev command
@@ -244,15 +247,20 @@ func (m *deviceUtils) VerifyDevicePath(devicePaths []string, deviceName string)
244247 // If there exists a devicePath we make sure disk at /dev/* matches the
245248 // expected disk at devicePath by matching device Serial to the disk name
246249 devFsPath , innerErr := filepath .EvalSymlinks (devicePath )
247- klog .V (4 ).Infof ("For disk %s the /dev/* path is %s" , deviceName , devFsPath )
248250 if innerErr != nil {
249- return false , fmt .Errorf ("filepath.EvalSymlinks(%q) failed with %w" , devicePath , innerErr )
251+ e := fmt .Errorf ("filepath.EvalSymlinks(%q) failed: %w" , devicePath , innerErr )
252+ klog .Errorf (e .Error ())
253+ return false , e
250254 }
255+ klog .V (4 ).Infof ("For disk %s the /dev/* path is %s for disk/by-id path %s" , deviceName , devFsPath , devicePath )
251256
252257 devFsSerial , innerErr := getDevFsSerial (devFsPath )
253258 if innerErr != nil {
254- return false , fmt .Errorf ("couldn't get serial number for disk %s at path %s: %w" , deviceName , devFsPath , innerErr )
259+ e := fmt .Errorf ("couldn't get serial number for disk %s at device path %s: %w" , deviceName , devFsPath , innerErr )
260+ klog .Errorf (e .Error ())
261+ return false , e
255262 }
263+ klog .V (4 ).Infof ("For disk %s, device path %s, found serial number %s" , deviceName , devFsPath , devFsSerial )
256264 // SUCCESS! devicePath points to a /dev/* path that has a serial
257265 // equivalent to our disk name
258266 if len (devFsSerial ) != 0 && devFsSerial == deviceName {
@@ -262,9 +270,12 @@ func (m *deviceUtils) VerifyDevicePath(devicePaths []string, deviceName string)
262270 // A /dev/* path exists, but is either not a recognized /dev prefix type
263271 // (/dev/nvme* or /dev/sd*) or devicePath is not mapped to the correct disk.
264272 // Attempt a repair
273+ klog .Warningf ("For disk %s and device path %s with mismatched serial number %q calling udevadmTriggerForDiskIfExists" , deviceName , devFsPath , devFsSerial )
265274 innerErr = udevadmTriggerForDiskIfExists (deviceName )
266275 if innerErr != nil {
267- return false , fmt .Errorf ("failed to trigger udevadm fix of misconfigured disk for %q: %w" , deviceName , innerErr )
276+ e := fmt .Errorf ("failed to trigger udevadm fix of misconfigured disk for %q: %w" , deviceName , innerErr )
277+ klog .Errorf (e .Error ())
278+ return false , e
268279 }
269280 // Go to next retry loop to get the deviceName again after
270281 // potentially fixing it with the udev command
@@ -318,23 +329,23 @@ func udevadmTriggerForDiskIfExists(deviceName string) error {
318329 if err != nil || len (devFsSerial ) == 0 {
319330 // If we get an error, ignore. Either this isn't a block device, or it
320331 // isn't something we can get a serial number from
321- klog .V ( 7 ). Infof ( "failed to get Serial num for disk %s at path %s: %v" , deviceName , devFsPath , err .Error ())
332+ klog .Errorf ( "failed to get serial num for disk %s at device path %s: %v" , deviceName , devFsPath , err .Error ())
322333 continue
323334 }
335+ klog .V (4 ).Infof ("device path %s, serial number %v" , devFsPath , devFsSerial )
324336 devFsPathToSerial [devFsPath ] = devFsSerial
325337 if devFsSerial == deviceName {
326338 // Found the disk that we're looking for so run a trigger on it
327339 // to resolve its /dev/by-id/ path
328- klog .Warningf ("udevadm --trigger running to fix disk at path %s which has serial numberID %s" , devFsPath , devFsSerial )
340+ klog .Warningf ("udevadm --trigger running to fix disk at path %s which has serial number %s" , devFsPath , devFsSerial )
329341 err := udevadmChangeToDrive (devFsPath )
330342 if err != nil {
331- return fmt .Errorf ("failed to fix disk which has serial numberID %s: %w" , devFsSerial , err )
343+ return fmt .Errorf ("udevadm --trigger failed to fix device path %s which has serial number %s: %w" , devFsPath , devFsSerial , err )
332344 }
333345 return nil
334346 }
335347 }
336- klog .Warningf ("udevadm --trigger requested to fix disk %s but no such disk was found in %v" , deviceName , devFsPathToSerial )
337- return fmt .Errorf ("udevadm --trigger requested to fix disk %s but no such disk was found" , deviceName )
348+ return fmt .Errorf ("udevadm --trigger requested to fix disk %s but no such disk was found in device path %v" , deviceName , devFsPathToSerial )
338349}
339350
340351// Calls "udevadm trigger --action=change" on the specified drive. drivePath
@@ -347,13 +358,15 @@ func udevadmTriggerForDiskIfExists(deviceName string) error {
347358// the change
348359func udevadmChangeToDrive (devFsPath string ) error {
349360 // Call "udevadm trigger --action=change --property-match=DEVNAME=/dev/..."
350- out , err := exec .Command (
361+ cmd := exec .Command (
351362 "udevadm" ,
352363 "trigger" ,
353364 "--action=change" ,
354- fmt .Sprintf ("--property-match=DEVNAME=%s" , devFsPath )).CombinedOutput ()
365+ fmt .Sprintf ("--property-match=DEVNAME=%s" , devFsPath ))
366+ klog .V (4 ).Infof ("Running command: %s" , cmd .String ())
367+ out , err := cmd .CombinedOutput ()
355368 if err != nil {
356- return fmt .Errorf ("udevadmChangeToDrive: udevadm trigger failed for drive %q with output %s: %w. " , devFsPath , string (out ), err )
369+ return fmt .Errorf ("udevadmChangeToDrive: udevadm trigger failed for drive %q with output %s: %w" , devFsPath , string (out ), err )
357370 }
358371 return nil
359372}
0 commit comments