Commit Graph

93 Commits

Author SHA1 Message Date
Akihiro Suda
d8b68e3ccc
Stop using math/rand.Read and rand.Seed (deprecated in Go 1.20)
From golangci-lint:

> SA1019: rand.Read has been deprecated since Go 1.20 because it
>shouldn't be used: For almost all use cases, crypto/rand.Read is more
>appropriate. (staticcheck)

> SA1019: rand.Seed has been deprecated since Go 1.20 and an alternative
>has been available since Go 1.0: Programs that call Seed and then expect
>a specific sequence of results from the global random source (using
>functions such as Int) can be broken when a dependency changes how
>much it consumes from the global random source. To avoid such breakages,
>programs that need a specific result sequence should use
>NewRand(NewSource(seed)) to obtain a random generator that other
>packages cannot access. (staticcheck)

See also:

- https://pkg.go.dev/math/rand@go1.20#Read
- https://pkg.go.dev/math/rand@go1.20#Seed

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2023-02-16 03:50:23 +09:00
Kohei Tokunaga
eeab052425 Make mount.UnmountRecursive compatible to mount.UnmountAll
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
2023-01-31 22:07:44 +09:00
Edgar Lee
34d5878185 Use mount.Target to specify subdirectory of rootfs mount
- Add Target to mount.Mount.
- Add UnmountMounts to unmount a list of mounts in reverse order.
- Add UnmountRecursive to unmount deepest mount first for a given target, using
moby/sys/mountinfo.

Signed-off-by: Edgar Lee <edgarhinshunlee@gmail.com>
2023-01-27 09:51:58 +08:00
Maksym Pavlenko
3bc8fc4d30 Cleanup build constraints
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2022-12-08 09:36:20 -08:00
Brian Goff
a24ef09937 Replace mount fork hack with CLONE_FS
This change spins up a new goroutine, locks it to a thread, then
unshares CLONE_FS which allows us to `Chdir` from inside the thread
without affecting the rest of the program.

The thread is no longer usable after unshare so it leaves the thread
locked to prevent go from returning the thread to the thread pool.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2022-11-03 22:30:35 +00:00
Phil Estes
455127859b
Merge pull request #7342 from tklauser/losetup-unix
Use ioctl helpers from x/sys/unix
2022-08-30 12:32:20 -04:00
Tobias Klauser
3cc3d8a560
mount: use ioctl helpers from x/sys/unix
Use the IoctlRetInt, IoctlSetInt and IoctlLoopSetStatus64 helper
functions defined in the golang.org/x/sys/unix package instead of
manually wrapping these using a locally defined ioctl function.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
2022-08-30 10:38:29 +02:00
Sebastiaan van Stijn
9ae2cc3a8a
mount: remove unused ErrNotImplementOnWindows
This error was added in c5843b7615, but no longer
used since a5a9f91832, which implemented Windows
support.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-08-29 10:55:04 +02:00
Maksym Pavlenko
871b6b6a9f Use testify
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2022-04-01 18:17:58 -07:00
Eng Zer Jun
18ec2761c0
test: use T.TempDir to create temporary test directory
The directory created by `T.TempDir` is automatically removed when the
test and all its subtests complete.

Reference: https://pkg.go.dev/testing#T.TempDir
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-03-15 14:03:50 +08:00
Shengjing Zhu
d28981d48e Fix build with gccgo
gccgo changes the mangling scheme
b483d0e0a2

The change is available in gcc-11, which is the least version that
implements go1.16.

Signed-off-by: Shengjing Zhu <zhsj@debian.org>
2022-02-22 02:31:58 +08:00
Derek McGowan
8816006d1e
Fix followup items from errors replacement
Signed-off-by: Derek McGowan <derek@mcg.dev>
2022-01-07 12:16:00 -08:00
haoyun
bbe46b8c43 feat: replace github.com/pkg/errors to errors
Signed-off-by: haoyun <yun.hao@daocloud.io>
Co-authored-by: zounengren <zouyee1989@gmail.com>
2022-01-07 10:27:03 +08:00
haoyun
c0d07094be feat: Errorf usage
Signed-off-by: haoyun <yun.hao@daocloud.io>
2021-12-13 14:31:53 +08:00
Michael Crosby
7b8a697f28
Merge pull request #6034 from claudiubelu/windows/fixes-image-volume
Fixes Windows containers with image volumes
2021-10-07 11:50:01 -04:00
Claudiu Belu
791e175c79 Windows: Fixes Windows containers with image volumes
Currently, there are few issues that preventing containers
with image volumes to properly start on Windows.

- Unlike the Linux implementation, the Container volume mount paths
  were not created if they didn't exist. Those paths are now created.

