Getting File Create Notifications for CIFS Mount in Linux

核能气质少年 提交于 2019-11-30 23:29:29

问题


I have a windows share mounted via CIFS on an ubuntu server. I need to a way to know when a new file has been added to the Windows share. I tried this inotify program:

http://www.thegeekstuff.com/2010/04/inotify-c-program-example/

Which works fine with standard directories, but is unable to catch any CIFS changes. I don't neccessarily need to use inotify, although I would like to, but any suggestions on how to accomplish getting file create notifications would be great.


回答1:


I have also been working on this and ran into the same issue - it seems (after a little trawling on google) that, unfortunately, it is not possible to use inotify on CIFS mounted partitions - The following was in a redhat forum post from a couple of years ago:

"Currently, no this isn't possible with CIFS. The VFS hooks to allow a filesystem to set up extra notfications were removed recently. The only "user" of them was CIFS and it never worked properly anyway. The kernel interface for this had serious problems too.

I think Steve has plans to reimplement it, but it's a major project that means adding new functionality to the VFS layer of the kernel."

While this was a couple of years ago, it seems we are no closer to having this facility available - shame, I could have really used it too!




回答2:


I too ran into this and reached the same conclusion as Stephen Sullivan (CIFS + inotify = no go).

However, since my workflow happened to depend on both remote mounts and auto-compile tools that rely on inotify, I ended up building a (fairly desperate & hacky) solution which basically just uses polling to watch for changes and then touches the same files again on the mounted side, which does seem to fire off inotify events. It is not my proudest moment.

Having said that, it does work, so, enjoy: http://github.com/rubyruy/watchntouch




回答3:


It can be done.. sort of

If you set up an webdav server and include the share as webdav location, you can monitor the location on you samba server while accessing it through webdav from your windows machine.

The big problem with this is that file permissions are a b*tch... as usual with apache2 webdav since its missing pass-through authentication




回答4:


For Windows hosts running Linux docker containers there is a detailed article on t his issue with a provided solution that works "docker-windows-volume-watcher": http://blog.subjectify.us/miscellaneous/2017/04/24/docker-for-windows-watch-bindings.html

Looks like support is not coming any time soon from Linux implementation of CIFS inotify.



来源:https://stackoverflow.com/questions/8124617/getting-file-create-notifications-for-cifs-mount-in-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!