mount: handle loopback mount#4178
Conversation
|
Build succeeded.
|
|
Would it be possible to reconcile this code with the other losetup code in containerd? https://github.com/containerd/containerd/search?q=losetup&unscoped_q=losetup provides some references. I didn't look into how similar they are. |
|
Build succeeded.
|
|
Build succeeded.
|
|
@stevvooe I've implemented the same losetup APIs needed by |
|
btw, the failed ci looks unrelated: |
|
We had a problem with unpinned dependencies breaking our protobuf checks in CI; if you can rebase on master HEAD, you should get a clean CI run now. Thanks! |
There was a problem hiding this comment.
What's the benefit of having this losetup code vs the old package ?
There was a problem hiding this comment.
The main purpose of the PR is to enable mount package to handle loopback mounts so that I can use it for the rawblock snapshotter. Maintainers also want to consolidate the two losetup implementation so I added the same APIs to replace the losetup command line wrappers. The main difference between them is calling the losetup binary or not.
There was a problem hiding this comment.
Sorry, I meant why not just reuse existing package. Potentially this one may be a lot harder to maintain and support, since Go is not the best fit for low level programming.
There was a problem hiding this comment.
Because it is not possible to create an autoclear loopback device with losetup command line. The workflow I want is:
- open the loop device
- set its backend and set the
autoclearflag - mount the loopback device with proper file system
- close the initial open file descriptor that we got in step 1
This is basically what you get with mount -o loop but it is not possible with the losetup command line. And the benefit is worthwhile -- we don't have to care about deleting the loopback device after unmounting the file system, nor if anything goes wrong in the middle before we mount the file system. The kernel takes care of cleaning up the loopback device once the last opener to it closes its open file descriptor.
There was a problem hiding this comment.
And we're already calling mount syscall instead of the mount binary in the mount package. Doing the same for loopback device follows the same philosophy.
There was a problem hiding this comment.
Because it is not possible to create an autoclear loopback device with losetup command line.
hm. As far as I understand losetup does that with --detach flag.
-d, --detach loopdev...
Detach the file or device associated with the specified loop
device(s). Note that since Linux v3.7 kernel uses "lazy device
destruction". The detach operation does not return EBUSY
error anymore if device is actively used by system, but it is
marked by autoclear flag and destroyed later.
There was a problem hiding this comment.
It is the detach action, not setting a loop device as autoclear. With autoclear, the loop device is detached automatically after it is unmounted -- that means we do not need to call losetup -d after unmounting a loop device.
If we use losetup command line, the workflow is like:
losetup -f <backing-file>- mount with a file system
- unmount the file system
losetup -d <loop-device>
Whereas with autoclear, we do:
mount -o loop <backing-file>alike withmountpackage- umount the file system
There was a problem hiding this comment.
Or do you mean that we should do the following?
losetup -f <backing-file>- mount with a file system
losetup -d <loop-device>- unmount the file system
That still doesn't look as neat as just doing
mount -o loop <backing-file>alike with mount package- umount the file system
|
Build succeeded.
|
|
@estesp Thanks for the hint. I've rebased on top of master. |
If a mount has specified `loop` option, we need to handle it on our own instead of passing it to the kernel. In such case, create a loopback device, attach the mount source to it, and mount the loopback device rather than the mount source. Signed-off-by: Peng Tao <[email protected]>
No need to use the private losetup command line wrapper package. The generic package provides the same functionality. Signed-off-by: Peng Tao <[email protected]>
|
Build succeeded.
|
zhsj
left a comment
There was a problem hiding this comment.
I think you don't need to define some magic values which are defined in golang.org/x/sys package.
| } | ||
|
|
||
| // struct loop_info64 in util-linux/include/loopdev.h | ||
| type loopInfo struct { |
There was a problem hiding this comment.
| _ [112]byte | ||
| } | ||
|
|
||
| func ioctl(fd, req, args uintptr) (uintptr, uintptr, error) { |
There was a problem hiding this comment.
maybe using Ioctl* family from golang.org/x/sys/unix?
| ioctlSetFd = 0x4C00 | ||
| ioctlClrFd = 0x4C01 | ||
| ioctlSetStatus64 = 0x4C04 | ||
| ioctlGetFree = 0x4C82 |
There was a problem hiding this comment.
unix.LOOP_SET_FD
unix.LOOP_CLR_FD
unix.LOOP_SET_STATUS64
unix.LOOP_CTL_GET_FREE
| //loFlagsUseAops = 2 | ||
| loFlagsAutoclear = 4 | ||
| //loFlagsPartScan = 8 | ||
| loFlagsDirectIO = 16 |
There was a problem hiding this comment.
unix.LO_FLAGS_READ_ONLY
unix.LO_FLAGS_AUTOCLEAR
unix.LO_FLAGS_PARTSCAN
unix.LO_FLAGS_DIRECT_IO
| //loFlagsPartScan = 8 | ||
| loFlagsDirectIO = 16 | ||
|
|
||
| ebusyString = "device or resource busy" |
There was a problem hiding this comment.
unix.EBUSY.Error() is this. But I think you don't need to compare the error string.
|
+1 for using existing routines from |
|
ping @bergwolf |
Signed-off-by: Maksym Pavlenko <[email protected]>
|
Carried in #4902 |
If a mount has specified
loopoption, we need to handle it on ourown instead of passing it to the kernel. In such case, create a
loopback device, attach the mount source to it, and mount the loopback
device rather than the mount source.
This is a spit from #3130 so that rawblock can be a non-builtin snapshotter.
/cc @dmcgowan @AkihiroSuda