diff options
author | rmacklem <rmacklem@FreeBSD.org> | 2012-12-02 01:16:04 +0000 |
---|---|---|
committer | rmacklem <rmacklem@FreeBSD.org> | 2012-12-02 01:16:04 +0000 |
commit | d79bf0f49f345b1a785c3dab710f032fd51ab28e (patch) | |
tree | a690246f6cf6e94772ffc11582b8695fff296c48 /sys/fs | |
parent | fd7b9e3752e161a90b2d9740f7c6a7f54a0780f1 (diff) | |
download | FreeBSD-src-d79bf0f49f345b1a785c3dab710f032fd51ab28e.zip FreeBSD-src-d79bf0f49f345b1a785c3dab710f032fd51ab28e.tar.gz |
Add an nfssvc() option to the kernel for the new NFS client
which dumps out the actual options being used by an NFS mount.
This will be used to implement a "-m" option for nfsstat(1).
Reviewed by: alfred
MFC after: 2 weeks
Diffstat (limited to 'sys/fs')
-rw-r--r-- | sys/fs/nfs/nfs_var.h | 1 | ||||
-rw-r--r-- | sys/fs/nfsclient/nfs_clport.c | 25 | ||||
-rw-r--r-- | sys/fs/nfsclient/nfs_clvfsops.c | 102 |
3 files changed, 128 insertions, 0 deletions
diff --git a/sys/fs/nfs/nfs_var.h b/sys/fs/nfs/nfs_var.h index e5bacb2..8e68d42 100644 --- a/sys/fs/nfs/nfs_var.h +++ b/sys/fs/nfs/nfs_var.h @@ -313,6 +313,7 @@ void nfsd_init(void); int nfsd_checkrootexp(struct nfsrv_descript *); /* nfs_clvfsops.c */ +void nfscl_retopts(struct nfsmount *, char *, size_t); /* nfs_commonport.c */ int nfsrv_checksockseqnum(struct socket *, tcp_seq); diff --git a/sys/fs/nfsclient/nfs_clport.c b/sys/fs/nfsclient/nfs_clport.c index 1cbf325..fe28975 100644 --- a/sys/fs/nfsclient/nfs_clport.c +++ b/sys/fs/nfsclient/nfs_clport.c @@ -1201,6 +1201,9 @@ nfssvc_nfscl(struct thread *td, struct nfssvc_args *uap) struct nfscbd_args nfscbdarg; struct nfsd_nfscbd_args nfscbdarg2; int error; + struct nameidata nd; + struct nfscl_dumpmntopts dumpmntopts; + char *buf; if (uap->flag & NFSSVC_CBADDSOCK) { error = copyin(uap->argp, (caddr_t)&nfscbdarg, sizeof(nfscbdarg)); @@ -1233,6 +1236,28 @@ nfssvc_nfscl(struct thread *td, struct nfssvc_args *uap) if (error) return (error); error = nfscbd_nfsd(td, &nfscbdarg2); + } else if (uap->flag & NFSSVC_DUMPMNTOPTS) { + error = copyin(uap->argp, &dumpmntopts, sizeof(dumpmntopts)); + if (error == 0 && (dumpmntopts.ndmnt_blen < 256 || + dumpmntopts.ndmnt_blen > 1024)) + error = EINVAL; + if (error == 0) + error = nfsrv_lookupfilename(&nd, + dumpmntopts.ndmnt_fname, td); + if (error == 0 && strcmp(nd.ni_vp->v_mount->mnt_vfc->vfc_name, + "nfs") != 0) { + vput(nd.ni_vp); + error = EINVAL; + } + if (error == 0) { + buf = malloc(dumpmntopts.ndmnt_blen, M_TEMP, M_WAITOK); + nfscl_retopts(VFSTONFS(nd.ni_vp->v_mount), buf, + dumpmntopts.ndmnt_blen); + vput(nd.ni_vp); + error = copyout(buf, dumpmntopts.ndmnt_buf, + dumpmntopts.ndmnt_blen); + free(buf, M_TEMP); + } } else { error = EINVAL; } diff --git a/sys/fs/nfsclient/nfs_clvfsops.c b/sys/fs/nfsclient/nfs_clvfsops.c index 71791fa..41a6b78 100644 --- a/sys/fs/nfsclient/nfs_clvfsops.c +++ b/sys/fs/nfsclient/nfs_clvfsops.c @@ -1627,3 +1627,105 @@ nfs_getnlminfo(struct vnode *vp, uint8_t *fhp, size_t *fhlenp, } } +/* + * This function prints out an option name, based on the conditional + * argument. + */ +static __inline void nfscl_printopt(struct nfsmount *nmp, int testval, + char *opt, char **buf, size_t *blen) +{ + int len; + + if (testval != 0 && *blen > strlen(opt)) { + len = snprintf(*buf, *blen, "%s", opt); + if (len != strlen(opt)) + printf("EEK!!\n"); + *buf += len; + *blen -= len; + } +} + +/* + * This function printf out an options integer value. + */ +static __inline void nfscl_printoptval(struct nfsmount *nmp, int optval, + char *opt, char **buf, size_t *blen) +{ + int len; + + if (*blen > strlen(opt) + 1) { + /* Could result in truncated output string. */ + len = snprintf(*buf, *blen, "%s=%d", opt, optval); + if (len < *blen) { + *buf += len; + *blen -= len; + } + } +} + +/* + * Load the option flags and values into the buffer. + */ +void nfscl_retopts(struct nfsmount *nmp, char *buffer, size_t buflen) +{ + char *buf; + size_t blen; + + buf = buffer; + blen = buflen; + nfscl_printopt(nmp, (nmp->nm_flag & NFSMNT_NFSV4) != 0, "nfsv4", &buf, + &blen); + nfscl_printopt(nmp, (nmp->nm_flag & NFSMNT_NFSV3) != 0, "nfsv3", &buf, + &blen); + nfscl_printopt(nmp, (nmp->nm_flag & (NFSMNT_NFSV3 | NFSMNT_NFSV4)) == 0, + "nfsv2", &buf, &blen); + nfscl_printopt(nmp, nmp->nm_sotype == SOCK_STREAM, ",tcp", &buf, &blen); + nfscl_printopt(nmp, nmp->nm_sotype != SOCK_STREAM, ",udp", &buf, &blen); + nfscl_printopt(nmp, (nmp->nm_flag & NFSMNT_RESVPORT) != 0, ",resvport", + &buf, &blen); + nfscl_printopt(nmp, (nmp->nm_flag & NFSMNT_NOCONN) != 0, ",noconn", + &buf, &blen); + nfscl_printopt(nmp, (nmp->nm_flag & NFSMNT_SOFT) == 0, ",hard", &buf, + &blen); + nfscl_printopt(nmp, (nmp->nm_flag & NFSMNT_SOFT) != 0, ",soft", &buf, + &blen); + nfscl_printopt(nmp, (nmp->nm_flag & NFSMNT_INT) != 0, ",intr", &buf, + &blen); + nfscl_printopt(nmp, (nmp->nm_flag & NFSMNT_NOCTO) == 0, ",cto", &buf, + &blen); + nfscl_printopt(nmp, (nmp->nm_flag & NFSMNT_NOCTO) != 0, ",nocto", &buf, + &blen); + nfscl_printopt(nmp, (nmp->nm_flag & (NFSMNT_NOLOCKD | NFSMNT_NFSV4)) == + 0, ",lockd", &buf, &blen); + nfscl_printopt(nmp, (nmp->nm_flag & (NFSMNT_NOLOCKD | NFSMNT_NFSV4)) == + NFSMNT_NOLOCKD, ",nolockd", &buf, &blen); + nfscl_printopt(nmp, (nmp->nm_flag & NFSMNT_RDIRPLUS) != 0, ",rdirplus", + &buf, &blen); + nfscl_printopt(nmp, (nmp->nm_flag & NFSMNT_KERB) == 0, ",sec=sys", + &buf, &blen); + nfscl_printopt(nmp, (nmp->nm_flag & (NFSMNT_KERB | NFSMNT_INTEGRITY | + NFSMNT_PRIVACY)) == NFSMNT_KERB, ",sec=krb5", &buf, &blen); + nfscl_printopt(nmp, (nmp->nm_flag & (NFSMNT_KERB | NFSMNT_INTEGRITY | + NFSMNT_PRIVACY)) == (NFSMNT_KERB | NFSMNT_INTEGRITY), ",sec=krb5i", + &buf, &blen); + nfscl_printopt(nmp, (nmp->nm_flag & (NFSMNT_KERB | NFSMNT_INTEGRITY | + NFSMNT_PRIVACY)) == (NFSMNT_KERB | NFSMNT_PRIVACY), ",sec=krb5p", + &buf, &blen); + nfscl_printoptval(nmp, nmp->nm_acdirmin, ",acdirmin", &buf, &blen); + nfscl_printoptval(nmp, nmp->nm_acdirmax, ",acdirmax", &buf, &blen); + nfscl_printoptval(nmp, nmp->nm_acregmin, ",acregmin", &buf, &blen); + nfscl_printoptval(nmp, nmp->nm_acregmax, ",acregmax", &buf, &blen); + nfscl_printoptval(nmp, nmp->nm_nametimeo, ",nametimeo", &buf, &blen); + nfscl_printoptval(nmp, nmp->nm_negnametimeo, ",negnametimeo", &buf, + &blen); + nfscl_printoptval(nmp, nmp->nm_rsize, ",rsize", &buf, &blen); + nfscl_printoptval(nmp, nmp->nm_wsize, ",wsize", &buf, &blen); + nfscl_printoptval(nmp, nmp->nm_readdirsize, ",readdirsize", &buf, + &blen); + nfscl_printoptval(nmp, nmp->nm_readahead, ",readahead", &buf, &blen); + nfscl_printoptval(nmp, nmp->nm_wcommitsize, ",wcommitsize", &buf, + &blen); + nfscl_printoptval(nmp, nmp->nm_timeo, ",timeout", &buf, &blen); + nfscl_printoptval(nmp, nmp->nm_retry, ",retrans", &buf, &blen); +} + |