Skip to content
This repository has been archived by the owner on Feb 24, 2020. It is now read-only.

Commit

Permalink
fly: use pkg/mountinfo for mountinfo parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
lucab committed Nov 25, 2016
1 parent aed0c0e commit b97c551
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 37 deletions.
4 changes: 0 additions & 4 deletions stage1_fly/gc/main.go
Expand Up @@ -23,10 +23,6 @@ import (
rktlog "github.com/coreos/rkt/pkg/log"
)

const (
mountinfoPath = "/proc/self/mountinfo"
)

var (
debug bool

Expand Down
38 changes: 5 additions & 33 deletions stage1_fly/run/main.go
Expand Up @@ -69,38 +69,6 @@ var (
dnsConfMode *pkgflag.PairList
)

func getHostMounts() (map[string]struct{}, error) {
hostMounts := map[string]struct{}{}

mi, err := os.Open("/proc/self/mountinfo")
if err != nil {
return nil, err
}
defer mi.Close()

sc := bufio.NewScanner(mi)
for sc.Scan() {
var (
discard string
mountPoint string
)

_, err := fmt.Sscanf(sc.Text(),
"%s %s %s %s %s",
&discard, &discard, &discard, &discard, &mountPoint,
)
if err != nil {
return nil, err
}

hostMounts[mountPoint] = struct{}{}
}
if sc.Err() != nil {
return nil, errwrap.Wrap(errors.New("problem parsing mountinfo"), sc.Err())
}
return hostMounts, nil
}

func init() {
flag.BoolVar(&debug, "debug", false, "Run in debug mode")

Expand Down Expand Up @@ -206,10 +174,14 @@ func evaluateMounts(rfs string, app string, p *stage1commontypes.Pod) ([]flyMoun
}

// Gather host mounts which we make MS_SHARED if passed as a volume source
hostMounts, err := getHostMounts()
hostMounts := map[string]struct{}{}
mnts, err := mountinfo.ParseMounts(0)
if err != nil {
return nil, errwrap.Wrap(errors.New("can't gather host mounts"), err)
}
for _, m := range mnts {
hostMounts[m.MountPoint] = struct{}{}
}

argFlyMounts := []flyMount{}
for _, tuple := range namedVolumeMounts {
Expand Down

0 comments on commit b97c551

Please sign in to comment.