Skip to content

Commit 1456f0a

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 5447519 commit 1456f0a

File tree

2 files changed

+9
-21
lines changed

2 files changed

+9
-21
lines changed

Diff for: mountinfo/mountinfo_linux.go

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

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

7868
major, minor, ok := strings.Cut(fields[2], ":")

Diff for: mountinfo/mountinfo_linux_test.go

+7-9
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
@@ -420,7 +419,7 @@ const (
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`
421420

422421
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
422+
31 21 0:23 / /DATA/foo_bla_bla rw,relatime - cifs //foo/BLA\040BLA\040BLA/ rw,sec=ntlm,cache=loose,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
424423
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`
425424
)
426425

@@ -434,7 +433,7 @@ func TestParseMountInfo(t *testing.T) {
434433
{
435434
name: "fedora",
436435
info: fedoraMountinfo,
437-
expectedLength: 58,
436+
expectedLength: 57,
438437
mi: &Info{
439438
ID: 15,
440439
Parent: 35,
@@ -562,7 +561,7 @@ func TestParseMountinfoWithSpaces(t *testing.T) {
562561
Optional: "",
563562
FSType: "cifs",
564563
Source: `//foo/BLA BLA BLA/`,
565-
VFSOptions: `rw,sec=ntlm,cache=loose,unc=\\foo\BLA`,
564+
VFSOptions: `rw,sec=ntlm,cache=loose,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`,
566565
},
567566
{
568567
ID: 649,
@@ -667,10 +666,9 @@ func TestParseMountinfoExtraCases(t *testing.T) {
667666
valid: false,
668667
},
669668
{
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"},
669+
name: "extra fields at the end (kernel < 3.10 bug)",
670+
entry: `251 15 0:3573 / /mnt/point rw,relatime - aufs none rw,unc=buggy pre-kernel 3.10 data`,
671+
valid: false,
674672
},
675673
{
676674
name: "one optional field",

0 commit comments

Comments
 (0)