Fri Apr 2 03:07:54 2021 UTC ()
Set f_namemax during mount time like all the other filesystems so that
it does gets the right data in copy_statvfs_info(). Otherwise f_namemax
can end up being 0. To reproduce: unmount the remote filesystem, remount
it, and kill -HUP mountd to refresh exports.


(christos)
diff -r1.241 -r1.242 src/sys/nfs/nfs_vfsops.c

cvs diff -r1.241 -r1.242 src/sys/nfs/nfs_vfsops.c (expand / switch to unified diff)

--- src/sys/nfs/nfs_vfsops.c 2020/04/13 19:23:20 1.241
+++ src/sys/nfs/nfs_vfsops.c 2021/04/02 03:07:54 1.242
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: nfs_vfsops.c,v 1.241 2020/04/13 19:23:20 ad Exp $ */ 1/* $NetBSD: nfs_vfsops.c,v 1.242 2021/04/02 03:07:54 christos Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1989, 1993, 1995 4 * Copyright (c) 1989, 1993, 1995
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Rick Macklem at The University of Guelph. 8 * Rick Macklem at The University of Guelph.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -25,27 +25,27 @@ @@ -25,27 +25,27 @@
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE. 32 * SUCH DAMAGE.
33 * 33 *
34 * @(#)nfs_vfsops.c 8.12 (Berkeley) 5/20/95 34 * @(#)nfs_vfsops.c 8.12 (Berkeley) 5/20/95
35 */ 35 */
36 36
37#include <sys/cdefs.h> 37#include <sys/cdefs.h>
38__KERNEL_RCSID(0, "$NetBSD: nfs_vfsops.c,v 1.241 2020/04/13 19:23:20 ad Exp $"); 38__KERNEL_RCSID(0, "$NetBSD: nfs_vfsops.c,v 1.242 2021/04/02 03:07:54 christos Exp $");
39 39
40#if defined(_KERNEL_OPT) 40#if defined(_KERNEL_OPT)
41#include "opt_nfs.h" 41#include "opt_nfs.h"
42#endif 42#endif
43 43
44#include <sys/param.h> 44#include <sys/param.h>
45#include <sys/ioctl.h> 45#include <sys/ioctl.h>
46#include <sys/signal.h> 46#include <sys/signal.h>
47#include <sys/proc.h> 47#include <sys/proc.h>
48#include <sys/namei.h> 48#include <sys/namei.h>
49#include <sys/device.h> 49#include <sys/device.h>
50#include <sys/vnode.h> 50#include <sys/vnode.h>
51#include <sys/kernel.h> 51#include <sys/kernel.h>
@@ -213,39 +213,37 @@ nfs_statvfs(struct mount *mp, struct sta @@ -213,39 +213,37 @@ nfs_statvfs(struct mount *mp, struct sta
213 tquad = fxdr_hyper(&sfp->sf_abytes); 213 tquad = fxdr_hyper(&sfp->sf_abytes);
214 tquad = ((quad_t)tquad / (quad_t)NFS_FABLKSIZE); 214 tquad = ((quad_t)tquad / (quad_t)NFS_FABLKSIZE);
215 sbp->f_bresvd = sbp->f_bfree - tquad; 215 sbp->f_bresvd = sbp->f_bfree - tquad;
216 sbp->f_bavail = tquad; 216 sbp->f_bavail = tquad;
217 /* Handle older NFS servers returning negative values */ 217 /* Handle older NFS servers returning negative values */
218 if ((quad_t)sbp->f_bavail < 0) 218 if ((quad_t)sbp->f_bavail < 0)
219 sbp->f_bavail = 0; 219 sbp->f_bavail = 0;
220 tquad = fxdr_hyper(&sfp->sf_tfiles); 220 tquad = fxdr_hyper(&sfp->sf_tfiles);
221 sbp->f_files = tquad; 221 sbp->f_files = tquad;
222 tquad = fxdr_hyper(&sfp->sf_ffiles); 222 tquad = fxdr_hyper(&sfp->sf_ffiles);
223 sbp->f_ffree = tquad; 223 sbp->f_ffree = tquad;
224 sbp->f_favail = tquad; 224 sbp->f_favail = tquad;
225 sbp->f_fresvd = 0; 225 sbp->f_fresvd = 0;
226 sbp->f_namemax = NFS_MAXNAMLEN; 
227 } else { 226 } else {
228 sbp->f_bsize = NFS_FABLKSIZE; 227 sbp->f_bsize = NFS_FABLKSIZE;
229 sbp->f_frsize = fxdr_unsigned(int32_t, sfp->sf_bsize); 228 sbp->f_frsize = fxdr_unsigned(int32_t, sfp->sf_bsize);
230 sbp->f_blocks = fxdr_unsigned(int32_t, sfp->sf_blocks); 229 sbp->f_blocks = fxdr_unsigned(int32_t, sfp->sf_blocks);
231 sbp->f_bfree = fxdr_unsigned(int32_t, sfp->sf_bfree); 230 sbp->f_bfree = fxdr_unsigned(int32_t, sfp->sf_bfree);
232 sbp->f_bavail = fxdr_unsigned(int32_t, sfp->sf_bavail); 231 sbp->f_bavail = fxdr_unsigned(int32_t, sfp->sf_bavail);
233 sbp->f_fresvd = 0; 232 sbp->f_fresvd = 0;
234 sbp->f_files = 0; 233 sbp->f_files = 0;
235 sbp->f_ffree = 0; 234 sbp->f_ffree = 0;
236 sbp->f_favail = 0; 235 sbp->f_favail = 0;
237 sbp->f_fresvd = 0; 236 sbp->f_fresvd = 0;
238 sbp->f_namemax = NFS_MAXNAMLEN; 
239 } 237 }
240 copy_statvfs_info(sbp, mp); 238 copy_statvfs_info(sbp, mp);
241 nfsm_reqdone; 239 nfsm_reqdone;
242 kauth_cred_free(cred); 240 kauth_cred_free(cred);
243 return (error); 241 return (error);
244} 242}
245 243
246#ifndef NFS_V2_ONLY 244#ifndef NFS_V2_ONLY
247/* 245/*
248 * nfs version 3 fsinfo rpc call 246 * nfs version 3 fsinfo rpc call
249 */ 247 */
250int 248int
251nfs_fsinfo(struct nfsmount *nmp, struct vnode *vp, kauth_cred_t cred, struct lwp *l) 249nfs_fsinfo(struct nfsmount *nmp, struct vnode *vp, kauth_cred_t cred, struct lwp *l)
@@ -696,39 +694,40 @@ mountnfs(struct nfs_args *argp, struct m @@ -696,39 +694,40 @@ mountnfs(struct nfs_args *argp, struct m
696 /* 694 /*
697 * If the number of nfs iothreads to use has never 695 * If the number of nfs iothreads to use has never
698 * been set, create a reasonable number of them. 696 * been set, create a reasonable number of them.
699 */ 697 */
700 698
701 if (nfs_niothreads < 0) { 699 if (nfs_niothreads < 0) {
702 nfs_set_niothreads(NFS_DEFAULT_NIOTHREADS); 700 nfs_set_niothreads(NFS_DEFAULT_NIOTHREADS);
703 } 701 }
704 702
705 if (mp->mnt_flag & MNT_UPDATE) { 703 if (mp->mnt_flag & MNT_UPDATE) {
706 nmp = VFSTONFS(mp); 704 nmp = VFSTONFS(mp);
707 /* update paths, file handles, etc, here XXX */ 705 /* update paths, file handles, etc, here XXX */
708 m_freem(nam); 706 m_freem(nam);
709 return (0); 707 return 0;
710 } else { 
711 nmp = kmem_zalloc(sizeof(*nmp), KM_SLEEP); 
712 mp->mnt_data = nmp; 
713 TAILQ_INIT(&nmp->nm_uidlruhead); 
714 TAILQ_INIT(&nmp->nm_bufq); 
715 rw_init(&nmp->nm_writeverflock); 
716 mutex_init(&nmp->nm_lock, MUTEX_DEFAULT, IPL_NONE); 
717 cv_init(&nmp->nm_rcvcv, "nfsrcv"); 
718 cv_init(&nmp->nm_sndcv, "nfssnd"); 
719 cv_init(&nmp->nm_aiocv, "nfsaio"); 
720 cv_init(&nmp->nm_disconcv, "nfsdis"); 
721 } 708 }
 709 nmp = kmem_zalloc(sizeof(*nmp), KM_SLEEP);
 710 TAILQ_INIT(&nmp->nm_uidlruhead);
 711 TAILQ_INIT(&nmp->nm_bufq);
 712 rw_init(&nmp->nm_writeverflock);
 713 mutex_init(&nmp->nm_lock, MUTEX_DEFAULT, IPL_NONE);
 714 cv_init(&nmp->nm_rcvcv, "nfsrcv");
 715 cv_init(&nmp->nm_sndcv, "nfssnd");
 716 cv_init(&nmp->nm_aiocv, "nfsaio");
 717 cv_init(&nmp->nm_disconcv, "nfsdis");
 718
 719 mp->mnt_data = nmp;
 720 mp->mnt_stat.f_namemax = NFS_MAXNAMLEN;
722 vfs_getnewfsid(mp); 721 vfs_getnewfsid(mp);
723 nmp->nm_mountp = mp; 722 nmp->nm_mountp = mp;
724 723
725#ifndef NFS_V2_ONLY 724#ifndef NFS_V2_ONLY
726 if ((argp->flags & NFSMNT_NFSV3) == 0) 725 if ((argp->flags & NFSMNT_NFSV3) == 0)
727#endif 726#endif
728 { 727 {
729 if (argp->fhsize != NFSX_V2FH) { 728 if (argp->fhsize != NFSX_V2FH) {
730 return EINVAL; 729 return EINVAL;
731 } 730 }
732 } 731 }
733 732
734 /* 733 /*