Skip to content

Commit 8832f96

Browse files
committed
mountinfo: GetMountsFromReader() remove workaround for kernel < 3.10
In Linux <= 3.9 mounting a cifs with spaces in a share name (like "//srv/My Docs") _may_ end up having a space in the last field of mountinfo (like "unc=//serv/My Docs"). Since kernel 3.10-rc1, cifs option "unc=" is ignored, so spaces should not appear. Given that all major distros are now on at least kernel 3.10, and (e.g.) docker has not supported older kernel versions for 5 Years [1], it should be save to remove this special handling. [1]: moby/moby@51b23d8 Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent f494bef commit 8832f96

File tree

2 files changed

+7
-83
lines changed

2 files changed

+7
-83
lines changed

Diff for: mountinfo/mountinfo_linux.go

+2-12
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,8 @@ func GetMountsFromReader(r io.Reader, filter FilterFunc) ([]*Info, error) {
5757

5858
// separator field
5959
sepIdx := numFields - 4
60-
// In Linux <= 3.9 mounting a cifs with spaces in a share
61-
// name (like "//srv/My Docs") _may_ end up having a space
62-
// in the last field of mountinfo (like "unc=//serv/My Docs").
63-
// Since kernel 3.10-rc1, cifs option "unc=" is ignored,
64-
// so spaces should not appear.
65-
//
66-
// Check for a separator, and work around the spaces bug
67-
for fields[sepIdx] != "-" {
68-
sepIdx--
69-
if sepIdx == 5 {
70-
return nil, fmt.Errorf("parsing '%s' failed: missing - separator", text)
71-
}
60+
if fields[sepIdx] != "-" {
61+
return nil, fmt.Errorf("parsing '%s' failed: missing - separator", text)
7262
}
7363

7464
p := &Info{}

Diff for: mountinfo/mountinfo_linux_test.go

+5-71
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ const (
6262
235 35 253:32 / /var/lib/docker/devicemapper/mnt/1a28059f29eda821578b1bb27a60cc71f76f846a551abefabce6efd0146dce9f rw,relatime shared:217 - ext4 /dev/mapper/docker-253:2-425882-1a28059f29eda821578b1bb27a60cc71f76f846a551abefabce6efd0146dce9f rw,seclabel,discard,stripe=16,data=ordered
6363
239 35 253:33 / /var/lib/docker/devicemapper/mnt/e9aa60c60128cad1 rw,relatime shared:221 - ext4 /dev/mapper/docker-253:2-425882-e9aa60c60128cad1 rw,seclabel,discard,stripe=16,data=ordered
6464
243 35 253:34 / /var/lib/docker/devicemapper/mnt/5fec11304b6f4713fea7b6ccdcc1adc0a1966187f590fe25a8227428a8df275d-init rw,relatime shared:225 - ext4 /dev/mapper/docker-253:2-425882-5fec11304b6f4713fea7b6ccdcc1adc0a1966187f590fe25a8227428a8df275d-init rw,seclabel,discard,stripe=16,data=ordered
65-
247 35 253:35 / /var/lib/docker/devicemapper/mnt/5fec11304b6f4713fea7b6ccdcc1adc0a1966187f590fe25a8227428a8df275d rw,relatime shared:229 - ext4 /dev/mapper/docker-253:2-425882-5fec11304b6f4713fea7b6ccdcc1adc0a1966187f590fe25a8227428a8df275d rw,seclabel,discard,stripe=16,data=ordered
66-
31 21 0:23 / /DATA/foo_bla_bla rw,relatime - cifs //foo/BLA\040BLA\040BLA/ rw,sec=ntlm,cache=loose,unc=\\foo\BLA BLA BLA,username=my_login,domain=mydomain.com,uid=12345678,forceuid,gid=12345678,forcegid,addr=10.1.30.10,file_mode=0755,dir_mode=0755,nounix,rsize=61440,wsize=65536,actimeo=1`
65+
247 35 253:35 / /var/lib/docker/devicemapper/mnt/5fec11304b6f4713fea7b6ccdcc1adc0a1966187f590fe25a8227428a8df275d rw,relatime shared:229 - ext4 /dev/mapper/docker-253:2-425882-5fec11304b6f4713fea7b6ccdcc1adc0a1966187f590fe25a8227428a8df275d rw,seclabel,discard,stripe=16,data=ordered`
6766

6867
ubuntuMountinfo = `15 20 0:14 / /sys rw,nosuid,nodev,noexec,relatime - sysfs sysfs rw
6968
16 20 0:3 / /proc rw,nosuid,nodev,noexec,relatime - proc proc rw
@@ -418,10 +417,6 @@ const (
418417
286 15 0:3631 / /var/lib/docker/aufs/mnt/ff28c27d5f894363993622de26d5dd352dba072f219e4691d6498c19bbbc15a9 rw,relatime - aufs none rw,si=9b4a7642265b339c
419418
289 15 0:3634 / /var/lib/docker/aufs/mnt/aa128fe0e64fdede333aa48fd9de39530c91a9244a0f0649a3c411c61e372daa rw,relatime - aufs none rw,si=9b4a764012ada39c
420419
99 15 8:33 / /media/REMOVE\040ME rw,nosuid,nodev,relatime - fuseblk /dev/sdc1 rw,user_id=0,group_id=0,allow_other,blksize=4096`
421-
422-
mountInfoWithSpaces = `486 28 252:1 / /mnt/foo\040bar rw,relatime shared:243 - ext4 /dev/vda1 rw,data=ordered
423-
31 21 0:23 / /DATA/foo_bla_bla rw,relatime - cifs //foo/BLA\040BLA\040BLA/ rw,sec=ntlm,cache=loose,unc=\\foo\BLA BLA BLA,username=my_login,domain=mydomain.com,uid=12345678,forceuid,gid=12345678,forcegid,addr=10.1.30.10,file_mode=0755,dir_mode=0755,nounix,rsize=61440,wsize=65536,actimeo=1
424-
649 94 259:5 /tmp/newline\012tab\011space\040backslash\134quote1'quote2" /tmp/newline\012tab\011space\040backslash\134quote1'quote2" rw,relatime shared:47 - ext4 /dev/nvme0n1p5 rw,seclabel`
425420
)
426421

427422
func TestParseFedoraMountinfo(t *testing.T) {
@@ -454,7 +449,7 @@ func TestParseFedoraMountinfoFields(t *testing.T) {
454449
if err != nil {
455450
t.Fatal(err)
456451
}
457-
expectedLength := 58
452+
expectedLength := 57
458453
if len(infos) != expectedLength {
459454
t.Fatalf("Expected %d entries, got %d", expectedLength, len(infos))
460455
}
@@ -504,66 +499,6 @@ func TestParseFedoraMountinfoFilterFields(t *testing.T) {
504499
}
505500
}
506501

507-
func TestParseMountinfoWithSpaces(t *testing.T) {
508-
r := bytes.NewBuffer([]byte(mountInfoWithSpaces))
509-
infos, err := GetMountsFromReader(r, nil)
510-
if err != nil {
511-
t.Fatal(err)
512-
}
513-
expected := []Info{
514-
{
515-
ID: 486,
516-
Parent: 28,
517-
Major: 252,
518-
Minor: 1,
519-
Root: "/",
520-
Mountpoint: "/mnt/foo bar",
521-
Options: "rw,relatime",
522-
Optional: "shared:243",
523-
FSType: "ext4",
524-
Source: "/dev/vda1",
525-
VFSOptions: "rw,data=ordered",
526-
},
527-
{
528-
ID: 31,
529-
Parent: 21,
530-
Major: 0,
531-
Minor: 23,
532-
Root: "/",
533-
Mountpoint: "/DATA/foo_bla_bla",
534-
Options: "rw,relatime",
535-
Optional: "",
536-
FSType: "cifs",
537-
Source: `//foo/BLA BLA BLA/`,
538-
VFSOptions: `rw,sec=ntlm,cache=loose,unc=\\foo\BLA`,
539-
},
540-
{
541-
ID: 649,
542-
Parent: 94,
543-
Major: 259,
544-
Minor: 5,
545-
Root: `/tmp/newline
546-
tab space backslash\quote1'quote2"`,
547-
Mountpoint: `/tmp/newline
548-
tab space backslash\quote1'quote2"`,
549-
Options: "rw,relatime",
550-
Optional: "shared:47",
551-
FSType: "ext4",
552-
Source: `/dev/nvme0n1p5`,
553-
VFSOptions: `rw,seclabel`,
554-
},
555-
}
556-
557-
if len(infos) != len(expected) {
558-
t.Fatalf("expected %d entries, got %d", len(expected), len(infos))
559-
}
560-
for i, mi := range expected {
561-
if *infos[i] != mi {
562-
t.Fatalf("expected %#v, got %#v", mi, infos[i])
563-
}
564-
}
565-
}
566-
567502
func TestParseMountinfoFilters(t *testing.T) {
568503
cases := []struct {
569504
filter FilterFunc
@@ -640,10 +575,9 @@ func TestParseMountinfoExtraCases(t *testing.T) {
640575
valid: false,
641576
},
642577
{
643-
name: "extra fields at the end", // which we currently discard
644-
entry: `251 15 0:3573 / /mnt/point rw,relatime - aufs none rw,unc=buggy but we cope`,
645-
valid: true,
646-
exp: &Info{Mountpoint: "/mnt/point", FSType: "aufs", Source: "none"},
578+
name: "extra fields at the end (kernel < 3.10 bug)",
579+
entry: `251 15 0:3573 / /mnt/point rw,relatime - aufs none rw,unc=buggy pre-kernel 3.10 data`,
580+
valid: false,
647581
},
648582
{
649583
name: "one optional field",

0 commit comments

Comments
 (0)