Skip to content

Commit 7bd3be9

Browse files
alex-mateiaustinvazquez
authored andcommitted
Swap internal ioctl implementation with golang.org/x/sys
Replace internal LOOP_CONFIGURE ioctl implementation with IoctlLoopConfigure from sys Signed-off-by: Alexandru Matei <[email protected]> (cherry picked from commit c2dfae8) Signed-off-by: Austin Vazquez <[email protected]>
1 parent a0739dc commit 7bd3be9

1 file changed

Lines changed: 2 additions & 15 deletions

File tree

mount/losetup_linux.go

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ import (
2121
"fmt"
2222
"os"
2323
"strings"
24-
"syscall"
2524
"time"
26-
"unsafe"
2725

2826
kernel "github.com/containerd/containerd/contrib/seccomp/kernelversion"
2927
"github.com/containerd/containerd/pkg/randutil"
@@ -35,8 +33,6 @@ const (
3533
loopDevFormat = "/dev/loop%d"
3634

3735
ebusyString = "device or resource busy"
38-
39-
loopConfigureIoctl = 0x4c0a
4036
)
4137

4238
type LoopConfig struct {
@@ -46,15 +42,6 @@ type LoopConfig struct {
4642
Reserved [8]uint64
4743
}
4844

49-
func ioctlConfigure(fd int, value *LoopConfig) error {
50-
_, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), uintptr(loopConfigureIoctl), uintptr(unsafe.Pointer(value)))
51-
if err == 0 {
52-
return nil
53-
}
54-
55-
return err
56-
}
57-
5845
// LoopParams parameters to control loop device setup
5946
type LoopParams struct {
6047
// Loop device should forbid write
@@ -107,7 +94,7 @@ func setupLoopDev(backingFile, loopDev string, param LoopParams) (_ *os.File, re
10794

10895
fiveDotEight := kernel.KernelVersion{Kernel: 5, Major: 8}
10996
if ok, err := kernel.GreaterEqualThan(fiveDotEight); err == nil && ok {
110-
config := LoopConfig{
97+
config := unix.LoopConfig{
11198
Fd: uint32(back.Fd()),
11299
}
113100

@@ -124,7 +111,7 @@ func setupLoopDev(backingFile, loopDev string, param LoopParams) (_ *os.File, re
124111
config.Info.Flags |= unix.LO_FLAGS_DIRECT_IO
125112
}
126113

127-
if err := ioctlConfigure(int(loop.Fd()), &config); err != nil {
114+
if err := unix.IoctlLoopConfigure(int(loop.Fd()), &config); err != nil {
128115
return nil, fmt.Errorf("failed to configure loop device: %s: %w", loopDev, err)
129116
}
130117

0 commit comments

Comments
 (0)