Skip to content

Commit

Permalink
mountinfo: use idiomatic naming for fields
Browse files Browse the repository at this point in the history
I am looking at using these modules in containerd, so that we can
reduce the effort of maintaining "mountinfo" implementations.

This change renames the info fields to match the ones used in
containerd, which are more "correct" from a Go naming perspective:

containerd/containerd@8cd2182

This will be a breaking changes for consumers of this package, but
we're still pre-v1.0.0, so if we want to make these changes, this
is still possible now.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
  • Loading branch information
thaJeztah committed Oct 1, 2020
1 parent 9fe7f4e commit 3f9aa13
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 31 deletions.
12 changes: 6 additions & 6 deletions mountinfo/mountinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,18 @@ type Info struct {
// Mountpoint indicates the mount point relative to the process's root.
Mountpoint string

// Opts represents mount-specific options.
Opts string
// Options represents mount-specific options.
Options string

// Optional represents optional fields.
Optional string

// Fstype indicates the type of filesystem, such as EXT3.
Fstype string
// FSType indicates the type of filesystem, such as EXT3.
FSType string

// Source indicates filesystem specific information or "none".
Source string

// VfsOpts represents per super block options.
VfsOpts string
// VFSOptions represents per super block options.
VFSOptions string
}
2 changes: 1 addition & 1 deletion mountinfo/mountinfo_bsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func parseMountTable(filter FilterFunc) ([]*Info, error) {
var mountinfo Info
var skip, stop bool
mountinfo.Mountpoint = C.GoString(&entry.f_mntonname[0])
mountinfo.Fstype = C.GoString(&entry.f_fstypename[0])
mountinfo.FSType = C.GoString(&entry.f_fstypename[0])
mountinfo.Source = C.GoString(&entry.f_mntfromname[0])

if filter != nil {
Expand Down
2 changes: 1 addition & 1 deletion mountinfo/mountinfo_filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func ParentsFilter(path string) FilterFunc {
func FstypeFilter(fstype ...string) FilterFunc {
return func(m *Info) (bool, bool) {
for _, t := range fstype {
if m.Fstype == t {
if m.FSType == t {
return false, false // don't skip, keep going
}
}
Expand Down
6 changes: 3 additions & 3 deletions mountinfo/mountinfo_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ func GetMountsFromReader(r io.Reader, filter FilterFunc) ([]*Info, error) {
if err != nil {
return nil, fmt.Errorf("Parsing '%s' failed: mount point: %w", fields[4], err)
}
p.Fstype, err = unescape(fields[sepIdx+1])
p.FSType, err = unescape(fields[sepIdx+1])
if err != nil {
return nil, fmt.Errorf("Parsing '%s' failed: fstype: %w", fields[sepIdx+1], err)
}
p.Source, err = unescape(fields[sepIdx+2])
if err != nil {
return nil, fmt.Errorf("Parsing '%s' failed: source: %w", fields[sepIdx+2], err)
}
p.VfsOpts = fields[sepIdx+3]
p.VFSOptions = fields[sepIdx+3]

// Run a filter early so we can skip parsing/adding entries
// the caller is not interested in
Expand Down Expand Up @@ -116,7 +116,7 @@ func GetMountsFromReader(r io.Reader, filter FilterFunc) ([]*Info, error) {
return nil, fmt.Errorf("Parsing '%s' failed: root: %w", fields[3], err)
}

p.Opts = fields[5]
p.Options = fields[5]

// zero or more optional fields
switch {
Expand Down
40 changes: 20 additions & 20 deletions mountinfo/mountinfo_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,11 +465,11 @@ func TestParseFedoraMountinfoFields(t *testing.T) {
Minor: 3,
Root: "/",
Mountpoint: "/proc",
Opts: "rw,nosuid,nodev,noexec,relatime",
Options: "rw,nosuid,nodev,noexec,relatime",
Optional: "shared:5",
Fstype: "proc",
FSType: "proc",
Source: "proc",
VfsOpts: "rw",
VFSOptions: "rw",
}

if *infos[0] != mi {
Expand All @@ -491,11 +491,11 @@ func TestParseMountinfoWithSpaces(t *testing.T) {
Minor: 1,
Root: "/",
Mountpoint: "/mnt/foo bar",
Opts: "rw,relatime",
Options: "rw,relatime",
Optional: "shared:243",
Fstype: "ext4",
FSType: "ext4",
Source: "/dev/vda1",
VfsOpts: "rw,data=ordered",
VFSOptions: "rw,data=ordered",
},
{
ID: 31,
Expand All @@ -504,11 +504,11 @@ func TestParseMountinfoWithSpaces(t *testing.T) {
Minor: 23,
Root: "/",
Mountpoint: "/DATA/foo_bla_bla",
Opts: "rw,relatime",
Options: "rw,relatime",
Optional: "",
Fstype: "cifs",
FSType: "cifs",
Source: `//foo/BLA BLA BLA/`,
VfsOpts: `rw,sec=ntlm,cache=loose,unc=\\foo\BLA`,
VFSOptions: `rw,sec=ntlm,cache=loose,unc=\\foo\BLA`,
},
{
ID: 649,
Expand All @@ -519,11 +519,11 @@ func TestParseMountinfoWithSpaces(t *testing.T) {
tab space backslash\quote1'quote2"`,
Mountpoint: `/tmp/newline
tab space backslash\quote1'quote2"`,
Opts: "rw,relatime",
Optional: "shared:47",
Fstype: "ext4",
Source: `/dev/nvme0n1p5`,
VfsOpts: `rw,seclabel`,
Options: "rw,relatime",
Optional: "shared:47",
FSType: "ext4",
Source: `/dev/nvme0n1p5`,
VFSOptions: `rw,seclabel`,
},
}

Expand Down Expand Up @@ -616,25 +616,25 @@ func TestParseMountinfoExtraCases(t *testing.T) {
name: "extra fields at the end", // which we currently discard
entry: `251 15 0:3573 / /mnt/point rw,relatime - aufs none rw,unc=buggy but we cope`,
valid: true,
exp: &Info{Mountpoint: "/mnt/point", Fstype: "aufs", Source: "none"},
exp: &Info{Mountpoint: "/mnt/point", FSType: "aufs", Source: "none"},
},
{
name: "one optional field",
entry: `251 15 0:3573 / /mnt/point rw,relatime shared:123 - aufs none rw`,
valid: true,
exp: &Info{Mountpoint: "/mnt/point", Fstype: "aufs", Source: "none", Optional: "shared:123 extra:tag what:ever"},
exp: &Info{Mountpoint: "/mnt/point", FSType: "aufs", Source: "none", Optional: "shared:123 extra:tag what:ever"},
},
{
name: "extra optional fields", // which we carefully gather
entry: `251 15 0:3573 / /mnt/point rw,relatime shared:123 extra:tag what:ever key:value - aufs none rw`,
valid: true,
exp: &Info{Mountpoint: "/mnt/point", Fstype: "aufs", Source: "none", Optional: "shared:123 extra:tag what:ever"},
exp: &Info{Mountpoint: "/mnt/point", FSType: "aufs", Source: "none", Optional: "shared:123 extra:tag what:ever"},
},
{
name: "empty source field (kernel < 5.1 bug)",
entry: `279 23 0:108 / /tmp/bb rw,relatime - tmpfs rw`,
valid: true,
exp: &Info{Mountpoint: "/tmp/bb", Fstype: "tmpfs", Source: "", VfsOpts: "rw"},
exp: &Info{Mountpoint: "/tmp/bb", FSType: "tmpfs", Source: "", VFSOptions: "rw"},
},
}

Expand All @@ -661,8 +661,8 @@ func TestParseMountinfoExtraCases(t *testing.T) {
if tc.exp.Mountpoint != "" && tc.exp.Mountpoint != i.Mountpoint {
t.Errorf("case %q: expected mp %s, got %s", tc.name, tc.exp.Mountpoint, i.Mountpoint)
}
if tc.exp.Fstype != "" && tc.exp.Fstype != i.Fstype {
t.Errorf("case %q: expected fs %s, got %s", tc.name, tc.exp.Fstype, i.Fstype)
if tc.exp.FSType != "" && tc.exp.FSType != i.FSType {
t.Errorf("case %q: expected fs %s, got %s", tc.name, tc.exp.FSType, i.FSType)
}
if tc.exp.Source != "" && tc.exp.Source != i.Source {
t.Errorf("case %q: expected src %s, got %s", tc.name, tc.exp.Source, i.Source)
Expand Down

0 comments on commit 3f9aa13

Please sign in to comment.