@@ -14,47 +14,25 @@ import (
14
14
15
15
. "github.com/netapp/trident/logging"
16
16
"github.com/netapp/trident/utils/devices/luks"
17
- "github.com/netapp/trident/utils/errors"
18
17
"github.com/netapp/trident/utils/exec"
19
18
"github.com/netapp/trident/utils/filesystem"
20
19
"github.com/netapp/trident/utils/models"
21
20
)
22
21
23
22
const NVMeAttachTimeout = 20 * time .Second
24
23
25
- var fsClient = filesystem .New (mountClient )
26
-
27
- // getNVMeSubsystem returns the NVMe subsystem details.
28
- func getNVMeSubsystem (ctx context.Context , subsysNqn string ) (* NVMeSubsystem , error ) {
29
- Logc (ctx ).Debug (">>>> nvme.getNVMeSubsystem" )
30
- defer Logc (ctx ).Debug ("<<<< nvme.getNVMeSubsystem" )
31
-
32
- subsys , err := GetNVMeSubsystemList (ctx )
33
- if err != nil {
34
- Logc (ctx ).WithField ("Error" , err ).Errorf ("Failed to get subsystem list: %v" , err )
35
- return nil , err
36
- }
37
-
38
- // Getting current subsystem details.
39
- for _ , sub := range subsys .Subsystems {
40
- if sub .NQN == subsysNqn {
41
- return & sub , nil
42
- }
43
- }
44
-
45
- return nil , fmt .Errorf ("couldn't find subsystem %s" , subsysNqn )
46
- }
24
+ var fsClient = * filesystem .New (mountClient )
47
25
48
26
// updatePaths updates the paths with the current state of the subsystem on the k8s node.
49
27
func (s * NVMeSubsystem ) updatePaths (ctx context.Context ) error {
50
28
// Getting current state of subsystem on the k8s node.
51
- sub , err := getNVMeSubsystem (ctx , s . NQN )
29
+ paths , err := GetNVMeSubsystemPaths (ctx , fsClient , s . Name )
52
30
if err != nil {
53
31
Logc (ctx ).WithField ("Error" , err ).Errorf ("Failed to update subsystem paths: %v" , err )
54
32
return fmt .Errorf ("failed to update subsystem paths: %v" , err )
55
33
}
56
34
57
- s .Paths = sub . Paths
35
+ s .Paths = paths
58
36
59
37
return nil
60
38
}
@@ -137,43 +115,38 @@ func (s *NVMeSubsystem) Disconnect(ctx context.Context) error {
137
115
138
116
// GetNamespaceCount returns the number of namespaces mapped to the subsystem.
139
117
func (s * NVMeSubsystem ) GetNamespaceCount (ctx context.Context ) (int , error ) {
140
- var combinedError error
141
-
118
+ credibility := false
142
119
for _ , path := range s .Paths {
143
- count , err := GetNamespaceCountForSubsDevice (ctx , "/dev/" + path .Name )
144
- if err != nil {
145
- Logc (ctx ).WithField ("Error" , err ).Warnf ("Failed to get namespace count: %v" , err )
146
- combinedError = multierr .Append (combinedError , err )
147
- continue
120
+ if path .State == "live" {
121
+ credibility = true
122
+ break
148
123
}
124
+ }
149
125
150
- return count , nil
126
+ if ! credibility {
127
+ return 0 , fmt .Errorf ("nvme paths are down, couldn't get the number of namespaces" )
128
+ }
129
+
130
+ count , err := GetNVMeDeviceCountAt (ctx , s .FS , s .Name )
131
+ if err != nil {
132
+ Logc (ctx ).Errorf ("Failed to get namespace count: %v" , err )
133
+ return 0 , err
151
134
}
152
135
153
- // Couldn't find any sessions, so no namespaces are attached to this subsystem.
154
- // But if there was error getting the number of namespaces from all the paths, return error.
155
- return 0 , combinedError
136
+ return count , nil
156
137
}
157
138
158
- // getNVMeDevice returns the NVMe device corresponding to nsPath namespace.
159
- func getNVMeDevice (ctx context.Context , nsUUID string ) (* NVMeDevice , error ) {
160
- Logc (ctx ).Debug (">>>> nvme.getNVMeDevice" )
161
- defer Logc (ctx ).Debug ("<<<< nvme.getNVMeDevice" )
139
+ func (s * NVMeSubsystem ) GetNVMeDevice (ctx context.Context , nsUUID string ) (NVMeDeviceInterface , error ) {
140
+ Logc (ctx ).Debug (">>>> nvme.GetNVMeDevice" )
141
+ defer Logc (ctx ).Debug ("<<<< nvme.GetNVMeDevice" )
162
142
163
- dList , err := GetNVMeDeviceList (ctx )
143
+ devInterface , err := GetNVMeDeviceAt (ctx , s . Name , nsUUID )
164
144
if err != nil {
165
- return nil , fmt .Errorf ("failed to get device: %v" , err )
166
- }
167
-
168
- for _ , dev := range dList .Devices {
169
- if dev .UUID == nsUUID {
170
- Logc (ctx ).Debugf ("Device found: %v." , dev )
171
- return & dev , nil
172
- }
145
+ Logc (ctx ).Errorf ("Failed to get NVMe device, %v" , err )
146
+ return nil , err
173
147
}
174
148
175
- Logc (ctx ).WithField ("nsUUID" , nsUUID ).Debug ("No device found for this Namespace." )
176
- return nil , errors .NotFoundError ("no device found for the given namespace %v" , nsUUID )
149
+ return devInterface , nil
177
150
}
178
151
179
152
// GetPath returns the device path where we mount the filesystem in NodePublish.
@@ -203,7 +176,7 @@ func (d *NVMeDevice) FlushDevice(ctx context.Context, ignoreErrors, force bool)
203
176
204
177
// IsNil returns true if Device and NamespacePath are not set.
205
178
func (d * NVMeDevice ) IsNil () bool {
206
- if d == nil || ( d .Device == "" && d . NamespacePath == "" ) {
179
+ if d == nil || d .Device == "" {
207
180
return true
208
181
}
209
182
return false
@@ -214,20 +187,15 @@ func NewNVMeHandler() NVMeInterface {
214
187
return & NVMeHandler {}
215
188
}
216
189
217
- // NewNVMeDevice returns new NVMe device
218
- func (nh * NVMeHandler ) NewNVMeDevice (ctx context.Context , nsUUID string ) (NVMeDeviceInterface , error ) {
219
- return getNVMeDevice (ctx , nsUUID )
220
- }
221
-
222
190
// NewNVMeSubsystem returns NVMe subsystem object. Even if a subsystem is not connected to the k8s node,
223
191
// this function returns a minimal NVMe subsystem object.
224
192
func (nh * NVMeHandler ) NewNVMeSubsystem (ctx context.Context , subsNqn string ) NVMeSubsystemInterface {
225
- sub , err := getNVMeSubsystem (ctx , subsNqn )
193
+ sub , err := GetNVMeSubsystem (ctx , fsClient , subsNqn )
226
194
if err != nil {
227
195
Logc (ctx ).WithField ("Error" , err ).Warnf ("Failed to get subsystem: %v; returning minimal subsystem" , err )
228
196
return & NVMeSubsystem {NQN : subsNqn }
229
197
}
230
- return sub
198
+ return & sub
231
199
}
232
200
233
201
// GetHostNqn returns the NQN of the k8s node.
@@ -295,7 +263,7 @@ func AttachNVMeVolume(
295
263
}
296
264
}
297
265
298
- nvmeDev , err := nvmeHandler . NewNVMeDevice (ctx , publishInfo .NVMeNamespaceUUID )
266
+ nvmeDev , err := nvmeSubsys . GetNVMeDevice (ctx , publishInfo .NVMeNamespaceUUID )
299
267
if err != nil {
300
268
return err
301
269
}
@@ -589,7 +557,7 @@ func (nh *NVMeHandler) PopulateCurrentNVMeSessions(ctx context.Context, currSess
589
557
}
590
558
591
559
// Get the list of the subsystems currently present on the k8s node.
592
- subs , err := GetNVMeSubsystemList ( ctx )
560
+ subs , err := listSubsystemsFromSysFs ( fsClient , ctx )
593
561
if err != nil {
594
562
Logc (ctx ).WithField ("Error" , err ).Errorf ("Failed to get subsystem list: %v" , err )
595
563
return err
0 commit comments