- comments on exported values
- constant string replaced by constant reference
- unexport implementation details of VolumeDriver 'local'
- add fixed packages to linter list
Signed-off-by: Morgan Bauer <mbauer@us.ibm.com>
| ... | ... |
@@ -4,11 +4,13 @@ package volumedrivers |
| 4 | 4 |
|
| 5 | 5 |
import "github.com/docker/docker/volume" |
| 6 | 6 |
|
| 7 |
+// NewVolumeDriver returns a driver has the given name mapped on the given client. |
|
| 7 | 8 |
func NewVolumeDriver(name string, c client) volume.Driver {
|
| 8 | 9 |
proxy := &volumeDriverProxy{c}
|
| 9 | 10 |
return &volumeDriverAdapter{name, proxy}
|
| 10 | 11 |
} |
| 11 | 12 |
|
| 13 |
+// VolumeDriver defines the available functions that volume plugins must implement. |
|
| 12 | 14 |
type VolumeDriver interface {
|
| 13 | 15 |
// Create a volume with the given name |
| 14 | 16 |
Create(name string) (err error) |
| ... | ... |
@@ -18,6 +18,8 @@ type driverExtpoint struct {
|
| 18 | 18 |
sync.Mutex |
| 19 | 19 |
} |
| 20 | 20 |
|
| 21 |
+// Register associates the given driver to the given name, checking if |
|
| 22 |
+// the name is already associated |
|
| 21 | 23 |
func Register(extension volume.Driver, name string) bool {
|
| 22 | 24 |
drivers.Lock() |
| 23 | 25 |
defer drivers.Unlock() |
| ... | ... |
@@ -32,6 +34,7 @@ func Register(extension volume.Driver, name string) bool {
|
| 32 | 32 |
return true |
| 33 | 33 |
} |
| 34 | 34 |
|
| 35 |
+// Unregister dissociates the name from it's driver, if the association exists. |
|
| 35 | 36 |
func Unregister(name string) bool {
|
| 36 | 37 |
drivers.Lock() |
| 37 | 38 |
defer drivers.Unlock() |
| ... | ... |
@@ -43,6 +46,9 @@ func Unregister(name string) bool {
|
| 43 | 43 |
return true |
| 44 | 44 |
} |
| 45 | 45 |
|
| 46 |
+// Lookup returns the driver associated with the given name. If a |
|
| 47 |
+// driver with the given name has not been registered it checks if |
|
| 48 |
+// there is a VolumeDriver plugin available with the given name. |
|
| 46 | 49 |
func Lookup(name string) (volume.Driver, error) {
|
| 47 | 50 |
drivers.Lock() |
| 48 | 51 |
defer drivers.Unlock() |
| ... | ... |
@@ -1,3 +1,6 @@ |
| 1 |
+// Package local provides the default implementation for volumes. It |
|
| 2 |
+// is used to mount data volume containers and directories local to |
|
| 3 |
+// the host server. |
|
| 1 | 4 |
package local |
| 2 | 5 |
|
| 3 | 6 |
import ( |
| ... | ... |
@@ -13,7 +16,7 @@ import ( |
| 13 | 13 |
) |
| 14 | 14 |
|
| 15 | 15 |
// VolumeDataPathName is the name of the directory where the volume data is stored. |
| 16 |
-// It uses a very distintive name to avoid colissions migrating data between |
|
| 16 |
+// It uses a very distintive name to avoid collisions migrating data between |
|
| 17 | 17 |
// Docker versions. |
| 18 | 18 |
const ( |
| 19 | 19 |
VolumeDataPathName = "_data" |
| ... | ... |
@@ -22,6 +25,9 @@ const ( |
| 22 | 22 |
|
| 23 | 23 |
var oldVfsDir = filepath.Join("vfs", "dir")
|
| 24 | 24 |
|
| 25 |
+// New instantiates a new Root instance with the provided scope. Scope |
|
| 26 |
+// is the base path that the Root instance uses to store its |
|
| 27 |
+// volumes. The base path is created here if it does not exist. |
|
| 25 | 28 |
func New(scope string) (*Root, error) {
|
| 26 | 29 |
rootDirectory := filepath.Join(scope, volumesPathName) |
| 27 | 30 |
|
| ... | ... |
@@ -32,7 +38,7 @@ func New(scope string) (*Root, error) {
|
| 32 | 32 |
r := &Root{
|
| 33 | 33 |
scope: scope, |
| 34 | 34 |
path: rootDirectory, |
| 35 |
- volumes: make(map[string]*Volume), |
|
| 35 |
+ volumes: make(map[string]*localVolume), |
|
| 36 | 36 |
} |
| 37 | 37 |
|
| 38 | 38 |
dirs, err := ioutil.ReadDir(rootDirectory) |
| ... | ... |
@@ -42,7 +48,7 @@ func New(scope string) (*Root, error) {
|
| 42 | 42 |
|
| 43 | 43 |
for _, d := range dirs {
|
| 44 | 44 |
name := filepath.Base(d.Name()) |
| 45 |
- r.volumes[name] = &Volume{
|
|
| 45 |
+ r.volumes[name] = &localVolume{
|
|
| 46 | 46 |
driverName: r.Name(), |
| 47 | 47 |
name: name, |
| 48 | 48 |
path: r.DataPath(name), |
| ... | ... |
@@ -51,21 +57,29 @@ func New(scope string) (*Root, error) {
|
| 51 | 51 |
return r, nil |
| 52 | 52 |
} |
| 53 | 53 |
|
| 54 |
+// Root implements the Driver interface for the volume package and |
|
| 55 |
+// manages the creation/removal of volumes. It uses only standard vfs |
|
| 56 |
+// commands to create/remove dirs within its provided scope. |
|
| 54 | 57 |
type Root struct {
|
| 55 | 58 |
m sync.Mutex |
| 56 | 59 |
scope string |
| 57 | 60 |
path string |
| 58 |
- volumes map[string]*Volume |
|
| 61 |
+ volumes map[string]*localVolume |
|
| 59 | 62 |
} |
| 60 | 63 |
|
| 64 |
+// DataPath returns the constructed path of this volume. |
|
| 61 | 65 |
func (r *Root) DataPath(volumeName string) string {
|
| 62 | 66 |
return filepath.Join(r.path, volumeName, VolumeDataPathName) |
| 63 | 67 |
} |
| 64 | 68 |
|
| 69 |
+// Name returns the name of Root, defined in the volume package in the DefaultDriverName constant. |
|
| 65 | 70 |
func (r *Root) Name() string {
|
| 66 |
- return "local" |
|
| 71 |
+ return volume.DefaultDriverName |
|
| 67 | 72 |
} |
| 68 | 73 |
|
| 74 |
+// Create creates a new volume.Volume with the provided name, creating |
|
| 75 |
+// the underlying directory tree required for this volume in the |
|
| 76 |
+// process. |
|
| 69 | 77 |
func (r *Root) Create(name string) (volume.Volume, error) {
|
| 70 | 78 |
r.m.Lock() |
| 71 | 79 |
defer r.m.Unlock() |
| ... | ... |
@@ -79,7 +93,7 @@ func (r *Root) Create(name string) (volume.Volume, error) {
|
| 79 | 79 |
} |
| 80 | 80 |
return nil, err |
| 81 | 81 |
} |
| 82 |
- v = &Volume{
|
|
| 82 |
+ v = &localVolume{
|
|
| 83 | 83 |
driverName: r.Name(), |
| 84 | 84 |
name: name, |
| 85 | 85 |
path: path, |
| ... | ... |
@@ -90,10 +104,14 @@ func (r *Root) Create(name string) (volume.Volume, error) {
|
| 90 | 90 |
return v, nil |
| 91 | 91 |
} |
| 92 | 92 |
|
| 93 |
+// Remove removes the specified volume and all underlying data. If the |
|
| 94 |
+// given volume does not belong to this driver and an error is |
|
| 95 |
+// returned. The volume is reference counted, if all references are |
|
| 96 |
+// not released then the volume is not removed. |
|
| 93 | 97 |
func (r *Root) Remove(v volume.Volume) error {
|
| 94 | 98 |
r.m.Lock() |
| 95 | 99 |
defer r.m.Unlock() |
| 96 |
- lv, ok := v.(*Volume) |
|
| 100 |
+ lv, ok := v.(*localVolume) |
|
| 97 | 101 |
if !ok {
|
| 98 | 102 |
return errors.New("unknown volume type")
|
| 99 | 103 |
} |
| ... | ... |
@@ -133,7 +151,9 @@ func (r *Root) scopedPath(realPath string) bool {
|
| 133 | 133 |
return false |
| 134 | 134 |
} |
| 135 | 135 |
|
| 136 |
-type Volume struct {
|
|
| 136 |
+// localVolume implements the Volume interface from the volume package and |
|
| 137 |
+// represents the volumes created by Root. |
|
| 138 |
+type localVolume struct {
|
|
| 137 | 139 |
m sync.Mutex |
| 138 | 140 |
usedCount int |
| 139 | 141 |
// unique name of the volume |
| ... | ... |
@@ -144,33 +164,38 @@ type Volume struct {
|
| 144 | 144 |
driverName string |
| 145 | 145 |
} |
| 146 | 146 |
|
| 147 |
-func (v *Volume) Name() string {
|
|
| 147 |
+// Name returns the name of the given Volume. |
|
| 148 |
+func (v *localVolume) Name() string {
|
|
| 148 | 149 |
return v.name |
| 149 | 150 |
} |
| 150 | 151 |
|
| 151 |
-func (v *Volume) DriverName() string {
|
|
| 152 |
+// DriverName returns the driver that created the given Volume. |
|
| 153 |
+func (v *localVolume) DriverName() string {
|
|
| 152 | 154 |
return v.driverName |
| 153 | 155 |
} |
| 154 | 156 |
|
| 155 |
-func (v *Volume) Path() string {
|
|
| 157 |
+// Path returns the data location. |
|
| 158 |
+func (v *localVolume) Path() string {
|
|
| 156 | 159 |
return v.path |
| 157 | 160 |
} |
| 158 | 161 |
|
| 159 |
-func (v *Volume) Mount() (string, error) {
|
|
| 162 |
+// Mount implements the localVolume interface, returning the data location. |
|
| 163 |
+func (v *localVolume) Mount() (string, error) {
|
|
| 160 | 164 |
return v.path, nil |
| 161 | 165 |
} |
| 162 | 166 |
|
| 163 |
-func (v *Volume) Unmount() error {
|
|
| 167 |
+// Umount is for satisfying the localVolume interface and does not do anything in this driver. |
|
| 168 |
+func (v *localVolume) Unmount() error {
|
|
| 164 | 169 |
return nil |
| 165 | 170 |
} |
| 166 | 171 |
|
| 167 |
-func (v *Volume) use() {
|
|
| 172 |
+func (v *localVolume) use() {
|
|
| 168 | 173 |
v.m.Lock() |
| 169 | 174 |
v.usedCount++ |
| 170 | 175 |
v.m.Unlock() |
| 171 | 176 |
} |
| 172 | 177 |
|
| 173 |
-func (v *Volume) release() {
|
|
| 178 |
+func (v *localVolume) release() {
|
|
| 174 | 179 |
v.m.Lock() |
| 175 | 180 |
v.usedCount-- |
| 176 | 181 |
v.m.Unlock() |
| ... | ... |
@@ -1,7 +1,10 @@ |
| 1 | 1 |
package volume |
| 2 | 2 |
|
| 3 |
-const DefaultDriverName = "local" |
|
| 3 |
+// DefaultDriverName is the driver name used for the driver |
|
| 4 |
+// implemented in the local package. |
|
| 5 |
+const DefaultDriverName string = "local" |
|
| 4 | 6 |
|
| 7 |
+// Driver is for creating and removing volumes. |
|
| 5 | 8 |
type Driver interface {
|
| 6 | 9 |
// Name returns the name of the volume driver. |
| 7 | 10 |
Name() string |
| ... | ... |
@@ -11,6 +14,7 @@ type Driver interface {
|
| 11 | 11 |
Remove(Volume) error |
| 12 | 12 |
} |
| 13 | 13 |
|
| 14 |
+// Volume is a place to store data. It is backed by a specific driver, and can be mounted. |
|
| 14 | 15 |
type Volume interface {
|
| 15 | 16 |
// Name returns the name of the volume |
| 16 | 17 |
Name() string |
| ... | ... |
@@ -51,7 +55,7 @@ func ValidateMountMode(mode string) (bool, bool) {
|
| 51 | 51 |
return roModes[mode] || rwModes[mode], rwModes[mode] |
| 52 | 52 |
} |
| 53 | 53 |
|
| 54 |
-// ReadOnly tells you if a mode string is a valid read-only mode or not. |
|
| 54 |
+// ReadWrite tells you if a mode string is a valid read-only mode or not. |
|
| 55 | 55 |
func ReadWrite(mode string) bool {
|
| 56 | 56 |
return rwModes[mode] |
| 57 | 57 |
} |