From: "E. Abbink" Subject: Re: Problem using mandatory locks (other apps can read/delete etc) Date: Wed, 17 Apr 2002 12:22:29 +0200 Sender: linux-fsdevel-owner@vger.kernel.org Message-ID: <200204171022.MAA28761@fikkie.vesc.nl> Reply-To: esger@bumblebeast.com Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Cc: linux-fsdevel@vger.kernel.org Return-path: To: "Bryan Henderson" List-Id: linux-fsdevel.vger.kernel.org > >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. > > 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? > >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. > > 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 > 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?? -- NeoMail - Webmail that doesn't suck... as much. http://neomail.sourceforge.net