public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* UBIFS question, atomic file create/rename semantics
@ 2011-04-04  8:54 Jon Povey
  2011-04-04  8:59 ` Artem Bityutskiy
  0 siblings, 1 reply; 3+ messages in thread
From: Jon Povey @ 2011-04-04  8:54 UTC (permalink / raw)
  To: linux-mtd

I have a file I want to create on first-time boot on my system,
on UBIFS. It's done in a shell script, and the logic is something like

if [ ! -e $FILE ]
then
        # create the file
fi

Once or twice this file has turned out to be zero length (or possibly
contain nulls, I am working on slightly vauge reports).

Looking into the issues of sync and semantics, I think this is related
to not doing sync and rename.
The script was pretty much just saying "prog > $FILE" and no sync.

I came up with the following and would appreciate any comments about
how reliable this should be:

if [ ! -e $FILE ]
then
        prog > $FILE.tmp
        sync
        mv $FILE.tmp $FILE
        sync
fi

My understanding is that as the .tmp file is on the same filesystem
and I ran sync, the mv means the final file atomically either exists
with full correct contents, or will not exist at all (after surprise
power cycle during the process).

A quick "yes, fine" or "won't work" would be appreciated.

Thanks,

--
Jon Povey
jon.povey@racelogic.co.uk

Racelogic is a limited company registered in England. Registered number 2743719 .
Registered Office Unit 10, Swan Business Centre, Osier Way, Buckingham, Bucks, MK18 1TB .

The information contained in this electronic mail transmission is intended by Racelogic Ltd for the use of the named individual or entity to which it is directed and may contain information that is confidential or privileged. If you have received this electronic mail transmission in error, please delete it from your system without copying or forwarding it, and notify the sender of the error by reply email so that the sender's address records can be corrected. The views expressed by the sender of this communication do not necessarily represent those of Racelogic Ltd. Please note that Racelogic reserves the right to monitor e-mail communications passing through its network

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: UBIFS question, atomic file create/rename semantics
  2011-04-04  8:54 UBIFS question, atomic file create/rename semantics Jon Povey
@ 2011-04-04  8:59 ` Artem Bityutskiy
  2011-04-04  9:10   ` Jon Povey
  0 siblings, 1 reply; 3+ messages in thread
From: Artem Bityutskiy @ 2011-04-04  8:59 UTC (permalink / raw)
  To: Jon Povey; +Cc: linux-mtd

Hi,

On Mon, 2011-04-04 at 09:54 +0100, Jon Povey wrote:
> I have a file I want to create on first-time boot on my system,
> on UBIFS. It's done in a shell script, and the logic is something like
> 
> if [ ! -e $FILE ]
> then
>         # create the file
> fi
> 
> Once or twice this file has turned out to be zero length (or possibly
> contain nulls, I am working on slightly vauge reports).
> 
> Looking into the issues of sync and semantics, I think this is related
> to not doing sync and rename.
> The script was pretty much just saying "prog > $FILE" and no sync.
> 
> I came up with the following and would appreciate any comments about
> how reliable this should be:
> 
> if [ ! -e $FILE ]
> then
>         prog > $FILE.tmp
>         sync
>         mv $FILE.tmp $FILE
>         sync
> fi
> 
> My understanding is that as the .tmp file is on the same filesystem
> and I ran sync, the mv means the final file atomically either exists
> with full correct contents, or will not exist at all (after surprise
> power cycle during the process).
> 
> A quick "yes, fine" or "won't work" would be appreciated.

It does not mean you should trust me and not test that, but I think
"yes", your sequence should make it.

-- 
Best Regards,
Artem Bityutskiy (Артём Битюцкий)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: UBIFS question, atomic file create/rename semantics
  2011-04-04  8:59 ` Artem Bityutskiy
@ 2011-04-04  9:10   ` Jon Povey
  0 siblings, 0 replies; 3+ messages in thread
From: Jon Povey @ 2011-04-04  9:10 UTC (permalink / raw)
  To: dedekind1@gmail.com; +Cc: linux-mtd

Artem Bityutskiy wrote:
> On Mon, 2011-04-04 at 09:54 +0100, Jon Povey wrote:
>> I came up with the following and would appreciate any comments about
>> how reliable this should be:
>>
>> if [ ! -e $FILE ]
>> then
>>         prog > $FILE.tmp
>>         sync
>>         mv $FILE.tmp $FILE
>>         sync
>> fi
>
> It does not mean you should trust me and not test that, but I think
> "yes", your sequence should make it.

Thanks for the quick response!

I was not able to reproduce the "zero file" fault on the bench, if I
powered off shortly after the file was "created" before, on my bench
test it just didn't exist.

After this new code, it seems to reliably exist on flash as soon as
the block exists, so.. off to our testers to bang on it a bit.


--
Jon Povey
jon.povey@racelogic.co.uk

Racelogic is a limited company registered in England. Registered number 2743719 .
Registered Office Unit 10, Swan Business Centre, Osier Way, Buckingham, Bucks, MK18 1TB .

The information contained in this electronic mail transmission is intended by Racelogic Ltd for the use of the named individual or entity to which it is directed and may contain information that is confidential or privileged. If you have received this electronic mail transmission in error, please delete it from your system without copying or forwarding it, and notify the sender of the error by reply email so that the sender's address records can be corrected. The views expressed by the sender of this communication do not necessarily represent those of Racelogic Ltd. Please note that Racelogic reserves the right to monitor e-mail communications passing through its network

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-04-04  9:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-04  8:54 UBIFS question, atomic file create/rename semantics Jon Povey
2011-04-04  8:59 ` Artem Bityutskiy
2011-04-04  9:10   ` Jon Povey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox