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:
parent
30f3bd643d
commit
ee00f07ea6
1 changed files with 8 additions and 27 deletions
|
@ -1,15 +1,5 @@
|
||||||
package zfs
|
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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
@ -19,10 +9,10 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
"unsafe"
|
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
"github.com/docker/docker/daemon/graphdriver"
|
"github.com/docker/docker/daemon/graphdriver"
|
||||||
|
"github.com/docker/docker/pkg/mount"
|
||||||
"github.com/docker/docker/pkg/parsers"
|
"github.com/docker/docker/pkg/parsers"
|
||||||
zfs "github.com/mistifyio/go-zfs"
|
zfs "github.com/mistifyio/go-zfs"
|
||||||
)
|
)
|
||||||
|
@ -129,27 +119,18 @@ func lookupZfsDataset(rootdir string) (string, error) {
|
||||||
}
|
}
|
||||||
wantedDev := stat.Dev
|
wantedDev := stat.Dev
|
||||||
|
|
||||||
Cfp, err := C.setmntent(C.PROC_MOUNTS, C.OPEN_MODE)
|
mounts, err := mount.GetMounts()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("Failed to open /proc/mounts: %v", err)
|
return "", err
|
||||||
}
|
}
|
||||||
defer C.endmntent(Cfp)
|
for _, m := range mounts {
|
||||||
|
if err := syscall.Stat(m.Mountpoint, &stat); err != nil {
|
||||||
var Cmnt C.struct_mntent
|
log.Debugf("[zfs] failed to stat '%s' while scanning for zfs mount: %v", m.Mountpoint, err)
|
||||||
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)
|
|
||||||
continue // may fail on fuse file systems
|
continue // may fail on fuse file systems
|
||||||
}
|
}
|
||||||
|
|
||||||
fs := C.GoString(Cmnt.mnt_type)
|
if stat.Dev == wantedDev && m.Fstype == "zfs" {
|
||||||
if stat.Dev == wantedDev && fs == "zfs" {
|
return m.Source, nil
|
||||||
return C.GoString(Cmnt.mnt_fsname), nil
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue