2929 ErrDeviceInitializationTimeout = errors .New ("device failed to initialize - size remained zero or unreadable" )
3030 ErrNVMeControllerNotFound = errors .New ("could not extract NVMe controller path from device path" )
3131 ErrDeviceSizeMismatch = errors .New ("device size does not match expected capacity" )
32+ ErrNVMeEmptyNQN = errors .New ("empty NQN in sysfs" )
33+ ErrNVMeNotNVMeDevice = errors .New ("not an NVMe device" )
34+ ErrNVMeNonNVMeStagingDevice = errors .New ("staging path resolved to non-NVMe device" )
3235)
3336
3437// NVMe subsystem states.
@@ -440,7 +443,7 @@ func (s *NodeService) deriveNQNFromStagingPath(ctx context.Context, stagingTarge
440443 return "" , err
441444 }
442445
443- nqnPath := filepath . Join ( "/sys/class/nvme" , controllerName , " subsysnqn")
446+ nqnPath := "/sys/class/nvme/" + controllerName + "/ subsysnqn"
444447 //nolint:gosec // sysfs read from fixed kernel path
445448 data , err := os .ReadFile (nqnPath )
446449 if err != nil {
@@ -449,7 +452,7 @@ func (s *NodeService) deriveNQNFromStagingPath(ctx context.Context, stagingTarge
449452
450453 nqn := strings .TrimSpace (string (data ))
451454 if nqn == "" {
452- return "" , fmt .Errorf ("empty NQN in %s " , nqnPath )
455+ return "" , fmt .Errorf ("%s: %w " , nqnPath , ErrNVMeEmptyNQN )
453456 }
454457 return nqn , nil
455458}
@@ -475,7 +478,7 @@ func (s *NodeService) getStagedNVMeDevicePath(ctx context.Context, stagingTarget
475478 return "" , fmt .Errorf ("failed to resolve staging path %s: %w" , stagingTargetPath , err )
476479 }
477480 if ! strings .HasPrefix (filepath .Base (resolved ), "nvme" ) {
478- return "" , fmt .Errorf ("staging path %s resolved to non-NVMe device %s " , stagingTargetPath , resolved )
481+ return "" , fmt .Errorf ("staging path %s resolved to %s: %w " , stagingTargetPath , resolved , ErrNVMeNonNVMeStagingDevice )
479482 }
480483 return resolved , nil
481484}
@@ -484,7 +487,7 @@ func (s *NodeService) getStagedNVMeDevicePath(ctx context.Context, stagingTarget
484487func getNVMeControllerFromDevicePath (devicePath string ) (string , error ) {
485488 base := filepath .Base (devicePath )
486489 if ! strings .HasPrefix (base , "nvme" ) {
487- return "" , fmt .Errorf ("not an NVMe device : %s " , devicePath )
490+ return "" , fmt .Errorf ("%s : %w " , devicePath , ErrNVMeNotNVMeDevice )
488491 }
489492
490493 // Namespace node: nvme0n1 -> nvme0
0 commit comments