From: NeilBrown <neilb@suse.de>
To: "Fox, Kevin M" <kevin.fox@pnnl.gov>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: Conditional Unlink
Date: Mon, 24 Sep 2012 15:02:39 +1000 [thread overview]
Message-ID: <20120924150239.1d87b868@notabene.brown> (raw)
In-Reply-To: <81A22C12505EF7419E792D791BC28B3C0104E178E598@EMAIL05.pnl.gov>
[-- 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 --]
prev parent reply other threads:[~2012-09-24 5:02 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-21 17:32 Conditional Unlink Fox, Kevin M
2012-09-24 5:02 ` NeilBrown [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120924150239.1d87b868@notabene.brown \
--to=neilb@suse.de \
--cc=kevin.fox@pnnl.gov \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox