Bad file descriptor when trying to lock file on NFS mount
Summary
File descriptor obtained using open() cannot be used in flock() call when the file is on NFS mount.
Related to:
Open BackendVFS ObjectStore files in R/W mode when obtaining exclusive locks
Steps to reproduce
(How one can reproduce the issue - this is very important)
What is the current bug behavior?
Locking of CTA object store files fails on NFS mount.
What is the expected correct behavior?
locking should work on NFS
Relevant logs and/or screenshots
220325 17:01:45 41080 ssi_XrdSsiCtaServiceProvider: pid:41080 tid:139722695624832 XrdSsiCtaServiceProvider::Init(): cta::exception::Exception In BackendVFS::lockHelper(): Failed
to flock file /cta-store/ctaObjectStore/.AgentRegister-cta-objectstore-initialize-tpm102.desy.de-14808-20220325-12:05:30-0-0.lock: Bad file descriptor
Possible fixes
- add O_RDWR flag to open command in CTA/objectstore/BackendVFS.cpp:
BackendVFS::ScopedLock * BackendVFS::lockHelper(const std::string& name, int type, uint64_t timeout_us) {
...
int flag = O_RDONLY;
if (type == LOCK_EX) {
flag = O_RDWR;
}
ret->set(::open(path.c_str(), flag), path);
...
- int fd=::open(path.c_str(), O_RDONLY | O_CREAT, S_IRWXU | S_IRGRP | S_IROTH);
+ int fd=::open(path.c_str(), flag | O_CREAT, S_IRWXU | S_IRGRP | S_IROTH);
...
}
or
- replacing flock() by lockf() or fcntl() and simultaneously applying fix 1.