如何在 Perl 中锁定 Linux 网络上的共享文件?

发布于 2024-07-26 19:09:08 字数 79 浏览 4 评论 0原文

我在两台 Linux 机器上安装了 cifs 文件。 我有一个可以修改共享文件的 Perl 脚本。 在这种情况下,我们如何通过网络锁定文件?

I have mounted a cifs file on two Linux machines. I have a Perl script which can modify the shared file. How do we lock the file over network in this scenario?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

醉生梦死 2024-08-02 19:09:08

看起来我们可以使用 fcntl() 来锁定文件。 我刚刚发现它可以工作:)
此链接可能有用

http://www.cpan.org /scripts/file-handling/flock.using.fcntl.example

感谢您的回复

_Anandan

Looks like we can fcntl() for locking files. I just found its working :)
this link might be useful

http://www.cpan.org/scripts/file-handling/flock.using.fcntl.example

Thanks for your response

_Anandan

深海不蓝 2024-08-02 19:09:08

如果您尝试通过 NFS 执行此操作,请尝试 File::NFSLock

If you're trying to do this over NFS, try File::NFSLock.

束缚m 2024-08-02 19:09:08

如果您的文件服务器是 Samba,则另请参阅 smb.conf 手册页:

...

阻塞锁 (S)

       This parameter controls the behavior of smbd(8) when given a request by a client
       to obtain a byte range lock on a region of an open file, and the request has a
       time limit associated with it.

       If this parameter is set and the lock range requested cannot be immediately
       satisfied, samba will internally queue the lock request, and periodically attempt
       to obtain the lock until the timeout period expires.

       If this parameter is set to no, then samba will behave as previous versions of
       Samba would and will fail the lock request immediately if the lock range cannot
       be obtained.

       Default: blocking locks = yes

...

锁定 (S)

       This controls whether or not locking will be performed by the server in response
       to lock requests from the client.

       If locking = no, all lock and unlock requests will appear to succeed and all lock
       queries will report that the file in question is available for locking.

       If locking = yes, real locking will be performed by the server.

       This option may be useful for read-only filesystems which may not need locking
       (such as CDROM drives), although setting this parameter of no is not really
       recommended even in this case.

       Be careful about disabling locking either globally or in a specific service, as
       lack of locking may result in data corruption. You should never need to set this
       parameter.

If your file server is Samba, then look also at the smb.conf man page:

...

blocking locks (S)

       This parameter controls the behavior of smbd(8) when given a request by a client
       to obtain a byte range lock on a region of an open file, and the request has a
       time limit associated with it.

       If this parameter is set and the lock range requested cannot be immediately
       satisfied, samba will internally queue the lock request, and periodically attempt
       to obtain the lock until the timeout period expires.

       If this parameter is set to no, then samba will behave as previous versions of
       Samba would and will fail the lock request immediately if the lock range cannot
       be obtained.

       Default: blocking locks = yes

...

locking (S)

       This controls whether or not locking will be performed by the server in response
       to lock requests from the client.

       If locking = no, all lock and unlock requests will appear to succeed and all lock
       queries will report that the file in question is available for locking.

       If locking = yes, real locking will be performed by the server.

       This option may be useful for read-only filesystems which may not need locking
       (such as CDROM drives), although setting this parameter of no is not really
       recommended even in this case.

       Be careful about disabling locking either globally or in a specific service, as
       lack of locking may result in data corruption. You should never need to set this
       parameter.
嘴硬脾气大 2024-08-02 19:09:08

我在 CPAN 上找不到实现此目的的模块。 包装 libsmbclient 的模块似乎没有实现协议的 OPLOCKing 部分。

smbfs根据消息来源,函数 smbfs_smb_lock 似乎可以满足您的需要。
要么编写您自己的 XS 包装器模块,要么使用 Inline::C。

I couldn't find a module on CPAN to achieve this. It seems that the modules wrapping libsmbclient do not implement the OPLOCKing portion of the protocol.

In the smbfs sources, the function smbfs_smb_lock appears to do what you need.
Either write your own XS wrapper module, or use Inline::C.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文