1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #15269 from brahmaroutu/lint_daemon_graphdriver_zfs

daemon/graphdriver/zfs fix lint errrors/warnings
This commit is contained in:
Arnaud Porterie 2015-08-04 18:41:02 -07:00
commit 2c3cd949c8
2 changed files with 24 additions and 4 deletions

View file

@ -21,7 +21,7 @@ import (
"github.com/opencontainers/runc/libcontainer/label" "github.com/opencontainers/runc/libcontainer/label"
) )
type ZfsOptions struct { type zfsOptions struct {
fsName string fsName string
mountPath string mountPath string
} }
@ -30,12 +30,17 @@ func init() {
graphdriver.Register("zfs", Init) graphdriver.Register("zfs", Init)
} }
// Logger returns a zfs logger implmentation.
type Logger struct{} type Logger struct{}
// Log wraps log message from ZFS driver with a prefix '[zfs]'.
func (*Logger) Log(cmd []string) { func (*Logger) Log(cmd []string) {
logrus.Debugf("[zfs] %s", strings.Join(cmd, " ")) 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) { func Init(base string, opt []string) (graphdriver.Driver, error) {
var err error var err error
@ -101,8 +106,8 @@ func Init(base string, opt []string) (graphdriver.Driver, error) {
return graphdriver.NaiveDiffDriver(d), nil return graphdriver.NaiveDiffDriver(d), nil
} }
func parseOptions(opt []string) (ZfsOptions, error) { func parseOptions(opt []string) (zfsOptions, error) {
var options ZfsOptions var options zfsOptions
options.fsName = "" options.fsName = ""
for _, option := range opt { for _, option := range opt {
key, val, err := parsers.ParseKeyValueOpt(option) 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) 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 { type Driver struct {
dataset *zfs.Dataset dataset *zfs.Dataset
options ZfsOptions options zfsOptions
sync.Mutex // protects filesystem cache against concurrent access sync.Mutex // protects filesystem cache against concurrent access
filesystemsCache map[string]bool filesystemsCache map[string]bool
} }
@ -156,10 +162,15 @@ func (d *Driver) String() string {
return "zfs" return "zfs"
} }
// Cleanup is used to implement graphdriver.ProtoDriver. There is no cleanup required for this driver.
func (d *Driver) Cleanup() error { func (d *Driver) Cleanup() error {
return nil 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 { func (d *Driver) Status() [][2]string {
parts := strings.Split(d.dataset.Name, "/") parts := strings.Split(d.dataset.Name, "/")
pool, err := zfs.GetZpool(parts[0]) 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) { func (d *Driver) GetMetadata(id string) (map[string]string, error) {
return nil, nil return nil, nil
} }
@ -215,14 +227,17 @@ func (d *Driver) cloneFilesystem(name, parentName string) error {
return snapshot.Destroy(zfs.DestroyDeferDeletion) return snapshot.Destroy(zfs.DestroyDeferDeletion)
} }
// ZfsPath returns the filesystem path for the id provided.
func (d *Driver) ZfsPath(id string) string { func (d *Driver) ZfsPath(id string) string {
return d.options.fsName + "/" + id return d.options.fsName + "/" + id
} }
// MountPath returns the mounted filesystem path for the id provided.
func (d *Driver) MountPath(id string) string { func (d *Driver) MountPath(id string) string {
return path.Join(d.options.mountPath, "graph", getMountpoint(id)) 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 { func (d *Driver) Create(id string, parent string) error {
err := d.create(id, parent) err := d.create(id, parent)
if err == nil { if err == nil {
@ -261,6 +276,7 @@ func (d *Driver) create(id, parent string) error {
return d.cloneFilesystem(name, d.ZfsPath(parent)) 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 { func (d *Driver) Remove(id string) error {
name := d.ZfsPath(id) name := d.ZfsPath(id)
dataset := zfs.Dataset{Name: name} dataset := zfs.Dataset{Name: name}
@ -273,6 +289,7 @@ func (d *Driver) Remove(id string) error {
return err 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) { func (d *Driver) Get(id, mountLabel string) (string, error) {
mountpoint := d.MountPath(id) mountpoint := d.MountPath(id)
filesystem := d.ZfsPath(id) filesystem := d.ZfsPath(id)
@ -292,6 +309,7 @@ func (d *Driver) Get(id, mountLabel string) (string, error) {
return mountpoint, nil return mountpoint, nil
} }
// Put removes the existing mountpoint for the given id if it exists.
func (d *Driver) Put(id string) error { func (d *Driver) Put(id string) error {
mountpoint := d.MountPath(id) mountpoint := d.MountPath(id)
logrus.Debugf(`[zfs] unmount("%s")`, mountpoint) logrus.Debugf(`[zfs] unmount("%s")`, mountpoint)
@ -302,6 +320,7 @@ func (d *Driver) Put(id string) error {
return nil return nil
} }
// Exists checks to see if the cache entry exists for the given id.
func (d *Driver) Exists(id string) bool { func (d *Driver) Exists(id string) bool {
return d.filesystemsCache[d.ZfsPath(id)] == true return d.filesystemsCache[d.ZfsPath(id)] == true
} }

View file

@ -26,6 +26,7 @@ packages=(
daemon/execdriver/windows daemon/execdriver/windows
daemon/graphdriver/aufs daemon/graphdriver/aufs
daemon/graphdriver/devmapper daemon/graphdriver/devmapper
daemon/graphdriver/zfs
daemon/logger daemon/logger
daemon/logger/fluentd daemon/logger/fluentd
daemon/logger/gelf daemon/logger/gelf