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

zfs: replace c for /proc/mounts parsing with go

Signed-off-by: Jörg Thalheim <joerg@higgsboson.tk>
This commit is contained in:
Jörg Thalheim 2015-04-16 13:06:44 +02:00
parent 30f3bd643d
commit ee00f07ea6

View file

@ -1,15 +1,5 @@
package zfs
/*
#include <stdlib.h>
#include <dirent.h>
#include <mntent.h>
const char* PROC_MOUNTS = "/proc/mounts";
const char* OPEN_MODE = "r";
*/
import "C"
import (
"fmt"
"os"
@ -19,10 +9,10 @@ import (
"strings"
"syscall"
"time"
"unsafe"
log "github.com/Sirupsen/logrus"
"github.com/docker/docker/daemon/graphdriver"
"github.com/docker/docker/pkg/mount"
"github.com/docker/docker/pkg/parsers"
zfs "github.com/mistifyio/go-zfs"
)
@ -129,27 +119,18 @@ func lookupZfsDataset(rootdir string) (string, error) {
}
wantedDev := stat.Dev
Cfp, err := C.setmntent(C.PROC_MOUNTS, C.OPEN_MODE)
mounts, err := mount.GetMounts()
if err != nil {
return "", fmt.Errorf("Failed to open /proc/mounts: %v", err)
return "", err
}
defer C.endmntent(Cfp)
var Cmnt C.struct_mntent
buf := string(make([]byte, 256, 256))
Cbuf := C.CString(buf)
defer C.free(unsafe.Pointer(Cbuf))
for C.getmntent_r(Cfp, &Cmnt, Cbuf, 256) != nil {
dir := C.GoString(Cmnt.mnt_dir)
if err := syscall.Stat(dir, &stat); err != nil {
log.Debugf("[zfs] failed to stat '%s' while scanning for zfs mount: %v", dir, err)
for _, m := range mounts {
if err := syscall.Stat(m.Mountpoint, &stat); err != nil {
log.Debugf("[zfs] failed to stat '%s' while scanning for zfs mount: %v", m.Mountpoint, err)
continue // may fail on fuse file systems
}
fs := C.GoString(Cmnt.mnt_type)
if stat.Dev == wantedDev && fs == "zfs" {
return C.GoString(Cmnt.mnt_fsname), nil
if stat.Dev == wantedDev && m.Fstype == "zfs" {
return m.Source, nil
}
}