Skip to content

Commit

Permalink
Update Mount/Unmount arguments
Browse files Browse the repository at this point in the history
Since [1], Mount() and Unmount() calls have their own structures.
Update our code accordingly.

[1] docker/go-plugins-helpers@461a12724a063

Signed-off-by: Kir Kolyshkin <[email protected]>
  • Loading branch information
kolyshkin committed Nov 15, 2016
1 parent 233c55a commit 0fd6b02
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
4 changes: 2 additions & 2 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func (d *ploopDriver) Remove(r volume.Request) volume.Response {
return volume.Response{}
}

func (d *ploopDriver) Mount(r volume.Request) volume.Response {
func (d *ploopDriver) Mount(r volume.MountRequest) volume.Response {
logrus.Debugf("Mounting volume %s", r.Name)

p, err := ploop.Open(d.dd(r.Name))
Expand Down Expand Up @@ -258,7 +258,7 @@ func (d *ploopDriver) Mount(r volume.Request) volume.Response {
return volume.Response{Mountpoint: mnt}
}

func (d *ploopDriver) Unmount(r volume.Request) volume.Response {
func (d *ploopDriver) Unmount(r volume.UnmountRequest) volume.Response {
logrus.Debugf("Unmounting volume %s", r.Name)

p, err := ploop.Open(d.dd(r.Name))
Expand Down
64 changes: 64 additions & 0 deletions fstype.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package main

import (
"bufio"
"fmt"
"os"
"strings"
"syscall"
)

// Given a file or directory, finds which filesystem it is on,
// by parsing /proc/self/mountinfo and comparing dev_t
// of the file to that in the mountinfo field.
func GetFilesystemType(path string) (string, error) {
var st syscall.Stat_t

err := syscall.Stat(path, &st)
if err != nil {
return "", err
}

return getFSTypeByDev(st.Dev)
}

// convert minor:major string from /proc/self/mountinfo into dev_t
func parseDev(s string) uint64 {
var major uint32
var minor uint32

n, _ := fmt.Sscanf(s, "%d:%d", &major, &minor)

if n != 2 {
return 0
}

return uint64(major<<8 + minor)
}

func getFSTypeByDev(dev uint64) (string, error) {
mi, err := os.Open("/proc/self/mountinfo")
if err != nil {
return "", err
}
defer mi.Close()

sc := bufio.NewScanner(mi)
for sc.Scan() {
line := strings.Split(sc.Text(), " ")
if len(line) < 10 {
return "", fmt.Errorf("Short line in /proc/self/mountinfo: %v\n", line)
}
dstr := line[2] // major:minor: value of st_dev for files on filesystem
fs := line[8] // filesystem type: name of filesystem of the form "type[.subtype]"
d := parseDev(dstr)
if d == 0 {
return "", fmt.Errorf("Can't parse device %s", dstr)
}
if d == dev {
return fs, nil
}
}

return "", nil
}

0 comments on commit 0fd6b02

Please sign in to comment.