Subject: afs/fs/cachefs replay.c,1.5,1.6 index.c,1.30,1.31 cachetest-main.c,1.13,1.14 cachefs-layout.h,1.34,1.35aops.c,1.46,1.47

From: [email-masked]
Date: Fri, 12 Sep 2003 14:01:20 +0100

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

Modified Files:
	replay.c index.c cachetest-main.c cachefs-layout.h aops.c 
Log Message:
fixed up a number of journalling/replaying bugs

Index: replay.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/replay.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- replay.c	12 Sep 2003 09:52:38 -0000	1.5
+++ replay.c	12 Sep 2003 13:01:17 -0000	1.6
@@ -404,6 +404,7 @@
 		super->rcm_indirect	= jentry->rcm_indirect;
 		super->rcm_ino		= jentry->rcm_ino;
 
+		BUG_ON(super->layout->ujnl_rsize == 0);
 		offset += super->layout->ujnl_rsize;
 		data += super->layout->ujnl_rsize;
 	}
@@ -670,11 +671,12 @@
  * note that a transaction is going to replay an effect on a particular block
  */
 static void cachefs_trans_replays_effect(struct cachefs_transaction *trans,
-					 struct cachefs_block *block)
+					 struct cachefs_block *block,
+					 const char *what)
 {
 	int ix = trans->eff_active;
 
-	kenter("%p{efa=%d},{%u}", trans, ix, block->bix);
+	kenter("{efa=%d},{b=%x},%s", ix, block->bix, what);
 
 	get_page(block->page);
 
@@ -710,7 +712,7 @@
 		clear_page(node);
 		node->next  = jentry->index;
 		node->count = jentry->ixentry;
-		cachefs_trans_replays_effect(trans, block);
+		cachefs_trans_replays_effect(trans, block, "rcynode");
 		kunmap(page);
 	}
 
@@ -753,7 +755,8 @@
 			if (node->next || node->count) {
 				node->next = 0;
 				node->count = 0;
-				cachefs_trans_replays_effect(trans, block);
+				cachefs_trans_replays_effect(trans, block,
+							     "rcynode");
 			}
 			kunmap(page);
 		}
@@ -809,7 +812,7 @@
 			memcpy(&node->leaves[jentry->auxblock],
 			       &jentry->rcyptrs[0],
 			       jentry->count * sizeof(cachefs_blockix_t));
-			cachefs_trans_replays_effect(trans, block);
+			cachefs_trans_replays_effect(trans, block, "rcyptrs");
 		}
 		kunmap(page);
 	}
@@ -866,7 +869,7 @@
 	layout = kmap(spage);
 	if (layout->bix_unready < jentry->pgnum) {
 		layout->bix_unready = jentry->pgnum;
-		cachefs_trans_replays_effect(trans, superblock);
+		cachefs_trans_replays_effect(trans, superblock, "unready");
 	}
 	kunmap(spage);
 
@@ -884,7 +887,7 @@
 		}
 
 		if (changed)
-			cachefs_trans_replays_effect(trans, block);
+			cachefs_trans_replays_effect(trans, block, "rcyptrs");
 		kunmap(page);
 	}
 
@@ -950,7 +953,8 @@
 			super->layout->metadata_size * CACHEFS_INO_METADATA;
 		if (metadata->freelink != jindex->next_ino) {
 			metadata->freelink = jindex->next_ino;
-			cachefs_trans_replays_effect(trans, metameta);
+			cachefs_trans_replays_effect(trans, metameta,
+						     "meta.freelink");
 		}
 		kunmap(metapage);
 	}
@@ -962,7 +966,8 @@
 		    metadata->size	!= jentry->size) {
 			metadata->freelink	= jindex->next_index;
 			metadata->size		= jentry->size;
-			cachefs_trans_replays_effect(trans, indexmeta);
+			cachefs_trans_replays_effect(trans, indexmeta,
+						     "ix.freelink");
 		}
 		kunmap(ixmpage);
 	}
