From: NeilBrown Date: Mon, 2 May 2011 01:33:23 +0000 (+1000) Subject: atime: make sure block is reserved before updating. X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=0f76112ac50e497ddde809c5910cc64ed1da1b8e;p=LaFS.git atime: make sure block is reserved before updating. 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 --- diff --git a/inode.c b/inode.c index cdaf128..d489f49 100644 --- 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<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 6111b05..cafae04 100644 --- 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'