Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #86 from kolyshkin/18.09-backport-btrfs-prop
Browse files Browse the repository at this point in the history
[18.09] backport Fix mount propagation for btrfs
  • Loading branch information
andrewhsu authored Oct 13, 2018
2 parents 7c63f17 + fa8ac94 commit 4d0b8cc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
25 changes: 24 additions & 1 deletion daemon/graphdriver/btrfs/btrfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ import (
"github.com/docker/docker/daemon/graphdriver"
"github.com/docker/docker/pkg/containerfs"
"github.com/docker/docker/pkg/idtools"
"github.com/docker/docker/pkg/mount"
"github.com/docker/docker/pkg/parsers"
"github.com/docker/docker/pkg/system"
"github.com/docker/go-units"
"github.com/opencontainers/selinux/go-selinux/label"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
)
Expand Down Expand Up @@ -81,6 +83,15 @@ func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap
return nil, err
}

// For some reason shared mount propagation between a container
// and the host does not work for btrfs, and a remedy is to bind
// mount graphdriver home to itself (even without changing the
// propagation mode).
err = mount.MakeMount(home)
if err != nil {
return nil, errors.Wrapf(err, "failed to make %s a mount", home)
}

driver := &Driver{
home: home,
uidMaps: uidMaps,
Expand Down Expand Up @@ -158,7 +169,19 @@ func (d *Driver) GetMetadata(id string) (map[string]string, error) {

// Cleanup unmounts the home directory.
func (d *Driver) Cleanup() error {
return d.subvolDisableQuota()
err := d.subvolDisableQuota()
umountErr := mount.Unmount(d.home)

// in case we have two errors, prefer the one from disableQuota()
if err != nil {
return err
}

if umountErr != nil {
return errors.Wrapf(umountErr, "error unmounting %s", d.home)
}

return nil
}

func free(p *C.char) {
Expand Down
20 changes: 12 additions & 8 deletions pkg/mount/sharedsubtree_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,22 @@ func MakeRUnbindable(mountPoint string) error {
return ensureMountedAs(mountPoint, "runbindable")
}

func ensureMountedAs(mountPoint, options string) error {
mounted, err := Mounted(mountPoint)
// MakeMount ensures that the file or directory given is a mount point,
// bind mounting it to itself it case it is not.
func MakeMount(mnt string) error {
mounted, err := Mounted(mnt)
if err != nil {
return err
}

if !mounted {
if err := Mount(mountPoint, mountPoint, "none", "bind,rw"); err != nil {
return err
}
if mounted {
return nil
}
if _, err = Mounted(mountPoint); err != nil {

return Mount(mnt, mnt, "none", "bind")
}

func ensureMountedAs(mountPoint, options string) error {
if err := MakeMount(mountPoint); err != nil {
return err
}

Expand Down

0 comments on commit 4d0b8cc

Please sign in to comment.