Skip to contentSkip to conversation

Check error status from vfs_getattr and i_op->fsync

PATCH In review NeilBrown 3 participants 4 messages Nov 28, 2005 – Dec 13, 2005 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): 20051128123945.24553.patches@notabene

NeilBrown

author
#1 lore raw

PATCH 1/1 Check error status from vfs_getattr and i_op->fsync

This patch against 2.6.15-rc2-mm1 checks some error statuses that nfsd was ignoring. Due to the extent of the change, and the fact that the problem has been un-noticed for so long, there is no hurry for them to go to Linus - it would be best if they sit in -mm for a while. Thanks,
NeilBrown

### Comments for Changeset

Bother vfs_getattr and i_op->fsync return error statuses which nfsd was largely ignoring. This as noticed when exporting directories using fuse.

This patch cleans up most of the offences, which involves moving the call to vfs_getattr out of the xdr encoding routines (where it is too late to report an error) into the main NFS procedure handling routines.

There is still a called to vfs_gettattr (related to the ACL code) where the status is ignored, and called to nfsd_sync_dir don't check return status either.

From: David Shaw <[email protected]>

### Diffstat output

 ./fs/nfsd/nfs3proc.c        |   11 ++++++++--
 ./fs/nfsd/nfs3xdr.c         |   47 ++++++++++++++++++++++---------------------
 ./fs/nfsd/nfsxdr.c          |   48 ++++++++++++++++++++++----------------------
 ./fs/nfsd/vfs.c             |   20 +++++++++++-------
 ./include/linux/nfsd/xdr.h  |    3 ++
 ./include/linux/nfsd/xdr3.h |    1 
 6 files changed, 75 insertions(+), 55 deletions(-)
fs/nfsd/nfs3proc.c renamed from fs/nfsd/nfs3proc.c~current~ +9 -2
diff ./fs/nfsd/nfs3proc.c~current~ ./fs/nfsd/nfs3proc.c
@@ -56,13 +56,20 @@ static int
 nfsd3_proc_getattr(struct svc_rqst *rqstp, struct nfsd_fhandle  *argp,
 					   struct nfsd3_attrstat *resp)
 {
-	int	nfserr;
+	int	err, nfserr;
 
 	dprintk("nfsd: GETATTR(3)  %s\n",
-				SVCFH_fmt(&argp->fh));
+		SVCFH_fmt(&argp->fh));
 
 	fh_copy(&resp->fh, &argp->fh);
 	nfserr = fh_verify(rqstp, &resp->fh, 0, MAY_NOP);
+	if (nfserr)
+		RETURN_STATUS(nfserr);
+
+	err = vfs_getattr(resp->fh.fh_export->ex_mnt,
+			  resp->fh.fh_dentry, &resp->stat);
+	nfserr = nfserrno(err);
+
 	RETURN_STATUS(nfserr);
 }
 
fs/nfsd/nfs3xdr.c renamed from fs/nfsd/nfs3xdr.c~current~ +25 -22

77 lines not on this page · raw message

fs/nfsd/nfsxdr.c renamed from fs/nfsd/nfsxdr.c~current~ +24 -24

98 lines not on this page · raw message

fs/nfsd/vfs.c renamed from fs/nfsd/vfs.c~current~ +13 -7
diff ./fs/nfsd/vfs.c~current~ ./fs/nfsd/vfs.c
@@ -705,27 +705,33 @@ nfsd_close(struct file *filp)
  * As this calls fsync (not fdatasync) there is no need for a write_inode
  * after it.
  */
-static inline void nfsd_dosync(struct file *filp, struct dentry *dp,
-			       struct file_operations *fop)
+static inline int nfsd_dosync(struct file *filp, struct dentry *dp,
+			      struct file_operations *fop)
 {
 	struct inode *inode = dp->d_inode;
 	int (*fsync) (struct file *, struct dentry *, int);
+	int err = nfs_ok;
 
 	filemap_fdatawrite(inode->i_mapping);
 	if (fop && (fsync = fop->fsync))
-		fsync(filp, dp, 0);
+		err=fsync(filp, dp, 0);
 	filemap_fdatawait(inode->i_mapping);
+
+	return nfserrno(err);
 }
 	
 
-static void
+static int
 nfsd_sync(struct file *filp)
 {
+        int err;
 	struct inode *inode = filp->f_dentry->d_inode;
 	dprintk("nfsd: sync file %s\n", filp->f_dentry->d_name.name);
 	down(&inode->i_sem);
-	nfsd_dosync(filp, filp->f_dentry, filp->f_op);
+	err=nfsd_dosync(filp, filp->f_dentry, filp->f_op);
 	up(&inode->i_sem);
+
+	return err;
 }
 
 void
