daemon/graphdriver/zfs fix lint errrors/warnings

Addresses #14756
Signed-off-by: Srini Brahmaroutu <srbrahma@us.ibm.com>
This commit is contained in:
Srini Brahmaroutu 2015-08-03 20:47:19 +00:00
parent b9aaf8c758
commit e27c904b99
2 changed files with 24 additions and 4 deletions

View File

@ -21,7 +21,7 @@ import (
"github.com/opencontainers/runc/libcontainer/label"
)
type ZfsOptions struct {
type zfsOptions struct {
fsName string
mountPath string
}
@ -30,12 +30,17 @@ func init() {
graphdriver.Register("zfs", Init)
}
// Logger returns a zfs logger implmentation.
type Logger struct{}
// Log wraps log message from ZFS driver with a prefix '[zfs]'.
func (*Logger) Log(cmd []string) {
logrus.Debugf("[zfs] %s", strings.Join(cmd, " "))
}
// Init returns a new ZFS driver.
// It takes base mount path and a array of options which are represented as key value pairs.
// Each option is in the for key=value. 'zfs.fsname' is expected to be a valid key in the options.
func Init(base string, opt []string) (graphdriver.Driver, error) {
var err error
@ -101,8 +106,8 @@ func Init(base string, opt []string) (graphdriver.Driver, error) {
return graphdriver.NaiveDiffDriver(d), nil
}
func parseOptions(opt []string) (ZfsOptions, error) {
var options ZfsOptions
func parseOptions(opt []string) (zfsOptions, error) {
var options zfsOptions
options.fsName = ""
for _, option := range opt {
key, val, err := parsers.ParseKeyValueOpt(option)
@ -145,9 +150,10 @@ func lookupZfsDataset(rootdir string) (string, error) {
return "", fmt.Errorf("Failed to find zfs dataset mounted on '%s' in /proc/mounts", rootdir)
}
// Driver holds information about the driver, such as zfs dataset, options and cache.
type Driver struct {
dataset *zfs.Dataset
options ZfsOptions
options zfsOptions
sync.Mutex // protects filesystem cache against concurrent access
filesystemsCache map[string]bool
}
@ -156,10 +162,15 @@ func (d *Driver) String() string {
return "zfs"
}
// Cleanup is used to implement graphdriver.ProtoDriver. There is no cleanup required for this driver.
func (d *Driver) Cleanup() error {
return nil
}
// Status returns information about the ZFS filesystem. It returns a two dimensional array of information
// such as pool name, dataset name, disk usage, parent quota and compression used.
// Currently it return 'Zpool', 'Zpool Health', 'Parent Dataset', 'Space Used By Parent',
// 'Space Available', 'Parent Quota' and 'Compression'.
func (d *Driver) Status() [][2]string {
parts := strings.Split(d.dataset.Name, "/")
pool, err := zfs.GetZpool(parts[0])
@ -189,6 +200,7 @@ func (d *Driver) Status() [][2]string {
}
}
// GetMetadata is used for implementing the graphdriver.ProtoDriver interface. ZFS does not currently have any meta data.
func (d *Driver) GetMetadata(id string) (map[string]string, error) {
return nil, nil
}
@ -215,14 +227,17 @@ func (d *Driver) cloneFilesystem(name, parentName string) error {
return snapshot.Destroy(zfs.DestroyDeferDeletion)
}
// ZfsPath returns the filesystem path for the id provided.
func (d *Driver) ZfsPath(id string) string {
return d.options.fsName + "/" + id
}
// MountPath returns the mounted filesystem path for the id provided.
func (d *Driver) MountPath(id string) string {
return path.Join(d.options.mountPath, "graph", getMountpoint(id))
}
// Create prepares the dataset and filesystem for the ZFS driver for the given id under the parent.
func (d *Driver) Create(id string, parent string) error {
err := d.create(id, parent)
if err == nil {
@ -261,6 +276,7 @@ func (d *Driver) create(id, parent string) error {
return d.cloneFilesystem(name, d.ZfsPath(parent))
}
// Remove deletes the dataset, filesystem and the cache for the given id.
func (d *Driver) Remove(id string) error {
name := d.ZfsPath(id)
dataset := zfs.Dataset{Name: name}
@ -273,6 +289,7 @@ func (d *Driver) Remove(id string) error {
return err
}
// Get returns the mountpoint for the given id after creating the target directories if necessary.
func (d *Driver) Get(id, mountLabel string) (string, error) {
mountpoint := d.MountPath(id)
filesystem := d.ZfsPath(id)
@ -292,6 +309,7 @@ func (d *Driver) Get(id, mountLabel string) (string, error) {
return mountpoint, nil
}
// Put removes the existing mountpoint for the given id if it exists.
func (d *Driver) Put(id string) error {
mountpoint := d.MountPath(id)
logrus.Debugf(`[zfs] unmount("%s")`, mountpoint)
@ -302,6 +320,7 @@ func (d *Driver) Put(id string) error {
return nil
}
// Exists checks to see if the cache entry exists for the given id.
func (d *Driver) Exists(id string) bool {
return d.filesystemsCache[d.ZfsPath(id)] == true
}

View File

@ -25,6 +25,7 @@ packages=(
daemon/execdriver/native/template
daemon/graphdriver/aufs
daemon/graphdriver/devmapper
daemon/graphdriver/zfs
daemon/logger
daemon/logger/fluentd
daemon/logger/gelf