Skip to content

Commit

Permalink
Merge pull request #1807 from dashpole/revert_1760
Browse files Browse the repository at this point in the history
Revert "fix #1708; move from inotify to fsnotify"
  • Loading branch information
dashpole authored Nov 17, 2017
2 parents 577f63f + 6988e70 commit a27bed7
Show file tree
Hide file tree
Showing 24 changed files with 372 additions and 2,302 deletions.
17 changes: 8 additions & 9 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions container/common/inotify_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ package common
import (
"sync"

"github.com/fsnotify/fsnotify"
"golang.org/x/exp/inotify"
)

// Watcher for container-related fsnotify events in the cgroup hierarchy.
// Watcher for container-related inotify events in the cgroup hierarchy.
//
// Implementation is thread-safe.
type InotifyWatcher struct {
// Underlying fsnotify watcher.
watcher *fsnotify.Watcher
// Underlying inotify watcher.
watcher *inotify.Watcher

// Map of containers being watched to cgroup paths watched for that container.
containersWatched map[string]map[string]bool
Expand All @@ -35,7 +35,7 @@ type InotifyWatcher struct {
}

func NewInotifyWatcher() (*InotifyWatcher, error) {
w, err := fsnotify.NewWatcher()
w, err := inotify.NewWatcher()
if err != nil {
return nil, err
}
Expand All @@ -53,9 +53,9 @@ func (iw *InotifyWatcher) AddWatch(containerName, dir string) (bool, error) {

cgroupsWatched, alreadyWatched := iw.containersWatched[containerName]

// Register an fsnotify notification.
// Register an inotify notification.
if !cgroupsWatched[dir] {
err := iw.watcher.Add(dir)
err := iw.watcher.AddWatch(dir, inotify.IN_CREATE|inotify.IN_DELETE|inotify.IN_MOVE)
if err != nil {
return alreadyWatched, err
}
Expand Down Expand Up @@ -84,9 +84,9 @@ func (iw *InotifyWatcher) RemoveWatch(containerName, dir string) (bool, error) {
return false, nil
}

// Remove the fsnotify watch if it exists.
// Remove the inotify watch if it exists.
if cgroupsWatched[dir] {
err := iw.watcher.Remove(dir)
err := iw.watcher.RemoveWatch(dir)
if err != nil {
return false, nil
}
Expand All @@ -104,15 +104,15 @@ func (iw *InotifyWatcher) RemoveWatch(containerName, dir string) (bool, error) {

// Errors are returned on this channel.
func (iw *InotifyWatcher) Error() chan error {
return iw.watcher.Errors
return iw.watcher.Error
}

// Events are returned on this channel.
func (iw *InotifyWatcher) Event() chan fsnotify.Event {
return iw.watcher.Events
func (iw *InotifyWatcher) Event() chan *inotify.Event {
return iw.watcher.Event
}

// Closes the fsnotify watcher.
// Closes the inotify watcher.
func (iw *InotifyWatcher) Close() error {
return iw.watcher.Close()
}
Expand Down
16 changes: 9 additions & 7 deletions manager/watcher/raw/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import (
"github.com/google/cadvisor/container/libcontainer"
"github.com/google/cadvisor/manager/watcher"

"github.com/fsnotify/fsnotify"
"github.com/golang/glog"
"golang.org/x/exp/inotify"
)

type rawContainerWatcher struct {
Expand Down Expand Up @@ -121,7 +121,7 @@ func (self *rawContainerWatcher) watchDirectory(dir string, containerName string
if cleanup {
_, err := self.watcher.RemoveWatch(containerName, dir)
if err != nil {
glog.Warningf("Failed to remove fsnotify watch for %q: %v", dir, err)
glog.Warningf("Failed to remove inotify watch for %q: %v", dir, err)
}
}
}()
Expand Down Expand Up @@ -152,16 +152,18 @@ func (self *rawContainerWatcher) watchDirectory(dir string, containerName string
return alreadyWatching, nil
}

func (self *rawContainerWatcher) processEvent(event fsnotify.Event, events chan watcher.ContainerEvent) error {
// Convert the fsnotify event type to a container create or delete.
func (self *rawContainerWatcher) processEvent(event *inotify.Event, events chan watcher.ContainerEvent) error {
// Convert the inotify event type to a container create or delete.
var eventType watcher.ContainerEventType
switch {
case event.Op == fsnotify.Create:
case (event.Mask & inotify.IN_CREATE) > 0:
eventType = watcher.ContainerAdd
case event.Op == fsnotify.Remove:
case (event.Mask & inotify.IN_DELETE) > 0:
eventType = watcher.ContainerDelete
case event.Op == fsnotify.Rename:
case (event.Mask & inotify.IN_MOVED_FROM) > 0:
eventType = watcher.ContainerDelete
case (event.Mask & inotify.IN_MOVED_TO) > 0:
eventType = watcher.ContainerAdd
default:
// Ignore other events.
return nil
Expand Down
14 changes: 7 additions & 7 deletions utils/tail/tail.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
"sync"
"time"

"github.com/fsnotify/fsnotify"
"github.com/golang/glog"
"golang.org/x/exp/inotify"
)

type Tail struct {
Expand All @@ -35,7 +35,7 @@ type Tail struct {
filename string
file *os.File
stop chan bool
watcher *fsnotify.Watcher
watcher *inotify.Watcher
}

const (
Expand All @@ -60,9 +60,9 @@ func newTail(filename string) (*Tail, error) {
}
var err error
t.stop = make(chan bool)
t.watcher, err = fsnotify.NewWatcher()
t.watcher, err = inotify.NewWatcher()
if err != nil {
return nil, fmt.Errorf("fsnotify init failed on %s: %v", t.filename, err)
return nil, fmt.Errorf("inotify init failed on %s: %v", t.filename, err)
}
// Initialize readerErr as io.EOF, so that the reader can work properly
// during initialization.
Expand Down Expand Up @@ -141,15 +141,15 @@ func (t *Tail) watchFile() error {
defer t.file.Close()

watchDir := filepath.Dir(t.filename)
err = t.watcher.Add(watchDir)
err = t.watcher.AddWatch(watchDir, inotify.IN_MOVED_FROM|inotify.IN_DELETE)
if err != nil {
return fmt.Errorf("Failed to add watch to directory %s: %v", watchDir, err)
}
defer t.watcher.Remove(watchDir)
defer t.watcher.RemoveWatch(watchDir)

for {
select {
case event := <-t.watcher.Events:
case event := <-t.watcher.Event:
eventPath := filepath.Clean(event.Name) // Directory events have an extra '/'
if eventPath == t.filename {
glog.V(4).Infof("Log file %s moved/deleted", t.filename)
Expand Down
5 changes: 0 additions & 5 deletions vendor/github.com/fsnotify/fsnotify/.editorconfig

This file was deleted.

6 changes: 0 additions & 6 deletions vendor/github.com/fsnotify/fsnotify/.gitignore

This file was deleted.

30 changes: 0 additions & 30 deletions vendor/github.com/fsnotify/fsnotify/.travis.yml

This file was deleted.

46 changes: 0 additions & 46 deletions vendor/github.com/fsnotify/fsnotify/AUTHORS

This file was deleted.

Loading

0 comments on commit a27bed7

Please sign in to comment.