Browse code

Fix some doc strings in the volume package

Signed-off-by: Brian Goff <cpuguy83@gmail.com>

Brian Goff authored on 2018/11/01 03:50:24
Showing 2 changed files
... ...
@@ -27,6 +27,7 @@ type volumeEventLogger interface {
27 27
 }
28 28
 
29 29
 // VolumesService manages access to volumes
30
+// This is used as the main access point for volumes to higher level services and the API.
30 31
 type VolumesService struct {
31 32
 	vs           *VolumeStore
32 33
 	ds           ds
... ...
@@ -54,6 +55,12 @@ func (s *VolumesService) GetDriverList() []string {
54 54
 }
55 55
 
56 56
 // Create creates a volume
57
+// If the caller is creating this volume to be consumed immediately, it is
58
+// expected that the caller specifies a reference ID.
59
+// This reference ID will protect this volume from removal.
60
+//
61
+// A good example for a reference ID is a container's ID.
62
+// When whatever is going to reference this volume is removed the caller should defeference the volume by calling `Release`.
57 63
 func (s *VolumesService) Create(ctx context.Context, name, driverName string, opts ...opts.CreateOption) (*types.Volume, error) {
58 64
 	if name == "" {
59 65
 		name = stringid.GenerateNonCryptoID()
... ...
@@ -68,7 +75,7 @@ func (s *VolumesService) Create(ctx context.Context, name, driverName string, op
68 68
 	return &apiV, nil
69 69
 }
70 70
 
71
-// Get gets a volume
71
+// Get returns details about a volume
72 72
 func (s *VolumesService) Get(ctx context.Context, name string, getOpts ...opts.GetOption) (*types.Volume, error) {
73 73
 	v, err := s.vs.Get(ctx, name, getOpts...)
74 74
 	if err != nil {
... ...
@@ -88,6 +95,14 @@ func (s *VolumesService) Get(ctx context.Context, name string, getOpts ...opts.G
88 88
 }
89 89
 
90 90
 // Mount mounts the volume
91
+// Callers should specify a uniqe reference for each Mount/Unmount pair.
92
+//
93
+// Example:
94
+// ```go
95
+// mountID := "randomString"
96
+// s.Mount(ctx, vol, mountID)
97
+// s.Unmount(ctx, vol, mountID)
98
+// ```
91 99
 func (s *VolumesService) Mount(ctx context.Context, vol *types.Volume, ref string) (string, error) {
92 100
 	v, err := s.vs.Get(ctx, vol.Name, opts.WithGetDriver(vol.Driver))
93 101
 	if err != nil {
... ...
@@ -101,6 +116,10 @@ func (s *VolumesService) Mount(ctx context.Context, vol *types.Volume, ref strin
101 101
 
102 102
 // Unmount unmounts the volume.
103 103
 // Note that depending on the implementation, the volume may still be mounted due to other resources using it.
104
+//
105
+// The reference specified here should be the same reference specified during `Mount` and should be
106
+// unique for each mount/unmount pair.
107
+// See `Mount` documentation for an example.
104 108
 func (s *VolumesService) Unmount(ctx context.Context, vol *types.Volume, ref string) error {
105 109
 	v, err := s.vs.Get(ctx, vol.Name, opts.WithGetDriver(vol.Driver))
106 110
 	if err != nil {
... ...
@@ -118,6 +137,7 @@ func (s *VolumesService) Release(ctx context.Context, name string, ref string) e
118 118
 }
119 119
 
120 120
 // Remove removes a volume
121
+// An error is returned if the volume is still referenced.
121 122
 func (s *VolumesService) Remove(ctx context.Context, name string, rmOpts ...opts.RemoveOption) error {
122 123
 	var cfg opts.RemoveConfig
123 124
 	for _, o := range rmOpts {
... ...
@@ -182,7 +182,7 @@ func (s *VolumeStore) purge(ctx context.Context, name string) error {
182 182
 	return nil
183 183
 }
184 184
 
185
-// VolumeStore is a struct that stores the list of volumes available and keeps track of their usage counts
185
+// VolumeStore is responsible for storing and reference counting volumes.
186 186
 type VolumeStore struct {
187 187
 	// locks ensures that only one action is being performed on a particular volume at a time without locking the entire store
188 188
 	// since actions on volumes can be quite slow, this ensures the store is free to handle requests for other volumes.