@@ -221,16 +221,21 @@ func (m *deviceUtils) VerifyDevicePath(devicePaths []string, deviceName string)
221
221
222
222
devicePath , innerErr = existingDevicePath (devicePaths )
223
223
if innerErr != nil {
224
- return false , fmt .Errorf ("failed to check for existing device path: %w" , innerErr )
224
+ e := fmt .Errorf ("for disk %s failed to check for existing device path: %w" , deviceName , innerErr )
225
+ klog .Errorf (e .Error ())
226
+ return false , e
225
227
}
226
228
227
229
if len (devicePath ) == 0 {
228
230
// Couldn't find a /dev/disk/by-id path for this deviceName, so we need to
229
231
// find a /dev/* with a serial that matches deviceName. Then we attempt
230
232
// to repair the symlink.
233
+ klog .Warningf ("For disk %s couldn't find a device path, calling udevadmTriggerForDiskIfExists" , deviceName )
231
234
innerErr := udevadmTriggerForDiskIfExists (deviceName )
232
235
if innerErr != nil {
233
- return false , fmt .Errorf ("failed to trigger udevadm fix of non existent disk for %q: %w" , deviceName , innerErr )
236
+ e := fmt .Errorf ("for disk %s failed to trigger udevadm fix of non existent device path: %w" , deviceName , innerErr )
237
+ klog .Errorf (e .Error ())
238
+ return false , e
234
239
}
235
240
// Go to next retry loop to get the deviceName again after
236
241
// potentially fixing it with the udev command
@@ -242,13 +247,20 @@ func (m *deviceUtils) VerifyDevicePath(devicePaths []string, deviceName string)
242
247
devFsPath , innerErr := filepath .EvalSymlinks (devicePath )
243
248
klog .V (4 ).Infof ("For disk %s the /dev/* path is %s" , deviceName , devFsPath )
244
249
if innerErr != nil {
245
- return false , fmt .Errorf ("filepath.EvalSymlinks(%q) failed with %w" , devicePath , innerErr )
250
+ e := fmt .Errorf ("filepath.EvalSymlinks(%q) failed: %w" , devicePath , innerErr )
251
+ klog .Errorf (e .Error ())
252
+ return false , e
246
253
}
247
254
255
+ klog .V (4 ).Infof ("For disk %s the /dev/* path is %s for disk/by-id path %s" , deviceName , devFsPath , devicePath )
248
256
devFsSerial , innerErr := getDevFsSerial (devFsPath )
249
257
if innerErr != nil {
250
- return false , fmt .Errorf ("couldn't get serial number for disk %s at path %s: %w" , deviceName , devFsPath , innerErr )
258
+ e := fmt .Errorf ("couldn't get serial number for disk %s at device path %s: %w" , deviceName , devFsPath , innerErr )
259
+ klog .Errorf (e .Error ())
260
+ return false , e
251
261
}
262
+
263
+ klog .V (4 ).Infof ("For disk %s, device path %s, found serial number %s" , deviceName , devFsPath , devFsSerial )
252
264
// SUCCESS! devicePath points to a /dev/* path that has a serial
253
265
// equivalent to our disk name
254
266
if len (devFsSerial ) != 0 && devFsSerial == deviceName {
@@ -258,9 +270,12 @@ func (m *deviceUtils) VerifyDevicePath(devicePaths []string, deviceName string)
258
270
// A /dev/* path exists, but is either not a recognized /dev prefix type
259
271
// (/dev/nvme* or /dev/sd*) or devicePath is not mapped to the correct disk.
260
272
// Attempt a repair
273
+ klog .Warningf ("For disk %s and device path %s with mismatched serial number %q calling udevadmTriggerForDiskIfExists" , deviceName , devFsPath , devFsSerial )
261
274
innerErr = udevadmTriggerForDiskIfExists (deviceName )
262
275
if innerErr != nil {
263
- 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
264
279
}
265
280
// Go to next retry loop to get the deviceName again after
266
281
// potentially fixing it with the udev command
@@ -310,23 +325,22 @@ func udevadmTriggerForDiskIfExists(deviceName string) error {
310
325
if err != nil || len (devFsSerial ) == 0 {
311
326
// If we get an error, ignore. Either this isn't a block device, or it
312
327
// isn't something we can get a serial number from
313
- klog .V ( 7 ). Infof ( "failed to get Serial num for disk %s at path %s: %v" , deviceName , devFsPath , err .Error ())
328
+ klog .Errorf ( "failed to get serial num for disk %s at device path %s: %v" , deviceName , devFsPath , err .Error ())
314
329
continue
315
330
}
316
331
devFsPathToSerial [devFsPath ] = devFsSerial
317
332
if devFsSerial == deviceName {
318
333
// Found the disk that we're looking for so run a trigger on it
319
334
// to resolve its /dev/by-id/ path
320
- klog .Warningf ("udevadm --trigger running to fix disk at path %s which has serial numberID %s" , devFsPath , devFsSerial )
335
+ klog .Warningf ("udevadm --trigger running to fix disk at path %s which has serial number %s" , devFsPath , devFsSerial )
321
336
err := udevadmChangeToDrive (devFsPath )
322
337
if err != nil {
323
- return fmt .Errorf ("failed to fix disk which has serial numberID %s: %w" , devFsSerial , err )
338
+ return fmt .Errorf ("udevadm --trigger failed to fix device path %s which has serial number %s: %w" , devFsPath , devFsSerial , err )
324
339
}
325
340
return nil
326
341
}
327
342
}
328
- klog .Warningf ("udevadm --trigger requested to fix disk %s but no such disk was found in %v" , deviceName , devFsPathToSerial )
329
- return fmt .Errorf ("udevadm --trigger requested to fix disk %s but no such disk was found" , deviceName )
343
+ return fmt .Errorf ("udevadm --trigger requested to fix disk %s but no such disk was found in device path %v" , deviceName , devFsPathToSerial )
330
344
}
331
345
332
346
// Calls "udevadm trigger --action=change" on the specified drive. drivePath
@@ -339,11 +353,13 @@ func udevadmTriggerForDiskIfExists(deviceName string) error {
339
353
// the change
340
354
func udevadmChangeToDrive (devFsPath string ) error {
341
355
// Call "udevadm trigger --action=change --property-match=DEVNAME=/dev/..."
342
- out , err := exec .Command (
356
+ cmd := exec .Command (
343
357
"udevadm" ,
344
358
"trigger" ,
345
359
"--action=change" ,
346
- fmt .Sprintf ("--property-match=DEVNAME=%s" , devFsPath )).CombinedOutput ()
360
+ fmt .Sprintf ("--property-match=DEVNAME=%s" , devFsPath ))
361
+ klog .V (4 ).Infof ("Running command: %s" , cmd .String ())
362
+ out , err := cmd .CombinedOutput ()
347
363
if err != nil {
348
364
return fmt .Errorf ("udevadmChangeToDrive: udevadm trigger failed for drive %q with output %s: %w." , devFsPath , string (out ), err )
349
365
}
0 commit comments