Skip to contentSkip to conversation

Problem using mandatory locks (other apps can read/delete etc)

DISCUSSION E. Abbink 1 participant 1 message Apr 17, 2002 VFS

lore
Share & tools
lore

E. Abbink

author
#0 lore raw
Quoted 6 lines
Quoted 5 lines

what i am trying to do is prevent file corruption on files shared between several processes, not all of which care one bit about (advisory) locking.

Quoted 7 lines

But you also mentioned a concern about the Rm program, which doesn't modify the file in any way, so I don't see what that has to do with file corruption. I'm thinking of file corruption as something that happens when two processes write to a file simultaneously and the resulting file has part of one process' write and part of the other's. Or maybe a process reads while another is writing and sees only part of the write.

Exactly, but I dont write all the applications we use together and there are some programs that dont truncate but apparently just delete & recreate a file when updating (ftp comes to mind). While as it looks now the lock(s) technically held in such a case it still leaves the file with content not written by the locking process in the place of the old file. Effectively the lock has been broken for my application as it doesnt care about the various bytes on disk for the file, it cares about the bytes for file X at location Y. Does this clarify my problem with rm enough?

Quoted 9 lines
Quoted 2 lines

If i try to set a read lock after i set a write lock (for program see first post) i get EAGAIN. Which is the correct error afaik?

Yes, and that's useful information because, as I read it, the exact same code is used to check the lock to produce that EAGAIN as is used to check the lock to produce the EAGAIN on the read or write with mandatory locks. So it's more likely that the mandatory locks aren't being checked at all on those reads than that they aren't being checked properly.

Quoted 4 lines

I don't know what good it does you to know that, though. It still requires someone to debug the kernel to figure out exactly what's wrong.

You mentioned using various well-known programs to test the locking.

Have

Quoted 4 lines

you tried simplifying things a bit by having two processes running your own code demonstrate the locking failure? If they could both keep the file open all the time, it would simplify things even more.

Well, i did some more testing and I'm actually rather more confused.

the file I use for testing is 'image.jpg' so I initially used Imagemagick display for read testing. I've now used some other programs as well.

reading with a mandatory file lock set:

display       -   reads & displays image fine, seems to break lock 
more          -   waits for lock to be released for displaying any file

content

cat           -   idem
ftp download  -   waits for lock
ftp upload    -   overwrites locked file (this is probably rm/unlink's

doing)
my program - waits for lock

since I was confused between the discrepancy between display & more I tested more also with advisory locks but in that case it just broke the lock.

So in spite of what seemed the case earlier, the locks are being enforced. That just leaves the rm problem (which should be solvable) and the fact display can completely ignore the lock??

Signature · 2 lines
NeoMail - Webmail that doesn't suck... as much.
http://neomail.sourceforge.net