@@ -221,16 +221,21 @@ func (m *deviceUtils) VerifyDevicePath(devicePaths []string, deviceName string)
221221
222222 devicePath , innerErr = existingDevicePath (devicePaths )
223223 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
225227 }
226228
227229 if len (devicePath ) == 0 {
228230 // Couldn't find a /dev/disk/by-id path for this deviceName, so we need to
229231 // find a /dev/* with a serial that matches deviceName. Then we attempt
230232 // to repair the symlink.
233+ klog .Warningf ("For disk %s couldn't find a device path, calling udevadmTriggerForDiskIfExists" , deviceName )
231234 innerErr := udevadmTriggerForDiskIfExists (deviceName )
232235 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
234239 }
235240 // Go to next retry loop to get the deviceName again after
236241 // potentially fixing it with the udev command
@@ -242,13 +247,20 @@ func (m *deviceUtils) VerifyDevicePath(devicePaths []string, deviceName string)
242247 devFsPath , innerErr := filepath .EvalSymlinks (devicePath )
243248 klog .V (4 ).Infof ("For disk %s the /dev/* path is %s" , deviceName , devFsPath )
244249 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
246253 }
247254
255+ klog .V (4 ).Infof ("For disk %s the /dev/* path is %s for disk/by-id path %s" , deviceName , devFsPath , devicePath )
248256 devFsSerial , innerErr := getDevFsSerial (devFsPath )
249257 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
251261 }
262+
263+ klog .V (4 ).Infof ("For disk %s, device path %s, found serial number %s" , deviceName , devFsPath , devFsSerial )
252264 // SUCCESS! devicePath points to a /dev/* path that has a serial
253265 // equivalent to our disk name
254266 if len (devFsSerial ) != 0 && devFsSerial == deviceName {
@@ -258,9 +270,12 @@ func (m *deviceUtils) VerifyDevicePath(devicePaths []string, deviceName string)
258270 // A /dev/* path exists, but is either not a recognized /dev prefix type
259271 // (/dev/nvme* or /dev/sd*) or devicePath is not mapped to the correct disk.
260272 // Attempt a repair
273+ klog .Warningf ("For disk %s and device path %s with mismatched serial number %q calling udevadmTriggerForDiskIfExists" , deviceName , devFsPath , devFsSerial )
261274 innerErr = udevadmTriggerForDiskIfExists (deviceName )
262275 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
264279 }
265280 // Go to next retry loop to get the deviceName again after
266281 // potentially fixing it with the udev command
@@ -310,23 +325,22 @@ func udevadmTriggerForDiskIfExists(deviceName string) error {
310325 if err != nil || len (devFsSerial ) == 0 {
311326 // If we get an error, ignore. Either this isn't a block device, or it
312327 // 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 ())
314329 continue
315330 }
316331 devFsPathToSerial [devFsPath ] = devFsSerial
317332 if devFsSerial == deviceName {
318333 // Found the disk that we're looking for so run a trigger on it
319334 // 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 )
321336 err := udevadmChangeToDrive (devFsPath )
322337 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 )
324339 }
325340 return nil
326341 }
327342 }
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 )
330344}
331345
332346// Calls "udevadm trigger --action=change" on the specified drive. drivePath
@@ -339,11 +353,13 @@ func udevadmTriggerForDiskIfExists(deviceName string) error {
339353// the change
340354func udevadmChangeToDrive (devFsPath string ) error {
341355 // Call "udevadm trigger --action=change --property-match=DEVNAME=/dev/..."
342- out , err := exec .Command (
356+ cmd := exec .Command (
343357 "udevadm" ,
344358 "trigger" ,
345359 "--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 ()
347363 if err != nil {
348364 return fmt .Errorf ("udevadmChangeToDrive: udevadm trigger failed for drive %q with output %s: %w." , devFsPath , string (out ), err )
349365 }
0 commit comments