summaryrefslogtreecommitdiff
path: root/volume
diff options
context:
space:
mode:
authorVincent Demeester <vincent@sbr.pm>2018-04-09 10:09:30 +0200
committerSebastiaan van Stijn <github@gone.nl>2018-12-22 16:02:50 +0100
commitd5b271c155926057d33c2128ff57e49274455813 (patch)
tree049505479c1a0065d273f393a033d706ca90105d /volume
parent2cb26cfe9cbf8a64c5046c74d65f4528b22e67f4 (diff)
downloaddocker-d5b271c155926057d33c2128ff57e49274455813.tar.gz
add check for local volume option
Description: When using local volume option such as size=10G, type=tmpfs, if we provide wrong options, we could create volume successfully. But when we are ready to use it, it will fail to start container by failing to mount the local volume(invalid option). We should check the options at when we create it. Signed-off-by: Wentao Zhang <zhangwentao234@huawei.com> Signed-off-by: Vincent Demeester <vincent@sbr.pm> Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Diffstat (limited to 'volume')
-rw-r--r--volume/local/local.go8
-rw-r--r--volume/local/local_unix.go4
-rw-r--r--volume/local/local_windows.go5
3 files changed, 16 insertions, 1 deletions
diff --git a/volume/local/local.go b/volume/local/local.go
index d3119cb2ff..1c844cf0e3 100644
--- a/volume/local/local.go
+++ b/volume/local/local.go
@@ -353,11 +353,19 @@ func (v *localVolume) unmount() error {
}
func validateOpts(opts map[string]string) error {
+ if len(opts) == 0 {
+ return nil
+ }
for opt := range opts {
if !validOpts[opt] {
return validationError(fmt.Sprintf("invalid option key: %q", opt))
}
}
+ for opt := range mandatoryOpts {
+ if _, ok := opts[opt]; !ok {
+ return errdefs.InvalidParameter(errors.Errorf("missing required option: %q", opt))
+ }
+ }
return nil
}
diff --git a/volume/local/local_unix.go b/volume/local/local_unix.go
index 5ee2ed894b..1d25c330da 100644
--- a/volume/local/local_unix.go
+++ b/volume/local/local_unix.go
@@ -27,6 +27,10 @@ var (
"o": true, // generic mount options
"device": true, // device to mount from
}
+ mandatoryOpts = map[string]struct{}{
+ "device": {},
+ "type": {},
+ }
)
type optsConfig struct {
diff --git a/volume/local/local_windows.go b/volume/local/local_windows.go
index d96fc0f594..5748681bb0 100644
--- a/volume/local/local_windows.go
+++ b/volume/local/local_windows.go
@@ -14,7 +14,10 @@ import (
type optsConfig struct{}
-var validOpts map[string]bool
+var (
+ validOpts map[string]bool
+ mandatoryOpts map[string]struct{}
+)
// scopedPath verifies that the path where the volume is located
// is under Docker's root and the valid local paths.