用NFS进行化 [英] inotify with NFS

查看:124
本文介绍了用NFS进行化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近使用inotify创建了一个保管箱系统,监视在特定目录中创建的文件.我正在查看的目录是从NFS服务器挂载的,并且inotify的行为与我预期的不同.考虑以下情形,其中inotify脚本在机器A上运行,并观看/some/nfs/dir/also/visible/to/B.

I've recently created a dropbox system using inotify, watching for files created in a particular directory. The directory I'm watching is mounted from an NFS server, and inotify is behaving differently than I'd expect. Consider the following scenario in which an inotify script is run on machine A, watching /some/nfs/dir/also/visible/to/B.

-使用机器A在/some/nfs/dir/also/visible/to/B中创建文件,脚本的行为符合预期.使用计算机B进行相同的操作,不会通知脚本有关目录中放置的新文件的信息.
-当脚本在NFS服务器上运行时,从计算机A和计算机B创建文件时都会收到通知.

-Using machine A to create a file in /some/nfs/dir/also/visible/to/B, the script behaves as expected. Using machine B to carry out the same action, the script is not notified about a new file dropped in the directory.
-When the script is run on the NFS server, it gets notified when files are created from both machine A and machine B.

这是我用来访问inotofy的软件包中的错误中的错误,还是这是预期的行为?

Is this a bug in the bug in the package I'm using to access inotofy, or is this expected behaviour?

推荐答案

inotify需要内核的支持才能起作用.当应用程序跟踪目录时,它会要求内核在发生这些更改时通知它.发生更改时,内核除了将这些更改写入磁盘外,还通知监视过程.

inotify requires support from the kernel to work. When an application tracks a directory, it asks the kernel to inform it when those changes occur. When the change occurs, in addition to writing those changes to disk, the kernel also notifies the watching process.

在远程NFS机器上,内核看不到更改;它完全是远程发生的. NFS早于inotify,并且NFS或任何等效版本均不对其提供网络级别的支持.

On a remote NFS machine, the change is not visible to the kernel; it happens entirely remotely. NFS predates inotify and there is no network level support for it in NFS, or anything equivalent.

如果要解决此问题,可以在存储服务器上运行服务(因为内核将始终看到文件系统的更改),该服务代理为远程计算机请求的内容,然后将数据转发到远程客户端.

If you want to get around this, You can run a service on the storage server (since that kernel will always see changes to the filesystem) that brokers inotify requests for remote machines, and forward the data to the remote clients.

对于我来说, NFS 应该是指责它缺乏对inotify的支持.

It seems odd to me that NFS should be blamed for its lack of support for inotify.

网络文件系统(NFS)是最初由 Sun Microsystems于1984年开发的一种分布式文件系统协议,维基百科文章

Network File System (NFS) is a distributed file system protocol originally developed by Sun Microsystems in 1984, wikipedia article

但是:

Inotify(inode通知)是一个 Linux内核子系统,用于扩展文件系统以注意到文件系统的更改. [...]它已包含在2.6.13版(6月18日, 2005 )中的主线Linux内核中.[...] 维基百科文章

Inotify (inode notify) is a Linux kernel subsystem that acts to extend filesystems to notice changes to the filesystem. [...] It has been included in the mainline Linux kernel from release 2.6.13 (June 18, 2005 ) [...]. wikipedia article

很难期望便携式网络协议/应用程序支持为不同的操作系统开发的特定内核功能,这种功能在二十多年后出现了.即使它 did 包括扩展名,它们在其他操作系统上也不可用.

It's hard to expect a portable network protocol/application to support a specific kernel feature developed for a different operating system and that appeared more than twenty years later. Even if it did include extensions for it, they would not be available or useful on other operating systems.

*在所有情况下都强调我的权利

与此有关的另一个问题;假设我们根本不使用网络,而是使用具有良好inotify支持的本地文件系统:ext3(假设其安装在/mnt/foo处).但是,文件系统是从回送设备挂载的,而不是实际磁盘.然后可以在vfs中的其他位置(例如/var/images/foo.img)访问基础文件.

Another problem with this; Lets suppose we are not using a network at all, but rather, a local filesystem with good inotify support: ext3 (suppose its mounted at /mnt/foo). But instead of a real disk, the filesystem is mounted from a loopback device ; and the underlying file is in turn accessible at a different location in the vfs (say, /var/images/foo.img).

现在,您不应该修改已挂载的ext3文件系统,但是如果更改是文件内容而不是元数据,这样做仍然是相当安全的.

Now, you're not supposed to modify mounted ext3 filesystems, But it's still reasonably safe to do so if the change is to file contents instead of metadata.

因此,假设一个聪明的用户在十六进制编辑器中修改了文件系统映像(/var/images/foo.img),用其他一些数据替换了文件的内容,而同时inotify监视程序正在观察已挂载的文件系统上的相同文件.

So suppose a clever user modifies the file system image (/var/images/foo.img) in a hex editor, replacing a file's contents with some other data, while at the same time an inotify watch is observing the same file on the mounted filesystem.

没有一种合理的方法可以安排inotify始终将这种变化告知观看过程.尽管可能需要一些回旋来引起ext3的注意并兑现更改,但是这些都不适用于xfs drtiver,否则它非常相似.

There's no reasonable way one can arrange for inotify to always inform the watching process of this sort of change. Although there are probably some gyrations that could be take to make ext3 notice and honor the change, none of that would apply to, say, the xfs drtiver, which is otherwise quite similar.

也不应该.你在作弊! inotify只能通知您在实际监视的挂载点通过vfs进行的更改.如果由于基础数据的更改而发生在该VFS之外的更改,则inotify不能为您提供帮助,也不能解决该问题.

Nor should it. You're cheating!. inotify can only inform you of changes that occured through the vfs at the actual mountpoint being watched. If the changes occured outside that VFS, because of a change to the underlying data, inotify can't help you and isn't designed to solve that problem.

您是否考虑过使用消息队列进行网络通知?

Have you considered using a message queue for network notification?

这篇关于用NFS进行化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