* Conditional Unlink
@ 2012-09-21 17:32 Fox, Kevin M
2012-09-24 5:02 ` NeilBrown
0 siblings, 1 reply; 2+ messages in thread
From: Fox, Kevin M @ 2012-09-21 17:32 UTC (permalink / raw)
To: linux-kernel@vger.kernel.org
Quick question:
Is there a syscall or some algorithm that would allow an unlink that would only happen if no writes to the file have occurred between a stat and an unlink, race free?
Background:
I'm writing a program that sync's files up to a server. I would like to unlink the files that have successfully been uploaded. There is a race though. If the file changed after uploading but before the unlink (I do not control who can write to the files), the next upload should take care of things and the unlink should fail. Otherwise, data could be lost!
Thanks,
Kevin
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Conditional Unlink
2012-09-21 17:32 Conditional Unlink Fox, Kevin M
@ 2012-09-24 5:02 ` NeilBrown
0 siblings, 0 replies; 2+ messages in thread
From: NeilBrown @ 2012-09-24 5:02 UTC (permalink / raw)
To: Fox, Kevin M; +Cc: linux-kernel@vger.kernel.org
[-- Attachment #1: Type: text/plain, Size: 971 bytes --]
On Fri, 21 Sep 2012 10:32:36 -0700 "Fox, Kevin M" <kevin.fox@pnnl.gov> wrote:
> Quick question:
> Is there a syscall or some algorithm that would allow an unlink that would only happen if no writes to the file have occurred between a stat and an unlink, race free?
>
> Background:
> I'm writing a program that sync's files up to a server. I would like to unlink the files that have successfully been uploaded. There is a race though. If the file changed after uploading but before the unlink (I do not control who can write to the files), the next upload should take care of things and the unlink should fail. Otherwise, data could be lost!
Probably your best bet is to rename the file in there.
mv file file.tmp
sleep 5
cp file.tmp $server/file
rm file.tmp
The "sleep 5" might not work for you, one would need to know more about total
context.
Is any locking done when writing to the file, or will there only ever be one
writer?
NeilBrown
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 828 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-09-24 5:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-21 17:32 Conditional Unlink Fox, Kevin M
2012-09-24 5:02 ` NeilBrown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox