]> git.neil.brown.name Git - LaFS.git/commitdiff
atime: make sure block is reserved before updating.
authorNeilBrown <neilb@suse.de>
Mon, 2 May 2011 01:33:23 +0000 (11:33 +1000)
committerNeilBrown <neilb@suse.de>
Mon, 2 May 2011 01:40:24 +0000 (11:40 +1000)
We need to 'reserve' space for the atime file blocks before updating
them.  This could of course fail.  If it does we could lose the
update, but as long as that is very rare it shouldn't be a problem.

When we fix things so the block hardly ever gets written, we should
also fix it to reserve the block when we first take the reference.
Then also refresh the reservation after writing.

Also fix up some comments and stuff.

Signed-off-by: NeilBrown <neilb@suse.de>
inode.c
test/go

diff --git a/inode.c b/inode.c
index cdaf1280c2bdde652920a0aa1e274b6483616010..d489f498ff7375fdb6c629c09319902a424a3d0c 100644 (file)
--- a/inode.c
+++ b/inode.c
@@ -484,7 +484,7 @@ out:
 
 static void check_atime_ref(struct inode *ino, int async)
 {
-       /* If there is an time file in this filesystem the inode
+       /* If there is an atime file in this filesystem the inode
         * should hold a reference to the relevant block in
         * that file.
         */
@@ -507,7 +507,7 @@ static void check_atime_ref(struct inode *ino, int async)
                LAFSI(ino)->md.file.atime_offset = 0;
 
        /* "* 2" to get byte number, then shift to get block
-        * number
+        * number.  So just shift by 1 less than blkbits.
         */
        bnum = ino->i_ino >> (at->i_blkbits-1);
        b = lafs_get_block(at, bnum, NULL, GFP_NOFS, MKREF(atime));
@@ -634,7 +634,12 @@ static void store_atime_delta(struct inode *ino)
        i = (ino->i_ino * 2) & ((1<<at->i_blkbits)-1);
        if (le16_to_cpu(atp[i]) != LAFSI(ino)->md.file.atime_offset) {
                atp[i] = cpu_to_le16(LAFSI(ino)->md.file.atime_offset);
-               lafs_dirty_dblock(b);
+               /* FIXME - I could lose an update here - do I care? */
+               /* Can only reserve NewSpace with checkpoint locked... */
+               lafs_checkpoint_lock(fs_from_inode(ino));
+               if (lafs_reserve_block(&b->b, NewSpace) == 0)
+                       lafs_dirty_dblock(b);
+               lafs_checkpoint_unlock(fs_from_inode(ino));
        }
        unmap_dblock(b, atp);
        putdref(b, MKREF(store_atime));
diff --git a/test/go b/test/go
index 6111b053bcf0517ab69972282579c571d7df33ee..cafae040766a2e0fef3ae2d2fb07d0dee8c2c5ab 100644 (file)
--- a/test/go
+++ b/test/go
@@ -13,7 +13,7 @@ rmmod lafs.ko
 tftp 10.0.2.2 -m binary -c get /lafs.ko
 insmod lafs.ko lafs_trace=1 || exit 1
 #mount -r -t lafs -o 'dev=/dev/sdc' /dev/sdb /mnt/1
-mount -t lafs  /dev/sdb /mnt/1
+#mount -t lafs  /dev/sdb /mnt/1
 #mount -r -t lafs_snap -o snapshot=first /mnt/1 /mnt/2
 #mount -r -t lafs_snap -o snapshot=second /mnt/1 /mnt/3
 #mount -r -t lafs -o 'snapshot=first /mnt/1 /mnt/2
@@ -29,7 +29,7 @@ ls -ia /mnt/1
 a=`md5sum /mnt/1/afile`
 echo $a
 set $a
-if [ $1 != 'db53a848287fe6dc69da95678da94f6a' ]
+if [ "$1" != 'db53a848287fe6dc69da95678da94f6a' ]
 then echo "Bad match" ; exit 1
 fi
 echo 'db53....4f6a'