Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support the native snapshotter on FreeBSD #4858

Merged
merged 2 commits into from
Jan 11, 2021

Conversation

samuelkarp
Copy link
Member

This PR adds support for the native snapshotter on FreeBSD using FreeBSD nullfs.

The native snapshotter passes its test suite and is able to unpack an image for the freebsd/amd64 platform:

% freebsd-version
12.1-RELEASE-p4
% pwd
/home/sam/go/src/github.com/containerd/containerd/snapshots/native
% sudo go test -v -test.root .
[...trimmed output...]
--- PASS: TestNaive (0.01s)                                                                                                                                              
    --- PASS: TestNaive/Basic (0.03s)                                                                                                                                    
    --- PASS: TestNaive/128LayersMount (4.04s)                                                                                                                           
    --- PASS: TestNaive/RootPermission (0.01s)                                                                                                                           
    --- PASS: TestNaive/CloseTwice (0.00s)                                                                                                                               
    --- PASS: TestNaive/StatInWalk (0.01s)                                                                                                                               
    --- PASS: TestNaive/ViewReadonly (0.01s)                                                                                                                             
    --- SKIP: TestNaive/Rename (0.00s)                                                                                                                                   
    --- PASS: TestNaive/MoveFileFromLowerLayer (0.03s)                                                                                                                   
    --- PASS: TestNaive/DeletedFilesInChildSnapshot (0.03s)                                                                                                              
    --- PASS: TestNaive/RemoveIntermediateSnapshot (0.01s)                                                                                                               
    --- PASS: TestNaive/DirectoryPermissionOnCommit (0.04s)                                                                                                              
    --- PASS: TestNaive/Chown (0.03s)                                                                                                                                    
    --- PASS: TestNaive/RemoveDirectoryInLowerLayer (0.04s)                                                                                                              
    --- PASS: TestNaive/LayerFileupdate (3.85s)                                                                                                                          
    --- PASS: TestNaive/Walk (0.01s)                                                                                                                                     
    --- PASS: TestNaive/Remove (0.01s)                                                                                                                                   
    --- PASS: TestNaive/Update (0.03s)                                                                                                                                   
    --- PASS: TestNaive/PreareViewFailingtest (0.01s)                                                                                                                    
    --- PASS: TestNaive/TransitivityTest (0.01s)                                                                                                                         
    --- PASS: TestNaive/StatComitted (0.01s)                                                                                                                             
    --- PASS: TestNaive/StatActive (0.01s)                                                                                                                               
PASS
ok      github.com/containerd/containerd/snapshots/native       8.226s
% sudo ctr i ls
REF     TYPE                                    DIGEST                                                                  SIZE      PLATFORMS     LABELS 
freebsd application/vnd.oci.image.index.v1+json sha256:960c76846cd112e09032c88914458faee8d03c04b8260dfbc4da70b25227534a 236.8 MiB freebsd/amd64 -

Comment on lines +54 to +60
// cmd.CombinedOutput() may intermittently return ECHILD because of our signal handling in shim.
// See #4387 and wait(2).
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The behavior around ECHILD and retries is copied from mount_linux.go. There isn't (yet) a shim on FreeBSD, so I don't know if the logic is really necessary, but I left it in to start. If there's a preference to remove it, I'm happy to do so.

Comment on lines +92 to +98
case unix.EBUSY:
time.Sleep(50 * time.Millisecond)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, the behavior around EBUSY and retries is copied from mount_linux.go. Again, I don't know if the logic is really necessary, but I left it in to start. If there's a preference to remove it, I'm happy to do so.

// See #4387 and wait(2).
const retriesOnECHILD = 10
for i := 0; i < retriesOnECHILD; i++ {
cmd := exec.Command("mount", args...)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason not to use mount(2) syscall directly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the comment on line 37:

// The "syscall" and "golang.org/x/sys/unix" packages do not define a Mount
// function for FreeBSD, so instead we execute mount(8) and trust it to do
// the right thing

We could use syscall.RawSyscall but using mount(8) felt more reliable to me.


var (
// ErrNotImplementOnUnix is returned for methods that are not implemented
ErrNotImplementOnUnix = errors.New("not implemented under unix")
Copy link
Member

@kzys kzys Dec 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. You haven't used this constant on the PR.
  2. Would it be ErrNotImplemented or ErrNotImplementedOnPlatform? This might be useful for other non-Unix platforms.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This constant is pre-existing (was in mount/mount_unix.go) and used elsewhere in the codebase when compiled for FreeBSD (specifically in pkg/os/mount_unix.go). I left the name as-is to avoid touching other places in the codebase.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see. LGTM then.

@samuelkarp
Copy link
Member Author

samuelkarp force-pushed the samuelkarp:freebsd-native-snapshotter branch from 2fb04a0 to b667c15

Rebased on top of the current master; no changes to the diff.

@theopenlab-ci
Copy link

theopenlab-ci bot commented Dec 18, 2020

Build succeeded.

Signed-off-by: Samuel Karp <me@samuelkarp.com>
Signed-off-by: Samuel Karp <me@samuelkarp.com>
@samuelkarp
Copy link
Member Author

samuelkarp force-pushed the samuelkarp:freebsd-native-snapshotter branch from b667c15 to b624486

Rebased on top of the current master; no changes to the diff.

@theopenlab-ci
Copy link

theopenlab-ci bot commented Dec 23, 2020

Build succeeded.

@samuelkarp
Copy link
Member Author

I believe the devicemapper failures are unrelated to my change as the only change on Linux is a reordering of mount options for the native snapshotter.

@mxpv mxpv merged commit 04df60d into containerd:master Jan 11, 2021
@kzys kzys mentioned this pull request Mar 25, 2021
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants