diff options
author | Benjamin Coddington <bcodding@redhat.com> | 2016-03-22 10:28:36 -0400 |
---|---|---|
committer | J. Bruce Fields <bfields@redhat.com> | 2016-03-23 16:02:39 -0400 |
commit | ac503e4a309a3993a069750f95c2815ee5db5aa5 (patch) | |
tree | b96495be6e8e44829db04073c6263ac43ac97a05 /fs/nfsd/vfs.h | |
parent | 4b15da44e742871206582f6aa2997b009648f02f (diff) |
nfsd: use short read as well as i_size to set eof
Use the result of a local read to determine when to set the eof flag. This
allows us to return the location of the end of the file atomically at the
time of the read.
Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
[bfields: add some documentation]
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
Diffstat (limited to 'fs/nfsd/vfs.h')
-rw-r--r-- | fs/nfsd/vfs.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/fs/nfsd/vfs.h b/fs/nfsd/vfs.h index c11ba316f23f..2d573ec057f8 100644 --- a/fs/nfsd/vfs.h +++ b/fs/nfsd/vfs.h @@ -139,4 +139,23 @@ static inline int nfsd_create_is_exclusive(int createmode) || createmode == NFS4_CREATE_EXCLUSIVE4_1; } +static inline bool nfsd_eof_on_read(long requested, long read, + loff_t offset, loff_t size) +{ + /* We assume a short read means eof: */ + if (requested > read) + return true; + /* + * A non-short read might also reach end of file. The spec + * still requires us to set eof in that case. + * + * Further operations may have modified the file size since + * the read, so the following check is not atomic with the read. + * We've only seen that cause a problem for a client in the case + * where the read returned a count of 0 without setting eof. + * That case was fixed by the addition of the above check. + */ + return (offset + read >= size); +} + #endif /* LINUX_NFSD_VFS_H */ |