Subject: afs/fs/cachefs super.c,1.30,1.31 rootdir.c,1.9,1.10 recycling.c,1.20,1.21 journal.c,1.32,1.33 inode.c,1.17,1.18 index.c,1.18,1.19 cachefs-layout.h,1.24,1.25 cachefs-int.h,1.33,1.34 aops.c,1.30,1.31

From: [email-masked]
Date: Mon, 02 Jun 2003 10:17:45 +0100

Update of /home/cvs/afs/fs/cachefs
In directory phoenix.infradead.org:/tmp/cvs-serv13054/fs/cachefs

Modified Files:
	super.c rootdir.c recycling.c journal.c inode.c index.c 
	cachefs-layout.h cachefs-int.h aops.c 
Log Message:
only access the inode metadata page pointer under a lock

Index: super.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/super.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- super.c	28 May 2003 10:32:11 -0000	1.30
+++ super.c	2 Jun 2003 09:17:42 -0000	1.31
@@ -386,7 +386,7 @@
 	super->ujnl_jsof <<= (PAGE_SHIFT - super->sb->s_blocksize_bits);
 
 	/* get and retain various meta-data inodes */
-	ret = cachefs_iget(super,CACHEFS_INO_STORAGE,&super->istorage);
+	ret = cachefs_iget(super,CACHEFS_INO_METADATA,&super->imetadata);
 	if (ret<0)
 		goto error;
 
@@ -445,8 +445,10 @@
 	if (inode)	iput(&inode->vfs_inode);
 
 	if (super) {
-		if (super->istorage)		cachefs_iput(super->istorage);
-		if (super->imisc)		iput(super->imisc);
+		if (super->imetadata)
+			cachefs_iput(super->imetadata);
+		if (super->imisc)
+			iput(super->imisc);
 		dbgfree(super);
 		kfree(super);
 	}
