Subject: afs/fs/afs inode.c,1.9,1.10 file.c,1.5,1.6

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

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

Modified Files:
	inode.c file.c 
Log Message:
fix some things to make caching work properly

Index: inode.c
===================================================================
RCS file: /home/cvs/afs/fs/afs/inode.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- inode.c	6 Jun 2003 08:33:37 -0000	1.9
+++ inode.c	9 Jun 2003 13:39:13 -0000	1.10
@@ -177,26 +177,28 @@
 		return ret;
 	}
 
+	/* set up caching before reading the status, as fetch-status reads the
+	 * first page of symlinks to see if they're really mntpts */
+	cachefs_acquire_cookie(vnode->volume->cache,
+			       NULL,
+			       vnode,
+			       &vnode->cache);
+
 	/* okay... it's a new inode */
 	vnode->flags |= AFS_VNODE_CHANGED;
 	ret = afs_inode_fetch_status(inode);
 	if (ret<0)
 		goto bad_inode;
 
-	cachefs_acquire_cookie(vnode->volume->cache,
-			       NULL,
-			       vnode,
-			       &vnode->cache);
-
 	/* success */
 	unlock_new_inode(inode);
 
 	*_inode = inode;
-	_leave(" = 0 [CB { v=%u x=%lu t=%u nix=%u }]",
+	_leave(" = 0 [CB { v=%u x=%lu t=%u } c=%p]",
 	       vnode->cb_version,
 	       vnode->cb_timeout.timo_jif,
 	       vnode->cb_type,
-	       vnode->nix
+	       vnode->cache
 	       );
 	return 0;

Index: file.c
===================================================================
RCS file: /home/cvs/afs/fs/afs/file.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- file.c	6 Jun 2003 08:33:37 -0000	1.5
+++ file.c	9 Jun 2003 13:39:13 -0000	1.6
@@ -16,6 +16,7 @@
 #include <linux/slab.h>
 #include <linux/fs.h>
 #include <linux/pagemap.h>
+#include <linux/buffer_head.h>
 #include "volume.h"
 #include "vnode.h"
 #include <rxrpc/call.h>
@@ -47,6 +48,10 @@
 
 struct address_space_operations afs_fs_aops = {
 	.readpage	= afs_file_readpage,
+	.sync_page	= block_sync_page,
+	.set_page_dirty	= __set_page_dirty_nobuffers,
+	.releasepage	= cachefs_releasepage,
+	.invalidatepage	= cachefs_invalidatepage,
 };
 
 /*****************************************************************************/
@@ -66,11 +71,42 @@
 
 /*****************************************************************************/
 /*
+ * deal with notification that a page was read from the cache
+ */
+static void afs_file_readpage_read_complete(void *cookie_data, struct page *page, void *data,
+					    int error)
+{
+	_enter("%p,%p,%p,%d",cookie_data,page,data,error);
+
+	if (error)
+		SetPageError(page);
+	else
+		SetPageUptodate(page);
+	unlock_page(page);
+
+} /* end afs_file_readpage_read_complete() */
+
+/*****************************************************************************/
+/*
+ * deal with notification that a page was written to the cache
+ */
+static void afs_file_readpage_write_complete(void *cookie_data, struct page *page, void *data,
+					     int error)
+{
+	_enter("%p,%p,%p,%d",cookie_data,page,data,error);
+
+	unlock_page(page);
+
+} /* end afs_file_readpage_write_complete() */
+
+/*****************************************************************************/
+/*
  * AFS read page from file (or symlink)
  */
 static int afs_file_readpage(struct file *file, struct page *page)
 {
 	struct afs_rxfs_fetch_descriptor desc;
+	struct cachefs_page *pageio;
 	struct inode *inode;
 	afs_vnode_t *vnode;
 	int ret;
@@ -88,28 +124,62 @@
 	if (vnode->flags & AFS_VNODE_DELETED)
 		goto error;
 
-	/* work out how much to get and from where */
-	desc.fid	= vnode->fid;
-	desc.offset	= page->index << PAGE_CACHE_SHIFT;
-	desc.size	= min((size_t)(inode->i_size - desc.offset),(size_t)PAGE_SIZE);
-	desc.buffer	= kmap(page);
-
-	clear_page(desc.buffer);
-
-	/* read the contents of the file from the server into the page */
-	ret = afs_vnode_fetch_data(vnode,&desc);
-	kunmap(page);
-	if (ret<0) {
-		if (ret==-ENOENT) {
-			_debug("got NOENT from server - marking file deleted and stale");
-			vnode->flags |= AFS_VNODE_DELETED;
-			ret = -ESTALE;
-		}
+	ret = cachefs_page_get_private(page,&pageio,GFP_NOIO);
+	if (ret<0)
 		goto error;
-	}
 
-	SetPageUptodate(page);
-	unlock_page(page);
+	/* is it cached? */
+	ret = cachefs_read_or_alloc_page(vnode->cache,
+					 page,
+					 afs_file_readpage_read_complete,
+					 NULL,
+					 GFP_KERNEL);
+	switch (ret) {
+		/* read BIO submitted and wb-journal entry found */
+	case 1:
+		BUG(); // TODO - handle wb-journal match
+
+		/* read BIO submitted (page in cache) */
+	case 0:
+		break;
+		
+		/* no page available in cache */
+	case -ENOBUFS:
+	case -ENODATA:
+	default:
+		desc.fid	= vnode->fid;
+		desc.offset	= page->index << PAGE_CACHE_SHIFT;
+		desc.size	= min((size_t)(inode->i_size - desc.offset),(size_t)PAGE_SIZE);
+		desc.buffer	= kmap(page);
+
+		clear_page(desc.buffer);
+
+		/* read the contents of the file from the server into the page */
+		ret = afs_vnode_fetch_data(vnode,&desc);
+		kunmap(page);
+		if (ret<0) {
+			if (ret==-ENOENT) {
+				_debug("got NOENT from server - marking file deleted and stale");
+				vnode->flags |= AFS_VNODE_DELETED;
+				ret = -ESTALE;
+			}
+
+			cachefs_uncache_page(vnode->cache,page,pageio);
+			goto error;
+		}
+
+		SetPageUptodate(page);
+
+		if (cachefs_write_page(vnode->cache,
+				       page,
+				       afs_file_readpage_write_complete,
+				       NULL,
+				       GFP_KERNEL) != 0
+		    ) {
+			cachefs_uncache_page(vnode->cache,page,pageio);
+			unlock_page(page);
+		}
+	}
 
 	_leave(" = 0");
 	return 0;
@@ -129,6 +199,11 @@
  */
 int afs_cache_get_page_cookie(struct page *page, struct cachefs_page **_page_cookie)
 {
-	return cachefs_page_get_private(page,_page_cookie,GFP_NOIO);
+	int ret;
 
+	_enter("");
+	ret = cachefs_page_get_private(page,_page_cookie,GFP_NOIO);
+
+	_leave(" = %d",ret);
+	return ret;
 } /* end afs_cache_get_page_cookie() */