Skip to content

Commit

Permalink
daemon/graphdriver/btrfs fix lint errors/warnings
Browse files Browse the repository at this point in the history
Addresses moby#14756
Signed-off-by: Srini Brahmaroutu <[email protected]>
  • Loading branch information
brahmaroutu committed Jul 23, 2015
1 parent c6f4c19 commit 17c19f3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
27 changes: 21 additions & 6 deletions daemon/graphdriver/btrfs/btrfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ func init() {
graphdriver.Register("btrfs", Init)
}

// Init returns a new BTRFS driver.
// An error is returned if BTRFS is not supported.
func Init(home string, options []string) (graphdriver.Driver, error) {
rootdir := path.Dir(home)

Expand Down Expand Up @@ -51,29 +53,37 @@ func Init(home string, options []string) (graphdriver.Driver, error) {
return graphdriver.NaiveDiffDriver(driver), nil
}

// Driver contains information about the filesystem mounted.
type Driver struct {
//root of the file system
home string
}

// String prints the name of the driver (btrfs).
func (d *Driver) String() string {
return "btrfs"
}

// Status returns current driver information in a two dimensional string array.
// Output contains "Build Version" and "Library Version" of the btrfs libraries used.
// Version information can be used to check compatibility with your kernel.
func (d *Driver) Status() [][2]string {
status := [][2]string{}
if bv := BtrfsBuildVersion(); bv != "-" {
if bv := btrfsBuildVersion(); bv != "-" {
status = append(status, [2]string{"Build Version", bv})
}
if lv := BtrfsLibVersion(); lv != -1 {
if lv := btrfsLibVersion(); lv != -1 {
status = append(status, [2]string{"Library Version", fmt.Sprintf("%d", lv)})
}
return status
}

// GetMetadata returns empty metadata for this driver.
func (d *Driver) GetMetadata(id string) (map[string]string, error) {
return nil, nil
}

// Cleanup unmounts the home directory.
func (d *Driver) Cleanup() error {
return mount.Unmount(d.home)
}
Expand Down Expand Up @@ -174,10 +184,11 @@ func (d *Driver) subvolumesDir() string {
return path.Join(d.home, "subvolumes")
}

func (d *Driver) subvolumesDirId(id string) string {
func (d *Driver) subvolumesDirID(id string) string {
return path.Join(d.subvolumesDir(), id)
}

// Create the filesystem with given id.
func (d *Driver) Create(id string, parent string) error {
subvolumes := path.Join(d.home, "subvolumes")
if err := os.MkdirAll(subvolumes, 0700); err != nil {
Expand All @@ -199,8 +210,9 @@ func (d *Driver) Create(id string, parent string) error {
return nil
}

// Remove the filesystem with given id.
func (d *Driver) Remove(id string) error {
dir := d.subvolumesDirId(id)
dir := d.subvolumesDirID(id)
if _, err := os.Stat(dir); err != nil {
return err
}
Expand All @@ -210,8 +222,9 @@ func (d *Driver) Remove(id string) error {
return os.RemoveAll(dir)
}

// Get the requested filesystem id.
func (d *Driver) Get(id, mountLabel string) (string, error) {
dir := d.subvolumesDirId(id)
dir := d.subvolumesDirID(id)
st, err := os.Stat(dir)
if err != nil {
return "", err
Expand All @@ -224,14 +237,16 @@ func (d *Driver) Get(id, mountLabel string) (string, error) {
return dir, nil
}

// Put is not implemented for BTRFS as there is no cleanup required for the id.
func (d *Driver) Put(id string) error {
// Get() creates no runtime resources (like e.g. mounts)
// so this doesn't need to do anything.
return nil
}

// Exists checks if the id exists in the filesystem.
func (d *Driver) Exists(id string) bool {
dir := d.subvolumesDirId(id)
dir := d.subvolumesDirID(id)
_, err := os.Stat(dir)
return err == nil
}
4 changes: 2 additions & 2 deletions daemon/graphdriver/btrfs/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ package btrfs
*/
import "C"

func BtrfsBuildVersion() string {
func btrfsBuildVersion() string {
return string(C.BTRFS_BUILD_VERSION)
}

func BtrfsLibVersion() int {
func btrfsLibVersion() int {
return int(C.BTRFS_LIB_VERSION)
}
4 changes: 2 additions & 2 deletions daemon/graphdriver/btrfs/version_none.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ package btrfs
// TODO(vbatts) remove this work-around once supported linux distros are on
// btrfs utililties of >= 3.16.1

func BtrfsBuildVersion() string {
func btrfsBuildVersion() string {
return "-"
}

func BtrfsLibVersion() int {
func btrfsLibVersion() int {
return -1
}

0 comments on commit 17c19f3

Please sign in to comment.