Subject: afs/fs/cachefs index.c,1.27,1.28 cachefs-layout.h,1.30,1.31 aops.c,1.41,1.42

From: [email-masked]
Date: Wed, 16 Jul 2003 11:44:24 +0100

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

Modified Files:
	index.c cachefs-layout.h aops.c 
Log Message:
note index inode metadata position in jentry auxblock/auxentry when extending
a file and initialise the index from within transaction data-modify phase

Index: index.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/index.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- index.c	10 Jul 2003 14:21:24 -0000	1.27
+++ index.c	16 Jul 2003 10:44:21 -0000	1.28
@@ -369,16 +369,10 @@
  */
 static int cachefs_index_preinit_page(void *data, struct page *page)
 {
-	struct cachefs_ondisc_index_entry *xent;
-	struct cachefs_ondisc_metadata *metadata;
-	struct cachefs_inode *iinode;
 	struct cachefs_page *pageio;
-	u_int32_t entry, next;
-	void *content;
-	int loop, ret;
+	int ret;
 
-	iinode = data;
-	_enter("{%lu},%p{%lu}", iinode->vfs_inode.i_ino, page, page->index);
+	_enter(",%p{%lu}", page, page->index);
 
 	ret = cachefs_page_get_private(page, &pageio, GFP_KERNEL);
 	if (ret < 0) {
@@ -386,29 +380,8 @@
 		return ret;
 	}
 
-	metadata = cachefs_metadata_preread(iinode);
-	next = metadata->freelink;
-	cachefs_metadata_postread(iinode);
-
-	entry = page->index * iinode->index_epp;
-
-	content = kmap(page);
-	clear_page(content);
-
-	for (loop = iinode->index_epp - 1; loop >= 0; loop--) {
-		xent = content + loop * iinode->index_esize;
-		xent->state		= CACHEFS_ONDISC_INDEX_FREE;
-		xent->freelink[0]	= next;
-		next = entry + loop;
-	}
-
-	kunmap(content);
-
-	_debug("new freelink: %u", next);
-
-	metadata = cachefs_metadata_prewrite(iinode);
-	metadata->freelink = next;
-	cachefs_metadata_postwrite(iinode);
+	clear_page(kmap(page));
+	kunmap(page);
 
 	SetPageUptodate(page);
 	unlock_page(page);
@@ -452,7 +425,7 @@
 		/* we need to get the new contents for this block ready in
 		 * advance */
 		page = read_cache_page(iinode->vfs_inode.i_mapping, pgnum,
-				       cachefs_index_preinit_page, iinode);
+				       cachefs_index_preinit_page, NULL);
 		dbgpgalloc(page);
 		if (IS_ERR(page)) {
 			ret = PTR_ERR(page);

Index: cachefs-layout.h
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/cachefs-layout.h,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- cachefs-layout.h	10 Jul 2003 14:21:24 -0000	1.30
+++ cachefs-layout.h	16 Jul 2003 10:44:21 -0000	1.31
@@ -359,7 +359,17 @@
 	 */
 	CACHEFS_ONDISC_UJNL_INDIRECT_FREEING,
 
-	/* index file being extended (as for data block allocation) */
+	/* index file being extended (as for data block allocation)
+	 * - ino	= index inode
+	 * - pgnum	= page in file holding index entry being allocated
+	 * - block	= new block being allocated
+	 * - auxblock	= metadata file block holding index metadata
+	 * - auxentry	= offset of entry in auxblock
+	 * - upblock	= block holding pointer to new block
+	 * - upentry	= offset of entry in upblock
+	 * - count	= size of index entry (inc header) in block
+	 * - next_index	= next free index file entry
+	 */
 	CACHEFS_ONDISC_UJNL_INDEX_EXTENDING,
 
 	/* index file being created

Index: aops.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/aops.c,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -r1.41 -r1.42
--- aops.c	15 Jul 2003 16:41:30 -0000	1.41
+++ aops.c	16 Jul 2003 10:44:22 -0000	1.42
@@ -954,8 +954,14 @@
 		if (!(step[1].flags & CACHEFS_BLOCK_IS_INODE))
 			cachefs_trans_affects_inode(step->transaction, inode);
 
-		jentry->count = inode->index_esize;
-		jentry->ixentry = step->page->index * inode->index_epp;
+		jentry->count		= inode->index_esize;
+		jentry->ixentry		= step->page->index * inode->index_epp;
+		jentry->auxblock	= inode->metadata->bix;
+		jentry->auxentry	= inode->metadata_offset;
+
+		metadata = cachefs_metadata_preread(inode);
+		jentry->index		= metadata->freelink;
+		cachefs_metadata_postread(inode);
 	}
 
 	/* freshly allocated data blocks must be recorded in the v-journal */
@@ -1056,8 +1062,7 @@
 
 	jentry->size = inode->vfs_inode.i_size;
 
-	_debug("selected block %u (next {%u}+%hu)",
-	       jentry->block, jentry->auxblock, jentry->auxentry);
+	_debug("selected block %u", jentry->block);
 
 	BUG_ON(jentry->block > super->layout->bix_end);
 
@@ -1092,12 +1097,39 @@
 		block->vjentry->bix = block->bix;
 	}
 
-	/* indirection blocks need to be cleared before use */
-	if (step->flags & CACHEFS_BLOCK_INIT_INDIRECT) {
+	/* index and indirection blocks need to be initialised before use */
+	if (step->flags & (CACHEFS_BLOCK_INIT_INDIRECT |
+			   CACHEFS_BLOCK_INIT_INDEX)
+	    ) {
 		cachefs_block_modify(super, block, &step->page);
 
-		memset(kmap(step->page), 0, PAGE_SIZE);
-		kunmap(step->page);
+		if (step->flags & CACHEFS_BLOCK_INIT_INDIRECT) {
+			memset(kmap(step->page), 0, PAGE_SIZE);
+			kunmap(step->page);
+		}
+		else {
+			struct cachefs_ondisc_index_entry *xent;
+			u_int32_t entry, next;
+			void *content;
+			int loop;
+
+			next = jentry->index;
+			entry = jentry->ixentry;
+
+			content = kmap(step->page);
+			clear_page(content);
+
+			for (loop = inode->index_epp - 1; loop >= 0; loop--) {
+				xent = content + loop * jentry->count;
+				xent->state		= CACHEFS_ONDISC_INDEX_FREE;
+				xent->freelink[0]	= next;
+				next = entry + loop;
+			}
+
+			kunmap(step->page);
+
+			_debug("new freelink: %u", jentry->ixentry);
+		}
 	}
 
 	/* clean up the alloc stack tracking */
@@ -1136,7 +1168,7 @@
 	metadata->mtime	= CURRENT_TIME.tv_sec;
 
 	if (step->flags & CACHEFS_BLOCK_INIT_INDEX) {
-		metadata->freelink = step->page->index * inode->index_epp;
+		metadata->freelink = jentry->ixentry;
 	}
 
 	if (step[1].flags & CACHEFS_BLOCK_IS_INODE) {