Skip to content

Commit

Permalink
Merge pull request moby#23026 from rhatdan/mkdir
Browse files Browse the repository at this point in the history
Need to create bind mount volume if it does not exist.
  • Loading branch information
cpuguy83 committed Jun 3, 2016
2 parents 94b2d35 + 322cc99 commit 850031c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
6 changes: 0 additions & 6 deletions daemon/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/docker/docker/volume"
"github.com/docker/engine-api/types"
containertypes "github.com/docker/engine-api/types/container"
"github.com/opencontainers/runc/libcontainer/label"
)

var (
Expand Down Expand Up @@ -148,11 +147,6 @@ func (daemon *Daemon) registerMountPoints(container *container.Container, hostCo
}
}

if label.RelabelNeeded(bind.Mode) {
if err := label.Relabel(bind.Source, container.MountLabel, label.IsShared(bind.Mode)); err != nil {
return err
}
}
binds[bind.Destination] = true
mountPoints[bind.Destination] = bind
}
Expand Down
2 changes: 1 addition & 1 deletion daemon/volumes_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (daemon *Daemon) setupMounts(c *container.Container) ([]container.Mount, er
if err := daemon.lazyInitializeVolume(c.ID, m); err != nil {
return nil, err
}
path, err := m.Setup()
path, err := m.Setup(c.MountLabel)
if err != nil {
return nil, err
}
Expand Down
17 changes: 11 additions & 6 deletions volume/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
"fmt"
"os"
"strings"
"syscall"

"github.com/docker/docker/pkg/stringid"
"github.com/docker/docker/pkg/system"
"github.com/opencontainers/runc/libcontainer/label"
)

// DefaultDriverName is the driver name used for the driver
Expand Down Expand Up @@ -73,7 +75,7 @@ type MountPoint struct {

// Setup sets up a mount point by either mounting the volume if it is
// configured, or creating the source directory if supplied.
func (m *MountPoint) Setup() (string, error) {
func (m *MountPoint) Setup(mountLabel string) (string, error) {
if m.Volume != nil {
if m.ID == "" {
m.ID = stringid.GenerateNonCryptoID()
Expand All @@ -84,12 +86,15 @@ func (m *MountPoint) Setup() (string, error) {
return "", fmt.Errorf("Unable to setup mount point, neither source nor volume defined")
}
// system.MkdirAll() produces an error if m.Source exists and is a file (not a directory),
// so first check if the path does not exist
if _, err := os.Stat(m.Source); err != nil {
if !os.IsNotExist(err) {
return "", err
if err := system.MkdirAll(m.Source, 0755); err != nil {
if perr, ok := err.(*os.PathError); ok {
if perr.Err != syscall.ENOTDIR {
return "", err
}
}
if err := system.MkdirAll(m.Source, 0755); err != nil {
}
if label.RelabelNeeded(m.Mode) {
if err := label.Relabel(m.Source, mountLabel, label.IsShared(m.Mode)); err != nil {
return "", err
}
}
Expand Down

0 comments on commit 850031c

Please sign in to comment.