[Yaffs] Re: power fail testing -->rename problem

Charles Manning manningc2@actrix.gen.nz
Mon, 2 May 2005 07:46:00 +1200


I have investigated this and figured out a fix which I will code and test=
 in=20
the next few days.

I considered a few approaches, but the mechanism I have settled on uses a=
=20
"shadowing" field.

The code went like this:

   if (newname exists)
   {
       unlink(newname);
   }
   rename(oldname,newname)

The problem Sergei discovered was that the power could be lost between th=
e=20
unlink and the rename, causing the file system to end up with no file cal=
led=20
newname.

We cannot just reverse the order because that could leave us with two nam=
es=20
for different files -- bad!

The new code will go like this

   if (newname exists)
   {
       rename_with_shadow(oldname,newname);
        // Point A
       unlink(newname);
       // Point B
   }
   rename(oldname,newname)

A shadowing rename is like its non-shadowing brother except that it also=20
stores the object Id of the object that it "shadows". The semantics of=20
scanning a shadowing objectheader are different. If the shadowed object=20
exists (ie power lost at point A) then we unlink it.

Essentially the shadowing gives us a way of determining priority between =
two=20
like-named objects.

Why do we rename without the shadow afterwards? This is done so that we=20
remove the shadow after it is no longer needed. If this was not done we w=
ould=20
potentially  have a shadow hanging around that would cause future files w=
ith=20
the same object Id to get deleted.

-- Charles




On Friday 29 April 2005 05:36, Sergei Sharonov wrote:
> Hi,
>
> > Rename() suppose to be atomic per
> > http://www.opengroup.org/onlinepubs/007908799/xsh/rename.html:
> > "If the link named by the new argument exists, it is removed and
> > old renamed to new. In this case, a link named new will remain
> > visible to other processes throughout the renaming operation and
> > will refer either to the file referred to by new or old before
> > the operation began."
>
> In yaffs_fs.c : yaffs_rename():
>  removed =3D
> yaffs_Unlink(yaffs_InodeToObject(new_dir),new_dentry->d_name.name); ret=
Val
> =3D yaffs_RenameObject(yaffs_InodeToObject(old_dir),
>                             old_dentry->d_name.name,
> yaffs_InodeToObject(new_dir),
>                             new_dentry->d_name.name);
>
>
> Is sequencing a problem here?
>
> Sergei
>
>
>
> _______________________________________________
> yaffs mailing list
> yaffs@stoneboat.aleph1.co.uk
> http://stoneboat.aleph1.co.uk/cgi-bin/mailman/listinfo/yaffs