- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 939
Inotify #39
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
Inotify #39
Conversation
to checks internal maps len
fail in checking maps len
inotify(7): IN_IGNORED Watch was removed explicitly (inotify_rm_watch(2)) or automatically (file was deleted, or file system was unmounted). watches is removed in ignoreLinux() and paths too. introduce condv to sync Remove() with ignoreLinux().
to finish go routine.
} | ||
event = &syscall.EpollEvent{syscall.EPOLLIN, int32(rp.Fd()), 0} |
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.
I'm not familiar with this stuff. Some comments would help.
So you're setting up epoll on the file descriptor for inotify events... and then this os.Pipe() file descriptor as well
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.
So you know though readEvents() blocks so that we need to break it to close gracefully.
epoll can be used which descriptor can be handled from which it was registerd like select(2)
but FdSet which is params of syscall.Select() has no handling function - FD_SET macro.
I introduced epoll and os.Pipe() just notifying to epoll that watcher.Close() method is called.
The flow is - watcher.Close() send bool through watcher.done channel, inline go routine receives it and closes the pipe, then epoll notices the pipe is closed and breaks loop, returns.
Introducing epoll seems overdoing but I could not find more better way, sorry.
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.
It might be just the right thing, I'm just still learning Linux stuff since taking over maintenance of the project. Thanks for explaining the choice of epoll rather than select.
I do want to make sure that the code is understandable and maintainable going forward.
Before I merge this in, take a look at #5 and the links to when @howeyc added and remove select(). Let me know what you think.
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.
it seems that FD_ macros were wrong. using original, 660b1c4 did not work but refering http://play.golang.org/p/rIuaDUzLXw, 0ab96cb worked. I will rewrite using select, timeout if you prefer.
By the way patches I've posted has strange EOF handling and needs a bit clean up, could you let me rewrite it? you can see these chamaken@d6718be#diff-9dee340ab29d1c1db9e272db38706348 and chamaken@3687df3#diff-9dee340ab29d1c1db9e272db38706348
Thanks for working on this @chamaken. I left a few comments. |
handle as same as another error.
Feel free to add more commits here or open a new pull request. Epoll vs. select is up to you. Whichever works better. Thanks @chamaken |
I close and reopen by mistake, sorry.
would you, maintainer decide which one is suitable? |
@chamaken I'm not familiar with either, so I don't know. We could try epoll and see how it goes. We could also request a code review from people on golang-nuts and see what we get back? |
I agree. Thank you for your suggestion. @nathany |
// Watcher watches a set of files, delivering events to a channel. | ||
type Watcher struct { | ||
Events chan Event | ||
Errors chan error | ||
mu sync.Mutex // Map access | ||
cv *sync.Cond // sync removing on rm_watch with IN_IGNORE |
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.
It looks like it needs to be gofmt
ed.
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.
I don't mind doing minor cleanup as part of my merging process. More concerned with functionality, structure and maintainability.
Of course, running gofmt and checking for typos is always appreciated. :-)
@chamaken Since I don't know when I'll read my Linux book and figure this stuff out, I put out a request for code review on golang-nuts. |
Thanks to shurcooL, I was able to grasp I should gofmt.
Sorry for letting this sit for so long. Even though this isn't changing the API, I'm beginning to think that such big internal changes should also warrant a new major version and a release candidate, which is something gopkg.in is considering support for: niemeyer/gopkg#25. I'm still figuring out exactly what this should look like. |
Thank you for telling me. @nathany |
inotify(7) says: When all file descriptors referring to an inotify instance have been closed, the underlying object and its resources are freed for reuse by the kernel; all associated watches are automatically freed.
I had forgotten.
Hi @chamaken, I think this is too big of a change for right now. Personally, I still haven't had a chance to learn the various Linux APIs nor have I been able to attract others to help code review and maintain the project. If you're interested in helping make some smaller incremental improvements, I'd certainly be grateful. Right now I'm trying to focus on cleaning up the code (see 1f65e2e) so that lower-level concerns are more isolated. I'm also trying to get an fslog project going to help better understand the behaviour of each OS. Thanks for all your work. Nathan. |
I think I could fix an inotify issue - https://code.google.com/p/go/issues/detail?id=2483
see https://github.com/chamaken/inotify
And then I am glad if I can backport it to your fsnotify. Would you review the patchs?