在 Linux 中获取 CIFS 挂载的文件创建通知
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8124617/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting File Create Notifications for CIFS Mount in Linux
提问by ofosho
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:
我在 ubuntu 服务器上通过 CIFS 安装了一个 Windows 共享。我需要一种方法来知道何时将新文件添加到 Windows 共享中。我试过这个 inotify 程序:
http://www.thegeekstuff.com/2010/04/inotify-c-program-example/
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.
它适用于标准目录,但无法捕获任何 CIFS 更改。我不一定需要使用 inotify,虽然我很想,但任何关于如何完成获取文件创建通知的建议都会很棒。
回答by Stephen Sullivan
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:
我也一直在研究这个并遇到了同样的问题 - 似乎(在谷歌上进行了一些搜索之后),不幸的是,不可能在 CIFS 挂载分区上使用 inotify - 以下是来自一个红帽论坛的帖子几年前:
"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."
“目前,CIFS 不可能做到这一点。最近删除了允许文件系统设置额外通知的 VFS 钩子。它们唯一的“用户”是 CIFS,无论如何它从来没有正常工作过。为此的内核接口有问题也很严重。
我认为史蒂夫已经计划重新实现它,但这是一个重大项目,意味着向内核的 VFS 层添加新功能。”
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!
虽然这是几年前的事,但似乎我们离拥有这个设施不远了 - 可惜,我也可以真正使用它!
回答by rubyruy
I too ran into this and reached the same conclusion as Stephen Sullivan (CIFS + inotify = no go).
我也遇到了这个问题,并得出了与 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 doesseem to fire off inotify events. It is not my proudest moment.
但是,由于我的工作流程碰巧同时依赖于依赖 inotify 的远程挂载和自动编译工具,因此我最终构建了一个(相当绝望和 hacky)解决方案,该解决方案基本上只是使用轮询来监视更改,然后再次接触相同的文件在安装方面,它也似乎火了inotify事件。这不是我最自豪的时刻。
Having said that, it does work, so, enjoy: http://github.com/rubyruy/watchntouch
话虽如此,它确实有效,所以,请享受:http: //github.com/rubyruy/watchntouch
回答by Peter Elzinga
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.
如果您设置了 webdav 服务器并将共享包含为 webdav 位置,则可以在从 Windows 机器通过 webdav 访问时监视 samba 服务器上的位置。
The big problem with this is that file permissions are a b*tch... as usual with apache2 webdav since its missing pass-through authentication
最大的问题是文件权限是 ab*tch... 与 apache2 webdav 一样,因为它缺少直通身份验证
回答by MyUserInStackOverflow
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
对于运行 Linux docker 容器的 Windows 主机,有一篇关于他的问题的详细文章,提供的解决方案适用于“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.
看起来 CIFS inotify 的 Linux 实现不会很快提供支持。
回答by RickS
Old topic, still important! My answer to this is: "it depends!". From my empirical tests at this time, the behavior is quite clear. If the Linux host initiates the filesystem event [upon a CIFS mount], then inotify will see it just fine. If the Windows machine which hosts the CIFS mount initiates the filesystem event, then inotify [on the Linux machine] will not see it at all.
老话题,依旧重要!我对此的回答是:“视情况而定!”。从我此时的经验测试来看,行为非常清楚。如果 Linux 主机 [在 CIFS 挂载时] 启动文件系统事件,那么 inotify 会看到它就好了。如果承载 CIFS 挂载的 Windows 机器启动文件系统事件,那么 inotify [在 Linux 机器上] 根本看不到它。
If your goal is for the Linux host to get notification that the Windows host created or wrote to a file, then you are out of luck. Since this is probably the most desired use of this mechanism, it does make this subtle "it depends" answer not so terribly useful!
如果您的目标是让 Linux 主机收到 Windows 主机创建或写入文件的通知,那么您就不走运了。由于这可能是这种机制最理想的用途,它确实使这个微妙的“取决于”答案没有那么有用!