@@ -65,15 +65,18 @@ func getRegionDevelTree(devices []device) dpapi.DeviceTree {
65
65
if region .interfaceID == unhealthyInterfaceID {
66
66
health = pluginapi .Unhealthy
67
67
}
68
+
68
69
devType := fmt .Sprintf ("%s-%s" , regionMode , region .interfaceID )
69
70
devNodes := make ([]pluginapi.DeviceSpec , len (region .afus )+ 1 )
71
+
70
72
for num , afu := range region .afus {
71
73
devNodes [num ] = pluginapi.DeviceSpec {
72
74
HostPath : afu .devNode ,
73
75
ContainerPath : afu .devNode ,
74
76
Permissions : "rw" ,
75
77
}
76
78
}
79
+
77
80
devNodes [len (region .afus )] = pluginapi.DeviceSpec {
78
81
HostPath : region .devNode ,
79
82
ContainerPath : region .devNode ,
@@ -97,15 +100,18 @@ func getRegionTree(devices []device) dpapi.DeviceTree {
97
100
if region .interfaceID == unhealthyInterfaceID {
98
101
health = pluginapi .Unhealthy
99
102
}
103
+
100
104
devType := fmt .Sprintf ("%s-%s" , regionMode , region .interfaceID )
101
105
devNodes := make ([]pluginapi.DeviceSpec , len (region .afus ))
106
+
102
107
for num , afu := range region .afus {
103
108
devNodes [num ] = pluginapi.DeviceSpec {
104
109
HostPath : afu .devNode ,
105
110
ContainerPath : afu .devNode ,
106
111
Permissions : "rw" ,
107
112
}
108
113
}
114
+
109
115
regionTree .AddDevice (devType , region .id , dpapi .NewDeviceInfo (health , devNodes , nil , nil ))
110
116
}
111
117
}
@@ -124,11 +130,13 @@ func getAfuTree(devices []device) dpapi.DeviceTree {
124
130
if afu .afuID == unhealthyAfuID {
125
131
health = pluginapi .Unhealthy
126
132
}
133
+
127
134
devType , err := fpga .GetAfuDevType (region .interfaceID , afu .afuID )
128
135
if err != nil {
129
136
klog .Warningf ("failed to get devtype: %+v" , err )
130
137
continue
131
138
}
139
+
132
140
devNodes := []pluginapi.DeviceSpec {
133
141
{
134
142
HostPath : afu .devNode ,
@@ -182,16 +190,20 @@ type devicePlugin struct {
182
190
183
191
// newDevicePlugin returns new instance of devicePlugin.
184
192
func newDevicePlugin (mode string , rootPath string ) (* devicePlugin , error ) {
185
- var dp * devicePlugin
186
- var err error
193
+ var (
194
+ dp * devicePlugin
195
+ err error
196
+ )
187
197
188
198
sysfsPathOPAE := path .Join (rootPath , sysfsDirectoryOPAE )
189
199
devfsPath := path .Join (rootPath , devfsDirectory )
200
+
190
201
if _ , err = os .Stat (sysfsPathOPAE ); os .IsNotExist (err ) {
191
202
sysfsPathDFL := path .Join (rootPath , sysfsDirectoryDFL )
192
203
if _ , err = os .Stat (sysfsPathDFL ); os .IsNotExist (err ) {
193
204
return nil , errors .Errorf ("kernel driver is not loaded: neither %s nor %s sysfs entry exists" , sysfsPathOPAE , sysfsPathDFL )
194
205
}
206
+
195
207
dp , err = newDevicePluginDFL (sysfsPathDFL , devfsPath , mode )
196
208
} else {
197
209
dp , err = newDevicePluginOPAE (sysfsPathOPAE , devfsPath , mode )
@@ -224,6 +236,7 @@ func (dp *devicePlugin) PostAllocate(response *pluginapi.AllocateResponse) error
224
236
// Scan starts scanning FPGA devices on the host.
225
237
func (dp * devicePlugin ) Scan (notifier dpapi.Notifier ) error {
226
238
defer dp .scanTicker .Stop ()
239
+
227
240
for {
228
241
devTree , err := dp .scanFPGAs ()
229
242
if err != nil {
@@ -242,20 +255,23 @@ func (dp *devicePlugin) Scan(notifier dpapi.Notifier) error {
242
255
243
256
func (dp * devicePlugin ) getRegions (deviceFiles []os.DirEntry ) ([]region , error ) {
244
257
regions := map [string ]region {}
258
+
245
259
for _ , deviceFile := range deviceFiles {
246
260
name := deviceFile .Name ()
247
261
if dp .portReg .MatchString (name ) {
248
262
port , err := dp .newPort (name )
249
263
if err != nil {
250
264
return nil , errors .Wrapf (err , "can't get port info for %s" , name )
251
265
}
266
+
252
267
fme , err := port .GetFME ()
253
268
if err != nil {
254
269
return nil , errors .Wrapf (err , "can't get FME info for %s" , name )
255
270
}
256
271
257
272
afuInfo := afu {id : port .GetName (), afuID : port .GetAcceleratorTypeUUID (), devNode : port .GetDevPath ()}
258
273
regionName := fme .GetName ()
274
+
259
275
reg , ok := regions [regionName ]
260
276
if ok {
261
277
reg .afus = append (reg .afus , afuInfo )
@@ -264,11 +280,13 @@ func (dp *devicePlugin) getRegions(deviceFiles []os.DirEntry) ([]region, error)
264
280
}
265
281
}
266
282
}
283
+
267
284
result := make ([]region , 0 , len (regions ))
268
285
// Get list of regions from the map
269
286
for _ , reg := range regions {
270
287
result = append (result , reg )
271
288
}
289
+
272
290
return result , nil
273
291
}
274
292
@@ -280,6 +298,7 @@ func (dp *devicePlugin) scanFPGAs() (dpapi.DeviceTree, error) {
280
298
}
281
299
282
300
devices := []device {}
301
+
283
302
for _ , file := range files {
284
303
devName := file .Name ()
285
304
@@ -301,6 +320,7 @@ func (dp *devicePlugin) scanFPGAs() (dpapi.DeviceTree, error) {
301
320
devices = append (devices , device {name : devName , regions : regions })
302
321
}
303
322
}
323
+
304
324
return dp .getDevTree (devices ), nil
305
325
}
306
326
@@ -327,10 +347,12 @@ func getPluginParams(mode string) (getDevTreeFunc, string, error) {
327
347
}
328
348
329
349
func main () {
330
- var mode string
331
- var kubeconfig string
332
- var master string
333
- var nodename string
350
+ var (
351
+ mode string
352
+ kubeconfig string
353
+ master string
354
+ nodename string
355
+ )
334
356
335
357
flag .StringVar (& kubeconfig , "kubeconfig" , "" , "absolute path to the kubeconfig file" )
336
358
flag .StringVar (& master , "master" , "" , "master url" )
0 commit comments