Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
- Divya Cote <divya.cote@gmail.com>
- Eduardo Arango <eduardo@sylabs.io>, <arangogutierrez@gmail.com>
- Egbert Eich <eich@suse.com>
- Eric Müller <mueller@kip.uni-heidelberg.de>
- Felix Abecassis <fabecassis@nvidia.com>
- Geoffroy Vallee <geoffroy@sylabs.io>, <geoffroy.vallee@gmail.com>
- George Hartzell <hartzell@alerce.com>
Expand Down
20 changes: 18 additions & 2 deletions pkg/util/loop/loop_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"os"
"syscall"
"time"
"unsafe"

"github.com/sylabs/singularity/pkg/util/fs/lock"
Expand Down Expand Up @@ -101,8 +102,23 @@ func (loop *Device) AttachFromFile(image *os.File, mode int, number *int) error
return fmt.Errorf("failed to set close-on-exec on loop device %s: %s", path, err.Error())
}

if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(loopFd), CmdSetStatus64, uintptr(unsafe.Pointer(loop.Info))); err != 0 {
return fmt.Errorf("failed to set loop flags on loop device: %s", syscall.Errno(err))
maxRetries := 5
for i := 0; i < maxRetries; i++ {
if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(loopFd), CmdSetStatus64, uintptr(unsafe.Pointer(loop.Info))); err != 0 {
if err == syscall.EAGAIN && i < maxRetries-1 {
// with changes introduces in https://github.com/torvalds/linux/commit/5db470e229e22b7eda6e23b5566e532c96fb5bc3
// loop_set_status() can temporarily fail with EAGAIN -> sleep and try again
// (cf. https://github.com/karelzak/util-linux/blob/dab1303287b7ebe30b57ccc78591070dad0a85ea/lib/loopdev.c#L1355)
time.Sleep(250 * time.Millisecond)
continue
}
// clear associated file descriptor to release the loop device,
// best-effort here without error checking because we need the
// error from previous ioctl call
syscall.Syscall(syscall.SYS_IOCTL, uintptr(loopFd), CmdClrFd, 0)
return fmt.Errorf("failed to set loop flags on loop device: %s", syscall.Errno(err))
}
break
}

return nil
Expand Down