Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading the same disc image into drives 0 and 1 causes b-em to hang #235

Open
ZornsLemma opened this issue Sep 21, 2024 · 1 comment
Open

Comments

@ZornsLemma
Copy link
Contributor

If I load the same disc image into drives 0 and 1 (and maybe do a *. to force disc access) , b-em locks up - doing an strace suggests this is probably down to file locking:

recvmsg(4, {msg_namelen=0}, 0)          = -1 EAGAIN (Resource temporarily unavailable)
recvmsg(4, {msg_namelen=0}, 0)          = -1 EAGAIN (Resource temporarily unavailable)
poll([{fd=4, events=POLLIN|POLLOUT}], 1, -1) = 1 ([{fd=4, revents=POLLOUT}])
writev(4, [{iov_base="\224\1\22\0\2\0\0\r\7\0 \r\332\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., iov_len=72}], 1) = 72
write(6, "\1\0\0\0\0\0\0\0", 8)         = 8
futex(0x55d260b8db10, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x55d261592948, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x55d261592838, FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, 0, NULL, FUTEX_BITSET_MATCH_ANY) = 0
futex(0x55d261592948, FUTEX_WAKE_PRIVATE, 1) = 0
futex(0x55d260cd5758, FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, 0, NULL, FUTEX_BITSET_MATCH_ANY) = 0
futex(0x55d260cd5708, FUTEX_WAKE_PRIVATE, 1) = 0
fcntl(42, F_OFD_SETLKW, {l_type=F_WRLCK, l_whence=SEEK_SET, l_start=0, l_len=0}) = 0
fcntl(43, F_OFD_SETLKW, {l_type=F_WRLCK, l_whence=SEEK_SET, l_start=0, l_len=0}

This is on Linux Mint 21.2 x86-64, FWIW. I've built b-em from the latest master branch (commit 5ce9c1b).

I appreciate this isn't a sensible thing to do, but I did it by accident (I had an image loaded into drive 1 from a while back without realising, then deliberately loaded the same image into drive 0 to use without noticing or caring it was already in drive 1) and I think it would be nice to generate an error or something instead of just locking up.

@SteveFosdick
Copy link
Collaborator

SteveFosdick commented Sep 25, 2024

Interesting. File locking on Linux already seems to have quite a number of choices and I opted for the newer locking that works by file descriptor rather than by process. That does mean if the same process opens the same file twice it can compete with itself for locks.

I think this may have worked better when I first implemented the locking, i.e. if you loaded the image file into both drives it wouldn't deadlock unless you accessed them both, for example by copying from one to the other. Somewhere along the line, maybe with the HFE support, someone noted that on real hardware both drives would spin up at the same time whichever is accessed which now means both try to lock their respective files, hence the deadlock.

Probably the best way to resolve this would be to add a test upon loading a disc image so you can't load it into both drives at the same time. That may need some research to work out if two pathnames are the same file beyond just comparing the names, i.e. because of links etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants