Skip to content

Commit 955e12d

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 76a42cd commit 955e12d

File tree

2 files changed

+6
-82
lines changed

2 files changed

+6
-82
lines changed

mountinfo/mountinfo_linux.go

Lines changed: 2 additions & 12 deletions
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{}

mountinfo/mountinfo_linux_test.go

Lines changed: 4 additions & 70 deletions
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 TestParseMountInfo(t *testing.T) {
@@ -531,66 +526,6 @@ func TestParseFedoraMountinfoFilterFields(t *testing.T) {
531526
}
532527
}
533528

534-
func TestParseMountinfoWithSpaces(t *testing.T) {
535-
r := bytes.NewBuffer([]byte(mountInfoWithSpaces))
536-
infos, err := GetMountsFromReader(r, nil)
537-
if err != nil {
538-
t.Fatal(err)
539-
}
540-
expected := []Info{
541-
{
542-
ID: 486,
543-
Parent: 28,
544-
Major: 252,
545-
Minor: 1,
546-
Root: "/",
547-
Mountpoint: "/mnt/foo bar",
548-
Options: "rw,relatime",
549-
Optional: "shared:243",
550-
FSType: "ext4",
551-
Source: "/dev/vda1",
552-
VFSOptions: "rw,data=ordered",
553-
},
554-
{
555-
ID: 31,
556-
Parent: 21,
557-
Major: 0,
558-
Minor: 23,
559-
Root: "/",
560-
Mountpoint: "/DATA/foo_bla_bla",
561-
Options: "rw,relatime",
562-
Optional: "",
563-
FSType: "cifs",
564-
Source: `//foo/BLA BLA BLA/`,
565-
VFSOptions: `rw,sec=ntlm,cache=loose,unc=\\foo\BLA`,
566-
},
567-
{
568-
ID: 649,
569-
Parent: 94,
570-
Major: 259,
571-
Minor: 5,
572-
Root: `/tmp/newline
573-
tab space backslash\quote1'quote2"`,
574-
Mountpoint: `/tmp/newline
575-
tab space backslash\quote1'quote2"`,
576-
Options: "rw,relatime",
577-
Optional: "shared:47",
578-
FSType: "ext4",
579-
Source: `/dev/nvme0n1p5`,
580-
VFSOptions: `rw,seclabel`,
581-
},
582-
}
583-
584-
if len(infos) != len(expected) {
585-
t.Fatalf("expected %d entries, got %d", len(expected), len(infos))
586-
}
587-
for i, mi := range expected {
588-
if *infos[i] != mi {
589-
t.Fatalf("expected %#v, got %#v", mi, infos[i])
590-
}
591-
}
592-
}
593-
594529
func TestParseMountinfoFilters(t *testing.T) {
595530
cases := []struct {
596531
filter FilterFunc
@@ -667,10 +602,9 @@ func TestParseMountinfoExtraCases(t *testing.T) {
667602
valid: false,
668603
},
669604
{
670-
name: "extra fields at the end", // which we currently discard
671-
entry: `251 15 0:3573 / /mnt/point rw,relatime - aufs none rw,unc=buggy but we cope`,
672-
valid: true,
673-
exp: &Info{Mountpoint: "/mnt/point", FSType: "aufs", Source: "none"},
605+
name: "extra fields at the end (kernel < 3.10 bug)",
606+
entry: `251 15 0:3573 / /mnt/point rw,relatime - aufs none rw,unc=buggy pre-kernel 3.10 data`,
607+
valid: false,
674608
},
675609
{
676610
name: "one optional field",

0 commit comments

Comments
 (0)