Browse code

daemon/graphdriver/overlay/ fix lint errors/warnings Addresses #14756 Signed-off-by: Srini Brahmaroutu <srbrahma@us.ibm.com>

Srini Brahmaroutu authored on 2015/07/25 02:55:15
Showing 3 changed files
... ...
@@ -12,10 +12,10 @@ import (
12 12
 	"github.com/docker/docker/pkg/system"
13 13
 )
14 14
 
15
-type CopyFlags int
15
+type copyFlags int
16 16
 
17 17
 const (
18
-	CopyHardlink CopyFlags = 1 << iota
18
+	copyHardlink copyFlags = 1 << iota
19 19
 )
20 20
 
21 21
 func copyRegular(srcPath, dstPath string, mode os.FileMode) error {
... ...
@@ -49,7 +49,7 @@ func copyXattr(srcPath, dstPath, attr string) error {
49 49
 	return nil
50 50
 }
51 51
 
52
-func copyDir(srcDir, dstDir string, flags CopyFlags) error {
52
+func copyDir(srcDir, dstDir string, flags copyFlags) error {
53 53
 	err := filepath.Walk(srcDir, func(srcPath string, f os.FileInfo, err error) error {
54 54
 		if err != nil {
55 55
 			return err
... ...
@@ -75,7 +75,7 @@ func copyDir(srcDir, dstDir string, flags CopyFlags) error {
75 75
 
76 76
 		switch f.Mode() & os.ModeType {
77 77
 		case 0: // Regular file
78
-			if flags&CopyHardlink != 0 {
78
+			if flags&copyHardlink != 0 {
79 79
 				isHardlink = true
80 80
 				if err := os.Link(srcPath, dstPath); err != nil {
81 81
 					return err
... ...
@@ -23,11 +23,15 @@ import (
23 23
 // implementation of ApplyDiff()
24 24
 
25 25
 var (
26
+	// ErrApplyDiffFallback is returned to indicate that a normal ApplyDiff is applied as a fallback from Naive diff writer.
26 27
 	ErrApplyDiffFallback = fmt.Errorf("Fall back to normal ApplyDiff")
27 28
 )
28 29
 
30
+// ApplyDiffProtoDriver wraps the ProtoDriver by extending the inteface with ApplyDiff method.
29 31
 type ApplyDiffProtoDriver interface {
30 32
 	graphdriver.ProtoDriver
33
+	// ApplyDiff writes the diff to the archive for the given id and parent id.
34
+	// It returns the size in bytes written if successful, an error ErrApplyDiffFallback is returned otherwise.
31 35
 	ApplyDiff(id, parent string, diff archive.Reader) (size int64, err error)
32 36
 }
33 37
 
... ...
@@ -36,6 +40,7 @@ type naiveDiffDriverWithApply struct {
36 36
 	applyDiff ApplyDiffProtoDriver
37 37
 }
38 38
 
39
+// NaiveDiffDriverWithApply returns a NaiveDiff driver with custom ApplyDiff.
39 40
 func NaiveDiffDriverWithApply(driver ApplyDiffProtoDriver) graphdriver.Driver {
40 41
 	return &naiveDiffDriverWithApply{
41 42
 		Driver:    graphdriver.NaiveDiffDriver(driver),
... ...
@@ -43,6 +48,7 @@ func NaiveDiffDriverWithApply(driver ApplyDiffProtoDriver) graphdriver.Driver {
43 43
 	}
44 44
 }
45 45
 
46
+// ApplyDiff creates a diff layer with either the NaiveDiffDriver or with a fallback.
46 47
 func (d *naiveDiffDriverWithApply) ApplyDiff(id, parent string, diff archive.Reader) (int64, error) {
47 48
 	b, err := d.applyDiff.ApplyDiff(id, parent, diff)
48 49
 	if err == ErrApplyDiffFallback {
... ...
@@ -79,11 +85,15 @@ func (d *naiveDiffDriverWithApply) ApplyDiff(id, parent string, diff archive.Rea
79 79
 // of that. This means all child images share file (but not directory)
80 80
 // data with the parent.
81 81
 
82
+// ActiveMount contains information about the count, path and whether is mounted or not.
83
+// This information is part of the Driver, that contains list of active mounts taht are part of this overlay.
82 84
 type ActiveMount struct {
83 85
 	count   int
84 86
 	path    string
85 87
 	mounted bool
86 88
 }
89
+
90
+// Driver contains information about the home directory and the list of active mounts that are created using this driver.
87 91
 type Driver struct {
88 92
 	home       string
89 93
 	sync.Mutex // Protects concurrent modification to active
... ...
@@ -96,6 +106,9 @@ func init() {
96 96
 	graphdriver.Register("overlay", Init)
97 97
 }
98 98
 
99
+// Init returns the NaiveDiffDriver, a native diff driver for overlay filesystem.
100
+// If overlay filesystem is not supported on the host, graphdriver.ErrNotSupported is returned as error.
101
+// If a overlay filesystem is not supported over a existing filesystem then error graphdriver.ErrIncompatibleFS is returned.
99 102
 func Init(home string, options []string) (graphdriver.Driver, error) {
100 103
 
101 104
 	if err := supportsOverlay(); err != nil {
... ...
@@ -161,12 +174,15 @@ func (d *Driver) String() string {
161 161
 	return "overlay"
162 162
 }
163 163
 
164
+// Status returns current driver information in a two dimensional string array.
165
+// Output contains "Backing Filesystem" used in this implementation.
164 166
 func (d *Driver) Status() [][2]string {
165 167
 	return [][2]string{
166 168
 		{"Backing Filesystem", backingFs},
167 169
 	}
168 170
 }
169 171
 
172
+// GetMetadata returns meta data about the overlay driver such as root, LowerDir, UpperDir, WorkDir and MergeDir used to store data.
170 173
 func (d *Driver) GetMetadata(id string) (map[string]string, error) {
171 174
 	dir := d.dir(id)
172 175
 	if _, err := os.Stat(dir); err != nil {
... ...
@@ -182,12 +198,12 @@ func (d *Driver) GetMetadata(id string) (map[string]string, error) {
182 182
 		return metadata, nil
183 183
 	}
184 184
 
185
-	lowerId, err := ioutil.ReadFile(path.Join(dir, "lower-id"))
185
+	lowerID, err := ioutil.ReadFile(path.Join(dir, "lower-id"))
186 186
 	if err != nil {
187 187
 		return nil, err
188 188
 	}
189 189
 
190
-	metadata["LowerDir"] = path.Join(d.dir(string(lowerId)), "root")
190
+	metadata["LowerDir"] = path.Join(d.dir(string(lowerID)), "root")
191 191
 	metadata["UpperDir"] = path.Join(dir, "upper")
192 192
 	metadata["WorkDir"] = path.Join(dir, "work")
193 193
 	metadata["MergedDir"] = path.Join(dir, "merged")
... ...
@@ -195,10 +211,14 @@ func (d *Driver) GetMetadata(id string) (map[string]string, error) {
195 195
 	return metadata, nil
196 196
 }
197 197
 
198
+// Cleanup simply returns nil and do not change the existing filesystem.
199
+// This is required to satisfy the graphdriver.Driver interface.
198 200
 func (d *Driver) Cleanup() error {
199 201
 	return nil
200 202
 }
201 203
 
204
+// Create is used to create the upper, lower, and merge directories required for overlay fs for a given id.
205
+// The parent filesystem is used to configure these directories for the overlay.
202 206
 func (d *Driver) Create(id string, parent string) (retErr error) {
203 207
 	dir := d.dir(id)
204 208
 	if err := os.MkdirAll(path.Dir(dir), 0700); err != nil {
... ...
@@ -251,12 +271,12 @@ func (d *Driver) Create(id string, parent string) (retErr error) {
251 251
 
252 252
 	// Otherwise, copy the upper and the lower-id from the parent
253 253
 
254
-	lowerId, err := ioutil.ReadFile(path.Join(parentDir, "lower-id"))
254
+	lowerID, err := ioutil.ReadFile(path.Join(parentDir, "lower-id"))
255 255
 	if err != nil {
256 256
 		return err
257 257
 	}
258 258
 
259
-	if err := ioutil.WriteFile(path.Join(dir, "lower-id"), lowerId, 0666); err != nil {
259
+	if err := ioutil.WriteFile(path.Join(dir, "lower-id"), lowerID, 0666); err != nil {
260 260
 		return err
261 261
 	}
262 262
 
... ...
@@ -284,6 +304,7 @@ func (d *Driver) dir(id string) string {
284 284
 	return path.Join(d.home, id)
285 285
 }
286 286
 
287
+// Remove cleans the directories that are created for this id.
287 288
 func (d *Driver) Remove(id string) error {
288 289
 	dir := d.dir(id)
289 290
 	if _, err := os.Stat(dir); err != nil {
... ...
@@ -292,6 +313,7 @@ func (d *Driver) Remove(id string) error {
292 292
 	return os.RemoveAll(dir)
293 293
 }
294 294
 
295
+// Get creates and mounts the required file system for the given id and returns the mount path.
295 296
 func (d *Driver) Get(id string, mountLabel string) (string, error) {
296 297
 	// Protect the d.active from concurrent access
297 298
 	d.Lock()
... ...
@@ -318,11 +340,11 @@ func (d *Driver) Get(id string, mountLabel string) (string, error) {
318 318
 		return mount.path, nil
319 319
 	}
320 320
 
321
-	lowerId, err := ioutil.ReadFile(path.Join(dir, "lower-id"))
321
+	lowerID, err := ioutil.ReadFile(path.Join(dir, "lower-id"))
322 322
 	if err != nil {
323 323
 		return "", err
324 324
 	}
325
-	lowerDir := path.Join(d.dir(string(lowerId)), "root")
325
+	lowerDir := path.Join(d.dir(string(lowerID)), "root")
326 326
 	upperDir := path.Join(dir, "upper")
327 327
 	workDir := path.Join(dir, "work")
328 328
 	mergedDir := path.Join(dir, "merged")
... ...
@@ -338,6 +360,7 @@ func (d *Driver) Get(id string, mountLabel string) (string, error) {
338 338
 	return mount.path, nil
339 339
 }
340 340
 
341
+// Put unmounts the mount path created for the give id.
341 342
 func (d *Driver) Put(id string) error {
342 343
 	// Protect the d.active from concurrent access
343 344
 	d.Lock()
... ...
@@ -373,6 +396,7 @@ func (d *Driver) Put(id string) error {
373 373
 	return nil
374 374
 }
375 375
 
376
+// ApplyDiff applies the new layer on top of the root, if parent does not exist with will return a ErrApplyDiffFallback error.
376 377
 func (d *Driver) ApplyDiff(id string, parent string, diff archive.Reader) (size int64, err error) {
377 378
 	dir := d.dir(id)
378 379
 
... ...
@@ -407,7 +431,7 @@ func (d *Driver) ApplyDiff(id string, parent string, diff archive.Reader) (size
407 407
 		}
408 408
 	}()
409 409
 
410
-	if err = copyDir(parentRootDir, tmpRootDir, CopyHardlink); err != nil {
410
+	if err = copyDir(parentRootDir, tmpRootDir, copyHardlink); err != nil {
411 411
 		return 0, err
412 412
 	}
413 413
 
... ...
@@ -423,6 +447,7 @@ func (d *Driver) ApplyDiff(id string, parent string, diff archive.Reader) (size
423 423
 	return
424 424
 }
425 425
 
426
+// Exists checks to see if the id is already mounted.
426 427
 func (d *Driver) Exists(id string) bool {
427 428
 	_, err := os.Stat(d.dir(id))
428 429
 	return err == nil
... ...
@@ -27,6 +27,7 @@ packages=(
27 27
 	daemon/execdriver/windows
28 28
 	daemon/graphdriver/aufs
29 29
 	daemon/graphdriver/devmapper
30
+	daemon/graphdriver/overlay
30 31
 	daemon/graphdriver/vfs
31 32
 	daemon/graphdriver/zfs
32 33
 	daemon/logger