linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* NFS client llseek
@ 2001-12-14  0:51 dzafman
  2001-12-14 12:42 ` Trond Myklebust
  2001-12-14 12:51 ` Trond Myklebust
  0 siblings, 2 replies; 8+ messages in thread
From: dzafman @ 2001-12-14  0:51 UTC (permalink / raw)
  To: trond.myklebust; +Cc: linux-kernel


I noticed that generic_file_llseek looks at i_size without performing a
revalidate, so I propose the following patch for NFS client.  It applies to
both 2.4.16 and 2.5.0 kernels.


diff -Naur linux-2.4.16.orig/fs/nfs/file.c linux-2.4.16/fs/nfs/file.c
--- linux-2.4.16.orig/fs/nfs/file.c	Sun Sep 23 09:48:01 2001
+++ linux-2.4.16/fs/nfs/file.c	Thu Dec 13 15:35:05 2001
@@ -39,9 +39,10 @@
 static ssize_t nfs_file_write(struct file *, const char *, size_t, loff_t *);
 static int  nfs_file_flush(struct file *);
 static int  nfs_fsync(struct file *, struct dentry *dentry, int datasync);
+static loff_t nfs_file_llseek(struct file *, loff_t, int origin);
 
 struct file_operations nfs_file_operations = {
-	llseek:		generic_file_llseek,
+	llseek:		nfs_file_llseek,
 	read:		nfs_file_read,
 	write:		nfs_file_write,
 	mmap:		nfs_file_mmap,
@@ -142,6 +143,24 @@
 	}
 	unlock_kernel();
 	return status;
+}
+
+static loff_t
+nfs_file_llseek(struct file *file, loff_t offset, int origin)
+{
+	struct dentry * dentry = file->f_dentry;
+	struct inode * inode = dentry->d_inode;
+	loff_t result;
+
+	/*
+	 * Make sure inode fields are up-to-date, since generic_file_llseek()
+	 * might look at anything in the inode.  Currently, i_size may be
+	 * used.
+	 */
+	result = nfs_revalidate_inode(NFS_SERVER(inode), inode);
+	if (!result)
+		result = generic_file_llseek(file, offset, origin);
+	return result;
 }
 
 /*

^ permalink raw reply	[flat|nested] 8+ messages in thread
* re: NFS client llseek
@ 2001-12-14 20:45 dzafman
  2001-12-14 23:13 ` Pedro M. Rodrigues
  0 siblings, 1 reply; 8+ messages in thread
From: dzafman @ 2001-12-14 20:45 UTC (permalink / raw)
  To: trond.myklebust; +Cc: linux-kernel


Trond Myklebust wrote:

>    Just one comment: Isn't it easier to do this in generic_file_llseek()
>    itself using inode->i_op->revalidate()? That would make it work for
>    coda and smbfs too...
>
>    Cheers,
>       Trond

Yes, you are right.  I've attached a patch which does the revalidate in
both default_llseek() and generic_file_llseek().  Also, it only happens
if i_size is going to be used.  This makes NFS client, smbfs, opengfs, and coda
work right, among others.  I copied do_revalidate() from fs/stat.c.  It would be
nice if it was in a header file instead.

By the way, we are looking at the challenges of integrating a fully coherent
distributed/cluster filesystem into the Linux filesystem architecture.

--- linux-2.4.16.orig/fs/read_write.c	Fri Dec 14 12:06:44 2001
+++ linux-2.4.16/fs/read_write.c	Fri Dec 14 12:54:02 2001
@@ -20,6 +20,19 @@
 	mmap:		generic_file_mmap,
 };
 
+/*
+ * Revalidate the inode. This is required for proper NFS attribute caching.
+ * ARG! Copied from fs/stat.c   (move to a header file)
+ */
+static __inline__ int
+do_revalidate(struct dentry *dentry)
+{
+	struct inode * inode = dentry->d_inode;
+	if (inode->i_op && inode->i_op->revalidate)
+		return inode->i_op->revalidate(dentry);
+	return 0;
+}
+
 ssize_t generic_read_dir(struct file *filp, char *buf, size_t siz, loff_t *ppos)
 {
 	return -EISDIR;
@@ -31,6 +44,8 @@
 
 	switch (origin) {
 		case 2:
+			if ((retval = do_revalidate(file->f_dentry)) < 0)
+				return retval;
 			offset += file->f_dentry->d_inode->i_size;
 			break;
 		case 1:
@@ -59,6 +74,8 @@
 
 	switch (origin) {
 		case 2:
+			if ((retval = do_revalidate(file->f_dentry)) < 0)
+				return retval;
 			offset += file->f_dentry->d_inode->i_size;
 			break;
 		case 1:

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2001-12-17 20:34 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-12-14  0:51 NFS client llseek dzafman
2001-12-14 12:42 ` Trond Myklebust
2001-12-14 12:51 ` Trond Myklebust
2001-12-17 18:18   ` Jan Harkes
2001-12-17 18:42     ` Alexander Viro
2001-12-17 20:34     ` Trond Myklebust
2001-12-14 20:45 dzafman
2001-12-14 23:13 ` Pedro M. Rodrigues

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).