From dwh at infradead.org  Tue Jul  1 19:44:53 2003
From: dwh at infradead.org (dwh@infradead.org)
Date: Tue Jul  1 18:44:39 2003
Subject: afs/fs/cachefs io.c,1.13,1.14 aops.c,1.37,1.38
Message-ID: <E19XPBV-0004nZ-00@phoenix.infradead.org>

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

Modified Files:
	io.c aops.c 
Log Message:
don't call try_to_release_page() - which isn't exported from core kernel


Index: io.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/io.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- io.c	23 May 2003 12:59:21 -0000	1.13
+++ io.c	1 Jul 2003 17:44:50 -0000	1.14
@@ -335,8 +335,14 @@
 	 * The get_block cached value has been unconditionally invalidated,
 	 * so real IO is not possible anymore.
 	 */
-	if (offset == 0)
-		ret = try_to_release_page(page,0);
+	if (offset == 0) {
+		BUG_ON(!PageLocked(page));
+
+		ret = 0;
+		if (!PageWriteback(page))
+			ret = page->mapping->a_ops->releasepage(page, 0);
+	}
+
 out:
 	_leave(" = %d",ret);
 	return ret;

Index: aops.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/aops.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- aops.c	11 Jun 2003 11:59:52 -0000	1.37
+++ aops.c	1 Jul 2003 17:44:50 -0000	1.38
@@ -837,7 +837,12 @@
 	 */
 	if (offset == 0) {
 		dbgpgfree(page);
-		ret = try_to_release_page(page,0);
+
+		BUG_ON(!PageLocked(page));
+
+		ret = 0;
+		if (!PageWriteback(page))
+			ret = page->mapping->a_ops->releasepage(page, 0);
 	}
 out:
 	_leave(" = %d",ret);


From dwh at infradead.org  Tue Jul  1 19:45:25 2003
From: dwh at infradead.org (dwh@infradead.org)
Date: Tue Jul  1 18:45:09 2003
Subject: afs/fs/cachefs super.c,1.34,1.35
Message-ID: <E19XPC1-0004oN-00@phoenix.infradead.org>

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

Modified Files:
	super.c 
Log Message:
the statfs method's arguments changed


Index: super.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/super.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- super.c	11 Jun 2003 12:11:33 -0000	1.34
+++ super.c	1 Jul 2003 17:45:22 -0000	1.35
@@ -26,14 +26,14 @@
 static void cachefs_i_init_once(void *foo, kmem_cache_t *cachep, unsigned long flags);
 
 static struct super_block *cachefs_get_sb(struct file_system_type *fs_type,
-				      int flags, char *dev_name, void *data);
+					  int flags, const char *dev_name, void *data);
 
 static struct inode *cachefs_alloc_inode(struct super_block *sb);
 static void cachefs_destroy_inode(struct inode *inode);
 
 static int cachefs_fill_super(struct super_block *sb, void *_data, int silent);
 static int cachefs_initialise_blockdev(struct cachefs_super *super);
-static int cachefs_statfs(struct super_block *sb, struct statfs *buf);
+static int cachefs_statfs(struct super_block *sb, struct kstatfs *buf);
 static void cachefs_write_super(struct super_block *sb);
 static void cachefs_put_super(struct super_block *sb);
 
@@ -115,7 +115,7 @@
  */
 static struct super_block *cachefs_get_sb(struct file_system_type *fs_type,
 					  int flags,
-					  char *dev_name,
+					  const char *dev_name,
 					  void *options)
 {
 	struct super_block *sb;
@@ -636,7 +636,7 @@
 /*
  * return some stats on the filesystem
  */
-static int cachefs_statfs(struct super_block *sb, struct statfs *buf)
+static int cachefs_statfs(struct super_block *sb, struct kstatfs *buf)
 {
 	struct cachefs_super *super = sb->s_fs_info;
 	unsigned long long tmp;


From dwh at infradead.org  Tue Jul  1 19:46:11 2003
From: dwh at infradead.org (dwh@infradead.org)
Date: Tue Jul  1 18:45:56 2003
Subject: afs/net/rxrpc transport.c,1.3,1.4
Message-ID: <E19XPCl-0004pF-00@phoenix.infradead.org>

Update of /home/cvs/afs/net/rxrpc
In directory phoenix.infradead.org:/tmp/cvs-serv18541/net/rxrpc

Modified Files:
	transport.c 
Log Message:
certain struct sock members have acquired an "sk_" prefix


Index: transport.c
===================================================================
RCS file: /home/cvs/afs/net/rxrpc/transport.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- transport.c	16 Oct 2002 11:59:44 -0000	1.3
+++ transport.c	1 Jul 2003 17:46:09 -0000	1.4
@@ -112,9 +112,9 @@
 
 	/* set the socket up */
 	sock = trans->socket->sk;
-	sock->user_data = trans;
-	sock->data_ready = rxrpc_data_ready;
-	sock->error_report = rxrpc_error_report;
+	sock->sk_user_data = trans;
+	sock->sk_data_ready = rxrpc_data_ready;
+	sock->sk_error_report = rxrpc_error_report;
 
 	down_write(&rxrpc_proc_transports_sem);
 	list_add_tail(&trans->proc_link,&rxrpc_proc_transports);
@@ -184,7 +184,7 @@
 
 	/* close the socket */
 	if (trans->socket) {
-		trans->socket->sk->user_data = NULL;
+		trans->socket->sk->sk_user_data = NULL;
 		sock_release(trans->socket);
 		trans->socket = NULL;
 	}
@@ -255,16 +255,16 @@
 {
 	struct rxrpc_transport *trans;
 
-	_enter("%p{t=%p},%d",sk,sk->user_data,count);
+	_enter("%p{t=%p},%d",sk,sk->sk_user_data,count);
 
 	/* queue the transport for attention by krxiod */
-	trans = (struct rxrpc_transport *) sk->user_data;
+	trans = (struct rxrpc_transport *) sk->sk_user_data;
 	if (trans)
 		rxrpc_krxiod_queue_transport(trans);
 
 	/* wake up anyone waiting on the socket */
-	if (sk->sleep && waitqueue_active(sk->sleep))
-		wake_up_interruptible(sk->sleep);
+	if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
+		wake_up_interruptible(sk->sk_sleep);
 
 	_leave("");
 
@@ -279,18 +279,18 @@
 {
 	struct rxrpc_transport *trans;
 
-	_enter("%p{t=%p}",sk,sk->user_data);
+	_enter("%p{t=%p}",sk,sk->sk_user_data);
 
 	/* queue the transport for attention by krxiod */
-	trans = (struct rxrpc_transport *) sk->user_data;
+	trans = (struct rxrpc_transport *) sk->sk_user_data;
 	if (trans) {
 		trans->error_rcvd = 1;
 		rxrpc_krxiod_queue_transport(trans);
 	}
 
 	/* wake up anyone waiting on the socket */
-	if (sk->sleep && waitqueue_active(sk->sleep))
-		wake_up_interruptible(sk->sleep);
+	if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
+		wake_up_interruptible(sk->sk_sleep);
 
 	_leave("");
 


From dwh at infradead.org  Fri Jul  4 11:04:46 2003
From: dwh at infradead.org (dwh@infradead.org)
Date: Fri Jul  4 10:04:33 2003
Subject: afs/include/linux cachefs.h,1.14,1.15
Message-ID: <E19YMUn-0002Qf-00@phoenix.infradead.org>

Update of /home/cvs/afs/include/linux
In directory phoenix.infradead.org:/tmp/cvs-serv9327/include/linux

Modified Files:
	cachefs.h 
Log Message:
manoeuvered the source towards hch-compliance (CodingStyle)
fixed a couple of bugs


Index: cachefs.h
===================================================================
RCS file: /home/cvs/afs/include/linux/cachefs.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- cachefs.h	10 Jun 2003 17:49:48 -0000	1.14
+++ cachefs.h	4 Jul 2003 09:04:43 -0000	1.15
@@ -150,28 +150,6 @@
 			       unsigned long gfp);
 
 /*
- * see if any of the list of pages are cached
- * - for each cached page:
- *   - the page cookie will have been changed to refer to the backing cache
- *     block
- *   - a BIO will have been dispatched to load the page with end_io as the
- *     completion function
- *     - end_io can be NULL, in which case a default function will just unlock
- *       the page
- *     - BIOs may be merged to serve multiple pages that are adjacent on disc
- *   - they will be removed from the page list
- * - all uncached pages will be left on the page list and will be otherwise
- *   untouched
- * - no cache space will be allocated
- * - all pages must be locked before calling
- */
-extern void cachefs_read_pages(struct cachefs_cookie *cookie,
-			       struct address_space *mapping,
-			       struct list_head *pages,
-			       unsigned nr_pages,
-			       bio_end_io_t end_io);
-
-/*
  * request a page be stored in the cache
  * - this request may be ignored if no cache block is currently attached, in which case it
  *   - returns -ENOBUFS
@@ -189,21 +167,6 @@
 			      unsigned long gfp);
 
 /*
- * request a list of pages be stored/updated in the cache
- * - this request may be ignored for any page that has no cache block currently attached, in which
- *   case, that page remains on the list
- * - for any page that has a cache block allocated:
- *   - the page cookie will be updated to reflect the block selected
- *   - the page will be removed from the list
- *   - a BIO will have been dispatched to write the page with end_io as the completion func
- *     - end_io can be NULL, in which case a default function will just clear the writeback bit
- *     - BIOs may be merged to serve multiple pages that are adjacent on disc
- */
-extern void cachefs_write_pages(struct cachefs_cookie *cookie,
-				struct list_head *pages,
-				bio_end_io_t end_io);
-
-/*
  * indicate that caching is no longer required on a page
  * - cannot cancel any outstanding BIOs between this page and the cache
  */
@@ -213,6 +176,7 @@
 /*
  * keep track of pages changed locally but not yet committed
  */
+#if 0 /* TODO */
 extern void cachefs_writeback_prepare(struct cachefs_cookie *cookie,
 				      struct page *page,
 				      unsigned short from,
@@ -227,6 +191,7 @@
 				      struct page *page,
 				      unsigned short from,
 				      unsigned short to);
+#endif
 
 /*
  * convenience routines for mapping page->private directly to a struct cachefs_page


From dwh at infradead.org  Fri Jul  4 11:04:46 2003
From: dwh at infradead.org (dwh@infradead.org)
Date: Fri Jul  4 10:27:47 2003
Subject: afs/fs/cachefs vjournal.c,1.3,1.4 super.c,1.35,1.36
 status.c,1.6,1.7 rootdir.c,1.11,1.12 recycling.c,1.22,1.23
 main.c,1.15,1.16 kcachefsd.c,1.12,1.13 kcachefs_jnld.c,1.5,1.6
 journal.c,1.36,1.37 io.c,1.14,1.15 interface.c,1.13,1.14
 inode.c,1.20,1.21 index.c,1.23,1.24 dump-journal.c,1.10,1.11
 cachetest-main.c,1.11,1.12 cachefs-layout.h,1.25,1.26
 cachefs-int.h,1.36,1.37 block.c,1.7,1.8 aops.c,1.38,1.39
Message-ID: <E19YMUo-0002Qk-00@phoenix.infradead.org>

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

Modified Files:
	vjournal.c super.c status.c rootdir.c recycling.c main.c 
	kcachefsd.c kcachefs_jnld.c journal.c io.c interface.c inode.c 
	index.c dump-journal.c cachetest-main.c cachefs-layout.h 
	cachefs-int.h block.c aops.c 
Log Message:
manoeuvered the source towards hch-compliance (CodingStyle)
fixed a couple of bugs


Index: vjournal.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/vjournal.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- vjournal.c	5 Jun 2003 08:27:39 -0000	1.3
+++ vjournal.c	4 Jul 2003 09:04:43 -0000	1.4
@@ -22,24 +22,24 @@
  */
 int cachefs_vj_alloc(struct cachefs_transaction *trans, struct cachefs_inode *inode)
 {
-	DECLARE_WAITQUEUE(myself,current);
-
 	struct cachefs_vj_entry *vjentry;
 	struct cachefs_super *super;
 	cachefs_blockix_t bix;
 	int slot, ret;
 
+	DECLARE_WAITQUEUE(myself,current);
+
 	_enter("");
 
 	super = trans->super;
 
-	vjentry = kmalloc(sizeof(*vjentry),GFP_KERNEL);
+	vjentry = kmalloc(sizeof(*vjentry), GFP_KERNEL);
 	if (!vjentry) {
 		_leave(" = -ENOMEM");
 		return -ENOMEM;
 	}
 
-	memset(vjentry,0,sizeof(vjentry));
+	memset(vjentry, 0, sizeof(vjentry));
 	INIT_LIST_HEAD(&vjentry->link);
 
 	vjentry->ino = inode->vfs_inode.i_ino;
@@ -47,11 +47,11 @@
 	/* now allocate a slot when one becomes available */
 	spin_lock(&super->vjnl_lock);
 
-	if (super->vjnl_count==0) {
+	if (super->vjnl_count == 0) {
 		set_current_state(TASK_INTERRUPTIBLE);
-		add_wait_queue(&super->vjnl_alloc_wq,&myself);
+		add_wait_queue(&super->vjnl_alloc_wq, &myself);
 
-		while (super->vjnl_count!=0 && !signal_pending(current)) {
+		while (super->vjnl_count == 0 && !signal_pending(current)) {
 			spin_unlock(&super->vjnl_lock);
 			schedule();
 			spin_lock(&super->vjnl_lock);
@@ -59,24 +59,27 @@
 		}
 
 		set_current_state(TASK_RUNNING);
-		remove_wait_queue(&super->vjnl_alloc_wq,&myself);
+		remove_wait_queue(&super->vjnl_alloc_wq, &myself);
 
 		ret = -EINTR;
 		if (signal_pending(current))
 			goto error_free;
 	}
 
-	slot = find_first_zero_bit(super->vjnl_map,CACHEFS_ONDISC_VJNL_ENTS);
-	if (slot<0 || slot>=CACHEFS_ONDISC_VJNL_ENTS)
+	slot = find_first_zero_bit(super->vjnl_map, CACHEFS_ONDISC_VJNL_ENTS);
+	if (slot < 0 || slot >= CACHEFS_ONDISC_VJNL_ENTS) {
+		printk("CacheFS: vjnl_count=%u slot=%d\n",
+		       super->vjnl_count, slot);
 		BUG();
+	}
 
-	set_bit(slot,super->vjnl_map);
+	set_bit(slot, super->vjnl_map);
 	super->vjnl_count--;
 
 	spin_unlock(&super->vjnl_lock);
 
 	/* got a slot - now find the block and page holding it */
-	_debug("VJ slot %d",slot);
+	_debug("VJ slot %d", slot);
 
 	vjentry->vslot	= slot;
 	vjentry->ventry	= slot % CACHEFS_ONDISC_VJNL_ENTPERPAGE;
@@ -84,13 +87,14 @@
 	bix = slot / CACHEFS_ONDISC_VJNL_ENTPERPAGE;
 	bix += super->layout->bix_vjournal;
 
-	ret = cachefs_block_read(super,NULL,bix,0,&vjentry->vblock,&vjentry->vpage);
-	if (ret<0)
+	ret = cachefs_block_read(super, NULL, bix, 0,
+				 &vjentry->vblock, &vjentry->vpage);
+	if (ret < 0)
 		goto error_clearbit;
 
 	trans->vjentry = vjentry;
 
-	cachefs_trans_affects_block(trans,vjentry->vblock,vjentry->ventry,
+	cachefs_trans_affects_block(trans, vjentry->vblock, vjentry->ventry,
 				    sizeof(struct cachefs_ondisc_validity_journal));
 
 	_leave(" = 0");
@@ -98,13 +102,14 @@
 
  error_clearbit:
 	spin_lock(&super->vjnl_lock);
-	clear_bit(slot,super->vjnl_map);
+	clear_bit(slot, super->vjnl_map);
 	super->vjnl_count++;
+	wake_up(&super->vjnl_alloc_wq);
 
  error_free:
 	spin_unlock(&super->vjnl_lock);
 	kfree(vjentry);
-	_leave(" = %d",ret);
+	_leave(" = %d", ret);
 	return ret;
 
 } /* end cachefs_vj_alloc() */
@@ -119,7 +124,7 @@
 	_enter("");
 
 	spin_lock(&super->vjnl_lock);
-	clear_bit(vjentry->vslot,super->vjnl_map);
+	clear_bit(vjentry->vslot, super->vjnl_map);
 	super->vjnl_count++;
 	spin_unlock(&super->vjnl_lock);
 
@@ -142,13 +147,14 @@
 	struct cachefs_super *super;
 
 	_enter("{vs=%u pg={%u}+%u up={%u}+%u",
-	       vjentry->vslot,vjentry->ino,vjentry->pgnum,vjentry->upblock,vjentry->upentry);
+	       vjentry->vslot, vjentry->ino, vjentry->pgnum,
+	       vjentry->upblock, vjentry->upentry);
 
 	block->vjentry = NULL;
 	super = block->super;
 
 	spin_lock(&super->vjnl_lock);
-	list_move_tail(&vjentry->link,&super->vjnl_writtenq);
+	list_move_tail(&vjentry->link, &super->vjnl_writtenq);
 	spin_unlock(&super->vjnl_lock);
 
 	wake_up(&super->dmn_sleepq);
@@ -165,12 +171,13 @@
 	struct cachefs_super *super;
 
 	_enter("{vs=%u pg={%u}+%u up={%u}+%u",
-	       vjentry->vslot,vjentry->ino,vjentry->pgnum,vjentry->upblock,vjentry->upentry);
+	       vjentry->vslot, vjentry->ino, vjentry->pgnum,
+	       vjentry->upblock, vjentry->upentry);
 
 	super = vjentry->vblock->super;
 
 	spin_lock(&super->vjnl_lock);
-	list_move_tail(&vjentry->link,&super->vjnl_unallocq);
+	list_move_tail(&vjentry->link, &super->vjnl_unallocq);
 	spin_unlock(&super->vjnl_lock);
 
 	wake_up(&super->dmn_sleepq);
@@ -195,10 +202,12 @@
 
 	/* we can access the next pointer without a lock because we know we're
 	 * the only ones going to change it now */
-	vjentry = list_entry(super->vjnl_writtenq.next,struct cachefs_vj_entry,link);
+	vjentry = list_entry(super->vjnl_writtenq.next,
+			     struct cachefs_vj_entry,
+			     link);
 
 	ret = -ENOMEM;
-	trans = cachefs_trans_alloc(super,GFP_KERNEL);
+	trans = cachefs_trans_alloc(super, GFP_KERNEL);
 	if (!trans)
 		goto error;
 
@@ -207,15 +216,16 @@
 	trans->jentry->auxmark	= vjentry->vslot;
 	trans->jentry->block	= vjentry->bix;
 
-	cachefs_trans_affects_block(trans,vjentry->vblock,vjentry->ventry,
-				    sizeof(struct cachefs_ondisc_validity_journal));
+	cachefs_trans_affects_block(
+		trans, vjentry->vblock, vjentry->ventry,
+		sizeof(struct cachefs_ondisc_validity_journal));
 
 	/* mark the journal and then make modifications */
 	ret = cachefs_trans_mark(trans);
-	if (ret<0)
+	if (ret < 0)
 		goto error_free;
 
-	cachefs_block_modify(super,vjentry->vblock,&vjentry->vpage);
+	cachefs_block_modify(super, vjentry->vblock, &vjentry->vpage);
 	memset(kmap(vjentry->vpage) + vjentry->ventry, 0,
 	       sizeof(struct cachefs_ondisc_validity_journal));
 	kunmap(vjentry->vpage);
@@ -226,13 +236,13 @@
 	list_del_init(&vjentry->link);
 	spin_unlock(&super->vjnl_lock);
 
-	cachefs_vj_release(super,vjentry);
+	cachefs_vj_release(super, vjentry);
 	_leave("");
 	return;
 
  error_free:
 	cachefs_trans_put(trans);
  error:
-	_leave(" [error %d]",ret);
+	_leave(" [error %d]", ret);
 
 } /* end cachefs_vj_note_write_completion() */

Index: super.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/super.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -r1.35 -r1.36
--- super.c	1 Jul 2003 17:45:22 -0000	1.35
+++ super.c	4 Jul 2003 09:04:43 -0000	1.36
@@ -23,10 +23,12 @@
 
 #define CACHEFS_FS_MAGIC 0x43414653 /* 'CAFS' */
 
-static void cachefs_i_init_once(void *foo, kmem_cache_t *cachep, unsigned long flags);
+static void cachefs_i_init_once(void *foo, kmem_cache_t *cachep,
+				unsigned long flags);
 
 static struct super_block *cachefs_get_sb(struct file_system_type *fs_type,
-					  int flags, const char *dev_name, void *data);
+					  int flags, const char *dev_name,
+					  void *data);
 
 static struct inode *cachefs_alloc_inode(struct super_block *sb);
 static void cachefs_destroy_inode(struct inode *inode);
@@ -76,8 +78,9 @@
 						 cachefs_i_init_once,
 						 NULL);
 	if (!cachefs_inode_cachep) {
-		printk(KERN_NOTICE "CacheFS: Failed to allocate inode cache\n");
-		kleave(" = %d",ret);
+		printk(KERN_NOTICE
+		       "CacheFS: Failed to allocate inode cache\n");
+		kleave(" = %d", ret);
 		return ret;
 	}
 
@@ -85,7 +88,7 @@
 	ret = register_filesystem(&cachefs_fs_type);
 	if (ret<0) {
 		kmem_cache_destroy(cachefs_inode_cachep);
-		kleave(" = %d",ret);
+		kleave(" = %d", ret);
 		return ret;
 	}
 
@@ -120,12 +123,13 @@
 {
 	struct super_block *sb;
 
-	_enter(",,%s,%p",dev_name,options);
+	_enter(",,%s,%p", dev_name, options);
 
 	/* allocate a device superblock */
-	sb = get_sb_bdev(fs_type,flags,dev_name,options,cachefs_fill_super);
+	sb = get_sb_bdev(fs_type, flags, dev_name, options,
+			 cachefs_fill_super);
 
-	_leave(" = %p",sb);
+	_leave(" = %p", sb);
 	return sb;
 } /* end cachefs_get_sb() */
 
@@ -133,22 +137,23 @@
 /*
  * BIO operation completed
  */
-static int cachefs_bio_completion(struct bio *bio, unsigned int bytes_done, int error)
+static int cachefs_bio_completion(struct bio *bio, unsigned int bytes_done,
+				  int error)
 {
 	unsigned short loop;
 
-	_enter("%p{%u},%u,%d",bio,bio->bi_size,bytes_done,error);
+	_enter("%p{%u},%u,%d", bio, bio->bi_size, bytes_done, error);
 
-	if (bio->bi_size>0) {
+	if (bio->bi_size > 0) {
 		_leave(" = 1");
 		return 1;
 	}
 
-	for (loop=0; loop<bio->bi_vcnt; loop++) {
+	for (loop = 0; loop < bio->bi_vcnt; loop++) {
 		struct page *page = bio->bi_io_vec[loop].bv_page;
 
 		if (PageLocked(page)) {
-			if (test_bit(BIO_UPTODATE,&bio->bi_flags))
+			if (test_bit(BIO_UPTODATE, &bio->bi_flags))
 				SetPageUptodate(page);
 			else
 				SetPageError(page);
@@ -171,14 +176,14 @@
 	struct bio *bio;
 	int loop;
 
-	if (*count>BIO_MAX_PAGES)
+	if (*count > BIO_MAX_PAGES)
 		*count = BIO_MAX_PAGES;
 
-	bio = bio_alloc(GFP_NOFS,*count);
+	bio = bio_alloc(GFP_NOFS, *count);
 	if (!bio)
 		return -ENOMEM;
 
-	_enter("{bdev=%p},%p,%u,%u,%d",sb->s_bdev,page,bix,*count,rw);
+	_enter("{bdev=%p},%p,%u,%u,%d", sb->s_bdev, page, bix, *count, rw);
 
 	SetPageLocked(page);
 
@@ -188,11 +193,11 @@
 	bio->bi_private	= NULL;
 
 	for (loop=0; loop<*count; loop++)
-		if (!bio_add_page(bio,page,PAGE_SIZE,0))
+		if (!bio_add_page(bio, page, PAGE_SIZE, 0))
 			break;
 	*count = loop;
 
-	submit_bio(rw,bio);
+	submit_bio(rw, bio);
 
 	_leave(" = 0");
 	return 0;
@@ -223,24 +228,27 @@
 		return -EROFS;
 	}
 
-	/* we want the block size to be at least as big as the size of a journal entry */
-	if (!sb_min_blocksize(sb,sizeof(struct cachefs_ondisc_update_journal))) {
+	/* we want the block size to be at least as big as the size of a
+	 * journal entry */
+	if (!sb_min_blocksize(sb,
+			      sizeof(struct cachefs_ondisc_update_journal))) {
 		printk("CacheFS: unable to set blocksize\n");
 		return -EIO;
 	}
 
-	kdebug("blockdev %u,%u",MAJOR(sb->s_dev),MINOR(sb->s_dev));
-	kdebug("blockdev size %LuMb",sb->s_bdev->bd_inode->i_size/1024/1024);
+	kdebug("blockdev %u,%u", MAJOR(sb->s_dev), MINOR(sb->s_dev));
+	kdebug("blockdev size %LuMb",
+	       sb->s_bdev->bd_inode->i_size / 1024 / 1024);
 
 	/* allocate a superblock info record */
 	ret = -ENOMEM;
-	super = kmalloc(sizeof(*super),GFP_KERNEL);
+	super = kmalloc(sizeof(*super), GFP_KERNEL);
 	if (!super)
 		goto error;
 
-	memset(super,0,sizeof(*super));
+	memset(super, 0, sizeof(*super));
 
-	super->rcm_imm_buf = (unsigned*) get_zeroed_page(GFP_KERNEL);
+	super->rcm_imm_buf = (unsigned *) get_zeroed_page(GFP_KERNEL);
 	if (!super->rcm_imm_buf)
 		goto error;
 
@@ -254,7 +262,7 @@
 
 	super->vjnl_count = CACHEFS_ONDISC_VJNL_ENTS;
 
-	srch = kmalloc(sizeof(*srch),GFP_KERNEL);
+	srch = kmalloc(sizeof(*srch), GFP_KERNEL);
 	if (!srch)
 		goto error;
 
@@ -313,17 +321,17 @@
 	init_waitqueue_head(&super->dmn_sleepq);
 
 	/* create the linear-mapping inode */
-	ret = cachefs_iget(super,CACHEFS_INO_MISC,&inode2);
-	if (ret<0)
+	ret = cachefs_iget(super, CACHEFS_INO_MISC, &inode2);
+	if (ret < 0)
 		goto error;
 	super->imisc = &inode2->vfs_inode;
 
 	/* read the superblock from disc */
-	ret = cachefs_block_read(super,NULL,0,0,NULL,&page);
-	if (ret<0)
+	ret = cachefs_block_read(super, NULL, 0, 0, NULL, &page);
+	if (ret < 0)
 		goto error;
 
-	set_bit(CACHEFS_BLOCK_NOCOW,&__cachefs_get_page_block(page)->flags);
+	set_bit(CACHEFS_BLOCK_NOCOW, &__cachefs_get_page_block(page)->flags);
 	super->layout = page_address(page);
 
 	/* examine the on-disc superblock record */
@@ -362,7 +370,7 @@
 		 ) {
 		printk("CacheFS: Found uninitialised cache\n");
 		ret = cachefs_initialise_blockdev(super);
-		if (ret<0)
+		if (ret < 0)
 			goto error;
 	}
 	else {
@@ -375,27 +383,27 @@
 	super->ujnl_jsof <<= (PAGE_SHIFT - super->sb->s_blocksize_bits);
 
 	/* get and retain various meta-data inodes */
-	ret = cachefs_iget(super,CACHEFS_INO_METADATA,&super->imetadata);
-	if (ret<0)
+	ret = cachefs_iget(super, CACHEFS_INO_METADATA, &super->imetadata);
+	if (ret < 0)
 		goto error;
 
 	if (jnlreplay) {
 		ret = cachefs_ujnl_replay(super);
-		if (ret<0)
+		if (ret < 0)
 			goto error;
 	}
 
 	kcachefs_jnld_add_super(super);
 
 	/* start the manager daemon */
-	ret = kernel_thread(kcachefsd,super,0);
+	ret = kernel_thread(kcachefsd, super, 0);
 	if (ret<0)
 		goto error;
 	wait_for_completion(&super->dmn_alive);
 
 	/* allocate the root inode and dentry */
-	ret = cachefs_iget(super,CACHEFS_INO_ROOTDIR,&inode);
-	if (ret<0)
+	ret = cachefs_iget(super, CACHEFS_INO_ROOTDIR, &inode);
+	if (ret < 0)
 		goto error;
 
 	ret = -ENOMEM;
@@ -405,9 +413,9 @@
 
 	sb->s_root = root;
 
-	cachefs_add_cache((struct cachefs_super *)sb->s_fs_info,srch);
+	cachefs_add_cache((struct cachefs_super *) sb->s_fs_info,srch);
 
-	kleave(" = 0 [super=%p]",super);
+	kleave(" = 0 [super=%p]", super);
 	return 0;
 
  error:
@@ -423,9 +431,9 @@
 
 		cachefs_put_page(super->alloc_next);
 		cachefs_put_page(super->recycle_node);
-		if (super->rcm_atm_list)	free_page((unsigned long)super->rcm_atm_list);
-		if (super->rcm_imm_buf)		free_page((unsigned long)super->rcm_imm_buf);
-		if (super->vjnl_map)		free_page((unsigned long)super->vjnl_map);
+		free_page((unsigned long) super->rcm_atm_list);
+		free_page((unsigned long) super->rcm_imm_buf);
+		free_page((unsigned long) super->vjnl_map);
 
 		kcachefs_jnld_remove_super(super);
 	}
@@ -435,22 +443,21 @@
 		dbgfree(page_address(page));
 		cachefs_put_page(page);
 	}
-	if (root)
-		dput(root);
 
+	dput(root);
 	cachefs_iput(inode);
 
 	if (super) {
 		cachefs_iput(super->imetadata);
-		if (super->imisc)
-			iput(super->imisc);
+		iput(super->imisc);
 		dbgfree(super);
 		kfree(super);
 	}
+
 	sb->s_root = NULL;
 	sb->s_fs_info = NULL;
 
-	kleave(" = %d",ret);
+	kleave(" = %d", ret);
 	return ret;
 } /* end cachefs_fill_super() */
 
@@ -468,7 +475,7 @@
 	int ret;
 
 	kenter("");
-	set_bit(CACHEFS_SUPER_INIT_BLKDEV,&super->flags);
+	set_bit(CACHEFS_SUPER_INIT_BLKDEV, &super->flags);
 
 	page = alloc_page(GFP_KERNEL);
 	if (!page)
@@ -477,18 +484,20 @@
 
 	/* work out how big the cache is (we use 32-bit block index numbers) */
 	nblocks = super->sb->s_bdev->bd_inode->i_size;
-	do_div(nblocks,PAGE_SIZE);
-	if (nblocks>UINT_MAX)
+	do_div(nblocks, PAGE_SIZE);
+	if (nblocks > UINT_MAX)
 		nblocks = UINT_MAX;
-	if (nblocks<256) {
+	if (nblocks < 256) {
 		printk("CacheFS: cache must be at least 256 blocks in size\n");
 		__free_page(page);
 		return -ENOSPC;
 	}
 
 	/* determine the layout */
-	memset(super->layout,0,PAGE_SIZE);
-	memcpy(super->layout->magic,CACHEFS_SUPER_MAGIC,sizeof(super->layout->magic));
+	memset(super->layout, 0, PAGE_SIZE);
+	memcpy(super->layout->magic,
+	       CACHEFS_SUPER_MAGIC,
+	       sizeof(super->layout->magic));
 
 	super->layout->endian		= CACHEFS_SUPER_ENDIAN;
 	super->layout->version		= CACHEFS_SUPER_VERSION;
@@ -496,30 +505,44 @@
 	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;
+	super->layout->ujnl_recperblk	=
+		super->layout->bsize / super->layout->ujnl_rsize;
 
 	ndirect = 1;
-	qty = super->layout->ujnl_rsize * CACHEFS_ONDISC_UJNL_NUMENTS / super->layout->bsize;
+	qty = super->layout->ujnl_rsize * CACHEFS_ONDISC_UJNL_NUMENTS;
+	qty /= super->layout->bsize;
 
 	super->layout->bix_ujournal	= 1 + ndirect;
-	super->layout->bix_vjournal	= super->layout->bix_ujournal  + qty;
-	super->layout->bix_wbjournal	= super->layout->bix_vjournal  + CACHEFS_ONDISC_VJNL_SIZE;
-	super->layout->bix_cache	= super->layout->bix_wbjournal + CACHEFS_ONDISC_WBJNL_SIZE;
-	super->layout->bix_unready	= super->layout->bix_cache;
-	super->layout->bix_end		= nblocks;
+	super->layout->bix_vjournal =
+		super->layout->bix_ujournal  + qty;
+	super->layout->bix_wbjournal =
+		super->layout->bix_vjournal  + CACHEFS_ONDISC_VJNL_SIZE;
+	super->layout->bix_cache =
+		super->layout->bix_wbjournal + CACHEFS_ONDISC_WBJNL_SIZE;
+	super->layout->bix_unready =
+		super->layout->bix_cache;
+	super->layout->bix_end
+		= nblocks;
 
 	printk("CacheFS: 00000000 super block\n");
-	printk("CacheFS: 00000001 initial vnodes (%u blocks)\n",ndirect);
+	printk("CacheFS: 00000001 initial vnodes (%u blocks)\n", ndirect);
 
 	printk("CacheFS: %08x update journal (%u recs of %u/%ub)\n",
-	       super->layout->bix_ujournal,qty,
+	       super->layout->bix_ujournal,
+	       qty,
 	       sizeof(struct cachefs_ondisc_update_journal),
 	       super->layout->ujnl_rsize);
 
-	printk("CacheFS: %08x validity journal\n",	super->layout->bix_vjournal);
-	printk("CacheFS: %08x writeback journal\n",	super->layout->bix_wbjournal);
-	printk("CacheFS: %08x data cache\n",		super->layout->bix_cache);
-	printk("CacheFS: %08x end\n",			super->layout->bix_end);
+	printk("CacheFS: %08x validity journal\n",
+	       super->layout->bix_vjournal);
+	printk("CacheFS: %08x writeback journal (%u recs of %ub)\n",
+	       super->layout->bix_wbjournal,
+	       super->vjnl_count,
+	       sizeof(struct cachefs_ondisc_validity_journal));
+	printk("CacheFS: %08x data cache\n",
+	       super->layout->bix_cache);
+	printk("CacheFS: %08x end\n",
+	       super->layout->bix_end);
 
 	/* initialise the metadata entry for the metadata file itself */
 	memset(data,0,PAGE_SIZE);
@@ -532,7 +555,8 @@
 
 	metadata =
 		(struct cachefs_ondisc_metadata *)
-		(data + (CACHEFS_INO_METADATA << super->layout->metadata_bits));
+		(data + (CACHEFS_INO_METADATA <<
+			 super->layout->metadata_bits));
 
 	metadata->header.state	= CACHEFS_ONDISC_INDEX_ACTIVE;
 	metadata->size		= PAGE_SIZE;
@@ -544,15 +568,16 @@
 	metadata->index_dsize	-= sizeof(struct cachefs_ondisc_index_entry);
 	metadata->index_esize	= super->layout->metadata_size;
 
-	strncpy(metadata->index_type,".METADAT",9);
+	strncpy(metadata->index_type, ".METADAT", 9);
 
-	for (tmp=0; tmp<ndirect; tmp++)
-		metadata->direct[tmp] = tmp+1; /* point to itself */
+	for (tmp = 0; tmp < ndirect; tmp++)
+		metadata->direct[tmp] = tmp + 1; /* point to itself */
 
 	/* initialise the metadata entry for the FSDEF catalogue */
 	metadata =
 		(struct cachefs_ondisc_metadata *)
-		(data + (CACHEFS_INO_FSDEF_CATALOGUE << super->layout->metadata_bits));
+		(data + (CACHEFS_INO_FSDEF_CATALOGUE <<
+			 super->layout->metadata_bits));
 
 	metadata->header.state	= CACHEFS_ONDISC_INDEX_ACTIVE;
 	metadata->size		= 0;
@@ -565,21 +590,11 @@
 	metadata->index_esize	+= metadata->index_dsize;
 	metadata->index_keys[0]	= CACHEFS_ONDISC_INDEXKEY_ASCIIZ | 24;
 
-	strncpy(metadata->index_type,".FSDEF",8);
-
-#if 1 /* TODO: remove */
-	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
+	strncpy(metadata->index_type, ".FSDEF", 8);
 
 	tmp = 1;
-	ret = cachefs_bio_submit(super->sb,page,1,&tmp,WRITE);
-	if (ret<0) {
+	ret = cachefs_bio_submit(super->sb, page, 1, &tmp, WRITE);
+	if (ret < 0) {
 		__free_page(page);
 		return ret;
 	}
@@ -592,24 +607,25 @@
 	}
 
 	/* clear the journals and other metafiles */
-	memset(data,0,PAGE_SIZE);
+	memset(data, 0, PAGE_SIZE);
 
 	bix = 2;
-	while (bix<super->layout->bix_cache) {
+	while (bix < super->layout->bix_cache) {
 		qty = super->layout->bix_cache - bix;
 
-		kdebug("clearing blocks %u-%u",bix,bix+qty-1);
+		kdebug("clearing blocks %u-%u", bix, bix + qty - 1);
 
 		tmp = qty;
-		ret = cachefs_bio_submit(super->sb,page,bix,&tmp,WRITE);
-		if (ret<0) {
+		ret = cachefs_bio_submit(super->sb, page, bix, &tmp, WRITE);
+		if (ret < 0) {
 			__free_page(page);
 			return ret;
 		}
 
 		wait_on_page_locked(page);
 		if (PageError(page)) {
-			printk("CacheFS: failed to write blocks %u-%u\n",bix,bix+qty-1);
+			printk("CacheFS: failed to write blocks %u-%u\n",
+			       bix, bix + qty - 1);
 			__free_page(page);
 			return -EIO;
 		}
@@ -622,12 +638,13 @@
 	/* write the superblock last */
 	kdebug("writing superblock");
 	tmp = 1;
-	ret = cachefs_bio_submit(super->sb,virt_to_page(super->layout),0,&tmp,WRITE);
-	if (ret<0)
+	ret = cachefs_bio_submit(super->sb, virt_to_page(super->layout), 0,
+				 &tmp, WRITE);
+	if (ret < 0)
 		return ret;
 	wait_on_page_locked(page);
 
-	clear_bit(CACHEFS_SUPER_INIT_BLKDEV,&super->flags);
+	clear_bit(CACHEFS_SUPER_INIT_BLKDEV, &super->flags);
 	kleave(" = 0");
 	return 0;
 } /* end cachefs_initialise_blockdev() */
@@ -656,7 +673,8 @@
 	buf->f_ffree	= tmp;
 	buf->f_namelen	= NAME_MAX;
 
-	if (super->recycle_room>0) buf->f_bfree++;
+	if (super->recycle_room > 0)
+		buf->f_bfree++;
 
 	return 0;
 } /* end cachefs_statfs() */
@@ -677,19 +695,21 @@
 
 	page = alloc_page(GFP_KERNEL);
 	if (!page) {
-		printk("CacheFS: unable to write superblock to disc (ENOMEM)\n");
+		printk("CacheFS:"
+		       " unable to write superblock to disc (ENOMEM)\n");
 		return;
 	}
 
 	data = kmap(page);
-	memset(data,0,PAGE_SIZE);
-	memcpy(data,&super->layout,sizeof(super->layout));
+	memset(data, 0, PAGE_SIZE);
+	memcpy(data, &super->layout, sizeof(super->layout));
 	kunmap(page);
 
 	tmp = 1;
-	ret = cachefs_bio_submit(super->sb,page,0,&tmp,WRITE);
-	if (ret<0) {
-		printk("CacheFS: unable to write superblock to disc (%d)\n",ret);
+	ret = cachefs_bio_submit(super->sb,page, 0, &tmp, WRITE);
+	if (ret < 0) {
+		printk("CacheFS: unable to write superblock to disc (%d)\n",
+		       ret);
 		return;
 	}
 	wait_on_page_locked(page);
@@ -706,12 +726,12 @@
 {
 	struct cachefs_super *super = sb->s_fs_info;
 
-	DECLARE_WAITQUEUE(myself,current);
+	DECLARE_WAITQUEUE(myself, current);
 
 	printk("\n\n");
-	kenter("{%p}",super);
+	kenter("{%p}", super);
 
-	if (!super) BUG();
+	BUG_ON(!super);
 
 	cachefs_withdraw_cache(super);
 
@@ -719,7 +739,7 @@
 	    !list_empty(&super->vjnl_writtenq)
 	    ) {
 		set_current_state(TASK_UNINTERRUPTIBLE);
-		add_wait_queue(&super->vjnl_alloc_wq,&myself);
+		add_wait_queue(&super->vjnl_alloc_wq, &myself);
 
 		while (!list_empty(&super->vjnl_unallocq) ||
 		       !list_empty(&super->vjnl_writtenq)) {
@@ -732,7 +752,7 @@
 	}
 
 	super->dmn_die = 1;
-	cachefs_trans_sync(super,CACHEFS_TRANS_SYNC_WAIT_FOR_ACK);
+	cachefs_trans_sync(super, CACHEFS_TRANS_SYNC_WAIT_FOR_ACK);
 
 	super->dmn_die = 2;
 	wake_up(&super->dmn_sleepq);
@@ -752,9 +772,9 @@
 	cachefs_put_page(super->recycle_node);
 	cachefs_block_put(super->recycle_block);
 
-	free_page((unsigned long)super->rcm_atm_list);
-	free_page((unsigned long)super->rcm_imm_buf);
-	free_page((unsigned long)super->vjnl_map);
+	free_page((unsigned long) super->rcm_atm_list);
+	free_page((unsigned long) super->rcm_imm_buf);
+	free_page((unsigned long) super->vjnl_map);
 
 	kcachefs_jnld_remove_super(super);
 
@@ -762,15 +782,17 @@
 	cachefs_iput(super->imetadata);
 	iput(super->imisc);
 
-	if (atomic_read(&super->cnt_blk_tree)!=0) {
+	if (atomic_read(&super->cnt_blk_tree) != 0) {
 		struct rb_node *_n;
 
 		printk("#### ERROR: %d block tree nodes left at unmount:\n",
 		       atomic_read(&super->cnt_blk_tree));
 
-		for (_n=rb_first(&super->blk_tree); _n; _n=rb_next(_n)) {
+		for (_n = rb_first(&super->blk_tree); _n; _n = rb_next(_n)) {
 			struct cachefs_block *block =
-				rb_entry(_n,struct cachefs_block,lookup_node);
+				rb_entry(_n,
+					 struct cachefs_block,
+					 lookup_node);
 
 			printk("- block %05d u=%d fl=%08lx pg=%p wb=%p\n",
 			       block->bix,
@@ -797,8 +819,9 @@
 {
 	struct cachefs_inode *inode = _inode;
 
-	if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == SLAB_CTOR_CONSTRUCTOR) {
-		memset(inode,0,sizeof(*inode));
+	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);
 
@@ -816,7 +839,8 @@
 {
 	struct cachefs_inode *inode;
 
-	inode = (struct cachefs_inode *) kmem_cache_alloc(cachefs_inode_cachep,SLAB_KERNEL);
+	inode = (struct cachefs_inode *)
+		kmem_cache_alloc(cachefs_inode_cachep, SLAB_KERNEL);
 	if (!inode)
 		return NULL;
 
@@ -829,6 +853,6 @@
  */
 static void cachefs_destroy_inode(struct inode *inode)
 {
-	_enter("{%lu}",inode->i_ino);
-	kmem_cache_free(cachefs_inode_cachep,CACHEFS_FS_I(inode));
+	_enter("{%lu}", inode->i_ino);
+	kmem_cache_free(cachefs_inode_cachep, CACHEFS_FS_I(inode));
 } /* end cachefs_destroy_inode() */

Index: status.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/status.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- status.c	9 Jun 2003 13:38:21 -0000	1.6
+++ status.c	4 Jul 2003 09:04:43 -0000	1.7
@@ -21,7 +21,8 @@
 #include "cachefs-int.h"
 
 static int cachefs_status_open(struct inode *inode, struct file *file);
-static ssize_t cachefs_status_write(struct file *, const char __user *, size_t, loff_t *);
+static ssize_t cachefs_status_write(struct file *, const char __user *,
+				    size_t, loff_t *);
 static void *cachefs_status_start(struct seq_file *p, loff_t *pos);
 static void *cachefs_status_next(struct seq_file *p, void *v, loff_t *pos);
 static void cachefs_status_stop(struct seq_file *p, void *v);
@@ -54,7 +55,7 @@
 	struct seq_file *m;
 	int ret;
 
-	ret = seq_open(file,&cachefs_status_ops);
+	ret = seq_open(file, &cachefs_status_ops);
 	if (ret<0)
 		return ret;
 
@@ -62,7 +63,6 @@
 	m->private = inode->i_sb->s_fs_info;
 
 	return 0;
-
 } /* end cachefs_status_open() */
 
 /*****************************************************************************/
@@ -71,7 +71,8 @@
  */
 static void *cachefs_status_start(struct seq_file *p, loff_t *pos)
 {
-	return (*pos) ? NULL : (void*)1;
+	return *pos ? NULL : (void *) 1;
+
 } /* end cachefs_status_start() */
 
 /*****************************************************************************/
@@ -81,8 +82,8 @@
 static void *cachefs_status_next(struct seq_file *p, void *v, loff_t *pos)
 {
 	(*pos)++;
-	return NULL;
 
+	return NULL;
 } /* end cachefs_status_next() */
 
 /*****************************************************************************/
@@ -101,50 +102,56 @@
 {
 	struct cachefs_super *super = m->private;
 
-	seq_puts(m,"CacheFS (c) Red Hat, Inc. 2002\n");
-	seq_puts(m,"\n");
+	seq_puts(m, "CacheFS (c) Red Hat, Inc. 2002\n");
+	seq_puts(m, "\n");
 
-	seq_printf(m,"u-journal : %u-%u (%u byte slots, %u per page)\n",
+	seq_printf(m, "u-journal : %u-%u (%u byte slots, %u per page)\n",
 		   super->layout->bix_ujournal,
 		   super->layout->bix_wbjournal,
 		   super->layout->ujnl_rsize,
-		   super->layout->ujnl_recperblk
-		   );
+		   super->layout->ujnl_recperblk);
 
-	seq_printf(m,"wb-journal: %u-%u\n",
+	seq_printf(m, "wb-journal: %u-%u\n",
 		   super->layout->bix_wbjournal,
-		   super->layout->bix_cache
-		   );
+		   super->layout->bix_cache);
 
-	seq_printf(m,"cache     : %u-%u [%u-%u unready]\n",
+	seq_printf(m, "cache     : %u-%u [%u-%u unready]\n",
 		   super->layout->bix_cache,
 		   super->layout->bix_end,
 		   super->layout->bix_unready,
-		   super->layout->bix_end
-		   );
-
-	seq_puts(m,"\n");
-
-	seq_printf(m,"Alloc Stk : TOS={%u}+%u NUM=%u\n",
-		   super->alloc_cur,super->alloc_leaf,super->alloc_cur_n);
+		   super->layout->bix_end);
 
-	seq_printf(m,"Recyc Stk : TOS={%u} #%u NUM=%u\n",
-		   super->recycle_cur,super->recycle_room,super->recycle_cur_n);
+	seq_puts(m, "\n");
 
-	seq_printf(m,"Reclaimer : ino=%u indir=%u blk=%u:%hu-%hu\n",
-		   super->rcm_ino,super->rcm_indirect,super->rcm_block,
-		   super->rcm_ptrnext,super->rcm_ptrstop);
+	seq_printf(m, "Alloc Stk : TOS={%u}+%u NUM=%u\n",
+		   super->alloc_cur,
+		   super->alloc_leaf,
+		   super->alloc_cur_n);
+
+	seq_printf(m, "Recyc Stk : TOS={%u} #%u NUM=%u\n",
+		   super->recycle_cur,
+		   super->recycle_room,
+		   super->recycle_cur_n);
+
+	seq_printf(m, "Reclaimer : ino=%u indir=%u blk=%u:%hu-%hu\n",
+		   super->rcm_ino,
+		   super->rcm_indirect,
+		   super->rcm_block,
+		   super->rcm_ptrnext,
+		   super->rcm_ptrstop);
+
+	seq_printf(m, "uj disc   : NEXT=%u ACK=%u\n",
+		   super->ujnl_head,
+		   super->ujnl_tail);
 
-	seq_printf(m,"uj disc   : NEXT=%u ACK=%u\n",super->ujnl_head,super->ujnl_tail);
-
-	seq_printf(m,"ujournal  : BATCH=%hd SERIAL=%hu\n",
+	seq_printf(m, "ujournal  : BATCH=%hd SERIAL=%hu\n",
 		   super->ujnl_batch,
-		   super->ujnl_serial
-		   );
+		   super->ujnl_serial);
 
-	seq_puts(m,"\n");
+	seq_puts(m, "\n");
 
-	seq_printf(m,"uj marks  : REQUESTED=%u GRANTED=%u WRITTEN=%u FREED=%u\n",
+	seq_printf(m,
+		   "uj marks  : REQUESTED=%u GRANTED=%u WRITTEN=%u FREED=%u\n",
 		   atomic_read(&super->cnt_ujnl_mkrq),
 		   atomic_read(&super->cnt_ujnl_mkgr),
 		   atomic_read(&super->cnt_ujnl_mkwr),
@@ -161,10 +168,10 @@
 
 /*****************************************************************************/
 /*
- * 
+ *
  */
-static ssize_t cachefs_status_write(struct file *file, const char __user *data, size_t size,
-				    loff_t *pos)
+static ssize_t cachefs_status_write(struct file *file, const char __user *data,
+				    size_t size, loff_t *pos)
 {
 	struct cachefs_super *super;
 	struct cachefs_block *block, *xblock;
@@ -176,16 +183,16 @@
 	super = inode->i_sb->s_fs_info;
 
 	xblock = NULL;
-	read_lock_irqsave(&super->blk_tree_lock,flags);
+	read_lock_irqsave(&super->blk_tree_lock, flags);
 
 	_rb = rb_first(&super->blk_tree);
 	while (_rb) {
-		block = rb_entry(_rb,struct cachefs_block,lookup_node);
+		block = rb_entry(_rb, struct cachefs_block, lookup_node);
 
 		if (block->page) {
 			cachefs_block_get(block);
 
-			read_unlock_irqrestore(&super->blk_tree_lock,flags);
+			read_unlock_irqrestore(&super->blk_tree_lock, flags);
 			cachefs_block_put(xblock);
 
 			printk("- block %05d u=%d fl=%08lx pg=%p wb=%p r=%p\n",
@@ -196,13 +203,13 @@
 			       block->writeback,
 			       block->ref);
 
-			read_lock_irqsave(&super->blk_tree_lock,flags);
+			read_lock_irqsave(&super->blk_tree_lock, flags);
 			xblock = block;
 		}
 		_rb = rb_next(_rb);
 	}
 
-	read_unlock_irqrestore(&super->blk_tree_lock,flags);
+	read_unlock_irqrestore(&super->blk_tree_lock, flags);
 	cachefs_block_put(xblock);
 
 	return size;

Index: rootdir.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/rootdir.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- rootdir.c	3 Jun 2003 17:43:15 -0000	1.11
+++ rootdir.c	4 Jul 2003 09:04:43 -0000	1.12
@@ -22,9 +22,12 @@
 #include <asm/uaccess.h>
 #include "cachefs-int.h"
 
-static struct dentry *cachefs_root_lookup(struct inode *dir, struct dentry *dentry);
-static int cachefs_root_readdir(struct file *file, void *dirent, filldir_t filldir);
-static int cachefs_root_rmdir_unlink(struct inode *dir, struct dentry *dentry);
+static struct dentry *cachefs_root_lookup(struct inode *dir,
+					  struct dentry *dentry);
+static int cachefs_root_readdir(struct file *file, void *dirent,
+				filldir_t filldir);
+static int cachefs_root_rmdir_unlink(struct inode *dir,
+				     struct dentry *dentry);
 
 struct file_operations cachefs_root_file_operations = {
 	.readdir	= cachefs_root_readdir,
@@ -58,6 +61,71 @@
 
 /*****************************************************************************/
 /*
+ * construct a name from an index entry and definition
+ */
+static
+int cachefs_readdir_actor_cons_name(struct cachefs_readdir_record *rec,
+				    struct cachefs_ondisc_index_entry *xent)
+{
+	unsigned char *ptr;
+	unsigned long tmp;
+	char *name;
+	int ksize, loop;
+
+	/* construct a name */
+	name = rec->scratch;
+	ptr = xent->data;
+
+	for (loop = 0; loop < 4; loop++) {
+
+		_debug("- key %04hx", rec->keys[loop]);
+
+		ksize = rec->keys[loop] & CACHEFS_ONDISC_INDEXKEY_KLEN;
+
+		if (loop > 0)
+			*name++ = ',';
+
+		switch (rec->keys[loop] & CACHEFS_ONDISC_INDEXKEY_TYPE) {
+		case CACHEFS_ONDISC_INDEXKEY_BIN:
+			for (tmp = 0; tmp < ksize; tmp++) {
+				sprintf(name, "%02x", ptr[tmp]);
+				name += 2;
+			}
+			break;
+
+		case CACHEFS_ONDISC_INDEXKEY_ASCIIZ:
+			tmp = strnlen(ptr, ksize);
+			memcpy(name, ptr, tmp);
+			name += tmp;
+			break;
+
+		case CACHEFS_ONDISC_INDEXKEY_IPV4:
+			tmp = sprintf(name, "%u.%u.%u.%u",
+				      ptr[0], ptr[1], ptr[2], ptr[3]);
+			name += tmp;
+			break;
+
+		case CACHEFS_ONDISC_INDEXKEY_IPV6:
+			tmp = sprintf(name, "%u:%u:%u:%u:%u:%u:%u:%u",
+				      ptr[0], ptr[1], ptr[2], ptr[3],
+				      ptr[4], ptr[5], ptr[6], ptr[7]);
+			name += tmp;
+			break;
+		default:
+			if (loop > 0)
+				name--;
+			break;
+		}
+
+		ptr += ksize;
+	}
+
+	*name = 0;
+	return name - rec->scratch;
+} /* end cachefs_readdir_actor_cons_name() */
+
+/*****************************************************************************/
+/*
  * root directory read actor
  * - return size to continue, 0 to stop (search also stops when desc->count==0)
  */
@@ -68,12 +136,10 @@
 {
 	struct cachefs_readdir_record *rec;
 	unsigned long stop, tmp;
-	unsigned char *ptr;
 	void *content;
-	char *name;
-	int loop, ret, type;
+	int ret, type, nlen;
 
-	_enter(",{%lu},%lu,%lu",page->index,offset,size);
+	_enter(",{%lu},%lu,%lu", page->index, offset, size);
 
 	rec = (struct cachefs_readdir_record *) desc->buf;
 
@@ -94,76 +160,32 @@
 	size		-= tmp;
 	ret		= tmp;
 
-	/* limit the search of this page to the amount specified in desc->count */
+	/* limit the search of this page to the amount specified in
+	 * desc->count */
 	stop = desc->count;
-	if (size<stop)
+	if (size < stop)
 		stop = size;
 
 	/* read the entries on the page (ignoring slack at end) */
 	content = kmap(page);
 
-	for (; offset+rec->esize<=stop; offset+=rec->esize) {
+	for (; offset + rec->esize <= stop; offset += rec->esize) {
 		struct cachefs_ondisc_index_entry *xent = content + offset;
 
-		if (xent->state==CACHEFS_ONDISC_INDEX_FREE ||
-		    xent->state==CACHEFS_ONDISC_INDEX_RECYCLE) {
+		if (xent->state == CACHEFS_ONDISC_INDEX_FREE ||
+		    xent->state == CACHEFS_ONDISC_INDEX_RECYCLE) {
 			desc->count	-= rec->esize;
 			desc->written	+= rec->esize;
 			ret		+= rec->esize;
 			continue;
 		}
 
-		/* construct a name */
-		name = rec->scratch;
-		ptr = xent->data;
-
-		for (loop=0; loop<4; loop++) {
-			int ksize = rec->keys[loop] & CACHEFS_ONDISC_INDEXKEY_KLEN;
-
-			_debug("- key %04hx",rec->keys[loop]);
-
-			if (loop>0) *name++ = ',';
-
-			switch (rec->keys[loop] & CACHEFS_ONDISC_INDEXKEY_TYPE) {
-			case CACHEFS_ONDISC_INDEXKEY_BIN:
-				for (tmp=0; tmp<ksize; tmp++) {
-					sprintf(name,"%02x",ptr[tmp]);
-					name += 2;
-				}
-				break;
-
-			case CACHEFS_ONDISC_INDEXKEY_ASCIIZ:
-				tmp = strnlen(ptr,ksize);
-				memcpy(name,ptr,tmp);
-				name += tmp;
-				break;
-
-			case CACHEFS_ONDISC_INDEXKEY_IPV4:
-				tmp = sprintf(name,"%u.%u.%u.%u",ptr[0],ptr[1],ptr[2],ptr[3]);
-				name += tmp;
-				break;
-
-			case CACHEFS_ONDISC_INDEXKEY_IPV6:
-				tmp = sprintf(name,"%u:%u:%u:%u:%u:%u:%u:%u",
-					      ptr[0],ptr[1],ptr[2],ptr[3],
-					      ptr[4],ptr[5],ptr[6],ptr[7]);
-				name += tmp;
-				break;
-			default:
-				if (loop>0) name--;
-				break;
-			}
-
-			ptr += ksize;
-		}
-
-		*name = 0;
-
-		tmp = rec->dpos_off + (page->index * rec->epp) + offset/rec->esize;
+		nlen = cachefs_readdir_actor_cons_name(rec, xent);
 
-		_debug("dirent: %d '%s' ino=%u",name-rec->scratch,rec->scratch,xent->ino);
+		_debug("dirent: %d '%s' ino=%u",
+		       nlen, rec->scratch, xent->ino);
 
-		if (name == rec->scratch) {
+		if (nlen) {
 			desc->count	-= rec->esize;
 			desc->written	+= rec->esize;
 			ret		+= rec->esize;
@@ -171,15 +193,18 @@
 		}
 
 		type = DT_REG;
-		if (xent->type==CACHEFS_ONDISC_INDEX_INDEXFILE)
+		if (xent->type == CACHEFS_ONDISC_INDEX_INDEXFILE)
 			type = DT_DIR;
 
+		tmp = rec->dpos_off + (page->index * rec->epp) +
+			offset / rec->esize;
+
 		if (rec->filldir(rec->cookie,
 				 rec->scratch,
-				 name - rec->scratch,
+				 nlen,
 				 tmp,
 				 xent->ino,
-				 type)<0
+				 type) < 0
 		    ) {
 			desc->count = 0;
 			goto done;
@@ -198,7 +223,7 @@
 	kunmap(page);
 
  done_already:
-	_leave(" = %d",ret);
+	_leave(" = %d", ret);
 	return ret;
 } /* end cachefs_readdir_actor() */
 
@@ -206,7 +231,9 @@
 /*
  * read the cache's root directory
  */
-static int cachefs_root_readdir(struct file *file, void *cookie, filldir_t filldir)
+static int cachefs_root_readdir(struct file *file,
+				void *cookie,
+				filldir_t filldir)
 {
 	struct cachefs_ondisc_metadata *metadata;
 	struct cachefs_readdir_record rec;
@@ -218,9 +245,9 @@
 
 	inode = CACHEFS_FS_I(file->f_dentry->d_inode);
 
-	_enter("{%Ld,{%lu}}",file->f_pos,inode->vfs_inode.i_ino);
+	_enter("{%Ld,{%lu}}", file->f_pos, inode->vfs_inode.i_ino);
 
-	rec.scratch = (char*) get_zeroed_page(GFP_KERNEL);
+	rec.scratch = (char *) get_zeroed_page(GFP_KERNEL);
 	dbgpgalloc(rec.scratch);
 	if (!rec.scratch)
 		return -ENOMEM;
@@ -233,18 +260,20 @@
 	rec.epp		= inode->index_esize;
 
 	metadata = cachefs_metadata_preread(inode);
-	memcpy(rec.keys,metadata->index_keys,sizeof(rec.keys));
+	memcpy(rec.keys, metadata->index_keys, sizeof(rec.keys));
 	cachefs_metadata_postread(inode);
 
 	switch (file->f_pos) {
 	case 0:
-		ret = filldir(cookie,".",1,file->f_pos,inode->vfs_inode.i_ino,DT_DIR);
-		if (ret<0)
+		ret = filldir(cookie, ".", 1, file->f_pos,
+			      inode->vfs_inode.i_ino, DT_DIR);
+		if (ret < 0)
 			goto done;
 		file->f_pos++;
 	case 1:
-		ret = filldir(cookie,"..",2,file->f_pos,parent_ino(file->f_dentry),DT_DIR);
-		if (ret<0)
+		ret = filldir(cookie, "..", 2, file->f_pos,
+			      parent_ino(file->f_dentry), DT_DIR);
+		if (ret < 0)
 			goto done;
 		file->f_pos++;
 	default:
@@ -252,57 +281,55 @@
 	}
 
 	/* deal with root directory only entries */
-	if (inode->vfs_inode.i_ino==CACHEFS_INO_ROOTDIR) {
+	if (inode->vfs_inode.i_ino == CACHEFS_INO_ROOTDIR) {
 		rec.dpos_off = 5;
 		switch (file->f_pos) {
 		case 2:
-			ret = filldir(cookie,"metadata_catalogue",18,
-				      file->f_pos,CACHEFS_INO_METADATA,DT_REG);
-			if (ret<0)
+			ret = filldir(cookie, "metadata_catalogue", 18,
+				      file->f_pos, CACHEFS_INO_METADATA,
+				      DT_REG);
+			if (ret < 0)
 				goto done;
 			file->f_pos++;
 		case 3:
-			ret = filldir(cookie,"status",6,file->f_pos,CACHEFS_INO_STATUS,DT_REG);
-			if (ret<0)
-				goto done;
-			file->f_pos++;
-#if 1 /* TODO: remove */
-		case 4:
-			ret = filldir(cookie,"wibble",6,
-				      file->f_pos,CACHEFS_INO_WIBBLE,DT_REG);
-			if (ret<0)
+			ret = filldir(cookie, "status", 6,
+				      file->f_pos, CACHEFS_INO_STATUS,
+				      DT_REG);
+			if (ret < 0)
 				goto done;
 			file->f_pos++;
-#endif
 		default:
 			break;
 		}
 	}
 
 	/* iterate through the index entries stored on disc */
-	if (inode->vfs_inode.i_size>0) {
+	if (inode->vfs_inode.i_size > 0) {
 		entry = file->f_pos - rec.dpos_off;
-		pos = (entry/rec.epp) << PAGE_SHIFT;
-		pos += (entry%rec.epp) * rec.esize;
+		pos = (entry / rec.epp) << PAGE_SHIFT;
+		pos += (entry % rec.epp) * rec.esize;
 
 		desc.written	= 0;
 		desc.count	= inode->vfs_inode.i_size - pos;
-		desc.buf	= (char*) &rec;
+		desc.buf	= (char *) &rec;
 		desc.error	= 0;
 
 		_debug("do read: isz=%llu pos=%llu count=%u",
-		       inode->vfs_inode.i_size,pos,desc.count);
+		       inode->vfs_inode.i_size, pos, desc.count);
 
-		do_generic_file_read(file,&pos,&desc,cachefs_readdir_actor);
+		do_generic_file_read(file, &pos, &desc, cachefs_readdir_actor);
 
 		file->f_pos = (pos >> PAGE_SHIFT) * rec.epp;
-		file->f_pos += ((unsigned)(pos & ~PAGE_MASK) + rec.esize - 1) / rec.esize;
+		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);
+		_debug("done read: err=%d pos=%llu fpos=%llu",
+		       desc.error, pos, file->f_pos);
 
 		ret = desc.error;
-		if (ret<0)
+		if (ret < 0)
 			goto error;
 	}
 
@@ -312,7 +339,7 @@
  error:
 	dbgpgfree(rec.scratch);
 	free_page((unsigned long) rec.scratch);
-	_leave(" = %d",ret);
+	_leave(" = %d", ret);
 	return ret;
 } /* end cachefs_root_readdir() */
 
@@ -331,7 +358,7 @@
 	void *content;
 	int ret;
 
-	_enter(",{%lu},%lu,%lu",page->index,offset,size);
+	_enter(",{%lu},%lu,%lu", page->index, offset, size);
 
 	rec = (struct cachefs_lookup_record *) desc->buf;
 	ret = size;
@@ -340,14 +367,15 @@
 	tmp = offset;
 	offset += rec->esize - 1;
 	offset -= offset % rec->esize;
-	if (offset-tmp > size)
+	if (offset - tmp > size)
 		goto done;
 
 	size -= offset - tmp;
 
-	/* limit the search of this page to the amount specified in desc->count */
+	/* limit the search of this page to the amount specified in
+	 * desc->count */
 	stop = desc->count;
-	if (size<stop)
+	if (size < stop)
 		stop = size;
 
 	tmp = rec->esize;
@@ -355,14 +383,14 @@
 	/* search the elements on the page (ignoring slack at end) */
 	content = kmap(page);
 
-	for (; offset+tmp<=stop; offset+=tmp) {
+	for (; offset + tmp <= stop; offset += tmp) {
 		struct cachefs_ondisc_index_entry *xent = content + offset;
 
-		if (xent->state==CACHEFS_ONDISC_INDEX_FREE ||
-		    xent->state==CACHEFS_ONDISC_INDEX_RECYCLE)
+		if (xent->state == CACHEFS_ONDISC_INDEX_FREE ||
+		    xent->state == CACHEFS_ONDISC_INDEX_RECYCLE)
 			continue;
 
-		if (memcmp(xent->data,rec->key,rec->ksize)==0) {
+		if (memcmp(xent->data, rec->key, rec->ksize) == 0) {
 			rec->ino = xent->ino;
 			desc->count = 0;
 			ret = 0;
@@ -376,7 +404,7 @@
 	desc->count -= ret;
 	desc->written += ret;
 
-	_leave(" = %d",ret);
+	_leave(" = %d", ret);
 	return ret;
 } /* end cachefs_lookup_actor() */
 
@@ -401,7 +429,7 @@
 	dir = CACHEFS_FS_I(_dir);
 	name = dentry->d_name.name;
 
-	_enter("{%lu},{%s}",dir->vfs_inode.i_ino,name);
+	_enter("{%lu},{%s}", dir->vfs_inode.i_ino, name);
 
 	rec.key		= NULL;
 	rec.esize	= dir->index_esize;
@@ -411,34 +439,27 @@
 	/* consider the virtual files we want to expose */
 	switch (dentry->d_name.len) {
 	case 1:
-		if (memcmp(name,".",1)==0) {
+		if (memcmp(name, ".", 1) == 0) {
 			target = cachefs_igrab(dir);
 			goto instantiate;
 		}
 		break;
 	case 2:
-		if (memcmp(name,"..",2)==0) {
+		if (memcmp(name, "..", 2)==0) {
 			target = cachefs_igrab(dir);
 			goto instantiate;
 		}
 		break;
 	case 6:
-		if (dir->vfs_inode.i_ino==CACHEFS_INO_ROOTDIR &&
-		    memcmp(name,"status",6)==0) {
+		if (dir->vfs_inode.i_ino == CACHEFS_INO_ROOTDIR &&
+		    memcmp(name, "status", 6) == 0) {
 			ino = CACHEFS_INO_STATUS;
 			goto get;
 		}
-#if 1 /* TODO: remove */
-		if (dir->vfs_inode.i_ino==CACHEFS_INO_ROOTDIR &&
-		    memcmp(name,"wibble",6)==0) {
-			ino = CACHEFS_INO_WIBBLE;
-			goto get;
-		}
-#endif
 		break;
 	case 18:
-		if (dir->vfs_inode.i_ino==CACHEFS_INO_ROOTDIR &&
-		    memcmp(name,"metadata_catalogue",18)==0) {
+		if (dir->vfs_inode.i_ino == CACHEFS_INO_ROOTDIR &&
+		    memcmp(name, "metadata_catalogue", 18) == 0) {
 			ino = CACHEFS_INO_METADATA;
 			goto get;
 		}
@@ -449,20 +470,21 @@
 
 	/* construct a key to search the FSDEF index with */
 	metadata = cachefs_metadata_preread(dir);
-	memcpy(rec.keys,metadata->index_keys,sizeof(rec.keys));
+	memcpy(rec.keys, metadata->index_keys, sizeof(rec.keys));
 	cachefs_metadata_postread(dir);
 
-	for (loop=0; loop<4; loop++)
+	for (loop = 0; loop < 4; loop++)
 		rec.ksize += rec.keys[loop] & CACHEFS_ONDISC_INDEXKEY_KLEN;
 
 	if (rec.ksize>dir->index_dsize) {
-		printk("CacheFS: key def longer than data %u>%u\n",rec.ksize,dir->index_dsize);
+		printk("CacheFS: key def longer than data %u>%u\n",
+		       rec.ksize, dir->index_dsize);
 		ret = -EIO;
 		goto error;
 	}
 
 	ret = -ENOMEM;
-	rec.key = (char*) get_zeroed_page(GFP_KERNEL);
+	rec.key = (char *) get_zeroed_page(GFP_KERNEL);
 	if (!rec.key)
 		goto error;
 
@@ -470,47 +492,57 @@
 
 	stop = name;
 	ptr = rec.key;
-	for (loop=0; loop<4; loop++) {
+	for (loop = 0; loop < 4; loop++) {
 		char x;
 		int ksize = rec.keys[loop] & CACHEFS_ONDISC_INDEXKEY_KLEN;
 
-		if (ksize==0)
+		if (ksize == 0)
 			continue;
 
-		stop = memchr(name,',',nend-name) ?: nend;
+		stop = memchr(name, ',', nend - name) ?: nend;
 
-		_debug("- key %04hx [%*.*s]",rec.keys[loop],nend-name,nend-name,name);
+		_debug("- key %04hx [%*.*s]",
+		       rec.keys[loop], nend - name, nend - name, name);
 
 		switch (rec.keys[loop] & CACHEFS_ONDISC_INDEXKEY_TYPE) {
 		case CACHEFS_ONDISC_INDEXKEY_BIN:
-			if (stop-name!=ksize*2 || ksize==0)
+			if (stop - name != ksize * 2 || ksize == 0)
 				goto not_found;
 
 			do {
+				char c;
+
 				if (!isxdigit(*name))
 					goto not_found;
-				x = isdigit(*name) ? *name-'0' : toupper(*name)-'A'+10;
+				c = *name - '0';
+				if (!isdigit(*name))
+					c = toupper(*name) - 'A' + 10;
 				name++;
-				x <<= 4;
+				x = c << 4;
 
 				if (!isxdigit(*name))
 					goto not_found;
-				x |= isdigit(*name) ? *name-'0' : toupper(*name)-'A'+10;
+				c = *name - '0';
+				if (!isdigit(*name))
+					c = toupper(*name) - 'A' + 10;
 				name++;
+				x |= c;
+
 				*ptr++ = x;
-			} while (name<stop);
+			} while (name < stop);
 
 			break;
 
 		case CACHEFS_ONDISC_INDEXKEY_ASCIIZ:
-			if (nend-name>ksize || ksize==0)
+			if (nend - name > ksize || ksize == 0)
 				goto not_found;
-			memcpy(ptr,name,stop-name);
+			memcpy(ptr, name, stop - name);
 			ptr += ksize;
 			break;
 
 		case CACHEFS_ONDISC_INDEXKEY_IPV4:
-			if (sscanf(ptr,"%hu.%hu.%hu.%hu",&ip[0],&ip[1],&ip[2],&ip[3])!=4)
+			if (sscanf(ptr, "%hu.%hu.%hu.%hu",
+				   &ip[0], &ip[1], &ip[2], &ip[3]) != 4)
 				goto not_found;
 			*ptr++ = ip[0];
 			*ptr++ = ip[1];
@@ -519,8 +551,9 @@
 			break;
 
 		case CACHEFS_ONDISC_INDEXKEY_IPV6:
-			if (sscanf(ptr,"%hu:%hu:%hu:%hu:%hu:%hu:%hu:%hu",
-				   &ip[0],&ip[1],&ip[2],&ip[3],&ip[4],&ip[5],&ip[6],&ip[7])!=8)
+			if (sscanf(ptr, "%hu:%hu:%hu:%hu:%hu:%hu:%hu:%hu",
+				   &ip[0], &ip[1], &ip[2], &ip[3],
+				   &ip[4], &ip[5], &ip[6], &ip[7]) != 8)
 				goto not_found;
 			*ptr++ = ip[0];
 			*ptr++ = ip[1];
@@ -536,14 +569,15 @@
 		name = stop + 1;
 	}
 
-	if (rec.ksize != ptr-rec.key) {
-		printk("CacheFS: Built key incorrectly %u!=%u\n",rec.ksize,ptr-rec.key);
+	if (rec.ksize != ptr - rec.key) {
+		printk("CacheFS: Built key incorrectly %u!=%u\n",
+		       rec.ksize, ptr - rec.key);
 		ret = -EIO;
 		goto error;
 	}
 
 	if (stop != nend) {
-		printk("CacheFS: Overran name %p!=%p\n",stop,nend);
+		printk("CacheFS: Overran name %p!=%p\n", stop, nend);
 		ret = -EIO;
 		goto error;
 	}
@@ -551,27 +585,27 @@
 #if 0
 	{ /* dump the key */
 		int loop;
-		for (loop=0; loop<rec.ksize; loop++)
-			printk("%02x",rec.key[loop]);
+		for (loop = 0; loop < rec.ksize; loop++)
+			printk("%02x", rec.key[loop]);
 		printk("\n");
 	}
 #endif
 
 	/* search the FSDEF index */
-	file_ra_state_init(&ra,dir->vfs_inode.i_mapping);
+	file_ra_state_init(&ra, dir->vfs_inode.i_mapping);
 
 	pos = 0;
 
 	desc.written	= 0;
 	desc.count	= dir->vfs_inode.i_size;
-	desc.buf	= (char*) &rec;
+	desc.buf	= (char *) &rec;
 	desc.error	= 0;
 
-	do_generic_mapping_read(dir->vfs_inode.i_mapping,&ra,NULL,
-				&pos,&desc,cachefs_lookup_actor);
+	do_generic_mapping_read(dir->vfs_inode.i_mapping, &ra, NULL, &pos,
+				&desc, cachefs_lookup_actor);
 
 	ret = desc.error;
-	if (ret<0)
+	if (ret < 0)
 		goto error;
 	ino = rec.ino;
 	if (ino)
@@ -579,23 +613,24 @@
  not_found:
 	ret = -ENOENT;
  error:
-	if (rec.key) free_page((unsigned long) rec.key);
-	_leave(" = %d",ret);
+	if (rec.key)
+		free_page((unsigned long) rec.key);
+	_leave(" = %d", ret);
 	return ERR_PTR(ret);
 
 	/* get the inode */
  get_free:
 	free_page((unsigned long) rec.key);
  get:
-	ret = cachefs_iget(dir->vfs_inode.i_sb->s_fs_info,ino,&target);
-	if (ret<0) {
-		_leave(" = %d",ret);
+	ret = cachefs_iget(dir->vfs_inode.i_sb->s_fs_info, ino, &target);
+	if (ret < 0) {
+		_leave(" = %d", ret);
 		return ERR_PTR(ret);
 	}
 
 	/* instantiate the dentry */
  instantiate:
-	d_add(dentry,&target->vfs_inode);
+	d_add(dentry, &target->vfs_inode);
 	_leave(" = NULL");
 	return NULL;
 } /* end cachefs_root_lookup() */
@@ -613,7 +648,7 @@
 	unsigned long flags;
 	int ret;
 
-	_enter("{%lx},{%s,%p}",dir->i_ino,dentry->d_name.name,dentry->d_inode);
+	_enter("{%lx},{%s,%p}", dir->i_ino, dentry->d_name.name, dentry->d_inode);
 
 	if (!dentry->d_inode) {
 		printk("&&& no inode &&&\n");
@@ -624,7 +659,7 @@
 	inode = CACHEFS_FS_I(dentry->d_inode);
 
 	/* mark for reclamation under journalling */
-	trans = cachefs_trans_alloc(super,GFP_KERNEL);
+	trans = cachefs_trans_alloc(super, GFP_KERNEL);
 	if (!trans) {
 		_leave(" = -ENOMEM");
 		return -ENOMEM;
@@ -633,12 +668,12 @@
 	trans->jentry->mark	= CACHEFS_ONDISC_UJNL_INODE_MARK_RECLAIM;
 	trans->jentry->ino	= inode->vfs_inode.i_ino;
 
-	cachefs_trans_affects_inode(trans,inode);
+	cachefs_trans_affects_inode(trans, inode);
 
 	ret = cachefs_trans_mark(trans);
-	if (ret<0) {
+	if (ret < 0) {
 		cachefs_trans_put(trans);
-		_leave(" = %d",ret);
+		_leave(" = %d", ret);
 		return ret;
 	}
 
@@ -650,19 +685,24 @@
 	cachefs_trans_commit(trans);
 
 	/* add to the immediate-reclaim table if possible */
-	spin_lock_irqsave(&super->rcm_lock,flags);
+	spin_lock_irqsave(&super->rcm_lock, flags);
 
-	if (CIRC_SPACE(super->rcm_imm_head,super->rcm_imm_tail,CACHEFS_RCM_IMM_BUFSIZE)>0) {
-		super->rcm_imm_buf[super->rcm_imm_head] = inode->vfs_inode.i_ino;
-		super->rcm_imm_head = (super->rcm_imm_head+1) & (CACHEFS_RCM_IMM_BUFSIZE-1);
+	if (CIRC_SPACE(super->rcm_imm_head,
+		       super->rcm_imm_tail,
+		       CACHEFS_RCM_IMM_BUFSIZE) > 0) {
+		super->rcm_imm_buf[super->rcm_imm_head] =
+			inode->vfs_inode.i_ino;
+		super->rcm_imm_head =
+			(super->rcm_imm_head + 1) &
+			(CACHEFS_RCM_IMM_BUFSIZE - 1);
 	}
 	else {
-		set_bit(CACHEFS_SUPER_RCM_IMM_SCAN,&super->flags);
+		set_bit(CACHEFS_SUPER_RCM_IMM_SCAN, &super->flags);
 	}
 
-	spin_unlock_irqrestore(&super->rcm_lock,flags);
+	spin_unlock_irqrestore(&super->rcm_lock, flags);
 
-	set_bit(CACHEFS_SUPER_DO_RECLAIM,&super->flags);
+	set_bit(CACHEFS_SUPER_DO_RECLAIM, &super->flags);
 	wake_up(&super->dmn_sleepq);
 
 	_leave(" = 0");

Index: recycling.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/recycling.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- recycling.c	11 Jun 2003 11:59:52 -0000	1.22
+++ recycling.c	4 Jul 2003 09:04:43 -0000	1.23
@@ -42,7 +42,7 @@
 	char used_unready_node = 0;
 	int ret;
 
-	_enter(",%u,%u,%u",bix,upblock,upentry);
+	_enter(",%u,%u,%u", bix, upblock, upentry);
 
 	/* select the block */
 	if (!bix) {
@@ -53,53 +53,56 @@
 		used_unready_node = 1;
 	}
 
-	_debug("begin new recycling on block %x",bix);
+	_debug("begin new recycling on block %x", bix);
 
 	/* mirror the block in memory */
-	ret = cachefs_block_read(super,NULL,bix,1,&block,&page);
-	if (ret<0) {
-		printk("kcachefsd: Failed to get page: %d\n",ret);
-		_leave(" = %d",ret);
-		return ret;
+	ret = cachefs_block_read(super, NULL, bix, 1, &block, &page);
+	if (ret < 0) {
+		printk("kcachefsd: Failed to get page: %d\n", ret);
+		_leave(" = %d", ret);
+		return  ret;
 	}
 
 	/* journal what we're going to do */
 	ret = -ENOMEM;
-	trans = cachefs_trans_alloc(super,GFP_KERNEL);
+	trans = cachefs_trans_alloc(super, GFP_KERNEL);
 	if (!trans)
 		goto error_rel_block;
 
-	cachefs_trans_affects_block(trans,block,0,PAGE_SIZE);
+	cachefs_trans_affects_block(trans, block, 0, PAGE_SIZE);
 
 	if (used_unready_node) {
-		/* need to update the superblock too if we've consumed an unready block */
+		/* need to update the superblock too if we've consumed an
+		 * unready block */
 		cachefs_trans_affects_super(trans);
 	}
 
 	trans->jentry->mark	= CACHEFS_ONDISC_UJNL_RECYC_BEGIN_NEW;
 	trans->jentry->block	= bix;
 	trans->jentry->auxblock	= super->recycle_cur;
-	trans->jentry->pgnum	= super->layout->bix_unready + used_unready_node;
 	trans->jentry->upblock	= upblock;
 	trans->jentry->upentry	= upentry;
 
+	trans->jentry->pgnum =
+		super->layout->bix_unready + used_unready_node;
+
 	/* mark the beginning of the operation */
 	ret = cachefs_trans_mark(trans);
 	if (ret<0)
 		goto error_rel_trans;
 
 	/* initialise the page */
-	cachefs_block_modify(super,block,&page);
+	cachefs_block_modify(super, block, &page);
 
-	node = (struct cachefs_ondisc_free_node*) kmap(page);
+	node = (struct cachefs_ondisc_free_node *) kmap(page);
 	node->next = super->recycle_cur;
 	node->count = super->recycle_cur_n;
 	kunmap(page);
 
 	super->recycle_cur	= bix;
 	super->recycle_room	= CACHEFS_ONDISC_LEAVES_PER_FREE_NODE;
-	page	= xchg(&super->recycle_node,page);
-	block	= xchg(&super->recycle_block,block);
+	page	= xchg(&super->recycle_node, page);
+	block	= xchg(&super->recycle_block, block);
 
 	if (used_unready_node)
 		super->layout->bix_unready++;
@@ -107,11 +110,8 @@
 	/* go do it */
 	cachefs_trans_commit(trans);
 
-	if (block) cachefs_block_put(block);
-	if (page) {
-		dbgpgfree(page);
-		page_cache_release(page);
-	}
+	cachefs_block_put(block);
+	cachefs_put_page(page);
 
 	_leave(" = 0");
 	return 0;
@@ -120,7 +120,7 @@
 	cachefs_trans_put(trans);
  error_rel_block:
 	cachefs_block_put(block);
-	_leave(" = %d",ret);
+	_leave(" = %d", ret);
 	return ret;
 } /* end cachefs_recycle_begin_new_node() */
 
@@ -138,29 +138,29 @@
 
 	_enter("");
 
-	/* if there's no room in the current front node of recycling, then consume the next unready
-	 * block to set up a new one
+	/* if there's no room in the current front node of recycling, then
+	 * consume the next unready block to set up a new one
 	 */
-	if (super->recycle_room==0)
-		cachefs_recycle_begin_new_node(super,0,0,0);
+	if (super->recycle_room == 0)
+		cachefs_recycle_begin_new_node(super, 0, 0, 0);
 
 	qty = super->layout->bix_end - super->layout->bix_unready;
-	if (qty==0) {
+	if (qty == 0) {
 		_leave("");
 		return;
 	}
 
-	if (qty>super->recycle_room)
+	if (qty > super->recycle_room)
 		qty = super->recycle_room;
 
 	/* journal what we're going to do */
-	trans = cachefs_trans_alloc(super,GFP_KERNEL);
+	trans = cachefs_trans_alloc(super, GFP_KERNEL);
 	if (!trans) {
 		_leave(" [ENOMEM]");
 		return;
 	}
 
-	cachefs_trans_affects_block(trans,super->recycle_block,0,PAGE_SIZE);
+	cachefs_trans_affects_block(trans, super->recycle_block, 0, PAGE_SIZE);
 	cachefs_trans_affects_super(trans);
 
 	trans->jentry->mark	= CACHEFS_ONDISC_UJNL_RECYC_MAKEREADY;
@@ -170,24 +170,26 @@
 	trans->jentry->count	= qty;
 
 	ret = cachefs_trans_mark(trans);
-	if (ret<0) {
+	if (ret < 0) {
 		cachefs_trans_put(trans);
 		_leave(" [ENOMEM]");
 		return;
 	}
 
-	cachefs_block_modify(super,super->recycle_block,&super->recycle_node);
+	cachefs_block_modify(super, super->recycle_block,
+			     &super->recycle_node);
 
 	super->recycle_cur_n += qty;
 
 	/* transfer a number of nodes to the recycling block */
-	node = (struct cachefs_ondisc_free_node*) kmap(super->recycle_node);
+	node = (struct cachefs_ondisc_free_node *) kmap(super->recycle_node);
 	pbix = node->leaves;
 
-	for (loop=0; loop<qty; loop++) {
-		while (*pbix) pbix++;
+	for (loop = 0; loop < qty; loop++) {
+		while (*pbix)
+			pbix++;
 
-		if (!((unsigned)pbix & (~PAGE_MASK & ~3))) BUG();
+		BUG_ON(!((unsigned) pbix & (~PAGE_MASK & ~3)));
 
 		*pbix = super->layout->bix_unready + loop;
 	}
@@ -198,7 +200,7 @@
 	super->layout->bix_unready += qty;
 	super->recycle_room -= qty;
 
-	if (super->recycle_room==0)
+	if (super->recycle_room == 0)
 		super->recycle_cur_n++;
 
 	cachefs_trans_commit(trans);
@@ -227,8 +229,9 @@
 		return;
 	}
 
-	/* if the front recycling node is saturated, then transfer the entire stack */
-	if (super->recycle_room==0) {
+	/* if the front recycling node is saturated, then transfer the entire
+	 * stack */
+	if (super->recycle_room == 0) {
 		kdebug("transfer entire stack");
 		allocTOS = super->recycle_cur;
 		cur_n	= super->recycle_cur_n;
@@ -236,7 +239,7 @@
 		page	= super->recycle_node;
 
 		/* mark the journal to begin the transfer */
-		trans = cachefs_trans_alloc(super,GFP_KERNEL);
+		trans = cachefs_trans_alloc(super, GFP_KERNEL);
 		if (!trans) {
 			_leave(" [ENOMEM]");
 			return;
@@ -246,9 +249,9 @@
 		trans->jentry->block	= allocTOS;
 
 		ret = cachefs_trans_mark(trans);
-		if (ret<0) {
-			printk("CacheFS: failed to mark ujnl: %d\n",ret);
-			_leave(" [error %d]",ret);
+		if (ret < 0) {
+			printk("CacheFS: failed to mark ujnl: %d\n", ret);
+			_leave(" [error %d]", ret);
 			return;
 		}
 
@@ -260,26 +263,28 @@
 	/* otherwise transfer from the second-in-line if there is one */
 	else {
 		kdebug("transfer 2OS+ of stack");
-		node = (struct cachefs_ondisc_free_node *) kmap(super->recycle_node);
+		node = (struct cachefs_ondisc_free_node *)
+			kmap(super->recycle_node);
 		allocTOS = node->next;
 		kunmap(super->recycle_node);
 
 		cur_n = super->recycle_cur_n - super->recycle_room;
 
-		if (allocTOS==0) {
+		if (allocTOS == 0) {
 			_leave(" [recyc stack almost empty]");
 			return;
 		}
 
-		ret = cachefs_block_read(super,NULL,allocTOS,0,&block,&page);
-		if (ret<0) {
-			printk("CacheFS: failed to read page: %d\n",ret);
-			_leave(" [error %d]",ret);
+		ret = cachefs_block_read(super, NULL, allocTOS, 0,
+					 &block, &page);
+		if (ret < 0) {
+			printk("CacheFS: failed to read page: %d\n", ret);
+			_leave(" [error %d]", ret);
 			return;
 		}
 
 		/* mark the journal to begin the transfer */
-		trans = cachefs_trans_alloc(super,GFP_KERNEL);
+		trans = cachefs_trans_alloc(super, GFP_KERNEL);
 		if (!trans) {
 			cachefs_block_put(block);
 			page_cache_release(page);
@@ -287,33 +292,35 @@
 			return;
 		}
 
-		cachefs_trans_affects_block(trans,super->recycle_block,0,PAGE_SIZE);
+		cachefs_trans_affects_block(trans, super->recycle_block, 0,
+					    PAGE_SIZE);
 
 		trans->jentry->mark	= CACHEFS_ONDISC_UJNL_RECYC_TRANSFER;
 		trans->jentry->block	= allocTOS;
 		trans->jentry->upblock	= super->recycle_cur;
 
 		ret = cachefs_trans_mark(trans);
-		if (ret<0) {
-			printk("CacheFS: failed to mark ujnl: %d\n",ret);
+		if (ret < 0) {
+			printk("CacheFS: failed to mark ujnl: %d\n", ret);
 			dbgpgfree(page);
 			page_cache_release(page);
 			cachefs_block_put(block);
 			cachefs_trans_put(trans);
-			_leave(" [error %d]",ret);
+			_leave(" [error %d]", ret);
 			return;
 		}
 
 		/* break the pointer from the recycling stack TOS to the 2OS */
-		node = (struct cachefs_ondisc_free_node *) kmap(super->recycle_node);
+		node = (struct cachefs_ondisc_free_node *)
+			kmap(super->recycle_node);
 		node->next	= 0;
 		node->count	= 0;
 		kunmap(super->recycle_node);
 
-		super->recycle_cur_n	= super->recycle_room;
+		super->recycle_cur_n = super->recycle_room;
 	}
 
-	set_bit(CACHEFS_BLOCK_CRITICAL,&block->flags);
+	set_bit(CACHEFS_BLOCK_CRITICAL, &block->flags);
 
 	super->alloc_cur	= allocTOS;
 	super->alloc_cur_n	= cur_n;
@@ -324,8 +331,7 @@
 	cachefs_trans_commit(trans);
 
 	/* force a batch to be written */
-	set_bit(CACHEFS_SUPER_BATCH_TIMER,&super->flags);
-
+	set_bit(CACHEFS_SUPER_BATCH_TIMER, &super->flags);
 	wake_up(&super->alloc_wq);
 
 	_leave("");
@@ -333,8 +339,8 @@
 
 /*****************************************************************************/
 /*
- * recycle the dependents of the block currently in the recycling bin and then recycle the block
- * itself
+ * recycle the dependents of the block currently in the recycling bin and then
+ * recycle the block itself
  */
 static void cachefs_recycle_pointer_array(struct cachefs_super *super)
 {
@@ -347,15 +353,20 @@
 	int ret;
 
 	kenter("{room=%u block=%u:%hu-%hu},",
-	       super->recycle_room,super->rcm_block,super->rcm_ptrnext,super->rcm_ptrstop);
+	       super->recycle_room,
+	       super->rcm_block,
+	       super->rcm_ptrnext,
+	       super->rcm_ptrstop);
 
-	max = super->sb->s_blocksize - sizeof(struct cachefs_ondisc_update_journal);
+	max = super->sb->s_blocksize;
+	max -= sizeof(struct cachefs_ondisc_update_journal);
 	max /= sizeof(cachefs_blockix_t);
 
 	/* load the pointer block page */
-	ret = cachefs_block_read(super,NULL,super->rcm_block,0,NULL,&page);
-	if (ret<0) {
-		kleave(" [error %d]",ret);
+	ret = cachefs_block_read(super, NULL, super->rcm_block, 0,
+				 NULL, &page);
+	if (ret < 0) {
+		kleave(" [error %d]", ret);
 		return;
 	}
 
@@ -364,7 +375,7 @@
 	indirect = (cachefs_blockix_t*) kmap(page);
 
 	/* find an occupied pointer */
-	for (src=super->rcm_ptrnext; src<super->rcm_ptrstop; src++)
+	for (src = super->rcm_ptrnext; src < super->rcm_ptrstop; src++)
 		if (indirect[src])
 			goto found;
 
@@ -373,21 +384,22 @@
 
  found:
 	/* make sure there's a recycling block with space available */
-	if (super->recycle_room==0) {
-		/* recycle the first dependent page as the new recycling node */
+	if (super->recycle_room == 0) {
+		/* recycle the first dependent page as the new recycling
+		 * node */
 		super->rcm_ptrnext = src;
-		ret = cachefs_recycle_begin_new_node(super,indirect[src],super->rcm_block,src);
+		ret = cachefs_recycle_begin_new_node(super, indirect[src],
+						     super->rcm_block, src);
 		goto out;
 	}
 
-	/* journal what we're going to do */
-	trans = cachefs_trans_alloc(super,GFP_KERNEL);
+	trans = cachefs_trans_alloc(super, GFP_KERNEL);
 	if (!trans)
 		goto out;
 
-	cachefs_trans_affects_block(trans,super->recycle_block,0,PAGE_SIZE);
+	cachefs_trans_affects_block(trans, super->recycle_block, 0, PAGE_SIZE);
 
-	limit = min(super->recycle_room,max);
+	limit = min(super->recycle_room, max);
 	dst = CACHEFS_ONDISC_LEAVES_PER_FREE_NODE - super->recycle_room;
 
 	trans->jentry->mark	= CACHEFS_ONDISC_UJNL_RECYC_SCAVENGE;
@@ -399,13 +411,15 @@
 	/* transfer the pointers into the journal entry first */
 	jeptr = trans->jentry->rcyptrs;
 	count = 0;
-	while (count<limit && src<super->rcm_ptrstop) {
+	while (count < limit && src < super->rcm_ptrstop) {
 		if (indirect[src]) {
 			jeptr[count] = indirect[src];
 			count++;
 
-			if (cachefs_block_find(super,jeptr[count],&block) == 0) {
-				clear_bit(CACHEFS_BLOCK_NETFSDATA,&block->flags);
+			if (cachefs_block_find(super, jeptr[count],
+					       &block) == 0) {
+				clear_bit(CACHEFS_BLOCK_NETFSDATA,
+					  &block->flags);
 				cachefs_block_put(block);
 			}
 		}
@@ -416,23 +430,26 @@
 	trans->jentry->count = count;
 
 	ret = cachefs_trans_mark(trans);
-	if (ret<0) {
-		printk("kcachefsd: Failed to mark journal: %d\n",ret);
+	if (ret < 0) {
+		printk("kcachefsd: Failed to mark journal: %d\n", ret);
 		cachefs_trans_put(trans);
 		goto out;
 	}
 
 	super->recycle_room -= count;
 	super->recycle_cur_n += count;
-	if (super->recycle_room==0)
+	if (super->recycle_room == 0)
 		super->recycle_cur_n++;
 
 	/* transfer from the jentry to the recycling block */
-	cachefs_block_modify(super,super->recycle_block,&super->recycle_node);
+	cachefs_block_modify(super, super->recycle_block,
+			     &super->recycle_node);
 
-	node = (struct cachefs_ondisc_free_node*) kmap(super->recycle_node);
+	node = (struct cachefs_ondisc_free_node *) kmap(super->recycle_node);
 
-	memcpy(&node->leaves[dst],trans->jentry->rcyptrs,count*sizeof(cachefs_blockix_t));
+	memcpy(&node->leaves[dst],
+	       trans->jentry->rcyptrs,
+	       count * sizeof(cachefs_blockix_t));
 
 	kunmap(super->recycle_node);
 
@@ -446,7 +463,7 @@
 	dbgpgfree(page);
 	page_cache_release(page);
 
-	kleave(" [error %d]",ret);
+	kleave(" [error %d]", ret);
 } /* end cachefs_recycle_pointer_array() */
 
 /*****************************************************************************/
@@ -468,7 +485,7 @@
 	unsigned iino, ixentry, offset;
 	int ret;
 
-	kenter("{%u}",super->rcm_ino);
+	kenter("{%u}", super->rcm_ino);
 
 	/* find the parent index entry */
 	metadata = cachefs_metadata_preread(super->rcm_inode);
@@ -477,12 +494,13 @@
 	cachefs_metadata_postread(super->rcm_inode);
 
 	if (iino) {
-		ret = cachefs_iget(super,iino,&iinode);
+		ret = cachefs_iget(super, iino, &iinode);
 		if (ret<0)
 			goto error;
 
-		ret = cachefs_get_page(iinode,ixentry/iinode->index_epp,&ixpage);
-		if (ret<0)
+		ret = cachefs_get_page(iinode, ixentry / iinode->index_epp,
+				       &ixpage);
+		if (ret < 0)
 			goto error;
 
 		offset = (ixentry % iinode->index_epp) * iinode->index_esize;
@@ -494,7 +512,7 @@
 
 	/* do the release under journalling */
 	ret = -ENOMEM;
-	trans = cachefs_trans_alloc(super,GFP_KERNEL);
+	trans = cachefs_trans_alloc(super, GFP_KERNEL);
 	if (!trans)
 		goto error;
 
@@ -502,43 +520,49 @@
 	trans->jentry->index	= iino;
 	trans->jentry->ixentry	= ixentry;
 	trans->jentry->ino	= super->rcm_ino;
-	trans->jentry->size	= iinode ? iinode->vfs_inode.i_size : 0;
-	trans->jentry->pgnum	= ixpage ? ixpage->index : 0;
-	trans->jentry->block	= ixpage ? __cachefs_get_page_block(ixpage)->bix : 0;
 	trans->jentry->entry	= offset;
-	trans->jentry->count	= iinode ? iinode->index_esize : 0;
 
-	metadata = cachefs_metadata_preread(super->imetadata);
-	trans->jentry->auxblock	= metadata->freelink;
-	cachefs_metadata_postread(super->imetadata);
+	if (ixpage) {
+		trans->jentry->pgnum = ixpage->index;
+		trans->jentry->block = __cachefs_get_page_block(ixpage)->bix;
+	}
 
 	if (iinode) {
+		trans->jentry->size  = iinode->vfs_inode.i_size;
+		trans->jentry->count = iinode->index_esize;
+
 		metadata = cachefs_metadata_preread(iinode);
-		trans->jentry->upblock	= metadata->freelink;
+		trans->jentry->upblock = metadata->freelink;
 		cachefs_metadata_postread(iinode);
 
-		cachefs_trans_affects_page(trans,__cachefs_page_get_private(ixpage),offset,
+		cachefs_trans_affects_page(trans,
+					   __cachefs_page_get_private(ixpage),
+					   offset,
 					   iinode->index_esize);
-		cachefs_trans_affects_inode(trans,iinode);
+
+		cachefs_trans_affects_inode(trans, iinode);
 	}
 
-	cachefs_trans_affects_inode(trans,super->rcm_inode);
-	cachefs_trans_affects_inode(trans,super->imetadata);
+	metadata = cachefs_metadata_preread(super->imetadata);
+	trans->jentry->auxblock	= metadata->freelink;
+	cachefs_metadata_postread(super->imetadata);
+
+	cachefs_trans_affects_inode(trans, super->rcm_inode);
+	cachefs_trans_affects_inode(trans, super->imetadata);
 
 	ret = cachefs_trans_mark(trans);
-	if (ret<0)
+	if (ret < 0)
 		goto error;
 
-	if (iinode)
-		cachefs_page_modify(super,&ixpage);
-
 	/* free up the parent index entry */
 	if (iinode) {
+		cachefs_page_modify(super, &ixpage);
+
 		xent = kmap(ixpage) + offset;
 		xent->state		= CACHEFS_ONDISC_INDEX_FREE;
 		xent->ino		= 0;
 		xent->freelink[0]	= trans->jentry->upblock;
-		memset(xent->data,0,iinode->index_dsize);
+		memset(xent->data, 0, iinode->index_dsize);
 		kunmap(ixpage);
 
 		/* modify the index inode metadata entry */
@@ -549,7 +573,7 @@
 
 	/* clear the inode definition */
 	metadata = cachefs_metadata_prewrite(super->rcm_inode);
-	memset(metadata,0,sizeof(super->imetadata->index_esize));
+	memset(metadata, 0, sizeof(super->imetadata->index_esize));
 
 	metadata->header.state	= CACHEFS_ONDISC_INDEX_FREE;
 	metadata->freelink	= trans->jentry->auxblock;
@@ -571,7 +595,7 @@
 	cachefs_put_page(ixpage);
 	cachefs_iput(iinode);
 
-	kleave(" = %d",ret);
+	kleave(" = %d", ret);
 	return ret;
 } /* end cachefs_recycle_reclaim_inode_metadata() */
 
@@ -607,12 +631,12 @@
 	const unsigned N = PAGE_SIZE / sizeof(cachefs_blockix_t);
 
 	kenter("{%u,%u,%u:%hu-%hu}",
-	       super->rcm_ino,super->rcm_indirect,super->rcm_block,
-	       super->rcm_ptrnext,super->rcm_ptrstop);
+	       super->rcm_ino, super->rcm_indirect, super->rcm_block,
+	       super->rcm_ptrnext, super->rcm_ptrstop);
 
 	BUG_ON(!super->rcm_ino);
 
-	if (super->rcm_ptrnext==super->rcm_ptrstop && super->rcm_curpage) {
+	if (super->rcm_ptrnext == super->rcm_ptrstop && super->rcm_curpage) {
 		put_page(super->rcm_curpage);
 		super->rcm_curpage = NULL;
 	}
@@ -629,10 +653,10 @@
 
 	/* clear out then entries in an index */
 	if (indirect == 1) {
-		if (super->rcm_inode->index_dsize==0)
+		if (super->rcm_inode->index_dsize == 0)
 			goto again;
 
-		if (cachefs_index_zap(super)<0)
+		if (cachefs_index_zap(super) < 0)
 			goto error2;
 		goto again;
 	}
@@ -649,27 +673,27 @@
 	}
 
 	/* deal with double indirection */
-	if (indirect <= 3+N) {
+	if (indirect <= 3 + N) {
 		metadata = cachefs_metadata_preread(super->rcm_inode);
 		bix = metadata->double_indirect;
 		cachefs_metadata_postread(super->rcm_inode);
 
 		if (!bix) {
-			indirect = 3+N;
+			indirect = 3 + N;
 			goto again;
 		}
 
-		ret = cachefs_block_read(super,NULL,bix,0,NULL,&dpage);
-		if (ret<0)
+		ret = cachefs_block_read(super, NULL, bix, 0, NULL, &dpage);
+		if (ret < 0)
 			goto error;
 
 		/* start processing a double indirect subblock */
-		if (indirect <= 3+N-1) {
+		if (indirect <= 3 + N - 1) {
 			wait_on_page_locked(dpage);
 
 			bix = 0;
 			pbix = kmap(dpage);
-			for (loop=indirect-2; loop<N; loop++) {
+			for (loop = indirect - 2; loop < N; loop++) {
 				bix = pbix[loop];
 				if (bix)
 					break;
@@ -690,13 +714,15 @@
 	}
 
 	/* reclaim all the block pointers in the inode metadata record */
-	if (indirect == 3+N+1) {
+	if (indirect == 3 + N + 1) {
 		bix	= super->rcm_inode->metadata->bix;
 		next	= super->rcm_inode->metadata_offset;
-		next	+= offsetof(struct cachefs_ondisc_metadata,triple_indirect);
+		next	+= offsetof(struct cachefs_ondisc_metadata,
+				    triple_indirect);
 		next	/= sizeof(cachefs_blockix_t);
 
-		stop	= super->rcm_inode->metadata_offset + super->layout->metadata_size;
+		stop	= super->rcm_inode->metadata_offset;
+		stop	+= super->layout->metadata_size;
 		stop	/= sizeof(cachefs_blockix_t);
 
 		down_read(&super->rcm_inode->metadata_sem);
@@ -707,7 +733,7 @@
 	}
 
 	/* reclaim the inode itself */
-	if (cachefs_recycle_reclaim_inode_metadata(super)<0) {
+	if (cachefs_recycle_reclaim_inode_metadata(super) < 0) {
 		indirect--;
 		bix	= 0;
 		next	= 0;
@@ -728,8 +754,8 @@
 	return;
 
  pointer_array:
-	ret = cachefs_block_read(super,NULL,bix,0,NULL,&page);
-	if (ret<0)
+	ret = cachefs_block_read(super, NULL, bix, 0, NULL, &page);
+	if (ret < 0)
 		goto error;
 
  pointer_array2:
@@ -745,13 +771,13 @@
 	return;
 
  error:
-	if (ret==-EIO) {
+	if (ret == -EIO) {
 		/* just sweep any buggy block under the rug */
-		printk("CacheFS: discarding block %u due to I/O error\n",bix);
+		printk("CacheFS: discarding block %u due to I/O error\n", bix);
 		goto again;
 	}
  error2:
-	kleave(" [error %d]",ret);
+	kleave(" [error %d]", ret);
 	goto set;
 } /* end cachefs_recycle_reclaim_inode() */
 
@@ -765,16 +791,17 @@
 	int ret;
 
 	kenter("{%u,%u,%u:%hu-%hu}",
-	       super->rcm_ino,super->rcm_indirect,super->rcm_block,
-	       super->rcm_ptrnext,super->rcm_ptrstop);
+	       super->rcm_ino, super->rcm_indirect, super->rcm_block,
+	       super->rcm_ptrnext, super->rcm_ptrstop);
 
 	/* recycle the next chunk of an inode we're busy reclaiming */
 	if (super->rcm_ino) {
 		kdebug("do reclaim");
 		if (!super->rcm_inode) {
-			ret = cachefs_iget(super,super->rcm_ino,&super->rcm_inode);
-			if (ret<0) {
-				kleave(" [error %d]",ret);
+			ret = cachefs_iget(super, super->rcm_ino,
+					   &super->rcm_inode);
+			if (ret < 0) {
+				kleave(" [error %d]", ret);
 				return;
 			}
 		}
@@ -786,19 +813,20 @@
 
 	/* see if there's an inode we can start reclaiming */
 	if (super->rcm_imm_head != super->rcm_imm_tail) {
-		kdebug("begin reclaim {%u-%u}",super->rcm_imm_tail,super->rcm_imm_head);
-		trans = cachefs_trans_alloc(super,GFP_KERNEL);
+		kdebug("begin reclaim {%u-%u}",
+		       super->rcm_imm_tail, super->rcm_imm_head);
+		trans = cachefs_trans_alloc(super, GFP_KERNEL);
 		if (!trans) {
 			kdebug("[ENOMEM]");
 			goto done;
 		}
 
-		trans->jentry->ino	= super->rcm_imm_buf[super->rcm_imm_tail];
-		trans->jentry->mark   	= CACHEFS_ONDISC_UJNL_INODE_RECLAIMING;
+		trans->jentry->ino  = super->rcm_imm_buf[super->rcm_imm_tail];
+		trans->jentry->mark = CACHEFS_ONDISC_UJNL_INODE_RECLAIMING;
 
 		ret = cachefs_trans_mark(trans);
 		if (ret<0) {
-			kdebug("[error %d]",ret);
+			kdebug("[error %d]", ret);
 			cachefs_trans_put(trans);
 			goto done;
 		}
@@ -811,7 +839,8 @@
 
 		cachefs_trans_commit(trans);
 
-		super->rcm_imm_tail = (super->rcm_imm_tail+1) & (CACHEFS_RCM_IMM_BUFSIZE-1);
+		super->rcm_imm_tail =
+			(super->rcm_imm_tail+1) & (CACHEFS_RCM_IMM_BUFSIZE-1);
 		goto done;
 	}
 
@@ -820,7 +849,7 @@
 	if (super->rcm_ino ||
 	    super->rcm_imm_head != super->rcm_imm_tail
 	    )
-		set_bit(CACHEFS_SUPER_DO_RECLAIM,&super->flags);
+		set_bit(CACHEFS_SUPER_DO_RECLAIM, &super->flags);
 	kleave("");
 	return;
 } /* end cachefs_recycle_reclaim() */
@@ -845,7 +874,9 @@
 
 	/* we can access the next pointer without a lock because we know we're
 	 * the only ones going to change it now */
-	vjentry = list_entry(super->vjnl_unallocq.next,struct cachefs_vj_entry,link);
+	vjentry = list_entry(super->vjnl_unallocq.next,
+			     struct cachefs_vj_entry,
+			     link);
 
 	ret = -ENOMEM;
 	trans = cachefs_trans_alloc(super,GFP_KERNEL);
@@ -861,51 +892,57 @@
 	trans->jentry->auxblock	= super->recycle_cur;
 	trans->jentry->auxentry	= ~0;
 
-	ret = cachefs_block_read(super,NULL,vjentry->upblock,1,&upblock,&uppage);
-	if (ret<0)
+	ret = cachefs_block_read(super, NULL, vjentry->upblock, 1,
+				 &upblock, &uppage);
+	if (ret < 0)
 		goto error_free;
 
-	cachefs_trans_affects_block(trans,upblock,vjentry->upentry,sizeof(cachefs_blockix_t));
+	cachefs_trans_affects_block(trans, upblock, vjentry->upentry,
+				    sizeof(cachefs_blockix_t));
 
-	cachefs_trans_affects_block(trans,vjentry->vblock,vjentry->ventry,
-				    sizeof(struct cachefs_ondisc_validity_journal));
+	cachefs_trans_affects_block(
+		trans, vjentry->vblock, vjentry->ventry,
+		sizeof(struct cachefs_ondisc_validity_journal));
 
-	if (cachefs_block_find(super,vjentry->bix,&block) == 0) {
-		clear_bit(CACHEFS_BLOCK_NETFSDATA,&block->flags);
+	if (cachefs_block_find(super, vjentry->bix, &block) == 0) {
+		clear_bit(CACHEFS_BLOCK_NETFSDATA, &block->flags);
 		cachefs_block_put(block);
 	}
 
-	if (super->recycle_room==0) {
+	if (super->recycle_room == 0) {
 		/* we have to generate a new recycling node */
-		ret = cachefs_block_read(super,NULL,vjentry->bix,1,&rcyblock,&rcypage);
-		if (ret<0)
+		ret = cachefs_block_read(super, NULL, vjentry->bix, 1,
+					 &rcyblock, &rcypage);
+		if (ret < 0)
 			goto error_free;
 
-		cachefs_trans_affects_block(trans,rcyblock,0,PAGE_SIZE);
+		cachefs_trans_affects_block(trans, rcyblock, 0, PAGE_SIZE);
 	}
 	else {
 		/* we can add into an existing recycling node */
-		cachefs_trans_affects_block(trans,super->recycle_block,0,PAGE_SIZE);
+		cachefs_trans_affects_block(trans, super->recycle_block, 0,
+					    PAGE_SIZE);
 
 		trans->jentry->auxentry	=
-			CACHEFS_ONDISC_LEAVES_PER_FREE_NODE - super->recycle_room;
+			CACHEFS_ONDISC_LEAVES_PER_FREE_NODE -
+			super->recycle_room;
 	}
 
 	/* mark the journal and then make modifications */
 	ret = cachefs_trans_mark(trans);
-	if (ret<0)
+	if (ret < 0)
 		goto error_free;
 
-	cachefs_block_modify(super,vjentry->vblock,&vjentry->vpage);
+	cachefs_block_modify(super, vjentry->vblock, &vjentry->vpage);
 	memset(kmap(vjentry->vpage) + vjentry->ventry, 0,
 	       sizeof(struct cachefs_ondisc_validity_journal));
 	kunmap(vjentry->vpage);
 
-	cachefs_block_modify(super,upblock,&uppage);
+	cachefs_block_modify(super, upblock, &uppage);
 	memset(kmap(uppage) + vjentry->upentry, 0, sizeof(cachefs_blockix_t));
 	kunmap(uppage);
 
-	if (trans->jentry->auxentry==UINT_MAX) {
+	if (trans->jentry->auxentry == UINT_MAX) {
 		/* new recycling node */
 		node = kmap(rcypage);
 		node->next  = super->recycle_cur;
@@ -914,12 +951,13 @@
 
 		super->recycle_cur	= vjentry->bix;
 		super->recycle_room	= CACHEFS_ONDISC_LEAVES_PER_FREE_NODE;
-		rcypage	 = xchg(&super->recycle_node,rcypage);
-		rcyblock = xchg(&super->recycle_block,rcyblock);
+		rcypage	 = xchg(&super->recycle_node, rcypage);
+		rcyblock = xchg(&super->recycle_block, rcyblock);
 	}
 	else {
 		/* add to existing recycling node */
-		cachefs_block_modify(super,super->recycle_block,&super->recycle_node);
+		cachefs_block_modify(super, super->recycle_block,
+				     &super->recycle_node);
 
 		node = kmap(super->recycle_node);
 		node->leaves[trans->jentry->auxentry] = vjentry->bix;
@@ -927,7 +965,7 @@
 
 		super->recycle_room--;
 		super->recycle_cur_n++;
-		if (super->recycle_room==0)
+		if (super->recycle_room == 0)
 			super->recycle_cur_n++;
 	}
 
@@ -937,7 +975,7 @@
 	list_del_init(&vjentry->link);
 	spin_unlock(&super->vjnl_lock);
 
-	cachefs_vj_release(super,vjentry);
+	cachefs_vj_release(super, vjentry);
 	cachefs_put_page(uppage);
 	cachefs_put_page(rcypage);
 	cachefs_block_put(upblock);
@@ -952,13 +990,13 @@
 	cachefs_block_put(rcyblock);
 	cachefs_trans_put(trans);
  error:
-	kleave(" [error %d]",ret);
+	kleave(" [error %d]", ret);
 
 } /* end cachefs_recycle_unallocate_data_block() */
 
 /*****************************************************************************/
 /*
- * 
+ *
  */
 int cachefs_replay_ujnl_recyc_empty_node(struct cachefs_super *super,
 					 struct cachefs_ondisc_update_journal *jentry)
@@ -968,7 +1006,7 @@
 
 /*****************************************************************************/
 /*
- * 
+ *
  */
 int cachefs_replay_ujnl_recyc_begin_new(struct cachefs_super *super,
 					struct cachefs_ondisc_update_journal *jentry)
@@ -978,7 +1016,7 @@
 
 /*****************************************************************************/
 /*
- * 
+ *
  */
 int cachefs_replay_ujnl_recyc_transfer(struct cachefs_super *super,
 				       struct cachefs_ondisc_update_journal *jentry)
@@ -988,7 +1026,7 @@
 
 /*****************************************************************************/
 /*
- * 
+ *
  */
 int cachefs_replay_ujnl_recyc_scavenge(struct cachefs_super *super,
 				       struct cachefs_ondisc_update_journal *jentry)
@@ -998,7 +1036,7 @@
 
 /*****************************************************************************/
 /*
- * 
+ *
  */
 int cachefs_replay_ujnl_recyc_makeready(struct cachefs_super *super,
 					struct cachefs_ondisc_update_journal *jentry)

Index: main.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/main.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- main.c	23 May 2003 12:59:21 -0000	1.15
+++ main.c	4 Jul 2003 09:04:44 -0000	1.16
@@ -39,35 +39,39 @@
 	printk(KERN_INFO "cachefs: general fs caching v0.1 registering.\n");
 
 	ret = kcachefs_jnld_start();
-	if (ret<0)
+	if (ret < 0)
 		goto error;
 
 	/* create ourselves a cookie jar and a block har */
 	ret = -ENOMEM;
-	cachefs_cookie_jar = kmem_cache_create("cachefs_cookie_jar",
-					       sizeof(struct cachefs_cookie),
-					       0,
-					       SLAB_HWCACHE_ALIGN,
-					       cachefs_cookie_init_once,
-					       NULL);
+	cachefs_cookie_jar =
+		kmem_cache_create("cachefs_cookie_jar",
+				  sizeof(struct cachefs_cookie),
+				  0,
+				  SLAB_HWCACHE_ALIGN,
+				  cachefs_cookie_init_once,
+				  NULL);
 	if (!cachefs_cookie_jar) {
-		printk(KERN_NOTICE "CacheFS: Failed to allocate a cookie jar\n");
+		printk(KERN_NOTICE
+		       "CacheFS: Failed to allocate a cookie jar\n");
 		goto error_jnld;
 	}
 
-	cachefs_block_jar = kmem_cache_create("cachefs_block_jar",
-					      sizeof(struct cachefs_block),
-					      0,
-					      SLAB_HWCACHE_ALIGN,
-					      cachefs_block_init_once,
-					      NULL);
+	cachefs_block_jar =
+		kmem_cache_create("cachefs_block_jar",
+				  sizeof(struct cachefs_block),
+				  0,
+				  SLAB_HWCACHE_ALIGN,
+				  cachefs_block_init_once,
+				  NULL);
 	if (!cachefs_block_jar) {
-		printk(KERN_NOTICE "CacheFS: Failed to allocate a block jar\n");
+		printk(KERN_NOTICE
+		       "CacheFS: Failed to allocate a block jar\n");
 		goto error_cookie_jar;
 	}
 
 	ret = cachefs_fs_init();
-	if (ret<0)
+	if (ret < 0)
 		goto error_block_jar;
 
 	return ret;
@@ -79,7 +83,7 @@
  error_jnld:
 	kcachefs_jnld_stop();	
  error:
-	printk(KERN_ERR "cachefs: failed to register: %d\n",ret);
+	printk(KERN_ERR "cachefs: failed to register: %d\n", ret);
 	return ret;
 } /* end cachefs_init() */
 

Index: kcachefsd.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/kcachefsd.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- kcachefsd.c	10 Jun 2003 17:49:49 -0000	1.12
+++ kcachefsd.c	4 Jul 2003 09:04:44 -0000	1.13
@@ -39,16 +39,111 @@
 
 /*****************************************************************************/
 /*
+ * sleep waiting for work
+ */
+static void kcachefsd_sleep(struct cachefs_super *super)
+{
+	DECLARE_WAITQUEUE(myself, current);
+	DECLARE_WAITQUEUE(myself2, current);
+
+	set_current_state(TASK_INTERRUPTIBLE);
+	add_wait_queue(&super->dmn_sleepq, &myself);
+	add_wait_queue(&super->batch_timer_wq, &myself2);
+
+	for (;;) {
+		/* discard pending signals */
+		discard_my_signals();
+
+		/* see if there's work to be done */
+		if (super->dmn_die == 0 &&
+		    (!super->alloc_node ||
+		     super->layout->bix_unready < super->layout->bix_end ||
+		     test_bit(CACHEFS_SUPER_DO_RECLAIM, &super->flags)
+		     ))
+			break;
+
+		if (test_bit(CACHEFS_SUPER_BATCH_TIMER, &super->flags) ||
+		    !list_empty(&super->vjnl_unallocq) ||
+		    !list_empty(&super->vjnl_writtenq)
+		    )
+			break;
+
+		/* deal with the server being asked to die */
+		if (super->dmn_die > 1) {
+			remove_wait_queue(&super->batch_timer_wq, &myself2);
+			remove_wait_queue(&super->dmn_sleepq, &myself);
+			_leave(" [dead]");
+			complete_and_exit(&super->dmn_dead, 0);
+		}
+
+		schedule();
+
+		set_current_state(TASK_INTERRUPTIBLE);
+	}
+
+	remove_wait_queue(&super->batch_timer_wq, &myself2);
+	remove_wait_queue(&super->dmn_sleepq, &myself);
+	set_current_state(TASK_RUNNING);
+} /* end kcachefsd_sleep() */
+
+/*****************************************************************************/
+/*
+ * actually do the work
+ */
+static void kcachefsd_work(struct cachefs_super *super)
+{
+	_debug("@@@ Begin Cache Management");
+
+	if (super->dmn_die)
+		goto dying;
+
+	/* decant the recycling queue */
+	if (test_and_clear_bit(CACHEFS_SUPER_DO_RECLAIM, &super->flags))
+		cachefs_recycle_reclaim(super);
+
+	/* transfer blocks from the unready data if possible */
+	if (super->layout->bix_unready < super->layout->bix_end) {
+		cachefs_recycle_unready_blocks(super);
+
+		if (super->layout->bix_unready == super->layout->bix_end) {
+			printk("CacheFS:"
+			       " all blocks now added to recycling stack\n");
+			cachefs_debug = 1;
+		}
+		else {
+			yield();
+		}
+	}
+
+	/* if there's no next node, then get one */
+	if (!super->alloc_node)
+		cachefs_recycle_transfer_stack(super);
+
+ dying:
+	/* deal with validity journal changes */
+	if (!list_empty(&super->vjnl_unallocq))
+		cachefs_recycle_unallocate_data_block(super);
+
+	if (!list_empty(&super->vjnl_writtenq))
+		cachefs_vj_note_write_completion(super);
+
+	/* write a batch of metadata if it's time to do so */
+	if (test_bit(CACHEFS_SUPER_BATCH_TIMER, &super->flags))
+		cachefs_trans_batch_write(super);
+
+	_debug("@@@ End Cache Management");
+
+} /* end kcachefsd_work() */
+
+/*****************************************************************************/
+/*
  * cache recycling daemon
  */
 int kcachefsd(void *_super)
 {
-	DECLARE_WAITQUEUE(myself,current);
-	DECLARE_WAITQUEUE(myself2,current);
-
 	struct cachefs_super *super = _super;
 
-	printk("CacheFS: Started kcachefsd %d\n",current->pid);
+	printk("CacheFS: Started kcachefsd %d\n", current->pid);
 	super->dmn_task = current;
 
 	daemonize("kcachefsd %02x%02x",
@@ -59,93 +154,17 @@
 
 	/* no signals are of interest */
 	spin_lock_irq(&current->sighand->siglock);
-	siginitsetinv(&current->blocked,0);
+	siginitsetinv(&current->blocked, 0);
 	recalc_sigpending();
 	spin_unlock_irq(&current->sighand->siglock);
 
 	/* loop around looking for things to attend to */
 	for (;;) {
-		set_current_state(TASK_INTERRUPTIBLE);
-		add_wait_queue(&super->dmn_sleepq,&myself);
-		add_wait_queue(&super->batch_timer_wq,&myself2);
-
-		for (;;) {
-			/* discard pending signals */
-			discard_my_signals();
-
-			/* see if there's work to be done */
-			if (super->dmn_die == 0) {
-				if (!super->alloc_node ||
-				    super->layout->bix_unready < super->layout->bix_end ||
-				    test_bit(CACHEFS_SUPER_DO_RECLAIM,&super->flags)
-				    )
-				break;
-			}
-
-			if (test_bit(CACHEFS_SUPER_BATCH_TIMER,&super->flags) ||
-			    !list_empty(&super->vjnl_unallocq) ||
-			    !list_empty(&super->vjnl_writtenq)
-			    )
-				break;
-
-			/* deal with the server being asked to die */
-			if (super->dmn_die > 1) {
-				remove_wait_queue(&super->dmn_sleepq,&myself);
-				_leave("");
-				complete_and_exit(&super->dmn_dead,0);
-			}
-
-			schedule();
-
-			set_current_state(TASK_INTERRUPTIBLE);
-		}
-
-		remove_wait_queue(&super->batch_timer_wq,&myself2);
-		remove_wait_queue(&super->dmn_sleepq,&myself);
-		set_current_state(TASK_RUNNING);
-
-		/* actually do some work */
-		_debug("@@@ Begin Cache Management");
-
-		if (super->dmn_die == 0) {
-			/* decant the recycling queue */
-			if (test_and_clear_bit(CACHEFS_SUPER_DO_RECLAIM,&super->flags))
-				cachefs_recycle_reclaim(super);
-
-			/* transfer blocks from the unready data if possible */
-			if (super->layout->bix_unready<super->layout->bix_end) {
-				cachefs_recycle_unready_blocks(super);
-				if (super->layout->bix_unready==super->layout->bix_end) {
-					printk("CacheFS:"
-					       " all blocks now added to recycling stack\n");
-					cachefs_debug = 1;
-				}
-				else {
-					yield();
-				}
-			}
-
-			/* if there's no next node, then get one */
-			if (!super->alloc_node)
-				cachefs_recycle_transfer_stack(super);
-		}
-
-		/* deal with validity journal changes */
-		if (!list_empty(&super->vjnl_unallocq))
-			cachefs_recycle_unallocate_data_block(super);
-
-		if (!list_empty(&super->vjnl_writtenq))
-			cachefs_vj_note_write_completion(super);
-
-		/* write a batch of metadata if it's time to do so */
-		if (test_bit(CACHEFS_SUPER_BATCH_TIMER,&super->flags))
-			cachefs_trans_batch_write(super);
-
-//		super->dmn_die = 2;
-
-		_debug("@@@ End Cache Management");
-
+		kcachefsd_sleep(super);
+		kcachefsd_work(super);
 		cond_resched();
+
+		// super->dmn_die = 2;
 	}
 
 } /* end kcachefsd() */

Index: kcachefs_jnld.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/kcachefs_jnld.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- kcachefs_jnld.c	21 Mar 2003 14:01:00 -0000	1.5
+++ kcachefs_jnld.c	4 Jul 2003 09:04:44 -0000	1.6
@@ -46,8 +46,8 @@
 {
 	int ret;
 
-	ret = kernel_thread(kcachefs_jnld,NULL,0);
-	if (ret<0)
+	ret = kernel_thread(kcachefs_jnld, NULL, 0);
+	if (ret < 0)
 		return ret;
 
 	wait_for_completion(&kcachefs_jnld_alive);
@@ -74,13 +74,11 @@
  */
 static int kcachefs_jnld(void *arg)
 {
-	DECLARE_WAITQUEUE(myself,current);
-
-//	struct cachefs_super *super;
-//	struct list_head *_p;
 	signed long timo = MAX_SCHEDULE_TIMEOUT;
 
-	printk("CacheFS: Started kcachefs_jnld %d\n",current->pid);
+	DECLARE_WAITQUEUE(myself, current);
+
+	printk("CacheFS: Started kcachefs_jnld %d\n", current->pid);
 
 	daemonize("kujnld");
 
@@ -88,14 +86,14 @@
 
 	/* no signals are of interest */
 	spin_lock_irq(&current->sighand->siglock);
-	siginitsetinv(&current->blocked,0);
+	siginitsetinv(&current->blocked, 0);
 	recalc_sigpending();
 	spin_unlock_irq(&current->sighand->siglock);
 
 	/* loop around looking for things to attend to */
 	do {
 		set_current_state(TASK_INTERRUPTIBLE);
-		add_wait_queue(&kcachefs_jnld_sleepq,&myself);
+		add_wait_queue(&kcachefs_jnld_sleepq, &myself);
 
 		while (timo) {
 			if (kcachefs_jnld_do_acks ||
@@ -107,7 +105,7 @@
 			set_current_state(TASK_INTERRUPTIBLE);
 		}
 
-		remove_wait_queue(&kcachefs_jnld_sleepq,&myself);
+		remove_wait_queue(&kcachefs_jnld_sleepq, &myself);
 		set_current_state(TASK_RUNNING);
 
 		/* discard pending signals */
@@ -117,13 +115,16 @@
 		timo = MAX_SCHEDULE_TIMEOUT;
 
 		/* poll the superblocks looking for ACKs to process
-		 * - use a semaphore to prevent the list from changing whilst we walk it
+		 * - use a semaphore to prevent the list from changing whilst
+		 *   we walk it
 		 */
 		down(&kcachefs_jnld_list_sem);
 
 #if 0
-		list_for_each(_p,&kcachefs_jnld_list) {
-			super = list_entry(_p,struct cachefs_super,jnld_link);
+		list_for_each(_p, &kcachefs_jnld_list) {
+			super = list_entry(_p,
+					   struct cachefs_super,
+					   jnld_link);
 
 			cachefs_trans_write_batch(super);
 
@@ -131,18 +132,22 @@
 				cachefs_ujnl_process_acks(super);
 
 			if (super->ujnl_ack_pend - super->ujnl_ack_disc &&
-			    time_before(super->ujnl_ack_last + CACHEFS_UJNL_ACKMARK_DELAY,jiffies))
-					cachefs_ujnl_generate_ackmark(super);
+			    time_before(super->ujnl_ack_last +
+					CACHEFS_UJNL_ACKMARK_DELAY,
+					jiffies))
+				cachefs_ujnl_generate_ackmark(super);
 			
-			/* determine how long to wait before we might need to write an ACK mark */
+			/* determine how long to wait before we might need to
+			 * write an ACK mark */
 			if (super->ujnl_ack_pend > super->ujnl_ack_disc) {
 				signed long _timo;
 
-				_timo = super->ujnl_ack_last + CACHEFS_UJNL_ACKMARK_DELAY;
+				_timo = super->ujnl_ack_last;
+				_timo += CACHEFS_UJNL_ACKMARK_DELAY;
 				_timo -= jiffies;
-				if (_timo<0)
+				if (_timo < 0)
 					timo = 0;
-				else if (timo==MAX_SCHEDULE_TIMEOUT || _timo<timo)
+				else if (timo == MAX_SCHEDULE_TIMEOUT || _timo < timo)
 					timo = _timo;
 			}
 		}
@@ -154,7 +159,7 @@
 
 	/* and that's all */
 	kleave("");
-	complete_and_exit(&kcachefs_jnld_dead,0);
+	complete_and_exit(&kcachefs_jnld_dead, 0);
 
 } /* end kcachefs_jnld() */
 
@@ -168,7 +173,7 @@
 
 	down(&kcachefs_jnld_list_sem);
 
-	list_add_tail(&super->jnld_link,&kcachefs_jnld_list);
+	list_add_tail(&super->jnld_link, &kcachefs_jnld_list);
 
 	up(&kcachefs_jnld_list_sem);
 

Index: journal.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/journal.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- journal.c	11 Jun 2003 11:59:52 -0000	1.36
+++ journal.c	4 Jul 2003 09:04:44 -0000	1.37
@@ -17,6 +17,8 @@
 #include <linux/bio.h>
 #include "cachefs-int.h"
 
+#define UJNL_WRAP(X) ((X) & (CACHEFS_ONDISC_UJNL_NUMENTS - 1))
+
 struct cachefs_replay_find_batch_desc {
 	read_descriptor_t	desc;
 	unsigned short		batch_first;	/* sector holding first entry in batch */
@@ -35,28 +37,37 @@
 	"RcycXfer ",
 	"RcycScvng",
[...1618 lines suppressed...]
 
 		if (ret<0) {
-			printk("CacheFS: failed to reload recycling stack: %d\n",ret);
+			printk("CacheFS: failed to reload recycling stack: %d\n",
+			       ret);
 			return ret;
 		}
 
@@ -1707,9 +1809,10 @@
 
 		node = kmap(super->recycle_node);
 
-		for (loop=0; loop<CACHEFS_ONDISC_LEAVES_PER_FREE_NODE; loop++)
+		for (loop = 0; loop < CACHEFS_ONDISC_LEAVES_PER_FREE_NODE; loop++)
 			if (!node->leaves[loop])
 				break;
+
 		super->recycle_room = CACHEFS_ONDISC_LEAVES_PER_FREE_NODE - loop;
 		super->recycle_cur_n = node->count + super->recycle_room;
 

Index: io.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/io.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- io.c	1 Jul 2003 17:44:50 -0000	1.14
+++ io.c	4 Jul 2003 09:04:44 -0000	1.15
@@ -22,14 +22,18 @@
 #include "cachefs-int.h"
 
 static int cachefs_vio_readpage(struct file *file, struct page *page);
-static int cachefs_vio_readpages(struct file *file, struct address_space *mapping,
-				 struct list_head *pages, unsigned nr_pages);
-static int cachefs_vio_writepage(struct page *page, struct writeback_control *wbc);
-static int cachefs_vio_writepages(struct address_space *mapping, struct writeback_control *wbc);
-static int cachefs_vio_prepare_write(struct file *file, struct page *page, unsigned from,
-				     unsigned to);
-static int cachefs_vio_commit_write(struct file *file, struct page *page, unsigned from,
-				    unsigned to);
+static int cachefs_vio_readpages(struct file *file,
+				 struct address_space *mapping,
+				 struct list_head *pages,
+				 unsigned nr_pages);
+static int cachefs_vio_writepage(struct page *page,
+				 struct writeback_control *wbc);
+static int cachefs_vio_writepages(struct address_space *mapping,
+				  struct writeback_control *wbc);
+static int cachefs_vio_prepare_write(struct file *file, struct page *page,
+				     unsigned from, unsigned to);
+static int cachefs_vio_commit_write(struct file *file, struct page *page,
+				    unsigned from, unsigned to);
 static int cachefs_vio_invalidatepage(struct page *page, unsigned long offset);
 static int cachefs_vio_releasepage(struct page *page, int gfp_flags);
 static int cachefs_vio_set_page_dirty(struct page *page);
@@ -59,12 +63,14 @@
  * status of that page is hard.  See end_buffer_async_read() for the details.
  * There is no point in duplicating all that complexity.
  */
-static int cachefs_vio_io_end_io_read(struct bio *bio, unsigned int bytes_done, int err)
+static int cachefs_vio_io_end_io_read(struct bio *bio, unsigned int bytes_done,
+				      int err)
 {
 	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);
+	_enter("{sz=%u rw=%lu},%u,%d",
+	       bio->bi_size, bio->bi_rw, bytes_done, err);
 
 	if (bio->bi_size)
 		return 1;
@@ -92,26 +98,30 @@
 	struct bio *bio;
 
 	bio = *_bio;
-	if (!bio) return;
+	if (!bio)
+		return;
 	*_bio = NULL;
 
-	_enter("{sz=%u}",bio->bi_size);
+	_enter("{sz=%u}", bio->bi_size);
 
 	bio->bi_end_io = cachefs_vio_io_end_io_read;
-	submit_bio(READ,bio);
+	submit_bio(READ, bio);
 }
 
 static int cachefs_vio_io_alloc(struct super_block *sb,
-				sector_t first_sector, int nr_vecs, int gfp_flags,
+				sector_t first_sector,
+				int nr_vecs,
+				int gfp_flags,
 				struct bio **_bio)
 {
 	struct bio *bio;
 
 	*_bio = NULL;
 
-	_enter("{bits=%u},%llu,%d,%x,",sb->s_blocksize_bits,first_sector,nr_vecs,gfp_flags);
+	_enter("{bits=%u},%llu,%d,%x,",
+	       sb->s_blocksize_bits, first_sector, nr_vecs, gfp_flags);
 
-	bio = bio_alloc(gfp_flags,nr_vecs);
+	bio = bio_alloc(gfp_flags, nr_vecs);
 
 	if (!bio && (current->flags & PF_MEMALLOC)) {
 		while (!bio && (nr_vecs /= 2))
@@ -126,15 +136,18 @@
 	return 0;
 }
 
-static int cachefs_vio_writepages(struct address_space *mapping, struct writeback_control *wbc)
+static int cachefs_vio_writepages(struct address_space *mapping,
+				  struct writeback_control *wbc)
 {
 	struct page *page;
 
 	spin_lock(&mapping->page_lock);
 
-	list_splice_init(&mapping->dirty_pages,&mapping->io_pages);
+	list_splice_init(&mapping->dirty_pages,
+			 &mapping->io_pages);
 
-	if (list_empty(&mapping->dirty_pages) && list_empty(&mapping->io_pages)) {
+	if (list_empty(&mapping->dirty_pages) &&
+	    list_empty(&mapping->io_pages)) {
 		spin_unlock(&mapping->page_lock);
 		return 0;
 	}
@@ -142,10 +155,10 @@
 	/* shouldn't ever get this far */
 	printk("CacheFS: meta-data writepages not supported\n");
 
-	printk("- inode %lx\n",mapping->host->i_ino);
+	printk("- inode %lx\n", mapping->host->i_ino);
 
-	list_for_each_entry(page,&mapping->io_pages,list) {
-		printk("  - pg %lu\n",page->index);
+	list_for_each_entry(page, &mapping->io_pages, list) {
+		printk("  - pg %lu\n", page->index);
 	}
 
 	spin_unlock(&mapping->page_lock);
@@ -154,7 +167,8 @@
 	return -EIO;
 }
 
-static int cachefs_vio_writepage(struct page *page, struct writeback_control *wbc)
+static int cachefs_vio_writepage(struct page *page,
+				 struct writeback_control *wbc)
 {
 	printk("CacheFS: meta-data writepage not supported\n");
 	BUG();
@@ -181,7 +195,9 @@
 /*
  *
  */
-static int cachefs_vio_do_readpage(struct bio **_bio, struct page *page, unsigned nr_pages,
+static int cachefs_vio_do_readpage(struct bio **_bio,
+				   struct page *page,
+				   unsigned nr_pages,
 				   cachefs_blockix_t *last_block_in_bio)
 {
 	struct cachefs_page *pageio;
@@ -190,26 +206,32 @@
 
 	_enter("");
 
-	ret = cachefs_page_get_private(page,&pageio,GFP_KERNEL);
-	if (ret<0)
+	ret = cachefs_page_get_private(page, &pageio, GFP_KERNEL);
+	if (ret < 0)
 		goto error;
 
-	ret = cachefs_block_insert(inode->i_sb->s_fs_info,page->index,&pageio->mapped_block);
-	if (ret<0)
+	ret = cachefs_block_insert(inode->i_sb->s_fs_info,
+				   page->index,
+				   &pageio->mapped_block);
+	if (ret < 0)
 		goto error;
 
 	/* dispatch the outstanding BIO if the pages are not adjacent */
-	if (*_bio && *last_block_in_bio != page->index-1)
+	if (*_bio && *last_block_in_bio != page->index - 1)
 		cachefs_vio_io_bio_submit(_bio);
 
  alloc_new:
 	if (!*_bio) {
-		ret = cachefs_vio_io_alloc(inode->i_sb,page->index,nr_pages,GFP_KERNEL,_bio);
-		if (ret<0)
+		ret = cachefs_vio_io_alloc(inode->i_sb,
+					   page->index,
+					   nr_pages,
+					   GFP_KERNEL,
+					   _bio);
+		if (ret < 0)
 			goto error;
 	}
 
-	if (!bio_add_page(*_bio,page,PAGE_SIZE,0)) {
+	if (!bio_add_page(*_bio, page, PAGE_SIZE, 0)) {
 		cachefs_vio_io_bio_submit(_bio);
 		goto alloc_new;
 	}
@@ -220,8 +242,9 @@
 	return 0;
 
  error:
-	if (*_bio) cachefs_vio_io_bio_submit(_bio);
-	_leave("= %d",ret);
+	if (*_bio)
+		cachefs_vio_io_bio_submit(_bio);
+	_leave("= %d", ret);
 	return ret;
 } /* end cachefs_vio_do_readpage() */
 
@@ -238,19 +261,22 @@
 	unsigned page_idx;
 	int ret;
 
-	_enter(",,%u",nr_pages);
+	_enter(",,%u", nr_pages);
 
 	ret = 0;
-	pagevec_init(&lru_pvec,0);
-	for (page_idx=0; page_idx<nr_pages; page_idx++) {
-		struct page *page = list_entry(pages->prev,struct page,list);
+	pagevec_init(&lru_pvec, 0);
+	for (page_idx = 0; page_idx < nr_pages; page_idx++) {
+		struct page *page = list_entry(pages->prev, struct page, list);
 
 		prefetchw(&page->flags);
 		list_del(&page->list);
-		if (!add_to_page_cache(page,mapping,page->index,GFP_KERNEL)) {
-			ret = cachefs_vio_do_readpage(&bio,page,nr_pages-page_idx,
+		if (!add_to_page_cache(page, mapping, page->index,
+				       GFP_KERNEL)) {
+			ret = cachefs_vio_do_readpage(&bio,
+						      page,
+						      nr_pages - page_idx,
 						      &last_block_in_bio);
-			if (ret<0)
+			if (ret < 0)
 				break;
 			if (!pagevec_add(&lru_pvec, page))
 				__pagevec_lru_add(&lru_pvec);
@@ -261,9 +287,10 @@
 	pagevec_lru_add(&lru_pvec);
 	BUG_ON(!list_empty(pages));
 
-	if (bio) cachefs_vio_io_bio_submit(&bio);
+	if (bio)
+		cachefs_vio_io_bio_submit(&bio);
 
-	_leave(" = %d",ret);
+	_leave(" = %d", ret);
 	return ret;
 } /* end cachefs_vio_readpages() */
 
@@ -278,23 +305,26 @@
 	struct bio *bio;
 	int ret;
 
-	_enter(",{%lu}",page->index);
+	_enter(",{%lu}", page->index);
 
-	ret = cachefs_page_get_private(page,&pageio,GFP_KERNEL);
-	if (ret<0)
+	ret = cachefs_page_get_private(page, &pageio, GFP_KERNEL);
+	if (ret < 0)
 		return ret;
 
-	ret = cachefs_block_insert(inode->i_sb->s_fs_info,page->index,&pageio->mapped_block);
-	if (ret<0)
+	ret = cachefs_block_insert(inode->i_sb->s_fs_info, page->index,
+				   &pageio->mapped_block);
+	if (ret < 0)
 		return ret;
 
-	ret = cachefs_vio_io_alloc(inode->i_sb,page->index,1,GFP_KERNEL,&bio);
-	if (ret==0) {
-		if (!bio_add_page(bio,page,PAGE_SIZE,0)) BUG();
+	ret = cachefs_vio_io_alloc(inode->i_sb, page->index, 1, GFP_KERNEL,
+				   &bio);
+	if (ret == 0) {
+		if (!bio_add_page(bio, page, PAGE_SIZE, 0))
+			BUG();
 		cachefs_vio_io_bio_submit(&bio);
 	}
 
-	_leave(" = %d",ret);
+	_leave(" = %d", ret);
 	return ret;
 } /* end cachefs_vio_readpage() */
 
@@ -308,32 +338,31 @@
 	struct cachefs_page *pageio;
 	int ret = 1;
 
-	_enter("{%lu},%lu",page->index,offset);
+	_enter("{%lu},%lu", page->index, offset);
 
 	BUG_ON(!PageLocked(page));
 	if (!PagePrivate(page))
 		goto out;
 
-	pageio = (struct cachefs_page*) page->private;
-	block = xchg(&pageio->mapped_block,NULL);
+	pageio = (struct cachefs_page *) page->private;
+	block = xchg(&pageio->mapped_block, NULL);
 	pageio->flags = 0;
 
 	if (block) {
 		int usage = atomic_read(&block->usage);
 
-		if ((usage&0xffffff00)==0x6b6b6b00) {
-			printk("\nBLOCK PUT ERROR pg=%p{ix=%lu} blk=%p{u=%x}\n",
-			       page,page->index,block,usage);
+		if ((usage & 0xffffff00) == 0x6b6b6b00) {
+			printk("BLOCK PUT ERROR pg=%p{ix=%lu} blk=%p{u=%x}\n",
+			       page, page->index, block, usage);
 			BUG();
 		}
 
 		cachefs_block_put(block);
 	}
 
-	/*
-	 * We release buffers only if the entire page is being invalidated.
-	 * The get_block cached value has been unconditionally invalidated,
-	 * so real IO is not possible anymore.
+	/* We release buffers only if the entire page is being invalidated.
+	 * The get_block cached value has been unconditionally invalidated, so
+	 * real IO is not possible anymore.
 	 */
 	if (offset == 0) {
 		BUG_ON(!PageLocked(page));
@@ -354,20 +383,17 @@
  */
 static int cachefs_vio_releasepage(struct page *page, int gfp_flags)
 {
-	struct cachefs_block *block;
 	struct cachefs_page *pageio;
 
-	_enter("{%lu},%x",page->index,gfp_flags);
+	_enter("{%lu},%x", page->index, gfp_flags);
 
 	if (PagePrivate(page)) {
-		pageio = (struct cachefs_page*) page->private;
+		pageio = (struct cachefs_page *) page->private;
 		page->private = 0;
 		ClearPagePrivate(page);
 
 		if (pageio) {
-			block = xchg(&pageio->mapped_block,NULL);
-			if (block)
-				cachefs_block_put(block);
+			cachefs_block_put(xchg(&pageio->mapped_block, NULL));
 			dbgfree(pageio);
 			kfree(pageio);
 		}
@@ -383,7 +409,7 @@
  */
 static int cachefs_vio_set_page_dirty(struct page *page)
 {
-	kenter("{%lu}",page->index);
+	kenter("{%lu}", page->index);
 
 	BUG();
 
@@ -418,14 +444,15 @@
 		       bio->bi_io_vec[loop].bv_page,
 		       bio->bi_io_vec[loop].bv_page->index,
 		       bio->bi_io_vec[loop].bv_offset,
-		       bio->bi_io_vec[loop].bv_offset + bio->bi_io_vec[loop].bv_len - 1
+		       bio->bi_io_vec[loop].bv_offset +
+		       bio->bi_io_vec[loop].bv_len - 1
 		       );
 
 		stuff = page_address(bio->bi_io_vec[loop].bv_page);
 		stuff += bio->bi_io_vec[loop].bv_offset;
 
-		for (loop2=0; loop2<20; loop2++)
-			printk("%02x",stuff[loop2]);
+		for (loop2 = 0; loop2 < 20; loop2++)
+			printk("%02x", stuff[loop2]);
 
 		printk(" }\n");
 	}

Index: interface.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/interface.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- interface.c	10 Jun 2003 17:49:49 -0000	1.13
+++ interface.c	4 Jul 2003 09:04:44 -0000	1.14
@@ -25,7 +25,8 @@
 
 kmem_cache_t *cachefs_cookie_jar;
 
-static cachefs_match_val_t cachefs_fsdef_index_match(void *target, const void *entry);
+static cachefs_match_val_t cachefs_fsdef_index_match(void *target,
+						     const void *entry);
 
 static void cachefs_fsdef_index_update(void *source, void *entry);
 
@@ -47,10 +48,10 @@
 static void __cachefs_cookie_put(struct cachefs_cookie *cookie);
[...1022 lines suppressed...]
 	struct cachefs_page *pageio;
 	int ret;
 
-	_enter(",{%lu}",page->index);
+	_enter(",{%lu}", page->index);
 
 	if (!cookie) {
 		_leave(" [no cookie]");
@@ -1167,9 +1212,9 @@
 
 	BUG_ON(cookie->idef); /* not supposed to use this for indexes */
 
-	ret = cookie->netfs->ops->get_page_cookie(page,&pageio);
+	ret = cookie->netfs->ops->get_page_cookie(page, &pageio);
 	if (ret<0) {
-		_leave(" [get_page_cookie() =:%d]",ret);
+		_leave(" [get_page_cookie() = %d]", ret);
 		return;
 	}
 

Index: inode.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/inode.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- inode.c	10 Jun 2003 17:49:49 -0000	1.20
+++ inode.c	4 Jul 2003 09:04:44 -0000	1.21
@@ -22,7 +22,8 @@
 #include <asm/div64.h>
 #include "cachefs-int.h"
 
-static int cachefs_inode_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
+static int cachefs_inode_getattr(struct vfsmount *mnt, struct dentry *dentry,
+				 struct kstat *stat);
 
 static struct inode_operations cachefs_inode_operations = {
 	.getattr	= cachefs_inode_getattr,
@@ -61,13 +62,14 @@
 /*
  * set up a linear file inode
  */
-static void cachefs_iget_linear_file(struct cachefs_inode *inode, unsigned blocks)
+static void cachefs_iget_linear_file(struct cachefs_inode *inode,
+				     unsigned blocks)
 {
 	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		= (unsigned long)blocks << PAGE_SHIFT;
+	inode->vfs_inode.i_size		= (unsigned long) blocks << PAGE_SHIFT;
 	inode->vfs_inode.i_atime	= CURRENT_TIME;
 	inode->vfs_inode.i_mtime	= CURRENT_TIME;
 	inode->vfs_inode.i_ctime	= CURRENT_TIME;
@@ -84,7 +86,8 @@
 
 /*****************************************************************************/
 /*
- * retrieve the inode for the meta-data file, the first block of which we know to reside in block 1
+ * retrieve the inode for the meta-data file, the first block of which we know
+ * to reside in block 1
  */
 static int cachefs_iget_file0(struct cachefs_inode *inode)
 {
@@ -95,9 +98,11 @@
 
 	super = inode->vfs_inode.i_sb->s_fs_info;
 
-	_enter("{sb=%p ino=%lu}",inode->vfs_inode.i_sb,inode->vfs_inode.i_ino);
+	_enter("{sb=%p ino=%lu}",
+	       inode->vfs_inode.i_sb, inode->vfs_inode.i_ino);
 
-	/* stick in some initial values so that we can read the first page into the page cache */
+	/* stick in some initial values so that we can read the first page into
+	 * the page cache */
 	inode->vfs_inode.i_mode		= S_IFREG | S_IRUGO | S_IWUSR;
 	inode->vfs_inode.i_uid		= 0;
 	inode->vfs_inode.i_gid		= 0;
@@ -116,14 +121,15 @@
 	inode->index_esize	= inode->index_dsize;
 	inode->index_epp	= PAGE_SIZE / inode->index_esize;
 
-	__set_bit(CACHEFS_ACTIVE_INODE_ISINDEX,&inode->flags);
+	__set_bit(CACHEFS_ACTIVE_INODE_ISINDEX, &inode->flags);
 
 	/* read the page containing this inode's meta-data */
 	pos = inode->vfs_inode.i_ino << super->layout->metadata_bits;
-	ret = cachefs_get_page(inode,pos/PAGE_SIZE,&inode->metadata_page);
+	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);
-		_leave(" = %d",ret);
+		printk("kAFS: Failed to read meta-data page %lu: %d\n",
+		       pos / PAGE_SIZE, ret);
+		_leave(" = %d", ret);
 		return ret;
 	}
 	inode->metadata = __cachefs_get_page_block(inode->metadata_page);
@@ -131,7 +137,7 @@
 	metadata = cachefs_metadata_preread(inode);
 
 	_debug("read page %lu (pos %04x-%04x)",
-	       inode->metadata_page->index,pos,pos+inode->index_esize-1);
+	       inode->metadata_page->index, pos, pos + inode->index_esize - 1);
 
 	inode->vfs_inode.i_size		= metadata->size;
 	inode->vfs_inode.i_blocks	= metadata->size + inode->vfs_inode.i_blksize - 1;
@@ -153,12 +159,12 @@
 
 	_leave(" = 0");
 	return 0;
-
 } /* end cachefs_iget_file0() */
 
 /*****************************************************************************/
 /*
- * retrieve the inode for the Nth file, for which we have to look it up in the meta-data file
+ * retrieve the inode for the Nth file, for which we have to look it up in the
+ * meta-data file
  */
 static int cachefs_iget_fileN(struct cachefs_inode *inode)
 {
@@ -170,7 +176,7 @@
 
 	super = inode->vfs_inode.i_sb->s_fs_info;
 
-	_enter("{s=%p ino=%lu}",super,inode->vfs_inode.i_ino);
+	_enter("{s=%p ino=%lu}", super, inode->vfs_inode.i_ino);
 
 	/* get the meta-file inode */
 	imetadata = cachefs_igrab(super->imetadata);
@@ -181,25 +187,23 @@
 
 	/* read the page containing this inode's meta-data */
 	pos = inode->vfs_inode.i_ino * imetadata->index_esize;
-	ret = cachefs_get_page(imetadata,pos/PAGE_SIZE,&inode->metadata_page);
+	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);
-		_leave(" = %d",ret);
+	if (ret < 0) {
+		printk("CacheFS: Failed to read meta-data page %lu: %d\n",
+		       pos / PAGE_SIZE, ret);
+		_leave(" = %d", ret);
 		return ret;
 	}
 	inode->metadata = __cachefs_get_page_block(inode->metadata_page);
 
 	_debug("Reading inode %lu metadata record {%lu,{%u}}+%04x",
-	       inode->vfs_inode.i_ino,inode->metadata_page->index,
-	       inode->metadata->bix,pos);
+	       inode->vfs_inode.i_ino,
+	       inode->metadata_page->index,
+	       inode->metadata->bix,
+	       pos);
 
-#if 0
-	if (inode->metadata.mtime==0) {
-		inode->metadata.mtime = CURRENT_TIME;
-		mark_inode_dirty(&inode->vfs_inode);
-	}
-#endif
 	inode->vfs_inode.i_atime.tv_nsec = 0;
 	inode->vfs_inode.i_mtime.tv_nsec = 0;
 	inode->vfs_inode.i_ctime.tv_nsec = 0;
@@ -216,7 +220,8 @@
 	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	= metadata->size + inode->vfs_inode.i_blksize-1;
+	inode->vfs_inode.i_blocks	= metadata->size;
+	inode->vfs_inode.i_blocks	+= inode->vfs_inode.i_blksize - 1;
 	inode->vfs_inode.i_blocks	>>= PAGE_SHIFT;
 	inode->vfs_inode.i_version	= metadata->version;
 	inode->vfs_inode.i_flags	|= S_NOATIME;
@@ -224,32 +229,33 @@
 	inode->vfs_inode.i_fop		= &cachefs_file_operations;
 	inode->vfs_inode.i_mapping->a_ops = &cachefs_addrspace_operations;
 
-	inode->index_dsize	= metadata->index_dsize;
-	inode->index_esize	= metadata->index_esize;
+	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) {
+	if (inode->index_esize ||
+	    inode->vfs_inode.i_ino == CACHEFS_INO_ROOTDIR) {
 		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;
-		inode->vfs_inode.i_fop		= &cachefs_root_file_operations;
+		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;
+		inode->vfs_inode.i_fop	= &cachefs_root_file_operations;
 
-		__set_bit(CACHEFS_ACTIVE_INODE_ISINDEX,&inode->flags);
+		__set_bit(CACHEFS_ACTIVE_INODE_ISINDEX, &inode->flags);
 	}
 
-	_leave(" = %d",ret);
+	_leave(" = %d", ret);
 	return ret;
-
 } /* end cachefs_iget_fileN() */
 
 /*****************************************************************************/
 /*
  * attempt to retrieve the inode for a cached file
  */
-int cachefs_iget(struct cachefs_super *super, ino_t ino, struct cachefs_inode **_inode)
+int cachefs_iget(struct cachefs_super *super, ino_t ino,
+		 struct cachefs_inode **_inode)
 {
 	struct cachefs_inode *inode;
 	struct inode *vfs_inode;
@@ -257,12 +263,14 @@
 	loff_t nblocks;
 	int ret;
 
-	_enter(",%lu,",ino);
+	_enter(",%lu,", ino);
 
 	*_inode = NULL;
 
+	BUG_ON(ino == 0);
+
 	/* it does reside in this cache - create an inode for it */
-	vfs_inode = iget_locked(super->sb,ino);
+	vfs_inode = iget_locked(super->sb, ino);
 	if (!vfs_inode) {
 		_leave(" = -ENOMEM");
 		return -ENOMEM;
@@ -282,16 +290,16 @@
 		/* miscellaneous data block linear inode */
 	case CACHEFS_INO_MISC:
 		nblocks = super->sb->s_bdev->bd_inode->i_size;
-		do_div(nblocks,PAGE_SIZE);
-		if (nblocks>UINT_MAX)
+		do_div(nblocks, PAGE_SIZE);
+		if (nblocks > UINT_MAX)
 			nblocks = UINT_MAX;
-		cachefs_iget_linear_file(inode,nblocks);
+		cachefs_iget_linear_file(inode, nblocks);
 		break;
 
 		/* writeback journal linear inode */
 	case CACHEFS_INO_WBJOURNAL:
 		tmp = super->layout->bix_cache - super->layout->bix_wbjournal;
-		cachefs_iget_linear_file(inode,tmp);
+		cachefs_iget_linear_file(inode, tmp);
 		break;
 
 		/* status file */
@@ -301,17 +309,19 @@
 
 		/* metadata meta-data inode */
 	case CACHEFS_INO_METADATA:
-		inode->metadata_offset = (ino << super->layout->metadata_bits) & ~PAGE_MASK;
+		inode->metadata_offset =
+			(ino << super->layout->metadata_bits) & ~PAGE_MASK;
 		ret = cachefs_iget_file0(inode);
-		if (ret<0)
+		if (ret < 0)
 			goto bad_inode;
 		break;
 
 		/* index and data-cache inodes */
 	default:
-		inode->metadata_offset = (ino << super->layout->metadata_bits) & ~PAGE_MASK;
+		inode->metadata_offset =
+			(ino << super->layout->metadata_bits) & ~PAGE_MASK;
 		ret = cachefs_iget_fileN(inode);
-		if (ret<0)
+		if (ret < 0)
 			goto bad_inode;
 		break;
 	}
@@ -320,7 +330,7 @@
 	unlock_new_inode(&inode->vfs_inode);
 
 	*_inode = inode;
-	_leave(" = 0 [%p]",inode);
+	_leave(" = 0 [%p]", inode);
 	return 0;
 
 	/* failure */
@@ -329,122 +339,20 @@
 	unlock_new_inode(&inode->vfs_inode);
 	iput(&inode->vfs_inode);
 
-	_leave(" = %d [bad]",ret);
+	_leave(" = %d [bad]", ret);
 	return ret;
-
 } /* end cachefs_iget() */
 
-#if 0
-/*****************************************************************************/
-/*
- *
- */
-static int cachefs_end_write_inode(struct bio *bio, unsigned int bytes_done, int err)
-{
-	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);
-
-	if (bio->bi_size)
-		return 1;
-
-	do {
-		struct page *page = bvec->bv_page;
-
-		if (--bvec >= bio->bi_io_vec)
-			prefetchw(&bvec->bv_page->flags);
-
-		if (!uptodate)
-			SetPageError(page);
-		end_page_writeback(page);
-	} while (bvec >= bio->bi_io_vec);
-	bio_put(bio);
-	return 0;
-} /* end cachefs_end_write_inode() */
-#endif
-
 /*****************************************************************************/
 /*
  * write a cache inode back to disc
- * - don't use generic_file_write() to write out the meta-data file's meta-data as it updates the
- *   mtime & ctime and marks the inode dirty again
+ * - don't use generic_file_write() to write out the meta-data file's meta-data
+ *   as it updates the mtime & ctime and marks the inode dirty again
  */
 void cachefs_write_inode(struct inode *vfs_inode, int sync)
 {
-#if 0
-	struct cachefs_ondisc_metadata *metadata;
-	struct cachefs_super *super;
-	struct cachefs_inode *inode;
-	struct bio *bio;
-#endif
-	unsigned ino;
-
-	ino = vfs_inode->i_ino;
-
-	_enter("{sb=%p ino=%u},%d",vfs_inode->i_sb,ino,sync);
-
-#if 0
-	inode = CACHEFS_FS_I(vfs_inode);
-	super = vfs_inode->i_sb->s_fs_info;
-
-	bio = bio_alloc(GFP_KERNEL,1);
-	if (!bio) {
-		printk("CacheFS: Can't allocate BIO to write inode: -ENOMEM\n");
-		return;
-	}
-
-	tmp = (ino << super->sb->s_blocksize_bits) & (PAGE_SIZE-1);
-
-	_debug("Writing inode %u metadata record {{%u}}+%04x",
-	       ino,cachefs_pageio(inode->metadata)->mapped_block,tmp);
-
-	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->metadata,super->sb->s_blocksize,tmp))
-		BUG();
-
-	/* make the change */
-	lock_page(inode->metadata);
-
-	metadata =
-		kmap(inode->metadata) +
-		(ino % CACHEFS_METADATA_PER_PAGE) * CACHEFS_ONDISC_METADATA_RECSIZE;
-
-	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->metadata);
-	flush_dcache_page(inode->metadata);
-
-	SetPageWriteback(inode->metadata);
-	unlock_page(inode->metadata);
-
-	submit_bio(WRITE,bio);
-	if (sync)
-		wait_on_page_writeback(inode->metadata);
-#endif
-
-#if 0
-	/* update the modification time of the meta-data inode */
-	if (inode!=imetadata) {
-		time_t time_now = CURRENT_TIME;
-		if (imetadata->vfs_inode.i_ctime != time_now ||
-		    imetadata->vfs_inode.i_mtime != time_now
-		    ) {
-			imetadata->vfs_inode.i_ctime = time_now;
-			imetadata->vfs_inode.i_mtime = time_now;
-			mark_inode_dirty_sync(&imetadata->vfs_inode);
-		}
-	}
-#endif
+	_enter("{sb=%p ino=%lu},%d", vfs_inode->i_sb, vfs_inode->i_ino, sync);
 
-	_leave("");
 } /* end cachefs_write_inode() */
 
 /*****************************************************************************/
@@ -453,25 +361,20 @@
  */
 void cachefs_clear_inode(struct inode *vfs_inode)
 {
-	struct cachefs_inode *inode;
-
-	inode = CACHEFS_FS_I(vfs_inode);
-
-	_enter("{ino=%lu nl=%u}",inode->vfs_inode.i_ino,inode->vfs_inode.i_nlink);
+	_enter("{ino=%lu nl=%u}", vfs_inode->i_ino, vfs_inode->i_nlink);
 
-	_leave("");
 } /* end cachefs_clear_inode() */
 
 /*****************************************************************************/
 /*
  * read the attributes of an inode
  */
-int cachefs_inode_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
+int cachefs_inode_getattr(struct vfsmount *mnt, struct dentry *dentry,
+			  struct kstat *stat)
 {
-	_enter("{ ino=%lu }",dentry->d_inode->i_ino);
+	_enter("{ ino=%lu }", dentry->d_inode->i_ino);
 
-	/* transfer attributes from the inode structure to the stat structure */
-	generic_fillattr(dentry->d_inode,stat);
+	generic_fillattr(dentry->d_inode, stat);
 
 	_leave(" = 0");
 	return 0;

Index: index.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/index.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- index.c	11 Jun 2003 11:59:52 -0000	1.23
+++ index.c	4 Jul 2003 09:04:44 -0000	1.24
@@ -52,7 +52,7 @@
 	void *content;
 	int ret;
 
-	_enter(",{%lu},%lu,%lu",page->index,offset,size);
+	_enter(",{%lu},%lu,%lu", page->index, offset, size);
 
 	rec = (struct cachefs_index_search_record *) desc->buf;
 	ret = size;
@@ -61,14 +61,15 @@
 	tmp = offset;
 	offset += rec->entsize - 1;
 	offset -= offset % rec->entsize;
-	if (offset-tmp > size)
+	if (offset - tmp > size)
 		goto done;
 
 	size -= offset - tmp;
 
-	/* limit the search of this page to the amount specified in desc->count */
+	/* limit the search of this page to the amount specified in
+	 * desc->count */
 	stop = desc->count;
-	if (size<stop)
+	if (size < stop)
 		stop = size;
 
 	tmp = rec->entsize;
@@ -76,16 +77,30 @@
 	/* search the elements on the page (ignoring slack at end) */
 	content = kmap(page);
 
-	for (; offset+tmp<=stop; offset+=tmp) {
+	for (; offset + tmp <= stop; offset += tmp) {
 		struct cachefs_ondisc_index_entry *xent = content + offset;
 
-		if (xent->state==CACHEFS_ONDISC_INDEX_FREE ||
-		    xent->state==CACHEFS_ONDISC_INDEX_RECYCLE)
+		if (xent->state == CACHEFS_ONDISC_INDEX_FREE ||
+		    xent->state == CACHEFS_ONDISC_INDEX_RECYCLE)
 			continue;
 
-		if (rec->index->idef->match(rec->target->netfs_data,xent->data)) {
-			rec->entry = offset/tmp + page->index*(PAGE_SIZE/tmp);
+		if (rec->index->idef->match(rec->target->netfs_data,
+					    xent->data)) {
+			rec->entry = offset / tmp;
+			rec->entry += page->index * (PAGE_SIZE / tmp);
 			rec->ino   = xent->ino;
+
+			if (rec->ino == 0) {
+				printk("CacheFS: Unexpected 0 inode number in"
+				       " index %lu ent %u {%lu [%u] +%lu}\n",
+				       rec->iinode->vfs_inode.i_ino,
+				       rec->entry,
+				       page->index,
+				       __cachefs_get_page_block(page)->bix,
+				       offset / tmp);
+				BUG();
+			}
+
 			desc->count = 0;
 			ret = 0;
 			break;
@@ -98,7 +113,7 @@
 	desc->count -= ret;
 	desc->written += ret;
 
-	_leave(" = %d",ret);
+	_leave(" = %d", ret);
 	return ret;
 } /* end cachefs_index_search_actor() */
 
@@ -120,7 +135,7 @@
 	loff_t pos;
 	int ret;
 
-	_enter("{%s,%lu}",index->cookie->idef->name,index->vfs_inode.i_ino);
+	_enter("{%s,%lu}", index->cookie->idef->name, index->vfs_inode.i_ino);
 
 	if (_entry)
 		*_entry = UINT_MAX;
@@ -135,26 +150,27 @@
 	rec.ino		= 0;
 
 	/* scan the file through the pagecache */
-	file_ra_state_init(&ra,rec.iinode->vfs_inode.i_mapping);
+	file_ra_state_init(&ra, rec.iinode->vfs_inode.i_mapping);
 
 	desc.written	= 0;
 	desc.count	= rec.iinode->vfs_inode.i_size;
-	desc.buf	= (char*) &rec;
+	desc.buf	= (char *) &rec;
 	desc.error	= 0;
 
 	pos = 0;
 
-	do_generic_mapping_read(rec.iinode->vfs_inode.i_mapping,&ra,NULL,
-				&pos,&desc,cachefs_index_search_actor);
+	do_generic_mapping_read(rec.iinode->vfs_inode.i_mapping, &ra, NULL,
+				&pos, &desc, cachefs_index_search_actor);
 
 	if (desc.error) {
 		ret = desc.error;
-		
 	}
-	else if (rec.entry==UINT_MAX) {
+	else if (rec.entry == UINT_MAX) {
 		ret = -ENOENT;
 	}
 	else {
+		BUG_ON(rec.ino == 0);
+
 		if (_entry)
 			*_entry = rec.entry;
 		if (_ino)
@@ -162,7 +178,7 @@
 		ret = 0;
 	}
 
-	_leave(" = %d [ent=%d ino=%u]",ret,rec.entry,rec.ino);
+	_leave(" = %d [ent=%d ino=%u]", ret, rec.entry, rec.ino);
 	return ret;
 } /* end cachefs_index_search() */
 
@@ -181,11 +197,11 @@
 	int loop, ret;
 
 	iinode = data;
-	_enter("{%lu},%p{%lu}",iinode->vfs_inode.i_ino,page,page->index);
+	_enter("{%lu},%p{%lu}", iinode->vfs_inode.i_ino, page, page->index);
 
-	ret = cachefs_page_get_private(page,&pageio,GFP_KERNEL);
-	if (ret<0) {
-		_leave(" = %d",ret);
+	ret = cachefs_page_get_private(page, &pageio, GFP_KERNEL);
+	if (ret < 0) {
+		_leave(" = %d", ret);
 		return ret;
 	}
 
@@ -198,7 +214,7 @@
 	content = kmap(page);
 	clear_page(content);
 
-	for (loop=iinode->index_epp-1; loop>=0; loop--) {
+	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;
@@ -207,7 +223,7 @@
 
 	kunmap(content);
 
-	_debug("new freelink: %u",next);
+	_debug("new freelink: %u", next);
 
 	metadata = cachefs_metadata_prewrite(iinode);
 	metadata->freelink = next;
@@ -235,7 +251,7 @@
 	unsigned newentry, pgnum, offset;
 	int ret;
 
-	_enter("{%lu},",iinode->vfs_inode.i_ino);
+	_enter("{%lu},", iinode->vfs_inode.i_ino);
 
 	*_page		= NULL;
 	*_newentry	= 0;
@@ -245,15 +261,17 @@
 	newentry = metadata->freelink;
 	cachefs_metadata_postread(iinode);
 
-	_debug("free entry: %u [size %Lu]",newentry,iinode->vfs_inode.i_size);
+	_debug("free entry: %u [size %Lu]",
+	       newentry, iinode->vfs_inode.i_size);
 
 	/* we may need to extend the index file */
-	if (newentry==UINT_MAX) {
+	if (newentry == UINT_MAX) {
 		pgnum = iinode->vfs_inode.i_size >> PAGE_SHIFT;
 
-		/* 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);
+		/* 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);
 		dbgpgalloc(page);
 		if (IS_ERR(page)) {
 			ret = PTR_ERR(page);
@@ -263,9 +281,9 @@
 		iinode->vfs_inode.i_size += PAGE_SIZE;
 
 		/* make the extension */
-		ret = cachefs_get_block(&iinode->vfs_inode,page,
-					__cachefs_page_get_private(page),1);
-		if (ret<0) {
+		ret = cachefs_get_block(&iinode->vfs_inode, page,
+					__cachefs_page_get_private(page), 1);
+		if (ret < 0) {
 			iinode->vfs_inode.i_size -= PAGE_SIZE;
 			goto error2;
 		}
@@ -274,19 +292,31 @@
 		newentry = metadata->freelink;
 		cachefs_metadata_postread(iinode);
 
-		BUG_ON(newentry==UINT_MAX);
-
-//		_debug("syncing");
-//		cachefs_trans_sync(iinode->vfs_inode.i_sb->s_fs_info,
-//				   CACHEFS_TRANS_SYNC_WAIT_FOR_ACK);
+		BUG_ON(newentry == UINT_MAX);
 		_debug("done");
 	}
 	/* get the page holding the next free entry */
 	else {
+		filler_t *filler = 
+			(filler_t *)
+			iinode->vfs_inode.i_mapping->a_ops->readpage;
+
+		if (!iinode->index_epp) {
+			printk("CacheFS:"
+			       " Index %lu {meta %u+%u} has zero-sized entries"
+			       " (%hu/%hu/%hu)\n",
+			       iinode->vfs_inode.i_ino,
+			       iinode->metadata->bix,
+			       iinode->metadata_offset,
+			       iinode->index_dsize,
+			       iinode->index_esize,
+			       iinode->index_epp);
+			BUG();
+		}
+
 		pgnum = newentry / iinode->index_epp;
-		page = read_cache_page(iinode->vfs_inode.i_mapping,pgnum,
-				       (filler_t*) iinode->vfs_inode.i_mapping->a_ops->readpage,
-				       NULL);
+		page = read_cache_page(iinode->vfs_inode.i_mapping, pgnum,
+				       filler, NULL);
 		dbgpgalloc(page);
 		if (IS_ERR(page)) {
 			ret = PTR_ERR(page);
@@ -305,13 +335,13 @@
 	*_next = xent->freelink[0];
 	kunmap(page);
 
-	_leave(" = 0 [{%lu},%u,%u]",page->index,newentry,*_next);
+	_leave(" = 0 [{%lu},%u,%u]", page->index, newentry, *_next);
 	return 0;
 
  error2:
 	cachefs_put_page(page);
  error:
-	_leave(" = %d",ret);
+	_leave(" = %d", ret);
 	return ret;
 
 } /* end cachefs_index_select_free_entry() */
@@ -319,8 +349,10 @@
 /*****************************************************************************/
 /*
  * allocate an entry in the specified index file and associate an inode with it
- * - target->cookie->def determines whether the new inode will be a file or an index
- * - if an inode is successfully allocated, *_newino will be set with the inode number
+ * - target->cookie->def determines whether the new inode will be a file or an
+ *   index
+ * - if an inode is successfully allocated *_newino will be set with the inode
+ *   number
  */
 int cachefs_index_add(struct cachefs_inode *index,
 		      struct cachefs_cookie *cookie,
@@ -335,7 +367,8 @@
 	unsigned ino, ixentry, offset, inonext, ixnext, ino_offset;
 	int ret, loop;
 
-	_enter("{%lu},{%s},",index->vfs_inode.i_ino,index->cookie->idef->name);
+	_enter("{%lu},{%s},",
+	       index->vfs_inode.i_ino, index->cookie->idef->name);
 
 	*_newino = 0;
 
@@ -345,27 +378,29 @@
 	trans	= NULL;
 
 	/* we need an index entry and a inode */
-	ret = cachefs_index_select_free_entry(index,&ixpage,&ixentry,&ixnext);
-	if (ret<0)
+	ret = cachefs_index_select_free_entry(index,
+					      &ixpage, &ixentry, &ixnext);
+	if (ret < 0)
 		goto error;
 
-	ret = cachefs_index_select_free_entry(super->imetadata,&inopage,&ino,&inonext);
-	if (ret<0)
+	ret = cachefs_index_select_free_entry(super->imetadata,
+					      &inopage, &ino, &inonext);
+	if (ret < 0)
 		goto error;
 
-	_debug("entry %u ino %u",ixentry,ino);
+	_debug("entry %u ino %u", ixentry, ino);
 
 	/* do the allocation under journalling */
 	ret = -ENOMEM;
-	trans = cachefs_trans_alloc(super,GFP_KERNEL);
+	trans = cachefs_trans_alloc(super, GFP_KERNEL);
 	if (!trans)
 		goto error;
 
 	offset = (ixentry % index->index_epp) * index->index_esize;
 
-	trans->jentry->mark = CACHEFS_ONDISC_UJNL_INDEX_ALLOCING;
+	trans->jentry->mark = CACHEFS_ONDISC_UJNL_INDEX_CREATING;
 	if (!cookie->idef)
-		trans->jentry->mark = CACHEFS_ONDISC_UJNL_INODE_ALLOCING;
+		trans->jentry->mark = CACHEFS_ONDISC_UJNL_INODE_CREATING;
 
 	trans->jentry->index	= index->vfs_inode.i_ino;
 	trans->jentry->ixentry	= ixentry;
@@ -381,20 +416,20 @@
 	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->metadata_size);
+	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->metadata_size);
 
-	cachefs_trans_affects_inode(trans,index);
-	cachefs_trans_affects_inode(trans,super->imetadata);
+	cachefs_trans_affects_inode(trans, index);
+	cachefs_trans_affects_inode(trans, super->imetadata);
 
 	ret = cachefs_trans_mark(trans);
-	if (ret<0)
+	if (ret < 0)
 		goto error;
 
-	cachefs_page_modify(super,&ixpage);
-	cachefs_page_modify(super,&inopage);
+	cachefs_page_modify(super, &ixpage);
+	cachefs_page_modify(super, &inopage);
 
 	/* fill the index entry */
 	xent = kmap(ixpage) + offset;
@@ -405,7 +440,7 @@
 	if (cookie->idef)
 		xent->type = CACHEFS_ONDISC_INDEX_INDEXFILE;
 
-	index->cookie->idef->update(cookie->netfs_data,xent->data);
+	index->cookie->idef->update(cookie->netfs_data, xent->data);
 
 	kunmap(ixpage);
 
@@ -417,7 +452,7 @@
 
 	/* fill the inode definition */
 	metadata = kmap(inopage) + ino_offset;
-	memset(metadata,0,sizeof(super->imetadata->index_esize));
+	memset(metadata, 0, sizeof(super->imetadata->index_esize));
 
 	metadata->header.state	= CACHEFS_ONDISC_INDEX_ACTIVE;
 	metadata->header.ino	= 0xfefefe;
@@ -431,17 +466,26 @@
 	if (cookie->idef) {
 		struct cachefs_index_def *definition = cookie->idef;
 
-		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++) {
-			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;
+		metadata->index_dsize = definition->data_size;
+		metadata->index_esize = metadata->index_dsize;
+		metadata->index_esize +=
+			sizeof(struct cachefs_ondisc_index_entry);
+
+		if (metadata->index_esize < CACHEFS_ONDISC_INDEX_ENTRY_MINSIZE)
+			metadata->index_esize =
+				CACHEFS_ONDISC_INDEX_ENTRY_MINSIZE;
+
+		for (loop = 0; loop < 4; loop++) {
+			metadata->index_keys[loop] =
+				definition->keys[loop].len &
+				CACHEFS_ONDISC_INDEXKEY_KLEN;
+			metadata->index_keys[loop] |=
+				definition->keys[loop].type << 12;
 		}
 
-		strncpy(metadata->index_type,definition->name,sizeof(metadata->index_type));
+		strncpy(metadata->index_type,
+			definition->name,
+			sizeof(metadata->index_type));
 	}
 
 	kunmap(inopage);
@@ -457,8 +501,8 @@
 	trans = NULL;
 
 	/* note that it is now present */
-	list_for_each_entry(srch,&cookie->search_results,link) {
-		if (srch->super==super) {
+	list_for_each_entry(srch, &cookie->search_results, link) {
+		if (srch->super == super) {
 			srch->ino = ino;
 			break;
 		}
@@ -471,13 +515,14 @@
 	cachefs_put_page(inopage);
 	cachefs_put_page(ixpage);
 
-	_leave(" = %d",ret);
+	_leave(" = %d", ret);
 	return ret;
 } /* end cachefs_index_add() */
 
 /*****************************************************************************/
 /*
- * mark the next inode pinned by an entry in the index currently being reclaimed as being obsolete
+ * mark the next inode pinned by an entry in the index currently being
+ * reclaimed as being obsolete
  */
 int cachefs_index_zap(struct cachefs_super *super)
 {
@@ -490,7 +535,7 @@
 	unsigned pgnum, offset, ino;
 	int ret;
 
-	_enter("{%u,%u}",super->rcm_ino,super->rcm_block);
+	_enter("{%u,%u}", super->rcm_ino, super->rcm_block);
 
 	pgnum	= super->rcm_block / super->rcm_inode->index_epp;
 	offset	= super->rcm_block % super->rcm_inode->index_epp;
@@ -500,13 +545,15 @@
 		return 0; /* done them all */
 	}
 
-	/* get the page holding the next index entry and extract the inode number from it */
-	ret = cachefs_get_page(super->rcm_inode,pgnum,&page);
-	if (ret<0) {
-		if (ret==-EIO) {
-			super->rcm_block = (pgnum+1) * super->rcm_inode->index_epp;
+	/* get the page holding the next index entry and extract the inode
+	 * number from it */
+	ret = cachefs_get_page(super->rcm_inode, pgnum, &page);
+	if (ret < 0) {
+		if (ret == -EIO) {
+			super->rcm_block =
+				(pgnum + 1) * super->rcm_inode->index_epp;
 		}
-		_leave(" = %d",ret);
+		_leave(" = %d", ret);
 		return ret;
 	}
 
@@ -515,13 +562,12 @@
 	ino = xent->ino;
 	kunmap(page);
 
-	/* open the inode */
-	ret = cachefs_iget(super,ino,&inode);
-	if (ret<0)
+	ret = cachefs_iget(super, ino, &inode);
+	if (ret < 0)
 		goto error_skip;
 
 	/* journal what we're going to do */
-	trans = cachefs_trans_alloc(super,GFP_KERNEL);
+	trans = cachefs_trans_alloc(super, GFP_KERNEL);
 	if (!trans) {
 		_leave(" = -ENOMEM");
 		return -ENOMEM;
@@ -549,17 +595,22 @@
 	trans = NULL;
 
 	/* add to the immediate-reclaim table if possible */
-	spin_lock_irqsave(&super->rcm_lock,flags);
+	spin_lock_irqsave(&super->rcm_lock, flags);
 
-	if (CIRC_SPACE(super->rcm_imm_head,super->rcm_imm_tail,CACHEFS_RCM_IMM_BUFSIZE)>0) {
-		super->rcm_imm_buf[super->rcm_imm_head] = inode->vfs_inode.i_ino;
-		super->rcm_imm_head = (super->rcm_imm_head+1) & (CACHEFS_RCM_IMM_BUFSIZE-1);
+	if (CIRC_SPACE(super->rcm_imm_head,
+		       super->rcm_imm_tail,
+		       CACHEFS_RCM_IMM_BUFSIZE) > 0) {
+		super->rcm_imm_buf[super->rcm_imm_head] =
+			inode->vfs_inode.i_ino;
+		super->rcm_imm_head =
+			(super->rcm_imm_head + 1) &
+			(CACHEFS_RCM_IMM_BUFSIZE - 1);
 	}
 	else {
-		set_bit(CACHEFS_SUPER_RCM_IMM_SCAN,&super->flags);
+		set_bit(CACHEFS_SUPER_RCM_IMM_SCAN, &super->flags);
 	}
 
-	spin_unlock_irqrestore(&super->rcm_lock,flags);
+	spin_unlock_irqrestore(&super->rcm_lock, flags);
 
 	super->rcm_block++;
 	ret = -EAGAIN;
@@ -568,10 +619,10 @@
 	cachefs_iput(inode);
 	cachefs_trans_put(trans);
 	cachefs_put_page(page);
-	if (ret==-EIO)
+	if (ret == -EIO)
 		super->rcm_block++;
 
-	_leave(" = %d",ret);
+	_leave(" = %d", ret);
 	return ret;
 } /* end cachefs_index_zap() */
 
@@ -581,11 +632,11 @@
  * - since we don't know what index data was associated with it, all we can do
  *   is mark it for reclamation
  */
-int cachefs_replay_ujnl_inode_allocing(struct cachefs_super *super,
+int cachefs_replay_ujnl_inode_creating(struct cachefs_super *super,
 				       struct cachefs_ondisc_update_journal *jentry)
 {
 	return -ENOANO;
-} /* end cachefs_replay_ujnl_inode_allocing() */
+} /* end cachefs_replay_ujnl_inode_creating() */
 
 /*****************************************************************************/
 /*
@@ -645,11 +696,11 @@
 /*
  * 
  */
-int cachefs_replay_ujnl_index_allocing(struct cachefs_super *super,
+int cachefs_replay_ujnl_index_creating(struct cachefs_super *super,
 				       struct cachefs_ondisc_update_journal *jentry)
 {
 	return -ENOANO;
-} /* end cachefs_replay_ujnl_index_allocing() */
+} /* end cachefs_replay_ujnl_index_creating() */
 
 /*****************************************************************************/
 /*
@@ -665,8 +716,8 @@
 /*
  * 
  */
-int cachefs_replay_ujnl_index_freeing(struct cachefs_super *super,
-				      struct cachefs_ondisc_update_journal *jentry)
+int cachefs_replay_ujnl_index_deleting(struct cachefs_super *super,
+				       struct cachefs_ondisc_update_journal *jentry)
 {
 	return -ENOANO;
-} /* end cachefs_replay_ujnl_index_freeing() */
+} /* end cachefs_replay_ujnl_index_deleting() */

Index: dump-journal.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/dump-journal.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- dump-journal.c	28 May 2003 10:32:54 -0000	1.10
+++ dump-journal.c	4 Jul 2003 09:04:44 -0000	1.11
@@ -31,7 +31,8 @@
 
 #define BP_RED	"\e[41;1m"
 
-#define OSERROR(X,Y) do { if ((int)(Y)<0) { perror((X)); exit(1); } } while(0)
+#define OSERROR(X,Y) \
+	do { if ((int)(Y) < 0) { perror((X)); exit(1); } } while(0)
 
 struct sector {
 	union {
@@ -49,9 +50,9 @@
 	BRIGHT	"RcycXfer "	NORMAL,
 	BRIGHT	"RcycScvng"	NORMAL,
 	BRIGHT	"RcycMkRdy"	NORMAL,
-	BRIGHT	"InoAlloc "	NORMAL,
-	BRIGHT	"InoUpdate"	NORMAL,
-	BRIGHT	"InoDelete"	NORMAL,
+	BRIGHT	"CrtData  "	NORMAL,
+	BRIGHT	"UpdData  "	NORMAL,
+	BRIGHT	"DelData  "	NORMAL,
 	BRIGHT	"InoMkRcm "	NORMAL,
 	BRIGHT	"InoRcming"	NORMAL,
 	BRIGHT	"DataAlloc"	NORMAL,
@@ -59,10 +60,10 @@
 	BRIGHT	"DataUnalc"	NORMAL,
 	BRIGHT	"IndrAlloc"	NORMAL,
 	BRIGHT	"IndrFree "	NORMAL,
-	BRIGHT	"IndexExtn"	NORMAL,
-	BRIGHT	"IndexAllc"	NORMAL,
-	BRIGHT	"IndexModf"	NORMAL,
-	BRIGHT	"IndexFree"	NORMAL,
+	BRIGHT	"ExtnIndex"	NORMAL,
+	BRIGHT	"CrtIndex "	NORMAL,
+	BRIGHT	"ModIndex "	NORMAL,
+	BRIGHT	"DelIndex "	NORMAL,
 	BP_RED	"?????????"	NORMAL
 };
 
@@ -76,33 +77,33 @@
 	int devfd, loop, delta;
 
 	delta = 1;
-	if (argc==3 && strcmp(argv[1],"-r")==0) {
+	if (argc == 3 && strcmp(argv[1], "-r") == 0) {
 		delta = -1;
 		argc--;
 		argv++;
 	}
 
-	if (argc!=2) abort();
+	if (argc != 2) abort();
 
-	devfd = open(argv[1],O_RDONLY);
-	OSERROR("open",devfd);
+	devfd = open(argv[1], O_RDONLY);
+	OSERROR("open", devfd);
 
-	OSERROR("stat",fstat(devfd,&st));
+	OSERROR("stat", fstat(devfd, &st));
 	if (!S_ISBLK(st.st_mode)) {
-		fprintf(stderr,"not a blockdev\n");
+		fprintf(stderr, "not a blockdev\n");
 		exit(1);
 	}
 
-	super = mmap(NULL,4096,PROT_READ,MAP_PRIVATE,devfd,0);
-	OSERROR("mmap",super);
+	super = mmap(NULL, 4096, PROT_READ, MAP_PRIVATE, devfd, 0);
+	OSERROR("mmap", super);
 
 	if (memcmp(super->magic,
 		   CACHEFS_SUPER_MAGIC,
-		   CACHEFS_SUPER_MAGIC_SIZE)!=0
+		   CACHEFS_SUPER_MAGIC_SIZE) != 0
 	    ) {
 		if (memcmp(super->magic,
 			   CACHEFS_SUPER_MAGIC_NEEDS_INIT,
-			   CACHEFS_SUPER_MAGIC_SIZE)!=0
+			   CACHEFS_SUPER_MAGIC_SIZE) != 0
 		    ) {
 			fprintf(stderr,"not a CacheFS filesystem");
 			exit(1);
@@ -110,8 +111,10 @@
 
 		printf("uninitialised CacheFS filesystem");
 
-		if (super->bix_ujournal!=2) exit(0);
-		if (super->bix_vjournal > super->bix_ujournal+65536/512) exit(0);
+		if (super->bix_ujournal != 2)
+			exit(0);
+		if (super->bix_vjournal > super->bix_ujournal + 65536 / 512)
+			exit(0);
 	}
 
 	numujnl = super->bix_vjournal - super->bix_ujournal;
@@ -119,14 +122,19 @@
 
 	jsof = super->bix_ujournal * (4096 / super->ujnl_rsize);
 
-	ujournal = mmap(NULL,numujnl,PROT_READ,MAP_PRIVATE,devfd,super->bix_ujournal*4096);
-	OSERROR("mmap",super);
+	ujournal = mmap(NULL,
+			numujnl,
+			PROT_READ,
+			MAP_PRIVATE,
+			devfd,
+			super->bix_ujournal * 4096);
+	OSERROR("mmap", super);
 
 	numujnl /= sizeof(struct sector);
 
 	printf("SECT"
 	       "    BATCH   "
-	       "   MARK    AUX"
+	       "   MARK    AUX "
 	       "  INODE    PGNUM  "
 	       "    INDEX:ENT "
 	       "    BLOCK+ENT "
@@ -139,7 +147,7 @@
 
 	printf("===="
 	       " ==========="
-	       " ========= ==="
+	       " ========= ===="
 	       " ======== ========"
 	       " ============="
 	       " ============="
@@ -150,23 +158,23 @@
 	       " ========"
 	       " ==================\n");
 
-	for (loop = delta>0 ? 0 : numujnl - 1;
-	     delta>0 ? loop<numujnl : loop >= 0;
+	for (loop = delta > 0 ? 0 : numujnl - 1;
+	     delta > 0 ? loop < numujnl : loop >= 0;
 	     loop += delta
 	     ) {
 		jentry = &ujournal[loop].jentry;
 
-		if (jentry->mark==CACHEFS_ONDISC_UJNL_NULL)
+		if (jentry->mark == CACHEFS_ONDISC_UJNL_NULL)
 			continue;
 
 		printf("%s%4u" NORMAL
 		       " " CYAN		"%5u"	GREY	"."	NORMAL	"%-5u"	NORMAL
-		       " "		"%s"		" %3d"
+		       " "		"%s"		" %4d"
 		       " " YELLOW	"%8x"	NORMAL	" %8u"
 		       " " YELLOW	"%8u"	GREY	":"	NORMAL	"%-4hu"
-		       " " YELLOW	"%8u"	GREY	"+"	NORMAL	"%-4hu"
-		       " " YELLOW	"%8u"	GREY	"+"	NORMAL	"%-4hu"
-		       " " YELLOW	"%8u"	GREY	"+"	NORMAL	"%-4hu"
+		       " " YELLOW	"%8d"	GREY	"+"	NORMAL	"%-4hu"
+		       " " YELLOW	"%8d"	GREY	"+"	NORMAL	"%-4hu"
+		       " " YELLOW	"%8d"	GREY	"+"	NORMAL	"%-4hu"
 		       " " YELLOW	"%4hu"	NORMAL	""
 		       " " GREEN	"%8u"	NORMAL	"[%-4hu]"
 		       " " CYAN		"%8u"	NORMAL	""
@@ -185,7 +193,8 @@
 		       jentry->count,
 		       jentry->alloc_cur,	jentry->alloc_leaf,
 		       jentry->recycle_cur,
-		       jentry->rcm_block,	jentry->rcm_ptrnext,	jentry->rcm_ptrstop
+		       jentry->rcm_block,	jentry->rcm_ptrnext,
+		       jentry->rcm_ptrstop
 		       );
 	}
 

Index: cachetest-main.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/cachetest-main.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- cachetest-main.c	10 Jun 2003 17:49:49 -0000	1.11
+++ cachetest-main.c	4 Jul 2003 09:04:44 -0000	1.12
@@ -16,9 +16,9 @@
 #include <linux/in.h>
 #include <linux/cachefs.h>
 
-#define kenter(FMT,...)	printk("==> %s("FMT")\n",__FUNCTION__,##__VA_ARGS__)
-#define kleave(FMT,...)	printk("<== %s()"FMT"\n",__FUNCTION__,##__VA_ARGS__)
-#define kdebug(FMT,...)	printk(FMT"\n",##__VA_ARGS__)
+#define kenter(FMT,...)	printk("==> %s("FMT")\n", __FUNCTION__ ,##__VA_ARGS__)
+#define kleave(FMT,...)	printk("<== %s()"FMT"\n", __FUNCTION__ ,##__VA_ARGS__)
+#define kdebug(FMT,...)	printk(FMT"\n" ,##__VA_ARGS__)
 
 static int cachefstest_init(void);
 static void cachefstest_exit(void);
@@ -63,7 +63,8 @@
 	.update			= cell_update,
 };
 
-static int afs_get_page_cookie(struct page *page, struct cachefs_page **_page_cookie);
+static int afs_get_page_cookie(struct page *page,
+			       struct cachefs_page **_page_cookie);
 
 static struct cachefs_netfs_operations cachetest_ops = {
 	.get_page_cookie	= afs_get_page_cookie,
@@ -77,7 +78,8 @@
 
 /* AFS cell
  * - this is an index containing volume location database references
- * - objects of this type will be typically embedded in the AFS fs's cell record structures
+ * - objects of this type will be typically embedded in the AFS fs's cell
+ *   record structures
  */
 static cachefs_match_val_t vldb_match(void *target, const void *entry);
 static void vldb_update(void *source, void *entry);
@@ -96,7 +98,8 @@
 
 /* AFS root volume
  * - this is an index containing file references
- * - objects of this type will be typically embedded in the AFS fs's volume record structures
+ * - objects of this type will be typically embedded in the AFS fs's volume
+ *   record structures
  */
 static cachefs_match_val_t file_match(void *target, const void *entry);
 static void file_update(void *source, void *entry);
@@ -115,7 +118,8 @@
 
 /* AFS root dir
  * - this is a file (hence .idef is NULL)
- * - objects of this type will be typically embedded in the AFS fs's inode structures
+ * - objects of this type will be typically embedded in the AFS fs's inode
+ *   structures
  */
 static struct afs_inode afs_root_dir = {
 	.fid		= 0x1234abcd,
@@ -133,11 +137,11 @@
 	.lock		= RW_LOCK_UNLOCKED,
 };
 
-static void afs_page_cache_write_complete(void *cookie_data, struct page *page, void *data,
-					  int error);
+static void afs_page_cache_write_complete(void *cookie_data, struct page *page,
+					  void *data, int error);
 
-static void afs_page_cache_read_complete(void *cookie_data, struct page *page, void *data,
-					 int error);
+static void afs_page_cache_read_complete(void *cookie_data, struct page *page,
+					 void *data, int error);
 
 /*****************************************************************************/
 /*
@@ -147,10 +151,11 @@
 {
 	int ret;
 
-	printk(KERN_INFO "cachefstest: general fs caching v0.1 tester registering\n");
+	printk(KERN_INFO
+	       "cachefstest: general fs caching v0.1 tester registering\n");
 
 	ret = -ENOMEM;
-	afs_data_page = alloc_pages(GFP_KERNEL,1);
+	afs_data_page = alloc_pages(GFP_KERNEL, 1);
 	if (!afs_data_page)
 		goto error;
 
@@ -158,10 +163,10 @@
 	afs_data_page->index  = 0;
 	afs_data_page2->index = 1;
 
-	memset(page_address(afs_data_page ),0xde,PAGE_SIZE);
-	memset(page_address(afs_data_page2),0xdf,PAGE_SIZE);
+	memset(page_address(afs_data_page ), 0xde, PAGE_SIZE);
+	memset(page_address(afs_data_page2), 0xdf, PAGE_SIZE);
 
-	ret = cachefs_register_netfs(&cachetest,&cachetest_cell_index_def);
+	ret = cachefs_register_netfs(&cachetest, &cachetest_cell_index_def);
 	if (ret<0)
 		goto error2;
 
@@ -187,40 +192,40 @@
 	ret = cachefs_read_or_alloc_page(afs_root_dir.cache,
 					 afs_data_page,
 					 afs_page_cache_read_complete,
-					 (void*)7,
+					 (void *) 7,
 					 GFP_KERNEL);
 
 	printk("\n### Read page 2\n");
 	ret = cachefs_read_or_alloc_page(afs_root_dir.cache,
 					 afs_data_page2,
 					 afs_page_cache_read_complete,
-					 (void*)9,
+					 (void *) 9,
 					 GFP_KERNEL);
 
 	printk("\n### Write page\n");
 	ret = cachefs_write_page(afs_root_dir.cache,
 				 afs_data_page,
 				 afs_page_cache_write_complete,
-				 (void*)3,
+				 (void *) 3,
 				 GFP_KERNEL);
 
-	printk("\nresult = %d\n",ret);
+	printk("\nresult = %d\n", ret);
 
 	printk("\n### Write page2\n");
 	ret = cachefs_write_page(afs_root_dir.cache,
 				 afs_data_page2,
 				 afs_page_cache_write_complete,
-				 (void*)23,
+				 (void *) 23,
 				 GFP_KERNEL);
 
-	printk("\nresult = %d\n",ret);
+	printk("\nresult = %d\n", ret);
 
 	return 0;
 
  error2:
-	__free_pages(afs_data_page,1);
+	__free_pages(afs_data_page, 1);
  error:
-	printk(KERN_ERR "cachefstest: failed to register: %d\n",ret);
+	printk(KERN_ERR "cachefstest: failed to register: %d\n", ret);
 	return ret;
 } /* end cachefstest_init() */
 
@@ -230,16 +235,17 @@
  */
 static void cachefstest_exit(void)
 {
-	printk(KERN_INFO "cachefstest: general fs caching v0.1 tester unregistering.\n");
+	printk(KERN_INFO
+	       "cachefstest: general fs caching v0.1 tester unregistering.\n");
 
-	cachefs_uncache_page(afs_root_dir.cache,afs_data_page);
-	cachefs_uncache_page(afs_root_dir.cache,afs_data_page2);
+	cachefs_uncache_page(afs_root_dir.cache, afs_data_page);
+	cachefs_uncache_page(afs_root_dir.cache, afs_data_page2);
 
-	__free_pages(afs_data_page,1);
+	__free_pages(afs_data_page, 1);
 
-	cachefs_relinquish_cookie(afs_root_dir.cache,0);
-	cachefs_relinquish_cookie(afs_root_volume.cache,0);
-	cachefs_relinquish_cookie(afs_mycell.cache,0);
+	cachefs_relinquish_cookie(afs_root_dir.cache, 0);
+	cachefs_relinquish_cookie(afs_root_volume.cache, 0);
+	cachefs_relinquish_cookie(afs_mycell.cache, 0);
 	cachefs_unregister_netfs(&cachetest);
 
 } /* end cachefstest_exit() */
@@ -254,7 +260,7 @@
 
 	kenter("");
 
-	if (strncmp(entry,cell->name,sizeof(cell->name))==0)
+	if (strncmp(entry, cell->name, sizeof(cell->name)) == 0)
 		return CACHEFS_MATCH_SUCCESS;
 
 	return CACHEFS_MATCH_FAILED;
@@ -268,9 +274,9 @@
 {
 	struct afs_cell *cell = source;
 
-	kenter("%p,%p",source,entry);
+	kenter("%p,%p", source, entry);
 
-	strncpy(entry,cell->name,sizeof(cell->name));
+	strncpy(entry, cell->name, sizeof(cell->name));
 
 } /* end cell_update() */
 
@@ -284,7 +290,7 @@
 
 	kenter("");
 
-	if (strncmp(entry,volume->name,sizeof(volume->name))==0)
+	if (strncmp(entry, volume->name, sizeof(volume->name)) == 0)
 		return CACHEFS_MATCH_SUCCESS;
 
 	return CACHEFS_MATCH_FAILED;
@@ -298,9 +304,9 @@
 {
 	struct afs_volume *volume = source;
 
-	kenter("%p,%p",source,entry);
+	kenter("%p,%p", source, entry);
 
-	strncpy(entry,volume->name,sizeof(volume->name));
+	strncpy(entry, volume->name, sizeof(volume->name));
 
 } /* end vldb_update() */
 
@@ -315,7 +321,7 @@
 
 	kenter("");
 
-	if (memcmp(entry,&fid,sizeof(fid))==0)
+	if (memcmp(entry, &fid, sizeof(fid)) == 0)
 		return CACHEFS_MATCH_SUCCESS;
 
 	return CACHEFS_MATCH_FAILED;
@@ -330,9 +336,9 @@
 	struct afs_inode *inode = source;
 	u_int32_t fid = htonl(inode->fid);
 
-	kenter("%p,%p",source,entry);
+	kenter("%p,%p", source, entry);
 
-	memcpy(entry,&fid,sizeof(fid));
+	memcpy(entry, &fid, sizeof(fid));
 
 } /* end file_update() */
 
@@ -340,10 +346,10 @@
 /*
  * 
  */
-static void afs_page_cache_write_complete(void *cookie_data, struct page *page, void *data,
-					  int error)
+static void afs_page_cache_write_complete(void *cookie_data, struct page *page,
+					  void *data, int error)
 {
-	kenter("%p,%p,%p,%d",cookie_data,page,data,error);
+	kenter("%p,%p,%p,%d", cookie_data, page, data, error);
 
 } /* end afs_page_cache_write_complete() */
 
@@ -351,10 +357,10 @@
 /*
  * 
  */
-static void afs_page_cache_read_complete(void *cookie_data, struct page *page, void *data,
-					 int error)
+static void afs_page_cache_read_complete(void *cookie_data, struct page *page,
+					 void *data, int error)
 {
-	kenter("%p,%p,%p,%d",cookie_data,page,data,error);
+	kenter("%p,%p,%p,%d", cookie_data, page, data, error);
 
 } /* end afs_page_cache_write_complete() */
 
@@ -362,18 +368,19 @@
 /*
  * get a page cookie for the specified page
  */
-static int afs_get_page_cookie(struct page *page, struct cachefs_page **_page_cookie)
+static int afs_get_page_cookie(struct page *page,
+			       struct cachefs_page **_page_cookie)
 {
-	kenter("%p,",page);
+	kenter("%p,", page);
 
 	if (page == afs_data_page) {
 		*_page_cookie = &afs_data_page_cookie;
-		kleave(" = 0 [%p]",*_page_cookie);
+		kleave(" = 0 [%p]", *_page_cookie);
 		return 0;
 	}
 	else if (page == afs_data_page2) {
 		*_page_cookie = &afs_data_page2_cookie;
-		kleave(" = 0 [%p]",*_page_cookie);
+		kleave(" = 0 [%p]", *_page_cookie);
 		return 0;
 	}
 

Index: cachefs-layout.h
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/cachefs-layout.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- cachefs-layout.h	2 Jun 2003 09:17:42 -0000	1.25
+++ cachefs-layout.h	4 Jul 2003 09:04:44 -0000	1.26
@@ -19,7 +19,6 @@
 	CACHEFS_INO_METADATA		= 0x00000001,
 	CACHEFS_INO_FSDEF_CATALOGUE,
 	CACHEFS_INO_ROOTDIR		= CACHEFS_INO_FSDEF_CATALOGUE,
-	CACHEFS_INO_WIBBLE,		/* TODO: remove */
 	CACHEFS_INO__FIRST_FILE,
 
 	/* virtual files all have the top bit set */
@@ -33,7 +32,8 @@
 /*****************************************************************************/
 /*
  * cache superblock block layout
- * - the blockdev is prepared for initialisation by 'echo "cachefs___" >/dev/hdaXX' before mounting
+ * - the blockdev is prepared for initialisation by
+ *   'echo "cachefs___" >/dev/hdaXX' before mounting
  * - when initialised, the magic number is changed to "cachefsrdy"
  */
 struct cachefs_ondisc_superblock
@@ -85,14 +85,17 @@
 	};
 };
 
+#define CACHEFS_ONDISC_INDEX_ENTRY_MINSIZE \
+	(sizeof(struct cachefs_ondisc_index_entry) + sizeof(u_int32_t))
+
 /*****************************************************************************/
 /*
  * 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
+ *   - 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
  */
@@ -133,26 +136,6 @@
 	cachefs_blockix_t		direct[0];	/* direct block ptrs */
 };
 
-//#define CACHEFS_ONDISC_STORAGE_DIRECT
-//	((CACHEFS_ONDISC_STORAGE_RECSIZE-sizeof(struct cachefs_ondisc_storage)) /
-//	sizeof(cachefs_blockix_t))
-
-//#define CACHEFS_STORAGE_PER_PAGE	(PAGE_SIZE / CACHEFS_ONDISC_STORAGE_RECSIZE)
-
-//#define CACHEFS_POINTERS_PER_PAGE	(PAGE_SIZE / sizeof(cachefs_blockix_t))
-
-/* #define CACHEFS_ONDISC_STORAGE_TRIPLE_INDR_OFFS \ */
-/* 	offsetof(struct cachefs_ondisc_storage,triple_indirect) */
-
-/* #define CACHEFS_ONDISC_STORAGE_DOUBLE_INDR_OFFS \ */
-/* 	offsetof(struct cachefs_ondisc_storage,double_indirect) */
-
-/* #define CACHEFS_ONDISC_STORAGE_SINGLE_INDR_OFFS \ */
-/* 	offsetof(struct cachefs_ondisc_storage,single_indirect) */
-
-/* #define CACHEFS_ONDISC_STORAGE_DIRECT_OFFS \ */
-/* 	offsetof(struct cachefs_ondisc_storage,direct) */
-
 /*****************************************************************************/
 /*
  * on-disc cached network filesystem definition record
@@ -166,7 +149,8 @@
 
 /*****************************************************************************/
 /*
- * Free blocks are kept in pair of a very one sided trees (more horsetail plants than trees)
+ * Free blocks are kept in pair of a very one sided trees (more horsetail
+ * plants than trees)
  *
  *        +---------+    +---------+    +---------+    +---------+
  * stk--->|         |--->|         |--->|         |--->|         |---> NULL
@@ -179,18 +163,14 @@
  * - each free block is on one of two trees, both pointed to by the ujournal:
  *   - the "recycling stack" - all newly freed blocks end up on here
  *   - the "alloc stack" - all allocations are popped off here
- *   - when the alloc stack is empty, the recycling stack is transferred into it
- * - the front node on the alloc stack is the current source of block allocations
- *   - when all a node's leaves have been allocated, then the node itself will be allocated
- *   - leaves are consumed in a rotating sector pattern to avoid waiting for BIO completion as much
- *     as possible
- * - the front node on the recycling stack is the current sink of recycled blocks
- *   - leaves are inserted in a rotating sector pattern to avoid waiting for BIO completion as much
- *     as possible
- */
-
-/*
- * on-disc free-block tree node format
+ *   - when the alloc stack is empty, the recycling stack is transferred into
+ *     it
+ * - the front node on the alloc stack is the current source of block
+ *   allocations
+ *   - when all a node's leaves have been allocated, then the node itself will
+ *     be allocated
+ * - the front node on the recycling stack is the current sink of recycled
+ *   blocks
  */
 struct cachefs_ondisc_free_node
 {
@@ -200,7 +180,7 @@
 };
 
 #define CACHEFS_ONDISC_LEAVES_PER_FREE_NODE \
-	((PAGE_SIZE-sizeof(struct cachefs_ondisc_free_node)) / sizeof(cachefs_blockix_t))
+	((PAGE_SIZE - sizeof(struct cachefs_ondisc_free_node)) / sizeof(cachefs_blockix_t))
 
 /*****************************************************************************/
 /*
@@ -210,10 +190,10 @@
  *   - ACKs specify everything between "index" & "block" as being complete
  *   - serial numbers can wrap, but can't go into window of un-ACK'd marks
  * - journal slots are the size of a sector (blockdev block size)
- *   - this means that two adjacent marks are made on separate sectors, and so the second doesn't
- *     have to wait for the first to be written to disc
- * - the current slot allocation point is not permitted to lap the currently un-ACK'd slots - the
- *   requestor must wait
+ *   - this means that two adjacent marks are made on separate sectors, and so
+ *     the second doesn't have to wait for the first to be written to disc
+ * - the current slot allocation point is not permitted to lap the currently
+ *   un-ACK'd slots - the requestor must wait
  */
 enum cachefs_ondisc_ujnl_mark {
 	/* NULL mark */
@@ -261,13 +241,13 @@
 	 */
 	CACHEFS_ONDISC_UJNL_RECYC_MAKEREADY,
 
-	/* inode record being allocated */
-	CACHEFS_ONDISC_UJNL_INODE_ALLOCING,
+	/* data file being created */
+	CACHEFS_ONDISC_UJNL_INODE_CREATING,
 
-	/* inode record being updated */
+	/* data file being updated */
 	CACHEFS_ONDISC_UJNL_INODE_UPDATING,
 
-	/* inode being deleted */
+	/* data file being deleted */
 	CACHEFS_ONDISC_UJNL_INODE_DELETING,
 
 	/* inode being marked for reclamation
@@ -341,9 +321,9 @@
 	/* index file being extended (as for data block allocation) */
 	CACHEFS_ONDISC_UJNL_INDEX_EXTENDING,
 
-	/* index entry being allocated
-	 * - index	= index being allocated from
-	 * - ixentry	= index entry being allocated
+	/* index file being created
+	 * - index	= parent index being attached to
+	 * - ixentry	= entry in parent index
 	 * - pgnum	= page in file holding index entry being allocated
 	 * - block	= block holding index entry being allocated
 	 * - entry	= offset of entry in block
@@ -351,13 +331,13 @@
 	 * - upblock	= next free index file entry
 	 * - count	= size of entry in block
 	 */
-	CACHEFS_ONDISC_UJNL_INDEX_ALLOCING,
+	CACHEFS_ONDISC_UJNL_INDEX_CREATING,
 
 	/* index entry being modified */
 	CACHEFS_ONDISC_UJNL_INDEX_MODIFYING,
 
-	/* index entry being freed */
-	CACHEFS_ONDISC_UJNL_INDEX_FREEING,
+	/* index file being deleted */
+	CACHEFS_ONDISC_UJNL_INDEX_DELETING,
 
 	CACHEFS_ONDISC_UJNL__LAST
 } __attribute__((packed));
@@ -407,7 +387,8 @@
 /*****************************************************************************/
 /*
  * on-disc block validity journal
- * - blocks noted here don't yet have valid data downloaded from the remote server
+ * - blocks noted here don't yet have valid data downloaded from the remote
+ *   server
  * - unused entries have ino==0
  * - changed under the influence of the u-journal
  */
@@ -418,7 +399,7 @@
 };
 
 #define CACHEFS_ONDISC_VJNL_ENTPERPAGE	\
-	(PAGE_SIZE / sizeof(struct cachefs_ondisc_writeback_journal))
+	(PAGE_SIZE / sizeof(struct cachefs_ondisc_validity_journal))
 
 #define CACHEFS_ONDISC_VJNL_SIZE	16 /* blocks */
 
@@ -429,9 +410,6 @@
 /*
  * on-disc writeback journal
  * - records pages that are pending being written back to the server
- * - journal slots are allocated in a round-robin fashion, going through slot 0 in every sector,
- *   then slot 1 in every sector, then slot 2... this means that two adjacent marks are made on
- *   separate sectors, and so the second doesn't have to wait for the first to be written to disc
  */
 struct cachefs_ondisc_writeback_journal
 {

Index: cachefs-int.h
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/cachefs-int.h,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- cachefs-int.h	11 Jun 2003 11:59:52 -0000	1.36
+++ cachefs-int.h	4 Jul 2003 09:04:44 -0000	1.37
@@ -51,8 +51,8 @@
 
 extern int cachefs_io_dummy_filler(void *data, struct page *page);
 
-extern int cachefs_get_block(struct inode *inode, struct page *page, struct cachefs_page *pageio,
-			     int create);
+extern int cachefs_get_block(struct inode *inode, struct page *page,
+			     struct cachefs_page *pageio, int create);
 
 struct cachefs_reclaimable {
 	unsigned	ino;
@@ -193,7 +193,8 @@
 	struct cachefs_ondisc_superblock *layout;
 };
 
-extern void cachefs_add_cache(struct cachefs_super *super, struct cachefs_search_result *srch);
+extern void cachefs_add_cache(struct cachefs_super *super,
+			      struct cachefs_search_result *srch);
 extern void cachefs_withdraw_cache(struct cachefs_super *super);
 
 extern void cachefs_recycle_unready_blocks(struct cachefs_super *super);
@@ -251,7 +252,8 @@
 
 extern kmem_cache_t *cachefs_block_jar;
 
-extern void cachefs_block_init_once(void *_block, kmem_cache_t *cachep, unsigned long flags);
+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,
@@ -283,9 +285,11 @@
 				 struct cachefs_block *block,
 				 struct page **_page);
 
-extern int cachefs_block_cow(struct cachefs_super *super, struct cachefs_block *block);
+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)
+static inline
+struct cachefs_block *cachefs_block_get(struct cachefs_block *block)
 {
 	atomic_inc(&block->usage);
 	return block;
@@ -298,12 +302,13 @@
 	if (block) {
 		int usage = atomic_read(&block->usage);
 
-		if ((usage&0xffffff00)==0x6b6b6b00) {
-			printk("\ncachefs_block_put(%p{u=%d})\n",block,usage);
+		if ((usage & 0xffffff00) == 0x6b6b6b00) {
+			printk("\ncachefs_block_put(%p{u=%d})\n",
+			       block, usage);
 			BUG();
 		}
 
-		BUG_ON(usage<=0);
+		BUG_ON(usage <= 0);
 		if (atomic_dec_and_test(&block->usage))
 			__cachefs_block_put(block);
 	}
@@ -315,9 +320,10 @@
 	return ((struct cachefs_page *) page->private)->mapped_block;
 }
 
-static inline void cachefs_page_modify(struct cachefs_super *super, struct page **page)
+static inline void cachefs_page_modify(struct cachefs_super *super,
+				       struct page **page)
 {
-	cachefs_block_modify(super,__cachefs_get_page_block(*page),page);
+	cachefs_block_modify(super, __cachefs_get_page_block(*page), page);
 }
 
 extern void cachefs_block_withdraw(struct cachefs_super *super);
@@ -326,8 +332,8 @@
 /*
  * 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
- *   space
+ * - a request to cache a file may or may not be honoured, subject to
+ *   constraints such as disc space
  * - indexes files are created on disc just-in-time
  */
 struct cachefs_cookie
@@ -384,9 +390,11 @@
 extern struct inode_operations cachefs_status_inode_operations;
 extern struct file_operations cachefs_status_file_operations;
 
-#define CACHEFS_FS_I(inode) container_of((inode),struct cachefs_inode,vfs_inode)
+#define CACHEFS_FS_I(inode) \
+	container_of((inode), struct cachefs_inode, vfs_inode)
 
-extern int cachefs_iget(struct cachefs_super *super, ino_t ino, struct cachefs_inode **_inode);
+extern int cachefs_iget(struct cachefs_super *super, ino_t ino,
+			struct cachefs_inode **_inode);
 extern void cachefs_write_inode(struct inode *_inode, int sync);
 extern void cachefs_clear_inode(struct inode *vfs_inode);
 
@@ -402,7 +410,8 @@
 		iput(&inode->vfs_inode);
 }
 
-extern int cachefs_get_page(struct cachefs_inode *inode, unsigned index, struct page **_page);
+extern int cachefs_get_page(struct cachefs_inode *inode, unsigned index,
+			    struct page **_page);
 
 static inline void cachefs_put_page(struct page *page)
 {
@@ -428,7 +437,8 @@
 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);
+	cachefs_block_modify(inode->metadata->super, inode->metadata,
+			     &inode->metadata_page);
 	return kmap(inode->metadata_page) + inode->metadata_offset;
 }
 
@@ -452,7 +462,7 @@
 
 extern int cachefs_index_zap(struct cachefs_super *super);
 
-extern int cachefs_replay_ujnl_inode_allocing(struct cachefs_super *super,
+extern int cachefs_replay_ujnl_inode_creating(struct cachefs_super *super,
 					      struct cachefs_ondisc_update_journal *jentry);
 extern int cachefs_replay_ujnl_inode_updating(struct cachefs_super *super,
 					      struct cachefs_ondisc_update_journal *jentry);
@@ -464,12 +474,12 @@
 						struct cachefs_ondisc_update_journal *jentry);
 extern int cachefs_replay_ujnl_index_extending(struct cachefs_super *super,
 					       struct cachefs_ondisc_update_journal *jentry);
-extern int cachefs_replay_ujnl_index_allocing(struct cachefs_super *super,
+extern int cachefs_replay_ujnl_index_creating(struct cachefs_super *super,
 					      struct cachefs_ondisc_update_journal *jentry);
 extern int cachefs_replay_ujnl_index_modifying(struct cachefs_super *super,
 					       struct cachefs_ondisc_update_journal *jentry);
-extern int cachefs_replay_ujnl_index_freeing(struct cachefs_super *super,
-					     struct cachefs_ondisc_update_journal *jentry);
+extern int cachefs_replay_ujnl_index_deleting(struct cachefs_super *super,
+					      struct cachefs_ondisc_update_journal *jentry);
 
 extern int cachefs_replay_ujnl_data_allocing(struct cachefs_super *super,
 					     struct cachefs_ondisc_update_journal *jentry);
@@ -500,8 +510,10 @@
 	unsigned		upentry;	/* offset in upblock at which pointer stored */
 };
 
-extern int cachefs_vj_alloc(struct cachefs_transaction *trans, struct cachefs_inode *inode);
-extern void cachefs_vj_release(struct cachefs_super *super, struct cachefs_vj_entry *vjentry);
+extern int cachefs_vj_alloc(struct cachefs_transaction *trans,
+			    struct cachefs_inode *inode);
+extern void cachefs_vj_release(struct cachefs_super *super,
+			       struct cachefs_vj_entry *vjentry);
 extern void cachefs_vj_cancel(struct cachefs_vj_entry *vjentry);
 extern void cachefs_vj_write_complete(struct cachefs_block *block);
 extern void cachefs_vj_note_write_completion(struct cachefs_super *super);
@@ -551,8 +563,9 @@
 	struct cachefs_trans_effect	effects[CACHEFS_EFFECTS_PER_TRANS];
 };
 
-extern struct cachefs_transaction *cachefs_trans_alloc(struct cachefs_super *super,
-						       unsigned long gfp);
+extern
+struct cachefs_transaction *cachefs_trans_alloc(struct cachefs_super *super,
+						unsigned long gfp);
 
 extern void __cachefs_trans_put(struct cachefs_transaction *trans);
 static inline void cachefs_trans_put(struct cachefs_transaction *trans)
@@ -566,16 +579,18 @@
 					unsigned offset,
 					unsigned size);
 
-static inline void cachefs_trans_affects_page(struct cachefs_transaction *trans,
-					      struct cachefs_page *pageio,
-					      unsigned offset,
-					      unsigned size)
+static inline
+void cachefs_trans_affects_page(struct cachefs_transaction *trans,
+				struct cachefs_page *pageio,
+				unsigned offset,
+				unsigned size)
 {
-	cachefs_trans_affects_block(trans,pageio->mapped_block,offset,size);
+	cachefs_trans_affects_block(trans, pageio->mapped_block, offset, size);
 }
 
-static inline void cachefs_trans_affects_inode(struct cachefs_transaction *trans,
-					       struct cachefs_inode *inode)
+static inline
+void cachefs_trans_affects_inode(struct cachefs_transaction *trans,
+				 struct cachefs_inode *inode)
 {
 	struct cachefs_super *super = inode->vfs_inode.i_sb->s_fs_info;
 
@@ -588,8 +603,11 @@
 static inline void cachefs_trans_affects_super(struct cachefs_transaction *trans)
 {
 	struct cachefs_super *super = trans->super;
-	cachefs_trans_affects_page(trans,__cachefs_page_get_private(virt_to_page(super->layout)),
-				   0,super->sb->s_blocksize);
+	cachefs_trans_affects_page(trans,
+				   __cachefs_page_get_private(
+					   virt_to_page(super->layout)),
+				   0,
+				   super->sb->s_blocksize);
 }
 
 extern int  cachefs_trans_mark(struct cachefs_transaction *trans);
@@ -604,7 +622,8 @@
 	CACHEFS_TRANS_SYNC_WAIT_FOR_ACK,	/* wait until ujnl ACK mark is written */
 } cachefs_trans_syncwt_t;
 
-extern void cachefs_trans_sync(struct cachefs_super *super, cachefs_trans_syncwt_t wait);
+extern void cachefs_trans_sync(struct cachefs_super *super,
+			       cachefs_trans_syncwt_t wait);
 
 extern int  cachefs_ujnl_replay(struct cachefs_super *super);
 
@@ -612,7 +631,8 @@
 /*
  * debug tracing
  */
-#define dbgprintk(FMT,...) printk("[%-6.6s] "FMT"\n",current->comm ,##__VA_ARGS__)
+#define dbgprintk(FMT,...) \
+	printk("[%-6.6s] "FMT"\n",current->comm ,##__VA_ARGS__)
 #define _dbprintk(FMT,...) do { } while(0)
 
 #define kenter(FMT,...)	dbgprintk("==> %s("FMT")",__FUNCTION__ ,##__VA_ARGS__)
@@ -631,13 +651,15 @@
 		  );							\
 } while(0)
 
-#define dbgpgfree(PAGE)								\
-do {										\
-	if ((PAGE))								\
-		_dbprintk("PGFREE %s:%d: %p {%lx,%lu}\n",			\
-			  __FILE__,__LINE__,					\
-			  (PAGE),(PAGE)->mapping->host->i_ino,(PAGE)->index	\
-			  );							\
+#define dbgpgfree(PAGE)						\
+do {								\
+	if ((PAGE))						\
+		_dbprintk("PGFREE %s:%d: %p {%lx,%lu}\n",	\
+			  __FILE__,__LINE__,			\
+			  (PAGE),				\
+			  (PAGE)->mapping->host->i_ino,		\
+			  (PAGE)->index				\
+			  );					\
 } while(0)
 
 #ifdef __KDEBUG

Index: block.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/block.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- block.c	10 Jun 2003 17:49:49 -0000	1.7
+++ block.c	4 Jul 2003 09:04:44 -0000	1.8
@@ -23,8 +23,9 @@
 {
 	struct cachefs_block *block = _block;
 
-	if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == SLAB_CTOR_CONSTRUCTOR) {
-		memset(block,0,sizeof(*block));
+	if ((flags & (SLAB_CTOR_VERIFY | SLAB_CTOR_CONSTRUCTOR)) ==
+	    SLAB_CTOR_CONSTRUCTOR) {
+		memset(block, 0, sizeof(*block));
 
 		rwlock_init(&block->ref_lock);
 		init_waitqueue_head(&block->writewq);
@@ -37,22 +38,21 @@
 	struct cachefs_page *pageio;
 	int ret;
 
-	_enter("%p,{%lu}",data,page->index);
+	_enter("%p,{%lu}", data, page->index);
 
 	/* we need somewhere to note journal ACKs that need to be made */
-	ret = cachefs_page_get_private(page,&pageio,GFP_KERNEL);
-	if (ret<0)
+	ret = cachefs_page_get_private(page, &pageio, GFP_KERNEL);
+	if (ret < 0)
 		return ret;
 
 	pageio->mapped_block = data;
 	cachefs_block_get(pageio->mapped_block);
 
-	memset(kmap(page),0,PAGE_SIZE);
+	memset(kmap(page), 0, PAGE_SIZE);
 	kunmap(page);
 	flush_dcache_page(page);
 
 	SetPageUptodate(page);
-
 	unlock_page(page);
 	return 0;
 }
@@ -70,13 +70,13 @@
 
 	struct cachefs_block *block2;
 
-	_enter(",%u,",block->bix);
+	_enter(",%u,", block->bix);
 
 	/* don't do anything if already associated as we want */
 	block2 = pageio->mapped_block;
 	if (block2) {
-		if (block2==block) {
-			if (block->page==page) {
+		if (block2 == block) {
+			if (block->page == page) {
 				_leave(" = 0 [assoc preset]");
 				return 0;
 			}
@@ -90,11 +90,11 @@
 	}
 
 	/* get the page alloc lock for this block */
-	if (test_and_set_bit(CACHEFS_BLOCK_ALLOC,&block->flags)) {
+	if (test_and_set_bit(CACHEFS_BLOCK_ALLOC, &block->flags)) {
 		set_current_state(TASK_INTERRUPTIBLE);
-		add_wait_queue(&block->writewq,&myself);
+		add_wait_queue(&block->writewq, &myself);
 
-		while (test_and_set_bit(CACHEFS_BLOCK_ALLOC,&block->flags)) {
+		while (test_and_set_bit(CACHEFS_BLOCK_ALLOC, &block->flags)) {
 			if (signal_pending(current))
 				break;
 
@@ -103,7 +103,7 @@
 		}
 
 		set_current_state(TASK_RUNNING);
-		remove_wait_queue(&block->writewq,&myself);
+		remove_wait_queue(&block->writewq, &myself);
 
 		if (signal_pending(current))
 			goto intr;
@@ -141,15 +141,16 @@
 
 	_enter(",%u,,",bix);
 
-	if (_block) *_block = NULL;
+	if (_block)
+		*_block = NULL;
 
 	/* get the block definition */
-	ret = cachefs_block_insert(super,bix,&block);
-	if (ret<0)
+	ret = cachefs_block_insert(super, bix, &block);
+	if (ret < 0)
 		goto error;
 
-	ret = cachefs_block_set(super,block,page,pageio);
-	if (ret<0)
+	ret = cachefs_block_set(super, block, page, pageio);
+	if (ret < 0)
 		goto error2;
 
 	if (_block) {
@@ -160,7 +161,7 @@
  error2:
 	cachefs_block_put(block);
  error:
-	_leave(" = %d",ret);
+	_leave(" = %d", ret);
 	return ret;
 } /* end cachefs_block_set2() */
 
@@ -175,32 +176,35 @@
 		       struct cachefs_block **_block,
 		       struct page **_page)
 {
-	DECLARE_WAITQUEUE(myself,current);
-
 	struct address_space *mapping;
 	struct cachefs_block *block;
 	struct page *page;
 	filler_t *filler;
 	int ret;
 
-	_enter(",%lx,%u,%d,,",inode?inode->vfs_inode.i_ino:CACHEFS_INO_MISC,bix,wipe);
+	DECLARE_WAITQUEUE(myself, current);
+
+	_enter(",%lx,%u,%d,,",
+	       inode ? inode->vfs_inode.i_ino : CACHEFS_INO_MISC, bix, wipe);
 
-	if (_block)	*_block  = NULL;
-	if (_page)	*_page   = NULL;
+	if (_block)
+		*_block = NULL;
+	if (_page)
+		*_page = NULL;
 
 	/* get the block definition */
-	ret = cachefs_block_insert(super,bix,&block);
-	if (ret<0) {
-		_leave(" = %d",ret);
+	ret = cachefs_block_insert(super, bix, &block);
+	if (ret < 0) {
+		_leave(" = %d", ret);
 		return ret;
 	}
 
 	/* get the page alloc lock for this block */
-	if (test_and_set_bit(CACHEFS_BLOCK_ALLOC,&block->flags)) {
+	if (test_and_set_bit(CACHEFS_BLOCK_ALLOC, &block->flags)) {
 		set_current_state(TASK_INTERRUPTIBLE);
-		add_wait_queue(&block->writewq,&myself);
+		add_wait_queue(&block->writewq, &myself);
 
-		while (test_and_set_bit(CACHEFS_BLOCK_ALLOC,&block->flags)) {
+		while (test_and_set_bit(CACHEFS_BLOCK_ALLOC, &block->flags)) {
 			if (signal_pending(current))
 				break;
 
@@ -209,7 +213,7 @@
 		}
 
 		set_current_state(TASK_RUNNING);
-		remove_wait_queue(&block->writewq,&myself);
+		remove_wait_queue(&block->writewq, &myself);
 
 		if (signal_pending(current))
 			goto intr;
@@ -217,13 +221,15 @@
 
 	/* get a page for it if it doesn't already exist */
 	if (!block->page) {
-		/* if the block is marked as currently undergoing writeback then there was an
-		 * ENOMEM encountered whilst trying to COW the block */
+		/* if the block is marked as currently undergoing writeback
+		 * then there was an ENOMEM encountered whilst trying to COW
+		 * the block */
 		if (test_bit(CACHEFS_BLOCK_WRITEBACK,&block->flags)) {
 			set_current_state(TASK_INTERRUPTIBLE);
 			add_wait_queue(&block->writewq,&myself);
 
-			while (test_bit(CACHEFS_BLOCK_WRITEBACK,&block->flags)) {
+			while (test_bit(CACHEFS_BLOCK_WRITEBACK,
+					&block->flags)) {
 				if (signal_pending(current))
 					break;
 
@@ -232,24 +238,27 @@
 			}
 
 			set_current_state(TASK_RUNNING);
-			remove_wait_queue(&block->writewq,&myself);
+			remove_wait_queue(&block->writewq, &myself);
 
 			if (signal_pending(current))
 				goto intr2;
 		}
 
 		/* load the page into the page cache */
-		mapping = (inode ? &inode->vfs_inode : super->imisc)->i_mapping;
+		if (inode)
+			mapping = inode->vfs_inode.i_mapping;
+		else
+			mapping = super->imisc->i_mapping;
 
-		filler = (filler_t*) mapping->a_ops->readpage;
+		filler = (filler_t *) mapping->a_ops->readpage;
 		if (wipe)
 			filler = cachefs_block_dummy_filler;
 
-		page = read_cache_page(mapping,bix,filler,block);
+		page = read_cache_page(mapping, bix, filler, block);
 
 		if (IS_ERR(page)) {
 			cachefs_block_put(block);
-			_leave(" = %ld",PTR_ERR(page));
+			_leave(" = %ld", PTR_ERR(page));
 			return PTR_ERR(page);
 		}
 
@@ -260,7 +269,7 @@
 		get_page(page);
 	}
 
-	clear_bit(CACHEFS_BLOCK_ALLOC,&block->flags);
+	clear_bit(CACHEFS_BLOCK_ALLOC, &block->flags);
 	wake_up_all(&block->writewq);
 
 	if (_block) {
@@ -283,7 +292,7 @@
 	return 0;
 
  intr2:
-	clear_bit(CACHEFS_BLOCK_ALLOC,&block->flags);
+	clear_bit(CACHEFS_BLOCK_ALLOC, &block->flags);
 	wake_up_all(&block->writewq);
  intr:
 	cachefs_block_put(block);
@@ -297,31 +306,31 @@
  */
 int cachefs_block_cow(struct cachefs_super *super, struct cachefs_block *block)
 {
-	DECLARE_WAITQUEUE(myself,current);
-
 //	struct address_space *mapping;
 	struct page *page; //, *newpage;
 	filler_t filler;
 //	int ret;
 
-	_enter(",%u",block->bix);
+	DECLARE_WAITQUEUE(myself, current);
+
+	_enter(",%u", block->bix);
 
 	/* get the page alloc lock for this block */
-	if (test_and_set_bit(CACHEFS_BLOCK_ALLOC,&block->flags)) {
+	if (test_and_set_bit(CACHEFS_BLOCK_ALLOC, &block->flags)) {
 		set_current_state(TASK_UNINTERRUPTIBLE);
-		add_wait_queue(&block->writewq,&myself);
+		add_wait_queue(&block->writewq, &myself);
 
-		while (test_and_set_bit(CACHEFS_BLOCK_ALLOC,&block->flags)) {
+		while (test_and_set_bit(CACHEFS_BLOCK_ALLOC, &block->flags)) {
 			schedule();
 			set_current_state(TASK_UNINTERRUPTIBLE);
 		}
 
 		set_current_state(TASK_RUNNING);
-		remove_wait_queue(&block->writewq,&myself);
+		remove_wait_queue(&block->writewq, &myself);
 	}
 
 	/* duplicate the page if it's flagged copy-on-write */
-	if (test_bit(CACHEFS_BLOCK_COW,&block->flags)) {
+	if (test_bit(CACHEFS_BLOCK_COW, &block->flags)) {
 		BUG();
 #if 0
 		struct cachefs_page *newpageio;
@@ -332,27 +341,30 @@
 		if (!newpage)
 			goto nomem;
 
-		if (cachefs_get_page_private(newpage,&newpageio,mapping->gfp_mask)<0)
+		if (cachefs_get_page_private(newpage, &newpageio,
+					     mapping->gfp_mask) < 0)
 			goto nomem_page;
 
 		newpageio->mapped_block =
-			cachefs_block_get(__cachefs_get_page_block(block->page));
+			cachefs_block_get(
+				__cachefs_get_page_block(block->page));
 
-		copy_page(kmap(newpage),kmap(block->page));
+		copy_page(kmap(newpage), kmap(block->page));
 		kunmap(newpage);
 		kunmap(block->page);
 
 		/* exchange the old page for the new page */
-		page = xchg(&block->page,NULL);
+		page = xchg(&block->page, NULL);
 
-		mapping->a_ops->releasepage(page,GFP_NOFS);
+		mapping->a_ops->releasepage(page, GFP_NOFS);
 		remove_from_page_cache(page);
 		page_cache_release(page);
 		page = NULL;
 
-		ret = add_to_page_cache_lru(newpage,mapping,block->bix,GFP_KERNEL);
+		ret = add_to_page_cache_lru(newpage, mapping, block->bix,
+					    GFP_KERNEL);
 		if (ret<0) {
-			BUG_ON(ret==-EEXIST);
+			BUG_ON(ret == -EEXIST);
 			page_cache_release(newpage);
 			return ret;
 		}
@@ -365,7 +377,7 @@
 		get_page(page);
 	}
 
-	clear_bit(CACHEFS_BLOCK_ALLOC,&block->flags);
+	clear_bit(CACHEFS_BLOCK_ALLOC, &block->flags);
 	wake_up_all(&block->writewq);
 
 	_leave(" = 0");
@@ -375,7 +387,7 @@
  nomem_page:
 	page_cache_release(newpage);
  nomem:
-	clear_bit(CACHEFS_BLOCK_ALLOC,&block->flags);
+	clear_bit(CACHEFS_BLOCK_ALLOC, &block->flags);
 	wake_up_all(&block->writewq);
 
 	_leave(" = -ENOMEM");
@@ -386,7 +398,8 @@
 /*****************************************************************************/
 /*
  * indicate that we're going to modify a block
- * - the page pointed to by *_page may be COW'd and replaced with a different page
+ * - the page pointed to by *_page may be COW'd and replaced with a different
+ *   page
  */
 void cachefs_block_modify(struct cachefs_super *super,
 			  struct cachefs_block *block,
@@ -394,13 +407,12 @@
 {
 	struct page *page;
 
-	_enter(",%u,",block->bix);
+	_enter(",%u,", block->bix);
 
-	if (*_page!=block->page) {
+	if (*_page != block->page) {
 		page = block->page;
 		get_page(page);
-		page = xchg(_page,page);
-		if (page) put_page(page);
+		cachefs_put_page(xchg(_page, page));
 	}
 
 	_leave("");
@@ -408,7 +420,8 @@
 
 /*****************************************************************************/
 /*
- * insert a block into the superblock's lookup tree (if it doesn't already exist)
+ * insert a block into the superblock's lookup tree (if it doesn't already
+ * exist)
  */
 int cachefs_block_insert(struct cachefs_super *super,
 			 cachefs_blockix_t bix,
@@ -423,7 +436,7 @@
 	*_block = NULL;
 
 	/* allocate a block record just in case */
-	newblock = kmem_cache_alloc(cachefs_block_jar,SLAB_KERNEL);
+	newblock = kmem_cache_alloc(cachefs_block_jar, SLAB_KERNEL);
 	if (!newblock)
 		return -ENOMEM;
 
@@ -438,12 +451,12 @@
 	parent = NULL;
 	block = NULL;
 
-	write_lock_irqsave(&super->blk_tree_lock,flags);
+	write_lock_irqsave(&super->blk_tree_lock, flags);
 	p = &super->blk_tree.rb_node;
 
 	while (*p) {
 		parent = *p;
-		block = rb_entry(parent,struct cachefs_block,lookup_node);
+		block = rb_entry(parent, struct cachefs_block, lookup_node);
 
 		if (bix < block->bix)
 			p = &(*p)->rb_left;
@@ -454,24 +467,24 @@
 	}
 
 	/* no block record yet - use the new one we allocated earlier */
-	rb_link_node(&newblock->lookup_node,parent,p);
-	rb_insert_color(&newblock->lookup_node,&super->blk_tree);
-	write_unlock_irqrestore(&super->blk_tree_lock,flags);
+	rb_link_node(&newblock->lookup_node, parent, p);
+	rb_insert_color(&newblock->lookup_node, &super->blk_tree);
+	write_unlock_irqrestore(&super->blk_tree_lock, flags);
 
 	atomic_inc(&super->cnt_blk_tree);
 	*_block = newblock;
-	_leave(" = 0 [new %p{u=%d}]",newblock,atomic_read(&newblock->usage));
+	_leave(" = 0 [new %p{u=%d}]", newblock, atomic_read(&newblock->usage));
 	return 0;
 
  found:
 	cachefs_block_get(block);
-	write_unlock_irqrestore(&super->blk_tree_lock,flags);
+	write_unlock_irqrestore(&super->blk_tree_lock, flags);
 
 	dbgfree(newblock);
-	kmem_cache_free(cachefs_block_jar,newblock);
+	kmem_cache_free(cachefs_block_jar, newblock);
 
 	*_block = block;
-	_leave(" = 0 [found %p{u=%d}]",block,atomic_read(&block->usage));
+	_leave(" = 0 [found %p{u=%d}]", block, atomic_read(&block->usage));
 	return 0;
 } /* end cachefs_block_insert() */
 
@@ -487,15 +500,15 @@
 	struct rb_node *node;
 	unsigned long flags;
 
-	_enter(",%d,",bix);
+	_enter(",%d,", bix);
 
 	*_block = NULL;
 
-	read_lock_irqsave(&super->blk_tree_lock,flags);
+	read_lock_irqsave(&super->blk_tree_lock, flags);
 	node = super->blk_tree.rb_node;
 
 	while (node) {
-		block = rb_entry(node,struct cachefs_block,lookup_node);
+		block = rb_entry(node, struct cachefs_block, lookup_node);
 
 		if (bix < block->bix)
 			node = node->rb_left;
@@ -504,17 +517,17 @@
 		else
 			goto found;
 	}
-	read_unlock_irqrestore(&super->blk_tree_lock,flags);
+	read_unlock_irqrestore(&super->blk_tree_lock, flags);
 
 	_leave(" = -ENOENT");
 	return -ENOENT;
 
  found:
 	cachefs_block_get(block);
-	read_unlock_irqrestore(&super->blk_tree_lock,flags);
+	read_unlock_irqrestore(&super->blk_tree_lock, flags);
 
 	*_block = block;
-	_leave(" = 0 [%p{u=%d}]",block,atomic_read(&block->usage));
+	_leave(" = 0 [%p{u=%d}]", block, atomic_read(&block->usage));
 	return 0;
 } /* end cachefs_block_find() */
 
@@ -527,21 +540,21 @@
 	struct cachefs_super *super = block->super;
 	unsigned long flags;
 
-	_enter(",{u=%d bix=%d}",atomic_read(&block->usage),block->bix);
+	_enter(",{u=%d bix=%d}", atomic_read(&block->usage), block->bix);
 
-	write_lock_irqsave(&super->blk_tree_lock,flags);
+	write_lock_irqsave(&super->blk_tree_lock, flags);
 
-	if (atomic_read(&block->usage)==0)
-		rb_erase(&block->lookup_node,&super->blk_tree);
+	if (atomic_read(&block->usage) == 0)
+		rb_erase(&block->lookup_node, &super->blk_tree);
 	else
 		block = NULL;
 
-	write_unlock_irqrestore(&super->blk_tree_lock,flags);
+	write_unlock_irqrestore(&super->blk_tree_lock, flags);
 
 	if (block) {
 		atomic_dec(&super->cnt_blk_tree);
 		dbgfree(block);
-		kmem_cache_free(cachefs_block_jar,block);
+		kmem_cache_free(cachefs_block_jar, block);
 	}
 
 	_leave("");
@@ -558,41 +571,44 @@
 	struct rb_node *node;
 	unsigned long flags;
 
-	DECLARE_WAITQUEUE(myself,current);
+	DECLARE_WAITQUEUE(myself, current);
 
 	_enter("");
 
 	/* first thing to do is mark all blocks withdrawn
 	 * - this prevents the netfs from getting underfoot
 	 */
-	read_lock_irqsave(&super->blk_tree_lock,flags);
+	read_lock_irqsave(&super->blk_tree_lock, flags);
 
-	for (node=rb_first(&super->blk_tree); node; node=rb_next(node)) {
-		block = rb_entry(node,struct cachefs_block,lookup_node);
-		set_bit(CACHEFS_BLOCK_WITHDRAWN,&block->flags);
+	for (node = rb_first(&super->blk_tree); node; node = rb_next(node)) {
+		block = rb_entry(node, struct cachefs_block, lookup_node);
+		set_bit(CACHEFS_BLOCK_WITHDRAWN, &block->flags);
 	}
 
-	read_unlock_irqrestore(&super->blk_tree_lock,flags);
+	read_unlock_irqrestore(&super->blk_tree_lock, flags);
 
 	/* now withdraw each block that's already in use by a netfs */
 	for (;;) {
 		block = NULL;
-		write_lock_irqsave(&super->blk_tree_lock,flags);
+		write_lock_irqsave(&super->blk_tree_lock, flags);
 
-		for (node=rb_first(&super->blk_tree); node; node=rb_next(node)) {
-			block = rb_entry(node,struct cachefs_block,lookup_node);
+		for (node = rb_first(&super->blk_tree);
+		     node;
+		     node = rb_next(node)) {
+			block = rb_entry(node, struct cachefs_block,
+					 lookup_node);
 			if (block->ref) {
 				cachefs_block_get(block);
 				break;
 			}
 		}
 
-		write_unlock_irqrestore(&super->blk_tree_lock,flags);
+		write_unlock_irqrestore(&super->blk_tree_lock, flags);
 
 		if (!node)
 			break;
 
-		_debug("withdraw block %u",block->bix);
+		_debug("withdraw block %u", block->bix);
 
 		/* disconnect block from netfs page cookie */
 		xblock = NULL;
@@ -609,21 +625,21 @@
 		}
 		write_unlock(&pageio->lock);
 
-		if (xblock)
-			cachefs_block_put(xblock);
+		cachefs_block_put(xblock);
 
 		/* wait for the netfs to finish with the block */
-		if (test_bit(CACHEFS_BLOCK_NETFSBUSY,&block->flags)) {
+		if (test_bit(CACHEFS_BLOCK_NETFSBUSY, &block->flags)) {
 			set_current_state(TASK_UNINTERRUPTIBLE);
-			add_wait_queue(&block->writewq,&myself);
+			add_wait_queue(&block->writewq, &myself);
 
-			while (test_bit(CACHEFS_BLOCK_NETFSBUSY,&block->flags)) {
+			while (test_bit(CACHEFS_BLOCK_NETFSBUSY,
+					&block->flags)) {
 				schedule();
 				set_current_state(TASK_UNINTERRUPTIBLE);
 			}
 
 			set_current_state(TASK_RUNNING);
-			remove_wait_queue(&block->writewq,&myself);
+			remove_wait_queue(&block->writewq, &myself);
 		}
 
 		/* a block that's not yet valid must be cancelled */

Index: aops.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/aops.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- aops.c	1 Jul 2003 17:44:50 -0000	1.38
+++ aops.c	4 Jul 2003 09:04:44 -0000	1.39
@@ -51,9 +51,12 @@
 static int cachefs_readpages(struct file *file, struct address_space *mapping,
 			     struct list_head *pages, unsigned nr_pages);
 static int cachefs_writepage(struct page *page, struct writeback_control *wbc);
-static int cachefs_writepages(struct address_space *mapping, struct writeback_control *wbc);
-static int cachefs_prepare_write(struct file *file, struct page *page, unsigned from, unsigned to);
-static int cachefs_commit_write(struct file *file, struct page *page, unsigned from, unsigned to);
+static int cachefs_writepages(struct address_space *mapping,
+			      struct writeback_control *wbc);
+static int cachefs_prepare_write(struct file *file, struct page *page,
+				 unsigned from, unsigned to);
+static int cachefs_commit_write(struct file *file, struct page *page,
[...1214 lines suppressed...]
 	ret = -ENOMEM;
-	bio = bio_alloc(GFP_KERNEL,1);
+	bio = bio_alloc(GFP_KERNEL, 1);
 	if (!bio)
 		goto error;
 
@@ -1455,11 +1517,11 @@
 	bio->bi_sector	= block->bix << (PAGE_SHIFT - sb->s_blocksize_bits);
 	bio->bi_end_io	= cachefs_io_end_io_read;
 	//dump_bio(bio,1);
-	submit_bio(READ,bio);
+	submit_bio(READ, bio);
 	ret = 0;
 
  error:
-	_leave(" = %d",ret);
+	_leave(" = %d", ret);
 	return ret;
 
 } /* end cachefs_file_readpage() */


From dwh at infradead.org  Fri Jul  4 16:25:43 2003
From: dwh at infradead.org (dwh@infradead.org)
Date: Fri Jul  4 15:25:34 2003
Subject: afs/fs/cachefs super.c,1.36,1.37 recycling.c,1.23,1.24
 main.c,1.16,1.17 journal.c,1.37,1.38 index.c,1.24,1.25
 dump-journal.c,1.11,1.12 cachefs-layout.h,1.26,1.27
Message-ID: <E19YRVO-0001Gs-00@phoenix.infradead.org>

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

Modified Files:
	super.c recycling.c main.c journal.c index.c dump-journal.c 
	cachefs-layout.h 
Log Message:
netfs can now request an index entry be updated/deleted during a search


Index: super.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/super.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- super.c	4 Jul 2003 09:04:43 -0000	1.36
+++ super.c	4 Jul 2003 14:25:39 -0000	1.37
@@ -252,7 +252,8 @@
 	if (!super->rcm_imm_buf)
 		goto error;
 
-	super->rcm_atm_list = (struct cachefs_reclaimable *) get_zeroed_page(GFP_KERNEL);
+	super->rcm_atm_list =
+		(struct cachefs_reclaimable *) get_zeroed_page(GFP_KERNEL);
 	if (!super->rcm_atm_list)
 		goto error;
 

Index: recycling.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/recycling.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- recycling.c	4 Jul 2003 09:04:43 -0000	1.23
+++ recycling.c	4 Jul 2003 14:25:39 -0000	1.24
@@ -825,7 +825,7 @@
 		trans->jentry->mark = CACHEFS_ONDISC_UJNL_INODE_RECLAIMING;
 
 		ret = cachefs_trans_mark(trans);
-		if (ret<0) {
+		if (ret < 0) {
 			kdebug("[error %d]", ret);
 			cachefs_trans_put(trans);
 			goto done;
@@ -840,7 +840,8 @@
 		cachefs_trans_commit(trans);
 
 		super->rcm_imm_tail =
-			(super->rcm_imm_tail+1) & (CACHEFS_RCM_IMM_BUFSIZE-1);
+			(super->rcm_imm_tail + 1) &
+			(CACHEFS_RCM_IMM_BUFSIZE - 1);
 		goto done;
 	}
 

Index: main.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/main.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- main.c	4 Jul 2003 09:04:44 -0000	1.16
+++ main.c	4 Jul 2003 14:25:40 -0000	1.17
@@ -36,8 +36,6 @@
 {
 	int ret;
 
-	printk(KERN_INFO "cachefs: general fs caching v0.1 registering.\n");
-
 	ret = kcachefs_jnld_start();
 	if (ret < 0)
 		goto error;
@@ -74,6 +72,8 @@
 	if (ret < 0)
 		goto error_block_jar;
 
+	printk(KERN_INFO "CacheFS: general fs caching v0.1 registered\n");
+
 	return ret;
 
  error_block_jar:
@@ -83,7 +83,7 @@
  error_jnld:
 	kcachefs_jnld_stop();	
  error:
-	printk(KERN_ERR "cachefs: failed to register: %d\n", ret);
+	printk(KERN_ERR "CacheFS: failed to register: %d\n", ret);
 	return ret;
 } /* end cachefs_init() */
 
@@ -93,7 +93,7 @@
  */
 static void __exit cachefs_exit(void)
 {
-	printk(KERN_INFO "cachefs: general fs caching v0.1 unregistering.\n");
+	printk(KERN_INFO "CacheFS: general fs caching v0.1 unregistering\n");
 
 	cachefs_fs_exit();
 	kcachefs_jnld_stop();	

Index: journal.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/journal.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- journal.c	4 Jul 2003 09:04:44 -0000	1.37
+++ journal.c	4 Jul 2003 14:25:40 -0000	1.38
@@ -39,7 +39,7 @@
 	"RcycMkRdy",
 	"CreatData",
 	"UpdatData",
-	"DeletData",
+	"DelInode ",
 	"InoMkRcm ",
 	"InoRcming",
 	"DataAlloc",
@@ -49,8 +49,7 @@
 	"FreeIndr ",
 	"ExtendIdx",
 	"CreateIdx",
-	"ModifyIdx",
-	"DeleteIdx",
+	"UpdateIdx",
 	"?????????"
 };
 
@@ -109,8 +108,7 @@
 	[CACHEFS_ONDISC_UJNL_INDIRECT_FREEING]	= cachefs_replay_ujnl_indirect_freeing,
 	[CACHEFS_ONDISC_UJNL_INDEX_EXTENDING]	= cachefs_replay_ujnl_index_extending,
 	[CACHEFS_ONDISC_UJNL_INDEX_CREATING]	= cachefs_replay_ujnl_index_creating,
-	[CACHEFS_ONDISC_UJNL_INDEX_MODIFYING]	= cachefs_replay_ujnl_index_modifying,
-	[CACHEFS_ONDISC_UJNL_INDEX_DELETING]	= cachefs_replay_ujnl_index_deleting,
+	[CACHEFS_ONDISC_UJNL_INDEX_UPDATING]	= cachefs_replay_ujnl_index_modifying
 };
 
 /*****************************************************************************/

Index: index.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/index.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- index.c	4 Jul 2003 09:04:44 -0000	1.24
+++ index.c	4 Jul 2003 14:25:40 -0000	1.25
@@ -39,6 +39,161 @@
 
 /*****************************************************************************/
 /*
+ * mark an inode/index entry pair for deletion when so requested by the match
+ * function supplied by the netfs
+ */
+static void cachefs_index_search_delete(struct cachefs_index_search_record *rec,
+					struct page *ixpage,
+					unsigned ixentry,
+					unsigned ixoffset,
+					unsigned ino)
+{
+	struct cachefs_ondisc_index_entry *xent;
+	struct cachefs_ondisc_metadata *metadata;
+	struct cachefs_transaction *trans;
+	struct cachefs_super *super;
+	struct cachefs_inode *inode;
+	unsigned long flags;
+	int ret;
+
+	_enter(",{%lx},%u,%u,%u", ixpage->index, ixentry, ixoffset, ino);
+
+	super = ixpage->mapping->host->i_sb->s_fs_info;
+
+	ret = cachefs_iget(super, ino, &inode);
+	if (ret < 0) {
+		_leave(" [iget error %d]", ret);
+		return;
+	}
+
+	ret = -ENOMEM;
+	trans = cachefs_trans_alloc(super, GFP_KERNEL);
+	if (!trans)
+		goto error;
+
+	trans->jentry->mark	= CACHEFS_ONDISC_UJNL_INODE_MARK_RECLAIM;
+	trans->jentry->ino	= inode->vfs_inode.i_ino;
+	trans->jentry->index	= rec->iinode->vfs_inode.i_ino;
+	trans->jentry->ixentry	= ixentry;
+	trans->jentry->pgnum	= ixpage->index;
+	trans->jentry->block	= inode->metadata->bix;
+	trans->jentry->entry	= inode->metadata_offset;
+	trans->jentry->upblock	= __cachefs_get_page_block(ixpage)->bix;
+	trans->jentry->upentry	= ixoffset;
+
+	cachefs_trans_affects_page(trans, __cachefs_page_get_private(ixpage),
+				   ixoffset, sizeof(*xent));
+	cachefs_trans_affects_inode(trans, inode);
+
+	ret = cachefs_trans_mark(trans);
+	if (ret < 0)
+		goto error;
+
+	cachefs_page_modify(super, &ixpage);
+
+	xent = kmap(ixpage) + ixoffset;
+	xent->state = CACHEFS_ONDISC_INDEX_RECYCLE;
+	kunmap(ixpage);
+
+	metadata = cachefs_metadata_prewrite(inode);
+	metadata->header.state = CACHEFS_ONDISC_INDEX_RECYCLE;
+	cachefs_metadata_postwrite(inode);
+
+	cachefs_trans_commit(trans);
+
+	/* add to the immediate-reclaim table if possible */
+	spin_lock_irqsave(&super->rcm_lock, flags);
+
+	if (CIRC_SPACE(super->rcm_imm_head,
+		       super->rcm_imm_tail,
+		       CACHEFS_RCM_IMM_BUFSIZE) > 0) {
+		super->rcm_imm_buf[super->rcm_imm_head] =
+			inode->vfs_inode.i_ino;
+		super->rcm_imm_head =
+			(super->rcm_imm_head + 1) &
+			(CACHEFS_RCM_IMM_BUFSIZE - 1);
+	}
+	else {
+		set_bit(CACHEFS_SUPER_RCM_IMM_SCAN, &super->flags);
+	}
+
+	spin_unlock_irqrestore(&super->rcm_lock, flags);
+
+	set_bit(CACHEFS_SUPER_DO_RECLAIM, &super->flags);
+	wake_up(&super->dmn_sleepq);
+
+	cachefs_iput(inode);
+	_leave(" [ok]");
+	return;
+
+ error:
+	cachefs_iput(inode);
+	cachefs_trans_put(trans);
+	_leave(" [error %d]", ret);
+	return;
+} /* end cachefs_index_search_delete() */
+
+/*****************************************************************************/
+/*
+ * mark an inode/index entry pair for deletion when so requested by the match
+ * function supplied by the netfs
+ */
+static void cachefs_index_search_update(struct cachefs_index_search_record *rec,
+					struct page *ixpage,
+					unsigned ixentry,
+					unsigned ixoffset,
+					unsigned ino)
+{
+	struct cachefs_ondisc_index_entry *xent;
+	struct cachefs_transaction *trans;
+	struct cachefs_super *super;
+	int ret;
+
+	_enter(",{%lx},%u,%u,%u", ixpage->index, ixentry, ixoffset, ino);
+
+	super = ixpage->mapping->host->i_sb->s_fs_info;
+
+	ret = -ENOMEM;
+	trans = cachefs_trans_alloc(super, GFP_KERNEL);
+	if (!trans)
+		goto error;
+
+	trans->jentry->mark	= CACHEFS_ONDISC_UJNL_INDEX_UPDATING;
+	trans->jentry->ino	= ino;
+	trans->jentry->index	= rec->iinode->vfs_inode.i_ino;
+	trans->jentry->ixentry	= ixentry;
+	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;
+
+	cachefs_trans_affects_page(trans, __cachefs_page_get_private(ixpage),
+				   ixoffset, sizeof(*xent));
+
+	ret = cachefs_trans_mark(trans);
+	if (ret < 0)
+		goto error;
+
+	cachefs_page_modify(super, &ixpage);
+
+	xent = kmap(ixpage) + ixoffset;
+
+	rec->index->idef->update(rec->target->netfs_data, xent->data);
+
+	kunmap(ixpage);
+
+	cachefs_trans_commit(trans);
+	_leave(" [ok]");
+	return;
+
+ error:
+	cachefs_trans_put(trans);
+	_leave(" [error %d]", ret);
+	return;
+} /* end cachefs_index_search_update() */
+
+/*****************************************************************************/
+/*
  * index file search actor
  * - return size to continue, 0 to stop (search also stops when desc->count==0)
  */
@@ -48,7 +203,7 @@
 				      unsigned long size)
 {
 	struct cachefs_index_search_record *rec;
-	unsigned long stop, tmp;
+	unsigned long stop, tmp, esize;
 	void *content;
 	int ret;
 
@@ -72,22 +227,33 @@
 	if (size < stop)
 		stop = size;
 
-	tmp = rec->entsize;
+	esize = rec->entsize;
 
 	/* search the elements on the page (ignoring slack at end) */
 	content = kmap(page);
 
-	for (; offset + tmp <= stop; offset += tmp) {
+	for (; offset + esize <= stop; offset += esize) {
 		struct cachefs_ondisc_index_entry *xent = content + offset;
+		cachefs_match_val_t result;
+		unsigned ixentry;
 
 		if (xent->state == CACHEFS_ONDISC_INDEX_FREE ||
 		    xent->state == CACHEFS_ONDISC_INDEX_RECYCLE)
 			continue;
 
-		if (rec->index->idef->match(rec->target->netfs_data,
-					    xent->data)) {
-			rec->entry = offset / tmp;
-			rec->entry += page->index * (PAGE_SIZE / tmp);
+		ixentry = offset / esize;
+		ixentry += page->index * (PAGE_SIZE / esize);
+
+		result = rec->index->idef->match(rec->target->netfs_data,
+						 xent->data);
+
+		switch (result) {
+		case CACHEFS_MATCH_SUCCESS_UPDATE:
+			cachefs_index_search_update(rec, page, ixentry, offset,
+						    xent->ino);
+
+		case CACHEFS_MATCH_SUCCESS:
+			rec->entry = tmp;
 			rec->ino   = xent->ino;
 
 			if (rec->ino == 0) {
@@ -97,13 +263,21 @@
 				       rec->entry,
 				       page->index,
 				       __cachefs_get_page_block(page)->bix,
-				       offset / tmp);
+				       offset / esize);
 				BUG();
 			}
 
 			desc->count = 0;
 			ret = 0;
 			break;
+
+		case CACHEFS_MATCH_SUCCESS_DELETE:
+			cachefs_index_search_delete(rec, page, ixentry, offset,
+						    xent->ino);
+
+		case CACHEFS_MATCH_FAILED:
+		default:
+			break;
 		}
 	}
 
@@ -297,7 +471,7 @@
 	}
 	/* get the page holding the next free entry */
 	else {
-		filler_t *filler = 
+		filler_t *filler =
 			(filler_t *)
 			iinode->vfs_inode.i_mapping->a_ops->readpage;
 
@@ -578,10 +752,10 @@
 	trans->jentry->index	= super->rcm_ino;
 	trans->jentry->ixentry	= super->rcm_block;
 
-	cachefs_trans_affects_inode(trans,inode);
+	cachefs_trans_affects_inode(trans, inode);
 
 	ret = cachefs_trans_mark(trans);
-	if (ret<0)
+	if (ret < 0)
 		goto error_skip;
 
 	/* modify the inode metadata entry */
@@ -674,7 +848,7 @@
 
 /*****************************************************************************/
 /*
- * 
+ *
  */
 int cachefs_replay_ujnl_inode_reclaiming(struct cachefs_super *super,
 					 struct cachefs_ondisc_update_journal *jentry)
@@ -684,7 +858,7 @@
 
 /*****************************************************************************/
 /*
- * 
+ *
  */
 int cachefs_replay_ujnl_index_extending(struct cachefs_super *super,
 					struct cachefs_ondisc_update_journal *jentry)
@@ -694,7 +868,7 @@
 
 /*****************************************************************************/
 /*
- * 
+ *
  */
 int cachefs_replay_ujnl_index_creating(struct cachefs_super *super,
 				       struct cachefs_ondisc_update_journal *jentry)
@@ -704,20 +878,10 @@
 
 /*****************************************************************************/
 /*
- * 
+ *
  */
 int cachefs_replay_ujnl_index_modifying(struct cachefs_super *super,
 					struct cachefs_ondisc_update_journal *jentry)
 {
 	return -ENOANO;
 } /* end cachefs_replay_ujnl_index_modifying() */
-
-/*****************************************************************************/
-/*
- * 
- */
-int cachefs_replay_ujnl_index_deleting(struct cachefs_super *super,
-				       struct cachefs_ondisc_update_journal *jentry)
-{
-	return -ENOANO;
-} /* end cachefs_replay_ujnl_index_deleting() */

Index: dump-journal.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/dump-journal.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- dump-journal.c	4 Jul 2003 09:04:44 -0000	1.11
+++ dump-journal.c	4 Jul 2003 14:25:40 -0000	1.12
@@ -52,7 +52,7 @@
 	BRIGHT	"RcycMkRdy"	NORMAL,
 	BRIGHT	"CrtData  "	NORMAL,
 	BRIGHT	"UpdData  "	NORMAL,
-	BRIGHT	"DelData  "	NORMAL,
+	BRIGHT	"DelInode "	NORMAL,
 	BRIGHT	"InoMkRcm "	NORMAL,
 	BRIGHT	"InoRcming"	NORMAL,
 	BRIGHT	"DataAlloc"	NORMAL,
@@ -62,8 +62,7 @@
 	BRIGHT	"IndrFree "	NORMAL,
 	BRIGHT	"ExtnIndex"	NORMAL,
 	BRIGHT	"CrtIndex "	NORMAL,
-	BRIGHT	"ModIndex "	NORMAL,
-	BRIGHT	"DelIndex "	NORMAL,
+	BRIGHT	"UpdIndex "	NORMAL,
 	BP_RED	"?????????"	NORMAL
 };
 

Index: cachefs-layout.h
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/cachefs-layout.h,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- cachefs-layout.h	4 Jul 2003 09:04:44 -0000	1.26
+++ cachefs-layout.h	4 Jul 2003 14:25:40 -0000	1.27
@@ -247,7 +247,7 @@
 	/* data file being updated */
 	CACHEFS_ONDISC_UJNL_INODE_UPDATING,
 
-	/* data file being deleted */
+	/* data or index file being deleted */
 	CACHEFS_ONDISC_UJNL_INODE_DELETING,
 
 	/* inode being marked for reclamation
@@ -333,11 +333,15 @@
 	 */
 	CACHEFS_ONDISC_UJNL_INDEX_CREATING,
 
-	/* index entry being modified */
-	CACHEFS_ONDISC_UJNL_INDEX_MODIFYING,
-
-	/* index file being deleted */
-	CACHEFS_ONDISC_UJNL_INDEX_DELETING,
+	/* index entry being updated
+	 * - index	= index being modified
+	 * - ixentry	= entry in index
+	 * - pgnum	= page in file holding index entry being allocated
+	 * - block	= block holding index entry being allocated
+	 * - entry	= offset of entry in block
+	 * - count	= size of entry in block
+	 */
+	CACHEFS_ONDISC_UJNL_INDEX_UPDATING,
 
 	CACHEFS_ONDISC_UJNL__LAST
 } __attribute__((packed));


From dwh at infradead.org  Fri Jul  4 17:23:02 2003
From: dwh at infradead.org (dwh@infradead.org)
Date: Fri Jul  4 16:22:48 2003
Subject: afs/fs/cachefs inode.c,1.21,1.22 cachefs-layout.h,1.27,1.28
Message-ID: <E19YSOs-0002j9-00@phoenix.infradead.org>

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

Modified Files:
	inode.c cachefs-layout.h 
Log Message:
remove entries from cache metadata that should be in the index


Index: inode.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/inode.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- inode.c	4 Jul 2003 09:04:44 -0000	1.21
+++ inode.c	4 Jul 2003 15:22:59 -0000	1.22
@@ -142,7 +142,7 @@
 	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	= metadata->version;
+	inode->vfs_inode.i_version	= 1;
 	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;
@@ -223,7 +223,7 @@
 	inode->vfs_inode.i_blocks	= metadata->size;
 	inode->vfs_inode.i_blocks	+= inode->vfs_inode.i_blksize - 1;
 	inode->vfs_inode.i_blocks	>>= PAGE_SHIFT;
-	inode->vfs_inode.i_version	= metadata->version;
+	inode->vfs_inode.i_version	= 1;
 	inode->vfs_inode.i_flags	|= S_NOATIME;
 	inode->vfs_inode.i_op		= &cachefs_inode_operations;
 	inode->vfs_inode.i_fop		= &cachefs_file_operations;

Index: cachefs-layout.h
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/cachefs-layout.h,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- cachefs-layout.h	4 Jul 2003 14:25:40 -0000	1.27
+++ cachefs-layout.h	4 Jul 2003 15:22:59 -0000	1.28
@@ -108,6 +108,7 @@
 	u_int32_t			mtime;		/* last modification time */
 	u_int32_t			pindex;		/* parent index ID (0 for top of tree) */
 	u_int32_t			pindex_entry;	/* parent index entry number */
+	u_int64_t			size;		/* size of file */
 
 	/* index file definition */
 	u_int16_t			index_dsize;	/* index entry data size */
@@ -122,12 +123,6 @@
 #define CACHEFS_ONDISC_INDEXKEY_ASCIIZ	0x2000	/* - null-terminated string */
 #define CACHEFS_ONDISC_INDEXKEY_IPV4	0x3000	/* - IPv4 address */
 #define CACHEFS_ONDISC_INDEXKEY_IPV6	0x4000	/* - IPv6 address */
-
-	/* file ID and status */
-	u_int64_t			inode;		/* real inode number */
-	u_int64_t			unique;		/* real inode number version */
-	u_int64_t			version;	/* current data version */
-	u_int64_t			size;		/* size of file */
 
 	/* file contents - recycling depends on triple_indirect being first */
 	cachefs_blockix_t		triple_indirect; /* triple indirect block index */


From dwh at infradead.org  Fri Jul  4 17:23:54 2003
From: dwh at infradead.org (dwh@infradead.org)
Date: Fri Jul  4 16:23:41 2003
Subject: afs/net/rxrpc main.c,1.3,1.4 Makefile,1.7,1.8
Message-ID: <E19YSPh-0002jw-00@phoenix.infradead.org>

Update of /home/cvs/afs/net/rxrpc
In directory phoenix.infradead.org:/tmp/cvs-serv10524/net/rxrpc

Modified Files:
	main.c Makefile 
Log Message:
add under-stack greasing to help make backtraces more sane


Index: main.c
===================================================================
RCS file: /home/cvs/afs/net/rxrpc/main.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- main.c	4 Feb 2003 16:12:04 -0000	1.3
+++ main.c	4 Jul 2003 15:23:51 -0000	1.4
@@ -125,3 +125,48 @@
 
 	kleave("");
 } /* end rxrpc_cleanup() */
+
+/*****************************************************************************/
+/*
+ * clear the dead space between task_struct and kernel stack
+ * - called by supplying -finstrument-functions to gcc
+ */
+#if 1
+void __cyg_profile_func_enter (void *this_fn, void *call_site)
+__attribute__((no_instrument_function));
+
+void __cyg_profile_func_enter (void *this_fn, void *call_site)
+{
+       asm volatile("  movl    %%esp,%%edi     \n"
+                    "  andl    %0,%%edi        \n"
+                    "  addl    %1,%%edi        \n"
+                    "  movl    %%esp,%%ecx     \n"
+                    "  subl    %%edi,%%ecx     \n"
+                    "  shrl    $2,%%ecx        \n"
+                    "  movl    $0xedededed,%%eax     \n"
+                    "  rep stosl               \n"
+                    :
+                    : "i"(~(THREAD_SIZE-1)), "i"(sizeof(struct thread_info))
+                    : "eax", "ecx", "edi", "memory", "cc"
+                    );
+}
+
+void __cyg_profile_func_exit(void *this_fn, void *call_site)
+__attribute__((no_instrument_function));
+
+void __cyg_profile_func_exit(void *this_fn, void *call_site)
+{
+       asm volatile("  movl    %%esp,%%edi     \n"
+                    "  andl    %0,%%edi        \n"
+                    "  addl    %1,%%edi        \n"
+                    "  movl    %%esp,%%ecx     \n"
+                    "  subl    %%edi,%%ecx     \n"
+                    "  shrl    $2,%%ecx        \n"
+                    "  movl    $0xdadadada,%%eax     \n"
+                    "  rep stosl               \n"
+                    :
+                    : "i"(~(THREAD_SIZE-1)), "i"(sizeof(struct thread_info))
+                    : "eax", "ecx", "edi", "memory", "cc"
+                    );
+}
+#endif

Index: Makefile
===================================================================
RCS file: /home/cvs/afs/net/rxrpc/Makefile,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Makefile	2 Mar 2003 18:56:14 -0000	1.7
+++ Makefile	4 Jul 2003 15:23:51 -0000	1.8
@@ -2,6 +2,8 @@
 # Makefile for Linux kernel Rx RPC
 #
 
+CFLAGS += -finstrument-functions
+
 rxrpc-objs := \
 	call.o \
 	connection.o \


From dwh at infradead.org  Fri Jul  4 17:26:34 2003
From: dwh at infradead.org (dwh@infradead.org)
Date: Fri Jul  4 16:42:08 2003
Subject: afs/fs/afs volume.h,1.4,1.5 volume.c,1.7,1.8 vnode.h,1.4,1.5
 vnode.c,1.6,1.7 vlocation.c,1.8,1.9 vlclient.h,1.4,1.5
 vlclient.c,1.6,1.7 super.h,1.2,1.3 super.c,1.8,1.9 server.c,1.3,1.4
 mntpt.c,1.6,1.7 main.c,1.11,1.12 kafstimod.c,1.6,1.7
 internal.h,1.14,1.15 inode.c,1.10,1.11 file.c,1.7,1.8
 dir.c,1.9,1.10 cmservice.c,1.6,1.7 cell.h,1.4,1.5 cell.c,1.8,1.9
 callback.c,1.3,1.4 Makefile,1.11,1.12
Message-ID: <E19YSSI-0002kc-00@phoenix.infradead.org>

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

Modified Files:
	volume.h volume.c vnode.h vnode.c vlocation.c vlclient.h 
	vlclient.c super.h super.c server.c mntpt.c main.c kafstimod.c 
	internal.h inode.c file.c dir.c cmservice.c cell.h cell.c 
	callback.c Makefile 
Log Message:
done some cleaning up
moved a little towards hch-compliance (CodingStyle)
added automount/expiry (requires kernel patch)
made cache index match functions request update/delete if necessary


Index: volume.h
===================================================================
RCS file: /home/cvs/afs/fs/afs/volume.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- volume.h	6 Jun 2003 08:33:37 -0000	1.4
+++ volume.h	4 Jul 2003 15:26:31 -0000	1.5
@@ -87,13 +87,16 @@
 	unsigned short		valid;		/* T if valid */
 };
 
-extern int afs_vlocation_lookup(afs_cell_t *cell, const char *name, afs_vlocation_t **_vlocation);
+extern int afs_vlocation_lookup(struct afs_cell *cell,
+				const char *name,
+				unsigned namesz,
+				struct afs_vlocation **_vlocation);
 
 #define afs_get_vlocation(V) do { atomic_inc(&(V)->usage); } while(0)
 
-extern void __afs_put_vlocation(afs_vlocation_t *vlocation);
-extern void afs_put_vlocation(afs_vlocation_t *vlocation);
-extern void afs_vlocation_do_timeout(afs_vlocation_t *vlocation);
+extern void __afs_put_vlocation(struct afs_vlocation *vlocation);
+extern void afs_put_vlocation(struct afs_vlocation *vlocation);
+extern void afs_vlocation_do_timeout(struct afs_vlocation *vlocation);
 
 /*****************************************************************************/
 /*
@@ -114,14 +117,19 @@
 	struct rw_semaphore	server_sem;	/* lock for accessing current server */
 };
 
-extern int afs_volume_lookup(char *name, int ro, afs_volume_t **_volume);
+extern int afs_volume_lookup(const char *name,
+			     struct afs_cell *cell,
+			     int rwpath,
+			     struct afs_volume **_volume);
 
 #define afs_get_volume(V) do { atomic_inc(&(V)->usage); } while(0)
 
-extern void afs_put_volume(afs_volume_t *volume);
+extern void afs_put_volume(struct afs_volume *volume);
 
-extern int afs_volume_pick_fileserver(afs_volume_t *volume, afs_server_t **_server);
+extern int afs_volume_pick_fileserver(struct afs_volume *volume, struct afs_server **_server);
 
-extern int afs_volume_release_fileserver(afs_volume_t *volume, afs_server_t *server, int result);
+extern int afs_volume_release_fileserver(struct afs_volume *volume,
+					 struct afs_server *server,
+					 int result);
 
 #endif /* _LINUX_AFS_VOLUME_H */

Index: volume.c
===================================================================
RCS file: /home/cvs/afs/fs/afs/volume.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- volume.c	9 Jun 2003 13:52:04 -0000	1.7
+++ volume.c	4 Jul 2003 15:26:31 -0000	1.8
@@ -56,19 +56,19 @@
  * - Rule 2: If parent volume is R/O, then mount R/O volume by preference, R/W if not available
  * - Rule 3: If parent volume is R/W, then only mount R/W volume unless explicitly told otherwise
  */
-int afs_volume_lookup(char *name, int rwparent, afs_volume_t **_volume)
+int afs_volume_lookup(const char *name, struct afs_cell *cell, int rwpath,
+		      afs_volume_t **_volume)
 {
-	afs_vlocation_t *vlocation = NULL;
+	struct afs_vlocation *vlocation = NULL;
+	struct afs_volume *volume = NULL;
 	afs_voltype_t type;
-	afs_volume_t *volume = NULL;
-	afs_cell_t *cell = NULL;
-	char *cellname, *volname, *suffix;
+	const char *cellname, *volname, *suffix;
 	char srvtmask;
-	int force, ret, loop;
+	int force, ret, loop, cellnamesz, volnamesz;
 
-	_enter(",%s,",name);
+	_enter("%s,,%d,", name, rwpath);
 
-	if (!name || (name[0]!='%' && name[0]!='#') || !name[1]) {
+	if (!name || (name[0] != '%' && name[0] != '#') || !name[1]) {
 		printk("kAFS: unparsable volume name\n");
 		return -EINVAL;
 	}
@@ -77,24 +77,22 @@
 	force = 0;
 	type = AFSVL_ROVOL;
 
-	if (rwparent || name[0]=='%') {
+	if (rwpath || name[0] == '%') {
 		type = AFSVL_RWVOL;
 		force = 1;
 	}
 
-	suffix = strrchr(name,'.');
+	suffix = strrchr(name, '.');
 	if (suffix) {
-		if (strcmp(suffix,".readonly")==0) {
+		if (strcmp(suffix, ".readonly") == 0) {
 			type = AFSVL_ROVOL;
 			force = 1;
 		}
-		else if (strcmp(suffix,".backup")==0) {
+		else if (strcmp(suffix, ".backup") == 0) {
 			type = AFSVL_BACKVOL;
 			force = 1;
 		}
-		else if (suffix[1]==0) {
-			*suffix = 0;
-			suffix = NULL;
+		else if (suffix[1] == 0) {
 		}
 		else {
 			suffix = NULL;
@@ -103,38 +101,45 @@
 
 	/* split the cell and volume names */
 	name++;
-	volname = strchr(name,':');
+	volname = strchr(name, ':');
 	if (volname) {
-		*volname++ = 0;
 		cellname = name;
+		cellnamesz = volname - name;
 	}
 	else {
 		volname = name;
 		cellname = NULL;
+		cellnamesz = 0;
 	}
 
-	_debug("CELL:%s VOLUME:%s SUFFIX:%s TYPE:%d%s",
-	       cellname,volname,suffix?:"-",type,force?" FORCE":"");
+	volnamesz = suffix ? suffix - volname : strlen(volname);
 
-	/* lookup the cell record */
-	ret = afs_cell_lookup(cellname,&cell);
-	if (ret<0)
-		printk("kAFS: unable to lookup cell '%s'\n",cellname?:"");
+	_debug("CELL:%*.*s [%p] VOLUME:%*.*s SUFFIX:%s TYPE:%d%s",
+	       cellnamesz, cellnamesz, cellname ?: "", cell,
+	       volnamesz, volnamesz, volname, suffix ?: "-",
+	       type,
+	       force ? " FORCE" : "");
 
-	if (cellname) volname[-1] = ':';
-	if (ret<0)
-		goto error;
+	/* lookup the cell record */
+	if (cellname || !cell) {
+		ret = afs_cell_lookup(cellname, cellnamesz, &cell);
+		if (ret<0) {
+			printk("kAFS: unable to lookup cell '%s'\n", cellname ?: "");
+			goto error;
+		}
+	}
+	else {
+		afs_get_cell(cell);
+	}
 
 	/* lookup the volume location record */
-	if (suffix) *suffix = 0;
-	ret = afs_vlocation_lookup(cell,volname,&vlocation);
-	if (suffix) *suffix = '.';
-	if (ret<0)
+	ret = afs_vlocation_lookup(cell, volname, volnamesz, &vlocation);
+	if (ret < 0)
 		goto error;
 
 	/* make the final decision on the type we want */
 	ret = -ENOMEDIUM;
-	if (force && !(vlocation->vldb.vidmask & (1<<type)))
+	if (force && !(vlocation->vldb.vidmask & (1 << type)))
 		goto error;
 
 	srvtmask = 0;
@@ -142,7 +147,7 @@
 		srvtmask |= vlocation->vldb.srvtmask[loop];
 
 	if (force) {
-		if (!(srvtmask & (1 <<type)))
+		if (!(srvtmask & (1 << type)))
 			goto error;
 	}
 	else if (srvtmask & AFS_VOL_VTM_RO) {
@@ -169,12 +174,12 @@
 	_debug("creating new volume record");
 
 	ret = -ENOMEM;
-	volume = kmalloc(sizeof(afs_volume_t),GFP_KERNEL);
+	volume = kmalloc(sizeof(afs_volume_t), GFP_KERNEL);
 	if (!volume)
 		goto error_up;
 
-	memset(volume,0,sizeof(afs_volume_t));
-	atomic_set(&volume->usage,1);
+	memset(volume, 0, sizeof(afs_volume_t));
+	atomic_set(&volume->usage, 1);
 	volume->type		= type;
 	volume->type_force	= force;
 	volume->cell		= cell;
@@ -207,7 +212,7 @@
 	vlocation->vols[type] = volume;
 
  success:
-	_debug("kAFS selected %s volume %08x",afs_voltypes[volume->type],volume->vid);
+	_debug("kAFS selected %s volume %08x", afs_voltypes[volume->type], volume->vid);
 	*_volume = volume;
 	ret = 0;
 
@@ -215,18 +220,17 @@
  error_up:
 	up_write(&cell->vl_sem);
  error:
-	if (vlocation)	afs_put_vlocation(vlocation);
-	if (cell)	afs_put_cell(cell);
+	afs_put_vlocation(vlocation);
+	afs_put_cell(cell);
 
-	_leave(" = %d (%p)",ret,volume);
+	_leave(" = %d (%p)", ret, volume);
 	return ret;
 
  error_discard:
 	up_write(&cell->vl_sem);
 
 	for (loop=volume->nservers-1; loop>=0; loop--)
-		if (volume->servers[loop])
-			afs_put_server(volume->servers[loop]);
+		afs_put_server(volume->servers[loop]);
 
 	kfree(volume);
 	goto error;
@@ -241,6 +245,9 @@
 	afs_vlocation_t *vlocation;
 	int loop;
 
+	if (!volume)
+		return;
+
 	_enter("%p",volume);
 
 	vlocation = volume->vlocation;
@@ -267,8 +274,7 @@
 	afs_put_vlocation(vlocation);
 
 	for (loop=volume->nservers-1; loop>=0; loop--)
-		if (volume->servers[loop])
-			afs_put_server(volume->servers[loop]);
+		afs_put_server(volume->servers[loop]);
 
 	kfree(volume);
 

Index: vnode.h
===================================================================
RCS file: /home/cvs/afs/fs/afs/vnode.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- vnode.h	6 Jun 2003 08:33:37 -0000	1.4
+++ vnode.h	4 Jul 2003 15:26:31 -0000	1.5
@@ -27,7 +27,9 @@
  */
 struct afs_cache_vnode
 {
-	afs_vnodeid_t		vnode;		/* vnode ID */
+	afs_vnodeid_t		vnode_id;	/* vnode ID */
+	unsigned		vnode_unique;	/* vnode ID uniquifier */
+	afs_dataversion_t	data_version;	/* data version */
 };
 
 extern struct cachefs_index_def afs_vnode_cache_index_def;

Index: vnode.c
===================================================================
RCS file: /home/cvs/afs/fs/afs/vnode.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- vnode.c	10 Jun 2003 17:49:49 -0000	1.6
+++ vnode.c	4 Jul 2003 15:26:31 -0000	1.7
@@ -72,8 +72,7 @@
 
 	spin_unlock(&vnode->lock);
 
-	if (oldserver)
-		afs_put_server(oldserver);
+	afs_put_server(oldserver);
 
 	_leave("");
 } /* end afs_vnode_cb_timed_out() */
@@ -137,8 +136,7 @@
 
 	wake_up_all(&vnode->update_waitq);
 
-	if (oldserver)
-		afs_put_server(oldserver);
+	afs_put_server(oldserver);
 
 	_leave("");
 
@@ -337,8 +335,12 @@
 
 	_enter("");
 
-	if (vnode->fid.vnode == cvnode->vnode)
-		return CACHEFS_MATCH_SUCCESS;
+	if (vnode->fid.vnode != cvnode->vnode_id)
+		return CACHEFS_MATCH_FAILED;
+
+	if (vnode->fid.unique != cvnode->vnode_unique ||
+	    vnode->status.version != cvnode->data_version)
+		return CACHEFS_MATCH_SUCCESS_DELETE;
 
 	return CACHEFS_MATCH_FAILED;
 } /* end afs_vnode_cache_match() */
@@ -354,6 +356,8 @@
 
 	_enter("");
 
-	cvnode->vnode = vnode->fid.vnode;
+	cvnode->vnode_id	= vnode->fid.vnode;
+	cvnode->vnode_unique	= vnode->fid.unique;
+	cvnode->data_version	= vnode->status.version;
 
 } /* end afs_vnode_cache_update() */

Index: vlocation.c
===================================================================
RCS file: /home/cvs/afs/fs/afs/vlocation.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- vlocation.c	9 Jun 2003 13:52:04 -0000	1.8
+++ vlocation.c	4 Jul 2003 15:26:31 -0000	1.9
@@ -75,21 +75,23 @@
  */
 static int afs_vlocation_access_vl_by_name(afs_vlocation_t *vlocation,
 					   const char *name,
+					   unsigned namesz,
 					   struct afs_cache_vlocation *vldb)
 {
 	afs_server_t *server = NULL;
 	afs_cell_t *cell = vlocation->cell;
 	int count, ret;
 
-	_enter("%s,%s,",cell->name,name);
+	_enter("%s,%*.*s,%u", cell->name, namesz, namesz, name, namesz);
 
 	ret = -ENOMEDIUM;
 	for (count=cell->vl_naddrs; count>0; count--) {
 		_debug("CellServ[%hu]: %08x",
-		       cell->vl_curr_svix,cell->vl_addrs[cell->vl_curr_svix].s_addr);
+		       cell->vl_curr_svix,
+		       cell->vl_addrs[cell->vl_curr_svix].s_addr);
 
 		/* try and create a server */
-		ret = afs_server_lookup(cell,&cell->vl_addrs[cell->vl_curr_svix],&server);
+		ret = afs_server_lookup(cell, &cell->vl_addrs[cell->vl_curr_svix], &server);
 		switch (ret) {
 		case 0:
 			break;
@@ -101,7 +103,7 @@
 		}
 
 		/* attempt to access the VL server */
-		ret = afs_rxvl_get_entry_by_name(server,name,vldb);
+		ret = afs_rxvl_get_entry_by_name(server, name, namesz, vldb);
 		switch (ret) {
 		case 0:
 			afs_put_server(server);
@@ -118,7 +120,7 @@
 			}
 			up_write(&server->sem);
 			afs_put_server(server);
-			if (ret==-ENOMEM || ret==-ENONET)
+			if (ret == -ENOMEM || ret == -ENONET)
 				goto out;
 			goto rotate;
 		case -ENOMEDIUM:
@@ -157,15 +159,16 @@
 	afs_cell_t *cell = vlocation->cell;
 	int count, ret;
 
-	_enter("%s,%x,%d,",cell->name,volid,voltype);
+	_enter("%s,%x,%d,", cell->name, volid, voltype);
 
 	ret = -ENOMEDIUM;
 	for (count=cell->vl_naddrs; count>0; count--) {
 		_debug("CellServ[%hu]: %08x",
-		       cell->vl_curr_svix,cell->vl_addrs[cell->vl_curr_svix].s_addr);
+		       cell->vl_curr_svix,
+		       cell->vl_addrs[cell->vl_curr_svix].s_addr);
 
 		/* try and create a server */
-		ret = afs_server_lookup(cell,&cell->vl_addrs[cell->vl_curr_svix],&server);
+		ret = afs_server_lookup(cell, &cell->vl_addrs[cell->vl_curr_svix], &server);
 		switch (ret) {
 		case 0:
 			break;
@@ -177,7 +180,7 @@
 		}
 
 		/* attempt to access the VL server */
-		ret = afs_rxvl_get_entry_by_id(server,volid,voltype,vldb);
+		ret = afs_rxvl_get_entry_by_id(server, volid, voltype, vldb);
 		switch (ret) {
 		case 0:
 			afs_put_server(server);
@@ -194,7 +197,7 @@
 			}
 			up_write(&server->sem);
 			afs_put_server(server);
-			if (ret==-ENOMEM || ret==-ENONET)
+			if (ret == -ENOMEM || ret == -ENONET)
 				goto out;
 			goto rotate;
 		case -ENOMEDIUM:
@@ -227,7 +230,8 @@
  * - lookup in the local cache if not able to find on the VL server
  * - insert/update in the local cache if did get a VL response
  */
-int afs_vlocation_lookup(afs_cell_t *cell, const char *name, afs_vlocation_t **_vlocation)
+int afs_vlocation_lookup(afs_cell_t *cell, const char *name, unsigned namesz,
+			 afs_vlocation_t **_vlocation)
 {
 	struct afs_cache_vlocation vldb;
 	struct list_head *_p;
@@ -236,48 +240,56 @@
 	afs_volid_t vid;
 	int active = 0, ret;
 
-	_enter(",%s,%s,",cell->name,name);
+	_enter("{%s},%*.*s,%u,", cell->name, namesz, namesz, name, namesz);
 
-	if (strlen(name)>sizeof(vlocation->vldb.name)) {
+	if (namesz > sizeof(vlocation->vldb.name)) {
 		_leave(" = -ENAMETOOLONG");
 		return -ENAMETOOLONG;
 	}
 
 	/* search the cell's active list first */
-	list_for_each(_p,&cell->vl_list) {
-		vlocation = list_entry(_p,afs_vlocation_t,link);
-		if (strncmp(vlocation->vldb.name,name,sizeof(vlocation->vldb.name))==0)
+	list_for_each(_p, &cell->vl_list) {
+		vlocation = list_entry(_p, afs_vlocation_t, link);
+		if (namesz < sizeof(vlocation->vldb.name) &&
+		    vlocation->vldb.name[namesz] != '\0')
+			continue;
+
+		if (memcmp(vlocation->vldb.name, name, namesz) == 0)
 			goto found_in_memory;
 	}
 
 	/* search the cell's graveyard list second */
 	spin_lock(&cell->vl_gylock);
-	list_for_each(_p,&cell->vl_graveyard) {
-		vlocation = list_entry(_p,afs_vlocation_t,link);
-		if (strncmp(vlocation->vldb.name,name,sizeof(vlocation->vldb.name))==0)
+	list_for_each(_p, &cell->vl_graveyard) {
+		vlocation = list_entry(_p, afs_vlocation_t, link);
+		if (namesz < sizeof(vlocation->vldb.name) &&
+		    vlocation->vldb.name[namesz] != '\0')
+			continue;
+
+		if (memcmp(vlocation->vldb.name, name, namesz) == 0)
 			goto found_in_graveyard;
 	}
 	spin_unlock(&cell->vl_gylock);
 
 	/* not in the cell's in-memory lists - create a new record */
-	vlocation = kmalloc(sizeof(afs_vlocation_t),GFP_KERNEL);
+	vlocation = kmalloc(sizeof(afs_vlocation_t), GFP_KERNEL);
 	if (!vlocation)
 		return -ENOMEM;
 
-	memset(vlocation,0,sizeof(afs_vlocation_t));
-	atomic_set(&vlocation->usage,1);
+	memset(vlocation, 0, sizeof(afs_vlocation_t));
+	atomic_set(&vlocation->usage, 1);
 	INIT_LIST_HEAD(&vlocation->link);
 	rwlock_init(&vlocation->lock);
-	strncpy(vlocation->vldb.name,name,sizeof(vlocation->vldb.name));
+	memcpy(vlocation->vldb.name, name, namesz);
 
-	afs_timer_init(&vlocation->timeout,&afs_vlocation_timer_ops);
-	afs_timer_init(&vlocation->upd_timer,&afs_vlocation_update_timer_ops);
-	afs_async_op_init(&vlocation->upd_op,&afs_vlocation_update_op_ops);
+	afs_timer_init(&vlocation->timeout, &afs_vlocation_timer_ops);
+	afs_timer_init(&vlocation->upd_timer, &afs_vlocation_update_timer_ops);
+	afs_async_op_init(&vlocation->upd_op, &afs_vlocation_update_op_ops);
 
 	afs_get_cell(cell);
 	vlocation->cell = cell;
 
-	list_add_tail(&vlocation->link,&cell->vl_list);
+	list_add_tail(&vlocation->link, &cell->vl_list);
 
 	/* we want to store it in the cache, plus it might already be encached */
 	cachefs_acquire_cookie(cell->cache,
@@ -289,9 +301,10 @@
 		goto found_in_cache;
 
 	/* try to look up an unknown volume in the cell VL databases by name */
-	ret = afs_vlocation_access_vl_by_name(vlocation,name,&vldb);
+	ret = afs_vlocation_access_vl_by_name(vlocation, name, namesz, &vldb);
 	if (ret<0) {
-		printk("kAFS: failed to locate '%s' in cell '%s'\n",name,cell->name);
+		printk("kAFS: failed to locate '%*.*s' in cell '%s'\n",
+		       namesz, namesz, name, cell->name);
 		goto error;
 	}
 
@@ -302,7 +315,7 @@
 	_debug("found in graveyard");
 	atomic_inc(&vlocation->usage);
 	list_del(&vlocation->link);
-	list_add_tail(&vlocation->link,&cell->vl_list);
+	list_add_tail(&vlocation->link, &cell->vl_list);
 	spin_unlock(&cell->vl_gylock);
 
 	afs_kafstimod_del_timer(&vlocation->timeout);
@@ -323,13 +336,13 @@
 	_debug("Locally Cached: %s %02x { %08x(%x) %08x(%x) %08x(%x) }",
 	       vlocation->vldb.name,
 	       vlocation->vldb.vidmask,
-	       ntohl(vlocation->vldb.servers[0].s_addr),vlocation->vldb.srvtmask[0],
-	       ntohl(vlocation->vldb.servers[1].s_addr),vlocation->vldb.srvtmask[1],
-	       ntohl(vlocation->vldb.servers[2].s_addr),vlocation->vldb.srvtmask[2]
+	       ntohl(vlocation->vldb.servers[0].s_addr), vlocation->vldb.srvtmask[0],
+	       ntohl(vlocation->vldb.servers[1].s_addr), vlocation->vldb.srvtmask[1],
+	       ntohl(vlocation->vldb.servers[2].s_addr), vlocation->vldb.srvtmask[2]
 	       );
 
 	_debug("Vids: %08x %08x %08x",
-	       vlocation->vldb.vid[0],vlocation->vldb.vid[1],vlocation->vldb.vid[2]);
+	       vlocation->vldb.vid[0], vlocation->vldb.vid[1], vlocation->vldb.vid[2]);
 
 	if (vlocation->vldb.vidmask & AFS_VOL_VTM_RW) {
 		vid = vlocation->vldb.vid[0];
@@ -349,12 +362,12 @@
 		voltype = 0;
 	}
 
-	ret = afs_vlocation_access_vl_by_id(vlocation,vid,voltype,&vldb);
+	ret = afs_vlocation_access_vl_by_id(vlocation, vid, voltype, &vldb);
 	switch (ret) {
 		/* net error */
 	default:
-		printk("kAFS: failed to volume '%s' (%x) up in '%s': %d\n",
-		       name,vid,cell->name,ret);
+		printk("kAFS: failed to volume '%*.*s' (%x) up in '%s': %d\n",
+		       namesz, namesz, name, vid, cell->name, ret);
 		goto error;
 
 		/* pulled from local cache into memory */
@@ -363,27 +376,30 @@
 
 		/* uh oh... looks like the volume got deleted */
 	case -ENOMEDIUM:
-		printk("kAFS: volume '%s' (%x) does not exist '%s'\n",name,vid,cell->name);
+		printk("kAFS: volume '%*.*s' (%x) does not exist '%s'\n",
+		       namesz, namesz, name, vid, cell->name);
 
 		/* TODO: make existing record unavailable */
 		goto error;
 	}
 
  found_on_vlserver:
-	_debug("Done VL Lookup: %s %02x { %08x(%x) %08x(%x) %08x(%x) }",
-	       name,
+	_debug("Done VL Lookup: %*.*s %02x { %08x(%x) %08x(%x) %08x(%x) }",
+	       namesz, namesz, name,
 	       vldb.vidmask,
-	       ntohl(vldb.servers[0].s_addr),vldb.srvtmask[0],
-	       ntohl(vldb.servers[1].s_addr),vldb.srvtmask[1],
-	       ntohl(vldb.servers[2].s_addr),vldb.srvtmask[2]
+	       ntohl(vldb.servers[0].s_addr), vldb.srvtmask[0],
+	       ntohl(vldb.servers[1].s_addr), vldb.srvtmask[1],
+	       ntohl(vldb.servers[2].s_addr), vldb.srvtmask[2]
 	       );
 
-	_debug("Vids: %08x %08x %08x",vldb.vid[0],vldb.vid[1],vldb.vid[2]);
+	_debug("Vids: %08x %08x %08x", vldb.vid[0], vldb.vid[1], vldb.vid[2]);
 
-	if (strncmp(vldb.name,name,sizeof(vlocation->vldb.name))!=0)
-		printk("kAFS: name of volume '%s' changed to '%s' on server\n",name,vldb.name);
+	if ((namesz < sizeof(vlocation->vldb.name) && vlocation->vldb.name[namesz] != '\0') ||
+	    memcmp(vldb.name, name, namesz) != 0)
+		printk("kAFS: name of volume '%*.*s' changed to '%s' on server\n",
+		       namesz, namesz, name, vldb.name);
 
-	memcpy(&vlocation->vldb,&vldb,sizeof(vlocation->vldb));
+	memcpy(&vlocation->vldb, &vldb, sizeof(vlocation->vldb));
 
 #if 0
 	/* add volume entry to local cache */
@@ -392,7 +408,7 @@
 		goto error;
 #endif
 
-	afs_kafstimod_add_timer(&vlocation->upd_timer,10*HZ);
+	afs_kafstimod_add_timer(&vlocation->upd_timer, 10*HZ);
 
 	*_vlocation = vlocation;
 	_leave(" = 0 (%p)",vlocation);
@@ -405,7 +421,7 @@
 		}
 		else {
 			list_del(&vlocation->link);
-			cachefs_relinquish_cookie(vlocation->cache,0);
+			cachefs_relinquish_cookie(vlocation->cache, 0);
 			afs_put_cell(vlocation->cell);
 			kfree(vlocation);
 		}
@@ -420,12 +436,17 @@
  * finish using a volume location record
  * - caller must have cell->vol_sem write-locked
  */
-void __afs_put_vlocation(afs_vlocation_t *vlocation)
+void __afs_put_vlocation(struct afs_vlocation *vlocation)
 {
-	afs_cell_t *cell = vlocation->cell;
+	struct afs_cell *cell;
+
+	if (!vlocation)
+		return;
 
 	_enter("%s",vlocation->vldb.name);
 
+	cell = vlocation->cell;
+
 	/* sanity check */
 	if (atomic_read(&vlocation->usage)<=0)
 		BUG();
@@ -459,11 +480,13 @@
  */
 void afs_put_vlocation(afs_vlocation_t *vlocation)
 {
-	afs_cell_t *cell = vlocation->cell;
+	if (vlocation) {
+		struct afs_cell *cell = vlocation->cell;
 
-	down_write(&cell->vl_sem);
-	__afs_put_vlocation(vlocation);
-	up_write(&cell->vl_sem);
+		down_write(&cell->vl_sem);
+		__afs_put_vlocation(vlocation);
+		up_write(&cell->vl_sem);
+	}
 } /* end afs_put_vlocation() */
 
 /*****************************************************************************/
@@ -575,10 +598,8 @@
 		printk("kAFS: Abandoning VL update '%s': %d\n",vlocation->vldb.name,ret);
 
 	/* discard the server record */
-	if (vlocation->upd_op.server) {
-		afs_put_server(vlocation->upd_op.server);
-		vlocation->upd_op.server = NULL;
-	}
+	afs_put_server(vlocation->upd_op.server);
+	vlocation->upd_op.server = NULL;
 
 	spin_lock(&afs_vlocation_update_lock);
 	afs_vlocation_update = NULL;
@@ -766,11 +787,9 @@
  try_next:
 	vlocation->upd_busy_cnt = 0;
 
-	if (vlocation->upd_op.server) {
-		/* discard the server record */
-		afs_put_server(vlocation->upd_op.server);
-		vlocation->upd_op.server = NULL;
-	}
+	/* discard the server record */
+	afs_put_server(vlocation->upd_op.server);
+	vlocation->upd_op.server = NULL;
 
 	tmp = vlocation->cell->vl_naddrs;
 	if (tmp==0)
@@ -832,20 +851,36 @@
  * match a VLDB record stored in the cache
  * - may also load target from entry
  */
-static cachefs_match_val_t afs_vlocation_cache_match(void *target, const void *entry)
+static cachefs_match_val_t afs_vlocation_cache_match(void *target,
+						     const void *entry)
 {
 	const struct afs_cache_vlocation *vldb = entry;
 	struct afs_vlocation *vlocation = target;
 
 	_enter("");
 
-	if (strncmp(vlocation->vldb.name,vldb->name,sizeof(vldb->name))==0) {
-		if (!vlocation->valid || vlocation->vldb.rtime == vldb->rtime) {
+	if (strncmp(vlocation->vldb.name,
+		    vldb->name,
+		    sizeof(vldb->name)) == 0) {
+		if (!vlocation->valid ||
+		    vlocation->vldb.rtime == vldb->rtime) {
 			struct_cpy(&vlocation->vldb,vldb);
 			vlocation->valid = 1;
+			return CACHEFS_MATCH_SUCCESS;
 		}
+		/* need to update cache if cached info differs */
+		else if (memcmp(&vlocation->vldb, vldb, sizeof(*vldb)) != 0) {
+			/* delete if VIDs for this name differ */
+			if (memcmp(&vlocation->vldb.vid,
+				   &vldb->vid,
+				   sizeof(vldb->vid)) != 0)
+				return CACHEFS_MATCH_SUCCESS_DELETE;
 
-		return CACHEFS_MATCH_SUCCESS;
+			return CACHEFS_MATCH_SUCCESS_UPDATE;
+		}
+		else {
+			return CACHEFS_MATCH_SUCCESS;
+		}
 	}
 
 	return CACHEFS_MATCH_FAILED;

Index: vlclient.h
===================================================================
RCS file: /home/cvs/afs/fs/afs/vlclient.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- vlclient.h	6 Jun 2003 08:33:37 -0000	1.4
+++ vlclient.h	4 Jul 2003 15:26:31 -0000	1.5
@@ -77,6 +77,7 @@
 /* look up a volume location database entry by name */
 extern int afs_rxvl_get_entry_by_name(afs_server_t *server,
 				      const char *volname,
+				      unsigned volnamesz,
 				      struct afs_cache_vlocation *entry);
 
 /* look up a volume location database entry by ID */

Index: vlclient.c
===================================================================
RCS file: /home/cvs/afs/fs/afs/vlclient.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- vlclient.c	6 Jun 2003 08:33:37 -0000	1.6
+++ vlclient.c	4 Jul 2003 15:26:31 -0000	1.7
@@ -176,7 +176,7 @@
 /*
  * look up a volume location database entry by name
  */
-int afs_rxvl_get_entry_by_name(afs_server_t *server, const char *volname,
+int afs_rxvl_get_entry_by_name(afs_server_t *server, const char *volname, unsigned volnamesz,
 			       struct afs_cache_vlocation *entry)
 {
 	DECLARE_WAITQUEUE(myself,current);
@@ -189,29 +189,29 @@
 	int ret, loop;
 	u32 *bp, param[2], zero;
 
-	_enter(",%s,",volname);
+	_enter(",%*.*s,%u,", volnamesz, volnamesz, volname, volnamesz);
 
-	memset(entry,0,sizeof(*entry));
+	memset(entry, 0, sizeof(*entry));
 
 	/* get hold of the vlserver connection */
-	ret = afs_server_get_vlconn(server,&conn);
+	ret = afs_server_get_vlconn(server, &conn);
 	if (ret<0)
 		goto out;
 
 	/* create a call through that connection */
-	ret = rxrpc_create_call(conn,NULL,NULL,afs_rxvl_aemap,&call);
-	if (ret<0) {
-		printk("kAFS: Unable to create call: %d\n",ret);
+	ret = rxrpc_create_call(conn, NULL, NULL, afs_rxvl_aemap, &call);
+	if (ret < 0) {
+		printk("kAFS: Unable to create call: %d\n", ret);
 		goto out_put_conn;
 	}
 	call->app_opcode = VLGETENTRYBYNAME;
 
 	/* we want to get event notifications from the call */
-	add_wait_queue(&call->waitq,&myself);
+	add_wait_queue(&call->waitq, &myself);
 
 	/* marshall the parameters */
-	piov[1].iov_len = strlen(volname);
-	piov[1].iov_base = (char*)volname;
+	piov[1].iov_len = volnamesz;
+	piov[1].iov_base = (char*) volname;
 
 	zero = 0;
 	piov[2].iov_len = (4 - (piov[1].iov_len & 3)) & 3;
@@ -224,16 +224,16 @@
 	piov[0].iov_base = param;
 
 	/* send the parameters to the server */
-	ret = rxrpc_call_write_data(call,3,piov,RXRPC_LAST_PACKET,GFP_NOFS,0,&sent);
+	ret = rxrpc_call_write_data(call, 3, piov, RXRPC_LAST_PACKET, GFP_NOFS, 0, &sent);
 	if (ret<0)
 		goto abort;
 
 	/* wait for the reply to completely arrive */
-	bp = rxrpc_call_alloc_scratch(call,384);
+	bp = rxrpc_call_alloc_scratch(call, 384);
 
-	ret = rxrpc_call_read_data(call,bp,384,RXRPC_CALL_READ_BLOCK|RXRPC_CALL_READ_ALL);
-	if (ret<0) {
-		if (ret==-ECONNABORTED) {
+	ret = rxrpc_call_read_data(call, bp, 384, RXRPC_CALL_READ_BLOCK|RXRPC_CALL_READ_ALL);
+	if (ret < 0) {
+		if (ret == -ECONNABORTED) {
 			ret = call->app_errno;
 			goto out_unwait;
 		}
@@ -281,12 +281,12 @@
 
  out_unwait:
 	set_current_state(TASK_RUNNING);
-	remove_wait_queue(&call->waitq,&myself);
+	remove_wait_queue(&call->waitq, &myself);
 	rxrpc_put_call(call);
  out_put_conn:
 	rxrpc_put_connection(conn);
  out:
-	_leave(" = %d",ret);
+	_leave(" = %d", ret);
 	return ret;
 
  abort:

Index: super.h
===================================================================
RCS file: /home/cvs/afs/fs/afs/super.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- super.h	14 Oct 2002 12:06:58 -0000	1.2
+++ super.h	4 Jul 2003 15:26:31 -0000	1.3
@@ -29,7 +29,7 @@
  */
 struct afs_super_info
 {
-	afs_volume_t		*volume;	/* volume record */
+	struct afs_volume	*volume;	/* volume record */
 	char			rwparent;	/* T if parent is R/W AFS volume */
 };
 

Index: super.c
===================================================================
RCS file: /home/cvs/afs/fs/afs/super.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- super.c	16 Oct 2002 12:45:03 -0000	1.8
+++ super.c	4 Jul 2003 15:26:31 -0000	1.9
@@ -29,18 +29,26 @@
 
 #define AFS_FS_MAGIC 0x6B414653 /* 'kAFS' */
 
+struct afs_mount_params {
+	int			rwpath;
+	struct afs_cell		*default_cell;
+	struct afs_volume	*volume;
+};
+
 static inline char *strdup(const char *s)
 {
-	char *ns = kmalloc(strlen(s)+1,GFP_KERNEL);
+	char *ns = kmalloc(strlen(s) + 1, GFP_KERNEL);
 	if (ns)
-		strcpy(ns,s);
+		strcpy(ns, s);
 	return ns;
 }
 
-static void afs_i_init_once(void *foo, kmem_cache_t *cachep, unsigned long flags);
+static void afs_i_init_once(void *foo, kmem_cache_t *cachep,
+			    unsigned long flags);
 
 static struct super_block *afs_get_sb(struct file_system_type *fs_type,
-				      int flags, char *dev_name, void *data);
+				      int flags, const char *dev_name,
+				      void *data);
 
 static struct inode *afs_alloc_inode(struct super_block *sb);
 
@@ -65,6 +73,7 @@
 };
 
 static kmem_cache_t *afs_inode_cachep;
+static atomic_t afs_count_active_inodes;
 
 /*****************************************************************************/
 /*
@@ -76,14 +85,18 @@
 
 	kenter("");
 
+	afs_timer_init(&afs_mntpt_expiry_timer, &afs_mntpt_expiry_timer_ops);
+
 	/* create ourselves an inode cache */
+	atomic_set(&afs_count_active_inodes, 0);
+
 	ret = -ENOMEM;
 	afs_inode_cachep = kmem_cache_create("afs_inode_cache",
-						sizeof(afs_vnode_t),
-						0,
-						SLAB_HWCACHE_ALIGN,
-						afs_i_init_once,
-						NULL);
+					     sizeof(afs_vnode_t),
+					     0,
+					     SLAB_HWCACHE_ALIGN,
+					     afs_i_init_once,
+					     NULL);
 	if (!afs_inode_cachep) {
 		printk(KERN_NOTICE "kAFS: Failed to allocate inode cache\n");
 		return ret;
@@ -91,9 +104,9 @@
 
 	/* now export our filesystem to lesser mortals */
 	ret = register_filesystem(&afs_fs_type);
-	if (ret<0) {
+	if (ret < 0) {
 		kmem_cache_destroy(afs_inode_cachep);
-		kleave(" = %d",ret);
+		kleave(" = %d", ret);
 		return ret;
 	}
 
@@ -107,11 +120,16 @@
  */
 void __exit afs_fs_exit(void)
 {
-	/* destroy our private inode cache */
-	kmem_cache_destroy(afs_inode_cachep);
-
 	unregister_filesystem(&afs_fs_type);
 
+	if (atomic_read(&afs_count_active_inodes) != 0) {
+		printk("kAFS: %d active inode objects still present\n",
+		       atomic_read(&afs_count_active_inodes));
+		BUG();
+	}
+
+	kmem_cache_destroy(afs_inode_cachep);
+
 } /* end afs_fs_exit() */
 
 /*****************************************************************************/
@@ -121,7 +139,7 @@
 static int want_arg(char **_value, const char *option)
 {
 	if (!_value || !*_value || !**_value) {
-		printk(KERN_NOTICE "kAFS: %s: argument missing\n",option);
+		printk(KERN_NOTICE "kAFS: %s: argument missing\n", option);
 		return 0;
 	}
 	return 1;
@@ -129,27 +147,13 @@
 
 /*****************************************************************************/
 /*
- * check that there is a value
- */
-#if 0
-static int want_value(char **_value, const char *option)
-{
-	if (!_value || !*_value || !**_value) {
-		printk(KERN_NOTICE "kAFS: %s: argument incomplete\n",option);
-		return 0;
-	}
-	return 1;
-} /* end want_value() */
-#endif
-
-/*****************************************************************************/
-/*
  * check that there's no subsequent value
  */
 static int want_no_value(char *const *_value, const char *option)
 {
 	if (*_value && **_value) {
-		printk(KERN_NOTICE "kAFS: %s: Invalid argument: %s\n",option,*_value);
+		printk(KERN_NOTICE "kAFS: %s: Invalid argument: %s\n",
+		       option, *_value);
 		return 0;
 	}
 	return 1;
@@ -157,150 +161,55 @@
 
 /*****************************************************************************/
 /*
- * extract a number from an option string value
- */
-#if 0
-static int want_number(char **_value, const char *option, unsigned long *number,
-		       unsigned long limit)
-{
-	char *value = *_value;
-
-	if (!want_value(_value,option))
-		return 0;
-
-	*number = simple_strtoul(value,_value,0);
-
-	if (value==*_value) {
-		printk(KERN_NOTICE "kAFS: %s: Invalid number: %s\n",option,value);
-		return 0;
-	}
-
-	if (*number>limit) {
-		printk(KERN_NOTICE "kAFS: %s: numeric value %lu > %lu\n",option,*number,limit);
-		return 0;
-	}
-
-	return 1;
-} /* end want_number() */
-#endif
-
-/*****************************************************************************/
-/*
- * extract a separator from an option string value
- */
-#if 0
-static int want_sep(char **_value, const char *option, char sep)
-{
-	if (!want_value(_value,option))
-		return 0;
-
-	if (*(*_value)++ != sep) {
-		printk(KERN_NOTICE "kAFS: %s: '%c' expected: %s\n",option,sep,*_value-1);
-		return 0;
-	}
-
-	return 1;
-} /* end want_number() */
-#endif
-
-/*****************************************************************************/
-/*
- * extract an IP address from an option string value
- */
-#if 0
-static int want_ipaddr(char **_value, const char *option, struct in_addr *addr)
-{
-	unsigned long number[4];
-
-	if (!want_value(_value,option))
-		return 0;
-
-	if (!want_number(_value,option,&number[0],255) ||
-	    !want_sep(_value,option,'.') ||
-	    !want_number(_value,option,&number[1],255) ||
-	    !want_sep(_value,option,'.') ||
-	    !want_number(_value,option,&number[2],255) ||
-	    !want_sep(_value,option,'.') ||
-	    !want_number(_value,option,&number[3],255))
-		return 0;
-
-	((u8*)addr)[0] = number[0];
-	((u8*)addr)[1] = number[1];
-	((u8*)addr)[2] = number[2];
-	((u8*)addr)[3] = number[3];
-
-	return 1;
-} /* end want_numeric() */
-#endif
-
-/*****************************************************************************/
-/*
  * parse the mount options
  * - this function has been shamelessly adapted from the ext3 fs which shamelessly adapted it from
  *   the msdos fs
  */
-static int afs_super_parse_options(struct afs_super_info *as, char *options, char **devname)
+static int afs_super_parse_options(struct afs_mount_params *params,
+				   char *options,
+				   const char **devname)
 {
 	char *key, *value;
 	int ret;
 
-	_enter("%s",options);
+	_enter("%s", options);
+
+	options[PAGE_SIZE - 1] = 0;
 
 	ret = 0;
-	while ((key = strsep(&options,",")))
+	while ((key = strsep(&options, ",")))
 	{
-		value = strchr(key,'=');
+		value = strchr(key, '=');
 		if (value)
 			*value++ = 0;
 
-		printk("kAFS: KEY: %s, VAL:%s\n",key,value?:"-");
+		printk("kAFS: KEY: %s, VAL:%s\n", key, value ?: "-");
 
-		if (strcmp(key,"rwpath")==0) {
-			if (!want_no_value(&value,"rwpath")) return -EINVAL;
-			as->rwparent = 1;
+		if (strcmp(key, "rwpath") == 0) {
+			if (!want_no_value(&value, "rwpath"))
+				return -EINVAL;
+			params->rwpath = 1;
 			continue;
 		}
-		else if (strcmp(key,"vol")==0) {
-			if (!want_arg(&value,"vol")) return -EINVAL;
+		else if (strcmp(key, "vol") == 0) {
+			if (!want_arg(&value, "vol"))
+				return -EINVAL;
 			*devname = value;
 			continue;
 		}
-
-#if 0
-		if (strcmp(key,"servers")==0) {
-			if (!want_arg(&value,"servers")) return -EINVAL;
-
-			_debug("servers=%s",value);
-
-			for (;;) {
-				struct in_addr addr;
-
-				if (!want_ipaddr(&value,"servers",&addr))
-					return -EINVAL;
-
-				ret = afs_create_server(as->cell,&addr,&as->server);
-				if (ret<0) {
-					printk("kAFS: unable to create server: %d\n",ret);
-					return ret;
-				}
-
-				if (!*value)
-					break;
-
-				if (as->server) {
-					printk(KERN_NOTICE
-					       "kAFS: only one server can be specified\n");
-					return -EINVAL;
-				}
-
-				if (!want_sep(&value,"servers",':'))
-					return -EINVAL;
-			}
+		else if (strcmp(key, "cell") == 0) {
+			if (!want_arg(&value, "cell"))
+				return -EINVAL;
+			afs_put_cell(params->default_cell);
+			ret = afs_cell_lookup(value,
+					      strlen(value),
+					      &params->default_cell);
+			if (ret < 0)
+				return -EINVAL;
 			continue;
 		}
-#endif
 
-		printk("kAFS: Unknown mount option: '%s'\n",key);
+		printk("kAFS: Unknown mount option: '%s'\n",  key);
 		ret = -EINVAL;
 		goto error;
 	}
@@ -308,61 +217,48 @@
 	ret = 0;
 
  error:
-	_leave(" = %d",ret);
-
+	_leave(" = %d", ret);
 	return ret;
 } /* end afs_super_parse_options() */
 
 /*****************************************************************************/
 /*
+ * check a superblock to see if it's the one we're looking for
+ */
+static int afs_test_super(struct super_block *sb, void *data)
+{
+	struct afs_mount_params *params = data;
+	struct afs_super_info *as = sb->s_fs_info;
+
+	return as->volume == params->volume;
+} /* end afs_test_super() */
+
+/*****************************************************************************/
+/*
  * fill in the superblock
  */
-static int afs_fill_super(struct super_block *sb, void *_data, int silent)
+static int afs_fill_super(struct super_block *sb, void *data, int silent)
 {
+	struct afs_mount_params *params = data;
 	struct afs_super_info *as = NULL;
 	struct dentry *root = NULL;
 	struct inode *inode = NULL;
 	afs_fid_t fid;
-	void **data = _data;
-	char *options, *devname;
 	int ret;
 
-	_enter("");
-
-	if (!data) {
-		_leave(" = -EINVAL");
-		return -EINVAL;
-	}
-	devname = data[0];
-	options = data[1];
-	if (options)
-		options[PAGE_SIZE-1] = 0;
+	kenter("");
 
 	/* allocate a superblock info record */
-	as = kmalloc(sizeof(struct afs_super_info),GFP_KERNEL);
+	as = kmalloc(sizeof(struct afs_super_info), GFP_KERNEL);
 	if (!as) {
 		_leave(" = -ENOMEM");
 		return -ENOMEM;
 	}
 
-	memset(as,0,sizeof(struct afs_super_info));
-
-	/* parse the options */
-	if (options) {
-		ret = afs_super_parse_options(as,options,&devname);
-		if (ret<0)
-			goto error;
-		if (!devname) {
-			printk("kAFS: no volume name specified\n");
-			ret = -EINVAL;
-			goto error;
-		}
-	}
+	memset(as, 0, sizeof(struct afs_super_info));
 
-	/* parse the device name */
-	ret = afs_volume_lookup(devname,as->rwparent,&as->volume);
-	if (ret<0)
-		goto error;
+	afs_get_volume(params->volume);
+	as->volume = params->volume;
 
 	/* fill in the superblock */
 	sb->s_blocksize		= PAGE_CACHE_SIZE;
@@ -375,8 +271,8 @@
 	fid.vid		= as->volume->vid;
 	fid.vnode	= 1;
 	fid.unique	= 1;
-	ret = afs_iget(sb,&fid,&inode);
-	if (ret<0)
+	ret = afs_iget(sb, &fid, &inode);
+	if (ret < 0)
 		goto error;
 
 	ret = -ENOMEM;
@@ -386,19 +282,18 @@
 
 	sb->s_root = root;
 
-	_leave(" = 0");
+	kleave(" = 0");
 	return 0;
 
  error:
-	if (root) dput(root);
-	if (inode) iput(inode);
-	if (as) {
-		if (as->volume)		afs_put_volume(as->volume);
-		kfree(as);
-	}
+	dput(root);
+	iput(inode);
+	afs_put_volume(as->volume);
+	kfree(as);
+
 	sb->s_fs_info = NULL;
 
-	_leave(" = %d",ret);
+	kleave(" = %d", ret);
 	return ret;
 } /* end afs_fill_super() */
 
@@ -409,31 +304,78 @@
  */
 static struct super_block *afs_get_sb(struct file_system_type *fs_type,
 				      int flags,
-				      char *dev_name,
+				      const char *dev_name,
 				      void *options)
 {
+	struct afs_mount_params params;
 	struct super_block *sb;
-	void *data[2] = { dev_name, options };
 	int ret;
 
-	_enter(",,%s,%p",dev_name,options);
+	kenter(",,%s,%p", dev_name, options);
+
+	memset(&params, 0, sizeof(params));
 
 	/* start the cache manager */
 	ret = afscm_start();
-	if (ret<0) {
-		_leave(" = %d",ret);
+	if (ret < 0) {
+		kleave(" = %d", ret);
 		return ERR_PTR(ret);
 	}
 
+	/* parse the options */
+	if (options) {
+		ret = afs_super_parse_options(&params, options, &dev_name);
+		if (ret < 0)
+			goto error;
+		if (!dev_name) {
+			printk("kAFS: no volume name specified\n");
+			ret = -EINVAL;
+			goto error;
+		}
+	}
+
+	/* parse the device name */
+	ret = afs_volume_lookup(dev_name,
+				params.default_cell,
+				params.rwpath,
+				&params.volume);
+	if (ret < 0)
+		goto error;
+
 	/* allocate a deviceless superblock */
-	sb = get_sb_nodev(fs_type,flags,data,afs_fill_super);
-	if (IS_ERR(sb)) {
+#if 0
+	sb = get_sb_nodev(fs_type, flags, &params, afs_fill_super);
+	if (IS_ERR(sb))
 		afscm_stop();
-		return sb;
+
+#else
+	sb = sget(fs_type, afs_test_super, set_anon_super, &params);
+	if (IS_ERR(sb))
+		goto error;
+
+	sb->s_flags = flags;
+
+	ret = afs_fill_super(sb, &params, flags & MS_VERBOSE ? 1 : 0);
+	if (ret < 0) {
+		up_write(&sb->s_umount);
+		deactivate_super(sb);
+		goto error;
 	}
+	sb->s_flags |= MS_ACTIVE;
 
-	_leave("");
+#endif
+
+	afs_put_volume(params.volume);
+	afs_put_cell(params.default_cell);
+	kleave(" = %p", sb);
 	return sb;
+
+ error:
+	afs_put_volume(params.volume);
+	afs_put_cell(params.default_cell);
+	afscm_stop();
+	kleave(" = %d", ret);
+	return ERR_PTR(ret);
 } /* end afs_get_sb() */
 
 /*****************************************************************************/
@@ -446,11 +388,7 @@
 
 	_enter("");
 
-	if (as) {
-		if (as->volume)		afs_put_volume(as->volume);
-	}
-
-	/* stop the cache manager */
+	afs_put_volume(as->volume);
 	afscm_stop();
 
 	_leave("");
@@ -460,18 +398,21 @@
 /*
  * initialise an inode cache slab element prior to any use
  */
-static void afs_i_init_once(void *_vnode, kmem_cache_t *cachep, unsigned long flags)
+static void afs_i_init_once(void *_vnode, kmem_cache_t *cachep,
+			    unsigned long flags)
 {
 	afs_vnode_t *vnode = (afs_vnode_t *) _vnode;
 
-	if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) == SLAB_CTOR_CONSTRUCTOR) {
-		memset(vnode,0,sizeof(*vnode));
+	if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
+	    SLAB_CTOR_CONSTRUCTOR) {
+		memset(vnode, 0, sizeof(*vnode));
 		inode_init_once(&vnode->vfs_inode);
 		init_waitqueue_head(&vnode->update_waitq);
 		spin_lock_init(&vnode->lock);
 		INIT_LIST_HEAD(&vnode->cb_link);
 		INIT_LIST_HEAD(&vnode->cb_hash_link);
-		afs_timer_init(&vnode->cb_timeout,&afs_vnode_cb_timed_out_ops);
+		afs_timer_init(&vnode->cb_timeout,
+			       &afs_vnode_cb_timed_out_ops);
 	}
 
 } /* end afs_i_init_once() */
@@ -484,16 +425,19 @@
 {
 	afs_vnode_t *vnode;
 
-	vnode = (afs_vnode_t *) kmem_cache_alloc(afs_inode_cachep,SLAB_KERNEL);
+	vnode = (afs_vnode_t *)
+		kmem_cache_alloc(afs_inode_cachep, SLAB_KERNEL);
 	if (!vnode)
 		return NULL;
 
-	memset(&vnode->fid,0,sizeof(vnode->fid));
-	memset(&vnode->status,0,sizeof(vnode->status));
+	atomic_inc(&afs_count_active_inodes);
 
-	vnode->volume = NULL;
-	vnode->update_cnt = 0;
-	vnode->flags = 0;
+	memset(&vnode->fid, 0, sizeof(vnode->fid));
+	memset(&vnode->status, 0, sizeof(vnode->status));
+
+	vnode->volume		= NULL;
+	vnode->update_cnt	= 0;
+	vnode->flags		= 0;
 
 	return &vnode->vfs_inode;
 } /* end afs_alloc_inode() */
@@ -504,6 +448,10 @@
  */
 static void afs_destroy_inode(struct inode *inode)
 {
-	_enter("{%lu}",inode->i_ino);
+	_enter("{%lu}", inode->i_ino);
+
 	kmem_cache_free(afs_inode_cachep, AFS_FS_I(inode));
+
+	atomic_dec(&afs_count_active_inodes);
+
 } /* end afs_destroy_inode() */

Index: server.c
===================================================================
RCS file: /home/cvs/afs/fs/afs/server.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- server.c	16 Oct 2002 09:59:50 -0000	1.3
+++ server.c	4 Jul 2003 15:26:31 -0000	1.4
@@ -148,6 +148,9 @@
 {
 	afs_cell_t *cell;
 
+	if (!server)
+		return;
+
 	_enter("%p",server);
 
 	cell = server->cell;

Index: mntpt.c
===================================================================
RCS file: /home/cvs/afs/fs/afs/mntpt.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- mntpt.c	16 Oct 2002 12:45:03 -0000	1.6
+++ mntpt.c	4 Jul 2003 15:26:31 -0000	1.7
@@ -16,13 +16,20 @@
 #include <linux/slab.h>
 #include <linux/fs.h>
 #include <linux/pagemap.h>
+#include <linux/mount.h>
+#include <linux/namei.h>
+#include <linux/namespace.h>
+#include "super.h"
+#include "cell.h"
 #include "volume.h"
 #include "vnode.h"
+#define __KDEBUG
 #include "internal.h"
 
 
 static struct dentry *afs_mntpt_lookup(struct inode *dir, struct dentry *dentry);
 static int afs_mntpt_open(struct inode *inode, struct file *file);
+static int afs_mntpt_follow_link(struct dentry *dentry, struct nameidata *nd);
 
 struct file_operations afs_mntpt_file_operations = {
 	.open		= afs_mntpt_open,
@@ -30,10 +37,23 @@
 
 struct inode_operations afs_mntpt_inode_operations = {
 	.lookup		= afs_mntpt_lookup,
+	.follow_link	= afs_mntpt_follow_link,
 	.readlink	= page_readlink,
 	.getattr	= afs_inode_getattr,
 };
 
+static LIST_HEAD(afs_vfsmounts);
+
+static void afs_mntpt_expiry_timed_out(struct afs_timer *timer);
+
+struct afs_timer_ops afs_mntpt_expiry_timer_ops = {
+	.timed_out	= afs_mntpt_expiry_timed_out,
+};
+
+struct afs_timer afs_mntpt_expiry_timer;
+
+unsigned long afs_mntpt_expiry_timeout = 20;
+
 /*****************************************************************************/
 /*
  * check a symbolic link to see whether it actually encodes a mountpoint
@@ -95,6 +115,13 @@
  */
 static struct dentry *afs_mntpt_lookup(struct inode *dir, struct dentry *dentry)
 {
+	kenter("%p,%p{%p{%s},%s}",
+	       dir,
+	       dentry,
+	       dentry->d_parent,
+	       dentry->d_parent ? dentry->d_parent->d_name.name : (const unsigned char*)"",
+	       dentry->d_name.name);
+
 	return ERR_PTR(-EREMOTE);
 } /* end afs_mntpt_lookup() */
 
@@ -104,5 +131,144 @@
  */
 static int afs_mntpt_open(struct inode *inode, struct file *file)
 {
+	kenter("%p,%p{%p{%s},%s}",
+	       inode, file,
+	       file->f_dentry->d_parent,
+	       file->f_dentry->d_parent ? file->f_dentry->d_parent->d_name.name : (const unsigned char*)"",
+	       file->f_dentry->d_name.name);
+
 	return -EREMOTE;
 } /* end afs_mntpt_open() */
+
+/*****************************************************************************/
+/*
+ * create a vfsmount to be automounted
+ */
+static struct vfsmount *afs_mntpt_do_automount(struct dentry *mntpt)
+{
+	struct afs_super_info *super;
+	struct vfsmount *mnt;
+	struct page *page = NULL;
+	size_t size;
+	char *buf, *devname = NULL, *options = NULL;
+	int ret;
+
+	kenter("{%s}", mntpt->d_name.name);
+
+	BUG_ON(!mntpt->d_inode);
+
+	ret = -EINVAL;
+	size = mntpt->d_inode->i_size;
+	if (size > PAGE_SIZE - 1)
+		goto error;
+
+	ret = -ENOMEM;
+	devname = (char *) get_zeroed_page(GFP_KERNEL);
+	if (!devname)
+		goto error;
+
+	options = (char *) get_zeroed_page(GFP_KERNEL);
+	if (!options)
+		goto error;
+
+	/* read the contents of the AFS special symlink */
+	page = read_cache_page(mntpt->d_inode->i_mapping,
+			       0,
+			       (filler_t*)mntpt->d_inode->i_mapping->a_ops->readpage,
+			       NULL);
+	if (IS_ERR(page)) {
+		ret = PTR_ERR(page);
+		goto error;
+	}
+
+	ret = -EIO;
+	wait_on_page_locked(page);
+	if (!PageUptodate(page) || PageError(page))
+		goto error;
+
+	buf = kmap(page);
+	memcpy(devname, buf, size);
+	kunmap(page);
+	page_cache_release(page);
+	page = NULL;
+
+	/* work out what options we want */
+	super = AFS_FS_S(mntpt->d_sb);
+	memcpy(options, "cell=", 5);
+	strcpy(options + 5, super->volume->cell->name);
+	if (super->volume->type == AFSVL_RWVOL)
+		strcat(options,",rwpath");
+
+	/* try and do the mount */
+	kdebug("--- attempting mount %s -o %s ---", devname, options);
+	mnt = do_kern_mount("afs", 0, devname, options);
+	kdebug("--- mount result %p ---", mnt);
+
+	free_page((unsigned long)devname);
+	free_page((unsigned long)options);
+	kleave(" = %p",mnt);
+	return mnt;
+
+ error:
+	if (page)
+		page_cache_release(page);
+	if (devname)
+		free_page((unsigned long)devname);
+	if (options)
+		free_page((unsigned long)options);
+	kleave(" = %d",ret);
+	return ERR_PTR(ret);
+} /* end afs_mntpt_do_automount() */
+
+/*****************************************************************************/
+/*
+ * follow a link from a mountpoint directory, thus causing it to be mounted
+ */
+static int afs_mntpt_follow_link(struct dentry *dentry, struct nameidata *nd)
+{
+	struct nameidata newnd;
+	struct vfsmount *newmnt;
+	int err;
+
+	kenter("%p{%s},{%s:%p{%s}}",
+	       dentry,
+	       dentry->d_name.name,
+	       nd->mnt->mnt_devname,
+	       dentry,
+	       nd->dentry->d_name.name);
+
+	newmnt = afs_mntpt_do_automount(dentry);
+	if (IS_ERR(newmnt))
+		return PTR_ERR(newmnt);
+
+	struct_cpy(&newnd,nd);
+	newnd.dentry = dentry;
+	err = do_add_mount(newmnt, &newnd, 0, &afs_vfsmounts);
+
+	if (!err) {
+		path_release(nd);
+		mntget(newmnt);
+		nd->mnt = newmnt;
+		dget(newmnt->mnt_root);
+		nd->dentry = newmnt->mnt_root;
+	}
+
+	kleave(" = %d", err);
+	return err;
+} /* end afs_mntpt_follow_link() */
+
+/*****************************************************************************/
+/*
+ * handle mountpoint expiry timer going off
+ */
+static void afs_mntpt_expiry_timed_out(struct afs_timer *timer)
+{
+	kenter("");
+
+	mark_mounts_for_expiry(&afs_vfsmounts);
+
+	afs_kafstimod_add_timer(&afs_mntpt_expiry_timer,
+				afs_mntpt_expiry_timeout * HZ);
+
+	kleave("");
+} /* end afs_mntpt_expiry_timed_out() */

Index: main.c
===================================================================
RCS file: /home/cvs/afs/fs/afs/main.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- main.c	6 Jun 2003 08:33:37 -0000	1.11
+++ main.c	4 Jul 2003 15:26:31 -0000	1.12
@@ -210,3 +210,48 @@
 	_leave("");
 
 } /* end afs_discarding_peer() */
+
+/*****************************************************************************/
+/*
+ * clear the dead space between task_struct and kernel stack
+ * - called by supplying -finstrument-functions to gcc
+ */
+#if 1
+void __cyg_profile_func_enter (void *this_fn, void *call_site)
+__attribute__((no_instrument_function));
+
+void __cyg_profile_func_enter (void *this_fn, void *call_site)
+{
+       asm volatile("  movl    %%esp,%%edi     \n"
+                    "  andl    %0,%%edi        \n"
+                    "  addl    %1,%%edi        \n"
+                    "  movl    %%esp,%%ecx     \n"
+                    "  subl    %%edi,%%ecx     \n"
+                    "  shrl    $2,%%ecx        \n"
+                    "  movl    $0xedededed,%%eax     \n"
+                    "  rep stosl               \n"
+                    :
+                    : "i"(~(THREAD_SIZE-1)), "i"(sizeof(struct thread_info))
+                    : "eax", "ecx", "edi", "memory", "cc"
+                    );
+}
+
+void __cyg_profile_func_exit(void *this_fn, void *call_site)
+__attribute__((no_instrument_function));
+
+void __cyg_profile_func_exit(void *this_fn, void *call_site)
+{
+       asm volatile("  movl    %%esp,%%edi     \n"
+                    "  andl    %0,%%edi        \n"
+                    "  addl    %1,%%edi        \n"
+                    "  movl    %%esp,%%ecx     \n"
+                    "  subl    %%edi,%%ecx     \n"
+                    "  shrl    $2,%%ecx        \n"
+                    "  movl    $0xdadadada,%%eax     \n"
+                    "  rep stosl               \n"
+                    :
+                    : "i"(~(THREAD_SIZE-1)), "i"(sizeof(struct thread_info))
+                    : "eax", "ecx", "edi", "memory", "cc"
+                    );
+}
+#endif

Index: kafstimod.c
===================================================================
RCS file: /home/cvs/afs/fs/afs/kafstimod.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- kafstimod.c	9 Apr 2003 15:43:07 -0000	1.6
+++ kafstimod.c	4 Jul 2003 15:26:31 -0000	1.7
@@ -177,7 +177,7 @@
 	wake_up(&kafstimod_sleepq);
 
 	_leave("");
-} /* end afs_kafstimod_queue_vlocation() */
+} /* end afs_kafstimod_add_timer() */
 
 /*****************************************************************************/
 /*

Index: internal.h
===================================================================
RCS file: /home/cvs/afs/fs/afs/internal.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- internal.h	6 Jun 2003 08:33:37 -0000	1.14
+++ internal.h	4 Jul 2003 15:26:31 -0000	1.15
@@ -28,7 +28,7 @@
 #define kproto(FMT, a...)	printk("### "FMT"\n" , ## a)
 #define knet(FMT, a...)		printk(FMT"\n" , ## a)
 
-#if 0
+#ifdef __KDEBUG
 #define _enter(FMT, a...)	kenter(FMT , ## a)
 #define _leave(FMT, a...)	kleave(FMT , ## a)
 #define _debug(FMT, a...)	kdebug(FMT , ## a)
@@ -92,8 +92,11 @@
  */
 extern struct inode_operations afs_mntpt_inode_operations;
 extern struct file_operations afs_mntpt_file_operations;
+extern struct afs_timer afs_mntpt_expiry_timer;
+extern struct afs_timer_ops afs_mntpt_expiry_timer_ops;
 
 extern int afs_mntpt_check_symlink(afs_vnode_t *vnode);
+extern unsigned long afs_mntpt_expiry_timeout;
 
 /*
  * super.c

Index: inode.c
===================================================================
RCS file: /home/cvs/afs/fs/afs/inode.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- inode.c	9 Jun 2003 13:39:13 -0000	1.10
+++ inode.c	4 Jul 2003 15:26:31 -0000	1.11
@@ -79,7 +79,7 @@
 	inode->i_mapping->a_ops	= &afs_fs_aops;
 
 	/* check to see whether a symbolic link is really a mountpoint */
-	if (vnode->status.type==AFS_FTYPE_SYMLINK) {
+	if (vnode->status.type == AFS_FTYPE_SYMLINK) {
 		afs_mntpt_check_symlink(vnode);
 
 		if (vnode->flags & AFS_VNODE_MOUNTPOINT) {
@@ -105,7 +105,7 @@
 
 	ret = afs_vnode_fetch_status(vnode);
 
-	if (ret==0)
+	if (ret == 0)
 		ret = afs_inode_map_status(vnode);
 
 	return ret;
@@ -120,8 +120,8 @@
 {
 	struct afs_iget_data *data = opaque;
 
-	/* only match inodes with the same version number */
-	return inode->i_ino==data->fid.vnode && inode->i_version==data->fid.unique;
+	return inode->i_ino == data->fid.vnode &&
+		inode->i_version == data->fid.unique;
 } /* end afs_iget5_test() */
 
 /*****************************************************************************/
@@ -145,7 +145,8 @@
 /*
  * inode retrieval
  */
-inline int afs_iget(struct super_block *sb, afs_fid_t *fid, struct inode **_inode)
+inline int afs_iget(struct super_block *sb, afs_fid_t *fid,
+		    struct inode **_inode)
 {
 	struct afs_iget_data data = { fid: *fid };
 	struct afs_super_info *as;
@@ -153,12 +154,13 @@
 	struct inode *inode;
 	int ret;
 
-	_enter(",{%u,%u,%u},,",fid->vid,fid->vnode,fid->unique);
+	_enter(",{%u,%u,%u},,", fid->vid, fid->vnode, fid->unique);
 
 	as = sb->s_fs_info;
 	data.volume = as->volume;
 
-	inode = iget5_locked(sb,fid->vnode,afs_iget5_test,afs_iget5_set,&data);
+	inode = iget5_locked(sb, fid->vnode, afs_iget5_test, afs_iget5_set,
+			     &data);
 	if (!inode) {
 		_leave(" = -ENOMEM");
 		return -ENOMEM;
@@ -173,7 +175,7 @@
 			*_inode = inode;
 		else
 			iput(inode);
-		_leave(" = %d",ret);
+		_leave(" = %d", ret);
 		return ret;
 	}
 
@@ -208,7 +210,7 @@
 	unlock_new_inode(inode);
 	iput(inode);
 
-	_leave(" = %d [bad]",ret);
+	_leave(" = %d [bad]", ret);
 	return ret;
 } /* end afs_iget() */
 
@@ -216,7 +218,8 @@
 /*
  * read the attributes of an inode
  */
-int afs_inode_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
+int afs_inode_getattr(struct vfsmount *mnt, struct dentry *dentry,
+		      struct kstat *stat)
 {
 	struct inode *inode;
 	afs_vnode_t *vnode;
@@ -224,23 +227,25 @@
 
 	inode = dentry->d_inode;
 
-	_enter("{ ino=%lu v=%lu }",inode->i_ino,inode->i_version);
+	_enter("{ ino=%lu v=%lu }", inode->i_ino, inode->i_version);
 
 	vnode = AFS_FS_I(inode);
 
 	ret = afs_inode_fetch_status(inode);
-	if (ret==-ENOENT) {
-		_leave(" = %d [%d %p]",ret,atomic_read(&dentry->d_count),dentry->d_inode);
+	if (ret == -ENOENT) {
+		_leave(" = %d [%d %p]",
+		       ret, atomic_read(&dentry->d_count), dentry->d_inode);
 		return ret;
 	}
-	else if (ret<0) {
+	else if (ret < 0) {
 		make_bad_inode(inode);
-		_leave(" = %d",ret);
+		_leave(" = %d", ret);
 		return ret;
 	}
 
-	/* transfer attributes from the inode structure to the stat structure */
-	generic_fillattr(inode,stat);
+	/* transfer attributes from the inode structure to the stat
+	 * structure */
+	generic_fillattr(inode, stat);
 
 	_leave(" = 0 CB { v=%u x=%u t=%u }",
 	       vnode->cb_version,
@@ -268,11 +273,11 @@
 	       vnode->cb_type
 	       );
 
-	if (inode->i_ino!=vnode->fid.vnode) BUG();
+	BUG_ON(inode->i_ino != vnode->fid.vnode);
 
 	afs_vnode_give_up_callback(vnode);
 
-	cachefs_relinquish_cookie(vnode->cache,0);
+	cachefs_relinquish_cookie(vnode->cache, 0);
 	vnode->cache = NULL;
 
 	_leave("");

Index: file.c
===================================================================
RCS file: /home/cvs/afs/fs/afs/file.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- file.c	10 Jun 2003 17:49:49 -0000	1.7
+++ file.c	4 Jul 2003 15:26:31 -0000	1.8
@@ -230,8 +230,13 @@
 		 * The get_block cached value has been unconditionally invalidated,
 		 * so real IO is not possible anymore.
 		 */
-		if (offset == 0)
-			ret = try_to_release_page(page,0);
+		if (offset == 0) {
+			BUG_ON(!PageLocked(page));
+
+			ret = 0;
+			if (!PageWriteback(page))
+				ret = page->mapping->a_ops->releasepage(page, 0);
+		}
 	}
 
 	_leave(" = %d",ret);

Index: dir.c
===================================================================
RCS file: /home/cvs/afs/fs/afs/dir.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- dir.c	9 Apr 2003 15:43:07 -0000	1.9
+++ dir.c	4 Jul 2003 15:26:31 -0000	1.10
@@ -423,11 +423,11 @@
 	unsigned fpos;
 	int ret;
 
-	_enter("{%lu},{%s}",dir->i_ino,dentry->d_name.name);
+	_enter("{%lu},%p{%s}",dir->i_ino,dentry,dentry->d_name.name);
 
 	/* insanity checks first */
-	if (sizeof(afs_dir_block_t) != 2048) BUG();
-	if (sizeof(afs_dirent_t) != 32) BUG();
+	BUG_ON(sizeof(afs_dir_block_t) != 2048);
+	BUG_ON(sizeof(afs_dirent_t) != 32);
 
 	if (dentry->d_name.len > 255) {
 		_leave(" = -ENAMETOOLONG");
@@ -495,7 +495,7 @@
 	unsigned fpos;
 	int ret;
 
-	_enter("%s,%x",dentry->d_name.name,flags);
+	_enter("{sb=%p n=%s},%x",dentry->d_sb,dentry->d_name.name,flags);
 
 	/* lock down the parent dentry so we can peer at it */
 	parent = dget_parent(dentry->d_parent);

Index: cmservice.c
===================================================================
RCS file: /home/cvs/afs/fs/afs/cmservice.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- cmservice.c	2 Mar 2003 18:56:15 -0000	1.6
+++ cmservice.c	4 Jul 2003 15:26:31 -0000	1.7
@@ -301,15 +301,18 @@
 
 	down_write(&afscm_sem);
 	if (!afscm_usage) {
-		ret = kernel_thread(kafscmd,NULL,0);
-		if (ret<0)
+		ret = kernel_thread(kafscmd, NULL, 0);
+		if (ret < 0)
 			goto out;
 
 		wait_for_completion(&kafscmd_alive);
 
-		ret = rxrpc_add_service(afs_transport,&AFSCM_service);
+		ret = rxrpc_add_service(afs_transport, &AFSCM_service);
 		if (ret<0)
 			goto kill;
+
+		afs_kafstimod_add_timer(&afs_mntpt_expiry_timer,
+					afs_mntpt_expiry_timeout * HZ);
 	}
 
 	afscm_usage++;
@@ -338,17 +341,20 @@
 
 	down_write(&afscm_sem);
 
-	if (afscm_usage==0) BUG();
+	if (afscm_usage == 0) BUG();
 	afscm_usage--;
 
-	if (afscm_usage==0) {
+	if (afscm_usage == 0) {
 		/* don't want more incoming calls */
-		rxrpc_del_service(afs_transport,&AFSCM_service);
+		rxrpc_del_service(afs_transport, &AFSCM_service);
 
 		/* abort any calls I've still got open (the afscm_error() will dequeue them) */
 		spin_lock(&afscm_calls_lock);
 		while (!list_empty(&afscm_calls)) {
-			call = list_entry(afscm_calls.next,struct rxrpc_call,app_link);
+			call = list_entry(afscm_calls.next,
+					  struct rxrpc_call,
+					  app_link);
+
 			list_del_init(&call->app_link);
 			rxrpc_get_call(call);
 			spin_unlock(&afscm_calls_lock);
@@ -356,7 +362,8 @@
 			rxrpc_call_abort(call,-ESRCH); /* abort, dequeue and put */
 
 			_debug("nuking active call %08x.%d",
-			       ntohl(call->conn->conn_id),ntohl(call->call_id));
+			       ntohl(call->conn->conn_id),
+			       ntohl(call->call_id));
 			rxrpc_put_call(call);
 			rxrpc_put_call(call);
 
@@ -384,6 +391,8 @@
 			spin_lock(&kafscmd_attention_lock);
 		}
 		spin_unlock(&kafscmd_attention_lock);
+
+		afs_kafstimod_del_timer(&afs_mntpt_expiry_timer);
 	}
 
 	up_write(&afscm_sem);
@@ -498,7 +507,7 @@
 	if (ret<0)
 		rxrpc_call_abort(call,ret);
 
-	if (server) afs_put_server(server);
+	afs_put_server(server);
 
 	_leave(" = %d",ret);
 
@@ -564,7 +573,7 @@
 	if (ret<0)
 		rxrpc_call_abort(call,ret);
 
-	if (server) afs_put_server(server);
+	afs_put_server(server);
 
 	_leave(" = %d",ret);
 
@@ -630,7 +639,7 @@
 	if (ret<0)
 		rxrpc_call_abort(call,ret);
 
-	if (server) afs_put_server(server);
+	afs_put_server(server);
 
 	_leave(" = %d",ret);
 

Index: cell.h
===================================================================
RCS file: /home/cvs/afs/fs/afs/cell.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- cell.h	6 Jun 2003 08:33:37 -0000	1.4
+++ cell.h	4 Jul 2003 15:26:31 -0000	1.5
@@ -25,7 +25,7 @@
 struct afs_cache_cell
 {
 	char			name[64];	/* cell name (padded with NULs) */
-	struct in_addr		servers[15];	/* cached cell servers */
+	struct in_addr		vl_servers[15];	/* cached cell VL servers */
 };
 
 /*****************************************************************************/
@@ -60,15 +60,15 @@
 
 extern int afs_cell_init(void);
 
-extern int afs_cell_create(const char *name, char *vllist, afs_cell_t **_cell);
+extern int afs_cell_create(const char *name, char *vllist, struct afs_cell **_cell);
 
-extern int afs_cell_lookup(const char *name, afs_cell_t **_cell);
+extern int afs_cell_lookup(const char *name, unsigned nmsize, struct afs_cell **_cell);
 
 #define afs_get_cell(C) do { atomic_inc(&(C)->usage); } while(0)
 
-extern afs_cell_t *afs_get_cell_maybe(afs_cell_t **_cell);
+extern struct afs_cell *afs_get_cell_maybe(struct afs_cell **_cell);
 
-extern void afs_put_cell(afs_cell_t *cell);
+extern void afs_put_cell(struct afs_cell *cell);
 
 extern void afs_cell_purge(void);
 

Index: cell.c
===================================================================
RCS file: /home/cvs/afs/fs/afs/cell.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- cell.c	9 Jun 2003 13:52:04 -0000	1.8
+++ cell.c	4 Jul 2003 15:26:31 -0000	1.9
@@ -182,36 +182,45 @@
 /*
  * lookup a cell record
  */
-int afs_cell_lookup(const char *name, afs_cell_t **_cell)
+int afs_cell_lookup(const char *name, unsigned namesz, struct afs_cell **_cell)
 {
 	struct list_head *_p;
 	afs_cell_t *cell;
+	int ret;
 
-	_enter("\"%s\",",name?name:"*thiscell*");
+	_enter("\"%*.*s\",", namesz, namesz, name ? name : "");
 
-	cell = afs_cell_root;
+	*_cell = NULL;
 
 	if (name) {
 		/* if the cell was named, look for it in the cell record list */
+		ret = -ENOENT;
 		cell = NULL;
 		read_lock(&afs_cells_lock);
 
 		list_for_each(_p,&afs_cells) {
-			cell = list_entry(_p,afs_cell_t,link);
-			if (strcmp(cell->name,name)==0)
+			cell = list_entry(_p, struct afs_cell, link);
+			if (strncmp(cell->name, name, namesz) == 0) {
+				afs_get_cell(cell);
 				break;
+			}
 			cell = NULL;
 		}
 
 		read_unlock(&afs_cells_lock);
-	}
 
-	if (cell)
+		if (cell)
+			ret = 0;
+	}
+	else {
+		cell = afs_cell_root;
 		afs_get_cell(cell);
+		ret = 0;
+	}
 
 	*_cell = cell;
-	_leave(" = %d (%p)",cell?0:-ENOENT,cell);
-	return cell ? 0 : -ENOENT;
+	_leave(" = %d (%p)", ret, cell);
+	return ret;
 
 } /* end afs_cell_lookup() */
 
@@ -227,7 +236,7 @@
 
 	cell = *_cell;
 	if (cell && !list_empty(&cell->link))
-		atomic_inc(&cell->usage);
+		afs_get_cell(cell);
 	else
 		cell = NULL;
 
@@ -242,6 +251,9 @@
  */
 void afs_put_cell(afs_cell_t *cell)
 {
+	if (!cell)
+		return;
+
 	_enter("%p{%d,%s}",cell,atomic_read(&cell->usage),cell->name);
 
 	/* sanity check */
@@ -395,8 +407,7 @@
 
 	_enter("");
 
-	if (afs_cell_root)
-		afs_put_cell(afs_cell_root);
+	afs_put_cell(afs_cell_root);
 
 	while (!list_empty(&afs_cells)) {
 		cell = NULL;
@@ -480,7 +491,7 @@
 
 	_enter("");
 
-	if (strncmp(ccell->name,cell->name,sizeof(ccell->name))==0)
+	if (strncmp(ccell->name, cell->name, sizeof(ccell->name)) == 0)
 		return CACHEFS_MATCH_SUCCESS;
 
 	return CACHEFS_MATCH_FAILED;
@@ -495,8 +506,12 @@
 	struct afs_cache_cell *ccell = entry;
 	struct afs_cell *cell = source;
 
-	kenter("%p,%p",source,entry);
+	kenter("%p,%p", source, entry);
+
+	strncpy(ccell->name, cell->name, sizeof(ccell->name));
 
-	strncpy(ccell->name,cell->name,sizeof(ccell->name));
+	memcpy(ccell->vl_servers,
+	       cell->vl_addrs,
+	       min(sizeof(ccell->vl_servers), sizeof(cell->vl_addrs)));
 
 } /* end afs_cell_cache_update() */

Index: callback.c
===================================================================
RCS file: /home/cvs/afs/fs/afs/callback.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- callback.c	8 Oct 2002 09:06:33 -0000	1.3
+++ callback.c	4 Jul 2003 15:26:31 -0000	1.4
@@ -68,7 +68,7 @@
 			spin_unlock(&vnode->lock);
 
 			iput(inode);
-			if (release) afs_put_server(server);
+			afs_put_server(server);
 
 			spin_lock(&server->cb_lock);
 		}

Index: Makefile
===================================================================
RCS file: /home/cvs/afs/fs/afs/Makefile,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- Makefile	4 Feb 2003 16:12:05 -0000	1.11
+++ Makefile	4 Jul 2003 15:26:31 -0000	1.12
@@ -2,6 +2,8 @@
 # Makefile for Red Hat Linux AFS client.
 #
 
+CFLAGS += -finstrument-functions
+
 kafs-objs := \
 	callback.o \
 	cell.o \


From dwh at infradead.org  Wed Jul  9 12:39:52 2003
From: dwh at infradead.org (dwh@infradead.org)
Date: Wed Jul  9 11:39:43 2003
Subject: afs/include/linux cachefs.h,1.15,1.16
Message-ID: <E19aCMa-0002Vg-00@phoenix.infradead.org>

Update of /home/cvs/afs/include/linux
In directory phoenix.infradead.org:/tmp/cvs-serv9636/include/linux

Modified Files:
	cachefs.h 
Log Message:
done some more cleaning up
include index entry data and index definition data in journal entry
made replaying mechanism regenerate transactions that need reapplying
implemented some replaying ops


Index: cachefs.h
===================================================================
RCS file: /home/cvs/afs/include/linux/cachefs.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- cachefs.h	4 Jul 2003 09:04:43 -0000	1.15
+++ cachefs.h	9 Jul 2003 10:39:49 -0000	1.16
@@ -58,6 +58,7 @@
 #define CACHEFS_INDEX_KEYS_ASCIIZ	2
 #define CACHEFS_INDEX_KEYS_IPV4ADDR	3
 #define CACHEFS_INDEX_KEYS_IPV6ADDR	4
+#define CACHEFS_INDEX_KEYS__LAST	CACHEFS_INDEX_KEYS_IPV6ADDR
 
 	/* see if entry matches the specified key
 	 * - the netfs data from the cookie being used as the target is presented


From dwh at infradead.org  Wed Jul  9 12:39:53 2003
From: dwh at infradead.org (dwh@infradead.org)
Date: Wed Jul  9 11:46:53 2003
Subject: afs/fs/cachefs replay.c,NONE,1.1 super.c,1.37,1.38
 rootdir.c,1.12,1.13 recycling.c,1.24,1.25 journal.c,1.38,1.39
 interface.c,1.14,1.15 inode.c,1.22,1.23 index.c,1.25,1.26
 dump-journal.c,1.12,1.13 cachefs-layout.h,1.28,1.29
 cachefs-int.h,1.37,1.38 aops.c,1.39,1.40 Makefile,1.16,1.17
Message-ID: <E19aCMb-0002Vs-00@phoenix.infradead.org>

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

Modified Files:
	super.c rootdir.c recycling.c journal.c interface.c inode.c 
	index.c dump-journal.c cachefs-layout.h cachefs-int.h aops.c 
	Makefile 
Added Files:
	replay.c 
Log Message:
done some more cleaning up
include index entry data and index definition data in journal entry
made replaying mechanism regenerate transactions that need reapplying
implemented some replaying ops


--- NEW FILE replay.c ---
/* replay.c: replay the update journal
 *
 * Copyright (C) 2003 Red Hat, Inc. All Rights Reserved.
 * Written by David Howells (dhowells@redhat.com)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version
 * 2 of the License, or (at your option) any later version.
 */

#include <linux/module.h>
#include <linux/init.h>
#include <linux/sched.h>
#include <linux/completion.h>
#include <linux/slab.h>
#include <linux/bio.h>
#include "cachefs-int.h"

[...980 lines suppressed...]
/*
 * replay indirection block allocation
 */
static int cachefs_replay_ujnl_indirect_allocing(struct cachefs_super *super,
						 struct cachefs_ondisc_update_journal *jentry,
						 struct cachefs_transaction *trans)
{
	return -ENOANO;
} /* end cachefs_replay_ujnl_indirect_allocing() */

/*****************************************************************************/
/*
 * replay indirection block freeing
 */
static int cachefs_replay_ujnl_indirect_freeing(struct cachefs_super *super,
						struct cachefs_ondisc_update_journal *jentry,
						struct cachefs_transaction *trans)
{
	return -ENOANO;
} /* end cachefs_replay_ujnl_indirect_freeing() */

Index: super.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/super.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- super.c	4 Jul 2003 14:25:39 -0000	1.37
+++ super.c	9 Jul 2003 10:39:50 -0000	1.38
@@ -23,7 +23,7 @@
 
 #define CACHEFS_FS_MAGIC 0x43414653 /* 'CAFS' */
 
-static void cachefs_i_init_once(void *foo, kmem_cache_t *cachep,
+static void cachefs_i_init_once(void *_inode, kmem_cache_t *cachep,
 				unsigned long flags);
 
 static struct super_block *cachefs_get_sb(struct file_system_type *fs_type,
@@ -168,7 +168,8 @@
 
 /*****************************************************************************/
 /*
- * submit a read or a write for the page count times starting at the specified block offset
+ * submit a read or a write for the page count times starting at the specified
+ * block offset
  */
 static int cachefs_bio_submit(struct super_block *sb, struct page *page,
 			      unsigned bix, size_t *count, int rw)
@@ -192,7 +193,7 @@
 	bio->bi_end_io	= cachefs_bio_completion;
 	bio->bi_private	= NULL;
 
-	for (loop=0; loop<*count; loop++)
+	for (loop = 0; loop < *count; loop++)
 		if (!bio_add_page(bio, page, PAGE_SIZE, 0))
 			break;
 	*count = loop;
@@ -257,7 +258,7 @@
 	if (!super->rcm_atm_list)
 		goto error;
 
-	super->vjnl_map = (unsigned long*) get_zeroed_page(GFP_KERNEL);
+	super->vjnl_map = (unsigned long *) get_zeroed_page(GFP_KERNEL);
 	if (!super->vjnl_map)
 		goto error;
 
@@ -292,6 +293,7 @@
 	INIT_LIST_HEAD(&super->ujnl_writeq);
 	INIT_LIST_HEAD(&super->ujnl_ackq);
 	INIT_LIST_HEAD(&super->ujnl_ackwq);
+	INIT_LIST_HEAD(&super->ujnl_replayq);
 
 	INIT_LIST_HEAD(&super->jnld_link);
 
@@ -360,14 +362,14 @@
 
 	if (memcmp(super->layout->magic,
 		   CACHEFS_SUPER_MAGIC,
-		   CACHEFS_SUPER_MAGIC_SIZE)==0
+		   CACHEFS_SUPER_MAGIC_SIZE) == 0
 	    ) {
 		printk("CacheFS: Found initialised cache\n");
 		jnlreplay = 1;
 	}
 	else if (memcmp(super->layout->magic,
 			CACHEFS_SUPER_MAGIC_NEEDS_INIT,
-			CACHEFS_SUPER_MAGIC_SIZE)==0
+			CACHEFS_SUPER_MAGIC_SIZE) == 0
 		 ) {
 		printk("CacheFS: Found uninitialised cache\n");
 		ret = cachefs_initialise_blockdev(super);
@@ -383,17 +385,17 @@
 	super->ujnl_jsof = super->layout->bix_ujournal;
 	super->ujnl_jsof <<= (PAGE_SHIFT - super->sb->s_blocksize_bits);
 
-	/* get and retain various meta-data inodes */
-	ret = cachefs_iget(super, CACHEFS_INO_METADATA, &super->imetadata);
-	if (ret < 0)
-		goto error;
-
 	if (jnlreplay) {
 		ret = cachefs_ujnl_replay(super);
 		if (ret < 0)
 			goto error;
 	}
 
+	/* get and retain various meta-data inodes */
+	ret = cachefs_iget(super, CACHEFS_INO_METADATA, &super->imetadata);
+	if (ret < 0)
+		goto error;
+
 	kcachefs_jnld_add_super(super);
 
 	/* start the manager daemon */
@@ -414,7 +416,7 @@
 
 	sb->s_root = root;
 
-	cachefs_add_cache((struct cachefs_super *) sb->s_fs_info,srch);
+	cachefs_add_cache((struct cachefs_super *) sb->s_fs_info, srch);
 
 	kleave(" = 0 [super=%p]", super);
 	return 0;
@@ -522,17 +524,17 @@
 		super->layout->bix_wbjournal + CACHEFS_ONDISC_WBJNL_SIZE;
 	super->layout->bix_unready =
 		super->layout->bix_cache;
-	super->layout->bix_end
-		= nblocks;
+	super->layout->bix_end =
+		nblocks;
 
 	printk("CacheFS: 00000000 super block\n");
 	printk("CacheFS: 00000001 initial vnodes (%u blocks)\n", ndirect);
 
-	printk("CacheFS: %08x update journal (%u recs of %u/%ub)\n",
+	printk("CacheFS: %08x update journal (recsize %u+%ub)\n",
 	       super->layout->bix_ujournal,
-	       qty,
 	       sizeof(struct cachefs_ondisc_update_journal),
-	       super->layout->ujnl_rsize);
+	       super->layout->ujnl_rsize -
+	       sizeof(struct cachefs_ondisc_update_journal));
 
 	printk("CacheFS: %08x validity journal\n",
 	       super->layout->bix_vjournal);
@@ -546,9 +548,9 @@
 	       super->layout->bix_end);
 
 	/* initialise the metadata entry for the metadata file itself */
-	memset(data,0,PAGE_SIZE);
+	memset(data, 0, PAGE_SIZE);
 
-	for (tmp=0; tmp<PAGE_SIZE; tmp+=super->layout->metadata_size) {
+	for (tmp = 0; tmp < PAGE_SIZE; tmp += super->layout->metadata_size) {
 		metadata = (struct cachefs_ondisc_metadata *) (data + tmp);
 
 		metadata->header.state = CACHEFS_ONDISC_INDEX_FREE;
@@ -565,11 +567,11 @@
 	metadata->mtime		= CURRENT_TIME.tv_sec;
 	metadata->atime		= CURRENT_TIME.tv_sec;
 
-	metadata->index_dsize	= super->layout->metadata_size;
-	metadata->index_dsize	-= sizeof(struct cachefs_ondisc_index_entry);
-	metadata->index_esize	= super->layout->metadata_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(metadata->index_type, ".METADAT", 9);
+	strncpy(metadata->index.type, ".METADAT", 9);
 
 	for (tmp = 0; tmp < ndirect; tmp++)
 		metadata->direct[tmp] = tmp + 1; /* point to itself */
@@ -586,12 +588,12 @@
 	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;
+	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(metadata->index_type, ".FSDEF", 8);
+	strncpy(metadata->index.type, ".FSDEF", 8);
 
 	tmp = 1;
 	ret = cachefs_bio_submit(super->sb, page, 1, &tmp, WRITE);
@@ -668,7 +670,8 @@
 	tmp = super->layout->bix_end;
 	tmp -= super->layout->bix_cache;
 	tmp <<= PAGE_SIZE - super->sb->s_blocksize_bits;
-	if (tmp > LONG_MAX) tmp = LONG_MAX;
+	if (tmp > LONG_MAX)
+		tmp = LONG_MAX;
 
 	buf->f_files	= tmp;
 	buf->f_ffree	= tmp;
@@ -749,7 +752,7 @@
 		}
 
 		set_current_state(TASK_RUNNING);
-		remove_wait_queue(&super->vjnl_alloc_wq,&myself);
+		remove_wait_queue(&super->vjnl_alloc_wq, &myself);
 	}
 
 	super->dmn_die = 1;

Index: rootdir.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/rootdir.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- rootdir.c	4 Jul 2003 09:04:43 -0000	1.12
+++ rootdir.c	9 Jul 2003 10:39:50 -0000	1.13
@@ -260,7 +260,7 @@
 	rec.epp		= inode->index_esize;
 
 	metadata = cachefs_metadata_preread(inode);
-	memcpy(rec.keys, metadata->index_keys, sizeof(rec.keys));
+	memcpy(rec.keys, metadata->index.keys, sizeof(rec.keys));
 	cachefs_metadata_postread(inode);
 
 	switch (file->f_pos) {
@@ -470,7 +470,7 @@
 
 	/* construct a key to search the FSDEF index with */
 	metadata = cachefs_metadata_preread(dir);
-	memcpy(rec.keys, metadata->index_keys, sizeof(rec.keys));
+	memcpy(rec.keys, metadata->index.keys, sizeof(rec.keys));
 	cachefs_metadata_postread(dir);
 
 	for (loop = 0; loop < 4; loop++)

Index: recycling.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/recycling.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- recycling.c	4 Jul 2003 14:25:39 -0000	1.24
+++ recycling.c	9 Jul 2003 10:39:50 -0000	1.25
@@ -133,7 +133,7 @@
 	struct cachefs_ondisc_free_node *node;
 	struct cachefs_transaction *trans;
 	cachefs_blockix_t *pbix;
-	unsigned loop, qty;
+	unsigned loop, qty, pos;
 	int ret;
 
 	_enter("");
@@ -153,6 +153,8 @@
 	if (qty > super->recycle_room)
 		qty = super->recycle_room;
 
+	pos = CACHEFS_ONDISC_LEAVES_PER_FREE_NODE - super->recycle_room;
+
 	/* journal what we're going to do */
 	trans = cachefs_trans_alloc(super, GFP_KERNEL);
 	if (!trans) {
@@ -165,6 +167,7 @@
 
 	trans->jentry->mark	= CACHEFS_ONDISC_UJNL_RECYC_MAKEREADY;
 	trans->jentry->block	= super->recycle_cur;
+	trans->jentry->entry	= pos;
 	trans->jentry->auxblock	= super->layout->bix_unready;
 	trans->jentry->pgnum	= super->layout->bix_unready + qty;
 	trans->jentry->count	= qty;
@@ -994,53 +997,3 @@
 	kleave(" [error %d]", ret);
 
 } /* end cachefs_recycle_unallocate_data_block() */
-
-/*****************************************************************************/
-/*
- *
- */
-int cachefs_replay_ujnl_recyc_empty_node(struct cachefs_super *super,
-					 struct cachefs_ondisc_update_journal *jentry)
-{
-	return -ENOANO;
-} /* end cachefs_replay_ujnl_recyc_empty_node() */
-
-/*****************************************************************************/
-/*
- *
- */
-int cachefs_replay_ujnl_recyc_begin_new(struct cachefs_super *super,
-					struct cachefs_ondisc_update_journal *jentry)
-{
-	return -ENOANO;
-} /* end cachefs_replay_ujnl_recyc_begin_new() */
-
-/*****************************************************************************/
-/*
- *
- */
-int cachefs_replay_ujnl_recyc_transfer(struct cachefs_super *super,
-				       struct cachefs_ondisc_update_journal *jentry)
-{
-	return -ENOANO;
-} /* end cachefs_replay_ujnl_recyc_transfer() */
-
-/*****************************************************************************/
-/*
- *
- */
-int cachefs_replay_ujnl_recyc_scavenge(struct cachefs_super *super,
-				       struct cachefs_ondisc_update_journal *jentry)
-{
-	return -ENOANO;
-} /* end cachefs_replay_ujnl_recyc_scavenge() */
-
-/*****************************************************************************/
-/*
- *
- */
-int cachefs_replay_ujnl_recyc_makeready(struct cachefs_super *super,
-					struct cachefs_ondisc_update_journal *jentry)
-{
-	return -ENOANO;
-} /* end cachefs_replay_ujnl_recyc_makeready() */

Index: journal.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/journal.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- journal.c	4 Jul 2003 14:25:40 -0000	1.38
+++ journal.c	9 Jul 2003 10:39:50 -0000	1.39
@@ -19,15 +19,6 @@
 
 #define UJNL_WRAP(X) ((X) & (CACHEFS_ONDISC_UJNL_NUMENTS - 1))
 
-struct cachefs_replay_find_batch_desc {
-	read_descriptor_t	desc;
-	unsigned short		batch_first;	/* sector holding first entry in batch */
-	unsigned short		batch_end;	/* batch mark sector for ujnl_batch */
-	unsigned short		batch_ack;	/* batch ACK sector for ujnl_batch */
-	unsigned short		batch_count;	/* number of marks in batch */
-	int16_t			ack_hi;		/* highest batch with ACK number */
-};
-
 const char *cachefs_ondisc_ujnl_marks[] = {
 	"Null     ",
 	"Batch    ",
@@ -87,30 +78,6 @@
 	}								\
 } while(0)
 
-typedef int (*cachefs_ujnl_replay_func_t)(struct cachefs_super *super,
-					  struct cachefs_ondisc_update_journal *jentry);
-
-static const cachefs_ujnl_replay_func_t cachefs_ujnl_replay_tbl[CACHEFS_ONDISC_UJNL__LAST] = {
-	[CACHEFS_ONDISC_UJNL_RECYC_EMPTY_NODE]	= cachefs_replay_ujnl_recyc_empty_node,
-	[CACHEFS_ONDISC_UJNL_RECYC_BEGIN_NEW]	= cachefs_replay_ujnl_recyc_begin_new,
-	[CACHEFS_ONDISC_UJNL_RECYC_TRANSFER]	= cachefs_replay_ujnl_recyc_transfer,
-	[CACHEFS_ONDISC_UJNL_RECYC_SCAVENGE]	= cachefs_replay_ujnl_recyc_scavenge,
-	[CACHEFS_ONDISC_UJNL_RECYC_MAKEREADY]	= cachefs_replay_ujnl_recyc_makeready,
-	[CACHEFS_ONDISC_UJNL_INODE_CREATING]	= cachefs_replay_ujnl_inode_creating,
-	[CACHEFS_ONDISC_UJNL_INODE_UPDATING]	= cachefs_replay_ujnl_inode_updating,
-	[CACHEFS_ONDISC_UJNL_INODE_DELETING]	= cachefs_replay_ujnl_inode_deleting,
-	[CACHEFS_ONDISC_UJNL_INODE_MARK_RECLAIM]= cachefs_replay_ujnl_inode_mark_reclaim,
-	[CACHEFS_ONDISC_UJNL_INODE_RECLAIMING]	= cachefs_replay_ujnl_inode_reclaiming,
-	[CACHEFS_ONDISC_UJNL_DATA_ALLOCING]	= cachefs_replay_ujnl_data_allocing,
-	[CACHEFS_ONDISC_UJNL_DATA_WRITTEN]	= cachefs_replay_ujnl_data_written,
-	[CACHEFS_ONDISC_UJNL_DATA_UNALLOCING]	= cachefs_replay_ujnl_data_unallocing,
-	[CACHEFS_ONDISC_UJNL_INDIRECT_ALLOCING]	= cachefs_replay_ujnl_indirect_allocing,
-	[CACHEFS_ONDISC_UJNL_INDIRECT_FREEING]	= cachefs_replay_ujnl_indirect_freeing,
-	[CACHEFS_ONDISC_UJNL_INDEX_EXTENDING]	= cachefs_replay_ujnl_index_extending,
-	[CACHEFS_ONDISC_UJNL_INDEX_CREATING]	= cachefs_replay_ujnl_index_creating,
-	[CACHEFS_ONDISC_UJNL_INDEX_UPDATING]	= cachefs_replay_ujnl_index_modifying
-};
-
 /*****************************************************************************/
 /*
  * batch write timer callback
@@ -163,6 +130,40 @@
 
 /*****************************************************************************/
 /*
+ * allocate an update-journalled transaction record and initialise it for
+ * replay
+ */
+struct cachefs_transaction *
+cachefs_trans_alloc_replay(struct cachefs_super *super,
+			   struct cachefs_ondisc_update_journal *jentry)
+{
+	struct cachefs_transaction *trans;
+
+	_enter("");
+
+	trans = kmalloc(sizeof(struct cachefs_transaction), GFP_KERNEL);
+	if (!trans) {
+		_leave(" = 0 [ENOMEM]");
+		return NULL;
+	}
+
+	memset(trans, 0, sizeof(*trans));
+
+	atomic_set(&trans->usage, 1);
+	INIT_LIST_HEAD(&trans->sblink);
+
+	trans->super	= super;
+	trans->batch	= jentry->batch;
+	trans->serial	= jentry->serial;
+	trans->phase	= CACHEFS_TRANS_MARKED;
+	trans->index	= 0;
+
+	_leave(" = %p", trans);
+	return trans;
+} /* end cachefs_trans_alloc_replay() */
+
+/*****************************************************************************/
+/*
  * release a reference to a transaction and ultimately free it
  */
 void __cachefs_trans_put(struct cachefs_transaction *trans)
@@ -184,8 +185,8 @@
 		return;
 	}
 
-	BUG_ON(trans->phase!=CACHEFS_TRANS_PREPARING &&
-	       trans->phase!=CACHEFS_TRANS_DEAD);
+	BUG_ON(trans->phase != CACHEFS_TRANS_PREPARING &&
+	       trans->phase != CACHEFS_TRANS_DEAD);
 
 	spin_lock_irqsave(&trans->super->ujnl_mk_lock, flags);
 	list_del(&trans->sblink);
@@ -467,7 +468,7 @@
 			       CACHEFS_TRANS_COMMITTING,
 			       CACHEFS_TRANS_MARKED);
 
-	for (loop=0; loop<CACHEFS_EFFECTS_PER_TRANS; loop++)
+	for (loop = 0; loop < CACHEFS_EFFECTS_PER_TRANS; loop++)
 		if (trans->effects[loop].held_page)
 			SetPageWriteback(trans->effects[loop].held_page);
 
@@ -500,6 +501,32 @@
 
 /*****************************************************************************/
 /*
+ * commit a replay transaction 
+ * - discard any transaction that is "ineffective"
+ */
+void cachefs_trans_commit_replay(struct cachefs_transaction *trans)
+{
+	int loop;
+
+	if (!trans->eff_active) {
+		cachefs_trans_put(trans);
+		return;
+	}
+
+	cachefs_ujnl_set_phase(trans,
+			       CACHEFS_TRANS_COMMITTING,
+			       CACHEFS_TRANS_MARKED);
+
+	for (loop = 0; loop < CACHEFS_EFFECTS_PER_TRANS; loop++)
+		if (trans->effects[loop].held_page)
+			SetPageWriteback(trans->effects[loop].held_page);
+
+	list_add_tail(&trans->sblink, &trans->super->ujnl_commitq);
+
+} /* end cachefs_trans_commit_replay() */
+
+/*****************************************************************************/
+/*
  * prepare a transaction for writing
  * - mark all modified journalling and data blocks for writeback
  * - mark data for COW
@@ -510,7 +537,7 @@
 {
 	struct cachefs_block *block;
 	int loop;
-	
+
 	/* mark u-journal page */
 	block = trans->jblock;
 	if (!test_and_set_bit(CACHEFS_BLOCK_WRITEBACK, &block->flags)) {
@@ -538,7 +565,7 @@
 			plist = &super->batch_writeq;
 			if (test_bit(CACHEFS_BLOCK_NETFSDATA, &block->flags)) {
 				plist = &super->batch_doneq;
-				kdebug("skip meta block %u", block->bix);
+				_debug("skip meta block %u", block->bix);
 			}
 
 			list_add_tail(&block->batch_link, plist);
@@ -597,8 +624,7 @@
 		       block->writeback);
 	}
 
-	/* decide where to put the BATCH and ACK marks and what the data for it
-	 * is */
+	/* invent BATCH and ACK marks */
 	jstop = super->ujnl_head;
 	super->ujnl_head = UJNL_WRAP(jstop + 2);
 
@@ -624,13 +650,17 @@
 
 	up_write(&super->batch_ctrl_sem);
 
-	/* write to the update journal with a barrier and then write the
-	 * data */
-	cachefs_trans_batch_write_ujnl(super, jstop);
+	/* write to the update journal with a barrier if we're not replaying
+	 * and then write the data (if we're replaying, all the journal entries
+	 * bar the ACK already reside on disc) */
+	if (!test_bit(CACHEFS_SUPER_REPLAYING_UJNL, &super->flags))
+		cachefs_trans_batch_write_ujnl(super, jstop);
 
 	ajentry->mark = CACHEFS_ONDISC_UJNL_BATCH;
 
-	cachefs_trans_batch_write_marker(super, jstop, ajentry);
+	if (!test_bit(CACHEFS_SUPER_REPLAYING_UJNL, &super->flags))
+		cachefs_trans_batch_write_marker(super, jstop, ajentry);
+
 	cachefs_trans_batch_write_data(super);
 	cachefs_trans_batch_process_written_blocks(super, 2);
 
@@ -1377,447 +1407,3 @@
 
 	kleave("");
 } /* end cachefs_trans_sync() */
-
-/*****************************************************************************/
-/*
- * journal replay actor for determining bounds of the latest batch of journal
- * entries
- * - each batch is a cyclically adjacent collection of entries with the same
- *   batch number, hopefully ending in a BATCH mark and an ACK mark
- */
-static int cachefs_ujnl_find_batch_actor(read_descriptor_t *_desc,
-					 struct page *page,
-					 unsigned long offset,
-					 unsigned long size)
-{
-	struct cachefs_replay_find_batch_desc *desc;
-	struct cachefs_ondisc_update_journal *jentry;
-	struct cachefs_super *super = (struct cachefs_super *) _desc->buf;
-	unsigned short slot;
-	u_int8_t *data;
-	int tmp;
-
-	desc = container_of(_desc,
-			    struct cachefs_replay_find_batch_desc,
-			    desc);
-
-	_enter("{%x},{%lu},%lu,%lu",
-	       desc->desc.count, page->index, offset, size);
-
-	BUG_ON(size != PAGE_SIZE);
-	BUG_ON(offset != 0);
-
-	data = (u_int8_t *) kmap(page);
-
-	slot = (page->index - super->layout->bix_ujournal);
-	slot *= super->layout->ujnl_recperblk;
-
-	while (offset < size) {
-		jentry = (struct cachefs_ondisc_update_journal *) (data + offset);
-
-		if (slot == 0) {
-			/* just paste the values of the very first slot in directly */
-			_debug("UJNL[%04x] mk=%s s=%hu.%hu",
-			       slot,
-			       cachefs_ondisc_ujnl_marks[jentry->mark],
-			       (unsigned) jentry->batch,
-			       jentry->serial);
-
-			super->ujnl_batch	= jentry->batch;
-			super->ujnl_serial	= jentry->serial;
-			super->ujnl_head	= slot;
-			desc->batch_first	= ~0;
-			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;
-				super->ujnl_tail = slot;
-			}
-
-		}
-		else if (jentry->mark == CACHEFS_ONDISC_UJNL_NULL) {
-			/* do nothing */
-		}
-		else {
-			_debug("UJNL[%04x] mk=%s s=%d.%u { b=%d s=%u }",
-			       slot,
-			       cachefs_ondisc_ujnl_marks[jentry->mark],
-			       jentry->batch,
-			       jentry->serial,
-			       super->ujnl_batch,
-			       super->ujnl_serial);
-
-			tmp = jentry->batch - super->ujnl_batch;
-			if (tmp > 0) {
-				super->ujnl_batch	= jentry->batch;
-				super->ujnl_serial	= jentry->serial;
-				desc->batch_first	= ~0;
-				desc->batch_end		= ~0;
-				desc->batch_ack		= ~0;
-				desc->batch_count	= 1;
-				super->ujnl_head	= slot;
-
-				if (jentry->serial == 0) {
-					desc->batch_first = slot;
-					super->ujnl_tail = slot;
-				}
-			}
-			else if (tmp == 0) {
-				desc->batch_count++;
-
-				if (super->ujnl_serial < jentry->serial) {
-					super->ujnl_serial = jentry->serial;
-					super->ujnl_head = slot;
-				}
-
-				if (jentry->serial == 0)
-					desc->batch_first = slot;
-			}
-		}
-
-		switch (jentry->mark) {
-		case CACHEFS_ONDISC_UJNL_BATCH:
-			if (super->ujnl_serial == jentry->serial)
-				desc->batch_end = slot;
-			break;
-
-		case CACHEFS_ONDISC_UJNL_ACK:
-			if (super->ujnl_serial == jentry->serial)
-				desc->batch_ack	= slot;
-
-			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;
-				super->rcm_block	= jentry->rcm_block;
-				super->rcm_ptrnext	= jentry->rcm_ptrnext;
-				super->rcm_ptrstop	= jentry->rcm_ptrstop;
-				super->rcm_indirect	= jentry->rcm_indirect;
-				super->rcm_ino		= jentry->rcm_ino;
-
-				kdebug("UJNL[%u] ACK %u"
-				       " { a=%u[%u] r=%u R=%u:%u:%u[%u-%u] }"
-				       " hi=%u",
-				       slot,
-				       jentry->batch,
-				       super->alloc_leaf,
-				       super->alloc_cur,
-				       super->recycle_cur,
-				       super->rcm_ino,
-				       super->rcm_indirect,
-				       super->rcm_block,
-				       super->rcm_ptrnext,
-				       super->rcm_ptrstop,
-				       desc->ack_hi);
-
-				desc->ack_hi = jentry->batch;
-			}
-			else {
-				kdebug("UJNL[%u] ACK %u { hi=%u }",
-				       slot,
-				       jentry->batch,
-				       desc->ack_hi);
-			}
-
-			break;
-
-		default:
-			break;
-		}
-
-		offset += super->layout->ujnl_rsize;
-		slot++;
-	}
-
-	kunmap(page);
-
-	desc->desc.count	-= size;
-	desc->desc.written	+= size;
-	return size;
-} /* end cachefs_ujnl_find_batch_actor() */
-
-/*****************************************************************************/
-/*
- * replay entries from the update journal
- */
-static int cachefs_ujnl_replay_actor(read_descriptor_t *desc,
-				     struct page *page,
-				     unsigned long offset,
-				     unsigned long size)
-{
-	struct cachefs_ondisc_update_journal *jentry;
-	struct cachefs_super *super = (struct cachefs_super *) desc->buf;
-	unsigned long stop;
-	void *data;
-
-	kenter("{%x},{%lu},%lu,%lu", desc->count, page->index, offset, size);
-
-	BUG_ON(offset % super->layout->ujnl_rsize);
-	BUG_ON(size % super->layout->ujnl_rsize);
-
-	stop = offset + size;
-
-	data = kmap(page) + offset;
-
-	while (offset<stop) {
-		cachefs_ujnl_replay_func_t replay;
-
-		jentry = (struct cachefs_ondisc_update_journal *) data;
-
-		if ((unsigned) jentry->mark >=
-		    (unsigned) CACHEFS_ONDISC_UJNL__LAST) {
-			kunmap(page);
-			printk("CacheFS: unimplemented ujnl mark (%x) found\n",
-			       jentry->mark);
-			return -EIO;
-		}
-
-		replay = cachefs_ujnl_replay_tbl[jentry->mark];
-		if (replay) {
-			desc->error = replay(super, jentry);
-			if (desc->error < 0)
-				break;
-		}
-
-		super->alloc_leaf	= jentry->alloc_leaf;
-		super->alloc_cur	= jentry->alloc_cur;
-		super->recycle_cur	= jentry->recycle_cur;
-		super->rcm_block	= jentry->rcm_block;
-		super->rcm_ptrnext	= jentry->rcm_ptrnext;
-		super->rcm_ptrstop	= jentry->rcm_ptrstop;
-		super->rcm_indirect	= jentry->rcm_indirect;
-		super->rcm_ino		= jentry->rcm_ino;
-
-		offset += super->layout->ujnl_rsize;
-	}
-
-	kunmap(page);
-
-	desc->count	-= size;
-	desc->written	+= size;
-	return size;
-} /* end cachefs_ujnl_replay_actor() */
-
-/*****************************************************************************/
-/*
- * replay the journal upon mounting to determine various parameters and to fix
- * up changes that failed to be made
- */
-int cachefs_ujnl_replay(struct cachefs_super *super)
-{
-	struct cachefs_replay_find_batch_desc find_batch;
-	struct cachefs_ondisc_update_journal *ajentry;
-	struct cachefs_ondisc_free_node *node;
-	struct file_ra_state ra;
-	read_descriptor_t desc;
-	loff_t ppos;
-	int loop, ret;
-
-	kenter("");
-
-	file_ra_state_init(&ra, super->imisc->i_mapping);
-
-	/* first of all scan to determine the bounds of the latest batch of
-	 * u-journal entries */
-	memset(&find_batch, 0, sizeof(find_batch));
-	find_batch.desc.count = super->layout->bix_vjournal;
-	find_batch.desc.count -= super->layout->bix_ujournal;
-	find_batch.desc.count *= super->layout->bsize;
-	find_batch.desc.buf   = (char *) super;
-
-	ppos = super->layout->bix_ujournal;
-	ppos *= super->layout->bsize;
-
-	do_generic_mapping_read(super->imisc->i_mapping, &ra, NULL, &ppos,
-				&find_batch.desc,
-				cachefs_ujnl_find_batch_actor);
-	if (find_batch.desc.error < 0) {
-		printk("CacheFS: failed to replay ujournal: %d\n",
-		       find_batch.desc.error);
-		return find_batch.desc.error;
-	}
-
-	kdebug("UJNL: last batch=%d { s=%u f=%u b=%u a=%u }",
-	       super->ujnl_batch,
-	       super->ujnl_serial,
-	       find_batch.batch_first,
-	       find_batch.batch_end,
-	       find_batch.batch_ack);
-
-	if (find_batch.batch_end != ~0u && find_batch.batch_ack != ~0u)
-		goto reload_tracking;
-
-	if (find_batch.batch_first == ~0u) {
-		printk("CacheFS: corrupted journal:"
-		       " ujnl batch has no start entry\n");
-		return -EIO;
-	}
-
-	if (find_batch.batch_ack != ~0u) {
-		printk("CacheFS: corrupted journal:"
-		       " ujnl batch has ACK but no end marker\n");
-		return -EIO;
-	}
-
-	if (find_batch.batch_count != super->ujnl_serial) {
-		printk("CacheFS: corrupted journal:"
-		       " ujnl batch has missing marks\n");
-		return -EIO;
-	}
-
-	/* need to replay journal - note it may need to be done in two chunks
-	 * if the batch wraps over the end of the journal space */
-	if (super->ujnl_head < super->ujnl_tail) {
-		memset(&desc, 0, sizeof(desc));
-		desc.count = CACHEFS_ONDISC_UJNL_NUMENTS - super->ujnl_tail;
-		desc.count *= super->layout->ujnl_rsize;
-		desc.buf   = (char *) super;
-
-		ppos = super->layout->bix_ujournal;
-		ppos *= super->layout->bsize;
-		ppos += super->ujnl_tail * super->layout->ujnl_rsize;
-
-		do_generic_mapping_read(super->imisc->i_mapping, &ra, NULL,
-					&ppos, &desc,
-					cachefs_ujnl_replay_actor);
-		if (desc.error < 0) {
-			printk("CacheFS: failed to replay ujournal: %d\n",
-			       desc.error);
-			return desc.error;
-		}
-
-		super->ujnl_tail = 0;
-	}
-
-	memset(&desc, 0, sizeof(desc));
-	desc.count = super->ujnl_head - super->ujnl_tail;
-	desc.count *= super->layout->ujnl_rsize;
-	desc.buf   = (char *) super;
-
-	ppos = super->layout->bix_ujournal;
-	ppos *= super->layout->bsize;
-	ppos += super->ujnl_tail * super->layout->ujnl_rsize;
-
-	do_generic_mapping_read(super->imisc->i_mapping, &ra, NULL, &ppos,
-				&desc, cachefs_ujnl_replay_actor);
-	if (desc.error < 0) {
-		printk("CacheFS: failed to replay ujournal: %d\n",
-		       desc.error);
-		return desc.error;
-	}
-
-	/* write all blocks that are marked for writeback */
-	cachefs_trans_batch_write_data(super);
-	cachefs_trans_batch_process_written_blocks(super, 2);
-
-	/* seal the replayed batch with BATCH and ACK markers */
-	ajentry = kmalloc(super->layout->ujnl_rsize, GFP_KERNEL);
-	if (!ajentry)
-		return -ENOMEM;
-
-	memset(ajentry, 0, sizeof(*ajentry));
-
-	ajentry->batch		= super->ujnl_batch;
-	ajentry->serial		= super->ujnl_serial;
-	ajentry->alloc_leaf	= super->alloc_leaf;
-	ajentry->alloc_cur	= super->alloc_cur;
-	ajentry->recycle_cur	= super->recycle_cur;
-	ajentry->rcm_ino	= super->rcm_ino;
-	ajentry->rcm_indirect	= super->rcm_indirect;
-	ajentry->rcm_block	= super->rcm_block;
-	ajentry->rcm_ptrnext	= super->rcm_ptrnext;
-	ajentry->rcm_ptrstop	= super->rcm_ptrstop;
-
-	if (find_batch.batch_end == ~0u) {
-		cachefs_trans_batch_write_marker(super, super->ujnl_head,
-						 ajentry);
-		super->ujnl_head = UJNL_WRAP(super->ujnl_head + 1);
-		ajentry->serial++;
-	}
-
-	find_batch.batch_ack = super->ujnl_head;
-	cachefs_trans_batch_write_ack(super, super->ujnl_head, ajentry);
-
-	kfree(ajentry);
-
- reload_tracking:
-	kdebug("reload_tracking");
-	super->ujnl_batch++;
-	super->ujnl_serial	= 0;
-	super->ujnl_head	= find_batch.batch_ack + 1;
-	super->ujnl_head	&= CACHEFS_ONDISC_UJNL_NUMENTS - 1;
-	super->ujnl_tail	= super->ujnl_head;
-
-	kdebug("UJNL slot window: next head=%hu tail=%hu",
-	       super->ujnl_head, super->ujnl_tail);
-	kdebug("UJNL Alloc stacks: A=%u[%u] R=%u",
-	       super->alloc_cur, super->alloc_leaf, super->recycle_cur);
-	kdebug("UJNL Recycling: %u:%u:%u:%u-%u",
-	       super->rcm_ino, super->rcm_indirect, super->rcm_block,
-	       super->rcm_ptrnext, super->rcm_ptrstop);
-
-	/* reload the front nodes for the allocation and recycling stacks */
-	if (super->alloc_cur) {
-		ret = cachefs_block_read(super,
-					 CACHEFS_FS_I(super->imisc),
-					 super->alloc_cur,
-					 0,
-					 &super->alloc_block,
-					 &super->alloc_node);
-
-		if (ret < 0) {
-			printk("CacheFS: failed to reload alloc stack: %d\n",
-			       ret);
-			return ret;
-		}
-
-		dbgpgalloc(super->alloc_node);
-
-		set_bit(CACHEFS_BLOCK_CRITICAL, &super->alloc_block->flags);
-		wait_on_page_locked(super->alloc_node);
-
-		node = kmap(super->alloc_node);
-		super->alloc_cur_n = node->count;
-		kunmap(node);
-
-		super->alloc_cur_n +=
-			CACHEFS_ONDISC_LEAVES_PER_FREE_NODE -
-			super->alloc_leaf;
-	}
-
-	if (super->recycle_cur) {
-		ret = cachefs_block_read(super,
-					 CACHEFS_FS_I(super->imisc),
-					 super->recycle_cur,
-					 0,
-					 &super->recycle_block,
-					 &super->recycle_node);
-
-		if (ret<0) {
-			printk("CacheFS: failed to reload recycling stack: %d\n",
-			       ret);
-			return ret;
-		}
-
-		dbgpgalloc(super->recycle_node);
-		wait_on_page_locked(super->recycle_node);
-
-		node = kmap(super->recycle_node);
-
-		for (loop = 0; loop < CACHEFS_ONDISC_LEAVES_PER_FREE_NODE; loop++)
-			if (!node->leaves[loop])
-				break;
-
-		super->recycle_room = CACHEFS_ONDISC_LEAVES_PER_FREE_NODE - loop;
-		super->recycle_cur_n = node->count + super->recycle_room;
-
-		kunmap(node);
-	}
-
-
-	_leave(" = 0");
-	return 0;
-} /* end cachefs_ujnl_replay() */

Index: interface.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/interface.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- interface.c	4 Jul 2003 09:04:44 -0000	1.14
+++ interface.c	9 Jul 2003 10:39:50 -0000	1.15
@@ -600,6 +600,57 @@
 	       idef ? (char *) idef->name : "<file>",
 	       netfs_data);
 
+	if (idef) {
+		int dsize;
+		int loop;
+
+		dsize = CACHEFS_ONDISC_UJNL_MIN_REC_SIZE -
+			sizeof(struct cachefs_ondisc_update_journal);
+
+		if (!idef->name[0]) {
+			printk("CacheFS: %s.%s.%p: nameless index\n",
+			       iparent->netfs->name,
+			       iparent->idef->name,
+			       idef);
+			return;
+		}
+
+		if (idef->data_size > dsize) {
+			printk("CacheFS: %s.%s.%s:"
+			       " index data size exceeds maximum %u>%d\n",
+			       iparent->netfs->name,
+			       iparent->idef->name,
+			       idef->name,
+			       idef->data_size,
+			       dsize);
+			return;
+		}
+
+		for (loop = 0; loop < 4; loop++) {
+			if (idef->keys[loop].type >=
+			    CACHEFS_INDEX_KEYS__LAST) {
+				printk("CacheFS: %s.%s.%s:"
+				       " index type %u unsupported\n",
+				       iparent->netfs->name,
+				       iparent->idef->name,
+				       idef->name,
+				       idef->keys[loop].type);
+				return;
+			}
+
+			dsize -= idef->keys[loop].len;
+			if (dsize < 0) {
+				printk("CacheFS: %s.%s.%s:"
+				       " index key size exceeds data size\n",
+				       iparent->netfs->name,
+				       iparent->idef->name,
+				       idef->name);
+				return;
+			}
+		}
+		
+	}
+
 	/* if no parent cookie, then don't create one here either */
 	if (!iparent) {
 		*_cookie = NULL;

Index: inode.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/inode.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- inode.c	4 Jul 2003 15:22:59 -0000	1.22
+++ inode.c	9 Jul 2003 10:39:50 -0000	1.23
@@ -147,9 +147,9 @@
 	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;
+	inode->index_dsize	= metadata->index.dsize;
+	inode->index_esize	= metadata->index.esize;
+	inode->index_epp	= PAGE_SIZE / metadata->index.esize;
 
 	cachefs_metadata_postread(inode);
 
@@ -229,15 +229,15 @@
 	inode->vfs_inode.i_fop		= &cachefs_file_operations;
 	inode->vfs_inode.i_mapping->a_ops = &cachefs_addrspace_operations;
 
-	inode->index_dsize = metadata->index_dsize;
-	inode->index_esize = metadata->index_esize;
+	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 / metadata->index_esize;
+		inode->index_epp = PAGE_SIZE / inode->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;

Index: index.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/index.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- index.c	4 Jul 2003 14:25:40 -0000	1.25
+++ index.c	9 Jul 2003 10:39:50 -0000	1.26
@@ -170,6 +170,9 @@
 	cachefs_trans_affects_page(trans, __cachefs_page_get_private(ixpage),
 				   ixoffset, sizeof(*xent));
 
+	rec->index->idef->update(rec->target->netfs_data,
+				 trans->jentry->ixdata[0].data);
+
 	ret = cachefs_trans_mark(trans);
 	if (ret < 0)
 		goto error;
@@ -177,9 +180,9 @@
 	cachefs_page_modify(super, &ixpage);
 
 	xent = kmap(ixpage) + ixoffset;
-
-	rec->index->idef->update(rec->target->netfs_data, xent->data);
-
+	memcpy(xent->data,
+	       trans->jentry->ixdata[0].data,
+	       rec->iinode->index_dsize);
 	kunmap(ixpage);
 
 	cachefs_trans_commit(trans);
@@ -532,6 +535,7 @@
 		      struct cachefs_cookie *cookie,
 		      unsigned *_newino)
 {
+	struct cachefs_ondisc_ujnl_index *jindex;
 	struct cachefs_ondisc_index_entry *xent;
 	struct cachefs_ondisc_metadata *metadata;
 	struct cachefs_search_result *srch;
@@ -570,6 +574,8 @@
 	if (!trans)
 		goto error;
 
+	jindex = &trans->jentry->ixdata[0];
+
 	offset = (ixentry % index->index_epp) * index->index_esize;
 
 	trans->jentry->mark = CACHEFS_ONDISC_UJNL_INDEX_CREATING;
@@ -598,6 +604,32 @@
 	cachefs_trans_affects_inode(trans, index);
 	cachefs_trans_affects_inode(trans, super->imetadata);
 
+	index->cookie->idef->update(cookie->netfs_data, jindex->data);
+
+	if (cookie->idef) {
+		struct cachefs_index_def *definition = cookie->idef;
+
+		jindex->def.dsize = definition->data_size;
+		jindex->def.esize = definition->data_size;
+		jindex->def.esize +=
+			sizeof(struct cachefs_ondisc_index_entry);
+
+		if (jindex->def.esize < CACHEFS_ONDISC_INDEX_ENTRY_MINSIZE)
+			jindex->def.esize = CACHEFS_ONDISC_INDEX_ENTRY_MINSIZE;
+
+		for (loop = 0; loop < 4; loop++) {
+			jindex->def.keys[loop] =
+				definition->keys[loop].len &
+				CACHEFS_ONDISC_INDEXKEY_KLEN;
+			jindex->def.keys[loop] |=
+				definition->keys[loop].type << 12;
+		}
+
+		strncpy(jindex->def.type,
+			definition->name,
+			sizeof(jindex->def.type));
+	}
+
 	ret = cachefs_trans_mark(trans);
 	if (ret < 0)
 		goto error;
@@ -614,7 +646,7 @@
 	if (cookie->idef)
 		xent->type = CACHEFS_ONDISC_INDEX_INDEXFILE;
 
-	index->cookie->idef->update(cookie->netfs_data, xent->data);
+	memcpy(xent->data, jindex->data, jindex->def.dsize);
 
 	kunmap(ixpage);
 
@@ -637,30 +669,7 @@
 	metadata->pindex	= index->vfs_inode.i_ino;
 	metadata->pindex_entry	= ixentry;
 
-	if (cookie->idef) {
-		struct cachefs_index_def *definition = cookie->idef;
-
-		metadata->index_dsize = definition->data_size;
-		metadata->index_esize = metadata->index_dsize;
-		metadata->index_esize +=
-			sizeof(struct cachefs_ondisc_index_entry);
-
-		if (metadata->index_esize < CACHEFS_ONDISC_INDEX_ENTRY_MINSIZE)
-			metadata->index_esize =
-				CACHEFS_ONDISC_INDEX_ENTRY_MINSIZE;
-
-		for (loop = 0; loop < 4; loop++) {
-			metadata->index_keys[loop] =
-				definition->keys[loop].len &
-				CACHEFS_ONDISC_INDEXKEY_KLEN;
-			metadata->index_keys[loop] |=
-				definition->keys[loop].type << 12;
-		}
-
-		strncpy(metadata->index_type,
-			definition->name,
-			sizeof(metadata->index_type));
-	}
+	struct_cpy(&metadata->index, &jindex->def);
 
 	kunmap(inopage);
 
@@ -799,89 +808,3 @@
 	_leave(" = %d", ret);
 	return ret;
 } /* end cachefs_index_zap() */
-
-/*****************************************************************************/
-/*
- * replay the creation of a new data inode
- * - since we don't know what index data was associated with it, all we can do
- *   is mark it for reclamation
- */
-int cachefs_replay_ujnl_inode_creating(struct cachefs_super *super,
-				       struct cachefs_ondisc_update_journal *jentry)
-{
-	return -ENOANO;
-} /* end cachefs_replay_ujnl_inode_creating() */
-
-/*****************************************************************************/
-/*
- * replay the updating of the information stored in an inode
- * - since we don't know what changes were to be made, we can't actually do
- *   anything, so we trust that the inode version number will suffice to cause
- *   an update upon accessing if need be
- */
-int cachefs_replay_ujnl_inode_updating(struct cachefs_super *super,
-				       struct cachefs_ondisc_update_journal *jentry)
-{
-	return 0;
-} /* end cachefs_replay_ujnl_inode_updating() */
-
-/*****************************************************************************/
-/*
- * not yet supported
- */
-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");
-	return -EIO;
-} /* end cachefs_replay_ujnl_inode_deleting() */
-
-/*****************************************************************************/
-/*
- * replay an inode being marked for reclamation
- */
-int cachefs_replay_ujnl_inode_mark_reclaim(struct cachefs_super *super,
-					   struct cachefs_ondisc_update_journal *jentry)
-{
-	return -ENOANO;
-} /* end cachefs_replay_ujnl_inode_mark_reclaim() */
-
-/*****************************************************************************/
-/*
- *
- */
-int cachefs_replay_ujnl_inode_reclaiming(struct cachefs_super *super,
-					 struct cachefs_ondisc_update_journal *jentry)
-{
-	return -ENOANO;
-} /* end cachefs_replay_ujnl_inode_reclaiming() */
-
-/*****************************************************************************/
-/*
- *
- */
-int cachefs_replay_ujnl_index_extending(struct cachefs_super *super,
-					struct cachefs_ondisc_update_journal *jentry)
-{
-	return -ENOANO;
-} /* end cachefs_replay_ujnl_index_extending() */
-
-/*****************************************************************************/
-/*
- *
- */
-int cachefs_replay_ujnl_index_creating(struct cachefs_super *super,
-				       struct cachefs_ondisc_update_journal *jentry)
-{
-	return -ENOANO;
-} /* end cachefs_replay_ujnl_index_creating() */
-
-/*****************************************************************************/
-/*
- *
- */
-int cachefs_replay_ujnl_index_modifying(struct cachefs_super *super,
-					struct cachefs_ondisc_update_journal *jentry)
-{
-	return -ENOANO;
-} /* end cachefs_replay_ujnl_index_modifying() */

Index: dump-journal.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/dump-journal.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- dump-journal.c	4 Jul 2003 14:25:40 -0000	1.12
+++ dump-journal.c	9 Jul 2003 10:39:50 -0000	1.13
@@ -45,7 +45,6 @@
 	BRIGHT	"Null     "	NORMAL,
 	GREY	"Batch    "	NORMAL,
 	GREY	"Ack      "	NORMAL,
-	BRIGHT	"RcycEmpty"	NORMAL,
 	BRIGHT	"RcycBegin"	NORMAL,
 	BRIGHT	"RcycXfer "	NORMAL,
 	BRIGHT	"RcycScvng"	NORMAL,

Index: cachefs-layout.h
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/cachefs-layout.h,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- cachefs-layout.h	4 Jul 2003 15:22:59 -0000	1.28
+++ cachefs-layout.h	9 Jul 2003 10:39:50 -0000	1.29
@@ -88,6 +88,25 @@
 #define CACHEFS_ONDISC_INDEX_ENTRY_MINSIZE \
 	(sizeof(struct cachefs_ondisc_index_entry) + sizeof(u_int32_t))
 
+/* index definition description */
+struct cachefs_ondisc_index_def
+{
+	u_int16_t			dsize;
+	u_int16_t			esize;
+	u_int16_t			keys[4];
+	u_int8_t			type[8];
+
+#define CACHEFS_ONDISC_INDEXKEY_KLEN	0x0FFF	/* length of key segment */
+#define CACHEFS_ONDISC_INDEXKEY_TYPE	0xF000	/* type of key segment */
+#define CACHEFS_ONDISC_INDEXKEY_NOTUSED	0x0000	/* - segment not used */
+#define CACHEFS_ONDISC_INDEXKEY_BIN	0x1000	/* - binary data */
+#define CACHEFS_ONDISC_INDEXKEY_ASCIIZ	0x2000	/* - null-terminated string */
+#define CACHEFS_ONDISC_INDEXKEY_IPV4	0x3000	/* - IPv4 address */
+#define CACHEFS_ONDISC_INDEXKEY_IPV6	0x4000	/* - IPv6 address */
+
+	u_int8_t			data[0];
+};
+
 /*****************************************************************************/
 /*
  * on-disc metadata record
@@ -111,18 +130,7 @@
 	u_int64_t			size;		/* size of file */
 
 	/* index file definition */
-	u_int16_t			index_dsize;	/* index entry data size */
-	u_int16_t			index_esize;	/* index entry size */
-	u_int16_t			index_keys[4];	/* key->ascii translation */
-	u_int8_t			index_type[8];	/* name of index type */
-
-#define CACHEFS_ONDISC_INDEXKEY_KLEN	0x0FFF	/* length of key segment */
-#define CACHEFS_ONDISC_INDEXKEY_TYPE	0xF000	/* type of key segment */
-#define CACHEFS_ONDISC_INDEXKEY_NOTUSED	0x0000	/* - segment not used */
-#define CACHEFS_ONDISC_INDEXKEY_BIN	0x1000	/* - binary data */
-#define CACHEFS_ONDISC_INDEXKEY_ASCIIZ	0x2000	/* - null-terminated string */
-#define CACHEFS_ONDISC_INDEXKEY_IPV4	0x3000	/* - IPv4 address */
-#define CACHEFS_ONDISC_INDEXKEY_IPV6	0x4000	/* - IPv6 address */
+	struct cachefs_ondisc_index_def	index;
 
 	/* file contents - recycling depends on triple_indirect being first */
 	cachefs_blockix_t		triple_indirect; /* triple indirect block index */
@@ -200,11 +208,6 @@
 	/* batch completion mark */
 	CACHEFS_ONDISC_UJNL_ACK,
 
-	/* front alloc_stk node recycled
-	 * - block	= block being recycled
-	 */
-	CACHEFS_ONDISC_UJNL_RECYC_EMPTY_NODE,
-
 	/* beginning new recycle_stk front node
 	 * - block	= block being begun
 	 * - auxblock	= old front recycling node
@@ -231,12 +234,23 @@
 
 	/* transfer bix_unready to recycle_stk
 	 * - block	= recycling node that blocks were pasted into
+	 * - entry	= index into block[] of first pointer inserted
 	 * - auxblock	= first unready block transferred
 	 * - pgnum	= new super->layout.bix_unready
+	 * - count	= number of blocks pasted
 	 */
 	CACHEFS_ONDISC_UJNL_RECYC_MAKEREADY,
 
-	/* data file being created */
+	/* data file being created
+	 * - index	= parent index being attached to
+	 * - ixentry	= entry in parent index
+	 * - pgnum	= page in file holding index entry being allocated
+	 * - block	= block holding index entry being allocated
+	 * - entry	= offset of entry in block
+	 * - ino	= inode being attached to hold index contents
+	 * - upblock	= next free index file entry
+	 * - count	= size of entry in block
+	 */
 	CACHEFS_ONDISC_UJNL_INODE_CREATING,
 
 	/* data file being updated */
@@ -341,6 +355,11 @@
 	CACHEFS_ONDISC_UJNL__LAST
 } __attribute__((packed));
 
+struct cachefs_ondisc_ujnl_index {
+	struct cachefs_ondisc_index_def	def;
+	u_int8_t			data[0];
+};
+
 struct cachefs_ondisc_update_journal
 {
 	enum cachefs_ondisc_ujnl_mark	mark;
@@ -377,11 +396,19 @@
 	cachefs_blockix_t		recycle_cur;	/* current block recycling node */
 
 	union {
-		cachefs_blockix_t	rcyptrs[0];	/* recycled pointers */
+		/* recycled pointers */
+		cachefs_blockix_t rcyptrs[0];
+
+		/* new/updated index entry */
+		struct cachefs_ondisc_ujnl_index ixdata[0];
+
+		/* miscellaneous data */
+		u_int8_t data[0];
 	};
 };
 
-#define CACHEFS_ONDISC_UJNL_NUMENTS	4096		/* number of entries in the u-journal */
+#define CACHEFS_ONDISC_UJNL_NUMENTS		4096	/* number of entries in the u-journal */
+#define CACHEFS_ONDISC_UJNL_MIN_REC_SIZE	512	/* minimum u-journal record size */
 
 /*****************************************************************************/
 /*

Index: cachefs-int.h
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/cachefs-int.h,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- cachefs-int.h	4 Jul 2003 09:04:44 -0000	1.37
+++ cachefs-int.h	9 Jul 2003 10:39:50 -0000	1.38
@@ -77,6 +77,7 @@
 #define CACHEFS_SUPER_RCM_IMM_SCAN	3		/* T if should scan for immediately
 							 * reclaimable inodes */
 #define CACHEFS_SUPER_WITHDRAWN		4		/* T if cache has been withdrawn */
+#define CACHEFS_SUPER_REPLAYING_UJNL	5		/* T if replaying u-journal */
 
 	/* index management */
 	struct list_head		ino_list;	/* list of data/index inodes */
@@ -143,6 +144,7 @@
 	struct list_head		ujnl_writeq;	/* transactions being written */
 	struct list_head		ujnl_ackq;	/* marks ACK'd by transaction completion */
 	struct list_head		ujnl_ackwq;	/* marks awaiting on-disc ACK */
+	struct list_head		ujnl_replayq;	/* blocks having allocation replayed */
 
 	struct semaphore		batch_sem;	/* batching mutex */
 	struct semaphore		batch_uj_sem;	/* ujnl written sync mutex */
@@ -202,17 +204,6 @@
 extern void cachefs_recycle_reclaim(struct cachefs_super *super);
 extern void cachefs_recycle_unallocate_data_block(struct cachefs_super *super);
 
-extern int cachefs_replay_ujnl_recyc_empty_node(struct cachefs_super *super,
-						struct cachefs_ondisc_update_journal *jentry);
-extern int cachefs_replay_ujnl_recyc_begin_new(struct cachefs_super *super,
-					       struct cachefs_ondisc_update_journal *jentry);
-extern int cachefs_replay_ujnl_recyc_transfer(struct cachefs_super *super,
-					      struct cachefs_ondisc_update_journal *jentry);
-extern int cachefs_replay_ujnl_recyc_scavenge(struct cachefs_super *super,
-					      struct cachefs_ondisc_update_journal *jentry);
-extern int cachefs_replay_ujnl_recyc_makeready(struct cachefs_super *super,
-					       struct cachefs_ondisc_update_journal *jentry);
-
 /*****************************************************************************/
 /*
  * block management record
@@ -462,36 +453,6 @@
 
 extern int cachefs_index_zap(struct cachefs_super *super);
 
-extern int cachefs_replay_ujnl_inode_creating(struct cachefs_super *super,
-					      struct cachefs_ondisc_update_journal *jentry);
-extern int cachefs_replay_ujnl_inode_updating(struct cachefs_super *super,
-					      struct cachefs_ondisc_update_journal *jentry);
-extern int cachefs_replay_ujnl_inode_deleting(struct cachefs_super *super,
-					      struct cachefs_ondisc_update_journal *jentry);
-extern int cachefs_replay_ujnl_inode_mark_reclaim(struct cachefs_super *super,
-						  struct cachefs_ondisc_update_journal *jentry);
-extern int cachefs_replay_ujnl_inode_reclaiming(struct cachefs_super *super,
-						struct cachefs_ondisc_update_journal *jentry);
-extern int cachefs_replay_ujnl_index_extending(struct cachefs_super *super,
-					       struct cachefs_ondisc_update_journal *jentry);
-extern int cachefs_replay_ujnl_index_creating(struct cachefs_super *super,
-					      struct cachefs_ondisc_update_journal *jentry);
-extern int cachefs_replay_ujnl_index_modifying(struct cachefs_super *super,
-					       struct cachefs_ondisc_update_journal *jentry);
-extern int cachefs_replay_ujnl_index_deleting(struct cachefs_super *super,
-					      struct cachefs_ondisc_update_journal *jentry);
-
-extern int cachefs_replay_ujnl_data_allocing(struct cachefs_super *super,
-					     struct cachefs_ondisc_update_journal *jentry);
-extern int cachefs_replay_ujnl_data_written(struct cachefs_super *super,
-					    struct cachefs_ondisc_update_journal *jentry);
-extern int cachefs_replay_ujnl_data_unallocing(struct cachefs_super *super,
-					       struct cachefs_ondisc_update_journal *jentry);
-extern int cachefs_replay_ujnl_indirect_allocing(struct cachefs_super *super,
-						 struct cachefs_ondisc_update_journal *jentry);
-extern int cachefs_replay_ujnl_indirect_freeing(struct cachefs_super *super,
-						struct cachefs_ondisc_update_journal *jentry);
-
 /*****************************************************************************/
 /*
  * record of as-yet invalid data block for which a v-journal entry exists
@@ -567,6 +528,11 @@
 struct cachefs_transaction *cachefs_trans_alloc(struct cachefs_super *super,
 						unsigned long gfp);
 
+extern
+struct cachefs_transaction *
+cachefs_trans_alloc_replay(struct cachefs_super *super,
+			   struct cachefs_ondisc_update_journal *jentry);
+
 extern void __cachefs_trans_put(struct cachefs_transaction *trans);
 static inline void cachefs_trans_put(struct cachefs_transaction *trans)
 {
@@ -612,7 +578,7 @@
 
 extern int  cachefs_trans_mark(struct cachefs_transaction *trans);
 extern void cachefs_trans_commit(struct cachefs_transaction *trans);
-extern void cachefs_trans_cancel(struct cachefs_transaction *trans);
+extern void cachefs_trans_commit_replay(struct cachefs_transaction *trans);
 extern void cachefs_trans_batch_write(struct cachefs_super *super);
 extern void cachefs_trans_batch_timer(unsigned long data);
 

Index: aops.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/aops.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- aops.c	4 Jul 2003 09:04:44 -0000	1.39
+++ aops.c	9 Jul 2003 10:39:50 -0000	1.40
@@ -1525,53 +1525,3 @@
 	return ret;
 
 } /* end cachefs_file_readpage() */
-
-/*****************************************************************************/
-/*
- * replay data block allocation and v-journal set
- */
-int cachefs_replay_ujnl_data_allocing(struct cachefs_super *super,
-				      struct cachefs_ondisc_update_journal *jentry)
-{
-	return -ENOANO;
-} /* end cachefs_replay_ujnl_data_allocing() */
-
-/*****************************************************************************/
-/*
- * replay data write and v-journal clear
- */
-int cachefs_replay_ujnl_data_written(struct cachefs_super *super,
-				     struct cachefs_ondisc_update_journal *jentry)
-{
-	return -ENOANO;
-} /* end cachefs_replay_ujnl_data_written() */
-
-/*****************************************************************************/
-/*
- * replay data block unallocation and v-journal clear
- */
-int cachefs_replay_ujnl_data_unallocing(struct cachefs_super *super,
-					struct cachefs_ondisc_update_journal *jentry)
-{
-	return -ENOANO;
-} /* end cachefs_replay_ujnl_data_unallocing() */
-
-/*****************************************************************************/
-/*
- * replay indirection block allocation
- */
-int cachefs_replay_ujnl_indirect_allocing(struct cachefs_super *super,
-					  struct cachefs_ondisc_update_journal *jentry)
-{
-	return -ENOANO;
-} /* end cachefs_replay_ujnl_indirect_allocing() */
-
-/*****************************************************************************/
-/*
- * replay indirection block freeing
- */
-int cachefs_replay_ujnl_indirect_freeing(struct cachefs_super *super,
-					 struct cachefs_ondisc_update_journal *jentry)
-{
-	return -ENOANO;
-} /* end cachefs_replay_ujnl_indirect_freeing() */

Index: Makefile
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/Makefile,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- Makefile	23 May 2003 12:59:22 -0000	1.16
+++ Makefile	9 Jul 2003 10:39:51 -0000	1.17
@@ -16,6 +16,7 @@
 	kcachefsd.o \
 	main.o \
 	recycling.o \
+	replay.o \
 	rootdir.o \
 	status.o \
 	super.o \


From dwh at infradead.org  Thu Jul 10 13:07:04 2003
From: dwh at infradead.org (dwh@infradead.org)
Date: Thu Jul 10 12:06:56 2003
Subject: afs/fs/afs volume.c,1.8,1.9 vnode.c,1.7,1.8 vlocation.c,1.9,1.10
 mntpt.c,1.7,1.8 cell.c,1.9,1.10
Message-ID: <E19aZGS-0006c9-00@phoenix.infradead.org>

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

Modified Files:
	volume.c vnode.c vlocation.c mntpt.c cell.c 
Log Message:
cache management callbacks fixing


Index: volume.c
===================================================================
RCS file: /home/cvs/afs/fs/afs/volume.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- volume.c	4 Jul 2003 15:26:31 -0000	1.8
+++ volume.c	10 Jul 2003 11:07:01 -0000	1.9
@@ -457,11 +457,14 @@
 	const struct afs_cache_vhash *vhash = entry;
 	struct afs_volume *volume = target;
 
-	_enter("");
+	_enter("{%u},{%u}", volume->type, vhash->vtype);
 
-	if (volume->type == vhash->vtype)
+	if (volume->type == vhash->vtype) {
+		_leave(" = SUCCESS");
 		return CACHEFS_MATCH_SUCCESS;
+	}
 
+	_leave(" = FAILED");
 	return CACHEFS_MATCH_FAILED;
 } /* end afs_volume_cache_match() */
 
@@ -474,7 +477,7 @@
 	struct afs_cache_vhash *vhash = entry;
 	struct afs_volume *volume = source;
 
-	kenter("");
+	_enter("");
 
 	vhash->vtype = volume->type;
 

Index: vnode.c
===================================================================
RCS file: /home/cvs/afs/fs/afs/vnode.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- vnode.c	4 Jul 2003 15:26:31 -0000	1.7
+++ vnode.c	10 Jul 2003 11:07:01 -0000	1.8
@@ -333,16 +333,27 @@
 	const struct afs_cache_vnode *cvnode = entry;
 	struct afs_vnode *vnode = target;
 
-	_enter("");
+	_enter("{%x,%x,%Lx},{%x,%x,%Lx}",
+	       vnode->fid.vnode,
+	       vnode->fid.unique,
+	       vnode->status.version,
+	       cvnode->vnode_id,
+	       cvnode->vnode_unique,
+	       cvnode->data_version);
 
-	if (vnode->fid.vnode != cvnode->vnode_id)
+	if (vnode->fid.vnode != cvnode->vnode_id) {
+		_leave(" = FAILED");
 		return CACHEFS_MATCH_FAILED;
+	}
 
 	if (vnode->fid.unique != cvnode->vnode_unique ||
-	    vnode->status.version != cvnode->data_version)
+	    vnode->status.version != cvnode->data_version) {
+		_leave(" = DELETE");
 		return CACHEFS_MATCH_SUCCESS_DELETE;
+	}
 
-	return CACHEFS_MATCH_FAILED;
+	_leave(" = SUCCESS");
+	return CACHEFS_MATCH_SUCCESS;
 } /* end afs_vnode_cache_match() */
 
 /*****************************************************************************/

Index: vlocation.c
===================================================================
RCS file: /home/cvs/afs/fs/afs/vlocation.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- vlocation.c	4 Jul 2003 15:26:31 -0000	1.9
+++ vlocation.c	10 Jul 2003 11:07:01 -0000	1.10
@@ -857,15 +857,16 @@
 	const struct afs_cache_vlocation *vldb = entry;
 	struct afs_vlocation *vlocation = target;
 
-	_enter("");
+	_enter("{%s},{%s}", vlocation->vldb.name, vldb->name);
 
 	if (strncmp(vlocation->vldb.name,
 		    vldb->name,
 		    sizeof(vldb->name)) == 0) {
 		if (!vlocation->valid ||
 		    vlocation->vldb.rtime == vldb->rtime) {
-			struct_cpy(&vlocation->vldb,vldb);
+			struct_cpy(&vlocation->vldb, vldb);
 			vlocation->valid = 1;
+			_leave(" = SUCCESS [c->m]");
 			return CACHEFS_MATCH_SUCCESS;
 		}
 		/* need to update cache if cached info differs */
@@ -873,16 +874,21 @@
 			/* delete if VIDs for this name differ */
 			if (memcmp(&vlocation->vldb.vid,
 				   &vldb->vid,
-				   sizeof(vldb->vid)) != 0)
+				   sizeof(vldb->vid)) != 0) {
+				_leave(" = DELETE");
 				return CACHEFS_MATCH_SUCCESS_DELETE;
+			}
 
+			_leave(" = UPDATE");
 			return CACHEFS_MATCH_SUCCESS_UPDATE;
 		}
 		else {
+			_leave(" = SUCCESS");
 			return CACHEFS_MATCH_SUCCESS;
 		}
 	}
 
+	_leave(" = FAILED");
 	return CACHEFS_MATCH_FAILED;
 } /* end afs_vlocation_cache_match() */
 
@@ -895,7 +901,7 @@
 	struct afs_cache_vlocation *vldb = entry;
 	struct afs_vlocation *vlocation = source;
 
-	kenter("");
+	_enter("");
 
 	struct_cpy(vldb,&vlocation->vldb);
 

Index: mntpt.c
===================================================================
RCS file: /home/cvs/afs/fs/afs/mntpt.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- mntpt.c	4 Jul 2003 15:26:31 -0000	1.7
+++ mntpt.c	10 Jul 2003 11:07:01 -0000	1.8
@@ -23,7 +23,6 @@
 #include "cell.h"
 #include "volume.h"
 #include "vnode.h"
-#define __KDEBUG
 #include "internal.h"
 
 

Index: cell.c
===================================================================
RCS file: /home/cvs/afs/fs/afs/cell.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- cell.c	4 Jul 2003 15:26:31 -0000	1.9
+++ cell.c	10 Jul 2003 11:07:01 -0000	1.10
@@ -489,11 +489,14 @@
 	const struct afs_cache_cell *ccell = entry;
 	struct afs_cell *cell = target;
 
-	_enter("");
+	_enter("{%s},{%s}", ccell->name, cell->name);
 
-	if (strncmp(ccell->name, cell->name, sizeof(ccell->name)) == 0)
+	if (strncmp(ccell->name, cell->name, sizeof(ccell->name)) == 0) {
+		_leave(" = SUCCESS");
 		return CACHEFS_MATCH_SUCCESS;
+	}
 
+	_leave(" = FAILED");
 	return CACHEFS_MATCH_FAILED;
 } /* end afs_cell_cache_match() */
 
@@ -506,7 +509,7 @@
 	struct afs_cache_cell *ccell = entry;
 	struct afs_cell *cell = source;
 
-	kenter("%p,%p", source, entry);
+	_enter("%p,%p", source, entry);
 
 	strncpy(ccell->name, cell->name, sizeof(ccell->name));
 


From dwh at infradead.org  Thu Jul 10 16:20:02 2003
From: dwh at infradead.org (dwh@infradead.org)
Date: Thu Jul 10 15:19:55 2003
Subject: afs/include/linux cachefs.h,1.16,1.17
Message-ID: <E19acHC-0003xH-00@phoenix.infradead.org>

Update of /home/cvs/afs/include/linux
In directory phoenix.infradead.org:/tmp/cvs-serv15190/include/linux

Modified Files:
	cachefs.h 
Log Message:
more codestylifying


Index: cachefs.h
===================================================================
RCS file: /home/cvs/afs/include/linux/cachefs.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- cachefs.h	9 Jul 2003 10:39:49 -0000	1.16
+++ cachefs.h	10 Jul 2003 14:19:59 -0000	1.17
@@ -15,37 +15,46 @@
 #include <linux/fs.h>
 #include <linux/list.h>
 #include <linux/pagemap.h>
-#include <linux/bio.h>
 
 struct cachefs_cookie;
 struct cachefs_netfs;
 struct cachefs_netfs_operations;
 struct cachefs_page;
 
-typedef enum {
-	CACHEFS_MATCH_FAILED,		/* no match */
-	CACHEFS_MATCH_SUCCESS,		/* successful match */
-	CACHEFS_MATCH_SUCCESS_UPDATE,	/* successful match, entry requires update */
-	CACHEFS_MATCH_SUCCESS_DELETE,	/* successful match, entry requires deletion */
-} cachefs_match_val_t;
-
 typedef void (*cachefs_rw_complete_t)(void *cookie_data,
 				      struct page *page,
 				      void *data,
 				      int error);
 
+/* result of index entry comparison */
+typedef enum {
+	/* no match */
+	CACHEFS_MATCH_FAILED,
+
+	/* successful match */
+	CACHEFS_MATCH_SUCCESS,
+
+	/* successful match, entry requires update */
+	CACHEFS_MATCH_SUCCESS_UPDATE,
+
+	/* successful match, entry requires deletion */
+	CACHEFS_MATCH_SUCCESS_DELETE,
+} cachefs_match_val_t;
+
 /*****************************************************************************/
 /*
  * cachefs index definition
  * - each index file contains a number of fixed size entries
- *   - they don't have to fit exactly into a page, but if they don't, the gap at the end of the
- *     page will not be used
- * - if the first 4 bytes of the entry are all zero, then the entry is taken as not being in use
+ *   - they don't have to fit exactly into a page, but if they don't, the gap
+ *     at the end of the page will not be used
  */
 struct cachefs_index_def
 {
-	u_int8_t			name[8];	/* name of index */
-	u_int16_t			data_size;	/* index entry data size */
+	/* name of index */
+	u_int8_t			name[8];
+
+	/* size of data to be stored in index */
+	u_int16_t			data_size;
 
 	/* key description (for displaying in cache mountpoint) */
 	struct {
@@ -61,13 +70,16 @@
 #define CACHEFS_INDEX_KEYS__LAST	CACHEFS_INDEX_KEYS_IPV6ADDR
 
 	/* see if entry matches the specified key
-	 * - the netfs data from the cookie being used as the target is presented
+	 * - the netfs data from the cookie being used as the target is
+	 *   presented
 	 * - entries that aren't in use will not be presented for matching
 	 */
-	cachefs_match_val_t (*match)(void *target_netfs_data, const void *entry);
+	cachefs_match_val_t (*match)(void *target_netfs_data,
+				     const void *entry);
 
 	/* update entry from key
-	 * - the netfs data from the cookie being used as the source is presented
+	 * - the netfs data from the cookie being used as the source is
+	 *   presented
 	 */
 	void (*update)(void *source_netfs_data, void *entry);
 };
@@ -77,7 +89,8 @@
 				   void *netfs_data,
 				   struct cachefs_cookie **_cookie);
 
-extern void cachefs_relinquish_cookie(struct cachefs_cookie *cookie, int retire);
+extern void cachefs_relinquish_cookie(struct cachefs_cookie *cookie,
+				      int retire);
 
 /*****************************************************************************/
 /*
@@ -87,11 +100,11 @@
  */
 struct cachefs_netfs
 {
-	const char			*name;		/* filesystem def name */
-	unsigned			version;	/* index layout version */
+	const char			*name;		/* filesystem name */
+	unsigned			version;	/* indexing version */
 	struct cachefs_cookie		*primary_index;
 	struct cachefs_netfs_operations	*ops;
-	struct list_head		link;		/* internal cachefs list link */
+	struct list_head		link;		/* internal link */
 };
 
 extern int cachefs_register_netfs(struct cachefs_netfs *netfs,
@@ -105,11 +118,8 @@
 	 * - returning -ENODATA will cause this page to be ignored
 	 * - typically, the struct will be attached to page->private
 	 */
-	int (*get_page_cookie)(struct page *page, struct cachefs_page **_page_cookie);
-
-	/* handle journal replaying indicating writeback needed */
-	int (*replay)(struct cachefs_cookie *cookie, unsigned page_number);
-
+	int (*get_page_cookie)(struct page *page,
+			       struct cachefs_page **_page_cookie);
 };
 
 /*****************************************************************************/
@@ -122,9 +132,11 @@
 {
 	struct cachefs_block	*mapped_block;	/* block mirroring this page */
 	rwlock_t		lock;
+
 	unsigned long		flags;
-#define CACHEFS_PAGE_BOUNDARY	0		/* next block has a different indirection chain */
-#define CACHEFS_PAGE_NEW	1		/* this is a newly allocated block */
+#define CACHEFS_PAGE_BOUNDARY	0	/* next block has a different
+					 * indirection chain */
+#define CACHEFS_PAGE_NEW	1	/* this is a newly allocated block */
 };
 
 /*
@@ -132,10 +144,10 @@
  * - if the cookie is not backed by a file:
  *   - -ENOBUFS will be returned and nothing more will be done
  * - else if the page is backed by a block in the cache:
- *   - a read will be started which will call end_io_data on completion
+ *   - a read will be started which will call end_io_func on completion
  *   - the wb-journal will be searched for an entry pertaining to this block
  *     - if an entry is found:
- *       - 1 will be returned
+ *       - 1 will be returned [not yet supported]
  *       else
  *       - 0 will be returned
  * - else if the page is unbacked:
@@ -152,13 +164,16 @@
 
 /*
  * request a page be stored in the cache
- * - this request may be ignored if no cache block is currently attached, in which case it
+ * - this request may be ignored if no cache block is currently attached, in
+ *   which case it:
  *   - returns -ENOBUFS
  * - if a cache block was already allocated:
  *   - the page cookie will be updated to reflect the block selected
- *   - a BIO will have been dispatched to write the page with end_io as the completion func
- *     - end_io can be NULL, in which case a default function will just clear the writeback bit
- *   - if a page is associated with a v-journal entry, that entry will be erased
+ *   - a BIO will be dispatched to write the page (end_io_func will be called
+ *     from the completion function)
+ *     - end_io_func can be NULL, in which case a default function will just
+ *       clear the writeback bit on the page
+ *   - any associated validity journal entry will be cleared
  *   - returns 0
  */
 extern int cachefs_write_page(struct cachefs_cookie *cookie,
@@ -169,7 +184,7 @@
 
 /*
  * indicate that caching is no longer required on a page
- * - cannot cancel any outstanding BIOs between this page and the cache
+ * - note: cannot cancel any outstanding BIOs between this page and the cache
  */
 extern void cachefs_uncache_page(struct cachefs_cookie *cookie,
 				 struct page *page);
@@ -195,9 +210,11 @@
 #endif
 
 /*
- * convenience routines for mapping page->private directly to a struct cachefs_page
+ * convenience routines for mapping page->private directly to a struct
+ * cachefs_page
  */
-static inline struct cachefs_page *__cachefs_page_get_private(struct page *page)
+static inline
+struct cachefs_page *__cachefs_page_get_private(struct page *page)
 {
 	BUG_ON(!PagePrivate(page));
 	return (struct cachefs_page *) page->private;


From dwh at infradead.org  Thu Jul 10 16:21:26 2003
From: dwh at infradead.org (dwh@infradead.org)
Date: Thu Jul 10 15:21:25 2003
Subject: afs/fs/cachefs rootdir.c,1.13,1.14 replay.c,1.1,1.2
 recycling.c,1.25,1.26 journal.c,1.39,1.40 interface.c,1.15,1.16
 index.c,1.26,1.27 dump-journal.c,1.13,1.14
 cachefs-layout.h,1.29,1.30 cachefs-int.h,1.38,1.39 block.c,1.8,1.9
Message-ID: <E19acIY-0003xh-00@phoenix.infradead.org>

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

Modified Files:
	rootdir.c replay.c recycling.c journal.c interface.c index.c 
	dump-journal.c cachefs-layout.h cachefs-int.h block.c 
Log Message:
started fleshing out the replaying properly
fixed a few bugs (including those introduced by the above)


Index: rootdir.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/rootdir.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- rootdir.c	9 Jul 2003 10:39:50 -0000	1.13
+++ rootdir.c	10 Jul 2003 14:21:23 -0000	1.14
@@ -641,14 +641,17 @@
  */
 static int cachefs_root_rmdir_unlink(struct inode *dir, struct dentry *dentry)
 {
+	struct cachefs_ondisc_index_entry *xent;
 	struct cachefs_ondisc_metadata *metadata;
 	struct cachefs_transaction *trans;
-	struct cachefs_inode *inode;
 	struct cachefs_super *super = dir->i_sb->s_fs_info;
+	struct cachefs_inode *inode, *index;
 	unsigned long flags;
+	struct page *ixpage;
 	int ret;
 
-	_enter("{%lx},{%s,%p}", dir->i_ino, dentry->d_name.name, dentry->d_inode);
+	_enter("{%lx},{%s,%p}",
+	       dir->i_ino, dentry->d_name.name, dentry->d_inode);
 
 	if (!dentry->d_inode) {
 		printk("&&& no inode &&&\n");
@@ -657,6 +660,7 @@
 	}
 
 	inode = CACHEFS_FS_I(dentry->d_inode);
+	index = CACHEFS_FS_I(dir);
 
 	/* mark for reclamation under journalling */
 	trans = cachefs_trans_alloc(super, GFP_KERNEL);
@@ -667,20 +671,52 @@
 
 	trans->jentry->mark	= CACHEFS_ONDISC_UJNL_INODE_MARK_RECLAIM;
 	trans->jentry->ino	= inode->vfs_inode.i_ino;
+	trans->jentry->auxblock	= inode->metadata->bix;
+	trans->jentry->auxentry	= inode->metadata_offset;
+
+	metadata = cachefs_metadata_preread(inode);
+	trans->jentry->index	= metadata->pindex;
+	trans->jentry->ixentry	= metadata->pindex_entry;
+	cachefs_metadata_postread(inode);
+
+	BUG_ON(trans->jentry->index != dir->i_ino);
+
+	trans->jentry->pgnum = trans->jentry->index / index->index_epp;
+	trans->jentry->entry =
+		(trans->jentry->index % index->index_epp) * index->index_esize;
+
+	ret = cachefs_get_page(index, trans->jentry->pgnum, &ixpage);
+	if (ret < 0) {
+		cachefs_trans_put(trans);
+		_leave(" = %d", ret);
+		return ret;
+	}
+
+	trans->jentry->block = __cachefs_get_page_block(ixpage)->bix;
 
 	cachefs_trans_affects_inode(trans, inode);
+	cachefs_trans_affects_page(trans, __cachefs_page_get_private(ixpage),
+				   trans->jentry->entry, sizeof(*xent));
 
 	ret = cachefs_trans_mark(trans);
 	if (ret < 0) {
+		cachefs_put_page(ixpage);
 		cachefs_trans_put(trans);
 		_leave(" = %d", ret);
 		return ret;
 	}
 
+	cachefs_page_modify(super, &ixpage);
+
 	/* modify the inode metadata entry */
 	metadata = cachefs_metadata_prewrite(inode);
 	metadata->header.state = CACHEFS_ONDISC_INDEX_RECYCLE;
 	cachefs_metadata_postwrite(inode);
+
+	/* modify the index entry */
+	xent = kmap(ixpage) + trans->jentry->entry;
+	xent->state = CACHEFS_ONDISC_INDEX_RECYCLE;
+	kunmap(ixpage);
 
 	cachefs_trans_commit(trans);
 

Index: replay.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/replay.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- replay.c	9 Jul 2003 10:39:50 -0000	1.1
+++ replay.c	10 Jul 2003 14:21:23 -0000	1.2
@@ -18,6 +18,9 @@
 #include "cachefs-int.h"
 
 #define UJNL_WRAP(X) ((X) & (CACHEFS_ONDISC_UJNL_NUMENTS - 1))
+#define BLOCK_VALID(BLOCK,JENTRY) \
+	((BLOCK) && \
+	 (u_int16_t) (unsigned long) (BLOCK)->ref <= (JENTRY)->serial)
 
 struct cachefs_replay_find_batch_desc {
 	read_descriptor_t	desc;
@@ -63,9 +66,6 @@
 static int cachefs_replay_ujnl_index_extending(struct cachefs_super *super,
 					       struct cachefs_ondisc_update_journal *jentry,
 					       struct cachefs_transaction *trans);
-static int cachefs_replay_ujnl_index_creating(struct cachefs_super *super,
-					      struct cachefs_ondisc_update_journal *jentry,
-					      struct cachefs_transaction *trans);
 static int cachefs_replay_ujnl_index_modifying(struct cachefs_super *super,
 					       struct cachefs_ondisc_update_journal *jentry,
 					       struct cachefs_transaction *trans);
@@ -102,7 +102,7 @@
 	[CACHEFS_ONDISC_UJNL_INDIRECT_ALLOCING]	= cachefs_replay_ujnl_indirect_allocing,
 	[CACHEFS_ONDISC_UJNL_INDIRECT_FREEING]	= cachefs_replay_ujnl_indirect_freeing,
 	[CACHEFS_ONDISC_UJNL_INDEX_EXTENDING]	= cachefs_replay_ujnl_index_extending,
-	[CACHEFS_ONDISC_UJNL_INDEX_CREATING]	= cachefs_replay_ujnl_index_creating,
+	[CACHEFS_ONDISC_UJNL_INDEX_CREATING]	= cachefs_replay_ujnl_inode_creating,
 	[CACHEFS_ONDISC_UJNL_INDEX_UPDATING]	= cachefs_replay_ujnl_index_modifying
 };
 
@@ -469,6 +469,7 @@
 {
 	struct cachefs_replay_find_batch_desc find_batch;
 	struct cachefs_ondisc_free_node *node;
+	struct cachefs_block *block;
 	struct file_ra_state ra;
 	loff_t ppos;
 	int loop, ret;
@@ -507,54 +508,65 @@
 	       find_batch.batch_end,
 	       find_batch.batch_ack);
 
-	if (find_batch.batch_end != ~0u && find_batch.batch_ack != ~0u)
-		goto reload_tracking;
+	if (find_batch.batch_end == ~0u || find_batch.batch_ack == ~0u) {
+		if (find_batch.batch_first == ~0u) {
+			clear_bit(CACHEFS_SUPER_REPLAYING_UJNL, &super->flags);
+			printk("CacheFS: corrupted journal:"
+			       " ujnl batch has no start entry\n");
+			return -EINVAL;
+		}
 
-	if (find_batch.batch_first == ~0u) {
-		clear_bit(CACHEFS_SUPER_REPLAYING_UJNL, &super->flags);
-		printk("CacheFS: corrupted journal:"
-		       " ujnl batch has no start entry\n");
-		return -EINVAL;
-	}
+		if (find_batch.batch_ack != ~0u) {
+			clear_bit(CACHEFS_SUPER_REPLAYING_UJNL, &super->flags);
+			printk("CacheFS: corrupted journal:"
+			       " ujnl batch has ACK but no end marker\n");
+			return -EINVAL;
+		}
 
-	if (find_batch.batch_ack != ~0u) {
-		clear_bit(CACHEFS_SUPER_REPLAYING_UJNL, &super->flags);
-		printk("CacheFS: corrupted journal:"
-		       " ujnl batch has ACK but no end marker\n");
-		return -EINVAL;
-	}
+		if (find_batch.batch_count != super->ujnl_serial) {
+			clear_bit(CACHEFS_SUPER_REPLAYING_UJNL, &super->flags);
+			printk("CacheFS: corrupted journal:"
+			       " ujnl batch has missing marks\n");
+			return -EINVAL;
+		}
 
-	if (find_batch.batch_count != super->ujnl_serial) {
-		clear_bit(CACHEFS_SUPER_REPLAYING_UJNL, &super->flags);
-		printk("CacheFS: corrupted journal:"
-		       " ujnl batch has missing marks\n");
-		return -EINVAL;
-	}
+		/* all checks bear out that we have a valid - though incomplete
+		 * - update journal batch */
+		printk("CacheFS: Need to replay update journal\n");
+
+		super->ujnl_tail = find_batch.batch_first;
+		super->ujnl_head = UJNL_WRAP(find_batch.batch_end - 1);
+
+		ret = cachefs_ujnl_replay_aux(
+			super, &ra, cachefs_ujnl_determine_overlap_actor);
+
+		if (ret == 0)
+			ret = cachefs_ujnl_replay_aux(
+				super, &ra, cachefs_ujnl_replay_actor);
+
+		while (!list_empty(&super->ujnl_replayq)) {
+			block = list_entry(super->ujnl_replayq.next,
+					   struct cachefs_block, batch_link);
+		
+			list_del_init(&block->batch_link);
+			block->ref = NULL;
+			cachefs_block_put(block);
+		}
 
-	/* all checks bear out that we have a valid - though incomplete -
-	 * update journal batch */
-	super->ujnl_tail = find_batch.batch_first;
-	super->ujnl_head = UJNL_WRAP(find_batch.batch_end - 1);
-
-	ret = cachefs_ujnl_replay_aux(super, &ra,
-				      cachefs_ujnl_determine_overlap_actor);
-	if (ret < 0) {
-		clear_bit(CACHEFS_SUPER_REPLAYING_UJNL, &super->flags);
-		return ret;
-	}
+		if (ret < 0) {
+			clear_bit(CACHEFS_SUPER_REPLAYING_UJNL, &super->flags);
+			printk("CacheFS: Failed to replay update journal\n");
+			return ret;
+		}
 
-	ret = cachefs_ujnl_replay_aux(super, &ra,
-				      cachefs_ujnl_replay_actor);
-	if (ret < 0) {
-		clear_bit(CACHEFS_SUPER_REPLAYING_UJNL, &super->flags);
-		return ret;
+		/* write all blocks that are marked for writeback */
+		cachefs_trans_batch_write(super);
+
+		printk("CacheFS: Finished replaying update journal\n");
 	}
 
-	/* write all blocks that are marked for writeback */
-	cachefs_trans_batch_write(super);
 	clear_bit(CACHEFS_SUPER_REPLAYING_UJNL, &super->flags);
 
- reload_tracking:
 	kdebug("reload_tracking");
 	super->ujnl_batch++;
 	super->ujnl_serial	= 0;
@@ -632,7 +644,7 @@
 	}
 
 
-	_leave(" = 0");
+	kleave(" = 0");
 	return 0;
 } /* end cachefs_ujnl_replay() */
 
@@ -676,7 +688,7 @@
 
 	/* we need to fix up the recycling block node header if the block is
 	 * currently part of one of the recycling chains */
-	if ((u_int16_t) (unsigned long) block->ref <= jentry->serial) {
+	if (BLOCK_VALID(block, jentry)) {
 		node = kmap(page);
 
 		if (node->next != jentry->auxblock) {
@@ -719,7 +731,7 @@
 		if (ret < 0)
 			goto error;
 
-		if ((u_int16_t) (unsigned long) block->ref <= jentry->serial) {
+		if (BLOCK_VALID(block, jentry)) {
 			node = kmap(page);
 
 			if (node->next || node->count) {
@@ -771,7 +783,7 @@
 		goto error2;
 	}
 
-	if ((u_int16_t) (unsigned long) block->ref <= jentry->serial) {
+	if (BLOCK_VALID(block, jentry)) {
 		node = kmap(page);
 
 		if (memcmp(&node->leaves[jentry->auxblock],
@@ -842,7 +854,7 @@
 	kunmap(spage);
 
 	/* we need to reload the pointers cached into the recycling block */
-	if ((u_int16_t) (unsigned long) block->ref <= jentry->serial) {
+	if (BLOCK_VALID(block, jentry)) {
 		node = kmap(page);
 
 		if (memcmp(&node->leaves[jentry->auxblock],
@@ -872,85 +884,358 @@
 
 /*****************************************************************************/
 /*
- * replay the creation of a new data inode
- * - since we don't know what index data was associated with it, all we can do
- *   is mark it for reclamation
+ * replay the creation of a new data or index inode
  */
 static int cachefs_replay_ujnl_inode_creating(struct cachefs_super *super,
 					      struct cachefs_ondisc_update_journal *jentry,
 					      struct cachefs_transaction *trans)
 {
-	return -ENOANO;
+	struct cachefs_ondisc_index_entry *xent;
+	struct cachefs_ondisc_ujnl_index *jindex;
+	struct cachefs_ondisc_metadata *metadata;
+	struct cachefs_block *metameta, *inometa, *indexmeta, *indexdata;
+	struct page *metapage, *inompage, *ixmpage, *ixdatapage;
+	u_int32_t type;
+	int ret;
+
+	kenter(",{%hd.%hu}", jentry->batch, jentry->serial);
+
+	jindex = &jentry->ixdata[0];
+
+	ret = cachefs_block_read(super, NULL, 1, 0, &metameta, &metapage);
+	if (ret < 0)
+		goto error;
+
+	ret = cachefs_block_read(super, NULL, jentry->auxblock, 0,
+				 &inometa, &inompage);
+	if (ret < 0)
+		goto error2;
+
+	ret = cachefs_block_read(super, NULL, jentry->upblock, 0,
+				 &indexmeta, &ixmpage);
+	if (ret < 0)
+		goto error3;
+
+	ret = cachefs_block_read(super, NULL, jentry->block, 0,
+				 &indexdata, &ixdatapage);
+	if (ret < 0)
+		goto error4;
+
+	type = CACHEFS_ONDISC_INDEX_DATAFILE;
+	if (jentry->mark == CACHEFS_ONDISC_UJNL_INDEX_CREATING)
+		type = CACHEFS_ONDISC_INDEX_INDEXFILE;
+
+	/* make sure the metadata file's freelink pointer is correct */
+	if (BLOCK_VALID(metameta, jentry)) {
+		metadata = kmap(metapage);
+		if (metadata->freelink != jindex->next_ino) {
+			metadata->freelink = jindex->next_ino;
+			cachefs_trans_replays_effect(trans, metameta);
+		}
+		kunmap(metapage);
+	}
+
+	/* make sure the index file's freelink pointer is correct */
+	if (BLOCK_VALID(indexmeta, jentry)) {
+		metadata = kmap(ixmpage);
+		if (metadata->freelink	!= jindex->next_index ||
+		    metadata->size	!= jentry->size) {
+			metadata->freelink	= jindex->next_index;
+			metadata->size		= jentry->size;
+			cachefs_trans_replays_effect(trans, indexmeta);
+		}
+		kunmap(ixmpage);
+	}
+
+	/* make sure the new inode's metadata contains the right data */
+	if (BLOCK_VALID(inometa, jentry)) {
+		metadata = kmap(inompage);
+		if (metadata->header.state != CACHEFS_ONDISC_INDEX_ACTIVE ||
+		    metadata->header.type  != type ||
+		    metadata->header.ino   != 0xfefdfc ||
+		    metadata->freelink     != UINT_MAX ||
+		    metadata->pindex       != jentry->index ||
+		    metadata->pindex_entry != jentry->ixentry ||
+		    memcmp(&metadata->index,
+			   &jindex->def,
+			   sizeof(metadata->index)) != 0
+		    ) {
+			metadata->header.state	= CACHEFS_ONDISC_INDEX_ACTIVE;
+			metadata->header.type	= type;
+			metadata->header.ino	= 0xfefdfc;
+			metadata->freelink	= UINT_MAX;
+			metadata->atime		= CURRENT_TIME.tv_sec;
+			metadata->pindex	= jentry->index;
+			metadata->pindex_entry	= jentry->ixentry;
+
+			memcpy(&metadata->index,
+			       &jindex->def,
+			       sizeof(metadata->index));
+
+			cachefs_trans_replays_effect(trans, inometa);
+		}
+		kunmap(inompage);
+	}
+
+	/* make sure the index data is written into the index entry */
+	if (BLOCK_VALID(indexdata, jentry)) {
+		xent = kmap(ixdatapage);
+		if (xent->state	!= CACHEFS_ONDISC_INDEX_ACTIVE	||
+		    xent->type	!= type				||
+		    xent->ino	!= jentry->ino			||
+		    memcmp(xent->data, jindex->data, jindex->def.dsize) != 0
+		    ) {
+			xent->state	= CACHEFS_ONDISC_INDEX_ACTIVE;
+			xent->type	= type;
+			xent->ino	= jentry->ino;
+
+			memcpy(xent->data, jindex->data, jindex->def.dsize);
+
+			cachefs_trans_replays_effect(trans, indexdata);
+		}
+		kunmap(ixdatapage);
+	}
+
+	cachefs_block_put(indexdata);
+	cachefs_put_page(ixdatapage);
+ error4:
+	cachefs_block_put(indexmeta);
+	cachefs_put_page(ixmpage);
+ error3:
+	cachefs_block_put(inometa);
+	cachefs_put_page(inompage);
+ error2:
+	cachefs_block_put(metameta);
+	cachefs_put_page(metapage);
+ error:
+	kleave(" = %d", ret);
+	return ret;
 } /* end cachefs_replay_ujnl_inode_creating() */
 
 /*****************************************************************************/
 /*
  * replay the updating of the information stored in an inode
- * - since we don't know what changes were to be made, we can't actually do
- *   anything, so we trust that the inode version number will suffice to cause
- *   an update upon accessing if need be
  */
 static int cachefs_replay_ujnl_inode_updating(struct cachefs_super *super,
 					      struct cachefs_ondisc_update_journal *jentry,
 					      struct cachefs_transaction *trans)
 {
-	return 0;
+	kenter(",{%hd.%hu}", jentry->batch, jentry->serial);
+
+	/* we don't do this yet */
+	return -EINVAL;
 } /* end cachefs_replay_ujnl_inode_updating() */
 
 /*****************************************************************************/
 /*
- * not yet supported
+ * replay the deletion of an inode and its associated index entry
  */
 static int cachefs_replay_ujnl_inode_deleting(struct cachefs_super *super,
 					      struct cachefs_ondisc_update_journal *jentry,
 					      struct cachefs_transaction *trans)
 {
-	return -EIO;
+	struct cachefs_ondisc_index_entry *xent;
+	struct cachefs_ondisc_ujnl_index *jindex;
+	struct cachefs_ondisc_metadata *metadata;
+	struct cachefs_block *metameta, *inometa;
+	struct cachefs_block *indexmeta = NULL, *indexdata = NULL;
+	struct page *metapage, *inompage, *ixmpage = NULL, *ixdatapage = NULL;
+	int ret;
+
+	kenter(",{%hd.%hu}", jentry->batch, jentry->serial);
+
+	jindex = &jentry->ixdata[0];
+
+	ret = cachefs_block_read(super, NULL, 1, 0, &metameta, &metapage);
+	if (ret < 0)
+		goto error;
+
+	ret = cachefs_block_read(super, NULL, jentry->auxblock, 0,
+				 &inometa, &inompage);
+	if (ret < 0)
+		goto error2;
+
+	if (jentry->index) {
+		ret = cachefs_block_read(super, NULL, jentry->upblock, 0,
+					 &indexmeta, &ixmpage);
+		if (ret < 0)
+			goto error3;
+
+		ret = cachefs_block_read(super, NULL, jentry->block, 0,
+					 &indexdata, &ixdatapage);
+		if (ret < 0)
+			goto error4;
+	}
+
+	/* make sure the metadata file's freelink pointer is correct */
+	if (BLOCK_VALID(metameta, jentry)) {
+		metadata = kmap(metapage);
+		if (metadata->freelink != jindex->next_ino) {
+			metadata->freelink = jindex->next_ino;
+			cachefs_trans_replays_effect(trans, metameta);
+		}
+		kunmap(metapage);
+	}
+
+	/* make sure the index file's freelink pointer is correct */
+	if (BLOCK_VALID(indexmeta, jentry)) {
+		metadata = kmap(ixmpage);
+		if (metadata->freelink	!= jindex->next_index ||
+		    metadata->size	!= jentry->size) {
+			metadata->freelink	= jindex->next_index;
+			metadata->size		= jentry->size;
+			cachefs_trans_replays_effect(trans, indexmeta);
+		}
+		kunmap(ixmpage);
+	}
+
+	/* make sure the deleted inode's metadata contains the right data */
+	if (BLOCK_VALID(inometa, jentry)) {
+		metadata = kmap(inompage);
+		if (metadata->header.state	!= CACHEFS_ONDISC_INDEX_FREE ||
+		    metadata->header.type	!= 0			||
+		    metadata->header.ino	!= 0xfefdfc		||
+		    metadata->freelink		!= jindex->next_ino	||
+		    metadata->pindex		!= 0			||
+		    metadata->pindex_entry	!= 0
+		    ) {
+			memset(metadata, 0, super->layout->metadata_size);
+
+			metadata->header.state	= CACHEFS_ONDISC_INDEX_FREE;
+			metadata->header.ino	= 0xfefdfc;
+			metadata->freelink	= jindex->next_ino;
+			metadata->atime		= CURRENT_TIME.tv_sec;
+			metadata->pindex	= 0;
+			metadata->pindex_entry	= 0;
+
+			cachefs_trans_replays_effect(trans, inometa);
+		}
+		kunmap(inompage);
+	}
+
+	/* make sure the index data is written into the index entry */
+	if (BLOCK_VALID(indexdata, jentry)) {
+		xent = kmap(ixdatapage);
+		if (xent->state	!= CACHEFS_ONDISC_INDEX_FREE	||
+		    xent->type	!= 0				||
+		    xent->ino	!= 0				||
+		    xent->freelink[0] != jindex->next_index
+		    ) {
+			xent->state	= CACHEFS_ONDISC_INDEX_FREE;
+			xent->type	= 0;
+			xent->ino	= 0;
+			xent->freelink[0] = jindex->next_index;
+
+			cachefs_trans_replays_effect(trans, indexdata);
+		}
+		kunmap(ixdatapage);
+	}
+
+	cachefs_block_put(indexdata);
+	cachefs_put_page(ixdatapage);
+ error4:
+	cachefs_block_put(indexmeta);
+	cachefs_put_page(ixmpage);
+ error3:
+	cachefs_block_put(inometa);
+	cachefs_put_page(inompage);
+ error2:
+	cachefs_block_put(metameta);
+	cachefs_put_page(metapage);
+ error:
+	kleave(" = %d", ret);
+	return ret;
 } /* end cachefs_replay_ujnl_inode_deleting() */
 
 /*****************************************************************************/
 /*
- * replay an inode being marked for reclamation
+ * replay the marking of an inode for reclamation
  */
 static int cachefs_replay_ujnl_inode_mark_reclaim(struct cachefs_super *super,
 						  struct cachefs_ondisc_update_journal *jentry,
 						  struct cachefs_transaction *trans)
 {
-	return -ENOANO;
+	struct cachefs_ondisc_index_entry *xent;
+	struct cachefs_ondisc_ujnl_index *jindex;
+	struct cachefs_ondisc_metadata *metadata;
+	struct cachefs_block *inometa, *indexdata;
+	struct page *inompage, *ixdatapage;
+	int ret;
+
+	kenter(",{%hd.%hu}", jentry->batch, jentry->serial);
+
+	jindex = &jentry->ixdata[0];
+
+	ret = cachefs_block_read(super, NULL, jentry->auxblock, 0,
+				 &inometa, &inompage);
+	if (ret < 0)
+		goto error;
+
+	ret = cachefs_block_read(super, NULL, jentry->block, 0,
+				 &indexdata, &ixdatapage);
+	if (ret < 0)
+		goto error2;
+
+	/* make sure the inode's metadata is set to the right state */
+	if (BLOCK_VALID(inometa, jentry)) {
+		metadata = kmap(inompage);
+		if (metadata->header.state != CACHEFS_ONDISC_INDEX_RECYCLE) {
+			metadata->header.state = CACHEFS_ONDISC_INDEX_FREE;
+
+			cachefs_trans_replays_effect(trans, inometa);
+		}
+		kunmap(inompage);
+	}
+
+	/* make sure the index entry is also set to the right state */
+	if (BLOCK_VALID(indexdata, jentry)) {
+		xent = kmap(ixdatapage);
+		if (xent->state	!= CACHEFS_ONDISC_INDEX_FREE) {
+			xent->state	= CACHEFS_ONDISC_INDEX_FREE;
+
+			cachefs_trans_replays_effect(trans, indexdata);
+		}
+		kunmap(ixdatapage);
+	}
+
+	cachefs_block_put(indexdata);
+	cachefs_put_page(ixdatapage);
+ error2:
+	cachefs_block_put(inometa);
+	cachefs_put_page(inompage);
+ error:
+	kleave(" = %d", ret);
+	return ret;
 } /* end cachefs_replay_ujnl_inode_mark_reclaim() */
 
 /*****************************************************************************/
 /*
- *
+ * replay the initiation of inode reclamation
  */
 static int cachefs_replay_ujnl_inode_reclaiming(struct cachefs_super *super,
 						struct cachefs_ondisc_update_journal *jentry,
 						struct cachefs_transaction *trans)
 {
-	return -ENOANO;
+	kenter(",{%hd.%hu}", jentry->batch, jentry->serial);
+
+	/* nothing needs to be done here - it's all handled implicitly by the
+	 * caller */
+	return 0;
+
 } /* end cachefs_replay_ujnl_inode_reclaiming() */
 
 /*****************************************************************************/
 /*
- *
+ * replay the extension of an index file
  */
 static int cachefs_replay_ujnl_index_extending(struct cachefs_super *super,
 					       struct cachefs_ondisc_update_journal *jentry,
 					       struct cachefs_transaction *trans)
 {
-	return -ENOANO;
-} /* end cachefs_replay_ujnl_index_extending() */
+	
 
-/*****************************************************************************/
-/*
- *
- */
-static int cachefs_replay_ujnl_index_creating(struct cachefs_super *super,
-					      struct cachefs_ondisc_update_journal *jentry,
-					      struct cachefs_transaction *trans)
-{
 	return -ENOANO;
-} /* end cachefs_replay_ujnl_index_creating() */
+} /* end cachefs_replay_ujnl_index_extending() */
 
 /*****************************************************************************/
 /*

Index: recycling.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/recycling.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- recycling.c	9 Jul 2003 10:39:50 -0000	1.25
+++ recycling.c	10 Jul 2003 14:21:24 -0000	1.26
@@ -481,6 +481,7 @@
 static int cachefs_recycle_reclaim_inode_metadata(struct cachefs_super *super)
 {
 	struct cachefs_ondisc_index_entry *xent;
+	struct cachefs_ondisc_ujnl_index *jindex;
 	struct cachefs_ondisc_metadata *metadata;
 	struct cachefs_transaction *trans = NULL;
 	struct cachefs_inode *iinode = NULL;
@@ -519,37 +520,44 @@
 	if (!trans)
 		goto error;
 
+	jindex = &trans->jentry->ixdata[0];
+	jindex->next_ino	= UINT_MAX;
+	jindex->next_index	= UINT_MAX;
+
 	trans->jentry->mark	= CACHEFS_ONDISC_UJNL_INODE_DELETING;
-	trans->jentry->index	= iino;
-	trans->jentry->ixentry	= ixentry;
 	trans->jentry->ino	= super->rcm_ino;
-	trans->jentry->entry	= offset;
-
-	if (ixpage) {
-		trans->jentry->pgnum = ixpage->index;
-		trans->jentry->block = __cachefs_get_page_block(ixpage)->bix;
-	}
 
 	if (iinode) {
-		trans->jentry->size  = iinode->vfs_inode.i_size;
-		trans->jentry->count = iinode->index_esize;
+		trans->jentry->index	= iino;
+		trans->jentry->ixentry	= ixentry;
+		trans->jentry->pgnum	= ixpage->index;
+		trans->jentry->block	=
+			__cachefs_get_page_block(ixpage)->bix;
+		trans->jentry->entry	= offset;
+		trans->jentry->upblock	= iinode->metadata->bix;
+		trans->jentry->upentry	= iinode->metadata_offset;
+		trans->jentry->size	= iinode->vfs_inode.i_size;
+		trans->jentry->count	= iinode->index_dsize;
 
 		metadata = cachefs_metadata_preread(iinode);
-		trans->jentry->upblock = metadata->freelink;
+		jindex->next_index = metadata->freelink;
 		cachefs_metadata_postread(iinode);
 
 		cachefs_trans_affects_page(trans,
 					   __cachefs_page_get_private(ixpage),
-					   offset,
-					   iinode->index_esize);
+					   trans->jentry->entry,
+					   trans->jentry->count);
 
 		cachefs_trans_affects_inode(trans, iinode);
 	}
 
 	metadata = cachefs_metadata_preread(super->imetadata);
-	trans->jentry->auxblock	= metadata->freelink;
+	jindex->next_ino = metadata->freelink;
 	cachefs_metadata_postread(super->imetadata);
 
+	trans->jentry->auxblock	= super->rcm_inode->metadata->bix;
+	trans->jentry->auxentry	= super->rcm_inode->metadata_offset;
+
 	cachefs_trans_affects_inode(trans, super->rcm_inode);
 	cachefs_trans_affects_inode(trans, super->imetadata);
 
@@ -563,14 +571,15 @@
 
 		xent = kmap(ixpage) + offset;
 		xent->state		= CACHEFS_ONDISC_INDEX_FREE;
+		xent->type		= 0;
 		xent->ino		= 0;
-		xent->freelink[0]	= trans->jentry->upblock;
+		xent->freelink[0]	= jindex->next_index;
 		memset(xent->data, 0, iinode->index_dsize);
 		kunmap(ixpage);
 
 		/* modify the index inode metadata entry */
 		metadata = cachefs_metadata_prewrite(iinode);
-		metadata->freelink	= ixentry;
+		metadata->freelink = ixentry;
 		cachefs_metadata_postwrite(iinode);
 	}
 
@@ -579,7 +588,7 @@
 	memset(metadata, 0, sizeof(super->imetadata->index_esize));
 
 	metadata->header.state	= CACHEFS_ONDISC_INDEX_FREE;
-	metadata->freelink	= trans->jentry->auxblock;
+	metadata->freelink	= jindex->next_ino;
 	metadata->mtime		= CURRENT_TIME.tv_sec;
 	metadata->atime		= CURRENT_TIME.tv_sec;
 	cachefs_metadata_postwrite(super->rcm_inode);
@@ -654,12 +663,12 @@
  again:
 	indirect++;
 
-	/* clear out then entries in an index */
+	/* iterate through an index clearing out the entries it contains */
 	if (indirect == 1) {
 		if (super->rcm_inode->index_dsize == 0)
 			goto again;
 
-		if (cachefs_index_zap(super) < 0)
+		if (cachefs_index_reclaim_one_entry(super) < 0)
 			goto error2;
 		goto again;
 	}
@@ -780,7 +789,7 @@
 		goto again;
 	}
  error2:
-	kleave(" [error %d]", ret);
+	kdebug("[error %d]", ret);
 	goto set;
 } /* end cachefs_recycle_reclaim_inode() */
 

Index: journal.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/journal.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- journal.c	9 Jul 2003 10:39:50 -0000	1.39
+++ journal.c	10 Jul 2003 14:21:24 -0000	1.40
@@ -104,6 +104,8 @@
 
 	_enter("");
 
+	BUG_ON(super->dmn_die > 0);
+
 	trans = kmalloc(sizeof(struct cachefs_transaction), gfp);
 	if (!trans) {
 		_leave(" = 0 [ENOMEM]");
@@ -277,6 +279,8 @@
 	 */
 	down_read(&super->batch_ctrl_sem);
 
+	BUG_ON(super->dmn_die > 0);
+
 	/* make sure any changes we make to memory don't end up on disc just
 	 * yet, either:
 	 * (1) wait for the page to be written back to disc, or:
@@ -1138,13 +1142,20 @@
 
 	_enter("");
 
-	/* see if any blocks are ready to be cleaned up */
+	/* see if any blocks are ready to be cleaned up
+	 * - note the checks made on the three queues must be done atomically
+	 *   or else list_move_tail() may cause a problem by having a node in
+	 *   transit
+	 */
  try_again:
+	spin_lock_irqsave(&super->batch_qlock, flags);
+
 	if (list_empty(&super->batch_writeq))
 		wait = 0;
 
 	if (list_empty(&super->batch_doneq) &&
 	    list_empty(&super->batch_errorq)) {
+		spin_unlock_irqrestore(&super->batch_qlock, flags);
 		if (!wait) {
 			_leave(" [nothing]");
 			return;
@@ -1161,6 +1172,8 @@
 
 		remove_wait_queue(&super->batch_done_wq, &myself);
 		set_current_state(TASK_RUNNING);
+
+		spin_lock_irqsave(&super->batch_qlock, flags);
 	}
 
 	if (wait == 1)
@@ -1168,8 +1181,6 @@
 
 	/* clean up as many blocks as we can */
 	error = 0;
-
-	spin_lock_irqsave(&super->batch_qlock, flags);
 
 	if (!list_empty(&super->batch_errorq)) {
 		list_splice_init(&super->batch_errorq, &myblocks);

Index: interface.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/interface.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- interface.c	9 Jul 2003 10:39:50 -0000	1.15
+++ interface.c	10 Jul 2003 14:21:24 -0000	1.16
@@ -211,7 +211,11 @@
 	}
 	spin_unlock(&super->ino_list_lock);
 
-	/* mark all active blocks a being withdrawn */
+	/* make sure all pages pinned by operations on behalf of the netfs are
+	 * written to disc */
+	cachefs_trans_sync(super, CACHEFS_TRANS_SYNC_WAIT_FOR_ACK);
+
+	/* mark all active blocks as being withdrawn */
 	cachefs_block_withdraw(super);
 
 	/* we now have to destroy all the active inodes pertaining to this
@@ -648,7 +652,6 @@
 				return;
 			}
 		}
-		
 	}
 
 	/* if no parent cookie, then don't create one here either */
@@ -1278,7 +1281,10 @@
 		pageio->flags = 0;
 		write_unlock(&pageio->lock);
 
-		BUG_ON(block->ref != pageio);
+		if (unlikely(block->ref != pageio)) {
+			printk("%p != %p", block->ref, pageio);
+			BUG();
+		}
 
 		/* locking order needs to be reversed */
 		write_lock(&block->ref_lock);

Index: index.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/index.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- index.c	9 Jul 2003 10:39:50 -0000	1.26
+++ index.c	10 Jul 2003 14:21:24 -0000	1.27
@@ -58,6 +58,8 @@
 
 	_enter(",{%lx},%u,%u,%u", ixpage->index, ixentry, ixoffset, ino);
 
+	kdebug("SEARCH/DELETE %u", ino);
+
 	super = ixpage->mapping->host->i_sb->s_fs_info;
 
 	ret = cachefs_iget(super, ino, &inode);
@@ -66,6 +68,8 @@
 		return;
 	}
 
+	BUG_ON(!list_empty(&inode->cookie_link));
+
 	ret = -ENOMEM;
 	trans = cachefs_trans_alloc(super, GFP_KERNEL);
 	if (!trans)
@@ -76,10 +80,10 @@
 	trans->jentry->index	= rec->iinode->vfs_inode.i_ino;
 	trans->jentry->ixentry	= ixentry;
 	trans->jentry->pgnum	= ixpage->index;
-	trans->jentry->block	= inode->metadata->bix;
-	trans->jentry->entry	= inode->metadata_offset;
-	trans->jentry->upblock	= __cachefs_get_page_block(ixpage)->bix;
-	trans->jentry->upentry	= ixoffset;
+	trans->jentry->block	= __cachefs_get_page_block(ixpage)->bix;
+	trans->jentry->entry	= ixoffset;
+	trans->jentry->auxblock	= inode->metadata->bix;
+	trans->jentry->auxentry	= inode->metadata_offset;
 
 	cachefs_trans_affects_page(trans, __cachefs_page_get_private(ixpage),
 				   ixoffset, sizeof(*xent));
@@ -535,8 +539,8 @@
 		      struct cachefs_cookie *cookie,
 		      unsigned *_newino)
 {
-	struct cachefs_ondisc_ujnl_index *jindex;
 	struct cachefs_ondisc_index_entry *xent;
+	struct cachefs_ondisc_ujnl_index *jindex;
 	struct cachefs_ondisc_metadata *metadata;
 	struct cachefs_search_result *srch;
 	struct cachefs_transaction *trans;
@@ -578,6 +582,9 @@
 
 	offset = (ixentry % index->index_epp) * index->index_esize;
 
+	ino_offset = ino % super->imetadata->index_epp;
+	ino_offset <<= super->layout->metadata_bits;
+
 	trans->jentry->mark = CACHEFS_ONDISC_UJNL_INDEX_CREATING;
 	if (!cookie->idef)
 		trans->jentry->mark = CACHEFS_ONDISC_UJNL_INODE_CREATING;
@@ -590,11 +597,13 @@
 	trans->jentry->block	= __cachefs_get_page_block(ixpage)->bix;
 	trans->jentry->entry	= offset;
 	trans->jentry->count	= index->index_esize;
-	trans->jentry->auxblock	= inonext;
-	trans->jentry->upblock	= ixnext;
+	trans->jentry->auxblock	= __cachefs_get_page_block(inopage)->bix;
+	trans->jentry->auxentry	= ino_offset;
+	trans->jentry->upblock	= index->metadata->bix;
+	trans->jentry->upentry	= index->metadata_offset;
 
-	ino_offset = ino % super->imetadata->index_epp;
-	ino_offset <<= super->layout->metadata_bits;
+	jindex->next_ino	= inonext;
+	jindex->next_index	= ixnext;
 
 	cachefs_trans_affects_page(trans, __cachefs_page_get_private(ixpage),
 				   offset, index->index_esize);
@@ -646,7 +655,7 @@
 	if (cookie->idef)
 		xent->type = CACHEFS_ONDISC_INDEX_INDEXFILE;
 
-	memcpy(xent->data, jindex->data, jindex->def.dsize);
+	memcpy(xent->data, jindex->data, index->index_dsize);
 
 	kunmap(ixpage);
 
@@ -707,7 +716,7 @@
  * mark the next inode pinned by an entry in the index currently being
  * reclaimed as being obsolete
  */
-int cachefs_index_zap(struct cachefs_super *super)
+int cachefs_index_reclaim_one_entry(struct cachefs_super *super)
 {
 	struct cachefs_ondisc_index_entry *xent;
 	struct cachefs_ondisc_metadata *metadata;
@@ -760,6 +769,11 @@
 	trans->jentry->ino	= inode->vfs_inode.i_ino;
 	trans->jentry->index	= super->rcm_ino;
 	trans->jentry->ixentry	= super->rcm_block;
+	trans->jentry->pgnum	= page->index;
+	trans->jentry->block	= __cachefs_get_page_block(page)->bix;
+	trans->jentry->entry	= offset;
+	trans->jentry->auxblock	= inode->metadata->bix;
+	trans->jentry->auxentry	= inode->metadata_offset;
 
 	cachefs_trans_affects_inode(trans, inode);
 
@@ -807,4 +821,4 @@
 
 	_leave(" = %d", ret);
 	return ret;
-} /* end cachefs_index_zap() */
+} /* end cachefs_index_reclaim_one_entry() */

Index: dump-journal.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/dump-journal.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- dump-journal.c	9 Jul 2003 10:39:50 -0000	1.13
+++ dump-journal.c	10 Jul 2003 14:21:24 -0000	1.14
@@ -169,7 +169,7 @@
 		       " " CYAN		"%5u"	GREY	"."	NORMAL	"%-5u"	NORMAL
 		       " "		"%s"		" %4d"
 		       " " YELLOW	"%8x"	NORMAL	" %8u"
-		       " " YELLOW	"%8u"	GREY	":"	NORMAL	"%-4hu"
+		       " " YELLOW	"%8x"	GREY	":"	NORMAL	"%-4hu"
 		       " " YELLOW	"%8d"	GREY	"+"	NORMAL	"%-4hu"
 		       " " YELLOW	"%8d"	GREY	"+"	NORMAL	"%-4hu"
 		       " " YELLOW	"%8d"	GREY	"+"	NORMAL	"%-4hu"

Index: cachefs-layout.h
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/cachefs-layout.h,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- cachefs-layout.h	9 Jul 2003 10:39:50 -0000	1.29
+++ cachefs-layout.h	10 Jul 2003 14:21:24 -0000	1.30
@@ -248,19 +248,46 @@
 	 * - block	= block holding index entry being allocated
 	 * - entry	= offset of entry in block
 	 * - ino	= inode being attached to hold index contents
-	 * - upblock	= next free index file entry
-	 * - count	= size of entry in block
+	 * - auxblock	= metadata file block holding inode metadata
+	 * - auxentry	= offset of entry in auxblock
+	 * - upblock	= metadata file block holding index metadata
+	 * - upentry	= offset of entry in upblock
+	 * - count	= size of index entry in block
+	 * - ixdata	= index data
+	 * - next_ino	= next free metadata file entry
+	 * - next_index	= next free index file entry
 	 */
 	CACHEFS_ONDISC_UJNL_INODE_CREATING,
 
 	/* data file being updated */
 	CACHEFS_ONDISC_UJNL_INODE_UPDATING,
 
-	/* data or index file being deleted */
+	/* data or index file being deleted
+	 * - index	= parent index being attached to [opt]
+	 * - ixentry	= entry in parent index [opt]
+	 * - pgnum	= page in file holding index entry being allocated [opt]
+	 * - block	= block holding index entry being allocated [opt]
+	 * - entry	= offset of entry in block [opt]
+	 * - ino	= inode being attached to hold index contents
+	 * - auxblock	= metadata file block holding inode metadata
+	 * - auxentry	= offset of entry in auxblock
+	 * - upblock	= metadata file block holding index metadata [opt]
+	 * - upentry	= offset of entry in upblock [opt]
+	 * - count	= size of index entry in block [opt]
+	 * - next_ino	= next free metadata file entry
+	 * - next_index	= next free index file entry [opt]
+	 */
 	CACHEFS_ONDISC_UJNL_INODE_DELETING,
 
 	/* inode being marked for reclamation
 	 * - ino	= target inode
+	 * - index	= inode's parent index
+	 * - ixentry	= inode's parent index entry
+	 * - pgnum	= page in index holding entry being marked
+	 * - block	= metadata file block holding index metadata
+	 * - entry	= offset of entry in upblock
+	 * - auxblock	= metadata file block holding inode metadata
+	 * - auxentry	= offset of entry in auxblock
 	 */
 	CACHEFS_ONDISC_UJNL_INODE_MARK_RECLAIM,
 
@@ -268,6 +295,11 @@
 	 * - ino	= target inode
 	 * - index	= inode's parent index
 	 * - ixentry	= inode's parent index entry
+	 * - pgnum	= page in index holding entry being marked
+	 * - block	= metadata file block holding index metadata
+	 * - entry	= offset of entry in upblock
+	 * - auxblock	= metadata file block holding inode metadata
+	 * - auxentry	= offset of entry in auxblock
 	 */
 	CACHEFS_ONDISC_UJNL_INODE_RECLAIMING,
 
@@ -337,8 +369,14 @@
 	 * - block	= block holding index entry being allocated
 	 * - entry	= offset of entry in block
 	 * - ino	= inode being attached to hold index contents
-	 * - upblock	= next free index file entry
-	 * - count	= size of entry in block
+	 * - auxblock	= metadata file block holding inode metadata
+	 * - auxentry	= offset of entry in auxblock
+	 * - upblock	= metadata file block holding index metadata
+	 * - upentry	= offset of entry in upblock
+	 * - count	= size of index entry in block
+	 * - ixdata	= index definition and data
+	 * - next_ino	= next free metadata file entry
+	 * - next_index	= next free index file entry
 	 */
 	CACHEFS_ONDISC_UJNL_INDEX_CREATING,
 
@@ -349,6 +387,7 @@
 	 * - block	= block holding index entry being allocated
 	 * - entry	= offset of entry in block
 	 * - count	= size of entry in block
+	 * - ixdata	= revised index data
 	 */
 	CACHEFS_ONDISC_UJNL_INDEX_UPDATING,
 
@@ -357,6 +396,8 @@
 
 struct cachefs_ondisc_ujnl_index {
 	struct cachefs_ondisc_index_def	def;
+	u_int32_t			next_ino;	/* next inode entry */
+	u_int32_t			next_index;	/* next index entry */
 	u_int8_t			data[0];
 };
 

Index: cachefs-int.h
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/cachefs-int.h,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- cachefs-int.h	9 Jul 2003 10:39:50 -0000	1.38
+++ cachefs-int.h	10 Jul 2003 14:21:24 -0000	1.39
@@ -451,7 +451,7 @@
 			     struct cachefs_cookie *cookie,
 			     unsigned *_newino);
 
-extern int cachefs_index_zap(struct cachefs_super *super);
+extern int cachefs_index_reclaim_one_entry(struct cachefs_super *super);
 
 /*****************************************************************************/
 /*

Index: block.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/block.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- block.c	4 Jul 2003 09:04:44 -0000	1.8
+++ block.c	10 Jul 2003 14:21:24 -0000	1.9
@@ -435,6 +435,8 @@
 
 	*_block = NULL;
 
+	BUG_ON(bix > super->sb->s_bdev->bd_inode->i_size / PAGE_SIZE);
+
 	/* allocate a block record just in case */
 	newblock = kmem_cache_alloc(cachefs_block_jar, SLAB_KERNEL);
 	if (!newblock)


From dwh at infradead.org  Tue Jul 15 15:51:20 2003
From: dwh at infradead.org (dwh@infradead.org)
Date: Tue Jul 15 14:51:17 2003
Subject: afs/Documentation/filesystems cachefs.txt,1.1,1.2
Message-ID: <E19cQDA-0000mA-00@phoenix.infradead.org>

Update of /home/cvs/afs/Documentation/filesystems
In directory phoenix.infradead.org:/tmp/cvs-serv2936/Documentation/filesystems

Modified Files:
	cachefs.txt 
Log Message:
documentation update


Index: cachefs.txt
===================================================================
RCS file: /home/cvs/afs/Documentation/filesystems/cachefs.txt,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- cachefs.txt	30 Jan 2003 11:30:38 -0000	1.1
+++ cachefs.txt	15 Jul 2003 13:51:17 -0000	1.2
@@ -1,22 +1,88 @@
-			 ===========================
-			 CacheFS: Caching Filesystem
-			 ===========================
+			  ===========================
+			  CacheFS: Caching Filesystem
+			  ===========================
 
 ========
 OVERVIEW
 ========
 
+CacheFS is a general purpose cache for network filesystems, though it could be
+used for caching other things such as ISO9660 filesystems too.
+
+CacheFS uses a block device directly rather than a directory under a
+filesystem. This means it can perform its own journalling more efficiently, and
+is not beholden to the underlying filesystem. If necessary, however, a file can
+be loopback mounted as a cache.
+
+CacheFS does not follow the idea of completely loading every netfs file opened
+into the cache before it can be operated upon, and then serving the pages out
+of the cachefs rather than the netfs because:
+
+ (1) It must be practical to operate without a cache.
+
+ (2) The size of any accessible file must not be limited to the size of the
+     cache.
+
+ (3) The combined size of all opened files (this includes mapped libraries)
+     must not be limited to the size of the cache.
+
+ (4) The user should not be forced to download an entire file just to do a
+     one-off access of a small portion of it.
+
+It rather serves the cache out in PAGE_SIZE chunks as and when requested by
+the netfs('s) using it.
+
+
+CacheFS provides the following facilities:
+
+ (1) More than one block device can be mounted as a cache.
+
+ (2) Caches can be mounted / unmounted at any time.
+
+ (3) The netfs is provided with an interface that allows either party to
+     withdraw caching facilities from a file (required for (2)).
+
+ (4) The interface to the netfs returns as few errors as possible, preferring
+     rather to let the netfs remain oblivious where possible.
+
+ (5) Cookies are used to represent files and indexes to the netfs. The simplest
+     cookie is just a NULL pointer - indicating nothing cached there.
+
+ (6) The netfs is allowed to propose - dynamically - any index hierarchy it
+     desires, though it must be aware that the index search function is
+     recursive and stack space is limited.
+
+ (7) Data I/O is done direct to and from the netfs's pages. The netfs indicates
+     that page A is at index B of the data-file represented by cookie C, and
+     that it should be read or written. CacheFS may or may not start I/O on
+     that page, but if it does, a netfs callback will be invoked to indicate
+     completion.
+
+ (8) Cookies can be "retired" upon release. At this point CacheFS will mark
+     them as obsolete and the index hierarchy rooted at that point will get
+     recycled.
+
+ (9) The netfs provides a "match" function for index searches. In addition to
+     saying whether a match was made or not, this can also specify that an
+     entry should be updated or deleted.
+
+(10) All metadata modifications (this includes index contents) are performed
+     as journalled transactions. These are replayed on mounting.
+
+
+======================
+GENERAL ON-DISC LAYOUT
+======================
+
 The filesystem is divided into a number of parts:
 
   0	+---------------------------+
 	|        Superblock         |
   1	+---------------------------+
-	|   Full-BA-Bitmap Bitmap   |  <-- also referred to as the "Fullmap"
-	+---------------------------+
-	|  Block Allocation Bitmap  |
-	+---------------------------+
 	|      Update Journal       |
 	+---------------------------+
+	|     Validity Journal      |
+	+---------------------------+
 	|    Write-Back Journal     |
 	+---------------------------+
 	|                           |
@@ -27,19 +93,22 @@
 The superblock contains the filesystem ID tags and pointers to all the other
 regions.
 
-There's a block allocation bitmap that has bits set according to which blocks
-in the data region are currently in use. There's also another bitmap which has
-a bit set for every block in the block allocation bitmap that's entirely
-full. This is to make allocating a block faster.
-
 The update journal consists of a set of entries of sector size that keep track
 of what changes have been made to the on-disc filesystem, but not yet
 committed.
 
+The validity journal contains records of data blocks that have been allocated
+but not yet written. Upon journal replay, all these blocks will be detached
+from their pointers and recycled.
+
 The writeback journal keeps track of changes that have been made locally to
-data blocks, but that have not yet been committed back to the server.
+data blocks, but that have not yet been committed back to the server. This is
+not yet implemented.
+
+The journals are replayed upon mounting to make sure that the cache is in a
+reasonable state.
 
-The data region holds three things:
+The data region holds a number of things:
 
   (1) Index Files
 
@@ -47,15 +116,20 @@
       that wish to cache data here (such as AFS) to keep track of what's in
       the cache at any given time.
 
-      The first index file (inode 1) is special. It has an entry (the storage
-      management record) for each file in the cache.
+      The first index file (inode 1) is special. It holds the cachefs-specific
+      metadata for every file in the cache (including direct, single-indirect
+      and double-indirect block pointers).
 
       The second index file (inode 2) is also special. It has an entry for
       each filesystem that's currently holding data in this cache.
 
+      Every allocated entry in an index has an inode bound to it. This inode is
+      either another index file or it is a data file.
+
   (2) Cached Data Files
 
-      These are caches of files from remote servers.
+      These are caches of files from remote servers. Holes in these files
+      represent blocks not yet obtained from the server.
 
   (3) Indirection Blocks
 
@@ -67,113 +141,603 @@
 
 	- single indirection
 	- double indirection
-	- triple indirection
-	
+
+ (4) Allocation Nodes and Free Blocks
+
+     The free blocks of the filesystem are kept in two single-branched
+     "trees". One tree is the blocks that are ready to be allocated, and the
+     other is the blocks that have just been recycled. When the former tree
+     becomes empty, the latter tree is decanted across.
+
+     Each tree is arranged as a chain of "nodes", each node points to the next
+     node in the chain (unless it's at the end) and also up to 1022 free
+     blocks.
+
+Note that all blocks are PAGE_SIZE in size. The blocks are numbered starting
+with the superblock at 0. Using 32-bit block pointers, a maximum number of
+0xffffffff blocks can be accessed, meaning that the maximum cache size is ~16Tb
+for 4Kb pages.
+
 
 ========
 MOUNTING
 ========
 
-Since CacheFS is actually a filesystem, the way you give it a device to cache
-is to mount it as cachefs type on a directory somewhere. The mounted
-filesystem will then present the user with a set of directories (one per
-cached network fs), each of which will contain a set of files that grant read
-access to the indexes contained within.
+Since CacheFS is actually a quasi-filesystem, it requires a block device behind
+it. The way to give it one is to mount it as cachefs type on a directory
+somewhere. The mounted filesystem will then present the user with a set of
+directories outlining the index structure resident in the cache. Indexes
+(directories) and files can be turfed out of the cache by the sysadmin through
+the use of rmdir and unlink.
 
 For instance, if a cache contains AFS data, the user might see the following:
 
-	root>mount -tcachefs /dev/hdg5 /cache-hdg5/
-	root>ls -1 /cache-hdg5
+	root>mount -t cachefs /dev/hdg9 /cache-hdg9
+	root>ls -1 /cache-hdg9
 	afs
-	root>ls -1 /cache-hdg5/afs
-	cells
-	vldb
-	files0
-	files1
-	files2
-	...
-	files127
-
-
-==========================
-PHYSICAL ACCESS MANAGEMENT
-==========================
-
-All blocks are PAGE_SIZE in size. The blocks are numbered starting with the
-superblock at 0. Using 32-bit block pointers, a maximum number of 0xffffffff
-blocks can be accessed, meaning that the maximum cache size is ~16Tb for 4Kb
-pages.
-
-The journals, however, are managed in smaller chunks. These reflect the
-underlying atomic sector size of the backing device, and will typically be
-512b (so there will be 8 journal entried per page).
-
-Absent blocks in cached data files do not imply a block of zeros, rather they
-indicate a block that has yet to be fetched from the server.
-
-Since VM pages full of cached data actually belong to whichever network
-filesystem is presenting them to the user, they can't also belong to
-CacheFS. To get around this problem, CacheFS lets the network filesystem tell
-it when to read or write data.
-
-
-==============
-FILESYSTEM API
-==============
-
-There is an API provided by CacheFS that grants network filesystems access to
-any cached data. Each network filesystem declares to CacheFS what indexes it
-requires in a cache, and how many files to allocate per index. For instance,
-AFS would declare:
-
-	INDEX	QTY	CONTENTS
-	=======	=======	=====================================
-	cells	1	Cached cell information
-	vldb	1	Cached volume location information
-	files	128	Cached file information (hash table)
-
-Each index definition must also be provided with the following operations:
-
- - a hashing function (should QTY be more than 1)
- - a function to say whether an entry is in use
- - a key comparison function (for searching)
- - an entry update function
- - an entry clear function
- - an access time update function
-
-Index entries can be of any size from 4b up to PAGE_SIZE. Each page is divided
-into as many entries as possible, and the free space at the end is
-ignored. This makes management easier as no entry will be split across pages.
-
-When the network filesystem wants to cache a file, it asks CacheFS for a
-handle. CacheFS walks through the indexes looking for the file (it may already
-be in there) and fills in the handle if it's found. If it wasn't found, then
-CacheFS will allocate new entries in any indexes that the appropriate ones
-don't exist, and fill the handle in with this information.
-
-Multiple caches are searched in order until one returns a match. Matches in
-other caches are ignored, and will eventually be discarded.
-
-When a network filesystem allocates a page from a file, it asks CacheFS to try
-and make an association with a block in the cache. If the association already
-exists on disc, CacheFS loads the data into the page, and the page is ready
-for use. If not, CacheFS reserves a block in the cache into which the contents
-of that page will be written when the network fs has downloaded it from the
-server.
-
-If the page is changed, then the VM will eventually ask the network to write
-the page back to storage. At this point, the network filesystem will ask
-CacheFS to write the page to disc into the block reserved for it.
-
-Additionally, when a page is written back, CacheFS writes an entry back into
-the writeback journal. When the network fs has finished uploading the page to
-the server, it should tell CacheFS so that the writeback journal can be
-further marked to show operation completion.
-
-When a network fs first associates with a cache, CacheFS tells it about all
-the blocks with oustanding writebacks journalled. The network fs can then
-either send them to the server again, or tell CacheFS to discard the pages.
-
-A network filesystem can also ask CacheFS to either delete or invalidate a
-file, thus discarding all the data attached, and either discarding or updating
-the metadata too.
+	root>ls -1 /cache-hdg9/afs
+	cambridge.redhat.com
+	root>ls -1 /cache-hdg9/afs/cambridge.redhat.com
+	root.afs
+	root.cell
+
+However, a block device that's going to be used for a cache must be prepared
+before it can be mounted initially. This is done very simply by:
+
+	echo "cachefs___" >/dev/hdg9
+
+During the initial mount, the basic structure will be scribed into the cache,
+and then a background thread will "recycle" the as-yet unused data blocks.
+
+
+======================
+NETWORK FILESYSTEM API
+======================
+
+There is, of course, an API by which a network filesystem can make use of the
+CacheFS facilities. This is based around a number of principles:
+
+ (1) Every file and index is represented by a cookie. This cookie may or may
+     not have anything associated with it, but the netfs doesn't need to care.
+
+ (2) Barring the top-level index (one entry per cached netfs), the index
+     hierarchy for each netfs is structured according the whim of the netfs.
+
+ (3) Any netfs page being backed by the cache must have a small token
+     associated with it (possibly pointed to by page->private) so that CacheFS
+     can keep track of it.
+
+This API is declared in <linux/cachefs.h>.
+
+
+NETWORK FILESYSTEM DEFINITION
+-----------------------------
+
+CacheFS needs a description of the network filesystem. This is specified using
+a record of the following structure:
+
+	struct cachefs_netfs {
+		const char			*name;
+		unsigned			version;
+		struct cachefs_netfs_operations	*ops;
+		struct cachefs_cookie		*primary_index;
+		...
+	};
+
+This first three fields should be filled in before registration, and the fourth
+will be filled in by the registration function; any other fields should just be
+ignored and are for internal use only.
+
+The fields are:
+
+ (1) The name of the netfs (used as the key in the toplevel index).
+
+ (2) The version of the netfs (if the name matches but the version doesn't, the
+     entire on-disc hierarchy for this netfs will be scrapped and begun
+     afresh).
+
+ (3) The operations table is defined as follows:
+
+	struct cachefs_netfs_operations {
+		int (*get_page_cookie)(struct page *page,
+				       struct cachefs_page **_page_cookie);
+	};
+
+     The functions here must all be present. Currently the only one is:
+
+     (a) get_page_cookie(): Get the token used to bind a page to a block in a
+         cache. This function should allocate it if it doesn't exist.
+
+	 Return -ENOMEM if there's not enough memory and -ENODATA if the page
+	 just shouldn't be cached.
+
+	 Set *_page_cookie to point to the token and return 0 if there is now a
+	 cookie. Note that the netfs must keep track of the cookie itself (and
+	 free it later). page->private can be used for this (see below).
+
+ (4) The cookie representing the primary index will be allocated according to
+     another parameter passed into the registration function.
+
+For example, kAFS (linux/fs/afs/) uses the following definitions to describe
+itself:
+
+	static struct cachefs_netfs_operations afs_cache_ops = {
+		.get_page_cookie	= afs_cache_get_page_cookie,
+	};
+
+	struct cachefs_netfs afs_cache_netfs = {
+		.name			= "afs",
+		.version		= 0,
+		.ops			= &afs_cache_ops,
+	};
+
+
+INDEX DEFINITION
+----------------
+
+Indexes are used for two purposes:
+
+ (1) To speed up the finding of a file based on a series of keys (such as AFS's
+     "cell", "volume ID", "vnode ID").
+
+ (2) To make it easier to discard a subset of all the files cached based around
+     a particular key - for instance to mirror the removal of an AFS volume.
+
+However, since it's unlikely that any two netfs's are going to want to define
+their index hierarchies in quite the same way, CacheFS tries to impose as few
+restraints as possible on how an index is structured and where it is placed in
+the tree. The netfs can even mix indexes and data files at the same level, but
+it's not recommended.
+
+There are some limits on indexes:
+
+ (1) All entries in any given index must be the same size. An array of such
+     entries needn't fit exactly into a page, but they will be not laid across
+     a page boundary.
+
+     The netfs supplies a blob of data for each index entry, and CacheFS
+     provides an inode number and a flag.
+
+ (2) The entries in one index can be of a different size to the entries in
+     another index.
+
+ (3) The entry data must be journallable, and thus must be able to fit into an
+     update journal entry - this limits the maximum size to a little over 400
+     bytes at present.
+
+ (4) The data should start with the key. The layout of the key is described in
+     the index definition, and this is used to display the key in some
+     appropriate way.
+
+ (5) The depth of the index tree should be judged with care as the search
+     function is recursive. Too many layers will run the kernel out of stack.
+
+To define an index, a structure of the following type should be filled out:
+
+	struct cachefs_index_def
+	{
+		u_int8_t name[8];
+		u_int16_t data_size;
+		struct {
+			u_int8_t type;
+			u_int16_t len;
+		} keys[4];
+
+		cachefs_match_val_t (*match)(void *target_netfs_data,
+					     const void *entry);
+
+		void (*update)(void *source_netfs_data, void *entry);
+	};
+
+This has the following fields:
+
+ (1) The name of the index (NUL terminated unless all 8 chars are used).
+
+ (2) The size of the data blob provided by the netfs.
+
+ (3) A definition of the key(s) at the beginning of the blob. The netfs is
+     permitted to specify up to four keys. The total length must not exceed the
+     data size. It is assumed that the keys will be laid end to end in order,
+     starting with the first byte of the data.
+
+     The type field specifies the way the data should be displayed. It can be
+     one of:
+
+	(*) CACHEFS_INDEX_KEYS_NOTUSED - key field not used
+	(*) CACHEFS_INDEX_KEYS_BIN - display byte-by-byte in hex
+	(*) CACHEFS_INDEX_KEYS_ASCIIZ - NUL-terminated ASCII
+	(*) CACHEFS_INDEX_KEYS_IPV4ADDR - display as IPv4 address
+	(*) CACHEFS_INDEX_KEYS_IPV6ADDR - display as IPv6 address
+
+ (4) A function to match an in-page-cache index entry blob to netfs data passed
+     to the cookie acquisition function by the netfs. This function can also be
+     used to extract data from the blob and copy it into the netfs's
+     structures.
+
+     The return values this function can make are:
+
+	(*) CACHEFS_MATCH_FAILED - failed to match
+	(*) CACHEFS_MATCH_SUCCESS - successful match
+	(*) CACHEFS_MATCH_SUCCESS_UPDATE - successful match, entry needs update
+	(*) CACHEFS_MATCH_SUCCESS_DELETE - entry should be deleted
+
+     For example, in linux/fs/afs/vnode.c:
+
+	static cachefs_match_val_t
+	afs_vnode_cache_match(void *target, const void *entry)
+	{
+		const struct afs_cache_vnode *cvnode = entry;
+		struct afs_vnode *vnode = target;
+
+		if (vnode->fid.vnode != cvnode->vnode_id)
+			return CACHEFS_MATCH_FAILED;
+
+		if (vnode->fid.unique != cvnode->vnode_unique ||
+		    vnode->status.version != cvnode->data_version)
+			return CACHEFS_MATCH_SUCCESS_DELETE;
+
+		return CACHEFS_MATCH_SUCCESS;
+	}
+
+ (5) A function to initialise or update an in-page-cache index entry blob from
+     netfs data passed to CacheFS by the netfs. This function should not assume
+     that there's any data yet in the in-page-cache.
+
+     Continuing the above example:
+
+	static void afs_vnode_cache_update(void *source, void *entry)
+	{
+		struct afs_cache_vnode *cvnode = entry;
+		struct afs_vnode *vnode = source;
+
+		cvnode->vnode_id	= vnode->fid.vnode;
+		cvnode->vnode_unique	= vnode->fid.unique;
+		cvnode->data_version	= vnode->status.version;
+	}
+
+To finish the above example, the index definition for the "vnode" level is as
+follows:
+
+	struct cachefs_index_def afs_vnode_cache_index_def = {
+		.name		= "vnode",
+		.data_size	= sizeof(struct afs_cache_vnode),
+		.keys[0]	= { CACHEFS_INDEX_KEYS_BIN, 4 },
+		.match		= afs_vnode_cache_match,
+		.update		= afs_vnode_cache_update,
+	};
+
+The first element of struct afs_cache_vnode is the vnode ID.
+
+And for contrast, the cell index definition is:
+
+	struct cachefs_index_def afs_cache_cell_index_def = {
+		.name			= "cell_ix",
+		.data_size		= sizeof(afs_cell_t),
+		.keys[0]		= { CACHEFS_INDEX_KEYS_ASCIIZ, 64 },
+		.match			= afs_cell_cache_match,
+		.update			= afs_cell_cache_update,
+	};
+
+The cell index is the primary index for kAFS.
+
+
+NETWORK FILESYSTEM (UN)REGISTRATION
+-----------------------------------
+
+The first step is to declare the network filesystem to the cache. This also
+involves specifying the layout of the primary index (for AFS, this would be the
+"cell" level).
+
+The registration function is:
+
+	int cachefs_register_netfs(struct cachefs_netfs *netfs,
+				   struct cachefs_index_def *primary_idef);
+
+It just takes pointers to the netfs definition and the primary index
+definition. It returns 0 or an error as appropriate.
+
+For kAFS, registration is done as follows:
+
+	ret = cachefs_register_netfs(&afs_cache_netfs,
+				     &afs_cache_cell_index_def);
+
+The last step is, of course, unregistration:
+
+	void cachefs_unregister_netfs(struct cachefs_netfs *netfs);
+
+
+INDEX REGISTRATION
+------------------
+
+The second step is to get cookies to represent the other indexes that are
+required to find files. This involves requesting that a new index entry be made
+in some already existing index:
+
+	void cachefs_acquire_cookie(struct cachefs_cookie *iparent,
+				    struct cachefs_index_def *idef,
+				    void *netfs_data,
+				    struct cachefs_cookie **_cookie);
+
+This function creates an index entry in the index represented by iparent,
+loading the associated blob by calling iparent's update method with the
+supplied netfs_data.
+
+It also creates a new index inode, formatted according to the definition
+supplied in idef. The new cookie is then returned in *_cookie.
+
+Note that this function never returns an error - all errors are handled
+internally. It may also return a NULL token. It is quite acceptable to pass
+this token back to this function as iparent (or even to the relinquish cookie,
+read page and write page functions - see below).
+
+Note also that no indexes are actually created on disc until a data file needs
+to be created somewhere down the hierarchy. Furthermore, an index may be
+created in several different caches independently at different times. This is
+all handled transparently, and the netfs doesn't see any of it.
+
+For example, with AFS, a cell would be added to the primary index. This index
+entry would have a dependent inode containing a volume location index for the
+volume mappings within this cell:
+
+	cachefs_acquire_cookie(afs_cache_netfs.primary_index,
+			       &afs_vlocation_cache_index_def,
+			       cell,
+			       &cell->cache);
+
+Then when a volume location was accessed, it would be entered into the cell's
+index and an inode would be allocated that acts as a volume type and hash chain
+combination:
+
+	cachefs_acquire_cookie(cell->cache,
+			       &afs_volume_cache_index_def,
+			       vlocation,
+			       &vlocation->cache);
+
+And then a particular flavour of volume (R/O for example) could be added to
+that index, creating another index for vnodes (AFS inode equivalents):
+
+	cachefs_acquire_cookie(vlocation->cache,
+			       &afs_vnode_cache_index_def,
+			       volume,
+			       &volume->cache);
+
+
+DATA FILE REGISTRATION
+----------------------
+
+The third step is to request a data file be created in the cache. This is
+almost identical to index cookie acquisition. The only difference is that a
+NULL index definition is passed.
+
+	cachefs_acquire_cookie(volume->cache,
+			       NULL,
+			       vnode,
+			       &vnode->cache);
+
+
+
+PAGE ALLOC/READ/WRITE
+---------------------
+
+And the fourth step is to propose a page be cached. There are two functions
+that are used to do this.
+
+Firstly, the netfs should ask CacheFS to examine the caches and read the
+contents cached for a particular page of a particular file if present, or else
+allocate space to store the contents if not:
+
+	typedef
+	void (*cachefs_rw_complete_t)(void *cookie_data,
+				      struct page *page,
+				      void *end_io_data,
+				      int error);
+
+	int cachefs_read_or_alloc_page(struct cachefs_cookie *cookie,
+				       struct page *page,
+				       cachefs_rw_complete_t end_io_func,
+				       void *end_io_data,
+				       unsigned long gfp);
+
+The cookie argument must specify a data file cookie, the page specified will
+have the data loaded into it (and is also used to specify the page number), and
+the gfp argument is used to control how any memory allocations made are satisfied.
+
+If the cookie indicates the inode is not cached:
+
+ (1) The function will return -ENOBUFS.
+
+Else if there's a copy of the page resident on disc:
+
+ (1) The function will submit a request to read the data off the disc directly
+     into the page specified.
+
+ (2) The function will return 0.
+
+ (3) When the read is complete, end_io_func() will be invoked with:
+
+     (*) The netfs data supplied when the cookie was created.
+
+     (*) The page descriptor.
+
+     (*) The data passed to the above function.
+
+     (*) An argument that's 0 on success or negative for an error.
+
+     If an error occurs, it should be assumed that the page contains no usable
+     data.
+
+Otherwise, if there's not a copy available on disc:
+
+ (1) A block may be allocated in the cache and attached to the inode at the
+     appropriate place.
+
+ (2) The validity journal will be marked to indicate this page does not yet
+     contain valid data.
+
+ (3) The function will return -ENODATA.
+
+
+Secondly, the if the netfs changes the contents of the page (either due to
+an initial download or if a user performs a write), then the page should be
+written back:
+
+	int cachefs_write_page(struct cachefs_cookie *cookie,
+			       struct page *page,
+			       cachefs_rw_complete_t end_io_func,
+			       void *end_io_data,
+			       unsigned long gfp);
+
+The cookie argument must specify a data file cookie, the page specified will
+should have the data ready to be written from it (and is also used to specify
+the page number), and the gfp argument is used to control how any memory
+allocations made are satisfied.
+
+If the cookie indicates the inode is not cached then:
+
+ (1) The function will return -ENOBUFS.
+
+Else if there's a block allocated on disc to hold this page:
+
+ (1) The function will submit a request to write the data to the disc directly
+     from the page specified.
+
+ (2) The function will return 0.
+
+ (3) When the write is complete:
+
+     (a) Any associated validity journal entry will be cleared (the block now
+	 contains valid data as far as CacheFS is concerned).
+
+     (b) end_io_func() will be invoked with:
+
+	 (*) The netfs data supplied when the cookie was created.
+
+	 (*) The page descriptor.
+
+	 (*) The data passed to the above function.
+
+	 (*) An argument that's 0 on success or negative for an error.
+
+	 If an error happens, it can be assumed that the page has been
+	 discarded from the cache.
+
+
+PAGE UNCACHING
+--------------
+
+To uncache a page, this function should be called:
+
+	void cachefs_uncache_page(struct cachefs_cookie *cookie,
+				  struct page *page);
+
+This detaches the page specified from the data file indicated by the cookie and
+unbinds it from the underlying block.
+
+Note that pages can't be explicitly detached from the a data file. The whole
+data file must be retired (see the relinquish cookie function below).
+
+Furthermore, note that this does not cancel the asynchronous read or write
+operation started by the read/alloc and write functions.
+
+
+INDEX AND DATA FILE UNREGISTRATION
+----------------------------------
+
+To get rid of a cookie, this function should be called.
+
+	void cachefs_relinquish_cookie(struct cachefs_cookie *cookie,
+				       int retire);
+
+If retire is non-zero, then the index or file will be marked for recycling, and
+all copies of it will be removed from all active caches in which it is present.
+
+If retire is zero, then the inode may be available again next the the
+acquisition function is called.
+
+One very important note - relinquish should NOT be called unless all "child"
+indexes, files and pages have been relinquished first.
+
+
+PAGE TOKEN MANAGEMENT
+---------------------
+
+As previously mentioned, the netfs must keep a token associated with each page
+currently actively backed by the cache. This is used by CacheFS to go from a
+page to the internal representation of the underlying block and back again. It
+is particularly important for managing the withdrawal of a cache whilst it is
+in active service (ie: it got unmounted).
+
+The token is this:
+
+	struct cachefs_page {
+		...
+	};
+
+Note that all fields are for internal CacheFS use only.
+
+The token only needs to be allocated when CacheFS asks for it. This it will do
+be calling the get_page_cookie() method in the netfs definition ops table. Once
+allocated, the same token should be presented every time the method is called
+again for the a particular page.
+
+The token should be retained by the netfs, and should be deleted only after the
+page has been uncached.
+
+One way to achieve this is to attach the token to page->private (and set the
+PG_private bit on the page) once allocated. Shortcut routines are provided by
+CacheFS to do this. Firstly, to retrieve if present and allocate if not:
+
+	int cachefs_page_get_private(struct page *page,
+				     struct cachefs_page **_page,
+				     unsigned gfp);
+
+Secondly to retrieve if present and BUG if not:
+
+	static inline
+	struct cachefs_page *__cachefs_page_get_private(struct page *page);
+
+To clean up the tokens, the netfs inode hosting the page should be provided
+with address space operations that circumvent the buffer-head operations for a
+page. For instance:
+
+	struct address_space_operations afs_fs_aops = {
+		...
+		.sync_page	= block_sync_page,
+		.set_page_dirty	= __set_page_dirty_nobuffers,
+		.releasepage	= afs_file_releasepage,
+		.invalidatepage	= afs_file_invalidatepage,
+	};
+
+	static int afs_file_invalidatepage(struct page *page,
+					   unsigned long offset)
+	{
+		struct afs_vnode *vnode = AFS_FS_I(page->mapping->host);
+		int ret = 1;
+
+		BUG_ON(!PageLocked(page));
+		if (!PagePrivate(page))
+			return 1;
+		cachefs_uncache_page(vnode->cache,page);
+		if (offset == 0)
+			return 1;
+		BUG_ON(!PageLocked(page));
+		if (PageWriteback(page))
+			return 0;
+		return page->mapping->a_ops->releasepage(page, 0);
+	}
+
+	static int afs_file_releasepage(struct page *page, int gfp_flags)
+	{
+		struct cachefs_page *token;
+		struct afs_vnode *vnode = AFS_FS_I(page->mapping->host);
+
+		if (PagePrivate(page)) {
+			cachefs_uncache_page(vnode->cache, page);
+			token = (struct cachefs_page *) page->private;
+			page->private = 0;
+			ClearPagePrivate(page);
+			if (token)
+				kfree(token);
+		}
+		return 0;
+	}


From dwh at infradead.org  Tue Jul 15 18:20:32 2003
From: dwh at infradead.org (dwh@infradead.org)
Date: Tue Jul 15 17:20:27 2003
Subject: afs/fs/cachefs recycling.c,1.26,1.27
Message-ID: <E19cSXY-0001sc-00@phoenix.infradead.org>

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

Modified Files:
	recycling.c 
Log Message:
note the transfer of recycle -> alloc stacks in the RcycXfer record, not the
one after


Index: recycling.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/recycling.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- recycling.c	10 Jul 2003 14:21:24 -0000	1.26
+++ recycling.c	15 Jul 2003 16:20:29 -0000	1.27
@@ -250,9 +250,15 @@
 
 		trans->jentry->mark	= CACHEFS_ONDISC_UJNL_RECYC_TRANSFER;
 		trans->jentry->block	= allocTOS;
+		super->recycle_cur	= 0;
+		super->alloc_cur	= allocTOS;
+		super->alloc_leaf	= 0;
 
 		ret = cachefs_trans_mark(trans);
 		if (ret < 0) {
+			super->recycle_cur	= allocTOS;
+			super->alloc_cur	= 0;
+			super->alloc_leaf	= 0;
 			printk("CacheFS: failed to mark ujnl: %d\n", ret);
 			_leave(" [error %d]", ret);
 			return;
@@ -260,7 +266,6 @@
 
 		super->recycle_block	= NULL;
 		super->recycle_node	= NULL;
-		super->recycle_cur	= 0;
 		super->recycle_cur_n	= 0;
 	}
 	/* otherwise transfer from the second-in-line if there is one */
@@ -302,8 +307,15 @@
 		trans->jentry->block	= allocTOS;
 		trans->jentry->upblock	= super->recycle_cur;
 
+		super->recycle_cur	= 0;
+		super->alloc_cur	= allocTOS;
+		super->alloc_leaf	= 0;
+
 		ret = cachefs_trans_mark(trans);
 		if (ret < 0) {
+			super->recycle_cur	= allocTOS;
+			super->alloc_cur	= 0;
+			super->alloc_leaf	= 0;
 			printk("CacheFS: failed to mark ujnl: %d\n", ret);
 			dbgpgfree(page);
 			page_cache_release(page);
@@ -314,8 +326,7 @@
 		}
 
 		/* break the pointer from the recycling stack TOS to the 2OS */
-		node = (struct cachefs_ondisc_free_node *)
-			kmap(super->recycle_node);
+		node = kmap(super->recycle_node);
 		node->next	= 0;
 		node->count	= 0;
 		kunmap(super->recycle_node);
@@ -325,9 +336,7 @@
 
 	set_bit(CACHEFS_BLOCK_CRITICAL, &block->flags);
 
-	super->alloc_cur	= allocTOS;
 	super->alloc_cur_n	= cur_n;
-	super->alloc_leaf	= 0;
 	super->alloc_block	= block;
 	super->alloc_node	= page;
 


From dwh at infradead.org  Tue Jul 15 18:41:32 2003
From: dwh at infradead.org (dwh@infradead.org)
Date: Tue Jul 15 17:41:25 2003
Subject: afs/fs/cachefs aops.c,1.40,1.41
Message-ID: <E19cSrs-0001yh-00@phoenix.infradead.org>

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

Modified Files:
	aops.c 
Log Message:
note advance of alloc stack tracking in allocation records, not following
records


Index: aops.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/aops.c,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -r1.40 -r1.41
--- aops.c	9 Jul 2003 10:39:50 -0000	1.40
+++ aops.c	15 Jul 2003 16:41:30 -0000	1.41
@@ -923,8 +923,8 @@
 	struct cachefs_ondisc_metadata *metadata;
 	struct cachefs_super *super = sb->s_fs_info;
 	struct cachefs_block *block;
-	cachefs_blockix_t alloc2os = 0;
-	unsigned next_count = 0;
+	cachefs_blockix_t alloc2os = 0, old_alloc_cur;
+	u_int32_t next_count = 0, old_alloc_leaf;
 	int ret;
 	u8 *data;
 
@@ -954,7 +954,8 @@
 		if (!(step[1].flags & CACHEFS_BLOCK_IS_INODE))
 			cachefs_trans_affects_inode(step->transaction, inode);
 
-		jentry->count = inode->index_epp;
+		jentry->count = inode->index_esize;
+		jentry->ixentry = step->page->index * inode->index_epp;
 	}
 
 	/* freshly allocated data blocks must be recorded in the v-journal */
@@ -999,6 +1000,9 @@
 	BUG_ON(super->alloc_leaf > CACHEFS_ONDISC_LEAVES_PER_FREE_NODE);
 
 	/* choose either a dependent block or the now empty node */
+	old_alloc_cur  = super->alloc_cur;
+	old_alloc_leaf = super->alloc_leaf;
+
 	if (super->alloc_leaf == CACHEFS_ONDISC_LEAVES_PER_FREE_NODE) {
 		/* no dependent blocks left - take the alloc node itself */
 		block = super->alloc_block;
@@ -1008,12 +1012,12 @@
 		BUG_ON(!jentry->block);
 
 		node = kmap(super->alloc_node);
-		alloc2os	= node->next;
-		next_count	= node->count;
+		super->alloc_cur	= node->next;
+		super->alloc_leaf	= 0;
+		next_count		= node->count;
 		kunmap(node);
 
-		jentry->auxblock = alloc2os;
-		jentry->auxentry = 1;
+		alloc2os = super->alloc_cur;
 
 		if (step->page)
 			cachefs_block_set(super,
@@ -1024,14 +1028,11 @@
 	else {
 		/* take the next dependent page */
 		node = kmap(super->alloc_node);
-		jentry->block	= node->leaves[super->alloc_leaf];
+		jentry->block	= node->leaves[super->alloc_leaf++];
 		alloc2os	= node->next;
 		kunmap(node);
 		BUG_ON(!jentry->block);
 
-		jentry->auxblock = 0;
-		jentry->auxentry = 0;
-
 		if (!step->page) {
 			ret = cachefs_block_read(super, NULL, jentry->block, 1,
 						 &block, &step->page);
@@ -1070,17 +1071,20 @@
 		ret = cachefs_block_read(super, NULL, alloc2os, 0,
 					 &super->alloc_nxblock,
 					 &super->alloc_next);
-		if (ret==0)
+		if (ret == 0)
 			set_bit(CACHEFS_BLOCK_CRITICAL,
 				&super->alloc_nxblock->flags);
 		else
-			printk("CacheFS: can't read 2OS of alloc stack:"
-			       " %d\n", ret);
+			printk("CacheFS: can't read 2OS of alloc stack: %d\n",
+			       ret);
 	}
 
 	/* make sure the journal is marked on disc before doing anything else */
-	if (cachefs_trans_mark(step->transaction) < 0)
+	if (cachefs_trans_mark(step->transaction) < 0) {
+		super->alloc_cur  = old_alloc_cur;
+		super->alloc_leaf = old_alloc_leaf;
 		goto error_block;
+	}
 
 	if (step->flags & CACHEFS_BLOCK_INIT_NETFSDATA) {
 		set_bit(CACHEFS_BLOCK_NETFSDATA, &block->flags);
@@ -1096,16 +1100,14 @@
 		kunmap(step->page);
 	}
 
-	/* now we can mess about with the alloc tracking */
-	if (super->alloc_leaf == CACHEFS_ONDISC_LEAVES_PER_FREE_NODE) {
+	/* clean up the alloc stack tracking */
+	if (old_alloc_leaf == CACHEFS_ONDISC_LEAVES_PER_FREE_NODE) {
 		struct page *dead;
 
 		/* move the allocation stack to the 2OS */
-		super->alloc_cur	= jentry->auxblock;
-		super->alloc_cur_n	= next_count;
-		super->alloc_leaf	= 0;
-
 		dead = super->alloc_node;
+
+		super->alloc_cur_n	= next_count;
 		super->alloc_node	= super->alloc_next;
 		super->alloc_block	= super->alloc_nxblock;
 		super->alloc_next	= NULL;
@@ -1113,9 +1115,6 @@
 		dbgpgfree(dead);
 		page_cache_release(dead);
 	}
-	else {
-		super->alloc_leaf++;
-	}
 
 	super->alloc_cur_n--;
 
@@ -1136,6 +1135,10 @@
 	metadata->size	= inode->vfs_inode.i_size;
 	metadata->mtime	= CURRENT_TIME.tv_sec;
 
+	if (step->flags & CACHEFS_BLOCK_INIT_INDEX) {
+		metadata->freelink = step->page->index * inode->index_epp;
+	}
+
 	if (step[1].flags & CACHEFS_BLOCK_IS_INODE) {
 		unsigned long pageaddr = (unsigned long) metadata & PAGE_MASK;
 		*(cachefs_blockix_t *)(pageaddr + step->offset) = step->bix;
@@ -1350,7 +1353,8 @@
 			jentry->auxmark	= step->auxmark;
 			jentry->upblock	=
 				__cachefs_get_page_block(step[1].page)->bix;
-			jentry->upentry	= step->offset / sizeof(cachefs_blockix_t);
+			jentry->upentry	=
+				step->offset / sizeof(cachefs_blockix_t);
 
 			ret = cachefs_get_block_alloc(inode->vfs_inode.i_sb,
 						      inode, step);


From dwh at infradead.org  Wed Jul 16 12:44:24 2003
From: dwh at infradead.org (dwh@infradead.org)
Date: Wed Jul 16 11:44:20 2003
Subject: afs/fs/cachefs index.c,1.27,1.28 cachefs-layout.h,1.30,1.31
 aops.c,1.41,1.42
Message-ID: <E19cjlo-0001wQ-00@phoenix.infradead.org>

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) {


From dwh at infradead.org  Wed Jul 16 13:19:42 2003
From: dwh at infradead.org (dwh@infradead.org)
Date: Wed Jul 16 12:19:37 2003
Subject: afs/fs/cachefs recycling.c,1.27,1.28 aops.c,1.42,1.43
Message-ID: <E19ckJy-0002Is-00@phoenix.infradead.org>

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

Modified Files:
	recycling.c aops.c 
Log Message:
don't put entry indexes in u-journal if offsets are available


Index: recycling.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/recycling.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- recycling.c	15 Jul 2003 16:20:29 -0000	1.27
+++ recycling.c	16 Jul 2003 11:19:39 -0000	1.28
@@ -910,7 +910,7 @@
 	trans->jentry->auxmark	= vjentry->vslot;
 	trans->jentry->block	= vjentry->bix;
 	trans->jentry->upblock	= vjentry->upblock;
-	trans->jentry->upentry	= vjentry->upentry / sizeof(cachefs_blockix_t);
+	trans->jentry->upentry	= vjentry->upentry;
 	trans->jentry->auxblock	= super->recycle_cur;
 	trans->jentry->auxentry	= ~0;
 

Index: aops.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/aops.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -r1.42 -r1.43
--- aops.c	16 Jul 2003 10:44:22 -0000	1.42
+++ aops.c	16 Jul 2003 11:19:39 -0000	1.43
@@ -1385,8 +1385,7 @@
 			jentry->auxmark	= step->auxmark;
 			jentry->upblock	=
 				__cachefs_get_page_block(step[1].page)->bix;
-			jentry->upentry	=
-				step->offset / sizeof(cachefs_blockix_t);
+			jentry->upentry	= step->offset;
 
 			ret = cachefs_get_block_alloc(inode->vfs_inode.i_sb,
 						      inode, step);


From dwh at infradead.org  Thu Jul 17 10:49:41 2003
From: dwh at infradead.org (dwh@infradead.org)
Date: Thu Jul 17 09:49:35 2003
Subject: afs/fs/cachefs rootdir.c,1.14,1.15
Message-ID: <E19d4SL-0003pZ-00@phoenix.infradead.org>

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

Modified Files:
	rootdir.c 
Log Message:
readdir now displays cache contents again


Index: rootdir.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/rootdir.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- rootdir.c	10 Jul 2003 14:21:23 -0000	1.14
+++ rootdir.c	17 Jul 2003 08:49:39 -0000	1.15
@@ -185,7 +185,7 @@
 		_debug("dirent: %d '%s' ino=%u",
 		       nlen, rec->scratch, xent->ino);
 
-		if (nlen) {
+		if (nlen <= 0) {
 			desc->count	-= rec->esize;
 			desc->written	+= rec->esize;
 			ret		+= rec->esize;
@@ -257,7 +257,7 @@
 	rec.dpos_off	= 2;
 	rec.dsize	= inode->index_dsize;
 	rec.esize	= inode->index_esize;
-	rec.epp		= inode->index_esize;
+	rec.epp		= inode->index_epp;
 
 	metadata = cachefs_metadata_preread(inode);
 	memcpy(rec.keys, metadata->index.keys, sizeof(rec.keys));
@@ -282,7 +282,7 @@
 
 	/* deal with root directory only entries */
 	if (inode->vfs_inode.i_ino == CACHEFS_INO_ROOTDIR) {
-		rec.dpos_off = 5;
+		rec.dpos_off = 4;
 		switch (file->f_pos) {
 		case 2:
 			ret = filldir(cookie, "metadata_catalogue", 18,


From dwh at infradead.org  Thu Jul 17 14:02:15 2003
From: dwh at infradead.org (dwh@infradead.org)
Date: Thu Jul 17 13:02:17 2003
Subject: afs/fs/cachefs vjournal.c,1.4,1.5 rootdir.c,1.15,1.16
 recycling.c,1.28,1.29 journal.c,1.40,1.41 index.c,1.28,1.29
 dump-journal.c,1.14,1.15 cachefs-layout.h,1.31,1.32aops.c,1.43,1.44
Message-ID: <E19d7Sh-0005wi-00@phoenix.infradead.org>

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

Modified Files:
	vjournal.c rootdir.c recycling.c journal.c index.c 
	dump-journal.c cachefs-layout.h aops.c 
Log Message:
improve/debug reclaimation and recycling and allocation stack tracking


Index: vjournal.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/vjournal.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- vjournal.c	4 Jul 2003 09:04:43 -0000	1.4
+++ vjournal.c	17 Jul 2003 12:02:13 -0000	1.5
@@ -225,6 +225,7 @@
 	if (ret < 0)
 		goto error_free;
 
+	wait_on_page_locked(vjentry->vpage);
 	cachefs_block_modify(super, vjentry->vblock, &vjentry->vpage);
 	memset(kmap(vjentry->vpage) + vjentry->ventry, 0,
 	       sizeof(struct cachefs_ondisc_validity_journal));

Index: rootdir.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/rootdir.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- rootdir.c	17 Jul 2003 08:49:39 -0000	1.15
+++ rootdir.c	17 Jul 2003 12:02:13 -0000	1.16
@@ -681,9 +681,10 @@
 
 	BUG_ON(trans->jentry->index != dir->i_ino);
 
-	trans->jentry->pgnum = trans->jentry->index / index->index_epp;
+	trans->jentry->pgnum = trans->jentry->ixentry / index->index_epp;
 	trans->jentry->entry =
-		(trans->jentry->index % index->index_epp) * index->index_esize;
+		(trans->jentry->ixentry % index->index_epp) *
+		index->index_esize;
 
 	ret = cachefs_get_page(index, trans->jentry->pgnum, &ixpage);
 	if (ret < 0) {

Index: recycling.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/recycling.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- recycling.c	16 Jul 2003 11:19:39 -0000	1.28
+++ recycling.c	17 Jul 2003 12:02:13 -0000	1.29
@@ -78,14 +78,23 @@
 	}
 
 	trans->jentry->mark	= CACHEFS_ONDISC_UJNL_RECYC_BEGIN_NEW;
+	trans->jentry->index	= super->recycle_cur;
+	trans->jentry->ixentry	= super->recycle_cur_n;
 	trans->jentry->block	= bix;
-	trans->jentry->auxblock	= super->recycle_cur;
 	trans->jentry->upblock	= upblock;
 	trans->jentry->upentry	= upentry;
 
 	trans->jentry->pgnum =
 		super->layout->bix_unready + used_unready_node;
 
+	trans->changed |= CACHEFS_TRANS_CHANGED_RECYCLE;
+	trans->jentry->recycle_cur = bix;
+
+	if (upblock) {
+		trans->changed |= CACHEFS_TRANS_CHANGED_RCMPTR;
+		trans->jentry->rcm_ptrnext = upentry;
+	}
+
 	/* mark the beginning of the operation */
 	ret = cachefs_trans_mark(trans);
 	if (ret<0)
@@ -95,12 +104,11 @@
 	cachefs_block_modify(super, block, &page);
 
 	node = (struct cachefs_ondisc_free_node *) kmap(page);
-	node->next = super->recycle_cur;
-	node->count = super->recycle_cur_n;
+	node->next  = trans->jentry->index;
+	node->count = trans->jentry->ixentry;
 	kunmap(page);
 
-	super->recycle_cur	= bix;
-	super->recycle_room	= CACHEFS_ONDISC_LEAVES_PER_FREE_NODE;
+	super->recycle_room = CACHEFS_ONDISC_LEAVES_PER_FREE_NODE;
 	page	= xchg(&super->recycle_node, page);
 	block	= xchg(&super->recycle_block, block);
 
@@ -250,15 +258,17 @@
 
 		trans->jentry->mark	= CACHEFS_ONDISC_UJNL_RECYC_TRANSFER;
 		trans->jentry->block	= allocTOS;
-		super->recycle_cur	= 0;
-		super->alloc_cur	= allocTOS;
-		super->alloc_leaf	= 0;
+
+		trans->jentry->recycle_cur	= 0;
+		trans->jentry->alloc_cur	= allocTOS;
+		trans->jentry->alloc_leaf	= 0;
+
+		trans->changed |=
+			CACHEFS_TRANS_CHANGED_RECYCLE |
+			CACHEFS_TRANS_CHANGED_ALLOC;
 
 		ret = cachefs_trans_mark(trans);
 		if (ret < 0) {
-			super->recycle_cur	= allocTOS;
-			super->alloc_cur	= 0;
-			super->alloc_leaf	= 0;
 			printk("CacheFS: failed to mark ujnl: %d\n", ret);
 			_leave(" [error %d]", ret);
 			return;
@@ -307,15 +317,12 @@
 		trans->jentry->block	= allocTOS;
 		trans->jentry->upblock	= super->recycle_cur;
 
-		super->recycle_cur	= 0;
-		super->alloc_cur	= allocTOS;
-		super->alloc_leaf	= 0;
+		trans->jentry->alloc_cur  = allocTOS;
+		trans->jentry->alloc_leaf = 0;
+		trans->changed |= CACHEFS_TRANS_CHANGED_ALLOC;
 
 		ret = cachefs_trans_mark(trans);
 		if (ret < 0) {
-			super->recycle_cur	= allocTOS;
-			super->alloc_cur	= 0;
-			super->alloc_leaf	= 0;
 			printk("CacheFS: failed to mark ujnl: %d\n", ret);
 			dbgpgfree(page);
 			page_cache_release(page);
@@ -351,21 +358,21 @@
 
 /*****************************************************************************/
 /*
- * recycle the dependents of the block currently in the recycling bin and then
- * recycle the block itself
+ * recycle the dependents of the page currently being reclaimed
  */
-static void cachefs_recycle_pointer_array(struct cachefs_super *super)
+static void cachefs_recycle_pointer_array(struct cachefs_super *super,
+					  struct cachefs_transaction **_trans)
 {
 	struct cachefs_ondisc_free_node *node;
 	struct cachefs_transaction *trans;
 	struct cachefs_block *block;
 	cachefs_blockix_t *indirect, *jeptr;
-	struct page *page;
 	unsigned limit, count, src, dst, max;
 	int ret;
 
-	kenter("{room=%u block=%u:%hu-%hu},",
+	kenter("{room=%u page=%lx block=%x:%hu-%hu},",
 	       super->recycle_room,
+	       super->rcm_curpage->index,
 	       super->rcm_block,
 	       super->rcm_ptrnext,
 	       super->rcm_ptrstop);
@@ -374,17 +381,9 @@
 	max -= sizeof(struct cachefs_ondisc_update_journal);
 	max /= sizeof(cachefs_blockix_t);
 
-	/* load the pointer block page */
-	ret = cachefs_block_read(super, NULL, super->rcm_block, 0,
-				 NULL, &page);
-	if (ret < 0) {
-		kleave(" [error %d]", ret);
-		return;
-	}
-
-	wait_on_page_locked(page);
-
-	indirect = (cachefs_blockix_t*) kmap(page);
+	ret = 0;
+	wait_on_page_locked(super->rcm_curpage);
+	indirect = (cachefs_blockix_t *) kmap(super->rcm_curpage);
 
 	/* find an occupied pointer */
 	for (src = super->rcm_ptrnext; src < super->rcm_ptrstop; src++)
@@ -397,17 +396,12 @@
  found:
 	/* make sure there's a recycling block with space available */
 	if (super->recycle_room == 0) {
-		/* recycle the first dependent page as the new recycling
-		 * node */
-		super->rcm_ptrnext = src;
 		ret = cachefs_recycle_begin_new_node(super, indirect[src],
 						     super->rcm_block, src);
 		goto out;
 	}
 
-	trans = cachefs_trans_alloc(super, GFP_KERNEL);
-	if (!trans)
-		goto out;
+	trans = *_trans;
 
 	cachefs_trans_affects_block(trans, super->recycle_block, 0, PAGE_SIZE);
 
@@ -440,14 +434,16 @@
 	}
 
 	trans->jentry->count = count;
+	trans->jentry->rcm_ptrnext = src;
 
 	ret = cachefs_trans_mark(trans);
 	if (ret < 0) {
 		printk("kcachefsd: Failed to mark journal: %d\n", ret);
-		cachefs_trans_put(trans);
 		goto out;
 	}
 
+	*_trans = NULL;
+
 	super->recycle_room -= count;
 	super->recycle_cur_n += count;
 	if (super->recycle_room == 0)
@@ -465,16 +461,10 @@
 
 	kunmap(super->recycle_node);
 
-	super->rcm_ptrnext = src;
-
 	cachefs_trans_commit(trans);
-	trans = NULL;
 
  out:
-	kunmap(page);
-	dbgpgfree(page);
-	page_cache_release(page);
-
+	kunmap(super->rcm_curpage);
 	kleave(" [error %d]", ret);
 } /* end cachefs_recycle_pointer_array() */
 
@@ -487,18 +477,19 @@
  *   - index entry pointing to inode being reclaimed
  *   - metadata record of index (we've got a new free index entry)
  */
-static int cachefs_recycle_reclaim_inode_metadata(struct cachefs_super *super)
+static int cachefs_recycle_reclaim_inode_metadata(struct cachefs_super *super,
+						  struct cachefs_transaction **_trans)
 {
 	struct cachefs_ondisc_index_entry *xent;
 	struct cachefs_ondisc_ujnl_index *jindex;
 	struct cachefs_ondisc_metadata *metadata;
-	struct cachefs_transaction *trans = NULL;
+	struct cachefs_transaction *trans;
 	struct cachefs_inode *iinode = NULL;
 	struct page *ixpage = NULL;
 	unsigned iino, ixentry, offset;
 	int ret;
 
-	kenter("{%u}", super->rcm_ino);
+	kenter("{%x}", super->rcm_ino);
 
 	/* find the parent index entry */
 	metadata = cachefs_metadata_preread(super->rcm_inode);
@@ -524,17 +515,13 @@
 	}
 
 	/* do the release under journalling */
-	ret = -ENOMEM;
-	trans = cachefs_trans_alloc(super, GFP_KERNEL);
-	if (!trans)
-		goto error;
+	trans = *_trans;
 
 	jindex = &trans->jentry->ixdata[0];
 	jindex->next_ino	= UINT_MAX;
 	jindex->next_index	= UINT_MAX;
 
 	trans->jentry->mark	= CACHEFS_ONDISC_UJNL_INODE_DELETING;
-	trans->jentry->ino	= super->rcm_ino;
 
 	if (iinode) {
 		trans->jentry->index	= iino;
@@ -570,10 +557,18 @@
 	cachefs_trans_affects_inode(trans, super->rcm_inode);
 	cachefs_trans_affects_inode(trans, super->imetadata);
 
+	trans->jentry->rcm_ino		= 0;
+	trans->jentry->rcm_indirect	= 0;
+	trans->jentry->rcm_block	= 0;
+	trans->jentry->rcm_ptrnext	= 0;
+	trans->jentry->rcm_ptrstop	= 0;
+
 	ret = cachefs_trans_mark(trans);
 	if (ret < 0)
 		goto error;
 
+	*_trans = NULL;
+
 	/* free up the parent index entry */
 	if (iinode) {
 		cachefs_page_modify(super, &ixpage);
@@ -604,15 +599,13 @@
 
 	/* modify the metadata inode metadata entry */
 	metadata = cachefs_metadata_prewrite(super->imetadata);
-	metadata->freelink	= super->rcm_ino;
+	metadata->freelink	= trans->jentry->ino;
 	cachefs_metadata_postwrite(super->imetadata);
 
 	/* do the writing */
 	cachefs_trans_commit(trans);
-	trans = NULL;
 
  error:
-	cachefs_trans_put(trans);
 	cachefs_put_page(ixpage);
 	cachefs_iput(iinode);
 
@@ -631,175 +624,197 @@
  * - 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:
- *	FROM		TO		WHAT
- *	0		-		not started yet
- *	1		-		reclaiming index entries
- *	2		-		pointers in single indirect block
- *	3		3+N-1		pointers in dblindirect subblocks 0...N-1
- *	3+N		-		pointers in dblindirect block
- *	3+N+1		-		all pointers in inode struct
- *	3+N+2		-		inode itself
+ *	FROM	TO	WHAT
+ *	0	-	reclaiming index entries
+ *	1	-	pointers in single indirect block
+ *	2	2+N-1	pointers in dblindirect subblocks 0...N-1
+ *	2+N	-	pointers in dblindirect block
+ *	2+N+1	-	all pointers in inode struct
+ *	2+N+2	-	inode itself
  */
 static void cachefs_recycle_reclaim_inode(struct cachefs_super *super)
 {
 	struct cachefs_ondisc_metadata *metadata;
-	cachefs_blockix_t bix, *pbix;
-	struct page *page, *dpage;
-	unsigned indirect;
-	unsigned short next, stop;
-	int ret, loop;
+	struct cachefs_transaction *trans;
+	struct page *dpage;
+	int ret = 0, loop;
 
 	const unsigned N = PAGE_SIZE / sizeof(cachefs_blockix_t);
 
-	kenter("{%u,%u,%u:%hu-%hu}",
+	kenter("{%x,%u,%x:%hu-%hu}",
 	       super->rcm_ino, super->rcm_indirect, super->rcm_block,
 	       super->rcm_ptrnext, super->rcm_ptrstop);
 
 	BUG_ON(!super->rcm_ino);
 
-	if (super->rcm_ptrnext == super->rcm_ptrstop && super->rcm_curpage) {
-		put_page(super->rcm_curpage);
+	if (super->rcm_ptrnext == super->rcm_ptrstop) {
+		cachefs_put_page(super->rcm_curpage);
 		super->rcm_curpage = NULL;
 	}
 
-	indirect = super->rcm_indirect;
-	bix = 0;
-	next = 0;
-	stop = PAGE_SIZE / sizeof(cachefs_blockix_t);
-
-	ret = 0;
+	trans = cachefs_trans_alloc(super, GFP_KERNEL);
+	if (!trans) {
+		kleave(" [ENOMEM");
+		return;
+	}
 
- again:
-	indirect++;
+	trans->jentry->ino		= super->rcm_ino;
+	trans->jentry->rcm_ino		= super->rcm_ino;
+	trans->jentry->rcm_indirect	= super->rcm_indirect;
+	trans->jentry->rcm_block	= super->rcm_block;
+	trans->jentry->rcm_ptrstop	= super->rcm_ptrstop;
+	trans->jentry->rcm_ptrnext	= super->rcm_ptrnext;
+
+	trans->changed |=
+		CACHEFS_TRANS_CHANGED_RCMBLOCK |
+		CACHEFS_TRANS_CHANGED_RCMPTR;
 
 	/* iterate through an index clearing out the entries it contains */
-	if (indirect == 1) {
-		if (super->rcm_inode->index_dsize == 0)
-			goto again;
-
-		if (cachefs_index_reclaim_one_entry(super) < 0)
-			goto error2;
-		goto again;
-	}
+	if (trans->jentry->rcm_indirect == 0) {
+		kdebug("-- step 0.%u", trans->jentry->rcm_block);
+
+		if (super->rcm_inode->index_dsize != 0)
+			if (cachefs_index_reclaim_one_entry(super, &trans) < 0)
+				goto error2;
+		goto advance;
+	}
+
+	/* continue a partially complete pointer array */
+	if (trans->jentry->rcm_ptrstop > 0 &&
+	    super->rcm_ptrnext < super->rcm_ptrstop)
+		goto process_pointer_array;
+
+ advance:
+	trans->jentry->rcm_indirect++;
+	kdebug("-- step %u", trans->jentry->rcm_indirect);
 
 	/* process the single indirect block */
-	if (indirect == 2) {
+	if (trans->jentry->rcm_indirect == 1) {
 		metadata = cachefs_metadata_preread(super->rcm_inode);
-		bix = metadata->single_indirect;
+		trans->jentry->rcm_block = metadata->single_indirect;
 		cachefs_metadata_postread(super->rcm_inode);
 
-		if (!bix)
-			goto again;
-		goto pointer_array;
+		if (!trans->jentry->rcm_block)
+			goto advance;
+		goto start_pointer_array;
 	}
 
 	/* deal with double indirection */
-	if (indirect <= 3 + N) {
+	if (trans->jentry->rcm_indirect <= 2 + N) {
+		cachefs_blockix_t *pbix, dblbix;
+
 		metadata = cachefs_metadata_preread(super->rcm_inode);
-		bix = metadata->double_indirect;
+		dblbix = metadata->double_indirect;
 		cachefs_metadata_postread(super->rcm_inode);
 
-		if (!bix) {
-			indirect = 3 + N;
-			goto again;
+		if (!dblbix) {
+			trans->jentry->rcm_indirect = 2 + N;
+			goto advance;
 		}
 
-		ret = cachefs_block_read(super, NULL, bix, 0, NULL, &dpage);
+		ret = cachefs_block_read(super, NULL, dblbix, 0, NULL, &dpage);
 		if (ret < 0)
 			goto error;
 
 		/* start processing a double indirect subblock */
-		if (indirect <= 3 + N - 1) {
+		if (trans->jentry->rcm_indirect <= 2 + N - 1) {
 			wait_on_page_locked(dpage);
 
-			bix = 0;
+			trans->jentry->rcm_block = 0;
 			pbix = kmap(dpage);
-			for (loop = indirect - 2; loop < N; loop++) {
-				bix = pbix[loop];
-				if (bix)
+			for (loop = trans->jentry->rcm_indirect - 2;
+			     loop < N;
+			     loop++) {
+				trans->jentry->rcm_block = pbix[loop];
+				if (trans->jentry->rcm_block)
 					break;
 			}
 			kunmap(dpage);
 
-			indirect = loop + 3;
-			if (bix) {
+			trans->jentry->rcm_indirect = loop + 3;
+			if (trans->jentry->rcm_block) {
 				put_page(dpage);
-				goto pointer_array;
+				goto start_pointer_array;
 			}
 		}
 
 		/* start processing the double indirect block */
-		page = dpage;
-		bix = __cachefs_get_page_block(dpage)->bix;
-		goto pointer_array2;
+		super->rcm_curpage = dpage;
+		super->rcm_block = __cachefs_get_page_block(dpage)->bix;
+		goto process_pointer_array;
 	}
 
 	/* reclaim all the block pointers in the inode metadata record */
-	if (indirect == 3 + N + 1) {
-		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->metadata_offset;
-		stop	+= super->layout->metadata_size;
-		stop	/= sizeof(cachefs_blockix_t);
+	if (trans->jentry->rcm_indirect == 2 + N + 1) {
+		trans->jentry->rcm_block = super->rcm_inode->metadata->bix;
+		trans->jentry->rcm_ptrnext = super->rcm_inode->metadata_offset;
+		trans->jentry->rcm_ptrnext +=
+			offsetof(struct cachefs_ondisc_metadata,
+				 triple_indirect);
+		trans->jentry->rcm_ptrnext /= sizeof(cachefs_blockix_t);
+
+		trans->jentry->rcm_ptrstop = super->rcm_inode->metadata_offset;
+		trans->jentry->rcm_ptrstop += super->layout->metadata_size;
+		trans->jentry->rcm_ptrstop /= sizeof(cachefs_blockix_t);
 
 		down_read(&super->rcm_inode->metadata_sem);
-		page = super->rcm_inode->metadata_page;
-		get_page(page);
+		super->rcm_curpage = super->rcm_inode->metadata_page;
+		get_page(super->rcm_curpage);
 		up_read(&super->rcm_inode->metadata_sem);
-		goto pointer_array2;
+		goto process_pointer_array;
 	}
 
 	/* reclaim the inode itself */
-	if (cachefs_recycle_reclaim_inode_metadata(super) < 0) {
-		indirect--;
-		bix	= 0;
-		next	= 0;
-		stop	= 0;
-		page	= NULL;
-		goto set;
-	}
+	ret = cachefs_recycle_reclaim_inode_metadata(super, &trans);
+	if (ret < 0)
+		goto error;
 
-	/* finished this inode */
 	cachefs_iput(super->rcm_inode);
-	super->rcm_inode	= NULL;
-	super->rcm_ino		= 0;
-	super->rcm_indirect	= 0;
-	super->rcm_block	= 0;
-	super->rcm_ptrnext	= 0;
-	super->rcm_ptrstop	= 0;
+	super->rcm_inode = NULL;
+
+	cachefs_trans_put(trans);
 	kleave("");
 	return;
 
- pointer_array:
-	ret = cachefs_block_read(super, NULL, bix, 0, NULL, &page);
+ start_pointer_array:
+	ret = cachefs_block_read(super, NULL, trans->jentry->rcm_block, 0,
+				 NULL, &super->rcm_curpage);
 	if (ret < 0)
 		goto error;
 
- pointer_array2:
-	cachefs_recycle_pointer_array(super);
+ process_pointer_array:
+	down(&super->ujnl_alloc_sem);
+	super->rcm_ino		= trans->jentry->rcm_ino;
+	super->rcm_indirect	= trans->jentry->rcm_indirect;
+	super->rcm_block	= trans->jentry->rcm_block;
+	super->rcm_ptrstop	= trans->jentry->rcm_ptrstop;
+	super->rcm_ptrnext	= trans->jentry->rcm_ptrnext;
+	up(&super->ujnl_alloc_sem);
 
- set:
-	super->rcm_indirect	= indirect;
-	super->rcm_block	= bix;
-	super->rcm_ptrnext	= next;
-	super->rcm_ptrstop	= stop;
-	super->rcm_curpage	= page;
+	cachefs_recycle_pointer_array(super, &trans);
+	cachefs_trans_put(trans);
 	kleave("");
 	return;
 
  error:
 	if (ret == -EIO) {
 		/* just sweep any buggy block under the rug */
-		printk("CacheFS: discarding block %u due to I/O error\n", bix);
-		goto again;
+		printk("CacheFS: discarding block %u due to I/O error\n",
+		       trans ? trans->jentry->rcm_block : super->rcm_block);
+		goto advance;
 	}
  error2:
-	kdebug("[error %d]", ret);
-	goto set;
+	if (trans) {
+		down(&super->ujnl_alloc_sem);
+		super->rcm_ino		= trans->jentry->rcm_ino;
+		super->rcm_indirect	= trans->jentry->rcm_indirect;
+		super->rcm_block	= trans->jentry->rcm_block;
+		super->rcm_ptrstop	= trans->jentry->rcm_ptrstop;
+		super->rcm_ptrnext	= trans->jentry->rcm_ptrnext;
+		up(&super->ujnl_alloc_sem);
+		cachefs_trans_put(trans);
+	}
+	kleave("[error %d]", ret);
 } /* end cachefs_recycle_reclaim_inode() */
 
 /*****************************************************************************/
@@ -811,13 +826,13 @@
 	struct cachefs_transaction *trans;
 	int ret;
 
-	kenter("{%u,%u,%u:%hu-%hu}",
+	kenter("{%x,%u,%x:%hu-%hu}",
 	       super->rcm_ino, super->rcm_indirect, super->rcm_block,
 	       super->rcm_ptrnext, super->rcm_ptrstop);
 
 	/* recycle the next chunk of an inode we're busy reclaiming */
 	if (super->rcm_ino) {
-		kdebug("do reclaim");
+		kdebug("do reclaim: %x", super->rcm_ino);
 		if (!super->rcm_inode) {
 			ret = cachefs_iget(super, super->rcm_ino,
 					   &super->rcm_inode);
@@ -845,6 +860,16 @@
 		trans->jentry->ino  = super->rcm_imm_buf[super->rcm_imm_tail];
 		trans->jentry->mark = CACHEFS_ONDISC_UJNL_INODE_RECLAIMING;
 
+		trans->jentry->rcm_ino		= trans->jentry->ino;
+		trans->jentry->rcm_indirect	= 0;
+		trans->jentry->rcm_block	= 0;
+		trans->jentry->rcm_ptrnext	= 0;
+		trans->jentry->rcm_ptrstop	= 0;
+
+		trans->changed |=
+			CACHEFS_TRANS_CHANGED_RCMBLOCK |
+			CACHEFS_TRANS_CHANGED_RCMPTR;
+
 		ret = cachefs_trans_mark(trans);
 		if (ret < 0) {
 			kdebug("[error %d]", ret);
@@ -852,12 +877,6 @@
 			goto done;
 		}
 
-		super->rcm_ino		= trans->jentry->ino;
-		super->rcm_indirect	= 0;
-		super->rcm_block	= 0;
-		super->rcm_ptrnext	= 0;
-		super->rcm_ptrstop	= 0;
-
 		cachefs_trans_commit(trans);
 
 		super->rcm_imm_tail =
@@ -866,7 +885,6 @@
 		goto done;
 	}
 
-
  done:
 	if (super->rcm_ino ||
 	    super->rcm_imm_head != super->rcm_imm_tail
@@ -906,6 +924,8 @@
 		goto error;
 
 	trans->jentry->mark   	= CACHEFS_ONDISC_UJNL_DATA_UNALLOCING;
+	trans->jentry->index	= super->recycle_cur;
+	trans->jentry->ixentry	= super->recycle_cur_n;
 	trans->jentry->ino	= vjentry->ino;
 	trans->jentry->auxmark	= vjentry->vslot;
 	trans->jentry->block	= vjentry->bix;
@@ -939,6 +959,9 @@
 			goto error_free;
 
 		cachefs_trans_affects_block(trans, rcyblock, 0, PAGE_SIZE);
+
+		trans->jentry->recycle_cur = vjentry->bix;
+		trans->changed |= CACHEFS_TRANS_CHANGED_RECYCLE;
 	}
 	else {
 		/* we can add into an existing recycling node */
@@ -964,15 +987,14 @@
 	memset(kmap(uppage) + vjentry->upentry, 0, sizeof(cachefs_blockix_t));
 	kunmap(uppage);
 
-	if (trans->jentry->auxentry == UINT_MAX) {
+	if (trans->changed & CACHEFS_TRANS_CHANGED_RECYCLE) {
 		/* new recycling node */
 		node = kmap(rcypage);
-		node->next  = super->recycle_cur;
-		node->count = super->recycle_cur_n;
+		node->next  = trans->jentry->index;
+		node->count = trans->jentry->ixentry;
 		kunmap(rcypage);
 
-		super->recycle_cur	= vjentry->bix;
-		super->recycle_room	= CACHEFS_ONDISC_LEAVES_PER_FREE_NODE;
+		super->recycle_room = CACHEFS_ONDISC_LEAVES_PER_FREE_NODE;
 		rcypage	 = xchg(&super->recycle_node, rcypage);
 		rcyblock = xchg(&super->recycle_block, rcyblock);
 	}

Index: journal.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/journal.c,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -r1.40 -r1.41
--- journal.c	10 Jul 2003 14:21:24 -0000	1.40
+++ journal.c	17 Jul 2003 12:02:13 -0000	1.41
@@ -381,19 +381,45 @@
 	trans->serial		= super->ujnl_serial++;
 	super->ujnl_head	= next;
 
+	/* some recorded values in the superblock should only be updated with
+	 * the lock held */
+	if (trans->changed & CACHEFS_TRANS_CHANGED_ALLOC) {
+		super->alloc_leaf = trans->jentry->alloc_leaf;
+		super->alloc_cur  = trans->jentry->alloc_cur;
+	} else {
+		trans->jentry->alloc_leaf = super->alloc_leaf;
+		trans->jentry->alloc_cur  = super->alloc_cur;
+	}
+
+	if (trans->changed & CACHEFS_TRANS_CHANGED_RECYCLE) {
+		super->recycle_cur = trans->jentry->recycle_cur;
+	} else {
+		trans->jentry->recycle_cur = super->recycle_cur;
+	}
+
+	if (trans->changed & CACHEFS_TRANS_CHANGED_RCMBLOCK) {
+		super->rcm_ino		= trans->jentry->rcm_ino;
+		super->rcm_indirect	= trans->jentry->rcm_indirect;
+		super->rcm_block	= trans->jentry->rcm_block;
+		super->rcm_ptrstop	= trans->jentry->rcm_ptrstop;
+	} else {
+		trans->jentry->rcm_ino		= super->rcm_ino;
+		trans->jentry->rcm_indirect	= super->rcm_indirect;
+		trans->jentry->rcm_block	= super->rcm_block;
+		trans->jentry->rcm_ptrstop	= super->rcm_ptrstop;
+	}
+
+	if (trans->changed & CACHEFS_TRANS_CHANGED_RCMPTR) {
+		super->rcm_ptrnext	= trans->jentry->rcm_ptrnext;
+	} else {
+		trans->jentry->rcm_ptrnext	= super->rcm_ptrnext;
+	}
+
 	up(&super->ujnl_alloc_sem);
 
 	trans->index			= index;
 	trans->jentry->batch		= trans->batch;
 	trans->jentry->serial		= trans->serial;
-	trans->jentry->alloc_leaf	= super->alloc_leaf;
-	trans->jentry->alloc_cur	= super->alloc_cur;
-	trans->jentry->recycle_cur	= super->recycle_cur;
-	trans->jentry->rcm_ino		= super->rcm_ino;
-	trans->jentry->rcm_indirect	= super->rcm_indirect;
-	trans->jentry->rcm_block	= super->rcm_block;
-	trans->jentry->rcm_ptrnext	= super->rcm_ptrnext;
-	trans->jentry->rcm_ptrstop	= super->rcm_ptrstop;
 
 	/* transfer the journal entry to the page it's going to be written
 	 * from */
@@ -433,6 +459,7 @@
 
 	/* record a mark in the validity journal */
 	if (trans->vjentry) {
+		wait_on_page_locked(trans->vjentry->vpage);
 		cachefs_block_modify(super, trans->vjentry->vblock,
 				     &trans->vjentry->vpage);
 		vjentry = kmap(trans->vjentry->vpage) + trans->vjentry->ventry;

Index: index.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/index.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- index.c	16 Jul 2003 10:44:21 -0000	1.28
+++ index.c	17 Jul 2003 12:02:13 -0000	1.29
@@ -640,7 +640,7 @@
 
 	/* fill the inode definition */
 	metadata = kmap(inopage) + ino_offset;
-	memset(metadata, 0, sizeof(super->imetadata->index_esize));
+	memset(metadata, 0, super->imetadata->index_esize);
 
 	metadata->header.state	= CACHEFS_ONDISC_INDEX_ACTIVE;
 	metadata->header.ino	= 0xfefefe;
@@ -689,24 +689,27 @@
  * mark the next inode pinned by an entry in the index currently being
  * reclaimed as being obsolete
  */
-int cachefs_index_reclaim_one_entry(struct cachefs_super *super)
+int cachefs_index_reclaim_one_entry(struct cachefs_super *super,
+				    struct cachefs_transaction **_trans)
 {
 	struct cachefs_ondisc_index_entry *xent;
 	struct cachefs_ondisc_metadata *metadata;
-	struct cachefs_transaction *trans = NULL;
+	struct cachefs_transaction *trans;
 	struct cachefs_inode *inode = NULL;
 	unsigned long flags;
 	struct page *page = NULL;
 	unsigned pgnum, offset, ino;
 	int ret;
 
-	_enter("{%u,%u}", super->rcm_ino, super->rcm_block);
+	kenter("{%x,%x}", super->rcm_ino, super->rcm_block);
 
+ try_next_block:
 	pgnum	= super->rcm_block / super->rcm_inode->index_epp;
 	offset	= super->rcm_block % super->rcm_inode->index_epp;
+	offset *= super->rcm_inode->index_esize;
 
 	if (pgnum >= (super->rcm_inode->vfs_inode.i_size >> PAGE_SHIFT)) {
-		_leave(" = 0");
+		kleave(" = 0");
 		return 0; /* done them all */
 	}
 
@@ -718,25 +721,39 @@
 			super->rcm_block =
 				(pgnum + 1) * super->rcm_inode->index_epp;
 		}
-		_leave(" = %d", ret);
+		kleave(" = %d", ret);
 		return ret;
 	}
 
-	offset *= super->rcm_inode->index_esize;
+ try_next_entry:
 	xent = kmap(page) + offset;
 	ino = xent->ino;
+	BUG_ON(ino == 0 && xent->state != CACHEFS_ONDISC_INDEX_FREE);
+	BUG_ON(ino != 0 && xent->state == CACHEFS_ONDISC_INDEX_FREE);
 	kunmap(page);
 
+	if (!ino) {
+		kdebug("skip slot %u", super->rcm_block);
+		super->rcm_block++;
+
+		offset += super->rcm_inode->index_esize;
+		if (offset + super->rcm_inode->index_esize <= PAGE_SIZE)
+			goto try_next_entry;
+
+		cachefs_put_page(page);
+		page = NULL;
+		goto try_next_block;
+	}
+
 	ret = cachefs_iget(super, ino, &inode);
-	if (ret < 0)
-		goto error_skip;
+	if (ret < 0) {
+		if (ret == -EIO)
+			super->rcm_block++;
+		goto error;
+	}
 
 	/* journal what we're going to do */
-	trans = cachefs_trans_alloc(super, GFP_KERNEL);
-	if (!trans) {
-		_leave(" = -ENOMEM");
-		return -ENOMEM;
-	}
+	trans = *_trans;
 
 	trans->jentry->mark	= CACHEFS_ONDISC_UJNL_INODE_MARK_RECLAIM;
 	trans->jentry->ino	= inode->vfs_inode.i_ino;
@@ -750,9 +767,13 @@
 
 	cachefs_trans_affects_inode(trans, inode);
 
+	trans->jentry->rcm_block = super->rcm_block + 1;
+
 	ret = cachefs_trans_mark(trans);
 	if (ret < 0)
-		goto error_skip;
+		goto error;
+
+	*_trans = NULL;
 
 	/* modify the inode metadata entry */
 	metadata = cachefs_metadata_prewrite(inode);
@@ -762,14 +783,14 @@
 	cachefs_metadata_postwrite(inode);
 
 	cachefs_trans_commit(trans);
-	trans = NULL;
 
 	/* add to the immediate-reclaim table if possible */
 	spin_lock_irqsave(&super->rcm_lock, flags);
 
 	if (CIRC_SPACE(super->rcm_imm_head,
 		       super->rcm_imm_tail,
-		       CACHEFS_RCM_IMM_BUFSIZE) > 0) {
+		       CACHEFS_RCM_IMM_BUFSIZE) > 0
+	    ) {
 		super->rcm_imm_buf[super->rcm_imm_head] =
 			inode->vfs_inode.i_ino;
 		super->rcm_imm_head =
@@ -782,16 +803,12 @@
 
 	spin_unlock_irqrestore(&super->rcm_lock, flags);
 
-	super->rcm_block++;
 	ret = -EAGAIN;
 
- error_skip:
+ error:
 	cachefs_iput(inode);
-	cachefs_trans_put(trans);
 	cachefs_put_page(page);
-	if (ret == -EIO)
-		super->rcm_block++;
 
-	_leave(" = %d", ret);
+	kleave(" = %d [%u]", ret, super->rcm_block);
 	return ret;
 } /* end cachefs_index_reclaim_one_entry() */

Index: dump-journal.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/dump-journal.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- dump-journal.c	10 Jul 2003 14:21:24 -0000	1.14
+++ dump-journal.c	17 Jul 2003 12:02:13 -0000	1.15
@@ -141,13 +141,13 @@
 	       "  CNT"
 	       "    ALLOC[LEAF]"
 	       " RECYCLE "
-	       " RCYBLOCK:NEXT-STOP\n");
+	       " RCMBLOCK:NEXT-STOP\n");
 
 	printf("===="
 	       " ==========="
 	       " ========= ===="
 	       " ======== ========"
-	       " ============="
+	       " =============="
 	       " ============="
 	       " ============="
 	       " ============="
@@ -168,15 +168,15 @@
 		printf("%s%4u" NORMAL
 		       " " CYAN		"%5u"	GREY	"."	NORMAL	"%-5u"	NORMAL
 		       " "		"%s"		" %4d"
-		       " " YELLOW	"%8x"	NORMAL	" %8u"
-		       " " YELLOW	"%8x"	GREY	":"	NORMAL	"%-4hu"
-		       " " YELLOW	"%8d"	GREY	"+"	NORMAL	"%-4hu"
-		       " " YELLOW	"%8d"	GREY	"+"	NORMAL	"%-4hu"
-		       " " YELLOW	"%8d"	GREY	"+"	NORMAL	"%-4hu"
+		       " " YELLOW	"%8x"	NORMAL	" %8x"
+		       " " YELLOW	"%8x"	GREY	":"	NORMAL	"%-5hu"
+		       " " YELLOW	"%8x"	GREY	"+"	NORMAL	"%-4hu"
+		       " " YELLOW	"%8x"	GREY	"+"	NORMAL	"%-4hu"
+		       " " YELLOW	"%8x"	GREY	"+"	NORMAL	"%-4hu"
 		       " " YELLOW	"%4hu"	NORMAL	""
-		       " " GREEN	"%8u"	NORMAL	"[%-4hu]"
-		       " " CYAN		"%8u"	NORMAL	""
-		       " " RED		"%8u"	GREY	":"	NORMAL
+		       " " GREEN	"%8x"	NORMAL	"[%-4hu]"
+		       " " CYAN		"%8x"	NORMAL	""
+		       " " RED		"%8x"	GREY	":"	NORMAL
 		       "%4hu" GREY"-"NORMAL "%-4hu"
 		       "\n",
 		       loop&7 ? NORMAL : GREEN,

Index: cachefs-layout.h
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/cachefs-layout.h,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- cachefs-layout.h	16 Jul 2003 10:44:21 -0000	1.31
+++ cachefs-layout.h	17 Jul 2003 12:02:13 -0000	1.32
@@ -210,7 +210,8 @@
 
 	/* beginning new recycle_stk front node
 	 * - block	= block being begun
-	 * - auxblock	= old front recycling node
+	 * - index	= old front recycling node
+	 * - ixentry	= old front recycling node's count
 	 * - upblock	= block from which transferred (or 0 if from unready list)
 	 * - upentry	= entry in upblock[]
 	 * - pgnum	= new super->layout.bix_unready
@@ -325,6 +326,8 @@
 	CACHEFS_ONDISC_UJNL_DATA_WRITTEN,
 
 	/* data block being unallocated
+	 * - index	= old front recycling node
+	 * - ixentry	= old front recycling node's count
 	 * - ino	= inode to which block belongs
 	 * - pgnum	= which page of inode being unallocated
 	 * - block	= block being recycled

Index: aops.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/aops.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -r1.43 -r1.44
--- aops.c	16 Jul 2003 11:19:39 -0000	1.43
+++ aops.c	17 Jul 2003 12:02:13 -0000	1.44
@@ -923,8 +923,8 @@
 	struct cachefs_ondisc_metadata *metadata;
 	struct cachefs_super *super = sb->s_fs_info;
 	struct cachefs_block *block;
-	cachefs_blockix_t alloc2os = 0, old_alloc_cur;
-	u_int32_t next_count = 0, old_alloc_leaf;
+	cachefs_blockix_t alloc2os = 0;
+	u_int32_t next_count = 0;
 	int ret;
 	u8 *data;
 
@@ -1005,10 +1005,9 @@
 
 	BUG_ON(super->alloc_leaf > CACHEFS_ONDISC_LEAVES_PER_FREE_NODE);
 
-	/* choose either a dependent block or the now empty node */
-	old_alloc_cur  = super->alloc_cur;
-	old_alloc_leaf = super->alloc_leaf;
+	step->transaction->changed |= CACHEFS_TRANS_CHANGED_ALLOC;
 
+	/* choose either a dependent block or the now empty node */
 	if (super->alloc_leaf == CACHEFS_ONDISC_LEAVES_PER_FREE_NODE) {
 		/* no dependent blocks left - take the alloc node itself */
 		block = super->alloc_block;
@@ -1018,12 +1017,12 @@
 		BUG_ON(!jentry->block);
 
 		node = kmap(super->alloc_node);
-		super->alloc_cur	= node->next;
-		super->alloc_leaf	= 0;
+		jentry->alloc_cur	= node->next;
+		jentry->alloc_leaf	= 0;
 		next_count		= node->count;
 		kunmap(node);
 
-		alloc2os = super->alloc_cur;
+		alloc2os = jentry->alloc_cur;
 
 		if (step->page)
 			cachefs_block_set(super,
@@ -1034,11 +1033,14 @@
 	else {
 		/* take the next dependent page */
 		node = kmap(super->alloc_node);
-		jentry->block	= node->leaves[super->alloc_leaf++];
+		jentry->block	= node->leaves[super->alloc_leaf];
 		alloc2os	= node->next;
 		kunmap(node);
 		BUG_ON(!jentry->block);
 
+		jentry->alloc_cur	= super->alloc_cur;
+		jentry->alloc_leaf	= super->alloc_leaf + 1;
+
 		if (!step->page) {
 			ret = cachefs_block_read(super, NULL, jentry->block, 1,
 						 &block, &step->page);
@@ -1085,11 +1087,8 @@
 	}
 
 	/* make sure the journal is marked on disc before doing anything else */
-	if (cachefs_trans_mark(step->transaction) < 0) {
-		super->alloc_cur  = old_alloc_cur;
-		super->alloc_leaf = old_alloc_leaf;
+	if (cachefs_trans_mark(step->transaction) < 0)
 		goto error_block;
-	}
 
 	if (step->flags & CACHEFS_BLOCK_INIT_NETFSDATA) {
 		set_bit(CACHEFS_BLOCK_NETFSDATA, &block->flags);
@@ -1133,7 +1132,7 @@
 	}
 
 	/* clean up the alloc stack tracking */
-	if (old_alloc_leaf == CACHEFS_ONDISC_LEAVES_PER_FREE_NODE) {
+	if (super->alloc_leaf == 0) {
 		struct page *dead;
 
 		/* move the allocation stack to the 2OS */


From dwh at infradead.org  Fri Jul 18 10:53:57 2003
From: dwh at infradead.org (dwh@infradead.org)
Date: Fri Jul 18 09:53:55 2003
Subject: afs/fs/cachefs recycling.c,1.29,1.30
Message-ID: <E19dR01-0004qr-00@phoenix.infradead.org>

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

Modified Files:
	recycling.c 
Log Message:
don't want reclaimed block to end up being a new recycling node _and_ also its
first dependent child


Index: recycling.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/recycling.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- recycling.c	17 Jul 2003 12:02:13 -0000	1.29
+++ recycling.c	18 Jul 2003 08:53:54 -0000	1.30
@@ -32,11 +32,9 @@
  */
 static int cachefs_recycle_begin_new_node(struct cachefs_super *super,
 					  cachefs_blockix_t bix,
-					  cachefs_blockix_t upblock,
-					  unsigned short upentry)
+					  struct cachefs_transaction *trans)
 {
 	struct cachefs_ondisc_free_node *node;
-	struct cachefs_transaction *trans;
 	struct cachefs_block *block;
 	struct page *page;
 	char used_unready_node = 0;
@@ -64,10 +62,12 @@
 	}
 
 	/* journal what we're going to do */
-	ret = -ENOMEM;
-	trans = cachefs_trans_alloc(super, GFP_KERNEL);
-	if (!trans)
-		goto error_rel_block;
+	if (!trans) {
+		ret = -ENOMEM;
+		trans = cachefs_trans_alloc(super, GFP_KERNEL);
+		if (!trans)
+			goto error_rel_block;
+	}
 
 	cachefs_trans_affects_block(trans, block, 0, PAGE_SIZE);
 
@@ -81,8 +81,6 @@
 	trans->jentry->index	= super->recycle_cur;
 	trans->jentry->ixentry	= super->recycle_cur_n;
 	trans->jentry->block	= bix;
-	trans->jentry->upblock	= upblock;
-	trans->jentry->upentry	= upentry;
 
 	trans->jentry->pgnum =
 		super->layout->bix_unready + used_unready_node;
@@ -90,11 +88,6 @@
 	trans->changed |= CACHEFS_TRANS_CHANGED_RECYCLE;
 	trans->jentry->recycle_cur = bix;
 
-	if (upblock) {
-		trans->changed |= CACHEFS_TRANS_CHANGED_RCMPTR;
-		trans->jentry->rcm_ptrnext = upentry;
-	}
-
 	/* mark the beginning of the operation */
 	ret = cachefs_trans_mark(trans);
 	if (ret<0)
@@ -150,7 +143,7 @@
 	 * consume the next unready block to set up a new one
 	 */
 	if (super->recycle_room == 0)
-		cachefs_recycle_begin_new_node(super, 0, 0, 0);
+		cachefs_recycle_begin_new_node(super, 0, NULL);
 
 	qty = super->layout->bix_end - super->layout->bix_unready;
 	if (qty == 0) {
@@ -394,14 +387,19 @@
 	goto out;
 
  found:
-	/* make sure there's a recycling block with space available */
+	trans = *_trans;
+
+	/* make sure there's a recycling node with space available */
 	if (super->recycle_room == 0) {
+		trans->jentry->upblock		= super->rcm_block;
+		trans->jentry->upentry		= src;
+		trans->jentry->rcm_ptrnext	= src + 1;
+
 		ret = cachefs_recycle_begin_new_node(super, indirect[src],
-						     super->rcm_block, src);
+						     trans);
+		*_trans = NULL;
 		goto out;
 	}
-
-	trans = *_trans;
 
 	cachefs_trans_affects_block(trans, super->recycle_block, 0, PAGE_SIZE);
 


From dwh at infradead.org  Fri Jul 18 10:55:01 2003
From: dwh at infradead.org (dwh@infradead.org)
Date: Fri Jul 18 09:55:30 2003
Subject: afs/fs/cachefs replay.c,1.2,1.3 journal.c,1.41,1.42
 dump-journal.c,1.15,1.16 cachefs-layout.h,1.32,1.33cachefs-int.h,1.39,1.40
Message-ID: <E19dR13-0004rm-00@phoenix.infradead.org>

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

Modified Files:
	replay.c journal.c dump-journal.c cachefs-layout.h 
	cachefs-int.h 
Log Message:
finished writing u-journal replay functions


Index: replay.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/replay.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- replay.c	10 Jul 2003 14:21:23 -0000	1.2
+++ replay.c	18 Jul 2003 08:54:58 -0000	1.3
@@ -18,9 +18,11 @@
 #include "cachefs-int.h"
 
 #define UJNL_WRAP(X) ((X) & (CACHEFS_ONDISC_UJNL_NUMENTS - 1))
-#define BLOCK_VALID(BLOCK,JENTRY) \
+#define BLOCK_VALID(BLOCK,PAGE,JENTRY) \
 	((BLOCK) && \
-	 (u_int16_t) (unsigned long) (BLOCK)->ref <= (JENTRY)->serial)
+	 (u_int16_t) (unsigned long) (BLOCK)->ref <= (JENTRY)->serial && \
+	 (wait_on_page_locked((PAGE)), 1) \
+	)
 
 struct cachefs_replay_find_batch_desc {
 	read_descriptor_t	desc;
@@ -82,9 +84,6 @@
 static int cachefs_replay_ujnl_indirect_allocing(struct cachefs_super *super,
 						 struct cachefs_ondisc_update_journal *jentry,
 						 struct cachefs_transaction *trans);
-static int cachefs_replay_ujnl_indirect_freeing(struct cachefs_super *super,
-						struct cachefs_ondisc_update_journal *jentry,
-						struct cachefs_transaction *trans);
 
 static const cachefs_ujnl_replay_func_t cachefs_ujnl_replay_tbl[CACHEFS_ONDISC_UJNL__LAST] = {
 	[CACHEFS_ONDISC_UJNL_RECYC_BEGIN_NEW]	= cachefs_replay_ujnl_recyc_begin_new,
@@ -100,7 +99,6 @@
 	[CACHEFS_ONDISC_UJNL_DATA_WRITTEN]	= cachefs_replay_ujnl_data_written,
 	[CACHEFS_ONDISC_UJNL_DATA_UNALLOCING]	= cachefs_replay_ujnl_data_unallocing,
 	[CACHEFS_ONDISC_UJNL_INDIRECT_ALLOCING]	= cachefs_replay_ujnl_indirect_allocing,
-	[CACHEFS_ONDISC_UJNL_INDIRECT_FREEING]	= cachefs_replay_ujnl_indirect_freeing,
 	[CACHEFS_ONDISC_UJNL_INDEX_EXTENDING]	= cachefs_replay_ujnl_index_extending,
 	[CACHEFS_ONDISC_UJNL_INDEX_CREATING]	= cachefs_replay_ujnl_inode_creating,
 	[CACHEFS_ONDISC_UJNL_INDEX_UPDATING]	= cachefs_replay_ujnl_index_modifying
@@ -229,12 +227,12 @@
 				super->rcm_ino		= jentry->rcm_ino;
 
 				kdebug("UJNL[%u] ACK %u"
-				       " { a=%u[%u] r=%u R=%u:%u:%u[%u-%u] }"
+				       " { a=%x[%u] r=%x R=%x:%u:%x[%u-%u] }"
 				       " hi=%u",
 				       slot,
 				       jentry->batch,
-				       super->alloc_leaf,
 				       super->alloc_cur,
+				       super->alloc_leaf,
 				       super->recycle_cur,
 				       super->rcm_ino,
 				       super->rcm_indirect,
@@ -547,7 +545,7 @@
 		while (!list_empty(&super->ujnl_replayq)) {
 			block = list_entry(super->ujnl_replayq.next,
 					   struct cachefs_block, batch_link);
-		
+
 			list_del_init(&block->batch_link);
 			block->ref = NULL;
 			cachefs_block_put(block);
@@ -575,9 +573,9 @@
 
 	kdebug("UJNL slot window: next head=%hu tail=%hu",
 	       super->ujnl_head, super->ujnl_tail);
-	kdebug("UJNL Alloc stacks: A=%u[%u] R=%u",
+	kdebug("UJNL Alloc stacks: A=%x[%u] R=%x",
 	       super->alloc_cur, super->alloc_leaf, super->recycle_cur);
-	kdebug("UJNL Recycling: %u:%u:%u:%u-%u",
+	kdebug("UJNL Recycling: %x.%u: %x:%u-%u",
 	       super->rcm_ino, super->rcm_indirect, super->rcm_block,
 	       super->rcm_ptrnext, super->rcm_ptrstop);
 
@@ -688,13 +686,12 @@
 
 	/* we need to fix up the recycling block node header if the block is
 	 * currently part of one of the recycling chains */
-	if (BLOCK_VALID(block, jentry)) {
+	if (BLOCK_VALID(block, page, jentry)) {
 		node = kmap(page);
-
-		if (node->next != jentry->auxblock) {
-			node->next = jentry->auxblock;
-			cachefs_trans_replays_effect(trans, block);
-		}
+		clear_page(node);
+		node->next  = jentry->index;
+		node->count = jentry->ixentry;
+		cachefs_trans_replays_effect(trans, block);
 		kunmap(page);
 	}
 
@@ -731,7 +728,7 @@
 		if (ret < 0)
 			goto error;
 
-		if (BLOCK_VALID(block, jentry)) {
+		if (BLOCK_VALID(block, page, jentry)) {
 			node = kmap(page);
 
 			if (node->next || node->count) {
@@ -783,7 +780,7 @@
 		goto error2;
 	}
 
-	if (BLOCK_VALID(block, jentry)) {
+	if (BLOCK_VALID(block, page, jentry)) {
 		node = kmap(page);
 
 		if (memcmp(&node->leaves[jentry->auxblock],
@@ -854,7 +851,7 @@
 	kunmap(spage);
 
 	/* we need to reload the pointers cached into the recycling block */
-	if (BLOCK_VALID(block, jentry)) {
+	if (BLOCK_VALID(block, page, jentry)) {
 		node = kmap(page);
 
 		if (memcmp(&node->leaves[jentry->auxblock],
@@ -926,8 +923,9 @@
 		type = CACHEFS_ONDISC_INDEX_INDEXFILE;
 
 	/* make sure the metadata file's freelink pointer is correct */
-	if (BLOCK_VALID(metameta, jentry)) {
-		metadata = kmap(metapage);
+	if (BLOCK_VALID(metameta, metapage, jentry)) {
+		metadata = kmap(metapage) +
+			super->layout->metadata_size * CACHEFS_INO_METADATA;
 		if (metadata->freelink != jindex->next_ino) {
 			metadata->freelink = jindex->next_ino;
 			cachefs_trans_replays_effect(trans, metameta);
@@ -936,8 +934,8 @@
 	}
 
 	/* make sure the index file's freelink pointer is correct */
-	if (BLOCK_VALID(indexmeta, jentry)) {
-		metadata = kmap(ixmpage);
+	if (BLOCK_VALID(indexmeta, ixmpage, jentry)) {
+		metadata = kmap(ixmpage) + jentry->upentry;
 		if (metadata->freelink	!= jindex->next_index ||
 		    metadata->size	!= jentry->size) {
 			metadata->freelink	= jindex->next_index;
@@ -948,8 +946,8 @@
 	}
 
 	/* make sure the new inode's metadata contains the right data */
-	if (BLOCK_VALID(inometa, jentry)) {
-		metadata = kmap(inompage);
+	if (BLOCK_VALID(inometa, inompage, jentry)) {
+		metadata = kmap(inompage) + jentry->auxentry;
 		if (metadata->header.state != CACHEFS_ONDISC_INDEX_ACTIVE ||
 		    metadata->header.type  != type ||
 		    metadata->header.ino   != 0xfefdfc ||
@@ -978,8 +976,8 @@
 	}
 
 	/* make sure the index data is written into the index entry */
-	if (BLOCK_VALID(indexdata, jentry)) {
-		xent = kmap(ixdatapage);
+	if (BLOCK_VALID(indexdata, ixdatapage, jentry)) {
+		xent = kmap(ixdatapage) + jentry->entry;
 		if (xent->state	!= CACHEFS_ONDISC_INDEX_ACTIVE	||
 		    xent->type	!= type				||
 		    xent->ino	!= jentry->ino			||
@@ -1068,8 +1066,9 @@
 	}
 
 	/* make sure the metadata file's freelink pointer is correct */
-	if (BLOCK_VALID(metameta, jentry)) {
-		metadata = kmap(metapage);
+	if (BLOCK_VALID(metameta, metapage, jentry)) {
+		metadata = kmap(metapage) +
+			super->layout->metadata_size * CACHEFS_INO_METADATA;
 		if (metadata->freelink != jindex->next_ino) {
 			metadata->freelink = jindex->next_ino;
 			cachefs_trans_replays_effect(trans, metameta);
@@ -1078,8 +1077,8 @@
 	}
 
 	/* make sure the index file's freelink pointer is correct */
-	if (BLOCK_VALID(indexmeta, jentry)) {
-		metadata = kmap(ixmpage);
+	if (BLOCK_VALID(indexmeta, ixmpage, jentry)) {
+		metadata = kmap(ixmpage) + jentry->upentry;;
 		if (metadata->freelink	!= jindex->next_index ||
 		    metadata->size	!= jentry->size) {
 			metadata->freelink	= jindex->next_index;
@@ -1090,8 +1089,8 @@
 	}
 
 	/* make sure the deleted inode's metadata contains the right data */
-	if (BLOCK_VALID(inometa, jentry)) {
-		metadata = kmap(inompage);
+	if (BLOCK_VALID(inometa, inompage, jentry)) {
+		metadata = kmap(inompage) + jentry->auxentry;
 		if (metadata->header.state	!= CACHEFS_ONDISC_INDEX_FREE ||
 		    metadata->header.type	!= 0			||
 		    metadata->header.ino	!= 0xfefdfc		||
@@ -1114,8 +1113,8 @@
 	}
 
 	/* make sure the index data is written into the index entry */
-	if (BLOCK_VALID(indexdata, jentry)) {
-		xent = kmap(ixdatapage);
+	if (BLOCK_VALID(indexdata, ixdatapage, jentry)) {
+		xent = kmap(ixdatapage) + jentry->entry;
 		if (xent->state	!= CACHEFS_ONDISC_INDEX_FREE	||
 		    xent->type	!= 0				||
 		    xent->ino	!= 0				||
@@ -1177,8 +1176,8 @@
 		goto error2;
 
 	/* make sure the inode's metadata is set to the right state */
-	if (BLOCK_VALID(inometa, jentry)) {
-		metadata = kmap(inompage);
+	if (BLOCK_VALID(inometa, inompage, jentry)) {
+		metadata = kmap(inompage) + jentry->auxentry;
 		if (metadata->header.state != CACHEFS_ONDISC_INDEX_RECYCLE) {
 			metadata->header.state = CACHEFS_ONDISC_INDEX_FREE;
 
@@ -1188,8 +1187,8 @@
 	}
 
 	/* make sure the index entry is also set to the right state */
-	if (BLOCK_VALID(indexdata, jentry)) {
-		xent = kmap(ixdatapage);
+	if (BLOCK_VALID(indexdata, ixdatapage, jentry)) {
+		xent = kmap(ixdatapage) + jentry->entry;
 		if (xent->state	!= CACHEFS_ONDISC_INDEX_FREE) {
 			xent->state	= CACHEFS_ONDISC_INDEX_FREE;
 
@@ -1232,31 +1231,212 @@
 					       struct cachefs_ondisc_update_journal *jentry,
 					       struct cachefs_transaction *trans)
 {
-	
+	struct cachefs_ondisc_index_entry *xent;
+	struct cachefs_ondisc_metadata *metadata;
+	struct cachefs_block *indexmeta, *indexptr, *indexdata;
+	cachefs_blockix_t *ptr;
+	struct page *metapage, *ptrpage, *datapage;
+	int ret;
+
+	kenter(",{%hd.%hu}", jentry->batch, jentry->serial);
+
+	ret = cachefs_block_read(super, NULL, jentry->auxblock, 0,
+				 &indexmeta, &metapage);
+	if (ret < 0)
+		goto error;
+
+	ret = cachefs_block_read(super, NULL, jentry->upblock, 0,
+				 &indexptr, &ptrpage);
+	if (ret < 0)
+		goto error2;
+
+	ret = cachefs_block_read(super, NULL, jentry->block, 0,
+				 &indexdata, &datapage);
+	if (ret < 0)
+		goto error3;
 
-	return -ENOANO;
+	/* make sure the index file's freelink pointer is correct */
+	if (BLOCK_VALID(indexmeta, metapage, jentry)) {
+		metadata = kmap(metapage) + jentry->auxentry;
+		if (metadata->freelink	!= jentry->ixentry ||
+		    metadata->size	!= jentry->size) {
+			metadata->freelink	= jentry->ixentry;
+			metadata->size		= jentry->size;
+			cachefs_trans_replays_effect(trans, indexmeta);
+		}
+		kunmap(metapage);
+	}
+
+	/* make sure the new block is pointed to by the appropriate pointer */
+	if (BLOCK_VALID(indexptr, ptrpage, jentry)) {
+		ptr = kmap(ptrpage) + jentry->upentry;
+		if (*ptr != jentry->block) {
+			*ptr = jentry->block;
+
+			cachefs_trans_replays_effect(trans, indexptr);
+		}
+		kunmap(ptrpage);
+	}
+
+	/* make sure the index data page is initialised */
+	if (BLOCK_VALID(indexdata, datapage, jentry)) {
+		u_int32_t entry, next;
+		void *content;
+		int loop;
+
+		next = jentry->index;
+		entry = jentry->ixentry;
+
+		content = kmap(datapage);
+		clear_page(content);
+
+		for (loop = PAGE_SIZE / jentry->count - 1; loop >= 0; loop--) {
+			xent = content + loop * jentry->count;
+			xent->state		= CACHEFS_ONDISC_INDEX_FREE;
+			xent->freelink[0]	= next;
+			next = entry + loop;
+		}
+
+		cachefs_trans_replays_effect(trans, indexdata);
+		kunmap(datapage);
+	}
+
+	cachefs_block_put(indexdata);
+	cachefs_put_page(datapage);
+ error3:
+	cachefs_block_put(indexptr);
+	cachefs_put_page(ptrpage);
+ error2:
+	cachefs_block_put(indexmeta);
+	cachefs_put_page(metapage);
+ error:
+	kleave(" = %d", ret);
+	return ret;
 } /* end cachefs_replay_ujnl_index_extending() */
 
 /*****************************************************************************/
 /*
- *
+ * replay the modification of the data in an index entry
  */
 static int cachefs_replay_ujnl_index_modifying(struct cachefs_super *super,
 					       struct cachefs_ondisc_update_journal *jentry,
 					       struct cachefs_transaction *trans)
 {
-	return -ENOANO;
+	struct cachefs_ondisc_index_entry *xent;
+	struct cachefs_ondisc_ujnl_index *jindex;
+	struct cachefs_block *indexdata;
+	struct page *ixdatapage;
+	int ret;
+
+	kenter(",{%hd.%hu}", jentry->batch, jentry->serial);
+
+	jindex = &jentry->ixdata[0];
+
+	ret = cachefs_block_read(super, NULL, jentry->block, 0,
+				 &indexdata, &ixdatapage);
+	if (ret < 0)
+		goto error;
+
+	/* make sure the index data is written into the index entry */
+	if (BLOCK_VALID(indexdata, ixdatapage, jentry)) {
+		xent = kmap(ixdatapage) + jentry->entry;
+		if (memcmp(xent->data, jindex->data, jindex->def.dsize) != 0) {
+			memcpy(xent->data, jindex->data, jindex->def.dsize);
+
+			cachefs_trans_replays_effect(trans, indexdata);
+		}
+		kunmap(ixdatapage);
+	}
+
+	cachefs_block_put(indexdata);
+	cachefs_put_page(ixdatapage);
+ error:
+	kleave(" = %d", ret);
+	return ret;
 } /* end cachefs_replay_ujnl_index_modifying() */
 
 /*****************************************************************************/
 /*
- * replay data block allocation and v-journal set
+ * replay data block allocation and v-journal entry marking
  */
 static int cachefs_replay_ujnl_data_allocing(struct cachefs_super *super,
 					     struct cachefs_ondisc_update_journal *jentry,
 					     struct cachefs_transaction *trans)
 {
-	return -ENOANO;
+	struct cachefs_ondisc_validity_journal *vjentry;
+	struct cachefs_ondisc_metadata *metadata;
+	struct cachefs_block *metablock, *ptrblock, *vjblock;
+	cachefs_blockix_t *ptr, vjbix;
+	struct page *metapage, *ptrpage, *vjpage;
+	int ret;
+
+	kenter(",{%hd.%hu}", jentry->batch, jentry->serial);
+
+	ret = cachefs_block_read(super, NULL, jentry->auxblock, 0,
+				 &metablock, &metapage);
+	if (ret < 0)
+		goto error;
+
+	ret = cachefs_block_read(super, NULL, jentry->upblock, 0,
+				 &ptrblock, &ptrpage);
+	if (ret < 0)
+		goto error2;
+
+	vjbix = super->layout->bix_vjournal;
+	vjbix += (jentry->auxmark / CACHEFS_ONDISC_VJNL_ENTPERPAGE) *
+		sizeof(struct cachefs_ondisc_validity_journal);
+
+	ret = cachefs_block_read(super, NULL, vjbix, 0,
+				 &vjblock, &vjpage);
+	if (ret < 0)
+		goto error3;
+
+	/* 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);
+		}
+		kunmap(metapage);
+	}
+
+	/* make sure the new block is pointed to by the appropriate pointer */
+	if (BLOCK_VALID(ptrblock, ptrpage, jentry)) {
+		ptr = kmap(ptrpage) + jentry->upentry;
+		if (*ptr != jentry->block) {
+			*ptr = jentry->block;
+
+			cachefs_trans_replays_effect(trans, ptrblock);
+		}
+		kunmap(ptrpage);
+	}
+
+	/* make sure the vjournal entry is marked */
+	vjentry = kmap(vjpage) + 
+		(jentry->auxmark % CACHEFS_ONDISC_VJNL_ENTPERPAGE) *
+		sizeof(struct cachefs_ondisc_validity_journal);
+
+	if (vjentry->ino	!= jentry->ino &&
+	    vjentry->pgnum	!= jentry->pgnum) {
+		vjentry->ino	= jentry->ino;
+		vjentry->pgnum	= jentry->pgnum;
+
+		cachefs_trans_replays_effect(trans, vjblock);
+	}
+	kunmap(vjpage);
+
+	cachefs_block_put(vjblock);
+	cachefs_put_page(vjpage);
+ error3:
+	cachefs_block_put(ptrblock);
+	cachefs_put_page(ptrpage);
+ error2:
+	cachefs_block_put(metablock);
+	cachefs_put_page(metapage);
+ error:
+	kleave(" = %d", ret);
+	return ret;
 } /* end cachefs_replay_ujnl_data_allocing() */
 
 /*****************************************************************************/
@@ -1267,7 +1447,42 @@
 					    struct cachefs_ondisc_update_journal *jentry,
 					    struct cachefs_transaction *trans)
 {
-	return -ENOANO;
+	struct cachefs_ondisc_validity_journal *vjentry;
+	struct cachefs_block *vjblock;
+	cachefs_blockix_t vjbix;
+	struct page *vjpage;
+	int ret;
+
+	kenter(",{%hd.%hu}", jentry->batch, jentry->serial);
+
+	vjbix = super->layout->bix_vjournal;
+	vjbix += (jentry->auxmark / CACHEFS_ONDISC_VJNL_ENTPERPAGE) *
+		sizeof(struct cachefs_ondisc_validity_journal);
+
+	ret = cachefs_block_read(super, NULL, vjbix, 0,
+				 &vjblock, &vjpage);
+	if (ret < 0)
+		goto error;
+
+	/* make sure the vjournal entry is cleared */
+	vjentry = kmap(vjpage) + 
+		(jentry->auxmark % CACHEFS_ONDISC_VJNL_ENTPERPAGE) *
+		sizeof(struct cachefs_ondisc_validity_journal);
+
+	if (vjentry->ino	!= 0 &&
+	    vjentry->pgnum	!= 0) {
+		vjentry->ino	= 0;
+		vjentry->pgnum	= 0;
+
+		cachefs_trans_replays_effect(trans, vjblock);
+	}
+	kunmap(vjpage);
+
+	cachefs_block_put(vjblock);
+	cachefs_put_page(vjpage);
+ error:
+	kleave(" = %d", ret);
+	return ret;
 } /* end cachefs_replay_ujnl_data_written() */
 
 /*****************************************************************************/
@@ -1278,7 +1493,107 @@
 					       struct cachefs_ondisc_update_journal *jentry,
 					       struct cachefs_transaction *trans)
 {
-	return -ENOANO;
+	struct cachefs_ondisc_validity_journal *vjentry;
+	struct cachefs_ondisc_free_node *node;
+	struct cachefs_block *ptrblock, *vjblock;
+	struct cachefs_block *deadblock = NULL, *rcyblock = NULL;
+	cachefs_blockix_t vjbix, *pbix;
+	struct page *ptrpage, *vjpage;
+	struct page *deadpage = NULL, *rcypage = NULL;
+	int ret;
+
+	kenter(",{%hd.%hu}", jentry->batch, jentry->serial);
+
+	ret = cachefs_block_read(super, NULL, jentry->upblock, 0,
+				 &ptrblock, &ptrpage);
+	if (ret < 0)
+		goto error;
+
+	vjbix = super->layout->bix_vjournal;
+	vjbix += (jentry->auxmark / CACHEFS_ONDISC_VJNL_ENTPERPAGE) *
+		sizeof(struct cachefs_ondisc_validity_journal);
+
+	ret = cachefs_block_read(super, NULL, vjbix, 0,
+				 &vjblock, &vjpage);
+	if (ret < 0)
+		goto error2;
+
+	if (trans->jentry->auxentry == (u_int16_t) ~0) {
+		/* block made new node on recycling stack */
+		ret = cachefs_block_read(super, NULL, trans->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,
+					 0, &rcyblock, &rcypage);
+		if (ret < 0)
+			goto error3;
+	}
+
+	/* make sure the block is no longer pointed to by the appropriate pointer */
+	if (BLOCK_VALID(ptrblock, ptrpage, jentry)) {
+		pbix = kmap(ptrpage) + jentry->upentry;
+		if (*pbix != 0) {
+			*pbix = 0;
+
+			cachefs_trans_replays_effect(trans, ptrblock);
+		}
+		kunmap(ptrpage);
+	}
+
+	/* make sure the vjournal entry is cleared */
+	vjentry = kmap(vjpage) + 
+		(jentry->auxmark % CACHEFS_ONDISC_VJNL_ENTPERPAGE) *
+		sizeof(struct cachefs_ondisc_validity_journal);
+
+	if (vjentry->ino	!= 0 &&
+	    vjentry->pgnum	!= 0) {
+		vjentry->ino	= 0;
+		vjentry->pgnum	= 0;
+
+		cachefs_trans_replays_effect(trans, vjblock);
+	}
+	kunmap(vjpage);
+
+	/* make sure the dead block is correctly set up as a node in the
+	 * recycling stack */
+	if (BLOCK_VALID(deadblock, deadpage, jentry)) {
+		node = kmap(deadpage);
+		clear_page(node);
+		node->next  = trans->jentry->index;
+		node->count = trans->jentry->ixentry;
+		kunmap(deadpage);
+
+		cachefs_trans_replays_effect(trans, deadblock);
+	}
+
+	/* 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);
+		}
+		kunmap(deadpage);
+	}
+
+	cachefs_block_put(rcyblock);
+	cachefs_put_page(rcypage);
+	cachefs_block_put(deadblock);
+	cachefs_put_page(deadpage);
+ error3:
+	cachefs_block_put(vjblock);
+	cachefs_put_page(vjpage);
+ error2:
+	cachefs_block_put(ptrblock);
+	cachefs_put_page(ptrpage);
+ error:
+	kleave(" = %d", ret);
+	return ret;
 } /* end cachefs_replay_ujnl_data_unallocing() */
 
 /*****************************************************************************/
@@ -1289,16 +1604,49 @@
 						 struct cachefs_ondisc_update_journal *jentry,
 						 struct cachefs_transaction *trans)
 {
-	return -ENOANO;
-} /* end cachefs_replay_ujnl_indirect_allocing() */
+	struct cachefs_block *ptrblock, *indblock;
+	cachefs_blockix_t *ptr;
+	struct page *ptrpage, *indpage;
+	void *content;
+	int ret;
 
-/*****************************************************************************/
-/*
- * replay indirection block freeing
- */
-static int cachefs_replay_ujnl_indirect_freeing(struct cachefs_super *super,
-						struct cachefs_ondisc_update_journal *jentry,
-						struct cachefs_transaction *trans)
-{
-	return -ENOANO;
-} /* end cachefs_replay_ujnl_indirect_freeing() */
+	kenter(",{%hd.%hu}", jentry->batch, jentry->serial);
+
+	ret = cachefs_block_read(super, NULL, jentry->upblock, 0,
+				 &ptrblock, &ptrpage);
+	if (ret < 0)
+		goto error;
+
+	ret = cachefs_block_read(super, NULL, jentry->block, 0,
+				 &indblock, &indpage);
+	if (ret < 0)
+		goto error2;
+
+	/* make sure the new block is pointed to by the appropriate pointer */
+	if (BLOCK_VALID(ptrblock, ptrpage, jentry)) {
+		ptr = kmap(ptrpage) + jentry->upentry;
+		if (*ptr != jentry->block) {
+			*ptr = jentry->block;
+
+			cachefs_trans_replays_effect(trans, ptrblock);
+		}
+		kunmap(ptrpage);
+	}
+
+	/* make sure the indirection block is cleared */
+	if (BLOCK_VALID(indblock, indpage, jentry)) {
+		content = kmap(indpage);
+		clear_page(content);
+		cachefs_trans_replays_effect(trans, indblock);
+		kunmap(indpage);
+	}
+
+	cachefs_block_put(indblock);
+	cachefs_put_page(indpage);
+ error2:
+	cachefs_block_put(ptrblock);
+	cachefs_put_page(ptrpage);
+ error:
+	kleave(" = %d", ret);
+	return ret;
+} /* end cachefs_replay_ujnl_indirect_allocing() */

Index: journal.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/journal.c,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -r1.41 -r1.42
--- journal.c	17 Jul 2003 12:02:13 -0000	1.41
+++ journal.c	18 Jul 2003 08:54:58 -0000	1.42
@@ -37,7 +37,6 @@
 	"DataWritn",
 	"DataUnalc",
 	"AllocIndr",
-	"FreeIndr ",
 	"ExtendIdx",
 	"CreateIdx",
 	"UpdateIdx",

Index: dump-journal.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/dump-journal.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- dump-journal.c	17 Jul 2003 12:02:13 -0000	1.15
+++ dump-journal.c	18 Jul 2003 08:54:58 -0000	1.16
@@ -52,13 +52,12 @@
 	BRIGHT	"CrtData  "	NORMAL,
 	BRIGHT	"UpdData  "	NORMAL,
 	BRIGHT	"DelInode "	NORMAL,
-	BRIGHT	"InoMkRcm "	NORMAL,
-	BRIGHT	"InoRcming"	NORMAL,
+	BRIGHT	"MarkReclm"	NORMAL,
+	BRIGHT	"Reclaim  "	NORMAL,
 	BRIGHT	"DataAlloc"	NORMAL,
 	BRIGHT	"DataWrite"	NORMAL,
 	BRIGHT	"DataUnalc"	NORMAL,
 	BRIGHT	"IndrAlloc"	NORMAL,
-	BRIGHT	"IndrFree "	NORMAL,
 	BRIGHT	"ExtnIndex"	NORMAL,
 	BRIGHT	"CrtIndex "	NORMAL,
 	BRIGHT	"UpdIndex "	NORMAL,

Index: cachefs-layout.h
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/cachefs-layout.h,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- cachefs-layout.h	17 Jul 2003 12:02:13 -0000	1.32
+++ cachefs-layout.h	18 Jul 2003 08:54:58 -0000	1.33
@@ -352,16 +352,6 @@
 	 */
 	CACHEFS_ONDISC_UJNL_INDIRECT_ALLOCING,
 
-	/* indirection block being detached for recycling
-	 * - ino	= inode to which indirection block or pointers belong
-	 * - block	= block holding pointer array being processed
-	 * - entry	= index into block[] of first pointer to process
-	 * - count	= number of pointers to process
-	 * - upblock	= block holding pointer that points to this block
-	 * - upentry	= index into auxblock[] of pointer to indirection block
-	 */
-	CACHEFS_ONDISC_UJNL_INDIRECT_FREEING,
-
 	/* index file being extended (as for data block allocation)
 	 * - ino	= index inode
 	 * - pgnum	= page in file holding index entry being allocated

Index: cachefs-int.h
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/cachefs-int.h,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- cachefs-int.h	10 Jul 2003 14:21:24 -0000	1.39
+++ cachefs-int.h	18 Jul 2003 08:54:58 -0000	1.40
@@ -451,7 +451,8 @@
 			     struct cachefs_cookie *cookie,
 			     unsigned *_newino);
 
-extern int cachefs_index_reclaim_one_entry(struct cachefs_super *super);
+extern int cachefs_index_reclaim_one_entry(struct cachefs_super *super,
+					   struct cachefs_transaction **_trans);
 
 /*****************************************************************************/
 /*
@@ -518,6 +519,14 @@
 	struct list_head		sblink;		/* next transaction in superblock's list */
 
 	atomic_t			usage;
+
+	/* keep track of special changes that must only take effect under
+	 * certain circumstances */
+	u_int16_t			changed;
+#define CACHEFS_TRANS_CHANGED_ALLOC	0x0001	/* alloc stack/leaf changed */
+#define CACHEFS_TRANS_CHANGED_RECYCLE	0x0002	/* recycle stack changed */
+#define CACHEFS_TRANS_CHANGED_RCMBLOCK	0x0004	/* inode/block being reclaimed changed */
+#define CACHEFS_TRANS_CHANGED_RCMPTR	0x0008	/* pointer being reclaimed changed */
 
 	/* tracking for blocks being modified by this transaction */
 	unsigned			eff_active;


From dwh at infradead.org  Fri Jul 18 17:16:23 2003
From: dwh at infradead.org (dwh@infradead.org)
Date: Fri Jul 18 16:16:19 2003
Subject: afs/fs/cachefs rootdir.c,1.16,1.17
Message-ID: <E19dWy7-0000cu-00@phoenix.infradead.org>

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

Modified Files:
	rootdir.c 
Log Message:
port to 2.6.0-test1


Index: rootdir.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/rootdir.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- rootdir.c	17 Jul 2003 12:02:13 -0000	1.16
+++ rootdir.c	18 Jul 2003 15:16:20 -0000	1.17
@@ -23,7 +23,8 @@
 #include "cachefs-int.h"
 
 static struct dentry *cachefs_root_lookup(struct inode *dir,
-					  struct dentry *dentry);
+					  struct dentry *dentry,
+					  struct nameidata *nd);
 static int cachefs_root_readdir(struct file *file, void *dirent,
 				filldir_t filldir);
 static int cachefs_root_rmdir_unlink(struct inode *dir,
@@ -412,7 +413,9 @@
 /*
  * look up an entry in the cache's root directory
  */
-static struct dentry *cachefs_root_lookup(struct inode *_dir, struct dentry *dentry)
+static struct dentry *cachefs_root_lookup(struct inode *_dir,
+					  struct dentry *dentry,
+					  struct nameidata *nd)
 {
 	struct cachefs_ondisc_metadata *metadata;
 	struct cachefs_lookup_record rec;


From dwh at infradead.org  Fri Jul 18 17:25:56 2003
From: dwh at infradead.org (dwh@infradead.org)
Date: Fri Jul 18 16:25:52 2003
Subject: afs/fs/afs dir.c,1.10,1.11
Message-ID: <E19dX7M-0000fa-00@phoenix.infradead.org>

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

Modified Files:
	dir.c 
Log Message:
port to 2.6.0-test1


Index: dir.c
===================================================================
RCS file: /home/cvs/afs/fs/afs/dir.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- dir.c	4 Jul 2003 15:26:31 -0000	1.10
+++ dir.c	18 Jul 2003 15:25:53 -0000	1.11
@@ -23,10 +23,11 @@
 #include "super.h"
 #include "internal.h"
 
-static struct dentry *afs_dir_lookup(struct inode *dir, struct dentry *dentry);
+static struct dentry *afs_dir_lookup(struct inode *dir, struct dentry *dentry,
+				     struct nameidata *nd);
 static int afs_dir_open(struct inode *inode, struct file *file);
 static int afs_dir_readdir(struct file *file, void *dirent, filldir_t filldir);
-static int afs_d_revalidate(struct dentry *dentry, int flags);
+static int afs_d_revalidate(struct dentry *dentry, struct nameidata *nd);
 static int afs_d_delete(struct dentry *dentry);
 static int afs_dir_lookup_filldir(void *_cookie, const char *name, int nlen, loff_t fpos,
 				     ino_t ino, unsigned dtype);
@@ -414,7 +415,8 @@
 /*
  * look up an entry in a directory
  */
-static struct dentry *afs_dir_lookup(struct inode *dir, struct dentry *dentry)
+static struct dentry *afs_dir_lookup(struct inode *dir, struct dentry *dentry,
+				     struct nameidata *nd)
 {
 	struct afs_dir_lookup_cookie cookie;
 	struct afs_super_info *as;
@@ -487,7 +489,7 @@
  * - NOTE! the hit can be a negative hit too, so we can't assume we have an inode
  * (derived from nfs_lookup_revalidate)
  */
-static int afs_d_revalidate(struct dentry *dentry, int flags)
+static int afs_d_revalidate(struct dentry *dentry, struct nameidata *nd)
 {
 	struct afs_dir_lookup_cookie cookie;
 	struct dentry *parent;
@@ -495,7 +497,7 @@
 	unsigned fpos;
 	int ret;
 
-	_enter("{sb=%p n=%s},%x",dentry->d_sb,dentry->d_name.name,flags);
+	_enter("{sb=%p n=%s},",dentry->d_sb,dentry->d_name.name);
 
 	/* lock down the parent dentry so we can peer at it */
 	parent = dget_parent(dentry->d_parent);


From dwh at infradead.org  Fri Jul 18 17:40:33 2003
From: dwh at infradead.org (dwh@infradead.org)
Date: Fri Jul 18 16:40:28 2003
Subject: afs/Documentation/filesystems afs.txt,1.5,1.6
Message-ID: <E19dXLV-0001Fu-00@phoenix.infradead.org>

Update of /home/cvs/afs/Documentation/filesystems
In directory phoenix.infradead.org:/tmp/cvs-serv4818

Modified Files:
	afs.txt 
Log Message:
Documentation updated to reflect CacheFS


Index: afs.txt
===================================================================
RCS file: /home/cvs/afs/Documentation/filesystems/afs.txt,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- afs.txt	2 Oct 2002 15:04:14 -0000	1.5
+++ afs.txt	18 Jul 2003 15:40:30 -0000	1.6
@@ -121,30 +121,10 @@
 CACHING
 =======
 
-This is currently being implemented. A block device can be nominated for a
-cache by writing a marker string to the first block and then mounting it as
-filesystem type afscache on an out of the way directory somewhere. Once
-initialised, the block device can just be remounted without the need to
-prepare it again:
+This is performed by way of the CacheFS quasi-filesystem. See the following
+file for more information:
 
-	echo "kafsuninit" >/dev/hde2
-	mount -t afscache /dev/hde2 /mnt
-
-Re-preparing the block device will erase anything cached within.
-
-The filesystem will show three files in its root directory that can be read:
-
-  (*) "meta"
-
-	Access to the contents of the meta-data storage file.
-
-  (*) "cells"
-
-	Access to the contents of the cell cache file.
-
-  (*) "vldb"
-
-	Access to the contents of the volume location cache file.
+	Documentation/filesystems/cachefs.txt
 
 
 EXAMPLES


