Skip to content

Commit 40222fc

Browse files
committed
Improve logging for device path verification
1 parent ebaa88a commit 40222fc

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

pkg/deviceutils/device-utils.go

+30-16
Original file line numberDiff line numberDiff line change
@@ -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,21 @@ 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)
250+
klog.V(4).Infof("For disk %s the /dev/* path is %s for disk/by-id path %s", deviceName, devFsPath, devicePath)
248251
if innerErr != nil {
249-
return false, fmt.Errorf("filepath.EvalSymlinks(%q) failed with %w", devicePath, innerErr)
252+
e := fmt.Errorf("filepath.EvalSymlinks(%q) failed: %w", devicePath, innerErr)
253+
klog.Errorf(e.Error())
254+
return false, e
250255
}
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+
264+
klog.V(4).Infof("For disk %s, device path %s, found serial number %s", deviceName, devFsPath, devFsSerial)
256265
// SUCCESS! devicePath points to a /dev/* path that has a serial
257266
// equivalent to our disk name
258267
if len(devFsSerial) != 0 && devFsSerial == deviceName {
@@ -262,9 +271,12 @@ func (m *deviceUtils) VerifyDevicePath(devicePaths []string, deviceName string)
262271
// A /dev/* path exists, but is either not a recognized /dev prefix type
263272
// (/dev/nvme* or /dev/sd*) or devicePath is not mapped to the correct disk.
264273
// Attempt a repair
274+
klog.V(4).Infof("For disk %s and device path %s with mismatched serial number %s calling udevadmTriggerForDiskIfExists", deviceName, devFsPath, devFsSerial)
265275
innerErr = udevadmTriggerForDiskIfExists(deviceName)
266276
if innerErr != nil {
267-
return false, fmt.Errorf("failed to trigger udevadm fix of misconfigured disk for %q: %w", deviceName, innerErr)
277+
e := fmt.Errorf("failed to trigger udevadm fix of misconfigured disk for %q: %w", deviceName, innerErr)
278+
klog.Errorf(e.Error())
279+
return false, e
268280
}
269281
// Go to next retry loop to get the deviceName again after
270282
// potentially fixing it with the udev command
@@ -318,23 +330,23 @@ func udevadmTriggerForDiskIfExists(deviceName string) error {
318330
if err != nil || len(devFsSerial) == 0 {
319331
// If we get an error, ignore. Either this isn't a block device, or it
320332
// 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())
333+
klog.Errorf("failed to get serial num for disk %s at device path %s: %v", deviceName, devFsPath, err.Error())
322334
continue
323335
}
336+
klog.V(4).Infof("device path %s, serial number %v", devFsPath, devFsSerial)
324337
devFsPathToSerial[devFsPath] = devFsSerial
325338
if devFsSerial == deviceName {
326339
// Found the disk that we're looking for so run a trigger on it
327340
// 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)
341+
klog.Warningf("udevadm --trigger running to fix disk at path %s which has serial number %s", devFsPath, devFsSerial)
329342
err := udevadmChangeToDrive(devFsPath)
330343
if err != nil {
331-
return fmt.Errorf("failed to fix disk which has serial numberID %s: %w", devFsSerial, err)
344+
return fmt.Errorf("failed to fix device path %s which has serial number %s: %w", devFsPath, devFsSerial, err)
332345
}
333346
return nil
334347
}
335348
}
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)
349+
return fmt.Errorf("udevadm --trigger requested to fix disk %s but no such disk was found in device path %v", deviceName, devFsPathToSerial)
338350
}
339351

340352
// Calls "udevadm trigger --action=change" on the specified drive. drivePath
@@ -347,13 +359,15 @@ func udevadmTriggerForDiskIfExists(deviceName string) error {
347359
// the change
348360
func udevadmChangeToDrive(devFsPath string) error {
349361
// Call "udevadm trigger --action=change --property-match=DEVNAME=/dev/..."
350-
out, err := exec.Command(
362+
cmd := exec.Command(
351363
"udevadm",
352364
"trigger",
353365
"--action=change",
354-
fmt.Sprintf("--property-match=DEVNAME=%s", devFsPath)).CombinedOutput()
366+
fmt.Sprintf("--property-match=DEVNAME=%s", devFsPath))
367+
klog.V(4).Infof("Running command: %s", cmd.String())
368+
out, err := cmd.CombinedOutput()
355369
if err != nil {
356-
return fmt.Errorf("udevadmChangeToDrive: udevadm trigger failed for drive %q with output %s: %w.", devFsPath, string(out), err)
370+
return fmt.Errorf("udevadmChangeToDrive: udevadm trigger failed for drive %q with output %s: %v", devFsPath, string(out), err)
357371
}
358372
return nil
359373
}

0 commit comments

Comments
 (0)