Subject: afs/fs/cachefs interface.c,1.10,1.11 aops.c,1.33,1.34

From: [email-masked]
Date: Mon, 09 Jun 2003 14:39:16 +0100

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

Modified Files:
	interface.c aops.c 
Log Message:
fix some things to make caching work properly

Index: interface.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/interface.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- interface.c	6 Jun 2003 08:33:36 -0000	1.10
+++ interface.c	9 Jun 2003 13:39:12 -0000	1.11
@@ -240,7 +240,7 @@
 	struct cachefs_search_result *srch;
 	struct cachefs_cookie *cookie, *xcookie = NULL;
 
-	_enter("{%lu}",inode->vfs_inode.i_ino);
+	_enter("{ino=%lu cnt=%u}",inode->vfs_inode.i_ino,atomic_read(&inode->vfs_inode.i_count));
 
 	/* first of all we have to break the links between the inode and the cookie
 	 * - we have to hold both semaphores BUT we have to get the cookie sem FIRST
@@ -373,19 +373,24 @@
 		if (ret<0)
 			goto error;
 
-		if (!cachefs_igrab(inode))
-			goto error_i;
-
 		down(&inode->vfs_inode.i_sem);
+
+		BUG_ON(!list_empty(&inode->cookie_link));
+
+		if (list_empty(&inode->super_link)) {
+			if (!cachefs_igrab(inode))
+				goto error_upput;
+
+			spin_lock(&super->ino_list_lock);
+			list_add_tail(&inode->super_link,&super->ino_list);
+			spin_unlock(&super->ino_list_lock);
+		}
+
 		inode->cookie = cookie;
 		list_add_tail(&srch->link,&cookie->search_results);
 		list_add_tail(&inode->cookie_link,&cookie->backing_inodes);
 		atomic_inc(&cookie->usage);
 
-		spin_lock(&super->ino_list_lock);
-		list_add_tail(&inode->super_link,&super->ino_list);
-		spin_unlock(&super->ino_list_lock);
-
 		up(&inode->vfs_inode.i_sem);
 		break;
 
@@ -401,7 +406,8 @@
 	_leave(" = %d",ret);
 	return ret;
 
- error_i:
+ error_upput:
+	up(&inode->vfs_inode.i_sem);
 	cachefs_iput(inode);
 	ret = -ENOENT;
  error:
@@ -476,19 +482,22 @@
 	if (ret<0)
 		goto error_x; /* uh-oh... our search record is now wrong */
 
-	if (!cachefs_igrab(inode))
-		goto error_xi;
-
 	down(&inode->vfs_inode.i_sem);
-	inode->cookie = cookie;
-	list_add_tail(&inode->cookie_link,&cookie->backing_inodes);
-	atomic_inc(&cookie->usage);
 
-	spin_lock(&super->ino_list_lock);
+	BUG_ON(!list_empty(&inode->cookie_link));
+
+	if (list_empty(&inode->super_link)) {
+		if (!cachefs_igrab(inode))
+			goto error_xi;
 
-	list_add_tail(&inode->super_link,&super->ino_list);
+		spin_lock(&super->ino_list_lock);
+		list_add_tail(&inode->super_link,&super->ino_list);
+		spin_unlock(&super->ino_list_lock);
+	}
 
-	spin_unlock(&super->ino_list_lock);
+	inode->cookie = cookie;
+	list_add_tail(&inode->cookie_link,&cookie->backing_inodes);
+	atomic_inc(&cookie->usage);
 
 	up(&inode->vfs_inode.i_sem);
 	up_write(&iparent->sem);
@@ -498,6 +507,7 @@
 	/* if we get an error after having instantiated an inode on disc, just discard the search
 	 * record so we find it next time */
  error_xi:
+	up(&inode->vfs_inode.i_sem);
 	cachefs_iput(inode);
 	ret = -ENOENT;
  error_x:
@@ -635,7 +645,7 @@
  done:
 	up_write(&cookie->sem);
 	up_read(&cachefs_addremove_sem);
-	kleave("");
+	_leave(" [%p]",cookie);
 } /* end cachefs_acquire_cookie() */
 
 EXPORT_SYMBOL(cachefs_acquire_cookie);
@@ -803,7 +813,7 @@
 	}
 
 	for (; bvec>=bio->bi_io_vec; bvec--)
-		end_io->func(end_io->cookie_data,bvec->bv_page,end_io->data);
+		end_io->func(end_io->cookie_data,bvec->bv_page,end_io->data,error);
 
 	clear_bit(CACHEFS_BLOCK_NETFSBUSY,&end_io->block->flags);
 	wake_up(&end_io->block->writewq);
@@ -1008,10 +1018,14 @@
 	}
 
 	for (; bvec>=bio->bi_io_vec; bvec--)
-		end_io->func(end_io->cookie_data,bvec->bv_page,end_io->data);
+		end_io->func(end_io->cookie_data,bvec->bv_page,end_io->data,error);
 
-	if (end_io->block->vjentry)
-		cachefs_vj_write_complete(end_io->block);
+	if (end_io->block->vjentry) {
+		if (error==0)
+			cachefs_vj_write_complete(end_io->block);
+		else
+			cachefs_vj_cancel(end_io->block->vjentry);
+	}
 
 	clear_bit(CACHEFS_BLOCK_NETFSBUSY,&end_io->block->flags);
 	wake_up(&end_io->block->writewq);

Index: aops.c
===================================================================
RCS file: /home/cvs/afs/fs/cachefs/aops.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- aops.c	6 Jun 2003 08:33:36 -0000	1.33
+++ aops.c	9 Jun 2003 13:39:12 -0000	1.34
@@ -55,8 +55,6 @@
 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_invalidatepage(struct page *page, unsigned long offset);
-static int cachefs_releasepage(struct page *page, int gfp_flags);
 
 struct address_space_operations cachefs_addrspace_operations = {
 	.readpage		= cachefs_readpage,
@@ -807,7 +805,7 @@
 /*
  * invalidate part or all of a page
  */
-static int cachefs_invalidatepage(struct page *page, unsigned long offset)
+int cachefs_invalidatepage(struct page *page, unsigned long offset)
 {
 	struct cachefs_block *block;
 	struct cachefs_page *pageio;
@@ -839,11 +837,13 @@
 	return ret;
 } /* end cachefs_invalidatepage() */
 
+EXPORT_SYMBOL(cachefs_invalidatepage);
+
 /*****************************************************************************/
 /*
  * release a page and cleanup its private data
  */
-static int cachefs_releasepage(struct page *page, int gfp_flags)
+int cachefs_releasepage(struct page *page, int gfp_flags)
 {
 	struct cachefs_block *block;
 	struct cachefs_page *pageio;
@@ -867,6 +867,8 @@
 	_leave(" = 0");
 	return 0;
 } /* end cachefs_releasepage() */
+
+EXPORT_SYMBOL(cachefs_releasepage);
 
 /*****************************************************************************/
 /*