github.com/MaximeAubanel/moby@v1.13.1/volume/volume_propagation_linux.go (about)

     1  // +build linux
     2  
     3  package volume
     4  
     5  import (
     6  	"strings"
     7  
     8  	mounttypes "github.com/docker/docker/api/types/mount"
     9  )
    10  
    11  // DefaultPropagationMode defines what propagation mode should be used by
    12  // default if user has not specified one explicitly.
    13  // propagation modes
    14  const DefaultPropagationMode = mounttypes.PropagationRPrivate
    15  
    16  var propagationModes = map[mounttypes.Propagation]bool{
    17  	mounttypes.PropagationPrivate:  true,
    18  	mounttypes.PropagationRPrivate: true,
    19  	mounttypes.PropagationSlave:    true,
    20  	mounttypes.PropagationRSlave:   true,
    21  	mounttypes.PropagationShared:   true,
    22  	mounttypes.PropagationRShared:  true,
    23  }
    24  
    25  // GetPropagation extracts and returns the mount propagation mode. If there
    26  // are no specifications, then by default it is "private".
    27  func GetPropagation(mode string) mounttypes.Propagation {
    28  	for _, o := range strings.Split(mode, ",") {
    29  		prop := mounttypes.Propagation(o)
    30  		if propagationModes[prop] {
    31  			return prop
    32  		}
    33  	}
    34  	return DefaultPropagationMode
    35  }
    36  
    37  // HasPropagation checks if there is a valid propagation mode present in
    38  // passed string. Returns true if a valid propagation mode specifier is
    39  // present, false otherwise.
    40  func HasPropagation(mode string) bool {
    41  	for _, o := range strings.Split(mode, ",") {
    42  		if propagationModes[mounttypes.Propagation(o)] {
    43  			return true
    44  		}
    45  	}
    46  	return false
    47  }