@@ -992,7 +997,8 @@
 			       &jindex->def,
 			       sizeof(metadata->index));
 
-			cachefs_trans_replays_effect(trans, inometa);
+			cachefs_trans_replays_effect(trans, inometa,
+						     "ino.meta");
 		}
 		kunmap(inompage);
 	}
@@ -1003,15 +1009,16 @@
 		if (xent->state	!= CACHEFS_ONDISC_INDEX_ACTIVE	||
 		    xent->type	!= type				||
 		    xent->ino	!= jentry->ino			||
-		    memcmp(xent->data, jindex->data, jindex->def.dsize) != 0
+		    memcmp(xent->data, jindex->data, jentry->count) != 0
 		    ) {
 			xent->state	= CACHEFS_ONDISC_INDEX_ACTIVE;
 			xent->type	= type;
 			xent->ino	= jentry->ino;
 
-			memcpy(xent->data, jindex->data, jindex->def.dsize);
+			memcpy(xent->data, jindex->data, jentry->count);
 
-			cachefs_trans_replays_effect(trans, indexdata);
+			cachefs_trans_replays_effect(trans, indexdata,
+						     "ix.entry");
 		}
 		kunmap(ixdatapage);
 	}
@@ -1093,7 +1100,8 @@
 			super->layout->metadata_size * CACHEFS_INO_METADATA;
 		if (metadata->freelink != jindex->next_ino) {
 			metadata->freelink = jindex->next_ino;
-			cachefs_trans_replays_effect(trans, metameta);
+			cachefs_trans_replays_effect(trans, metameta,
+						     "meta.freelink");
 		}
 		kunmap(metapage);
 	}
@@ -1105,7 +1113,8 @@
 		    metadata->size	!= jentry->size) {
 			metadata->freelink	= jindex->next_index;
 			metadata->size		= jentry->size;
-			cachefs_trans_replays_effect(trans, indexmeta);
+			cachefs_trans_replays_effect(trans, indexmeta,
+						     "ix.freelink");
 		}
 		kunmap(ixmpage);
 	}
@@ -1129,7 +1138,8 @@
 			metadata->pindex	= 0;
 			metadata->pindex_entry	= 0;
 
-			cachefs_trans_replays_effect(trans, inometa);
+			cachefs_trans_replays_effect(trans, inometa,
+						     "ino.meta");
 		}
 		kunmap(inompage);
 	}
@@ -1147,7 +1157,8 @@
 			xent->ino	= 0;
 			xent->freelink[0] = jindex->next_index;
 
-			cachefs_trans_replays_effect(trans, indexdata);
+			cachefs_trans_replays_effect(trans, indexdata,
+						     "ix.entry");
 		}
 		kunmap(ixdatapage);
 	}
@@ -1203,7 +1214,8 @@
 		if (metadata->header.state != CACHEFS_ONDISC_INDEX_RECYCLE) {
 			metadata->header.state = CACHEFS_ONDISC_INDEX_FREE;
 
-			cachefs_trans_replays_effect(trans, inometa);
+			cachefs_trans_replays_effect(trans, inometa,
+						     "ino.meta");
 		}
 		kunmap(inompage);
 	}
@@ -1214,7 +1226,8 @@
 		if (xent->state	!= CACHEFS_ONDISC_INDEX_FREE) {
 			xent->state	= CACHEFS_ONDISC_INDEX_FREE;
 
-			cachefs_trans_replays_effect(trans, indexdata);
+			cachefs_trans_replays_effect(trans, indexdata,
+						     "ix.entry");
 		}
 		kunmap(ixdatapage);
 	}
