「NFS」- 常见错误列表

mount_nfs: can’t mount … from … onto …: Operation not permitted

问题描述:macOS High Sierra挂在NFS时返回的错误:

mount_nfs: can't mount ... from ... onto ...: Operation not permitted

系统环境:服务端为 NFSv4 运行于 Debian;客户端为 mount 运行与 macOS High Sierra;

问题原因:参考 Operation Not Permitted Mounting NFS Share on OS X Mountain Lion 文章。

解决方案:修改/etc/exports配置文件中的配置,对相应的导出目录加入insecure选项。类似下面的样子:

/srv/nfs  *(rw,sync,no_root_squash,insecure)

Stale NFS file handle

fcntl — The fcntl and ioctl system calls — Python 3.9.5 documentation
file locking – python lockf and flock behaviour – Stack Overflow

问题描述:在 NFS 上,如下代码打开文件锁,但产生该错误:

import fcntl

lock_f = open("test.lock", "r")
fcntl.flock(lock_f, fcntl.LOCK_EX | fcntl.LOCK_NB)

原因分析:NFS Client 持有 NFS Server 已经无法识别的文件句柄。或许是 NFS Server 发生过重启,导致已打开的文件句柄丢失,而 NFS Client 又没有释放这些文件句柄。

解决方案:通过如下选项挂载 NFS:

-o vers=3,nolock,local_lock=all