patch-2.3.99-pre4 linux/fs/nfs/read.c

Next file: linux/fs/nfs/symlink.c
Previous file: linux/fs/nfs/proc.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.3.99-pre3/linux/fs/nfs/read.c linux/fs/nfs/read.c
@@ -15,7 +15,6 @@
  * within the RPC code when root squashing is suspected.
  */
 
-#define NFS_NEED_XDR_TYPES
 #include <linux/sched.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -52,14 +51,18 @@
  */
 static inline void
 nfs_readreq_setup(struct nfs_rreq *req, struct nfs_fh *fh,
-		  unsigned long offset, void *buffer, unsigned int rsize)
+		  loff_t offset, void *buffer, unsigned int rsize)
 {
 	req->ra_args.fh     = fh;
 	req->ra_args.offset = offset;
 	req->ra_args.count  = rsize;
-	req->ra_args.buffer = buffer;
+	req->ra_args.iov[0].iov_base = (void *)buffer;
+	req->ra_args.iov[0].iov_len = rsize;
+	req->ra_args.nriov  = 1;
+	req->ra_fattr.valid = 0;
 	req->ra_res.fattr   = &req->ra_fattr;
 	req->ra_res.count   = rsize;
+	req->ra_res.eof     = 0;
 }
 
 
@@ -70,11 +73,12 @@
 nfs_readpage_sync(struct dentry *dentry, struct inode *inode, struct page *page)
 {
 	struct nfs_rreq	rqst;
-	unsigned long	offset = page->index << PAGE_CACHE_SHIFT;
+	struct rpc_message msg;
+	loff_t		offset = page_offset(page);
 	char		*buffer;
 	int		rsize = NFS_SERVER(inode)->rsize;
 	int		result, refresh = 0;
-	int		count = PAGE_SIZE;
+	int		count = PAGE_CACHE_SIZE;
 	int		flags = IS_SWAPFILE(inode)? NFS_RPC_SWAPFLAGS : 0;
 
 	dprintk("NFS: nfs_readpage_sync(%p)\n", page);
@@ -89,16 +93,21 @@
 		if (count < rsize)
 			rsize = count;
 
-		dprintk("NFS: nfs_proc_read(%s, (%s/%s), %ld, %d, %p)\n",
+		dprintk("NFS: nfs_proc_read(%s, (%s/%s), %Ld, %d, %p)\n",
 			NFS_SERVER(inode)->hostname,
 			dentry->d_parent->d_name.name, dentry->d_name.name,
-			offset, rsize, buffer);
+			(long long)offset, rsize, buffer);
 
 		/* Set up arguments and perform rpc call */
 		nfs_readreq_setup(&rqst, NFS_FH(dentry), offset, buffer, rsize);
 		lock_kernel();
-		result = rpc_call(NFS_CLIENT(inode), NFSPROC_READ, &rqst.ra_args, &rqst.ra_res, flags);
+		msg.rpc_proc = (NFS_PROTO(inode)->version == 3) ? NFS3PROC_READ : NFSPROC_READ;
+		msg.rpc_argp = &rqst.ra_args;
+		msg.rpc_resp = &rqst.ra_res;
+		msg.rpc_cred = NULL;
+		result = rpc_call_sync(NFS_CLIENT(inode), &msg, flags);
 		unlock_kernel();
+		nfs_refresh_inode(inode, &rqst.ra_fattr);
 
 		/*
 		 * Even if we had a partial success we can't mark the page
@@ -124,9 +133,6 @@
 io_error:
 	kunmap(page);
 	UnlockPage(page);
-	/* Note: we don't refresh if the call returned error */
-	if (refresh && result >= 0)
-		nfs_refresh_inode(inode, &rqst.ra_fattr);
 	return result;
 }
 
@@ -139,19 +145,18 @@
 {
 	struct nfs_rreq	*req = (struct nfs_rreq *) task->tk_calldata;
 	struct page	*page = req->ra_page;
-	unsigned long	address = page_address(page);
+	char		*address = req->ra_args.iov[0].iov_base;
 	int		result = task->tk_status;
 	static int	succ = 0, fail = 0;
 
-	dprintk("NFS: %4d received callback for page %lx, result %d\n",
+	dprintk("NFS: %4d received callback for page %p, result %d\n",
 			task->tk_pid, address, result);
 
+	nfs_refresh_inode(req->ra_inode, &req->ra_fattr);
 	if (result >= 0) {
 		result = req->ra_res.count;
-		if (result < PAGE_SIZE) {
-			memset((char *) address + result, 0, PAGE_SIZE - result);
-		}
-		nfs_refresh_inode(req->ra_inode, &req->ra_fattr);
+		if (result < PAGE_CACHE_SIZE)
+			memset(address + result, 0, PAGE_CACHE_SIZE - result);
 		SetPageUptodate(page);
 		succ++;
 	} else {
@@ -161,9 +166,8 @@
 	}
 	kunmap(page);
 	UnlockPage(page);
-	__free_page(page);
+	page_cache_release(page);
 
-	rpc_release_task(task);
 	kfree(req);
 }
 
@@ -189,15 +193,15 @@
 	address = kmap(page);	
 	/* Initialize request */
 	/* N.B. Will the dentry remain valid for life of request? */
-	nfs_readreq_setup(req, NFS_FH(dentry), page->index << PAGE_CACHE_SHIFT,
-				(void *) address, PAGE_SIZE);
+	nfs_readreq_setup(req, NFS_FH(dentry), page_offset(page),
+				(void *) address, PAGE_CACHE_SIZE);
 	req->ra_inode = inode;
 	req->ra_page = page; /* count has been incremented by caller */
 
 	/* Start the async call */
 	dprintk("NFS: executing async READ request.\n");
 
-	msg.rpc_proc = NFSPROC_READ;
+	msg.rpc_proc = (NFS_PROTO(inode)->version == 3) ? NFS3PROC_READ : NFSPROC_READ;
 	msg.rpc_argp = &req->ra_args;
 	msg.rpc_resp = &req->ra_res;
 	msg.rpc_cred = NULL;
@@ -225,7 +229,7 @@
  * We read the page synchronously in the following cases:
  *  -	The file is a swap file. Swap-ins are always sync operations,
  *	so there's no need bothering to make async reads 100% fail-safe.
- *  -	The NFS rsize is smaller than PAGE_SIZE. We could kludge our way
+ *  -	The NFS rsize is smaller than PAGE_CACHE_SIZE. We could kludge our way
  *	around this by creating several consecutive read requests, but
  *	that's hardly worth it.
  *  -	The error flag is set for this page. This happens only when a
@@ -240,7 +244,7 @@
 
 	lock_kernel();
 	dprintk("NFS: nfs_readpage (%p %ld@%lu)\n",
-		page, PAGE_SIZE, page->index);
+		page, PAGE_CACHE_SIZE, page->index);
 	get_page(page);
 
 	/*
@@ -256,7 +260,7 @@
 
 	error = -1;
 	if (!IS_SWAPFILE(inode) && !PageError(page) &&
-	    NFS_SERVER(inode)->rsize >= PAGE_SIZE)
+	    NFS_SERVER(inode)->rsize >= PAGE_CACHE_SIZE)
 		error = nfs_readpage_async(dentry, inode, page);
 	if (error >= 0)
 		goto out;
@@ -269,7 +273,7 @@
 out_error:
 	UnlockPage(page);
 out_free:
-	__free_page(page);
+	page_cache_release(page);
 out:
 	unlock_kernel();
 	return error;

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)