Browse code

Merge pull request #15269 from brahmaroutu/lint_daemon_graphdriver_zfs

daemon/graphdriver/zfs fix lint errrors/warnings

Arnaud Porterie authored on 2015/08/05 10:41:02
Showing 2 changed files
... ...
@@ -21,7 +21,7 @@ import (
21 21
 	"github.com/opencontainers/runc/libcontainer/label"
22 22
 )
23 23
 
24
-type ZfsOptions struct {
24
+type zfsOptions struct {
25 25
 	fsName    string
26 26
 	mountPath string
27 27
 }
... ...
@@ -30,12 +30,17 @@ func init() {
30 30
 	graphdriver.Register("zfs", Init)
31 31
 }
32 32
 
33
+// Logger returns a zfs logger implmentation.
33 34
 type Logger struct{}
34 35
 
36
+// Log wraps log message from ZFS driver with a prefix '[zfs]'.
35 37
 func (*Logger) Log(cmd []string) {
36 38
 	logrus.Debugf("[zfs] %s", strings.Join(cmd, " "))
37 39
 }
38 40
 
41
+// Init returns a new ZFS driver.
42
+// It takes base mount path and a array of options which are represented as key value pairs.
43
+// Each option is in the for key=value. 'zfs.fsname' is expected to be a valid key in the options.
39 44
 func Init(base string, opt []string) (graphdriver.Driver, error) {
40 45
 	var err error
41 46
 
... ...
@@ -101,8 +106,8 @@ func Init(base string, opt []string) (graphdriver.Driver, error) {
101 101
 	return graphdriver.NaiveDiffDriver(d), nil
102 102
 }
103 103
 
104
-func parseOptions(opt []string) (ZfsOptions, error) {
105
-	var options ZfsOptions
104
+func parseOptions(opt []string) (zfsOptions, error) {
105
+	var options zfsOptions
106 106
 	options.fsName = ""
107 107
 	for _, option := range opt {
108 108
 		key, val, err := parsers.ParseKeyValueOpt(option)
... ...
@@ -145,9 +150,10 @@ func lookupZfsDataset(rootdir string) (string, error) {
145 145
 	return "", fmt.Errorf("Failed to find zfs dataset mounted on '%s' in /proc/mounts", rootdir)
146 146
 }
147 147
 
148
+// Driver holds information about the driver, such as zfs dataset, options and cache.
148 149
 type Driver struct {
149 150
 	dataset          *zfs.Dataset
150
-	options          ZfsOptions
151
+	options          zfsOptions
151 152
 	sync.Mutex       // protects filesystem cache against concurrent access
152 153
 	filesystemsCache map[string]bool
153 154
 }
... ...
@@ -156,10 +162,15 @@ func (d *Driver) String() string {
156 156
 	return "zfs"
157 157
 }
158 158
 
159
+// Cleanup is used to implement graphdriver.ProtoDriver. There is no cleanup required for this driver.
159 160
 func (d *Driver) Cleanup() error {
160 161
 	return nil
161 162
 }
162 163
 
164
+// Status returns information about the ZFS filesystem. It returns a two dimensional array of information
165
+// such as pool name, dataset name, disk usage, parent quota and compression used.
166
+// Currently it return 'Zpool', 'Zpool Health', 'Parent Dataset', 'Space Used By Parent',
167
+// 'Space Available', 'Parent Quota' and 'Compression'.
163 168
 func (d *Driver) Status() [][2]string {
164 169
 	parts := strings.Split(d.dataset.Name, "/")
165 170
 	pool, err := zfs.GetZpool(parts[0])
... ...
@@ -189,6 +200,7 @@ func (d *Driver) Status() [][2]string {
189 189
 	}
190 190
 }
191 191
 
192
+// GetMetadata is used for implementing the graphdriver.ProtoDriver interface. ZFS does not currently have any meta data.
192 193
 func (d *Driver) GetMetadata(id string) (map[string]string, error) {
193 194
 	return nil, nil
194 195
 }
... ...
@@ -215,14 +227,17 @@ func (d *Driver) cloneFilesystem(name, parentName string) error {
215 215
 	return snapshot.Destroy(zfs.DestroyDeferDeletion)
216 216
 }
217 217
 
218
+// ZfsPath returns the filesystem path for the id provided.
218 219
 func (d *Driver) ZfsPath(id string) string {
219 220
 	return d.options.fsName + "/" + id
220 221
 }
221 222
 
223
+// MountPath returns the mounted filesystem path for the id provided.
222 224
 func (d *Driver) MountPath(id string) string {
223 225
 	return path.Join(d.options.mountPath, "graph", getMountpoint(id))
224 226
 }
225 227
 
228
+// Create prepares the dataset and filesystem for the ZFS driver for the given id under the parent.
226 229
 func (d *Driver) Create(id string, parent string) error {
227 230
 	err := d.create(id, parent)
228 231
 	if err == nil {
... ...
@@ -261,6 +276,7 @@ func (d *Driver) create(id, parent string) error {
261 261
 	return d.cloneFilesystem(name, d.ZfsPath(parent))
262 262
 }
263 263
 
264
+// Remove deletes the dataset, filesystem and the cache for the given id.
264 265
 func (d *Driver) Remove(id string) error {
265 266
 	name := d.ZfsPath(id)
266 267
 	dataset := zfs.Dataset{Name: name}
... ...
@@ -273,6 +289,7 @@ func (d *Driver) Remove(id string) error {
273 273
 	return err
274 274
 }
275 275
 
276
+// Get returns the mountpoint for the given id after creating the target directories if necessary.
276 277
 func (d *Driver) Get(id, mountLabel string) (string, error) {
277 278
 	mountpoint := d.MountPath(id)
278 279
 	filesystem := d.ZfsPath(id)
... ...
@@ -292,6 +309,7 @@ func (d *Driver) Get(id, mountLabel string) (string, error) {
292 292
 	return mountpoint, nil
293 293
 }
294 294
 
295
+// Put removes the existing mountpoint for the given id if it exists.
295 296
 func (d *Driver) Put(id string) error {
296 297
 	mountpoint := d.MountPath(id)
297 298
 	logrus.Debugf(`[zfs] unmount("%s")`, mountpoint)
... ...
@@ -302,6 +320,7 @@ func (d *Driver) Put(id string) error {
302 302
 	return nil
303 303
 }
304 304
 
305
+// Exists checks to see if the cache entry exists for the given id.
305 306
 func (d *Driver) Exists(id string) bool {
306 307
 	return d.filesystemsCache[d.ZfsPath(id)] == true
307 308
 }
... ...
@@ -26,6 +26,7 @@ packages=(
26 26
 	daemon/execdriver/windows
27 27
 	daemon/graphdriver/aufs
28 28
 	daemon/graphdriver/devmapper
29
+	daemon/graphdriver/zfs
29 30
 	daemon/logger
30 31
 	daemon/logger/fluentd
31 32
 	daemon/logger/gelf