- while copying the image volume contents to the container volume,
  the layers were not properly deactivated, which means that the
  container can't start since those layers are still open. The layers
  are now properly deactivated, allowing the container to start.

- even if the above issue didn't exist, the Windows implementation of
  mount/Mount.Mount deactivates the layers, which wouldn't allow us
  to copy files from them. The layers are now deactivated after we've
  copied the necessary files from them.

- the target argument of the Windows implementation of mount/Mount.Mount
  was unused, which means that folder was always empty. We're now
  symlinking the Layer Mount Path into the target folder.

- hcsshim needs its Container Mount Paths to be properly formated, to be
  prefixed by C:. This was an issue for Volumes defined with Linux-like
  paths (e.g.: /test_dir). filepath.Abs solves this issue.

Signed-off-by: Claudiu Belu <cbelu@cloudbasesolutions.com>
2021-10-01 09:02:18 +00:00
Eng Zer Jun
50da673592
refactor: move from io/ioutil to io and os package
The io/ioutil package has been deprecated as of Go 1.16, see
https://golang.org/doc/go1.16#ioutil. This commit replaces the existing
io/ioutil functions with their new definitions in io and os packages.

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2021-09-21 09:50:38 +08:00
Sebastiaan van Stijn
2ac9968401
replace uses of os/exec with golang.org/x/sys/execabs
Go 1.15.7 contained a security fix for CVE-2021-3115, which allowed arbitrary
code to be executed at build time when using cgo on Windows. This issue also
affects Unix users who have “.” listed explicitly in their PATH and are running
“go get” outside of a module or with module mode disabled.

This issue is not limited to the go command itself, and can also affect binaries
that use `os.Command`, `os.LookPath`, etc.

