@@ -65,15 +65,18 @@ func getRegionDevelTree(devices []device) dpapi.DeviceTree {
6565 if region .interfaceID == unhealthyInterfaceID {
6666 health = pluginapi .Unhealthy
6767 }
68+
6869 devType := fmt .Sprintf ("%s-%s" , regionMode , region .interfaceID )
6970 devNodes := make ([]pluginapi.DeviceSpec , len (region .afus )+ 1 )
71+
7072 for num , afu := range region .afus {
7173 devNodes [num ] = pluginapi.DeviceSpec {
7274 HostPath : afu .devNode ,
7375 ContainerPath : afu .devNode ,
7476 Permissions : "rw" ,
7577 }
7678 }
79+
7780 devNodes [len (region .afus )] = pluginapi.DeviceSpec {
7881 HostPath : region .devNode ,
7982 ContainerPath : region .devNode ,
@@ -97,15 +100,18 @@ func getRegionTree(devices []device) dpapi.DeviceTree {
97100 if region .interfaceID == unhealthyInterfaceID {
98101 health = pluginapi .Unhealthy
99102 }
103+
100104 devType := fmt .Sprintf ("%s-%s" , regionMode , region .interfaceID )
101105 devNodes := make ([]pluginapi.DeviceSpec , len (region .afus ))
106+
102107 for num , afu := range region .afus {
103108 devNodes [num ] = pluginapi.DeviceSpec {
104109 HostPath : afu .devNode ,
105110 ContainerPath : afu .devNode ,
106111 Permissions : "rw" ,
107112 }
108113 }
114+
109115 regionTree .AddDevice (devType , region .id , dpapi .NewDeviceInfo (health , devNodes , nil , nil ))
110116 }
111117 }
@@ -124,11 +130,13 @@ func getAfuTree(devices []device) dpapi.DeviceTree {
124130 if afu .afuID == unhealthyAfuID {
125131 health = pluginapi .Unhealthy
126132 }
133+
127134 devType , err := fpga .GetAfuDevType (region .interfaceID , afu .afuID )
128135 if err != nil {
129136 klog .Warningf ("failed to get devtype: %+v" , err )
130137 continue
131138 }
139+
132140 devNodes := []pluginapi.DeviceSpec {
133141 {
134142 HostPath : afu .devNode ,
@@ -182,16 +190,20 @@ type devicePlugin struct {
182190
183191// newDevicePlugin returns new instance of devicePlugin.
184192func newDevicePlugin (mode string , rootPath string ) (* devicePlugin , error ) {
185- var dp * devicePlugin
186- var err error
193+ var (
194+ dp * devicePlugin
195+ err error
196+ )
187197
188198 sysfsPathOPAE := path .Join (rootPath , sysfsDirectoryOPAE )
189199 devfsPath := path .Join (rootPath , devfsDirectory )
200+
190201 if _ , err = os .Stat (sysfsPathOPAE ); os .IsNotExist (err ) {
191202 sysfsPathDFL := path .Join (rootPath , sysfsDirectoryDFL )
192203 if _ , err = os .Stat (sysfsPathDFL ); os .IsNotExist (err ) {
193204 return nil , errors .Errorf ("kernel driver is not loaded: neither %s nor %s sysfs entry exists" , sysfsPathOPAE , sysfsPathDFL )
194205 }
206+
195207 dp , err = newDevicePluginDFL (sysfsPathDFL , devfsPath , mode )
196208 } else {
197209 dp , err = newDevicePluginOPAE (sysfsPathOPAE , devfsPath , mode )
@@ -224,6 +236,7 @@ func (dp *devicePlugin) PostAllocate(response *pluginapi.AllocateResponse) error
224236// Scan starts scanning FPGA devices on the host.
225237func (dp * devicePlugin ) Scan (notifier dpapi.Notifier ) error {
226238 defer dp .scanTicker .Stop ()
239+
227240 for {
228241 devTree , err := dp .scanFPGAs ()
229242 if err != nil {
@@ -242,20 +255,23 @@ func (dp *devicePlugin) Scan(notifier dpapi.Notifier) error {
242255
243256func (dp * devicePlugin ) getRegions (deviceFiles []os.DirEntry ) ([]region , error ) {
244257 regions := map [string ]region {}
258+
245259 for _ , deviceFile := range deviceFiles {
246260 name := deviceFile .Name ()
247261 if dp .portReg .MatchString (name ) {
248262 port , err := dp .newPort (name )
249263 if err != nil {
250264 return nil , errors .Wrapf (err , "can't get port info for %s" , name )
251265 }
266+
252267 fme , err := port .GetFME ()
253268 if err != nil {
254269 return nil , errors .Wrapf (err , "can't get FME info for %s" , name )
255270 }
256271
257272 afuInfo := afu {id : port .GetName (), afuID : port .GetAcceleratorTypeUUID (), devNode : port .GetDevPath ()}
258273 regionName := fme .GetName ()
274+
259275 reg , ok := regions [regionName ]
260276 if ok {
261277 reg .afus = append (reg .afus , afuInfo )
@@ -264,11 +280,13 @@ func (dp *devicePlugin) getRegions(deviceFiles []os.DirEntry) ([]region, error)
264280 }
265281 }
266282 }
283+
267284 result := make ([]region , 0 , len (regions ))
268285 // Get list of regions from the map
269286 for _ , reg := range regions {
270287 result = append (result , reg )
271288 }
289+
272290 return result , nil
273291}
274292
@@ -280,6 +298,7 @@ func (dp *devicePlugin) scanFPGAs() (dpapi.DeviceTree, error) {
280298 }
281299
282300 devices := []device {}
301+
283302 for _ , file := range files {
284303 devName := file .Name ()
285304
@@ -301,6 +320,7 @@ func (dp *devicePlugin) scanFPGAs() (dpapi.DeviceTree, error) {
301320 devices = append (devices , device {name : devName , regions : regions })
302321 }
303322 }
323+
304324 return dp .getDevTree (devices ), nil
305325}
306326
@@ -327,10 +347,12 @@ func getPluginParams(mode string) (getDevTreeFunc, string, error) {
327347}
328348
329349func 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+ )
334356
335357 flag .StringVar (& kubeconfig , "kubeconfig" , "" , "absolute path to the kubeconfig file" )
336358 flag .StringVar (& master , "master" , "" , "master url" )
0 commit comments