@@ -1284,7 +1297,8 @@
 		    metadata->size	!= jentry->size) {
 			metadata->freelink	= jentry->ixentry;
 			metadata->size		= jentry->size;
-			cachefs_trans_replays_effect(trans, indexmeta);
+			cachefs_trans_replays_effect(trans, indexmeta,
+						     "ix.freelink");
 		}
 		kunmap(metapage);
 	}
@@ -1295,7 +1309,8 @@
 		if (*ptr != jentry->block) {
 			*ptr = jentry->block;
 
-			cachefs_trans_replays_effect(trans, indexptr);
+			cachefs_trans_replays_effect(trans, indexptr,
+						     "ptr");
 		}
 		kunmap(ptrpage);
 	}
@@ -1319,7 +1334,7 @@
 			next = entry + loop;
 		}
 
-		cachefs_trans_replays_effect(trans, indexdata);
+		cachefs_trans_replays_effect(trans, indexdata, "ix.block");
 		kunmap(datapage);
 	}
 
@@ -1365,7 +1380,8 @@
 		if (memcmp(xent->data, jindex->data, jindex->def.dsize) != 0) {
 			memcpy(xent->data, jindex->data, jindex->def.dsize);
 
-			cachefs_trans_replays_effect(trans, indexdata);
+			cachefs_trans_replays_effect(trans, indexdata,
+						     "ix.entry");
 		}
 		kunmap(ixdatapage);
 	}
@@ -1416,9 +1432,10 @@
 	/* make sure the datafile's size is correct */
 	if (BLOCK_VALID(metablock, metapage, jentry)) {
 		metadata = kmap(metapage) + jentry->auxentry;
-		if (metadata->size	!= jentry->size) {
-			metadata->size		= jentry->size;
-			cachefs_trans_replays_effect(trans, metablock);
+		if (metadata->size != jentry->size) {
+			metadata->size = jentry->size;
+			cachefs_trans_replays_effect(trans, metablock,
+						     "ino.size");
 		}
 		kunmap(metapage);
 	}
@@ -1429,7 +1446,8 @@
 		if (*ptr != jentry->block) {
 			*ptr = jentry->block;
 
-			cachefs_trans_replays_effect(trans, ptrblock);
+			cachefs_trans_replays_effect(trans, ptrblock,
+						     "ptr");
 		}
 		kunmap(ptrpage);
 	}
@@ -1439,12 +1457,12 @@
 		(jentry->auxmark % CACHEFS_ONDISC_VJNL_ENTPERPAGE) *
 		sizeof(struct cachefs_ondisc_validity_journal);
 
-	if (vjentry->ino	!= jentry->ino &&
-	    vjentry->pgnum	!= jentry->pgnum) {
+	if (vjentry->ino   != jentry->ino ||
+	    vjentry->pgnum != jentry->pgnum) {
 		vjentry->ino	= jentry->ino;
 		vjentry->pgnum	= jentry->pgnum;
 
-		cachefs_trans_replays_effect(trans, vjblock);
+		cachefs_trans_replays_effect(trans, vjblock, "vj");
 	}
 	kunmap(vjpage);
 
@@ -1496,7 +1514,7 @@
 		vjentry->ino	= 0;
 		vjentry->pgnum	= 0;
 
-		cachefs_trans_replays_effect(trans, vjblock);
+		cachefs_trans_replays_effect(trans, vjblock, "vj");
 	}
 	kunmap(vjpage);
 
@@ -1540,15 +1558,15 @@
 	if (ret < 0)
 		goto error2;
 