From the related blogpost (ttps://blog.golang.org/path-security):

> Are your own programs affected?
>
> If you use exec.LookPath or exec.Command in your own programs, you only need to
> be concerned if you (or your users) run your program in a directory with untrusted
> contents. If so, then a subprocess could be started using an executable from dot
> instead of from a system directory. (Again, using an executable from dot happens
> always on Windows and only with uncommon PATH settings on Unix.)
>
> If you are concerned, then we’ve published the more restricted variant of os/exec
> as golang.org/x/sys/execabs. You can use it in your program by simply replacing

This patch replaces all uses of `os/exec` with `golang.org/x/sys/execabs`. While
some uses of `os/exec` should not be problematic (e.g. part of tests), it is
probably good to be consistent, in case code gets moved around.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-08-25 18:11:09 +02:00
Akihiro Suda
d3aa7ee9f0
Run go fmt with Go 1.17
The new `go fmt` adds `//go:build` lines (https://golang.org/doc/go1.17#tools).

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2021-08-22 09:31:50 +09:00
Derek McGowan
6f027e38a8
Remove redundant build tags
Remove build tags which are already implied by the name of the file.
Ensures build tags are used consistently

Signed-off-by: Derek McGowan <derek@mcg.dev>
2021-08-05 22:27:46 -07:00
Maksym Pavlenko
7917da764c Change default directories on Darwin
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2021-08-04 14:12:32 -07:00
Sebastiaan van Stijn
a964cf0cc4
un-export mount.FMountat
It's only used internally, so we can un-export this utility until
it is needed elsewhere.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-06-23 18:14:53 +02:00
Sebastiaan van Stijn
21f532d518
move sys.FMountat() into mount package
It's the only location this is used, so might as well move it
into that package. I could not find external users of this utility,
so not adding an alias / deprecation.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-06-23 18:14:30 +02:00
Derek McGowan
35eeb24a17
Fix exported comments enforcer in CI
Add comments where missing and fix incorrect comments

Signed-off-by: Derek McGowan <derek@mcg.dev>
2021-03-12 08:47:05 -08:00
Shiming Zhang
5e4acc0436 Fix file is not closed
Signed-off-by: Shiming Zhang <wzshiming@foxmail.com>
2021-02-18 21:38:44 +08:00
Kazuyoshi Kato
05a2e280ac mount: make setupLoop() work with with Autoclear
setupLoop()'s Autoclear (LO_FLAGS_AUTOCLEAR) will destruct the
loopback device when all associated file descriptors are closed.

However this behavior didn't work before since setupLoop() was
returning a file name. The looppack device was destructed at
the end of the function when LoopParams had Autoclear = true.

Fixes #4969.

Signed-off-by: Kazuyoshi Kato <katokazu@amazon.com>
2021-02-04 11:04:04 -08:00
Phil Estes
e62d03b61a
Merge pull request #4578 from thaJeztah/use_moby_sys
mount: replace mountinfo handling with moby/sys/mountinfo
2021-01-12 11:33:28 -05:00
Maksym Pavlenko
04df60d106
Merge pull request #4858 from samuelkarp/freebsd-native-snapshotter
Support the native snapshotter on FreeBSD
2021-01-11 09:52:56 -08:00
Sebastiaan van Stijn
7572919201
mount: remove remaining uses of mount.Self()
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-01-08 17:31:59 +01:00
Sebastiaan van Stijn
474abe5723
mount: remove unused mount.PID()
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-01-08 17:31:57 +01:00
Sebastiaan van Stijn
f6a0ec7c0a
mount.CleanupTempMounts() use github.com/moby/sys/mountinfo
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-01-08 17:31:55 +01:00
Sebastiaan van Stijn
43578a9d6e
mount: mount.PID(), mount.Self(): change signature to return pointers
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-01-08 17:31:53 +01:00
Sebastiaan van Stijn
fb464b94d3
mount: replace mountinfo handling with moby/sys/mountinfo
Trying to reduce duplicated effort in maintaining a mountinfo
parser, this patch replaces the local implementation with the
implementation in github.com/moby/sys, which is actively maintained
and contains various optimizations.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-01-08 17:31:50 +01:00
Maksym Pavlenko
eb1649225d Refactor loseup test
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2021-01-05 10:06:02 -08:00
Maksym Pavlenko
c5fa0298c1 Address loop dev PR comments #4178
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2021-01-04 10:44:29 -08:00
Peng Tao
9e42070169 mount: handle loopback mount
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 <bergwolf@hyper.sh>
2021-01-04 10:14:55 -08:00
Samuel Karp
d6baafa75f
mount: basic support for FreeBSD
Signed-off-by: Samuel Karp <me@samuelkarp.com>
2020-12-22 21:26:04 -08:00
Sebastiaan van Stijn
48f64a18be
mount: extract FUSE unmounting to a function
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-10-01 17:29:40 +02:00
Sebastiaan van Stijn
5b13dcc73a
mount.isFUSE(): remove unused error return
The error itself was unused, so may as well remove it.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-09-28 21:43:21 +02:00
Akihiro Suda
403dc83a29
mount: retry executing the helper binary on ECHILD
`exec.CombinedOutput()` intermittently returns `ECHILD` due to our
signal handling.

`wait(2)`: https://man7.org/linux/man-pages/man2/wait.2.html

> ECHILD (for waitpid() or waitid()) The process specified by pid
>   (waitpid()) or idtype and id (waitid()) does not exist or is
>   not a child of the calling process.  (This can happen for
>   one's own child if the action for SIGCHLD is set to SIG_IGN.
>   See also the Linux Notes section about threads.)

Fix #4387

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2020-07-22 14:24:08 +09:00
Johannes Frey
ee734e867a
Add test case with backticks
Signed-off-by: Johannes Frey <me@johannes-frey.de>
2020-06-18 08:37:31 +02:00
Johannes Frey
8897e15203
Add more test cases with single quotes
Signed-off-by: Johannes Frey <me@johannes-frey.de>
2020-06-16 13:06:54 +02:00
Johannes Frey
cb91b1724d
Add testcase containing mountpoint with escaped backslash
Signed-off-by: Johannes Frey <me@johannes-frey.de>
2020-06-16 13:06:54 +02:00
Johannes Frey
87f9fdb065
Cope with double quotes in Linux Mountinfo
Signed-off-by: Johannes Frey <me@johannes-frey.de>
2020-06-16 13:06:36 +02:00
Kir Kolyshkin
6e638ad27a Nit: fix use of bufio.Scanner.Err
The Err() method should be called after the Scan() loop, not inside it.

Found by: git grep -A3 -F '.Scan()'

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-03-11 19:36:21 -07:00
Sebastiaan van Stijn
f2edc6f164
vendor: update gotest.tools v3.0.2
full diff: https://github.com/gotestyourself/gotest.tools/compare/v2.3.0...v3.0.2

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-02-28 17:47:20 +01:00
Akihiro Suda
e739314ed4 mount: support FUSE helper
When m.Type starts with either `fuse.` or `fuse3`, the
mount helper binary `mount.fuse` or `mount.fuse3` is executed.

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2020-01-01 04:16:30 +09:00
Derek McGowan
5a0ff41c81
Update continuity vendor
Pulls in copy and fstest changes

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2019-08-16 15:49:47 -07:00
Michael Crosby
19af235051
Merge pull request #3148 from masters-of-cats/wip-rootless-containerd
Skip rootfs unmount when no mounts are provided
2019-05-07 10:39:02 -04:00
Georgi Sabev
ae5ca8177d Refactor mount path check and add comments
Co-authored-by: Danail Branekov <danailster@gmail.com>
Signed-off-by: Georgi Sabev <georgethebeatle@gmail.com>
2019-04-09 16:20:05 +03:00