github.com/imran-kn/cilium-fork@v1.6.9/pkg/mountinfo/mountinfo_test.go (about) 1 // Copyright 2018 Authors of Cilium 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // +build !privileged_tests 16 17 package mountinfo 18 19 import ( 20 "bytes" 21 "testing" 22 23 "github.com/cilium/cilium/pkg/checker" 24 25 . "gopkg.in/check.v1" 26 ) 27 28 const ( 29 mountInfoContent = `21 68 0:20 / /sys rw,nosuid,nodev,noexec,relatime shared:2 - sysfs sysfs rw 30 22 68 0:4 / /proc rw,nosuid,nodev,noexec,relatime shared:23 - proc proc rw 31 23 68 0:6 / /dev rw,nosuid shared:19 - devtmpfs devtmpfs rw,size=8023924k,nr_inodes=2005981,mode=755 32 24 21 0:7 / /sys/kernel/security rw,nosuid,nodev,noexec,relatime shared:3 - securityfs securityfs rw 33 25 23 0:21 / /dev/shm rw,nosuid,nodev shared:20 - tmpfs tmpfs rw 34 26 23 0:22 / /dev/pts rw,nosuid,noexec,relatime shared:21 - devpts devpts rw,gid=5,mode=620,ptmxmode=000 35 27 68 0:23 / /run rw,nosuid,nodev shared:22 - tmpfs tmpfs rw,mode=755 36 28 21 0:24 / /sys/fs/cgroup ro,nosuid,nodev,noexec shared:4 - tmpfs tmpfs ro,mode=755 37 29 28 0:25 / /sys/fs/cgroup/unified rw,nosuid,nodev,noexec,relatime shared:5 - cgroup2 cgroup rw,nsdelegate 38 30 28 0:26 / /sys/fs/cgroup/systemd rw,nosuid,nodev,noexec,relatime shared:6 - cgroup cgroup rw,xattr,name=systemd 39 31 21 0:27 / /sys/fs/pstore rw,nosuid,nodev,noexec,relatime shared:18 - pstore pstore rw 40 32 28 0:28 / /sys/fs/cgroup/blkio rw,nosuid,nodev,noexec,relatime shared:7 - cgroup cgroup rw,blkio 41 33 28 0:29 / /sys/fs/cgroup/pids rw,nosuid,nodev,noexec,relatime shared:8 - cgroup cgroup rw,pids 42 34 28 0:30 / /sys/fs/cgroup/net_cls,net_prio rw,nosuid,nodev,noexec,relatime shared:9 - cgroup cgroup rw,net_cls,net_prio 43 35 28 0:31 / /sys/fs/cgroup/freezer rw,nosuid,nodev,noexec,relatime shared:10 - cgroup cgroup rw,freezer 44 36 28 0:32 / /sys/fs/cgroup/rdma rw,nosuid,nodev,noexec,relatime shared:11 - cgroup cgroup rw,rdma 45 37 28 0:33 / /sys/fs/cgroup/cpu,cpuacct rw,nosuid,nodev,noexec,relatime shared:12 - cgroup cgroup rw,cpu,cpuacct 46 38 28 0:34 / /sys/fs/cgroup/cpuset rw,nosuid,nodev,noexec,relatime shared:13 - cgroup cgroup rw,cpuset 47 39 28 0:35 / /sys/fs/cgroup/hugetlb rw,nosuid,nodev,noexec,relatime shared:14 - cgroup cgroup rw,hugetlb 48 40 28 0:36 / /sys/fs/cgroup/devices rw,nosuid,nodev,noexec,relatime shared:15 - cgroup cgroup rw,devices 49 41 28 0:37 / /sys/fs/cgroup/perf_event rw,nosuid,nodev,noexec,relatime shared:16 - cgroup cgroup rw,perf_event 50 42 28 0:38 / /sys/fs/cgroup/memory rw,nosuid,nodev,noexec,relatime shared:17 - cgroup cgroup rw,memory 51 68 0 254:1 / / rw,relatime shared:1 - xfs /dev/mapper/system-root rw,attr2,inode64,noquota 52 43 22 0:41 / /proc/sys/fs/binfmt_misc rw,relatime shared:24 - autofs systemd-1 rw,fd=35,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=16155 53 44 23 0:42 / /dev/hugepages rw,relatime shared:25 - hugetlbfs hugetlbfs rw,pagesize=2M 54 45 23 0:19 / /dev/mqueue rw,relatime shared:26 - mqueue mqueue rw 55 46 21 0:8 / /sys/kernel/debug rw,relatime shared:27 - debugfs debugfs rw 56 78 68 8:1 / /boot rw,relatime shared:28 - ext4 /dev/sda1 rw,stripe=4 57 80 68 254:3 / /home rw,relatime shared:29 - xfs /dev/mapper/system-home rw,attr2,inode64,noquota 58 382 27 0:47 / /run/user/463 rw,nosuid,nodev,relatime shared:294 - tmpfs tmpfs rw,size=1606744k,mode=700,uid=463,gid=463 59 472 27 0:48 / /run/user/1000 rw,nosuid,nodev,relatime shared:380 - tmpfs tmpfs rw,size=1606744k,mode=700,uid=1000,gid=100 60 485 21 0:49 / /sys/fs/fuse/connections rw,relatime shared:391 - fusectl fusectl rw 61 497 472 0:50 / /run/user/1000/gvfs rw,nosuid,nodev,relatime shared:401 - fuse.gvfsd-fuse gvfsd-fuse rw,user_id=1000,group_id=100 62 510 46 0:11 / /sys/kernel/debug/tracing rw,relatime shared:412 - tracefs tracefs rw 63 225 472 0:45 / /run/user/1000/doc rw,nosuid,nodev,relatime shared:141 - fuse /dev/fuse rw,user_id=1000,group_id=100 64 655 68 0:100 / /var/lib/docker/overlay2/209d7aafdafc7ebde84cb9f993c1e34cf0376f4f15dae4ddd2dd260b8d987d4d/merged rw,relatime shared:150 - overlay overlay rw,lowerdir=/var/lib/docker/overlay2/l/MX2FFSUOIXOBNUCHC33QEQNNX2:/var/lib/docker/overlay2/l/Q3SPWQ6QMC22TK7SPQOLSVHLUQ:/var/lib/docker/overlay2/l/SPVXNCJEV3EQJGMHEOQGTLNDRT:/var/lib/docker/overlay2/l/EFMD4SE3UNOSVMNMD7EOGIIL5I:/var/lib/docker/overlay2/l/SFK3LVVM7XUXJWRS6I75TSS2DI:/var/lib/docker/overlay2/l/GL3CZA4OB3YI7A6JKWOLVNESSL:/var/lib/docker/overlay2/l/L6OAE4YY2C6BKHH55W42V7T6Y7,upperdir=/var/lib/docker/overlay2/209d7aafdafc7ebde84cb9f993c1e34cf0376f4f15dae4ddd2dd260b8d987d4d/diff,workdir=/var/lib/docker/overlay2/209d7aafdafc7ebde84cb9f993c1e34cf0376f4f15dae4ddd2dd260b8d987d4d/work 65 810 68 0:107 / /var/lib/docker/containers/178dc073e1eb58e137d562d28928a187bdc05905ff889b7658dd7a9b3488e494/mounts/shm rw,nosuid,nodev,noexec,relatime shared:159 - tmpfs shm rw,size=65536k 66 1017 27 0:3 net:[4026532775] /run/docker/netns/85c40bc29e30 rw shared:168 - nsfs nsfs rw 67 969 68 0:117 / /var/lib/docker/overlay2/e35eafd51f5f1e5a1f055de47bfccae6bb47c57317628507bb00b0981d33d717/merged rw,relatime shared:177 - overlay overlay rw,lowerdir=/var/lib/docker/overlay2/l/SRXSWY4NGUH5ZX5EHGZ3R72ZZZ:/var/lib/docker/overlay2/l/4MKSUFUR2WVKNR47LRVGQUHDIX:/var/lib/docker/overlay2/l/CGHCSEQRDDOB7LDRMW6DNKGYKF:/var/lib/docker/overlay2/l/KXCYX6NI6XSXSW3R6YRYOJIXJY:/var/lib/docker/overlay2/l/5SWRNPTBRYPDDHKFPKXBQJ3AGN:/var/lib/docker/overlay2/l/L6OAE4YY2C6BKHH55W42V7T6Y7,upperdir=/var/lib/docker/overlay2/e35eafd51f5f1e5a1f055de47bfccae6bb47c57317628507bb00b0981d33d717/diff,workdir=/var/lib/docker/overlay2/e35eafd51f5f1e5a1f055de47bfccae6bb47c57317628507bb00b0981d33d717/work 68 990 68 0:118 / /var/lib/docker/containers/eb56406256443e41d885581f36a790155bfa7eab49753a3cbeef6c12226fb7eb/mounts/shm rw,nosuid,nodev,noexec,relatime shared:249 - tmpfs shm rw,size=65536k 69 1110 27 0:3 net:[4026532846] /run/docker/netns/35b7f0885825 rw shared:258 - nsfs nsfs rw 70 657 21 0:98 / /sys/fs/bpf rw,relatime shared:267 - bpf bpffs rw` 71 ) 72 73 // Hook up gocheck into the "go test" runner. 74 func Test(t *testing.T) { 75 TestingT(t) 76 } 77 78 type MountInfoTestSuite struct{} 79 80 var _ = Suite(&MountInfoTestSuite{}) 81 82 func (s *MountInfoTestSuite) TestParseMountInfoFile(c *C) { 83 expectedLength := 42 84 expectedMountInfos := []*MountInfo{ 85 { 86 MountID: 21, 87 ParentID: 68, 88 StDev: "0:20", 89 Root: "/", 90 MountPoint: "/sys", 91 MountOptions: "rw,nosuid,nodev,noexec,relatime", 92 OptionalFields: []string{"shared:2"}, 93 FilesystemType: "sysfs", 94 MountSource: "sysfs", 95 SuperOptions: "rw", 96 }, 97 { 98 MountID: 22, 99 ParentID: 68, 100 StDev: "0:4", 101 Root: "/", 102 MountPoint: "/proc", 103 MountOptions: "rw,nosuid,nodev,noexec,relatime", 104 OptionalFields: []string{"shared:23"}, 105 FilesystemType: "proc", 106 MountSource: "proc", 107 SuperOptions: "rw", 108 }, 109 { 110 MountID: 23, 111 ParentID: 68, 112 StDev: "0:6", 113 Root: "/", 114 MountPoint: "/dev", 115 MountOptions: "rw,nosuid", 116 OptionalFields: []string{"shared:19"}, 117 FilesystemType: "devtmpfs", 118 MountSource: "devtmpfs", 119 SuperOptions: "rw,size=8023924k,nr_inodes=2005981,mode=755", 120 }, 121 { 122 MountID: 24, 123 ParentID: 21, 124 StDev: "0:7", 125 Root: "/", 126 MountPoint: "/sys/kernel/security", 127 MountOptions: "rw,nosuid,nodev,noexec,relatime", 128 OptionalFields: []string{"shared:3"}, 129 FilesystemType: "securityfs", 130 MountSource: "securityfs", 131 SuperOptions: "rw", 132 }, 133 { 134 MountID: 25, 135 ParentID: 23, 136 StDev: "0:21", 137 Root: "/", 138 MountPoint: "/dev/shm", 139 MountOptions: "rw,nosuid,nodev", 140 OptionalFields: []string{"shared:20"}, 141 FilesystemType: "tmpfs", 142 MountSource: "tmpfs", 143 SuperOptions: "rw", 144 }, 145 { 146 MountID: 26, 147 ParentID: 23, 148 StDev: "0:22", 149 Root: "/", 150 MountPoint: "/dev/pts", 151 MountOptions: "rw,nosuid,noexec,relatime", 152 OptionalFields: []string{"shared:21"}, 153 FilesystemType: "devpts", 154 MountSource: "devpts", 155 SuperOptions: "rw,gid=5,mode=620,ptmxmode=000", 156 }, 157 { 158 MountID: 27, 159 ParentID: 68, 160 StDev: "0:23", 161 Root: "/", 162 MountPoint: "/run", 163 MountOptions: "rw,nosuid,nodev", 164 OptionalFields: []string{"shared:22"}, 165 FilesystemType: "tmpfs", 166 MountSource: "tmpfs", 167 SuperOptions: "rw,mode=755", 168 }, 169 { 170 MountID: 28, 171 ParentID: 21, 172 StDev: "0:24", 173 Root: "/", 174 MountPoint: "/sys/fs/cgroup", 175 MountOptions: "ro,nosuid,nodev,noexec", 176 OptionalFields: []string{"shared:4"}, 177 FilesystemType: "tmpfs", 178 MountSource: "tmpfs", 179 SuperOptions: "ro,mode=755", 180 }, 181 { 182 MountID: 29, 183 ParentID: 28, 184 StDev: "0:25", 185 Root: "/", 186 MountPoint: "/sys/fs/cgroup/unified", 187 MountOptions: "rw,nosuid,nodev,noexec,relatime", 188 OptionalFields: []string{"shared:5"}, 189 FilesystemType: "cgroup2", 190 MountSource: "cgroup", 191 SuperOptions: "rw,nsdelegate", 192 }, 193 { 194 MountID: 30, 195 ParentID: 28, 196 StDev: "0:26", 197 Root: "/", 198 MountPoint: "/sys/fs/cgroup/systemd", 199 MountOptions: "rw,nosuid,nodev,noexec,relatime", 200 OptionalFields: []string{"shared:6"}, 201 FilesystemType: "cgroup", 202 MountSource: "cgroup", 203 SuperOptions: "rw,xattr,name=systemd", 204 }, 205 { 206 MountID: 31, 207 ParentID: 21, 208 StDev: "0:27", 209 Root: "/", 210 MountPoint: "/sys/fs/pstore", 211 MountOptions: "rw,nosuid,nodev,noexec,relatime", 212 OptionalFields: []string{"shared:18"}, 213 FilesystemType: "pstore", 214 MountSource: "pstore", 215 SuperOptions: "rw", 216 }, 217 { 218 MountID: 32, 219 ParentID: 28, 220 StDev: "0:28", 221 Root: "/", 222 MountPoint: "/sys/fs/cgroup/blkio", 223 MountOptions: "rw,nosuid,nodev,noexec,relatime", 224 OptionalFields: []string{"shared:7"}, 225 FilesystemType: "cgroup", 226 MountSource: "cgroup", 227 SuperOptions: "rw,blkio", 228 }, 229 { 230 MountID: 33, 231 ParentID: 28, 232 StDev: "0:29", 233 Root: "/", 234 MountPoint: "/sys/fs/cgroup/pids", 235 MountOptions: "rw,nosuid,nodev,noexec,relatime", 236 OptionalFields: []string{"shared:8"}, 237 FilesystemType: "cgroup", 238 MountSource: "cgroup", 239 SuperOptions: "rw,pids", 240 }, 241 { 242 MountID: 34, 243 ParentID: 28, 244 StDev: "0:30", 245 Root: "/", 246 MountPoint: "/sys/fs/cgroup/net_cls,net_prio", 247 MountOptions: "rw,nosuid,nodev,noexec,relatime", 248 OptionalFields: []string{"shared:9"}, 249 FilesystemType: "cgroup", 250 MountSource: "cgroup", 251 SuperOptions: "rw,net_cls,net_prio", 252 }, 253 { 254 MountID: 35, 255 ParentID: 28, 256 StDev: "0:31", 257 Root: "/", 258 MountPoint: "/sys/fs/cgroup/freezer", 259 MountOptions: "rw,nosuid,nodev,noexec,relatime", 260 OptionalFields: []string{"shared:10"}, 261 FilesystemType: "cgroup", 262 MountSource: "cgroup", 263 SuperOptions: "rw,freezer", 264 }, 265 { 266 MountID: 36, 267 ParentID: 28, 268 StDev: "0:32", 269 Root: "/", 270 MountPoint: "/sys/fs/cgroup/rdma", 271 MountOptions: "rw,nosuid,nodev,noexec,relatime", 272 OptionalFields: []string{"shared:11"}, 273 FilesystemType: "cgroup", 274 MountSource: "cgroup", 275 SuperOptions: "rw,rdma", 276 }, 277 { 278 MountID: 37, 279 ParentID: 28, 280 StDev: "0:33", 281 Root: "/", 282 MountPoint: "/sys/fs/cgroup/cpu,cpuacct", 283 MountOptions: "rw,nosuid,nodev,noexec,relatime", 284 OptionalFields: []string{"shared:12"}, 285 FilesystemType: "cgroup", 286 MountSource: "cgroup", 287 SuperOptions: "rw,cpu,cpuacct", 288 }, 289 { 290 MountID: 38, 291 ParentID: 28, 292 StDev: "0:34", 293 Root: "/", 294 MountPoint: "/sys/fs/cgroup/cpuset", 295 MountOptions: "rw,nosuid,nodev,noexec,relatime", 296 OptionalFields: []string{"shared:13"}, 297 FilesystemType: "cgroup", 298 MountSource: "cgroup", 299 SuperOptions: "rw,cpuset", 300 }, 301 { 302 MountID: 39, 303 ParentID: 28, 304 StDev: "0:35", 305 Root: "/", 306 MountPoint: "/sys/fs/cgroup/hugetlb", 307 MountOptions: "rw,nosuid,nodev,noexec,relatime", 308 OptionalFields: []string{"shared:14"}, 309 FilesystemType: "cgroup", 310 MountSource: "cgroup", 311 SuperOptions: "rw,hugetlb", 312 }, 313 { 314 MountID: 40, 315 ParentID: 28, 316 StDev: "0:36", 317 Root: "/", 318 MountPoint: "/sys/fs/cgroup/devices", 319 MountOptions: "rw,nosuid,nodev,noexec,relatime", 320 OptionalFields: []string{"shared:15"}, 321 FilesystemType: "cgroup", 322 MountSource: "cgroup", 323 SuperOptions: "rw,devices", 324 }, 325 { 326 MountID: 41, 327 ParentID: 28, 328 StDev: "0:37", 329 Root: "/", 330 MountPoint: "/sys/fs/cgroup/perf_event", 331 MountOptions: "rw,nosuid,nodev,noexec,relatime", 332 OptionalFields: []string{"shared:16"}, 333 FilesystemType: "cgroup", 334 MountSource: "cgroup", 335 SuperOptions: "rw,perf_event", 336 }, 337 { 338 MountID: 42, 339 ParentID: 28, 340 StDev: "0:38", 341 Root: "/", 342 MountPoint: "/sys/fs/cgroup/memory", 343 MountOptions: "rw,nosuid,nodev,noexec,relatime", 344 OptionalFields: []string{"shared:17"}, 345 FilesystemType: "cgroup", 346 MountSource: "cgroup", 347 SuperOptions: "rw,memory", 348 }, 349 { 350 MountID: 68, 351 ParentID: 0, 352 StDev: "254:1", 353 Root: "/", 354 MountPoint: "/", 355 MountOptions: "rw,relatime", 356 OptionalFields: []string{"shared:1"}, 357 FilesystemType: "xfs", 358 MountSource: "/dev/mapper/system-root", 359 SuperOptions: "rw,attr2,inode64,noquota", 360 }, 361 { 362 MountID: 43, 363 ParentID: 22, 364 StDev: "0:41", 365 Root: "/", 366 MountPoint: "/proc/sys/fs/binfmt_misc", 367 MountOptions: "rw,relatime", 368 OptionalFields: []string{"shared:24"}, 369 FilesystemType: "autofs", 370 MountSource: "systemd-1", 371 SuperOptions: "rw,fd=35,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=16155", 372 }, 373 { 374 MountID: 44, 375 ParentID: 23, 376 StDev: "0:42", 377 Root: "/", 378 MountPoint: "/dev/hugepages", 379 MountOptions: "rw,relatime", 380 OptionalFields: []string{"shared:25"}, 381 FilesystemType: "hugetlbfs", 382 MountSource: "hugetlbfs", 383 SuperOptions: "rw,pagesize=2M", 384 }, 385 { 386 MountID: 45, 387 ParentID: 23, 388 StDev: "0:19", 389 Root: "/", 390 MountPoint: "/dev/mqueue", 391 MountOptions: "rw,relatime", 392 OptionalFields: []string{"shared:26"}, 393 FilesystemType: "mqueue", 394 MountSource: "mqueue", 395 SuperOptions: "rw", 396 }, 397 { 398 MountID: 46, 399 ParentID: 21, 400 StDev: "0:8", 401 Root: "/", 402 MountPoint: "/sys/kernel/debug", 403 MountOptions: "rw,relatime", 404 OptionalFields: []string{"shared:27"}, 405 FilesystemType: "debugfs", 406 MountSource: "debugfs", 407 SuperOptions: "rw", 408 }, 409 { 410 MountID: 78, 411 ParentID: 68, 412 StDev: "8:1", 413 Root: "/", 414 MountPoint: "/boot", 415 MountOptions: "rw,relatime", 416 OptionalFields: []string{"shared:28"}, 417 FilesystemType: "ext4", 418 MountSource: "/dev/sda1", 419 SuperOptions: "rw,stripe=4", 420 }, 421 { 422 MountID: 80, 423 ParentID: 68, 424 StDev: "254:3", 425 Root: "/", 426 MountPoint: "/home", 427 MountOptions: "rw,relatime", 428 OptionalFields: []string{"shared:29"}, 429 FilesystemType: "xfs", 430 MountSource: "/dev/mapper/system-home", 431 SuperOptions: "rw,attr2,inode64,noquota", 432 }, 433 { 434 MountID: 382, 435 ParentID: 27, 436 StDev: "0:47", 437 Root: "/", 438 MountPoint: "/run/user/463", 439 MountOptions: "rw,nosuid,nodev,relatime", 440 OptionalFields: []string{"shared:294"}, 441 FilesystemType: "tmpfs", 442 MountSource: "tmpfs", 443 SuperOptions: "rw,size=1606744k,mode=700,uid=463,gid=463", 444 }, 445 { 446 MountID: 472, 447 ParentID: 27, 448 StDev: "0:48", 449 Root: "/", 450 MountPoint: "/run/user/1000", 451 MountOptions: "rw,nosuid,nodev,relatime", 452 OptionalFields: []string{"shared:380"}, 453 FilesystemType: "tmpfs", 454 MountSource: "tmpfs", 455 SuperOptions: "rw,size=1606744k,mode=700,uid=1000,gid=100", 456 }, 457 { 458 MountID: 485, 459 ParentID: 21, 460 StDev: "0:49", 461 Root: "/", 462 MountPoint: "/sys/fs/fuse/connections", 463 MountOptions: "rw,relatime", 464 OptionalFields: []string{"shared:391"}, 465 FilesystemType: "fusectl", 466 MountSource: "fusectl", 467 SuperOptions: "rw", 468 }, 469 { 470 MountID: 497, 471 ParentID: 472, 472 StDev: "0:50", 473 Root: "/", 474 MountPoint: "/run/user/1000/gvfs", 475 MountOptions: "rw,nosuid,nodev,relatime", 476 OptionalFields: []string{"shared:401"}, 477 FilesystemType: "fuse.gvfsd-fuse", 478 MountSource: "gvfsd-fuse", 479 SuperOptions: "rw,user_id=1000,group_id=100", 480 }, 481 { 482 MountID: 510, 483 ParentID: 46, 484 StDev: "0:11", 485 Root: "/", 486 MountPoint: "/sys/kernel/debug/tracing", 487 MountOptions: "rw,relatime", 488 OptionalFields: []string{"shared:412"}, 489 FilesystemType: "tracefs", 490 MountSource: "tracefs", 491 SuperOptions: "rw", 492 }, 493 { 494 MountID: 225, 495 ParentID: 472, 496 StDev: "0:45", 497 Root: "/", 498 MountPoint: "/run/user/1000/doc", 499 MountOptions: "rw,nosuid,nodev,relatime", 500 OptionalFields: []string{"shared:141"}, 501 FilesystemType: "fuse", 502 MountSource: "/dev/fuse", 503 SuperOptions: "rw,user_id=1000,group_id=100", 504 }, 505 { 506 MountID: 655, 507 ParentID: 68, 508 StDev: "0:100", 509 Root: "/", 510 MountPoint: "/var/lib/docker/overlay2/209d7aafdafc7ebde84cb9f993c1e34cf0376f4f15dae4ddd2dd260b8d987d4d/merged", 511 MountOptions: "rw,relatime", 512 OptionalFields: []string{"shared:150"}, 513 FilesystemType: "overlay", 514 MountSource: "overlay", 515 SuperOptions: "rw,lowerdir=/var/lib/docker/overlay2/l/MX2FFSUOIXOBNUCHC33QEQNNX2:/var/lib/docker/overlay2/l/Q3SPWQ6QMC22TK7SPQOLSVHLUQ:/var/lib/docker/overlay2/l/SPVXNCJEV3EQJGMHEOQGTLNDRT:/var/lib/docker/overlay2/l/EFMD4SE3UNOSVMNMD7EOGIIL5I:/var/lib/docker/overlay2/l/SFK3LVVM7XUXJWRS6I75TSS2DI:/var/lib/docker/overlay2/l/GL3CZA4OB3YI7A6JKWOLVNESSL:/var/lib/docker/overlay2/l/L6OAE4YY2C6BKHH55W42V7T6Y7,upperdir=/var/lib/docker/overlay2/209d7aafdafc7ebde84cb9f993c1e34cf0376f4f15dae4ddd2dd260b8d987d4d/diff,workdir=/var/lib/docker/overlay2/209d7aafdafc7ebde84cb9f993c1e34cf0376f4f15dae4ddd2dd260b8d987d4d/work", 516 }, 517 { 518 MountID: 810, 519 ParentID: 68, 520 StDev: "0:107", 521 Root: "/", 522 MountPoint: "/var/lib/docker/containers/178dc073e1eb58e137d562d28928a187bdc05905ff889b7658dd7a9b3488e494/mounts/shm", 523 MountOptions: "rw,nosuid,nodev,noexec,relatime", 524 OptionalFields: []string{"shared:159"}, 525 FilesystemType: "tmpfs", 526 MountSource: "shm", 527 SuperOptions: "rw,size=65536k", 528 }, 529 { 530 MountID: 1017, 531 ParentID: 27, 532 StDev: "0:3", 533 Root: "net:[4026532775]", 534 MountPoint: "/run/docker/netns/85c40bc29e30", 535 MountOptions: "rw", 536 OptionalFields: []string{"shared:168"}, 537 FilesystemType: "nsfs", 538 MountSource: "nsfs", 539 SuperOptions: "rw", 540 }, 541 { 542 MountID: 969, 543 ParentID: 68, 544 StDev: "0:117", 545 Root: "/", 546 MountPoint: "/var/lib/docker/overlay2/e35eafd51f5f1e5a1f055de47bfccae6bb47c57317628507bb00b0981d33d717/merged", 547 MountOptions: "rw,relatime", 548 OptionalFields: []string{"shared:177"}, 549 FilesystemType: "overlay", 550 MountSource: "overlay", 551 SuperOptions: "rw,lowerdir=/var/lib/docker/overlay2/l/SRXSWY4NGUH5ZX5EHGZ3R72ZZZ:/var/lib/docker/overlay2/l/4MKSUFUR2WVKNR47LRVGQUHDIX:/var/lib/docker/overlay2/l/CGHCSEQRDDOB7LDRMW6DNKGYKF:/var/lib/docker/overlay2/l/KXCYX6NI6XSXSW3R6YRYOJIXJY:/var/lib/docker/overlay2/l/5SWRNPTBRYPDDHKFPKXBQJ3AGN:/var/lib/docker/overlay2/l/L6OAE4YY2C6BKHH55W42V7T6Y7,upperdir=/var/lib/docker/overlay2/e35eafd51f5f1e5a1f055de47bfccae6bb47c57317628507bb00b0981d33d717/diff,workdir=/var/lib/docker/overlay2/e35eafd51f5f1e5a1f055de47bfccae6bb47c57317628507bb00b0981d33d717/work", 552 }, 553 { 554 MountID: 990, 555 ParentID: 68, 556 StDev: "0:118", 557 Root: "/", 558 MountPoint: "/var/lib/docker/containers/eb56406256443e41d885581f36a790155bfa7eab49753a3cbeef6c12226fb7eb/mounts/shm", 559 MountOptions: "rw,nosuid,nodev,noexec,relatime", 560 OptionalFields: []string{"shared:249"}, 561 FilesystemType: "tmpfs", 562 MountSource: "shm", 563 SuperOptions: "rw,size=65536k", 564 }, 565 { 566 MountID: 1110, 567 ParentID: 27, 568 StDev: "0:3", 569 Root: "net:[4026532846]", 570 MountPoint: "/run/docker/netns/35b7f0885825", 571 MountOptions: "rw", 572 OptionalFields: []string{"shared:258"}, 573 FilesystemType: "nsfs", 574 MountSource: "nsfs", 575 SuperOptions: "rw", 576 }, 577 { 578 MountID: 657, 579 ParentID: 21, 580 StDev: "0:98", 581 Root: "/", 582 MountPoint: "/sys/fs/bpf", 583 MountOptions: "rw,relatime", 584 OptionalFields: []string{"shared:267"}, 585 FilesystemType: "bpf", 586 MountSource: "bpffs", 587 SuperOptions: "rw", 588 }, 589 } 590 591 r := bytes.NewBuffer([]byte(mountInfoContent)) 592 mountInfos, err := parseMountInfoFile(r) 593 c.Assert(err, IsNil) 594 c.Assert(mountInfos, HasLen, expectedLength) 595 c.Assert(mountInfos, checker.DeepEquals, expectedMountInfos) 596 } 597 598 func (s *MountInfoTestSuite) TestGetMountInfo(c *C) { 599 _, err := GetMountInfo() 600 c.Assert(err, IsNil) 601 } 602 603 // TestIsMountFSPrivate tests the private function isMountFS which expects 604 // mountinfo to be provided as a slice. 605 func (s *MountInfoTestSuite) TestIsMountFSPrivate(c *C) { 606 r := bytes.NewBuffer([]byte(mountInfoContent)) 607 mountInfos, err := parseMountInfoFile(r) 608 c.Assert(err, IsNil) 609 610 // /sys/fs/bpffs should be recognized as a BPFFS mount. 611 mounted, bpffsInstance := isMountFS(mountInfos, FilesystemTypeBPFFS, "/sys/fs/bpf") 612 c.Assert(mounted, Equals, true) 613 c.Assert(bpffsInstance, Equals, true) 614 615 // /sys/fs/cgroup/unified should be recognized as a cgroup2 mount. 616 mounted, cgroup2Instance := isMountFS(mountInfos, FilesystemTypeCgroup2, "/sys/fs/cgroup/unified") 617 c.Assert(mounted, Equals, true) 618 c.Assert(cgroup2Instance, Equals, true) 619 620 // /run/user/463 should be recognized as a mount, but not of BPFFS type. 621 mounted, bpffsInstance = isMountFS(mountInfos, FilesystemTypeBPFFS, "/run/user/463") 622 c.Assert(mounted, Equals, true) 623 c.Assert(bpffsInstance, Equals, false) 624 625 // /foo/bar shouldn't be found in mountinfo. 626 mounted, bpffsInstance = isMountFS(mountInfos, FilesystemTypeBPFFS, "/foo/bar") 627 c.Assert(mounted, Equals, false) 628 c.Assert(bpffsInstance, Equals, false) 629 } 630 631 // TestIsMountFS tests the public funcion IsMountFS which gets mountinfo from 632 // /proc/self/mountinfo. We cannot expect every system and machine to have any 633 // predictable mounts. The only thing which can be checked is whether there is 634 // no error returned by mountinfo parser. 635 func (s *MountInfoTestSuite) TestIsMountFS(c *C) { 636 _, _, err := IsMountFS(FilesystemTypeBPFFS, "/sys/fs/bpf") 637 c.Assert(err, IsNil) 638 }