Code Monkey home page Code Monkey logo

Comments (5)

earlruby avatar earlruby commented on August 21, 2024

I also tried using fcntl locks, which also failed to work. I used the following Python script within a bindfs directory to test:

#!/usr/bin/python
import fcntl, os, time
fd = open('./lockfile', 'w')
fcntl.lockf(fd, fcntl.LOCK_EX|fcntl.LOCK_NB)
time.sleep(30)
fcntl.lockf(fd, fcntl.LOCK_UN)
fd.close()

When executed twice in the same directory, the second lock attempt fails to lock an already-locked file, as expected:

root@ubuntu:/test/bindfs1# ./fcntl-locktest &
[1] 5159
root@ubuntu:/test/bindfs1# ./fcntl-locktest
Traceback (most recent call last):
  File "./fcntl-locktest", line 5, in <module>
    fcntl.lockf(fd, fcntl.LOCK_EX|fcntl.LOCK_NB)
IOError: [Errno 11] Resource temporarily unavailable

However, when run in two different bindfs directories, both bound to the same underlying filesystem, it "succeeds" in locking the same file twice, indicating that fcntl locks are not working:

root@ubuntu:/test/bindfs1# ./fcntl-locktest &
[1] 5161
root@ubuntu:/test/bindfs1# cd ../bindfs2
root@ubuntu:/test/bindfs2# ./fcntl-locktest

Also "succeeds" in locking the same file twice when locking the file on the underlying file system, indicating that fcntl locks are not working:

root@ubuntu:/test/bindfs1# ./fcntl-locktest &
[1] 5165
root@ubuntu:/test/bindfs1# cd ../realfs/
root@ubuntu:/test/realfs# ./fcntl-locktest

The expected behavior is that the second lock attempt should fail.

from bindfs.

mpartel avatar mpartel commented on August 21, 2024

This should now be implemented in the master branch for both types of locks, but it requires --multithreaded to avoid deadlocks. Please test and let me know if it works. I'll probably make a release after a week if no problems are reported.

The problems with --multithreaded are probably fixable with a simple in-process lock, but sadly I don't have the time to do that right now. The code itself should be thread-safe i.e. I don't expect it to crash (what little global mutable state there is is behind a lock).

from bindfs.

earlruby avatar earlruby commented on August 21, 2024

I rebuilt using the current master + the latest FUSE and I see see this issue:

root@ubuntu-14:/test/bindfs1# which bindfs
/usr/local/bin/bindfs
root@ubuntu-14:/test/bindfs1# bindfs -V
bindfs 1.13.1
root@ubuntu-14:~# mkdir -p /test/realfs /test/bindfs1 /test/bindfs2
root@ubuntu-14:~# bindfs /test/realfs /test/bindfs1
root@ubuntu-14:~# bindfs /test/realfs /test/bindfs2
root@ubuntu-14:~# flock -n -x -o /test/bindfs1/lockfile sleep 30 &
[1] 1734
root@ubuntu-14:~# flock -n -x -o /test/bindfs2/lockfile sleep 10
root@ubuntu-14:~# echo $?
0

(Second lock succeeds, should fail.)

from bindfs.

mpartel avatar mpartel commented on August 21, 2024

Sorry, I forgot to mention you need to pass the new flag --enable-lock-forwarding to make it work (new man page entry).

Enabling lock forwarding by default is blocked on some problems with multithreaded mode.

from bindfs.

earlruby avatar earlruby commented on August 21, 2024

Just tried:

root@ubuntu-14:~# bindfs --enable-lock-forwarding --enable-ioctl --multithreaded /test/realfs /test/bindfs1
root@ubuntu-14:~# bindfs --enable-lock-forwarding --enable-ioctl --multithreaded /test/realfs /test/bindfs2
root@ubuntu-14:~# flock -n -x -o /test/bindfs1/lockfile sleep 30 &
[1] 1798
root@ubuntu-14:~# flock -n -x -o /test/bindfs2/lockfile sleep 10
root@ubuntu-14:~# echo $?
1

Success! Thanks!

from bindfs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.