Skip to content

Commit facb421

Browse files
committed
tree-wide: drop deprecated io/ioutil
Go 1.16 release notes announced the deprecation of io/ioutil [1]. It's easy for us to move to use what is was recommended so just do it. [1] https://golang.org/doc/go1.16#ioutil Signed-off-by: Mikko Ylinen <mikko.ylinen@intel.com>
1 parent f59a1fb commit facb421

File tree

26 files changed

+58
-153
lines changed

26 files changed

+58
-153
lines changed

cmd/fpga_crihook/main_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package main
1616

1717
import (
1818
"flag"
19-
"io/ioutil"
2019
"os"
2120
"path"
2221
"testing"
@@ -38,7 +37,7 @@ func createTestDirs(sysfs string, sysfsDirs []string, sysfsFiles map[string][]by
3837
}
3938
}
4039
for filename, body := range sysfsFiles {
41-
err := ioutil.WriteFile(path.Join(sysfs, filename), body, 0600)
40+
err := os.WriteFile(path.Join(sysfs, filename), body, 0600)
4241
if err != nil {
4342
return errors.Wrap(err, "Failed to create fake vendor file")
4443
}
@@ -216,7 +215,7 @@ func newTestPort(dev string) (fpga.Port, error) {
216215
}
217216

218217
func TestGetFPGAParams(t *testing.T) {
219-
tmpdir, err := ioutil.TempDir("", "TestGetFPGAParams")
218+
tmpdir, err := os.MkdirTemp("", "TestGetFPGAParams")
220219
if err != nil {
221220
t.Fatalf("can't create temporary directory: %+v", err)
222221
}
@@ -333,7 +332,7 @@ func TestGetFPGAParams(t *testing.T) {
333332
}
334333

335334
func TestProcess(t *testing.T) {
336-
tmpdir, err := ioutil.TempDir("", "testProcess")
335+
tmpdir, err := os.MkdirTemp("", "testProcess")
337336
if err != nil {
338337
t.Fatalf("can't create temporary directory: %+v", err)
339338
}

cmd/fpga_plugin/dfl_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package main
1616

1717
import (
18-
"io/ioutil"
1918
"os"
2019
"path"
2120
"reflect"
@@ -309,7 +308,7 @@ func genNewDFLPort(sysFsPrefix, devDir string, sysFsInfo map[string][]string) ne
309308
}
310309
}
311310
func TestScanFPGAsDFL(t *testing.T) {
312-
tmpdir, err := ioutil.TempDir("", "TestScanFPGAsDFL")
311+
tmpdir, err := os.MkdirTemp("", "TestScanFPGAsDFL")
313312
if err != nil {
314313
t.Fatalf("can't create temporary directory: %+v", err)
315314
}

cmd/fpga_plugin/fpga_plugin.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package main
1717
import (
1818
"flag"
1919
"fmt"
20-
"io/ioutil"
2120
"os"
2221
"path"
2322
"regexp"
@@ -241,7 +240,7 @@ func (dp *devicePlugin) Scan(notifier dpapi.Notifier) error {
241240
}
242241
}
243242

244-
func (dp *devicePlugin) getRegions(deviceFiles []os.FileInfo) ([]region, error) {
243+
func (dp *devicePlugin) getRegions(deviceFiles []os.DirEntry) ([]region, error) {
245244
regions := map[string]region{}
246245
for _, deviceFile := range deviceFiles {
247246
name := deviceFile.Name()
@@ -274,7 +273,7 @@ func (dp *devicePlugin) getRegions(deviceFiles []os.FileInfo) ([]region, error)
274273
}
275274

276275
func (dp *devicePlugin) scanFPGAs() (dpapi.DeviceTree, error) {
277-
files, err := ioutil.ReadDir(dp.sysfsDir)
276+
files, err := os.ReadDir(dp.sysfsDir)
278277
if err != nil {
279278
klog.Warningf("Can't read folder %s. Kernel driver not loaded?", dp.sysfsDir)
280279
return dp.getDevTree([]device{}), nil
@@ -288,7 +287,7 @@ func (dp *devicePlugin) scanFPGAs() (dpapi.DeviceTree, error) {
288287
continue
289288
}
290289

291-
deviceFiles, err := ioutil.ReadDir(path.Join(dp.sysfsDir, devName))
290+
deviceFiles, err := os.ReadDir(path.Join(dp.sysfsDir, devName))
292291
if err != nil {
293292
return nil, errors.WithStack(err)
294293
}

cmd/fpga_plugin/fpga_plugin_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package main
1717
import (
1818
"flag"
1919
"fmt"
20-
"io/ioutil"
2120
"os"
2221
"path"
2322
"testing"
@@ -49,7 +48,7 @@ func createTestDirs(devfs, sysfs string, devfsDirs, sysfsDirs []string, sysfsFil
4948
}
5049
}
5150
for filename, body := range sysfsFiles {
52-
err = ioutil.WriteFile(path.Join(sysfs, filename), body, 0600)
51+
err = os.WriteFile(path.Join(sysfs, filename), body, 0600)
5352
if err != nil {
5453
return errors.Wrap(err, "Failed to create fake vendor file")
5554
}
@@ -102,7 +101,7 @@ func TestPostAllocate(t *testing.T) {
102101
}
103102

104103
func TestNewDevicePlugin(t *testing.T) {
105-
root, err := ioutil.TempDir("", "test_new_device_plugin")
104+
root, err := os.MkdirTemp("", "test_new_device_plugin")
106105
if err != nil {
107106
t.Fatalf("can't create temporary directory: %+v", err)
108107
}
@@ -183,7 +182,7 @@ func (n *fakeNotifier) Notify(newDeviceTree dpapi.DeviceTree) {
183182
}
184183

185184
func TestScan(t *testing.T) {
186-
root, err := ioutil.TempDir("", "TestScan")
185+
root, err := os.MkdirTemp("", "TestScan")
187186
if err != nil {
188187
t.Fatalf("can't create temporary directory: %+v", err)
189188
}

cmd/fpga_plugin/opae_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package main
1616

1717
import (
18-
"io/ioutil"
1918
"os"
2019
"path"
2120
"reflect"
@@ -261,7 +260,7 @@ func genNewIntelFpgaPort(sysFsPrefix, devDir string, sysFsInfo map[string][]stri
261260
}
262261

263262
func TestScanFPGAsOPAE(t *testing.T) {
264-
tmpdir, err := ioutil.TempDir("", "TestScanFPGAsOPAE")
263+
tmpdir, err := os.MkdirTemp("", "TestScanFPGAsOPAE")
265264
if err != nil {
266265
t.Fatalf("can't create temporary directory: %+v", err)
267266
}

cmd/gpu_nfdhook/labeler.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package main
1717
import (
1818
"bufio"
1919
"fmt"
20-
"io/ioutil"
2120
"os"
2221
"path"
2322
"path/filepath"
@@ -63,7 +62,7 @@ func newLabeler(sysfsDRMDir, debugfsDRIDir string) *labeler {
6362
}
6463

6564
func (l *labeler) scan() ([]string, error) {
66-
files, err := ioutil.ReadDir(l.sysfsDRMDir)
65+
files, err := os.ReadDir(l.sysfsDRMDir)
6766
gpuNameList := []string{}
6867

6968
if err != nil {
@@ -76,7 +75,7 @@ func (l *labeler) scan() ([]string, error) {
7675
continue
7776
}
7877

79-
dat, err := ioutil.ReadFile(path.Join(l.sysfsDRMDir, f.Name(), "device/vendor"))
78+
dat, err := os.ReadFile(path.Join(l.sysfsDRMDir, f.Name(), "device/vendor"))
8079
if err != nil {
8180
klog.Warning("Skipping. Can't read vendor file: ", err)
8281
continue
@@ -87,7 +86,7 @@ func (l *labeler) scan() ([]string, error) {
8786
continue
8887
}
8988

90-
_, err = ioutil.ReadDir(path.Join(l.sysfsDRMDir, f.Name(), "device/drm"))
89+
_, err = os.ReadDir(path.Join(l.sysfsDRMDir, f.Name(), "device/drm"))
9190
if err != nil {
9291
return gpuNameList, errors.Wrap(err, "Can't read device folder")
9392
}
@@ -125,7 +124,7 @@ func (l *labeler) getTileMemoryAmount(gpuName string) (mem, numTiles uint64) {
125124
}
126125

127126
for _, fileName := range files {
128-
dat, err := ioutil.ReadFile(fileName)
127+
dat, err := os.ReadFile(fileName)
129128
if err != nil {
130129
klog.Warning("Skipping. Can't read file: ", err)
131130
continue

cmd/gpu_nfdhook/labeler_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package main
1616

1717
import (
18-
"io/ioutil"
1918
"os"
2019
"path"
2120
"reflect"
@@ -198,7 +197,7 @@ func getTestCases() []testcase {
198197
func (tc *testcase) createFiles(t *testing.T, sysfs, root string) {
199198
var err error
200199
for filename, body := range tc.capabilityFile {
201-
if err = ioutil.WriteFile(path.Join(root, filename), body, 0600); err != nil {
200+
if err = os.WriteFile(path.Join(root, filename), body, 0600); err != nil {
202201
t.Fatalf("Failed to create fake capability file: %+v", err)
203202
}
204203
}
@@ -208,14 +207,14 @@ func (tc *testcase) createFiles(t *testing.T, sysfs, root string) {
208207
}
209208
}
210209
for filename, body := range tc.sysfsfiles {
211-
if err := ioutil.WriteFile(path.Join(sysfs, filename), body, 0600); err != nil {
210+
if err := os.WriteFile(path.Join(sysfs, filename), body, 0600); err != nil {
212211
t.Fatalf("Failed to create fake vendor file: %+v", err)
213212
}
214213
}
215214
}
216215

217216
func TestLabeling(t *testing.T) {
218-
root, err := ioutil.TempDir("", "test_new_device_plugin")
217+
root, err := os.MkdirTemp("", "test_new_device_plugin")
219218
if err != nil {
220219
t.Fatalf("can't create temporary directory: %+v", err)
221220
}

cmd/gpu_plugin/gpu_plugin.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package main
1717
import (
1818
"flag"
1919
"fmt"
20-
"io/ioutil"
2120
"os"
2221
"path"
2322
"regexp"
@@ -112,7 +111,7 @@ func (dp *devicePlugin) isCompatibleDevice(name string) bool {
112111
klog.V(4).Info("Not compatible device: ", name)
113112
return false
114113
}
115-
dat, err := ioutil.ReadFile(path.Join(dp.sysfsDir, name, "device/vendor"))
114+
dat, err := os.ReadFile(path.Join(dp.sysfsDir, name, "device/vendor"))
116115
if err != nil {
117116
klog.Warning("Skipping. Can't read vendor file: ", err)
118117
return false
@@ -125,7 +124,7 @@ func (dp *devicePlugin) isCompatibleDevice(name string) bool {
125124
}
126125

127126
func (dp *devicePlugin) scan() (dpapi.DeviceTree, error) {
128-
files, err := ioutil.ReadDir(dp.sysfsDir)
127+
files, err := os.ReadDir(dp.sysfsDir)
129128
if err != nil {
130129
return nil, errors.Wrap(err, "Can't read sysfs folder")
131130
}
@@ -139,12 +138,12 @@ func (dp *devicePlugin) scan() (dpapi.DeviceTree, error) {
139138
continue
140139
}
141140

142-
drmFiles, err := ioutil.ReadDir(path.Join(dp.sysfsDir, f.Name(), "device/drm"))
141+
drmFiles, err := os.ReadDir(path.Join(dp.sysfsDir, f.Name(), "device/drm"))
143142
if err != nil {
144143
return nil, errors.Wrap(err, "Can't read device folder")
145144
}
146145

147-
dat, err := ioutil.ReadFile(path.Join(dp.sysfsDir, f.Name(), "device/sriov_numvfs"))
146+
dat, err := os.ReadFile(path.Join(dp.sysfsDir, f.Name(), "device/sriov_numvfs"))
148147
isPFwithVFs := (err == nil && strings.TrimSpace(string(dat)) != "0")
149148

150149
for _, drmFile := range drmFiles {

cmd/gpu_plugin/gpu_plugin_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package main
1616

1717
import (
1818
"flag"
19-
"io/ioutil"
2019
"os"
2120
"path"
2221
"testing"
@@ -59,7 +58,7 @@ func createTestFiles(root string, devfsdirs, sysfsdirs []string, sysfsfiles map[
5958
}
6059
}
6160
for filename, body := range sysfsfiles {
62-
if err := ioutil.WriteFile(path.Join(sysfs, filename), body, 0600); err != nil {
61+
if err := os.WriteFile(path.Join(sysfs, filename), body, 0600); err != nil {
6362
return "", "", errors.Wrap(err, "Failed to create fake vendor file")
6463
}
6564
}
@@ -186,7 +185,7 @@ func TestScan(t *testing.T) {
186185
tc.options.sharedDevNum = 1
187186
}
188187
t.Run(tc.name, func(t *testing.T) {
189-
root, err := ioutil.TempDir("", "test_new_device_plugin")
188+
root, err := os.MkdirTemp("", "test_new_device_plugin")
190189
if err != nil {
191190
t.Fatalf("can't create temporary directory: %+v", err)
192191
}

cmd/qat_plugin/dpdkdrv/dpdkdrv.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package dpdkdrv
1818
import (
1919
"bytes"
2020
"fmt"
21-
"io/ioutil"
21+
"os"
2222
"path/filepath"
2323
"strconv"
2424
"strings"
@@ -114,7 +114,7 @@ func (dp *DevicePlugin) getDpdkDevice(vfBdf string) (string, error) {
114114
switch dp.dpdkDriver {
115115
case igbUio:
116116
uioDirPath := filepath.Join(dp.pciDeviceDir, vfBdf, uioSuffix)
117-
files, err := ioutil.ReadDir(uioDirPath)
117+
files, err := os.ReadDir(uioDirPath)
118118
if err != nil {
119119
return "", err
120120
}
@@ -189,7 +189,7 @@ func (dp *DevicePlugin) getDpdkMounts(dpdkDeviceName string) []pluginapi.Mount {
189189
}
190190

191191
func (dp *DevicePlugin) getDeviceID(pciAddr string) (string, error) {
192-
devID, err := ioutil.ReadFile(filepath.Join(dp.pciDeviceDir, filepath.Clean(pciAddr), "device"))
192+
devID, err := os.ReadFile(filepath.Join(dp.pciDeviceDir, filepath.Clean(pciAddr), "device"))
193193
if err != nil {
194194
return "", errors.Wrapf(err, "Cannot obtain ID for the device %s", pciAddr)
195195
}
@@ -202,7 +202,7 @@ func (dp *DevicePlugin) bindDevice(vfBdf string) error {
202202
unbindDevicePath := filepath.Join(dp.pciDeviceDir, vfBdf, driverUnbindSuffix)
203203

204204
// Unbind from the kernel driver
205-
err := ioutil.WriteFile(unbindDevicePath, []byte(vfBdf), 0600)
205+
err := os.WriteFile(unbindDevicePath, []byte(vfBdf), 0600)
206206
if err != nil {
207207
return errors.Wrapf(err, "Unbinding from kernel driver failed for the device %s", vfBdf)
208208
}
@@ -212,7 +212,7 @@ func (dp *DevicePlugin) bindDevice(vfBdf string) error {
212212
}
213213
bindDevicePath := filepath.Join(dp.pciDriverDir, dp.dpdkDriver, newIDSuffix)
214214
//Bind to the the dpdk driver
215-
err = ioutil.WriteFile(bindDevicePath, []byte(vendorPrefix+vfdevID), 0600)
215+
err = os.WriteFile(bindDevicePath, []byte(vendorPrefix+vfdevID), 0600)
216216
if err != nil {
217217
return errors.Wrapf(err, "Binding to the DPDK driver failed for the device %s", vfBdf)
218218
}

0 commit comments

Comments
 (0)