[PATCH v4 6/5] NFSD: filecache: only get DIO alignment attrs if NFSD_IO_DIRECT enabled modes

Mike Snitzer
2025-07-23T20:37:16Z

Avoids needless extra fh_getattr() unless NFSD_IO_DIRECT enabled.

Suggested-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Mike Snitzer <snitzer@kernel.org>
---
fs/nfsd/filecache.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c
index 5447dba6c5da..5601e839a72d 100644
--- a/fs/nfsd/filecache.c
+++ b/fs/nfsd/filecache.c
@@ -1058,8 +1058,12 @@ nfsd_file_getattr(const struct svc_fh *fhp, struct nfsd_file *nf)
struct kstat stat;
__be32 status;

- /* Currently only need to get DIO alignment info for regular files */
- if (!S_ISREG(inode->i_mode))
+ /* Currently only need to get DIO alignment info for regular files
+ * IFF NFSD_IO_DIRECT is enabled for nfsd_io_cache_{read,write}.
+ */
+ if (!S_ISREG(inode->i_mode) ||
+ (nfsd_io_cache_read != NFSD_IO_DIRECT &&
+ nfsd_io_cache_write != NFSD_IO_DIRECT))
return nfs_ok;

status = fh_getattr(fhp, &stat);
--
2.43.5