-
Notifications
You must be signed in to change notification settings - Fork 872
Try to patch inotify #4672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Try to patch inotify #4672
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ import ( | |
| "os" | ||
| "path/filepath" | ||
| "reflect" | ||
| "time" | ||
|
|
||
| "github.com/sirupsen/logrus" | ||
| "google.golang.org/protobuf/types/known/timestamppb" | ||
|
|
@@ -48,13 +49,11 @@ func New(ctx context.Context, ticker ticker.Ticker, runtimeDir string) (Agent, e | |
| var _ Agent = (*agent)(nil) | ||
|
|
||
| type agent struct { | ||
| // Ticker is like time.Ticker. | ||
| // We can't use inotify for /proc/net/tcp, so we need this ticker to | ||
| // reload /proc/net/tcp. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why remove? |
||
| ticker ticker.Ticker | ||
| socketLister *sockets.Lister | ||
| kubernetesServiceWatcher *kubernetesservice.ServiceWatcher | ||
| runtimeDir string | ||
| recentChtimes map[string]time.Time | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs a comment line to explain the key |
||
| } | ||
|
|
||
| type eventState struct { | ||
|
|
@@ -211,13 +210,39 @@ func (a *agent) Info(ctx context.Context) (*api.Info, error) { | |
|
|
||
| func (a *agent) HandleInotify(event *api.Inotify) { | ||
| location := event.MountPath | ||
| if _, err := os.Stat(location); err == nil { | ||
| local := event.Time.AsTime().Local() | ||
| err := os.Chtimes(location, local, local) | ||
| if err != nil { | ||
| logrus.Errorf("error in inotify handle. Event: %s, Error: %s", event, err) | ||
| fi, err := os.Stat(location) | ||
| if err != nil { | ||
| return | ||
| } | ||
| if fi.IsDir() { | ||
| return | ||
| } | ||
|
|
||
| now := time.Now() | ||
|
|
||
| // If we called Chtimes on this path recently, this is an echo: | ||
| // our Chtimes → virtiofs → macOS FSEvents → host agent → back here. | ||
| // Skip to prevent reload loops and reduce virtiofs traffic. | ||
| if lastTouch, ok := a.recentChtimes[location]; ok { | ||
| if now.Sub(lastTouch) < time.Second { | ||
| return | ||
| } | ||
| } | ||
|
|
||
| local := event.Time.AsTime().Local() | ||
| if err := os.Chtimes(location, local, local); err != nil { | ||
| logrus.Errorf("error in inotify handle. Event: %s, Error: %s", event, err) | ||
| } | ||
|
|
||
| if a.recentChtimes == nil { | ||
| a.recentChtimes = make(map[string]time.Time) | ||
| } | ||
| a.recentChtimes[location] = now | ||
|
|
||
| // Prevent unbounded growth during bulk operations | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use LRU algorithm or something? |
||
| if len(a.recentChtimes) > 10000 { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 10000 should be defined as a const |
||
| a.recentChtimes = make(map[string]time.Time) | ||
| } | ||
| } | ||
|
|
||
| func (a *agent) Close() error { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.