@@ -219,22 +219,25 @@ func (m *deviceUtils) VerifyDevicePath(devicePaths []string, deviceName string)
219
219
if err != nil {
220
220
return "" , err
221
221
}
222
-
223
222
err = wait .Poll (pollInterval , pollTimeout , func () (bool , error ) {
224
223
var innerErr error
225
-
226
224
devicePath , innerErr = existingDevicePath (devicePaths )
227
225
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
229
229
}
230
230
231
231
if len (devicePath ) == 0 {
232
232
// Couldn't find a /dev/disk/by-id path for this deviceName, so we need to
233
233
// find a /dev/* with a serial that matches deviceName. Then we attempt
234
234
// to repair the symlink.
235
+ klog .Warningf ("For disk %s couldn't find a device path, calling udevadmTriggerForDiskIfExists" , deviceName )
235
236
innerErr := udevadmTriggerForDiskIfExists (deviceName )
236
237
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
238
241
}
239
242
// Go to next retry loop to get the deviceName again after
240
243
// potentially fixing it with the udev command
@@ -244,15 +247,20 @@ func (m *deviceUtils) VerifyDevicePath(devicePaths []string, deviceName string)
244
247
// If there exists a devicePath we make sure disk at /dev/* matches the
245
248
// expected disk at devicePath by matching device Serial to the disk name
246
249
devFsPath , innerErr := filepath .EvalSymlinks (devicePath )
247
- klog .V (4 ).Infof ("For disk %s the /dev/* path is %s" , deviceName , devFsPath )
248
250
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
250
254
}
255
+ klog .V (4 ).Infof ("For disk %s the /dev/* path is %s for disk/by-id path %s" , deviceName , devFsPath , devicePath )
251
256
252
257
devFsSerial , innerErr := getDevFsSerial (devFsPath )
253
258
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
255
262
}
263
+ klog .V (4 ).Infof ("For disk %s, device path %s, found serial number %s" , deviceName , devFsPath , devFsSerial )
256
264
// SUCCESS! devicePath points to a /dev/* path that has a serial
257
265
// equivalent to our disk name
258
266
if len (devFsSerial ) != 0 && devFsSerial == deviceName {
@@ -262,9 +270,12 @@ func (m *deviceUtils) VerifyDevicePath(devicePaths []string, deviceName string)
262
270
// A /dev/* path exists, but is either not a recognized /dev prefix type
263
271
// (/dev/nvme* or /dev/sd*) or devicePath is not mapped to the correct disk.
264
272
// Attempt a repair
273
+ klog .V (4 ).Infof ("For disk %s and device path %s with mismatched serial number %q calling udevadmTriggerForDiskIfExists" , deviceName , devFsPath , devFsSerial )
265
274
innerErr = udevadmTriggerForDiskIfExists (deviceName )
266
275
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
268
279
}
269
280
// Go to next retry loop to get the deviceName again after
270
281
// potentially fixing it with the udev command
@@ -318,23 +329,23 @@ func udevadmTriggerForDiskIfExists(deviceName string) error {
318
329
if err != nil || len (devFsSerial ) == 0 {
319
330
// If we get an error, ignore. Either this isn't a block device, or it
320
331
// 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 ())
322
333
continue
323
334
}
335
+ klog .V (4 ).Infof ("device path %s, serial number %v" , devFsPath , devFsSerial )
324
336
devFsPathToSerial [devFsPath ] = devFsSerial
325
337
if devFsSerial == deviceName {
326
338
// Found the disk that we're looking for so run a trigger on it
327
339
// 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 )
329
341
err := udevadmChangeToDrive (devFsPath )
330
342
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 )
332
344
}
333
345
return nil
334
346
}
335
347
}
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 )
338
349
}
339
350
340
351
// Calls "udevadm trigger --action=change" on the specified drive. drivePath
@@ -347,13 +358,15 @@ func udevadmTriggerForDiskIfExists(deviceName string) error {
347
358
// the change
348
359
func udevadmChangeToDrive (devFsPath string ) error {
349
360
// Call "udevadm trigger --action=change --property-match=DEVNAME=/dev/..."
350
- out , err := exec .Command (
361
+ cmd := exec .Command (
351
362
"udevadm" ,
352
363
"trigger" ,
353
364
"--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 ()
355
368
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: %v " , devFsPath , string (out ), err )
357
370
}
358
371
return nil
359
372
}
0 commit comments