Skip to content

Commit

Permalink
Merge pull request moby#44267 from thaJeztah/pkg_loopback_xsysunix
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelkarp authored Oct 9, 2022
2 parents c218211 + c7c02ee commit 9582dd1
Show file tree
Hide file tree
Showing 136 changed files with 6,870 additions and 1,847 deletions.
23 changes: 9 additions & 14 deletions pkg/loopback/attach_loopback.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import (
// Loopback related errors
var (
ErrAttachLoopbackDevice = errors.New("loopback attach failed")
ErrGetLoopbackBackingFile = errors.New("Unable to get loopback backing file")
ErrSetCapacity = errors.New("Unable set loopback capacity")
ErrGetLoopbackBackingFile = errors.New("unable to get loopback backing file")
ErrSetCapacity = errors.New("unable set loopback capacity")
)

func stringToLoopName(src string) [LoNameSize]uint8 {
var dst [LoNameSize]uint8
func stringToLoopName(src string) [unix.LO_NAME_SIZE]uint8 {
var dst [unix.LO_NAME_SIZE]uint8
copy(dst[:], src[:])
return dst
}
Expand All @@ -31,12 +31,7 @@ func getNextFreeLoopbackIndex() (int, error) {
return 0, err
}
defer f.Close()

index, err := ioctlLoopCtlGetFree(f.Fd())
if index < 0 {
index = 0
}
return index, err
return unix.IoctlRetInt(int(f.Fd()), unix.LOOP_CTL_GET_FREE)
}

func openNextAvailableLoopback(index int, sparseFile *os.File) (loopFile *os.File, err error) {
Expand Down Expand Up @@ -66,7 +61,7 @@ func openNextAvailableLoopback(index int, sparseFile *os.File) (loopFile *os.Fil
}

// Try to attach to the loop file
if err := ioctlLoopSetFd(loopFile.Fd(), sparseFile.Fd()); err != nil {
if err = unix.IoctlSetInt(int(loopFile.Fd()), unix.LOOP_SET_FD, int(sparseFile.Fd())); err != nil {
loopFile.Close()

// If the error is EBUSY, then try the next loopback
Expand Down Expand Up @@ -119,14 +114,14 @@ func AttachLoopDevice(sparseName string) (loop *os.File, err error) {
loopInfo := &unix.LoopInfo64{
File_name: stringToLoopName(loopFile.Name()),
Offset: 0,
Flags: LoFlagsAutoClear,
Flags: unix.LO_FLAGS_AUTOCLEAR,
}

if err := ioctlLoopSetStatus64(loopFile.Fd(), loopInfo); err != nil {
if err = unix.IoctlLoopSetStatus64(int(loopFile.Fd()), loopInfo); err != nil {
logrus.Errorf("Cannot set up loopback device info: %s", err)

// If the call failed, then free the loopback device
if err := ioctlLoopClrFd(loopFile.Fd()); err != nil {
if err = unix.IoctlSetInt(int(loopFile.Fd()), unix.LOOP_CLR_FD, 0); err != nil {
logrus.Error("Error while cleaning up the loopback device")
}
loopFile.Close()
Expand Down
53 changes: 0 additions & 53 deletions pkg/loopback/ioctl.go

This file was deleted.

25 changes: 0 additions & 25 deletions pkg/loopback/loop_wrapper.go

This file was deleted.

7 changes: 3 additions & 4 deletions pkg/loopback/loopback.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func getLoopbackBackingFile(file *os.File) (uint64, uint64, error) {
loopInfo, err := ioctlLoopGetStatus64(file.Fd())
loopInfo, err := unix.IoctlLoopGetStatus64(int(file.Fd()))
if err != nil {
logrus.Errorf("Error get loopback backing file: %s", err)
return 0, 0, ErrGetLoopbackBackingFile
Expand All @@ -22,7 +22,7 @@ func getLoopbackBackingFile(file *os.File) (uint64, uint64, error) {

// SetCapacity reloads the size for the loopback device.
func SetCapacity(file *os.File) error {
if err := ioctlLoopSetCapacity(file.Fd(), 0); err != nil {
if err := unix.IoctlSetInt(int(file.Fd()), unix.LOOP_SET_CAPACITY, 0); err != nil {
logrus.Errorf("Error loopbackSetCapacity: %s", err)
return ErrSetCapacity
}
Expand All @@ -38,8 +38,7 @@ func FindLoopDeviceFor(file *os.File) *os.File {
return nil
}
targetInode := stat.Ino
// the type is 32bit on mips
targetDevice := uint64(stat.Dev) //nolint: unconvert
targetDevice := uint64(stat.Dev) //nolint: unconvert // the type is 32bit on mips

for i := 0; true; i++ {
path := fmt.Sprintf("/dev/loop%d", i)
Expand Down
2 changes: 1 addition & 1 deletion vendor.mod
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ require (
go.etcd.io/bbolt v1.3.6
golang.org/x/net v0.0.0-20220906165146-f3363e06e74c
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10
golang.org/x/sys v0.0.0-20221006211917-84dc82d7e875
golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11
google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa
google.golang.org/grpc v1.45.0
Expand Down
3 changes: 2 additions & 1 deletion vendor.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1419,8 +1419,9 @@ golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 h1:WIoqL4EROvwiPdUtaip4VcDdpZ4kha7wBWZrbVKCIZg=
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20221006211917-84dc82d7e875 h1:AzgQNqF+FKwyQ5LbVrVqOcuuFB67N47F9+htZYH0wFM=
golang.org/x/sys v0.0.0-20221006211917-84dc82d7e875/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
Expand Down
12 changes: 6 additions & 6 deletions vendor/golang.org/x/sys/cpu/cpu_arm64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions vendor/golang.org/x/sys/cpu/cpu_openbsd_arm64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions vendor/golang.org/x/sys/cpu/cpu_openbsd_arm64.s

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vendor/golang.org/x/sys/cpu/cpu_other_arm64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 17 additions & 3 deletions vendor/golang.org/x/sys/unix/ioctl_linux.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9582dd1

Please sign in to comment.