Skip to content

Commit aa696a6

Browse files
Trond MyklebustJ. Bruce Fields
authored andcommitted
nfsd: Use vfs_fsync_range() in nfsd_commit
The NFS COMMIT operation allows the client to specify the exact byte range that it wishes to sync to disk in order to optimise server performance. Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>
1 parent 3749829 commit aa696a6

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

‎fs/nfsd/vfs.c‎

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,8 +1141,9 @@ nfsd_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
11411141
#ifdef CONFIG_NFSD_V3
11421142
/*
11431143
* Commit all pending writes to stable storage.
1144-
* Strictly speaking, we could sync just the indicated file region here,
1145-
* but there's currently no way we can ask the VFS to do so.
1144+
*
1145+
* Note: we only guarantee that data that lies within the range specified
1146+
* by the 'offset' and 'count' parameters will be synced.
11461147
*
11471148
* Unfortunately we cannot lock the file to make sure we return full WCC
11481149
* data to the client, as locking happens lower down in the filesystem.
@@ -1152,23 +1153,32 @@ nfsd_commit(struct svc_rqst *rqstp, struct svc_fh *fhp,
11521153
loff_t offset, unsigned long count)
11531154
{
11541155
struct file *file;
1155-
__be32 err;
1156+
loff_t end = LLONG_MAX;
1157+
__be32 err = nfserr_inval;
11561158

1157-
if ((u64)count > ~(u64)offset)
1158-
return nfserr_inval;
1159+
if (offset < 0)
1160+
goto out;
1161+
if (count != 0) {
1162+
end = offset + (loff_t)count - 1;
1163+
if (end < offset)
1164+
goto out;
1165+
}
11591166

11601167
err = nfsd_open(rqstp, fhp, S_IFREG, NFSD_MAY_WRITE, &file);
11611168
if (err)
1162-
return err;
1169+
goto out;
11631170
if (EX_ISSYNC(fhp->fh_export)) {
1164-
if (file->f_op && file->f_op->fsync) {
1165-
err = nfserrno(vfs_fsync(file, file->f_path.dentry, 0));
1166-
} else {
1171+
int err2 = vfs_fsync_range(file, file->f_path.dentry,
1172+
offset, end, 0);
1173+
1174+
if (err2 != -EINVAL)
1175+
err = nfserrno(err2);
1176+
else
11671177
err = nfserr_notsupp;
1168-
}
11691178
}
11701179

11711180
nfsd_close(file);
1181+
out:
11721182
return err;
11731183
}
11741184
#endif /* CONFIG_NFSD_V3 */

0 commit comments

Comments
 (0)