-	if (trans->jentry->auxentry == (uint16_t) ~0) {
+	if (jentry->auxentry == (uint16_t) ~0) {
 		/* block made new node on recycling stack */
-		ret = cachefs_block_read(super, NULL, trans->jentry->block, 0,
+		ret = cachefs_block_read(super, NULL, jentry->block, 0,
 					 &deadblock, &deadpage);
 		if (ret < 0)
 			goto error3;
 	} else {
 		/* block depends from current node in recycling stack */
-		ret = cachefs_block_read(super, NULL, trans->jentry->auxblock,
+		ret = cachefs_block_read(super, NULL, jentry->auxblock,
 					 0, &rcyblock, &rcypage);
 		if (ret < 0)
 			goto error3;
@@ -1560,7 +1578,7 @@
 		if (*pbix != 0) {
 			*pbix = 0;
 
-			cachefs_trans_replays_effect(trans, ptrblock);
+			cachefs_trans_replays_effect(trans, ptrblock, "ptr");
 		}
 		kunmap(ptrpage);
 	}
@@ -1570,12 +1588,12 @@
 		(jentry->auxmark % CACHEFS_ONDISC_VJNL_ENTPERPAGE) *
 		sizeof(struct cachefs_ondisc_validity_journal);
 
-	if (vjentry->ino	!= 0 &&
-	    vjentry->pgnum	!= 0) {
+	if (vjentry->ino   != 0 ||
+	    vjentry->pgnum != 0) {
 		vjentry->ino	= 0;
 		vjentry->pgnum	= 0;
 
-		cachefs_trans_replays_effect(trans, vjblock);
+		cachefs_trans_replays_effect(trans, vjblock, "vj");
 	}
 	kunmap(vjpage);
 
@@ -1584,21 +1602,22 @@
 	if (BLOCK_VALID(deadblock, deadpage, jentry)) {
 		node = kmap(deadpage);
 		clear_page(node);
-		node->next  = trans->jentry->index;
-		node->count = trans->jentry->ixentry;
+		node->next  = jentry->index;
+		node->count = jentry->ixentry;
 		kunmap(deadpage);
 
-		cachefs_trans_replays_effect(trans, deadblock);
+		cachefs_trans_replays_effect(trans, deadblock, "rcynode");
 	}
 
 	/* alternatively, make sure the dead block now depends from a node in
 	 * the recycling stack */
 	if (BLOCK_VALID(rcyblock, rcypage, jentry)) {
 		node = kmap(rcypage);
-		pbix = &node->leaves[trans->jentry->auxentry];
-		if (*pbix != trans->jentry->block) {
-			*pbix = trans->jentry->block;
-			cachefs_trans_replays_effect(trans, rcyblock);
+		pbix = &node->leaves[jentry->auxentry];
+		if (*pbix != jentry->block) {
+			*pbix = jentry->block;
+			cachefs_trans_replays_effect(trans, rcyblock,
+						     "rcyptrs");
 		}
 		kunmap(deadpage);
 	}
@@ -1650,7 +1669,7 @@
 		if (*ptr != jentry->block) {
 			*ptr = jentry->block;
 
-			cachefs_trans_replays_effect(trans, ptrblock);
+			cachefs_trans_replays_effect(trans, ptrblock, "ptr");
 		}
 		kunmap(ptrpage);
 	}
@@ -1659,7 +1678,7 @@
 	if (BLOCK_VALID(indblock, indpage, jentry)) {
 		content = kmap(indpage);
 		clear_page(content);
-		cachefs_trans_replays_effect(trans, indblock);
+		cachefs_trans_replays_effect(trans, indblock, "indir");
 		kunmap(indpage);
 	}

Index: index.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/index.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- index.c	19 Aug 2003 13:37:07 -0000	1.30
+++ index.c	12 Sep 2003 13:01:17 -0000	1.31
@@ -169,7 +169,7 @@
 	trans->jentry->pgnum	= ixpage->index;
 	trans->jentry->block	= __cachefs_get_page_block(ixpage)->bix;
 	trans->jentry->entry	= ixoffset;
-	trans->jentry->count	= rec->iinode->index_esize;
+	trans->jentry->count	= rec->iinode->index_dsize;
 
 	cachefs_trans_affects_page(trans, cachefs_page_grab_private(ixpage),
 				   ixoffset, sizeof(*xent));
@@ -569,7 +569,7 @@
 	trans->jentry->pgnum	= ixpage->index;
 	trans->jentry->block	= __cachefs_get_page_block(ixpage)->bix;
 	trans->jentry->entry	= offset;
-	trans->jentry->count	= index->index_esize;
+	trans->jentry->count	= index->index_dsize;
 	trans->jentry->auxblock	= __cachefs_get_page_block(inopage)->bix;
 	trans->jentry->auxentry	= ino_offset;
 	trans->jentry->upblock	= index->metadata->bix;

Index: cachetest-main.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/cachetest-main.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- cachetest-main.c	13 Aug 2003 10:05:28 -0000	1.13
+++ cachetest-main.c	12 Sep 2003 13:01:17 -0000	1.14
@@ -202,6 +202,7 @@
 					 (void *) 9,
 					 GFP_KERNEL);
 
+#if 0
 	printk("\n### Write page\n");
 	ret = cachefs_write_page(afs_root_dir.cache,
 				 afs_data_page,
@@ -217,6 +218,7 @@
 				 afs_page_cache_write_complete,
 				 (void *) 23,
 				 GFP_KERNEL);
+#endif
 
 	printk("\nresult = %d\n", ret);

Index: cachefs-layout.h
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/cachefs-layout.h,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- cachefs-layout.h	13 Aug 2003 10:05:28 -0000	1.34
+++ cachefs-layout.h	12 Sep 2003 13:01:17 -0000	1.35
@@ -304,13 +304,13 @@
 	 */
 	CACHEFS_ONDISC_UJNL_INODE_RECLAIMING,
 
-	/* data block allocation
+	/* data file block allocation
 	 * - ino	= inode for which block allocated
 	 * - pgnum	= page of inode being instantiated
 	 * - size	= current file size
 	 * - block	= block allocated
-	 * - auxblock	= (auxentry==1) block holding 2OS of alloc stack (0 if stack now empty)
-	 * - auxentry	= 0: alloc TOS leaf, 1: alloc TOS node
+	 * - auxblock	= block holding inode's metadata
+	 * - auxentry	= offset in auxblock of metadata record
 	 * - upblock	= block which will point to this one
 	 * - upentry	= entry in block pointing to this one
 	 * - auxmark	= v-journal entry number
@@ -345,8 +345,8 @@
 	 * - pgnum	= which page of inode being allocated
 	 * - size	= current file size
 	 * - block	= block being allocated
-	 * - auxblock	= (auxentry==1) block holding 2OS of alloc stack (0 if stack now empty)
-	 * - auxentry	= 0: alloc TOS leaf, 1: alloc TOS node
+	 * - auxblock	= block holding inode's metadata
+	 * - auxentry	= offset in auxblock of metadata record
 	 * - upblock	= block which will point to this one
 	 * - upentry	= entry in block pointing to this one
 	 */
@@ -355,6 +355,7 @@
 	/* index file being extended (as for data block allocation)
 	 * - ino	= index inode
 	 * - pgnum	= page in file holding index entry being allocated
+	 * - size	= current file size
 	 * - block	= new block being allocated
 	 * - auxblock	= metadata file block holding index metadata
 	 * - auxentry	= offset of entry in auxblock

Index: aops.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/aops.c,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -r1.46 -r1.47
--- aops.c	19 Aug 2003 13:37:07 -0000	1.46
+++ aops.c	12 Sep 2003 13:01:17 -0000	1.47
@@ -956,8 +956,6 @@
 
 		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;
@@ -1062,7 +1060,9 @@
 		cachefs_trans_affects_block(step->transaction, block, 0,
 					    PAGE_SIZE);
 
-	jentry->size = inode->vfs_inode.i_size;
+	jentry->auxblock	= inode->metadata->bix;
+	jentry->auxentry	= inode->metadata_offset;
+	jentry->size		= inode->vfs_inode.i_size;
 
 	_debug("selected block %u", jentry->block);