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

From: [email-masked]
Date: Fri, 04 Jul 2003 15:25:43 +0100

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