@@ -463,7 +465,7 @@
  */
 static int cachefs_initialise_blockdev(struct cachefs_super *super)
 {
-	struct cachefs_ondisc_storage *storage;
+	struct cachefs_ondisc_metadata *metadata;
 	struct page *page;
 	size_t bix, tmp, qty, ndirect;
 	loff_t nblocks;
@@ -496,8 +498,8 @@
 	super->layout->endian		= CACHEFS_SUPER_ENDIAN;
 	super->layout->version		= CACHEFS_SUPER_VERSION;
 	super->layout->bsize		= PAGE_SIZE;
-	super->layout->storage_size	= super->sb->s_blocksize;
-	super->layout->storage_bits	= super->sb->s_blocksize_bits;
+	super->layout->metadata_size	= super->sb->s_blocksize;
+	super->layout->metadata_bits	= super->sb->s_blocksize_bits;
 	super->layout->ujnl_rsize	= super->sb->s_blocksize;
 	super->layout->ujnl_recperblk	= super->layout->bsize / super->layout->ujnl_rsize;
 
@@ -524,59 +526,60 @@
 	printk("CacheFS: %08x data cache\n",		super->layout->bix_cache);
 	printk("CacheFS: %08x end\n",			super->layout->bix_end);
 
-	/* initialise the storage entry for the storage file itself */
+	/* initialise the metadata entry for the metadata file itself */
 	memset(data,0,PAGE_SIZE);
 
-	for (tmp=0; tmp<PAGE_SIZE; tmp+=super->layout->storage_size) {
-		storage = (struct cachefs_ondisc_storage *) (data + tmp);
+	for (tmp=0; tmp<PAGE_SIZE; tmp+=super->layout->metadata_size) {
+		metadata = (struct cachefs_ondisc_metadata *) (data + tmp);
 
-		storage->header.state = CACHEFS_ONDISC_INDEX_FREE;
+		metadata->header.state = CACHEFS_ONDISC_INDEX_FREE;
 	}
 
-	storage =
-		(struct cachefs_ondisc_storage *)
-		(data + (CACHEFS_INO_STORAGE << super->layout->storage_bits));
+	metadata =
+		(struct cachefs_ondisc_metadata *)
+		(data + (CACHEFS_INO_METADATA << super->layout->metadata_bits));
 
-	storage->header.state	= CACHEFS_ONDISC_INDEX_ACTIVE;
-	storage->size		= PAGE_SIZE;
-	storage->freelink	= UINT_MAX;
-	storage->mtime		= CURRENT_TIME.tv_sec;
-	storage->atime		= CURRENT_TIME.tv_sec;
+	metadata->header.state	= CACHEFS_ONDISC_INDEX_ACTIVE;
+	metadata->size		= PAGE_SIZE;
+	metadata->freelink	= UINT_MAX;
+	metadata->mtime		= CURRENT_TIME.tv_sec;
+	metadata->atime		= CURRENT_TIME.tv_sec;
 
-	storage->index_dsize	= super->layout->storage_size;
-	storage->index_dsize	-= sizeof(struct cachefs_ondisc_index_entry);
-	storage->index_esize	= super->layout->storage_size;
+	metadata->index_dsize	= super->layout->metadata_size;
+	metadata->index_dsize	-= sizeof(struct cachefs_ondisc_index_entry);
+	metadata->index_esize	= super->layout->metadata_size;
 
-	strncpy(storage->index_type,".STORAGE",8);
+	strncpy(metadata->index_type,".METADAT",9);
 
 	for (tmp=0; tmp<ndirect; tmp++)
-		storage->direct[tmp] = tmp+1; /* point to itself */
+		metadata->direct[tmp] = tmp+1; /* point to itself */
 
-	/* initialise the storage entry for the FSDEF catalogue */
-	storage =
-		(struct cachefs_ondisc_storage *)
-		(data + (CACHEFS_INO_FSDEF_CATALOGUE << super->layout->storage_bits));
-
-	storage->header.state	= CACHEFS_ONDISC_INDEX_ACTIVE;
-	storage->size		= 0;
-	storage->freelink	= UINT_MAX;
-	storage->mtime		= CURRENT_TIME.tv_sec;
-	storage->atime		= CURRENT_TIME.tv_sec;
-
-	storage->index_dsize	= sizeof(struct cachefs_ondisc_fsdef);
-	storage->index_esize	= sizeof(struct cachefs_ondisc_index_entry) + storage->index_dsize;
-	storage->index_keys[0]	= CACHEFS_ONDISC_INDEXKEY_ASCIIZ | 24;
+	/* initialise the metadata entry for the FSDEF catalogue */
+	metadata =
+		(struct cachefs_ondisc_metadata *)
+		(data + (CACHEFS_INO_FSDEF_CATALOGUE << super->layout->metadata_bits));
+
+	metadata->header.state	= CACHEFS_ONDISC_INDEX_ACTIVE;
+	metadata->size		= 0;
+	metadata->freelink	= UINT_MAX;
+	metadata->mtime		= CURRENT_TIME.tv_sec;
+	metadata->atime		= CURRENT_TIME.tv_sec;
+
+	metadata->index_dsize	= sizeof(struct cachefs_ondisc_fsdef);
+	metadata->index_esize	= sizeof(struct cachefs_ondisc_index_entry);
+	metadata->index_esize	+= metadata->index_dsize;
+	metadata->index_keys[0]	= CACHEFS_ONDISC_INDEXKEY_ASCIIZ | 24;
 
-	strncpy(storage->index_type,".FSDEF",8);
+	strncpy(metadata->index_type,".FSDEF",8);
 
 #if 1 /* TODO: remove */
-	storage =
-		(struct cachefs_ondisc_storage *)
-		(data + (CACHEFS_INO_WIBBLE << super->layout->storage_bits));
-
-	storage->header.state	= CACHEFS_ONDISC_INDEX_ACTIVE;
-	storage->freelink	= UINT_MAX;
-	storage->mtime		= CURRENT_TIME.tv_sec;
+	metadata =
+		(struct cachefs_ondisc_metadata *)
+		(data + (CACHEFS_INO_WIBBLE << super->layout->metadata_bits));
+
+	metadata->header.state	= CACHEFS_ONDISC_INDEX_ACTIVE;
+	metadata->freelink	= UINT_MAX;
+	metadata->mtime		= CURRENT_TIME.tv_sec;
 #endif
 
 	tmp = 1;
@@ -760,7 +763,7 @@
 	kcachefs_jnld_remove_super(super);
 
 	cachefs_put_page(virt_to_page(super->layout));
-	cachefs_iput(super->istorage);
+	cachefs_iput(super->imetadata);
 	iput(super->imisc);
 
 	if (atomic_read(&super->cnt_blk_tree)!=0) {
@@ -801,6 +804,7 @@
 	if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == SLAB_CTOR_CONSTRUCTOR) {
 		memset(inode,0,sizeof(*inode));
 		inode_init_once(&inode->vfs_inode);
+		init_rwsem(&inode->metadata_sem);
 
 		INIT_LIST_HEAD(&inode->cookie_link);
 		INIT_LIST_HEAD(&inode->super_link);

Index: rootdir.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/rootdir.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- rootdir.c	17 Apr 2003 11:59:04 -0000	1.9
+++ rootdir.c	2 Jun 2003 09:17:42 -0000	1.10
@@ -120,7 +120,7 @@
 		for (loop=0; loop<4; loop++) {
 			int ksize = rec->keys[loop] & CACHEFS_ONDISC_INDEXKEY_KLEN;
 
-			_debug("- key %04hx",rec->keys[loop]);
+			kdebug("- key %04hx",rec->keys[loop]);
 
 			if (loop>0) *name++ = ',';
 
@@ -161,7 +161,7 @@
 
 		tmp = rec->dpos_off + (page->index * rec->epp) + offset/rec->esize;
 
-		_debug("dirent: %d '%s' ino=%u",name-rec->scratch,rec->scratch,xent->ino);
+		kdebug("dirent: %d '%s' ino=%u",name-rec->scratch,rec->scratch,xent->ino);
 
 		if (name == rec->scratch) {
 			desc->count	-= rec->esize;
@@ -208,7 +208,7 @@
  */
 static int cachefs_root_readdir(struct file *file, void *cookie, filldir_t filldir)
 {
-	struct cachefs_ondisc_storage *storage;
+	struct cachefs_ondisc_metadata *metadata;
 	struct cachefs_readdir_record rec;
 	struct cachefs_inode *inode;
 	read_descriptor_t desc;
@@ -232,9 +232,9 @@
 	rec.esize	= inode->index_esize;
 	rec.epp		= inode->index_esize;
 
-	storage = kmap(inode->storage) + inode->storage_offset;
-	memcpy(rec.keys,storage->index_keys,sizeof(rec.keys));
-	kunmap(storage);
+	metadata = cachefs_metadata_preread(inode);
+	memcpy(rec.keys,metadata->index_keys,sizeof(rec.keys));
+	cachefs_metadata_postread(inode);
 
 	switch (file->f_pos) {
 	case 0:
@@ -256,8 +256,8 @@
 		rec.dpos_off = 5;
 		switch (file->f_pos) {
 		case 2:
-			ret = filldir(cookie,"storage_catalogue",17,
-				      file->f_pos,CACHEFS_INO_STORAGE,DT_REG);
+			ret = filldir(cookie,"metadata_catalogue",18,
+				      file->f_pos,CACHEFS_INO_METADATA,DT_REG);
 			if (ret<0)
 				goto done;
 			file->f_pos++;
@@ -290,7 +290,7 @@
 		desc.buf	= (char*) &rec;
 		desc.error	= 0;
 
-		_debug("do read: isz=%llu pos=%llu count=%u",
+		kdebug("do read: isz=%llu pos=%llu count=%u",
 		       inode->vfs_inode.i_size,pos,desc.count);
 
 		do_generic_file_read(file,&pos,&desc,cachefs_readdir_actor);
@@ -299,7 +299,7 @@
 		file->f_pos += ((unsigned)(pos & ~PAGE_MASK) + rec.esize - 1) / rec.esize;
 		file->f_pos += rec.dpos_off;
 
-		_debug("done read: err=%d pos=%llu fpos=%llu",desc.error,pos,file->f_pos);
+		kdebug("done read: err=%d pos=%llu fpos=%llu",desc.error,pos,file->f_pos);
 
 		ret = desc.error;
 		if (ret<0)
@@ -386,7 +386,7 @@
  */
 static struct dentry *cachefs_root_lookup(struct inode *_dir, struct dentry *dentry)
 {
-	struct cachefs_ondisc_storage *storage;
+	struct cachefs_ondisc_metadata *metadata;
 	struct cachefs_lookup_record rec;
 	struct cachefs_inode *dir, *target;
 	struct file_ra_state ra;
@@ -436,10 +436,10 @@
 		}
 #endif
 		break;
-	case 17:
+	case 18:
 		if (dir->vfs_inode.i_ino==CACHEFS_INO_ROOTDIR &&
-		    memcmp(name,"storage_catalogue",17)==0) {
-			ino = CACHEFS_INO_STORAGE;
+		    memcmp(name,"metadata_catalogue",18)==0) {
+			ino = CACHEFS_INO_METADATA;
 			goto get;
 		}
 		break;
@@ -448,9 +448,9 @@
 	}
 
 	/* construct a key to search the FSDEF index with */
-	storage = kmap(dir->storage) + dir->storage_offset;
-	memcpy(rec.keys,storage->index_keys,sizeof(rec.keys));
-	kunmap(storage);
+	metadata = cachefs_metadata_preread(dir);
+	memcpy(rec.keys,metadata->index_keys,sizeof(rec.keys));
+	cachefs_metadata_postread(dir);
 
 	for (loop=0; loop<4; loop++)
 		rec.ksize += rec.keys[loop] & CACHEFS_ONDISC_INDEXKEY_KLEN;
@@ -479,7 +479,7 @@
 
 		stop = memchr(name,',',nend-name) ?: nend;
 
-		_debug("- key %04hx [%*.*s]",rec.keys[loop],nend-name,nend-name,name);
+		kdebug("- key %04hx [%*.*s]",rec.keys[loop],nend-name,nend-name,name);
 
 		switch (rec.keys[loop] & CACHEFS_ONDISC_INDEXKEY_TYPE) {
 		case CACHEFS_ONDISC_INDEXKEY_BIN:
@@ -606,7 +606,7 @@
  */
 static int cachefs_root_rmdir_unlink(struct inode *dir, struct dentry *dentry)
 {
-	struct cachefs_ondisc_storage *storage;
+	struct cachefs_ondisc_metadata *metadata;
 	struct cachefs_transaction *trans;
 	struct cachefs_inode *inode;
 	struct cachefs_super *super = dir->i_sb->s_fs_info;
@@ -642,10 +642,10 @@
 		return ret;
 	}
 
-	/* modify the inode storage entry */
-	storage = kmap(inode->storage) + inode->storage_offset;
-	storage->header.state = CACHEFS_ONDISC_INDEX_RECYCLE;
-	kunmap(inode->storage);
+	/* modify the inode metadata entry */
+	metadata = cachefs_metadata_prewrite(inode);
+	metadata->header.state = CACHEFS_ONDISC_INDEX_RECYCLE;
+	cachefs_metadata_postwrite(inode);
 
 	cachefs_trans_commit(trans);

Index: recycling.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/recycling.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- recycling.c	28 May 2003 10:32:54 -0000	1.20
+++ recycling.c	2 Jun 2003 09:17:42 -0000	1.21
@@ -445,17 +445,17 @@
 
 /*****************************************************************************/
 /*
- * reclaim an inode storage entry
+ * reclaim an inode metadata entry
  * - need to change four entities:
- *   - storage record of inode being reclaimed
- *   - storage record of storage inode (we've got a new free inode)
+ *   - metadata record of inode being reclaimed
+ *   - metadata record of metadata inode (we've got a new free inode)
  *   - index entry pointing to inode being reclaimed
- *   - storage record of index (we've got a new free index entry)
+ *   - metadata record of index (we've got a new free index entry)
  */
-static int cachefs_recycle_reclaim_inode_storage(struct cachefs_super *super)
+static int cachefs_recycle_reclaim_inode_metadata(struct cachefs_super *super)
 {
 	struct cachefs_ondisc_index_entry *xent;
-	struct cachefs_ondisc_storage *storage;
+	struct cachefs_ondisc_metadata *metadata;
 	struct cachefs_transaction *trans = NULL;
 	struct cachefs_inode *iinode = NULL;
 	struct page *ixpage = NULL;
@@ -465,10 +465,10 @@
 	kenter("{%u}",super->rcm_ino);
 
 	/* find the parent index entry */
-	storage = kmap(super->rcm_inode->storage) + super->rcm_inode->storage_offset;
-	iino	= storage->pindex;
-	ixentry	= storage->pindex_entry;
-	kunmap(super->rcm_inode->storage);
+	metadata = cachefs_metadata_preread(super->rcm_inode);
+	iino	= metadata->pindex;
+	ixentry	= metadata->pindex_entry;
+	cachefs_metadata_postread(super->rcm_inode);
 
 	if (iino) {
 		ret = cachefs_iget(super,iino,&iinode);
@@ -502,14 +502,14 @@
 	trans->jentry->entry	= offset;
 	trans->jentry->count	= iinode ? iinode->index_esize : 0;
 
-	storage = kmap(super->istorage->storage) + super->istorage->storage_offset;
-	trans->jentry->auxblock	= storage->freelink;
-	kunmap(super->istorage->storage);
+	metadata = cachefs_metadata_preread(super->imetadata);
+	trans->jentry->auxblock	= metadata->freelink;
+	cachefs_metadata_postread(super->imetadata);
 
 	if (iinode) {
-		storage = kmap(iinode->storage) + iinode->storage_offset;
-		trans->jentry->upblock	= storage->freelink;
-		kunmap(iinode->storage);
+		metadata = cachefs_metadata_preread(iinode);
+		trans->jentry->upblock	= metadata->freelink;
+		cachefs_metadata_postread(iinode);
 
 		cachefs_trans_affects_page(trans,__cachefs_page_get_private(ixpage),offset,
 					   iinode->index_esize);
@@ -517,7 +517,7 @@
 	}
 
 	cachefs_trans_affects_inode(trans,super->rcm_inode);
-	cachefs_trans_affects_inode(trans,super->istorage);
+	cachefs_trans_affects_inode(trans,super->imetadata);
 
 	ret = cachefs_trans_mark(trans);
 	if (ret<0)
@@ -535,26 +535,26 @@
 		memset(xent->data,0,iinode->index_dsize);
 		kunmap(ixpage);
 
-		/* modify the index inode storage entry */
-		storage = kmap(iinode->storage) + iinode->storage_offset;
-		storage->freelink	= ixentry;
-		kunmap(iinode->storage);
+		/* modify the index inode metadata entry */
+		metadata = cachefs_metadata_prewrite(iinode);
+		metadata->freelink	= ixentry;
+		cachefs_metadata_postwrite(iinode);
 	}
 
 	/* clear the inode definition */
-	storage = kmap(super->rcm_inode->storage) + super->rcm_inode->storage_offset;
-	memset(storage,0,sizeof(super->istorage->index_esize));
+	metadata = cachefs_metadata_prewrite(super->rcm_inode);
+	memset(metadata,0,sizeof(super->imetadata->index_esize));
 
-	storage->header.state	= CACHEFS_ONDISC_INDEX_FREE;
-	storage->freelink	= trans->jentry->auxblock;
-	storage->mtime		= CURRENT_TIME.tv_sec;
-	storage->atime		= CURRENT_TIME.tv_sec;
-	kunmap(super->rcm_inode->storage);
-
-	/* modify the storage inode storage entry */
-	storage = kmap(super->istorage->storage) + super->istorage->storage_offset;
-	storage->freelink	= super->rcm_ino;
-	kunmap(super->istorage->storage);
+	metadata->header.state	= CACHEFS_ONDISC_INDEX_FREE;
+	metadata->freelink	= trans->jentry->auxblock;
+	metadata->mtime		= CURRENT_TIME.tv_sec;
+	metadata->atime		= CURRENT_TIME.tv_sec;
+	cachefs_metadata_postwrite(super->rcm_inode);
+
+	/* modify the metadata inode metadata entry */
+	metadata = cachefs_metadata_prewrite(super->imetadata);
+	metadata->freelink	= super->rcm_ino;
+	cachefs_metadata_postwrite(super->imetadata);
 
 	/* do the writing */
 	cachefs_trans_commit(trans);
@@ -567,7 +567,7 @@
 
 	kleave(" = %d",ret);
 	return ret;
-} /* end cachefs_recycle_reclaim_inode_storage() */
+} /* end cachefs_recycle_reclaim_inode_metadata() */
 
 /*****************************************************************************/
 /*
@@ -576,7 +576,7 @@
  *   (1) index entries in file content (if it's an index file)
  *   (2) data blocks and indirection blocks
  *   (3) parent index entry
- *   (4) inode storage entry
+ *   (4) inode metadata entry
  * - update journal keeps track of recycling point
  *   - rcm_ino, rcm_indirect, rcm_block, rcm_ptrnext & rcm_ptrstop
  * - work out which block we're actually dealing with from rcm_indirect:
@@ -591,7 +591,7 @@
  */
 static void cachefs_recycle_reclaim_inode(struct cachefs_super *super)
 {
-	struct cachefs_ondisc_storage *storage;
+	struct cachefs_ondisc_metadata *metadata;
 	cachefs_blockix_t bix, *pbix;
 	struct page *page, *dpage;
 	unsigned indirect;
@@ -633,9 +633,9 @@
 
 	/* process the single indirect block */
 	if (indirect == 2) {
-		storage = kmap(super->rcm_inode->storage) + super->rcm_inode->storage_offset;
-		bix = storage->single_indirect;
-		kunmap(super->rcm_inode->storage);
+		metadata = cachefs_metadata_preread(super->rcm_inode);
+		bix = metadata->single_indirect;
+		cachefs_metadata_postread(super->rcm_inode);
 
 		if (!bix)
 			goto again;
@@ -644,9 +644,9 @@
 
 	/* deal with double indirection */
 	if (indirect <= 3+N) {
-		storage = kmap(super->rcm_inode->storage) + super->rcm_inode->storage_offset;
-		bix = storage->double_indirect;
-		kunmap(super->rcm_inode->storage);
+		metadata = cachefs_metadata_preread(super->rcm_inode);
+		bix = metadata->double_indirect;
+		cachefs_metadata_postread(super->rcm_inode);
 
 		if (!bix) {
 			indirect = 3+N;
@@ -683,23 +683,25 @@
 		goto pointer_array2;
 	}
 
-	/* reclaim all the block pointers in the inode storage record */
+	/* reclaim all the block pointers in the inode metadata record */
 	if (indirect == 3+N+1) {
-		bix	= __cachefs_get_page_block(super->rcm_inode->storage)->bix;
-		next	= super->rcm_inode->storage_offset;
-		next	+= offsetof(struct cachefs_ondisc_storage,triple_indirect);
+		bix	= super->rcm_inode->metadata->bix;
+		next	= super->rcm_inode->metadata_offset;
+		next	+= offsetof(struct cachefs_ondisc_metadata,triple_indirect);
 		next	/= sizeof(cachefs_blockix_t);
 
-		stop	= super->rcm_inode->storage_offset + super->layout->storage_size;
+		stop	= super->rcm_inode->metadata_offset + super->layout->metadata_size;
 		stop	/= sizeof(cachefs_blockix_t);
 
-		page = super->rcm_inode->storage;
+		down_read(&super->rcm_inode->metadata_sem);
+		page = super->rcm_inode->metadata_page;
 		get_page(page);
+		up_read(&super->rcm_inode->metadata_sem);
 		goto pointer_array2;
 	}
 
 	/* reclaim the inode itself */
-	if (cachefs_recycle_reclaim_inode_storage(super)<0) {
+	if (cachefs_recycle_reclaim_inode_metadata(super)<0) {
 		indirect--;
 		bix	= 0;
 		next	= 0;
@@ -819,7 +821,7 @@
 
 /*****************************************************************************/
 /*
- * unallocate and recycle a single data storage block that's marked as invalid
+ * unallocate and recycle a single data metadata block that's marked as invalid
  * in the validity journal
  */
 void cachefs_recycle_unallocate_data_block(struct cachefs_super *super)

Index: journal.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/journal.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- journal.c	28 May 2003 10:32:54 -0000	1.32
+++ journal.c	2 Jun 2003 09:17:42 -0000	1.33
@@ -551,13 +551,13 @@
 	super->ujnl_head = (jstop+2) & (CACHEFS_ONDISC_UJNL_NUMENTS-1);
 
 	for (;;) {
-		ajentry = kmalloc(sizeof(*ajentry),GFP_KERNEL);
+		ajentry = kmalloc(super->layout->ujnl_rsize,GFP_KERNEL);
 		if (ajentry)
 			break;
 		yield();
 	}
 
-	memset(ajentry,0,sizeof(*ajentry));
+	memset(ajentry,0,super->layout->ujnl_rsize);
 
 	ajentry->batch		= super->ujnl_batch++;
 	ajentry->serial		= xchg(&super->ujnl_serial,0);
@@ -1339,6 +1339,7 @@
 			desc->batch_end		= ~0;
 			desc->batch_ack		= ~0;
 			desc->batch_count	= 1;
+			desc->ack_hi		= jentry->batch - 1;
 
 			if (jentry->serial == 0) {
 				desc->batch_first = slot;
@@ -1350,11 +1351,11 @@
 			/* do nothing */
 		}
 		else {
-			_debug("UJNL[%04x] mk=%s s=%d a=%d { b=%d s=%u }",
+			_debug("UJNL[%04x] mk=%s s=%d.%u { b=%d s=%u }",
 			       slot,
 			       cachefs_ondisc_ujnl_marks[jentry->mark],
+			       jentry->batch,
 			       jentry->serial,
-			       jentry->ack,
 			       super->ujnl_batch,
 			       super->ujnl_serial);
 
@@ -1396,7 +1397,7 @@
 			if (super->ujnl_serial == jentry->serial)
 				desc->batch_ack	= slot;
 
-			if (jentry->batch - desc->ack_hi < 0) {
+			if (jentry->batch - desc->ack_hi > 0) {
 				super->alloc_leaf	= jentry->alloc_leaf;
 				super->alloc_cur	= jentry->alloc_cur;
 				super->recycle_cur	= jentry->recycle_cur;
@@ -1414,6 +1415,11 @@
 				       super->rcm_ino,super->rcm_indirect,super->rcm_block,
 				       super->rcm_ptrnext,super->rcm_ptrstop);
 			}
+			else {
+				kdebug("UJNL[%u] ACK %u { hi=%u }",
+				       slot,jentry->batch,desc->ack_hi);
+			}
+
 			break;
 
 		default:

Index: inode.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/inode.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- inode.c	24 Apr 2003 12:02:34 -0000	1.17
+++ inode.c	2 Jun 2003 09:17:42 -0000	1.18
@@ -88,7 +88,7 @@
  */
 static int cachefs_iget_file0(struct cachefs_inode *inode)
 {
-	struct cachefs_ondisc_storage *storage;
+	struct cachefs_ondisc_metadata *metadata;
 	struct cachefs_super *super;
 	unsigned pos;
 	int ret;
@@ -112,36 +112,38 @@
 	inode->vfs_inode.i_fop		= &cachefs_file_operations;
 	inode->vfs_inode.i_mapping->a_ops = &cachefs_addrspace_operations;
 
-	inode->index_dsize	= super->layout->storage_bits;
+	inode->index_dsize	= super->layout->metadata_size;
 	inode->index_esize	= inode->index_dsize;
 	inode->index_epp	= PAGE_SIZE / inode->index_esize;
 
 	/* read the page containing this inode's meta-data */
-	pos = inode->vfs_inode.i_ino << super->layout->storage_bits;
-	ret = cachefs_get_page(inode,pos/PAGE_SIZE,&inode->storage);
+	pos = inode->vfs_inode.i_ino << super->layout->metadata_bits;
+	ret = cachefs_get_page(inode,pos/PAGE_SIZE,&inode->metadata_page);
 	if (ret<0) {
 		printk("kAFS: Failed to read meta-data page %lu: %d\n",pos/PAGE_SIZE,ret);
 		kleave(" = %d",ret);
 		return ret;
 	}
+	inode->metadata = __cachefs_get_page_block(inode->metadata_page);
 
-	kdebug("read page %lu (pos %04x-%04x)",inode->storage->index,pos,pos+inode->index_esize-1);
+	metadata = cachefs_metadata_preread(inode);
 
-	storage = kmap(inode->storage) + inode->storage_offset;
+	kdebug("read page %lu (pos %04x-%04x)",
+	       inode->metadata_page->index,pos,pos+inode->index_esize-1);
 
-	inode->vfs_inode.i_size		= storage->size;
-	inode->vfs_inode.i_blocks	= storage->size + inode->vfs_inode.i_blksize - 1;
+	inode->vfs_inode.i_size		= metadata->size;
+	inode->vfs_inode.i_blocks	= metadata->size + inode->vfs_inode.i_blksize - 1;
 	inode->vfs_inode.i_blocks	>>= PAGE_SHIFT;
-	inode->vfs_inode.i_version	= storage->version;
-	inode->vfs_inode.i_atime.tv_sec	= storage->mtime;
-	inode->vfs_inode.i_mtime.tv_sec	= storage->mtime;
-	inode->vfs_inode.i_ctime.tv_sec	= storage->mtime;
-
-	inode->index_dsize	= storage->index_dsize;
-	inode->index_esize	= storage->index_esize;
-	inode->index_epp	= PAGE_SIZE / storage->index_esize;
+	inode->vfs_inode.i_version	= metadata->version;
+	inode->vfs_inode.i_atime.tv_sec	= metadata->mtime;
+	inode->vfs_inode.i_mtime.tv_sec	= metadata->mtime;
+	inode->vfs_inode.i_ctime.tv_sec	= metadata->mtime;
+
+	inode->index_dsize	= metadata->index_dsize;
+	inode->index_esize	= metadata->index_esize;
+	inode->index_epp	= PAGE_SIZE / metadata->index_esize;
 
-	kunmap(inode->storage);
+	cachefs_metadata_postread(inode);
 
 	inode->vfs_inode.i_atime.tv_nsec = 0;
 	inode->vfs_inode.i_mtime.tv_nsec = 0;
@@ -158,9 +160,9 @@
  */
 static int cachefs_iget_fileN(struct cachefs_inode *inode)
 {
-	struct cachefs_ondisc_storage *storage;
+	struct cachefs_ondisc_metadata *metadata;
 	struct cachefs_super *super;
-	struct cachefs_inode *istorage;
+	struct cachefs_inode *imetadata;
 	unsigned pos;
 	int ret;
 
@@ -169,30 +171,30 @@
 	_enter("{s=%p ino=%lu}",super,inode->vfs_inode.i_ino);
 
 	/* get the meta-file inode */
-	istorage = cachefs_igrab(super->istorage);
-	if (!istorage) {
+	imetadata = cachefs_igrab(super->imetadata);
+	if (!imetadata) {
 		_leave(" = -EIO");
 		return -EIO;
 	}
 
 	/* read the page containing this inode's meta-data */
-	pos = inode->vfs_inode.i_ino * istorage->index_esize;
-	ret = cachefs_get_page(istorage,pos/PAGE_SIZE,&inode->storage);
+	pos = inode->vfs_inode.i_ino * imetadata->index_esize;
+	ret = cachefs_get_page(imetadata,pos/PAGE_SIZE,&inode->metadata_page);
+	cachefs_iput(imetadata);
 	if (ret<0) {
 		printk("CacheFS: Failed to read meta-data page %lu: %d\n",pos/PAGE_SIZE,ret);
-		cachefs_iput(istorage);
 		kleave(" = %d",ret);
 		return ret;
 	}
-	cachefs_iput(istorage);
+	inode->metadata = __cachefs_get_page_block(inode->metadata_page);
 
-	_debug("Reading inode %lu storage record {%lu,{%u}}+%04x",
-	       inode->vfs_inode.i_ino,inode->storage->index,
-	       __cachefs_get_page_block(inode->storage)->bix,pos);
+	_debug("Reading inode %lu metadata record {%lu,{%u}}+%04x",
+	       inode->vfs_inode.i_ino,inode->metadata_page->index,
+	       inode->metadata->bix,pos);
 
 #if 0
-	if (inode->storage.mtime==0) {
-		inode->storage.mtime = CURRENT_TIME;
+	if (inode->metadata.mtime==0) {
+		inode->metadata.mtime = CURRENT_TIME;
 		mark_inode_dirty(&inode->vfs_inode);
 	}
 #endif
@@ -200,33 +202,34 @@
 	inode->vfs_inode.i_mtime.tv_nsec = 0;
 	inode->vfs_inode.i_ctime.tv_nsec = 0;
 
-	storage = kmap(inode->storage) + inode->storage_offset;
+	metadata = cachefs_metadata_preread(inode);
 
 	inode->vfs_inode.i_mode		= S_IFREG | S_IRUGO;
 	inode->vfs_inode.i_uid		= 0;
 	inode->vfs_inode.i_gid		= 0;
 	inode->vfs_inode.i_nlink	= 1;
-	inode->vfs_inode.i_size		= storage->size;
-	inode->vfs_inode.i_atime.tv_sec	= storage->mtime;
-	inode->vfs_inode.i_mtime.tv_sec	= storage->mtime;
-	inode->vfs_inode.i_ctime.tv_sec	= storage->mtime;
+	inode->vfs_inode.i_size		= metadata->size;
+	inode->vfs_inode.i_atime.tv_sec	= metadata->mtime;
+	inode->vfs_inode.i_mtime.tv_sec	= metadata->mtime;
+	inode->vfs_inode.i_ctime.tv_sec	= metadata->mtime;
 	inode->vfs_inode.i_blksize	= PAGE_SIZE;
 	inode->vfs_inode.i_blkbits	= PAGE_SHIFT;
-	inode->vfs_inode.i_blocks	= storage->size + inode->vfs_inode.i_blksize-1;
+	inode->vfs_inode.i_blocks	= metadata->size + inode->vfs_inode.i_blksize-1;
 	inode->vfs_inode.i_blocks	>>= PAGE_SHIFT;
-	inode->vfs_inode.i_version	= storage->version;
+	inode->vfs_inode.i_version	= metadata->version;
 	inode->vfs_inode.i_flags	|= S_NOATIME;
 	inode->vfs_inode.i_op		= &cachefs_inode_operations;
 	inode->vfs_inode.i_fop		= &cachefs_file_operations;
 	inode->vfs_inode.i_mapping->a_ops = &cachefs_addrspace_operations;
 
-	inode->index_dsize	= storage->index_dsize;
-	inode->index_esize	= storage->index_esize;
-	kunmap(inode->storage);
+	inode->index_dsize	= metadata->index_dsize;
+	inode->index_esize	= metadata->index_esize;
+
+	cachefs_metadata_postread(inode);
 
 	inode->index_epp = 0;
 	if (inode->index_esize || inode->vfs_inode.i_ino==CACHEFS_INO_ROOTDIR) {
-		inode->index_epp = PAGE_SIZE / storage->index_esize;
+		inode->index_epp = PAGE_SIZE / metadata->index_esize;
 		inode->vfs_inode.i_mode		= S_IFDIR | S_IRUGO | S_IXUGO;
 		inode->vfs_inode.i_nlink	= 2;
 		inode->vfs_inode.i_op		= &cachefs_root_inode_operations;
@@ -292,9 +295,9 @@
 		cachefs_iget_status_file(inode);
 		break;
 
-		/* storage meta-data inode */
-	case CACHEFS_INO_STORAGE:
-		inode->storage_offset = (ino << super->layout->storage_bits) & ~PAGE_MASK;
+		/* metadata meta-data inode */
+	case CACHEFS_INO_METADATA:
+		inode->metadata_offset = (ino << super->layout->metadata_bits) & ~PAGE_MASK;
 		ret = cachefs_iget_file0(inode);
 		if (ret<0)
 			goto bad_inode;
@@ -302,7 +305,7 @@
 
 		/* index and data-cache inodes */
 	default:
-		inode->storage_offset = (ino << super->layout->storage_bits) & ~PAGE_MASK;
+		inode->metadata_offset = (ino << super->layout->metadata_bits) & ~PAGE_MASK;
 		ret = cachefs_iget_fileN(inode);
 		if (ret<0)
 			goto bad_inode;
@@ -366,7 +369,7 @@
 void cachefs_write_inode(struct inode *vfs_inode, int sync)
 {
 #if 0
-	struct cachefs_ondisc_storage *storage;
+	struct cachefs_ondisc_metadata *metadata;
 	struct cachefs_super *super;
 	struct cachefs_inode *inode;
 	struct bio *bio;
@@ -389,50 +392,50 @@
 
 	tmp = (ino << super->sb->s_blocksize_bits) & (PAGE_SIZE-1);
 
-	_debug("Writing inode %u storage record {{%u}}+%04x",
-	       ino,cachefs_pageio(inode->storage)->mapped_block,tmp);
+	_debug("Writing inode %u metadata record {{%u}}+%04x",
+	       ino,cachefs_pageio(inode->metadata)->mapped_block,tmp);
 
-	bio->bi_sector	= __cachefs_get_page_block(inode->storage)->bix;
+	bio->bi_sector	= __cachefs_get_page_block(inode->metadata)->bix;
 	bio->bi_sector	<<= (PAGE_SHIFT - super->sb->s_blocksize_bits);
 	bio->bi_sector	+= tmp >> super->sb->s_blocksize_bits;
 	bio->bi_bdev	= super->sb->s_bdev;
 	bio->bi_end_io	= cachefs_end_write_inode;
 
-	if (!bio_add_page(bio,inode->storage,super->sb->s_blocksize,tmp))
+	if (!bio_add_page(bio,inode->metadata,super->sb->s_blocksize,tmp))
 		BUG();
 
 	/* make the change */
-	lock_page(inode->storage);
+	lock_page(inode->metadata);
 
-	storage =
-		kmap(inode->storage) +
-		(ino % CACHEFS_STORAGE_PER_PAGE) * CACHEFS_ONDISC_STORAGE_RECSIZE;
+	metadata =
+		kmap(inode->metadata) +
+		(ino % CACHEFS_METADATA_PER_PAGE) * CACHEFS_ONDISC_METADATA_RECSIZE;
 
-	storage->size		= inode->vfs_inode.i_size;
-	storage->version	= inode->vfs_inode.i_version;
-	storage->mtime		= inode->vfs_inode.i_mtime.tv_sec;
+	metadata->size		= inode->vfs_inode.i_size;
+	metadata->version	= inode->vfs_inode.i_version;
+	metadata->mtime		= inode->vfs_inode.i_mtime.tv_sec;
 
-	kunmap(inode->storage);
-	flush_dcache_page(inode->storage);
+	kunmap(inode->metadata);
+	flush_dcache_page(inode->metadata);
 
-	SetPageWriteback(inode->storage);
-	unlock_page(inode->storage);
+	SetPageWriteback(inode->metadata);
+	unlock_page(inode->metadata);
 
 	submit_bio(WRITE,bio);
 	if (sync)
-		wait_on_page_writeback(inode->storage);
+		wait_on_page_writeback(inode->metadata);
 #endif
 
 #if 0
 	/* update the modification time of the meta-data inode */
-	if (inode!=istorage) {
+	if (inode!=imetadata) {
 		time_t time_now = CURRENT_TIME;
-		if (istorage->vfs_inode.i_ctime != time_now ||
-		    istorage->vfs_inode.i_mtime != time_now
+		if (imetadata->vfs_inode.i_ctime != time_now ||
+		    imetadata->vfs_inode.i_mtime != time_now
 		    ) {
-			istorage->vfs_inode.i_ctime = time_now;
-			istorage->vfs_inode.i_mtime = time_now;
-			mark_inode_dirty_sync(&istorage->vfs_inode);
+			imetadata->vfs_inode.i_ctime = time_now;
+			imetadata->vfs_inode.i_mtime = time_now;
+			mark_inode_dirty_sync(&imetadata->vfs_inode);
 		}
 	}
 #endif

Index: index.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/index.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- index.c	28 May 2003 10:32:54 -0000	1.18
+++ index.c	2 Jun 2003 09:17:42 -0000	1.19
@@ -12,10 +12,10 @@
 /*
  * - all index files are arranged in pages
  *   - each page contains an array of fixed length records
- *     - the length recorded in the storage data for that file
+ *     - the length recorded in the metadata data for that file
  *   - each page will have a gap at the end if the records don't fit exactly
  *   - normally all pages will be allocated and there won't be any holes
- *     - the storage records file is the only exception to this
+ *     - the metadata records file is the only exception to this
  * - each file maintains a list of allocated but currently unused entries
  */
 
@@ -162,7 +162,7 @@
 static int cachefs_index_preinit_page(void *data, struct page *page)
 {
 	struct cachefs_ondisc_index_entry *xent;
-	struct cachefs_ondisc_storage *storage;
+	struct cachefs_ondisc_metadata *metadata;
 	struct cachefs_inode *iinode;
 	struct cachefs_page *pageio;
 	u_int32_t entry, next;
@@ -173,12 +173,14 @@
 	kenter("{%lu},%p{%lu}",iinode->vfs_inode.i_ino,page,page->index);
 
 	ret = cachefs_page_get_private(page,&pageio,GFP_KERNEL);
-	if (ret<0)
+	if (ret<0) {
+		kleave(" = %d",ret);
 		return ret;
+	}
 
-	storage = kmap(iinode->storage) + iinode->storage_offset;
-	next = storage->freelink;
-	kunmap(storage);
+	metadata = cachefs_metadata_preread(iinode);
+	next = metadata->freelink;
+	cachefs_metadata_postread(iinode);
 
 	entry = page->index * iinode->index_epp;
 
@@ -196,12 +198,9 @@
 
 	kdebug("new freelink: %u",next);
 
-	storage = kmap(iinode->storage) + iinode->storage_offset;
-	storage->freelink = next;
-	kunmap(storage);
-
-	flush_dcache_page(iinode->storage);
-	flush_dcache_page(page);
+	metadata = cachefs_metadata_prewrite(iinode);
+	metadata->freelink = next;
+	cachefs_metadata_postwrite(iinode);
 
 	SetPageUptodate(page);
 	unlock_page(page);
@@ -220,7 +219,7 @@
 					   unsigned *_next)
 {
 	struct cachefs_ondisc_index_entry *xent;
-	struct cachefs_ondisc_storage *storage;
+	struct cachefs_ondisc_metadata *metadata;
 	struct page *page;
 	unsigned newentry, pgnum, offset;
 	int ret;
@@ -231,9 +230,9 @@
 	*_newentry	= 0;
 	*_next		= 0;
 
-	storage = kmap(iinode->storage) + iinode->storage_offset;
-	newentry = storage->freelink;
-	kunmap(iinode->storage);
+	metadata = cachefs_metadata_preread(iinode);
+	newentry = metadata->freelink;
+	cachefs_metadata_postread(iinode);
 
 	kdebug("free entry: %u",newentry);
 
@@ -260,9 +259,9 @@
 			goto error2;
 		}
 
-		storage = kmap(iinode->storage) + iinode->storage_offset;
-		newentry = storage->freelink;
-		kunmap(iinode->storage);
+		metadata = cachefs_metadata_preread(iinode);
+		newentry = metadata->freelink;
+		cachefs_metadata_postread(iinode);
 
 		BUG_ON(newentry==UINT_MAX);
 
@@ -314,7 +313,7 @@
 		      unsigned *_newino)
 {
 	struct cachefs_ondisc_index_entry *xent;
-	struct cachefs_ondisc_storage *storage;
+	struct cachefs_ondisc_metadata *metadata;
 	struct cachefs_search_result *srch;
 	struct cachefs_transaction *trans;
 	struct cachefs_super *super;
@@ -336,7 +335,7 @@
 	if (ret<0)
 		goto error;
 
-	ret = cachefs_index_select_free_entry(super->istorage,&inopage,&ino,&inonext);
+	ret = cachefs_index_select_free_entry(super->imetadata,&inopage,&ino,&inonext);
 	if (ret<0)
 		goto error;
 
@@ -365,16 +364,16 @@
 	trans->jentry->auxblock	= inonext;
 	trans->jentry->upblock	= ixnext;
 
-	ino_offset = ino % super->istorage->index_epp;
-	ino_offset <<= super->layout->storage_bits;
+	ino_offset = ino % super->imetadata->index_epp;
+	ino_offset <<= super->layout->metadata_bits;
 
 	cachefs_trans_affects_page(trans,__cachefs_page_get_private(ixpage),offset,
 				   index->index_esize);
 	cachefs_trans_affects_page(trans,__cachefs_page_get_private(inopage),ino_offset,
-				   super->layout->storage_size);
+				   super->layout->metadata_size);
 
 	cachefs_trans_affects_inode(trans,index);
-	cachefs_trans_affects_inode(trans,super->istorage);
+	cachefs_trans_affects_inode(trans,super->imetadata);
 
 	ret = cachefs_trans_mark(trans);
 	if (ret<0)
@@ -396,48 +395,48 @@
 
 	kunmap(ixpage);
 
-	/* modify the index inode storage entry */
-	storage = kmap(index->storage) + index->storage_offset;
-	storage->freelink	= ixnext;
-	storage->atime		= CURRENT_TIME.tv_sec;
-	kunmap(index->storage);
+	/* modify the index inode metadata entry */
+	metadata = cachefs_metadata_prewrite(index);
+	metadata->freelink	= ixnext;
+	metadata->atime		= CURRENT_TIME.tv_sec;
+	cachefs_metadata_postwrite(index);
 
 	/* fill the inode definition */
-	storage = kmap(inopage) + ino_offset;
-	memset(storage,0,sizeof(super->istorage->index_esize));
+	metadata = kmap(inopage) + ino_offset;
+	memset(metadata,0,sizeof(super->imetadata->index_esize));
 
-	storage->header.state	= CACHEFS_ONDISC_INDEX_ACTIVE;
-	storage->header.ino	= 0xfefefe;
-	storage->size		= 0;
-	storage->freelink	= UINT_MAX;
-	storage->mtime		= CURRENT_TIME.tv_sec;
-	storage->atime		= CURRENT_TIME.tv_sec;
-	storage->pindex		= index->vfs_inode.i_ino;
-	storage->pindex_entry	= ixentry;
+	metadata->header.state	= CACHEFS_ONDISC_INDEX_ACTIVE;
+	metadata->header.ino	= 0xfefefe;
+	metadata->size		= 0;
+	metadata->freelink	= UINT_MAX;
+	metadata->mtime		= CURRENT_TIME.tv_sec;
+	metadata->atime		= CURRENT_TIME.tv_sec;
+	metadata->pindex	= index->vfs_inode.i_ino;
+	metadata->pindex_entry	= ixentry;
 
 	if (cookie->idef) {
 		struct cachefs_index_def *definition = cookie->idef;
 
-		storage->index_dsize	= definition->data_size;
-		storage->index_esize	= storage->index_dsize;
-		storage->index_esize	+= sizeof(struct cachefs_ondisc_index_entry);
+		metadata->index_dsize	= definition->data_size;
+		metadata->index_esize	= metadata->index_dsize;
+		metadata->index_esize	+= sizeof(struct cachefs_ondisc_index_entry);
 
 		for (loop=0; loop<4; loop++) {
-			storage->index_keys[loop] = definition->keys[loop].len;
-			storage->index_keys[loop] &= CACHEFS_ONDISC_INDEXKEY_KLEN;
-			storage->index_keys[loop] |= definition->keys[loop].type << 12;
+			metadata->index_keys[loop] = definition->keys[loop].len;
+			metadata->index_keys[loop] &= CACHEFS_ONDISC_INDEXKEY_KLEN;
+			metadata->index_keys[loop] |= definition->keys[loop].type << 12;
 		}
 
-		strncpy(storage->index_type,definition->name,sizeof(storage->index_type));
+		strncpy(metadata->index_type,definition->name,sizeof(metadata->index_type));
 	}
 
 	kunmap(inopage);
 
-	/* modify the storage inode storage entry */
-	storage = kmap(super->istorage->storage) + super->istorage->storage_offset;
-	storage->freelink	= inonext;
-	storage->atime		= CURRENT_TIME.tv_sec;
-	kunmap(super->istorage->storage);
+	/* modify the metadata inode metadata entry */
+	metadata = cachefs_metadata_prewrite(super->imetadata);
+	metadata->freelink	= inonext;
+	metadata->atime		= CURRENT_TIME.tv_sec;
+	cachefs_metadata_postwrite(super->imetadata);
 
 	/* do the writing */
 	cachefs_trans_commit(trans);
@@ -469,7 +468,7 @@
 int cachefs_index_zap(struct cachefs_super *super)
 {
 	struct cachefs_ondisc_index_entry *xent;
-	struct cachefs_ondisc_storage *storage;
+	struct cachefs_ondisc_metadata *metadata;
 	struct cachefs_transaction *trans = NULL;
 	struct cachefs_inode *inode = NULL;
 	unsigned long flags;
@@ -525,12 +524,12 @@
 	if (ret<0)
 		goto error_skip;
 
-	/* modify the inode storage entry */
-	storage = kmap(inode->storage) + inode->storage_offset;
-	storage->header.state	= CACHEFS_ONDISC_INDEX_RECYCLE;
-	storage->pindex		= 0;
-	storage->pindex_entry	= 0;
-	kunmap(inode->storage);
+	/* modify the inode metadata entry */
+	metadata = cachefs_metadata_prewrite(inode);
+	metadata->header.state	= CACHEFS_ONDISC_INDEX_RECYCLE;
+	metadata->pindex	= 0;
+	metadata->pindex_entry	= 0;
+	cachefs_metadata_postwrite(inode);
 
 	cachefs_trans_commit(trans);
 	trans = NULL;
@@ -593,7 +592,7 @@
 int cachefs_replay_ujnl_inode_deleting(struct cachefs_super *super,
 				       struct cachefs_ondisc_update_journal *jentry)
 {
-	printk("CacheFS: u-jnl mark UJNL_INODE_DELETING not yet supported\n"
+	printk("CacheFS: u-jnl mark UJNL_INODE_DELETING not yet supported\n");
 	return -EIO;
 } /* end cachefs_replay_ujnl_inode_deleting() */

Index: cachefs-layout.h
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/cachefs-layout.h,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- cachefs-layout.h	28 May 2003 10:32:54 -0000	1.24
+++ cachefs-layout.h	2 Jun 2003 09:17:42 -0000	1.25
@@ -16,7 +16,7 @@
 
 enum cachefs_meta_inode_numbers {
 	CACHEFS_INO_NULL		= 0x00000000,
-	CACHEFS_INO_STORAGE		= 0x00000001,
+	CACHEFS_INO_METADATA		= 0x00000001,
 	CACHEFS_INO_FSDEF_CATALOGUE,
 	CACHEFS_INO_ROOTDIR		= CACHEFS_INO_FSDEF_CATALOGUE,
 	CACHEFS_INO_WIBBLE,		/* TODO: remove */
@@ -51,8 +51,8 @@
 
 	/* layout */
 	u_int32_t			bsize;		/* cache block size */
-	u_int32_t			storage_size;	/* cache storage record size */
-	u_int32_t			storage_bits;	/* log2 cache storage record size */
+	u_int32_t			metadata_size;	/* cache metadata record size */
+	u_int32_t			metadata_bits;	/* log2 cache metadata record size */
 	u_int32_t			ujnl_rsize;	/* update journal record size */
 	u_int32_t			ujnl_recperblk;	/* u-journal records per block */
 	cachefs_blockix_t		bix_ujournal;	/* start of update journal */
@@ -87,17 +87,16 @@
 
 /*****************************************************************************/
 /*
- * on-disc storage metadata record
- * - padded out to sector size and stored several to a page
+ * on-disc metadata record
+ * - padded out to sector size and stored several to a block
  * - only the data version is necessary
  *   - disconnected operation is not supported
  *   - afs_iget() contacts the server to get the meta-data _anyway_ when an inode is first brought
  *     into memory
  * - at least 64 direct block pointers will be available
  * - any block pointer which is 0 indicates an uncached page
- * - storage, fsdef and index files have an entry size set cachefs_ondisc_storage
  */
-struct cachefs_ondisc_storage
+struct cachefs_ondisc_metadata
 {
 	struct cachefs_ondisc_index_entry header;

Index: cachefs-int.h
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/cachefs-int.h,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- cachefs-int.h	28 May 2003 10:32:54 -0000	1.33
+++ cachefs-int.h	2 Jun 2003 09:17:42 -0000	1.34
@@ -67,7 +67,7 @@
 {
 	struct super_block		*sb;
 	struct list_head		mnt_link;	/* link in list of mounted caches */
-	struct cachefs_inode		*istorage;	/* the storage metadata records file */
+	struct cachefs_inode		*imetadata;	/* the metadata records file */
 	struct inode			*imisc;		/* an inode covering the whole blkdev */
 
 	unsigned long			flags;
@@ -213,6 +213,116 @@
 
 /*****************************************************************************/
 /*
+ * block management record
+ */
+struct cachefs_block
+{
+	struct rb_node			lookup_node;	/* node in superblock's lookup tree */
+	struct cachefs_super		*super;		/* superblock on which block resides */
+	cachefs_blockix_t		bix;		/* index of block on disc */
+	atomic_t			usage;		/* usage count */
+	wait_queue_head_t		writewq;	/* write completion sleep queue */
+	unsigned long			flags;
+#define CACHEFS_BLOCK_ALLOC	0	/* [bit] page allocation lock */
+#define CACHEFS_BLOCK_WRITEBACK	1	/* [bit] block undergoing writeback */
+#define CACHEFS_BLOCK_COW	2	/* [bit] page must be copied before modification */
+#define CACHEFS_BLOCK_NOCOW	3	/* [bit] page mustn't be COW'ed */
+#define CACHEFS_BLOCK_ERROR	4	/* [bit] block has disc error */
+#define CACHEFS_BLOCK_UJOURNAL	5	/* [bit] block holds update journal entries */
+#define CACHEFS_BLOCK_CRITICAL	6	/* [bit] block holds critical data that mustn't be
+					 *       zapped until sync'd */
+#define CACHEFS_BLOCK_WITHDRAWN	7	/* [bit] backing cache withdrawn from service */
+#define CACHEFS_BLOCK_NETFSBUSY	8	/* [bit] netfs is accessing the block */
+
+#define _CACHEFS_BLOCK_ALLOC		(1 << CACHEFS_BLOCK_ALLOC)
+#define _CACHEFS_BLOCK_COW		(1 << CACHEFS_BLOCK_COW)
+#define _CACHEFS_BLOCK_WRITEBACK	(1 << CACHEFS_BLOCK_WRITEBACK)
+#define _CACHEFS_BLOCK_UJOURNAL		(1 << CACHEFS_BLOCK_UJOURNAL)
+
+	struct list_head		batch_link;	/* link in batch writer's list */
+	struct page			*page;		/* current data for this block */
+	struct page			*writeback;	/* source of writeback for this block */
+	struct cachefs_page		*ref;		/* netfs's ref to this page */
+	rwlock_t			ref_lock;	/* lock governing ref pointer */
+	struct cachefs_vj_entry		*vjentry;	/* invalid block record */
+};
+
+extern kmem_cache_t *cachefs_block_jar;
+
+extern void cachefs_block_init_once(void *_block, kmem_cache_t *cachep, unsigned long flags);
+
+extern int cachefs_block_insert(struct cachefs_super *super,
+				cachefs_blockix_t bix,
+				struct cachefs_block **_block);
+
+extern int cachefs_block_find(struct cachefs_super *super,
+			      cachefs_blockix_t bix,
+			      struct cachefs_block **_block);
+
+extern int cachefs_block_set(struct cachefs_super *super,
+			     struct cachefs_block *block,
+			     struct page *page,
+			     struct cachefs_page *pageio);
+
+extern int cachefs_block_set2(struct cachefs_super *super,
+			      cachefs_blockix_t bix,
+			      struct page *page,
+			      struct cachefs_page *pageio,
+			      struct cachefs_block **_block);
+
+extern int cachefs_block_read(struct cachefs_super *super,
+			      struct cachefs_inode *inode,
+			      cachefs_blockix_t bix,
+			      int wipe,
+			      struct cachefs_block **_block,
+			      struct page **_page);
+
+extern void cachefs_block_modify(struct cachefs_super *super,
+				 struct cachefs_block *block,
+				 struct page **_page);
+
+extern int cachefs_block_cow(struct cachefs_super *super, struct cachefs_block *block);
+
+static inline struct cachefs_block *cachefs_block_get(struct cachefs_block *block)
+{
+	atomic_inc(&block->usage);
+	return block;
+}
+
+extern void __cachefs_block_put(struct cachefs_block *block);
+
+static inline void cachefs_block_put(struct cachefs_block *block)
+{
+	if (block) {
+		int usage = atomic_read(&block->usage);
+		/*kenter(",{bix=%u u=%d",block->bix,atomic_read(&block->usage));*/
+
+		if ((usage&0xffffff00)==0x6b6b6b00) {
+			printk("\ncachefs_block_put(%p{u=%d})\n",block,usage);
+			BUG();
+		}
+
+		BUG_ON(usage<=0);
+		if (atomic_dec_and_test(&block->usage))
+			__cachefs_block_put(block);
+	}
+}
+
+static inline struct cachefs_block *__cachefs_get_page_block(struct page *page)
+{
+	BUG_ON(!PagePrivate(page));
+	return ((struct cachefs_page *) page->private)->mapped_block;
+}
+
+static inline void cachefs_page_modify(struct cachefs_super *super, struct page **page)
+{
+	cachefs_block_modify(super,__cachefs_get_page_block(*page),page);
+}
+
+extern void cachefs_block_withdraw(struct cachefs_super *super);
+
+/*****************************************************************************/
+/*
  * data file or index object cookie
  * - a file will only appear in one cache
  * - a request to cache a file may or may not be honoured, subject to constraints such as disc
@@ -250,8 +360,10 @@
 {
 	struct inode			vfs_inode;	/* VFS inode record for this file */
 
-	struct page			*storage;	/* page in mem containing storage info */
-	unsigned short			storage_offset;	/* data storage record offset */
+	struct cachefs_block		*metadata;	/* block containing metadata */
+	struct page			*metadata_page;	/* page mapped to metadata block */
+	struct rw_semaphore		metadata_sem;	/* metadata page access semaphore */
+	unsigned short			metadata_offset; /* metadata record offset */
 
 	unsigned short			index_dsize;	/* size of data in each index entry */
 	unsigned short			index_esize;	/* size of index entries */
@@ -297,6 +409,35 @@
 		page_cache_release(page);
 }
 
+static inline
+struct cachefs_ondisc_metadata *cachefs_metadata_preread(struct cachefs_inode *inode)
+{
+	down_read(&inode->metadata_sem);
+	return kmap(inode->metadata_page) + inode->metadata_offset;
+}
+
+static inline
+void cachefs_metadata_postread(struct cachefs_inode *inode)
+{
+	kunmap(inode->metadata_page);
+	up_read(&inode->metadata_sem);
+}
+
+static inline
+struct cachefs_ondisc_metadata *cachefs_metadata_prewrite(struct cachefs_inode *inode)
+{
+	down_write(&inode->metadata_sem);
+	cachefs_block_modify(inode->metadata->super,inode->metadata,&inode->metadata_page);
+	return kmap(inode->metadata_page) + inode->metadata_offset;
+}
+
+static inline
+void cachefs_metadata_postwrite(struct cachefs_inode *inode)
+{
+	kunmap(inode->metadata_page);
+	up_write(&inode->metadata_sem);
+}
+
 extern void cachefs_withdraw_inode(struct cachefs_inode *inode);
 
 extern int cachefs_index_search(struct cachefs_inode *index,
@@ -341,116 +482,6 @@
 
 /*****************************************************************************/
 /*
- * block management record
- */
-struct cachefs_block
-{
-	struct rb_node			lookup_node;	/* node in superblock's lookup tree */
-	struct cachefs_super		*super;		/* superblock on which block resides */
-	cachefs_blockix_t		bix;		/* index of block on disc */
-	atomic_t			usage;		/* usage count */
-	wait_queue_head_t		writewq;	/* write completion sleep queue */
-	unsigned long			flags;
-#define CACHEFS_BLOCK_ALLOC	0	/* [bit] page allocation lock */
-#define CACHEFS_BLOCK_WRITEBACK	1	/* [bit] block undergoing writeback */
-#define CACHEFS_BLOCK_COW	2	/* [bit] page must be copied before modification */
-#define CACHEFS_BLOCK_NOCOW	3	/* [bit] page mustn't be COW'ed */
-#define CACHEFS_BLOCK_ERROR	4	/* [bit] block has disc error */
-#define CACHEFS_BLOCK_UJOURNAL	5	/* [bit] block holds update journal entries */
-#define CACHEFS_BLOCK_CRITICAL	6	/* [bit] block holds critical data that mustn't be
-					 *       zapped until sync'd */
-#define CACHEFS_BLOCK_WITHDRAWN	7	/* [bit] backing cache withdrawn from service */
-#define CACHEFS_BLOCK_NETFSBUSY	8	/* [bit] netfs is accessing the block */
-
-#define _CACHEFS_BLOCK_ALLOC		(1 << CACHEFS_BLOCK_ALLOC)
-#define _CACHEFS_BLOCK_COW		(1 << CACHEFS_BLOCK_COW)
-#define _CACHEFS_BLOCK_WRITEBACK	(1 << CACHEFS_BLOCK_WRITEBACK)
-#define _CACHEFS_BLOCK_UJOURNAL		(1 << CACHEFS_BLOCK_UJOURNAL)
-
-	struct list_head		batch_link;	/* link in batch writer's list */
-	struct page			*page;		/* current data for this block */
-	struct page			*writeback;	/* source of writeback for this block */
-	struct cachefs_page		*ref;		/* netfs's ref to this page */
-	rwlock_t			ref_lock;	/* lock governing ref pointer */
-	struct cachefs_vj_entry		*vjentry;	/* invalid block record */
-};
-
-extern kmem_cache_t *cachefs_block_jar;
-
-extern void cachefs_block_init_once(void *_block, kmem_cache_t *cachep, unsigned long flags);
-
-extern int cachefs_block_insert(struct cachefs_super *super,
-				cachefs_blockix_t bix,
-				struct cachefs_block **_block);
-
-extern int cachefs_block_find(struct cachefs_super *super,
-			      cachefs_blockix_t bix,
-			      struct cachefs_block **_block);
-
-extern int cachefs_block_set(struct cachefs_super *super,
-			     struct cachefs_block *block,
-			     struct page *page,
-			     struct cachefs_page *pageio);
-
-extern int cachefs_block_set2(struct cachefs_super *super,
-			      cachefs_blockix_t bix,
-			      struct page *page,
-			      struct cachefs_page *pageio,
-			      struct cachefs_block **_block);
-
-extern int cachefs_block_read(struct cachefs_super *super,
-			      struct cachefs_inode *inode,
-			      cachefs_blockix_t bix,
-			      int wipe,
-			      struct cachefs_block **_block,
-			      struct page **_page);
-
-extern void cachefs_block_modify(struct cachefs_super *super,
-				 struct cachefs_block *block,
-				 struct page **_page);
-
-extern int cachefs_block_cow(struct cachefs_super *super, struct cachefs_block *block);
-
-static inline struct cachefs_block *cachefs_block_get(struct cachefs_block *block)
-{
-	atomic_inc(&block->usage);
-	return block;
-}
-
-extern void __cachefs_block_put(struct cachefs_block *block);
-
-static inline void cachefs_block_put(struct cachefs_block *block)
-{
-	if (block) {
-		int usage = atomic_read(&block->usage);
-		/*kenter(",{bix=%u u=%d",block->bix,atomic_read(&block->usage));*/
-
-		if ((usage&0xffffff00)==0x6b6b6b00) {
-			printk("\ncachefs_block_put(%p{u=%d})\n",block,usage);
-			BUG();
-		}
-
-		BUG_ON(usage<=0);
-		if (atomic_dec_and_test(&block->usage))
-			__cachefs_block_put(block);
-	}
-}
-
-static inline struct cachefs_block *__cachefs_get_page_block(struct page *page)
-{
-	BUG_ON(!PagePrivate(page));
-	return ((struct cachefs_page *) page->private)->mapped_block;
-}
-
-static inline void cachefs_page_modify(struct cachefs_super *super, struct page **page)
-{
-	cachefs_block_modify(super,__cachefs_get_page_block(*page),page);
-}
-
-extern void cachefs_block_withdraw(struct cachefs_super *super);
-
-/*****************************************************************************/
-/*
  * record of as-yet invalid data block for which a v-journal entry exists
  */
 struct cachefs_vj_entry
@@ -546,10 +577,10 @@
 {
 	struct cachefs_super *super = inode->vfs_inode.i_sb->s_fs_info;
 
-	cachefs_trans_affects_page(trans,
-				   __cachefs_page_get_private(inode->storage),
-				   inode->storage_offset,
-				   super->layout->storage_size);
+	cachefs_trans_affects_block(trans,
+				    inode->metadata,
+				    inode->metadata_offset,
+				    super->layout->metadata_size);
 }
 
 static inline void cachefs_trans_affects_super(struct cachefs_transaction *trans)

Index: aops.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/aops.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- aops.c	28 May 2003 10:32:54 -0000	1.30
+++ aops.c	2 Jun 2003 09:17:42 -0000	1.31
@@ -28,7 +28,7 @@
 #include "cachefs-int.h"
 
 struct cachefs_io_block_path {
-	struct page			*page;		/* page holding this block */
+	struct page			*page;
 	struct cachefs_page		*pageio;	/* page => block mapping */
 	cachefs_blockix_t		bix;		/* block number for this level */
 	unsigned			offset;		/* offset into parent pointer block */
@@ -110,7 +110,7 @@
 	const int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags);
 	struct bio_vec *bvec = bio->bi_io_vec + bio->bi_vcnt - 1;
 
-	_enter("{sz=%u rw=%lu},%u,%d",bio->bi_size,bio->bi_rw,bytes_done,err);
+	kenter("{sz=%u rw=%lu},%u,%d",bio->bi_size,bio->bi_rw,bytes_done,err);
 
 	if (bio->bi_size)
 		return 1;
@@ -293,7 +293,7 @@
 
 	last_block = (inode->i_size + PAGE_SIZE - 1) >> PAGE_SHIFT;
 	if (page->index < last_block) {
-		if (inode->i_ino==CACHEFS_INO_STORAGE && page->index==0) {
+		if (inode->i_ino==CACHEFS_INO_METADATA && page->index==0) {
 			ret = cachefs_block_set2(inode->i_sb->s_fs_info,1,page,pageio,NULL);
 			if (ret<0)
 				goto error;
@@ -879,7 +879,7 @@
 
 	struct cachefs_ondisc_update_journal *jentry;
 	struct cachefs_ondisc_free_node *node;
-	struct cachefs_ondisc_storage *storage;
+	struct cachefs_ondisc_metadata *metadata;
 	struct cachefs_super *super = sb->s_fs_info;
 	struct cachefs_block *block;
 	cachefs_blockix_t alloc2os = 0;
@@ -1064,21 +1064,29 @@
 
 	up(&super->alloc_sem);
 
-	/* change the appropriate pointer on disc to point to this block */
-	cachefs_page_modify(super,&step[1].page);
-
+	/* set the appropriate pointer on disc to point to this block */
 	step->bix = jentry->block;
-	data = kmap(step[1].page);
-	*(cachefs_blockix_t *)(data + step->offset) = step->bix;
-	kunmap(data);
 
-	unlock_page(step[1].page);
+	if (!(step[1].flags & CACHEFS_BLOCK_IS_INODE)) {
+		cachefs_page_modify(super,&step[1].page);
 
-	/* keep track of file size (mainly for index files) */
-	storage = kmap(inode->storage) + inode->storage_offset;
-	storage->size	= inode->vfs_inode.i_size;
-	storage->mtime	= CURRENT_TIME.tv_sec;
-	kunmap(inode->storage);
+		data = kmap(step[1].page);
+		*(cachefs_blockix_t *)(data + step->offset) = step->bix;
+		kunmap(data);
+	}
+
+	metadata = cachefs_metadata_prewrite(inode);
+	metadata->size	= inode->vfs_inode.i_size;
+	metadata->mtime	= CURRENT_TIME.tv_sec;
+
+	if (step[1].flags & CACHEFS_BLOCK_IS_INODE) {
+		unsigned long pageaddr = (unsigned long) metadata & PAGE_MASK;
+		*(cachefs_blockix_t *)(pageaddr + step->offset) = step->bix;
+	}
+
+	cachefs_metadata_postwrite(inode);
+
+	unlock_page(step[1].page);
 
 	/* okay... done that */
 	cachefs_trans_commit(step->transaction);
@@ -1161,16 +1169,16 @@
 
 	/* is it inside direct range? */
 	iblock = page->index;
-	ptrqty = super->sb->s_blocksize - sizeof(struct cachefs_ondisc_storage);
+	ptrqty = super->sb->s_blocksize - sizeof(struct cachefs_ondisc_metadata);
 	ptrqty /= sizeof(cachefs_blockix_t);
 	if (iblock < ptrqty) {
 		kdebug("direct (%llu/%u)",iblock,ptrqty);
 		notboundary = ptrqty - iblock + 1;
 
 		path[0].offset	= iblock * sizeof(cachefs_blockix_t);
-		path[0].offset	+= offsetof(struct cachefs_ondisc_storage,direct);
+		path[0].offset	+= offsetof(struct cachefs_ondisc_metadata,direct);
 		path[1].flags	= CACHEFS_BLOCK_IS_INODE;
-		path[1].page	= inode->storage;
+		path[1].page	= inode->metadata_page;
 		pix = 0;
 		goto process;
 	}
@@ -1184,10 +1192,10 @@
 
 		path[0].offset	= iblock * sizeof(cachefs_blockix_t);
 		path[1].flags	= CACHEFS_BLOCK_INIT_INDIRECT;
-		path[1].offset	= offsetof(struct cachefs_ondisc_storage,single_indirect);
+		path[1].offset	= offsetof(struct cachefs_ondisc_metadata,single_indirect);
 		path[1].auxmark	= CACHEFS_ONDISC_UJNL_SINGLE_0;
 		path[2].flags	= CACHEFS_BLOCK_IS_INODE;
-		path[2].page	= inode->storage;
+		path[2].page	= inode->metadata_page;
 		pix = 1;
 		goto process;
 	}
@@ -1205,10 +1213,10 @@
 		path[1].offset	= iblock * sizeof(cachefs_blockix_t);
 		path[1].auxmark	= CACHEFS_ONDISC_UJNL_DOUBLE_1;
 		path[2].flags	= CACHEFS_BLOCK_INIT_INDIRECT;
-		path[2].offset	= offsetof(struct cachefs_ondisc_storage,double_indirect);
+		path[2].offset	= offsetof(struct cachefs_ondisc_metadata,double_indirect);
 		path[2].auxmark	= CACHEFS_ONDISC_UJNL_DOUBLE_0;
 		path[3].flags	= CACHEFS_BLOCK_IS_INODE;
-		path[3].page	= inode->storage;
+		path[3].page	= inode->metadata_page;
 		pix = 2;
 		goto process;
 	}
@@ -1222,10 +1230,13 @@
 	dbgpgalloc(path[pix+1].page);
 	page_cache_get(path[pix+1].page);
 
-	path[pix].offset += inode->storage_offset;
+	path[pix].offset += inode->metadata_offset;
+
+	down_read(&inode->metadata_sem);
+	path[pix+1].pageio = __cachefs_page_get_private(inode->metadata_page);
+	up_read(&inode->metadata_sem);
 
-	path[pix+1].pageio	= __cachefs_page_get_private(inode->storage);
-	path[pix+1].bix		= path[pix+1].pageio->mapped_block->bix;
+	path[pix+1].bix = path[pix+1].pageio->mapped_block->bix;
 
 	ret = 0;
 	for (; pix>=0; pix--) {