Commit Graph

80 Commits

Author SHA1 Message Date
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
Georgi Sabev
c0f0b21314 Apply PR feedback
* Rootfs dir is created during container creation not during bundle
  creation
* Add support for v2
* UnmountAll is a no-op when the path to unmount (i.e. the rootfs dir)
  does not exist or is invalid

Co-authored-by: Danail Branekov <danailster@gmail.com>
Signed-off-by: Georgi Sabev <georgethebeatle@gmail.com>
2019-04-04 18:40:30 +03:00
Sebastiaan van Stijn
adc4fa217b
Use pkg/errors for all errors
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-04-02 14:13:23 +02:00
Sebastiaan van Stijn
c22effb168
fix parseInfoFile does not handle spaces in filenames
`/proc/self/mountinfo` uses `\040` for spaces, however, `parseInfoFile()`
did not decode those spaces in paths, therefore attempting to use `\040`
as a literal part of the path.

This patch un-quotes the `root` and `mount point` fields to fix
situations where paths contain spaces.

Note that the `mount source` field is not modified, given that
this field is documented (man `PROC(5)`) as:

    filesystem-specific information or "none"

Which I interpreted as "the format in this field is undefined".

Reported-by: Daniil Yaroslavtsev <daniilyar@users.noreply.github.com>
Reported-by: Nathan Ringo <remexre@gmail.com>
Based-on-patch-by: Diego Becciolini <itizir@users.noreply.github.com>
Based-on-patch-by: Sergei Utinski <sergei-utinski@users.noreply.github.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-04-02 13:06:32 +02:00
zhangyue
996c60616a fix: fix error info start capitalized
Signed-off-by: zhangyue <zy675793960@yeah.net>
2018-11-28 15:26:16 +08:00
Ivan Markin
0828b7aa96 mount: add support for OpenBSD
Signed-off-by: Ivan Markin <sw@nogoegst.net>
2018-10-12 22:24:13 +00:00
Akihiro Suda
5349fa31df remove pkg/testutil/loopback_linux.go and use continuity/testutil/loopback
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2018-10-02 13:12:25 +09:00
Justin Terry (VM)
0110b3c0bc Introduce the Windows lcow diff/snaphotter
Implements the Windows lcow differ/snapshotter responsible for managing
the creation and lifetime of lcow containers on Windows.

Signed-off-by: Justin Terry (VM) <juterry@microsoft.com>
2018-08-28 13:51:04 -07:00
Wei Fu
67b54c6670 Support >= 128 layers in overlayfs snapshots
Auto-detect longest common dir in lowerdir option and compact it if the
option size is hitting one page size. If does, Use chdir + CLONE to do
mount thing to avoid hitting one page argument buffer in linux kernel
mount.

Signed-off-by: Wei Fu <fhfuwei@163.com>
2018-08-07 10:59:36 +08:00
Michael Crosby
0105959c3d Don't prevent boot on temp cleanup
Fixes #2462
Fixes #2455

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2018-07-13 16:07:17 -04:00
Vincent Demeester
832b05ae67
Update tests to use gotest.tools angel
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2018-06-08 21:02:01 +02:00
Michael Crosby
009ba4d797 Move testutils to pkg
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2018-05-22 17:08:38 -04:00
Derek McGowan
6eee2a0785
Merge pull request #2324 from kolyshkin/mountinfo
mount/mountinfo_linux: parser speed up
2018-05-07 13:46:39 -07:00
Kir Kolyshkin
8eec9259e6 mount/mountinfo_linux: parser speed up
The mountinfo parser implemented via `fmt.Sscanf()` is slower than the one
using `strings.Split()` and `strconv.Atoi()`. This rewrite helps to speed it
up to a factor of 8x, here is a result from `go bench`:

> BenchmarkParsingScanf-4            300          22294112 ns/op
> BenchmarkParsingSplit-4           3000           2780703 ns/op

I tried other approaches, such as using `fmt.Sscanf()` for the first
three (integer) fields and `strings.Split()` for the rest, but it slows
things down considerably:

> BenchmarkParsingMixed-4           1000           8827058 ns/op

Note the old code uses `fmt.Sscanf` first, then a linear search for the
'-' field, then a split for the last 3 fields. The new code relies
on a single split.

One other thing is, the new code is more future proof as it skips
extra optional fields before the separator (currently there are none).

I have also added more comments to aid in future development.

Finally, the test data is fixed to not have white space before
the first field.

Based on a similar change in Moby,
 https://github.com/moby/moby/pull/36091

[v2: remove no-op break statement to silence staticcheck]
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2018-05-07 11:38:37 -07:00