@@ -98,7 +98,7 @@ type Container struct {
98
98
99
99
oomKills int
100
100
101
- mountIds map [string ]struct {}
101
+ mounts map [string ]proc. MountInfo
102
102
103
103
nsIPs []netaddr.IP
104
104
@@ -136,7 +136,7 @@ func NewContainer(cg *cgroup.Cgroup, md *ContainerMetadata, hostConntrack *Connt
136
136
retransmits : map [AddrPair ]int64 {},
137
137
l7Stats : map [ebpftracer.L7Protocol ]map [AddrPair ]* L7Stats {},
138
138
139
- mountIds : map [string ]struct {} {},
139
+ mounts : map [string ]proc. MountInfo {},
140
140
141
141
logParsers : map [string ]* LogParser {},
142
142
@@ -360,13 +360,30 @@ func (c *Container) onProcessExit(pid uint32, oomKill bool) {
360
360
361
361
func (c * Container ) onFileOpen (pid uint32 , fd uint64 ) {
362
362
mntId , logPath := resolveFd (pid , fd )
363
- c .lock .Lock ()
364
- defer c .lock .Unlock ()
365
- if mntId != "" {
366
- c .mountIds [mntId ] = struct {}{}
367
- }
363
+ func () {
364
+ if mntId == "" {
365
+ return
366
+ }
367
+ c .lock .Lock ()
368
+ _ , ok := c .mounts [mntId ]
369
+ c .lock .Unlock ()
370
+ if ok {
371
+ return
372
+ }
373
+ byMountId := proc .GetMountInfo (pid )
374
+ if byMountId == nil {
375
+ return
376
+ }
377
+ if mi , ok := byMountId [mntId ]; ok {
378
+ c .lock .Lock ()
379
+ c .mounts [mntId ] = mi
380
+ c .lock .Unlock ()
381
+ }
382
+ }()
368
383
if logPath != "" {
384
+ c .lock .Lock ()
369
385
c .runLogParser (logPath )
386
+ c .lock .Unlock ()
370
387
}
371
388
}
372
389
@@ -571,24 +588,11 @@ func (c *Container) updateDelays() {
571
588
}
572
589
573
590
func (c * Container ) getMounts () map [string ]map [string ]* proc.FSStat {
574
- mounts := map [string ]proc.MountInfo {}
575
- for p := range c .pids {
576
- mi := proc .GetMountInfo (p )
577
- if mi != nil {
578
- mounts = mi
579
- break
580
- }
581
- }
582
- for mountId := range mounts {
583
- if _ , ok := c .mountIds [mountId ]; ! ok {
584
- delete (mounts , mountId )
585
- }
586
- }
587
- if len (mounts ) == 0 {
591
+ if len (c .mounts ) == 0 {
588
592
return nil
589
593
}
590
594
res := map [string ]map [string ]* proc.FSStat {}
591
- for _ , mi := range mounts {
595
+ for _ , mi := range c . mounts {
592
596
var stat * proc.FSStat
593
597
for pid := range c .pids {
594
598
s , err := proc .StatFS (proc .Path (pid , "root" , mi .MountPoint ))
0 commit comments