@@ -21,7 +21,7 @@ import (
2121 "github.com/opencontainers/runc/libcontainer/label"
2222)
2323
24- type ZfsOptions struct {
24+ type zfsOptions struct {
2525 fsName string
2626 mountPath string
2727}
@@ -30,12 +30,17 @@ func init() {
3030 graphdriver .Register ("zfs" , Init )
3131}
3232
33+ // Logger returns a zfs logger implmentation.
3334type Logger struct {}
3435
36+ // Log wraps log message from ZFS driver with a prefix '[zfs]'.
3537func (* Logger ) Log (cmd []string ) {
3638 logrus .Debugf ("[zfs] %s" , strings .Join (cmd , " " ))
3739}
3840
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.
3944func Init (base string , opt []string ) (graphdriver.Driver , error ) {
4045 var err error
4146
@@ -101,8 +106,8 @@ func Init(base string, opt []string) (graphdriver.Driver, error) {
101106 return graphdriver .NaiveDiffDriver (d ), nil
102107}
103108
104- func parseOptions (opt []string ) (ZfsOptions , error ) {
105- var options ZfsOptions
109+ func parseOptions (opt []string ) (zfsOptions , error ) {
110+ var options zfsOptions
106111 options .fsName = ""
107112 for _ , option := range opt {
108113 key , val , err := parsers .ParseKeyValueOpt (option )
@@ -145,9 +150,10 @@ func lookupZfsDataset(rootdir string) (string, error) {
145150 return "" , fmt .Errorf ("Failed to find zfs dataset mounted on '%s' in /proc/mounts" , rootdir )
146151}
147152
153+ // Driver holds information about the driver, such as zfs dataset, options and cache.
148154type Driver struct {
149155 dataset * zfs.Dataset
150- options ZfsOptions
156+ options zfsOptions
151157 sync.Mutex // protects filesystem cache against concurrent access
152158 filesystemsCache map [string ]bool
153159}
@@ -156,10 +162,15 @@ func (d *Driver) String() string {
156162 return "zfs"
157163}
158164
165+ // Cleanup is used to implement graphdriver.ProtoDriver. There is no cleanup required for this driver.
159166func (d * Driver ) Cleanup () error {
160167 return nil
161168}
162169
170+ // Status returns information about the ZFS filesystem. It returns a two dimensional array of information
171+ // such as pool name, dataset name, disk usage, parent quota and compression used.
172+ // Currently it return 'Zpool', 'Zpool Health', 'Parent Dataset', 'Space Used By Parent',
173+ // 'Space Available', 'Parent Quota' and 'Compression'.
163174func (d * Driver ) Status () [][2 ]string {
164175 parts := strings .Split (d .dataset .Name , "/" )
165176 pool , err := zfs .GetZpool (parts [0 ])
@@ -189,6 +200,7 @@ func (d *Driver) Status() [][2]string {
189200 }
190201}
191202
203+ // GetMetadata is used for implementing the graphdriver.ProtoDriver interface. ZFS does not currently have any meta data.
192204func (d * Driver ) GetMetadata (id string ) (map [string ]string , error ) {
193205 return nil , nil
194206}
@@ -215,14 +227,17 @@ func (d *Driver) cloneFilesystem(name, parentName string) error {
215227 return snapshot .Destroy (zfs .DestroyDeferDeletion )
216228}
217229
230+ // ZfsPath returns the filesystem path for the id provided.
218231func (d * Driver ) ZfsPath (id string ) string {
219232 return d .options .fsName + "/" + id
220233}
221234
235+ // MountPath returns the mounted filesystem path for the id provided.
222236func (d * Driver ) MountPath (id string ) string {
223237 return path .Join (d .options .mountPath , "graph" , getMountpoint (id ))
224238}
225239
240+ // Create prepares the dataset and filesystem for the ZFS driver for the given id under the parent.
226241func (d * Driver ) Create (id string , parent string ) error {
227242 err := d .create (id , parent )
228243 if err == nil {
@@ -261,6 +276,7 @@ func (d *Driver) create(id, parent string) error {
261276 return d .cloneFilesystem (name , d .ZfsPath (parent ))
262277}
263278
279+ // Remove deletes the dataset, filesystem and the cache for the given id.
264280func (d * Driver ) Remove (id string ) error {
265281 name := d .ZfsPath (id )
266282 dataset := zfs.Dataset {Name : name }
@@ -273,6 +289,7 @@ func (d *Driver) Remove(id string) error {
273289 return err
274290}
275291
292+ // Get returns the mountpoint for the given id after creating the target directories if necessary.
276293func (d * Driver ) Get (id , mountLabel string ) (string , error ) {
277294 mountpoint := d .MountPath (id )
278295 filesystem := d .ZfsPath (id )
@@ -292,6 +309,7 @@ func (d *Driver) Get(id, mountLabel string) (string, error) {
292309 return mountpoint , nil
293310}
294311
312+ // Put removes the existing mountpoint for the given id if it exists.
295313func (d * Driver ) Put (id string ) error {
296314 mountpoint := d .MountPath (id )
297315 logrus .Debugf (`[zfs] unmount("%s")` , mountpoint )
@@ -302,6 +320,7 @@ func (d *Driver) Put(id string) error {
302320 return nil
303321}
304322
323+ // Exists checks to see if the cache entry exists for the given id.
305324func (d * Driver ) Exists (id string ) bool {
306325 return d .filesystemsCache [d .ZfsPath (id )] == true
307326}
0 commit comments