@@ -950,7 +956,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, s
 
 			if (inode->i_state & I_DIRTY) {
 				dprintk("nfsd: write sync %d\n", current->pid);
-				nfsd_sync(file);
+				err=nfsd_sync(file);
 			}
 #if 0
 			wake_up(&inode->i_wait);
@@ -1054,7 +1060,7 @@ nfsd_commit(struct svc_rqst *rqstp, stru
 		return err;
 	if (EX_ISSYNC(fhp->fh_export)) {
 		if (file->f_op && file->f_op->fsync) {
-			nfsd_sync(file);
+			err = nfsd_sync(file);
 		} else {
 			err = nfserr_notsupp;
 		}
include/linux/nfsd/xdr.h renamed from include/linux/nfsd/xdr.h~current~ +3 -0
diff ./include/linux/nfsd/xdr.h~current~ ./include/linux/nfsd/xdr.h
@@ -88,10 +88,12 @@ struct nfsd_readdirargs {
 
 struct nfsd_attrstat {
 	struct svc_fh		fh;
+	struct kstat		stat;
 };
 
 struct nfsd_diropres  {
 	struct svc_fh		fh;
+	struct kstat		stat;
 };
 
 struct nfsd_readlinkres {
@@ -101,6 +103,7 @@ struct nfsd_readlinkres {
 struct nfsd_readres {
 	struct svc_fh		fh;
 	unsigned long		count;
+	struct kstat		stat;
 };
 
 struct nfsd_readdirres {
include/linux/nfsd/xdr3.h renamed from include/linux/nfsd/xdr3.h~current~ +1 -0
diff ./include/linux/nfsd/xdr3.h~current~ ./include/linux/nfsd/xdr3.h
@@ -126,6 +126,7 @@ struct nfsd3_setaclargs {
 struct nfsd3_attrstat {
 	__u32			status;
 	struct svc_fh		fh;
+	struct kstat            stat;
 };
 
 /* LOOKUP, CREATE, MKDIR, SYMLINK, MKNOD */

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

#2 lore raw

hi,

Quoted 14 lines

This patch against 2.6.15-rc2-mm1 checks some error statuses that nfsd was ignoring. Due to the extent of the change, and the fact that the problem has been un-noticed for so long, there is no hurry for them to go to Linus - it would be best if they sit in -mm for a while. Thanks,
NeilBrown

### Comments for Changeset

Bother vfs_getattr and i_op->fsync return error statuses which nfsd was largely ignoring. This as noticed when exporting directories using fuse.

Quoted 8 lines

This patch cleans up most of the offences, which involves moving the call to vfs_getattr out of the xdr encoding routines (where it is too late to report an error) into the main NFS procedure handling routines.

There is still a called to vfs_gettattr (related to the ACL code) where the status is ignored, and called to nfsd_sync_dir don't check return status either.

it reminded me of a similar diff in our local tree. (attached) it's fsync part only but more complete.

YAMAMOTO Takashi

fs/nfsd/vfs.c renamed from fs/nfsd/vfs.c.BACKUP +61 -21
@@ -712,33 +712,48 @@ nfsd_close(struct file *filp)
  * As this calls fsync (not fdatasync) there is no need for a write_inode
  * after it.
  */
-static inline void nfsd_dosync(struct file *filp, struct dentry *dp,
+static inline int nfsd_dosync(struct file *filp, struct dentry *dp,
 			       struct file_operations *fop)
 {
 	struct inode *inode = dp->d_inode;
 	int (*fsync) (struct file *, struct dentry *, int);
+	int error;
+	int ret;
 
-	filemap_fdatawrite(inode->i_mapping);
-	if (fop && (fsync = fop->fsync))
-		fsync(filp, dp, 0);
-	filemap_fdatawait(inode->i_mapping);
+	ret = filemap_fdatawrite(inode->i_mapping);
+	if (fop && (fsync = fop->fsync)) {
+		error = fsync(filp, dp, 0);
+		if (ret == 0) {
+			ret = error;
+		}
+	}
+	error = filemap_fdatawait(inode->i_mapping);
+	if (ret == 0) {
+		ret = error;
+	}
+
+	return ret;
 }
 	
 
-static void
+static int
 nfsd_sync(struct file *filp)
 {
 	struct inode *inode = filp->f_dentry->d_inode;
+	int error;
+
 	dprintk("nfsd: sync file %s\n", filp->f_dentry->d_name.name);
 	down(&inode->i_sem);
-	nfsd_dosync(filp, filp->f_dentry, filp->f_op);
+	error = nfsd_dosync(filp, filp->f_dentry, filp->f_op);
 	up(&inode->i_sem);
+
+	return error;
 }
 
-static void
+static int
 nfsd_sync_dir(struct dentry *dp)
 {
-	nfsd_dosync(NULL, dp, dp->d_inode->i_fop);
+	return nfsd_dosync(NULL, dp, dp->d_inode->i_fop);
 }
 
 /*
@@ -958,8 +973,13 @@ nfsd_vfs_write(struct svc_rqst *rqstp, s
 			}
 
 			if (inode->i_state & I_DIRTY) {
+				int err2;
+
 				dprintk("nfsd: write sync %d\n", current->pid);
-				nfsd_sync(file);
+				err2 = nfsd_sync(file);
+				if (err2) {
+					err = err2;
+				}
 			}
 #if 0
 			wake_up(&inode->i_wait);
@@ -1063,7 +1083,8 @@ nfsd_commit(struct svc_rqst *rqstp, stru
 		return err;
 	if (EX_ISSYNC(fhp->fh_export)) {
 		if (file->f_op && file->f_op->fsync) {
-			nfsd_sync(file);
+			err = nfsd_sync(file);
+			err = nfserrno(err);
 		} else {
 			err = nfserr_notsupp;
 		}
@@ -1174,7 +1195,11 @@ nfsd_create(struct svc_rqst *rqstp, stru
 		goto out_nfserr;
 
 	if (EX_ISSYNC(fhp->fh_export)) {
-		nfsd_sync_dir(dentry);
+		err = nfsd_sync_dir(dentry);
+		if (err) {
+			goto out_nfserr;
+		}
+
 		write_inode_now(dchild->d_inode, 1);
 	}
 
@@ -1305,7 +1330,10 @@ nfsd_create_v3(struct svc_rqst *rqstp, s
 		goto out_nfserr;
 
 	if (EX_ISSYNC(fhp->fh_export)) {
-		nfsd_sync_dir(dentry);
+		err = nfsd_sync_dir(dentry);
+		if (err) {
+			goto out_nfserr;
+		}
 		/* setattr will sync the child (or not) */
 	}
 
@@ -1447,10 +1475,13 @@ nfsd_symlink(struct svc_rqst *rqstp, str
 		err = vfs_symlink(dentry->d_inode, dnew, path, mode);
 
 	if (!err) {
-		if (EX_ISSYNC(fhp->fh_export))
-			nfsd_sync_dir(dentry);
-	} else
+		if (EX_ISSYNC(fhp->fh_export)) {
+			err = nfsd_sync_dir(dentry);
+		}
+	}
+	if (err) {
 		err = nfserrno(err);
+	}
 	fh_unlock(fhp);
 
 	cerr = fh_compose(resfhp, fhp->fh_export, dnew, fhp);
@@ -1505,8 +1536,11 @@ nfsd_link(struct svc_rqst *rqstp, struct
 	err = vfs_link(dold, dirp, dnew);
 	if (!err) {
 		if (EX_ISSYNC(ffhp->fh_export)) {
-			nfsd_sync_dir(ddir);
+			err = nfsd_sync_dir(ddir);
 			write_inode_now(dest, 1);
+			if (err) {
+				err = nfserrno(err);
+			}
 		}
 	} else {
 		if (err == -EXDEV && rqstp->rq_vers == 2)
@@ -1594,8 +1628,10 @@ nfsd_rename(struct svc_rqst *rqstp, stru
 #endif
 	err = vfs_rename(fdir, odentry, tdir, ndentry);
 	if (!err && EX_ISSYNC(tfhp->fh_export)) {
-		nfsd_sync_dir(tdentry);
-		nfsd_sync_dir(fdentry);
+		err = nfsd_sync_dir(tdentry);
+		if (!err) {
+			err = nfsd_sync_dir(fdentry);
+		}
 	}
 
  out_dput_new:
@@ -1672,8 +1708,12 @@ nfsd_unlink(struct svc_rqst *rqstp, stru
 
 	if (err)
 		goto out_nfserr;
-	if (EX_ISSYNC(fhp->fh_export)) 
-		nfsd_sync_dir(dentry);
+	if (EX_ISSYNC(fhp->fh_export)) {
+		err = nfsd_sync_dir(dentry);
+		if (err) {
+			goto out_nfserr;
+		}
+	}
 
 out:
 	return err;
#3 lore raw
Quoted 4 lines · On Friday December 9, [email protected] wrote:

it reminded me of a similar diff in our local tree. (attached) it's fsync part only but more complete.

Thanks. I've merged and revised it a bit and will submit it shortly.

Are there any other nfs patches in your local tree that you would like to share ?? ;-)

NeilBrown

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

#4 lore raw
Quoted 5 lines
Quoted 3 lines

it reminded me of a similar diff in our local tree. (attached) it's fsync part only but more complete.

Thanks. I've merged and revised it a bit and will submit it shortly.

thanks.

Quoted 2 lines

Are there any other nfs patches in your local tree that you would like to share ?? ;-)

i'll send you and/or this list if suitable ones are digged up. not today, tho. :-)

YAMAMOTO Takashi

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs