Bug 177971 - [nfs] FreeBSD 9.1 nfs client dirlist problem w/ nfsv3,rsize=4096,wsize=4096
Summary: [nfs] FreeBSD 9.1 nfs client dirlist problem w/ nfsv3,rsize=4096,wsize=4096
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 9.1-RELEASE
Hardware: Any Any
: Normal Affects Only Me
Assignee: Rick Macklem
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-04-19 07:00 UTC by Mihai M.
Modified: 2015-12-03 12:35 UTC (History)
2 users (show)

See Also:
rmacklem: mfc-stable10+
rmacklem: mfc-stable9+


Attachments
patch to fix this problem (705 bytes, patch)
2015-10-29 00:32 UTC, Rick Macklem
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mihai M. 2013-04-19 07:00:00 UTC
9.1-RELEASE nfs client seems to have a problem with dir read (listing) when
the system is mounted with nfsv3,rsize=4096,wsize=4096 or
nfsv3,rsize=2049,wsize=2048 (may be others sizes too). Some of the file
names are missing from the result and others are duplicated. Tried with
7.2-STABLE FreeBSD and Linux 2.6.32.12 as server, same result. The
nfs_bug.py works ok under FreeBSD 8.2.

Fix: 

Mounting the nfs dir with defaults does not show the problem. Changing to nfsv2 or other rsize/wsize combinations seem to be ok (i.e. rsize=8192,wsize=8192 looks ok for now).
How-To-Repeat: mount -o nfsv3,rsize=4096,wsize=4096 server:/export /mnt

Run the python nfs_bug.py program from 

http://www.delajii.net/mmWiKi/_media/docs:code:nfs_bug.py
Comment 1 Mark Linimon freebsd_committer freebsd_triage 2013-04-20 18:08:46 UTC
Responsible Changed
From-To: freebsd-bugs->freebsd-fs

Over to maintainer(s).
Comment 2 krichy 2015-10-27 20:03:24 UTC
This still exists in releng/10.2. Any solutions?
Comment 3 krichy 2015-10-28 12:20:03 UTC
I've noticed difference between mounting with wsize and without wsize:

# mount -o rsize=2048 10.0.0.2:/home/kh /home/kh/
root@freebsd9:~ # ls -1 /home/kh/fenykepek/20110429 | sort | uniq | wc -l
     309
# umount /home/kh/
# mount -o rsize=2048,wsize=2048 10.0.0.2:/home/kh /home/kh/
# ls -1 /home/kh/fenykepek/20110429 | sort | uniq | wc -l
     225

Dont know if this helps.
Comment 4 Rick Macklem freebsd_committer freebsd_triage 2015-10-29 00:32:14 UTC
Created attachment 162553 [details]
patch to fix this problem

I think this patch will fix the problem. When f_iosize
which sets bo_bsize is less than the size of a buffer
cache buffer problems occur. NFS_DIRBLKSIZ (8K) is the
size of the buffer cache blocks used for directories and
without this patch, rsize=4096 would set f_iosize->bo_bsize
to 4096.
Comment 5 Rick Macklem freebsd_committer freebsd_triage 2015-10-29 00:33:53 UTC
I think the attached patch fixes the problem, which I
believe woudl only occur when rsize was set to less than
NFS_DIRBLKSIZ (8K).
Comment 6 krichy 2015-10-29 09:29:10 UTC
Seems that for my simple test case it works, it gaves the expected directory listing.
Comment 7 commit-hook freebsd_committer freebsd_triage 2015-11-17 01:44:56 UTC
A commit references this bug:

Author: rmacklem
Date: Tue Nov 17 01:44:26 UTC 2015
New revision: 290970
URL: https://svnweb.freebsd.org/changeset/base/290970

Log:
  mnt_stat.f_iosize (which is used to set bo_bsize) must be set to
  the largest size of buffer cache block or the mapping of the buffer
  is bogus. When a mount with rsize=4096,wsize=4096 was done, f_iosize
  would be set to 4096. This resulted in corrupted directory data, since
  the buffer cache block size for directories is NFS_DIRBLKSIZ (8192).
  This patch fixes the code so that it always sets f_iosize to at least
  NFS_DIRBLKSIZ.

  Tested by:	krichy@cflinux.hu
  PR:		177971
  MFC after:	2 weeks

Changes:
  head/sys/fs/nfsclient/nfs_clvfsops.c
Comment 8 Rick Macklem freebsd_committer freebsd_triage 2015-12-01 02:40:50 UTC
The patch that fixes this has been committed to stable/10
as r291551 and stable/9 as r291552.