Gerald Pfeifer <[EMAIL PROTECTED]> writes:
> What I'd like to see is `mount -v' printing
> 
>   vexpert:/files5 on /.amd_mnt/vexpert/files5 (nfs: v3, udp)
>                                                ^^^^^^^^^^^^
> instead of
> 
>   vexpert:/files5 on /.amd_mnt/vexpert/files5 (nfs)
>                                                ^^^
> This kind of information is incredibly useful for debugging, yet I
> haven't found ANY way to obtain it, let alone such a natural one.

IIRC tcpdump can detect NFS3 vs. NFS2, but that's suboptimal.

Implementing the above functionality in mount(8) isn't actually that
hard.  We would need to export the filesystem-specific <fs>_args
structures (e.g., nfs_args, ffs_args) to the userland.  If we do that,
mount(8) will be able to display all kinds of interesting,
filesystem-specific stuff (e.g., NFS version and transport, whether a
mounted CDROM is using Joilet, etc.).

I tried to export this stuff in struct statfs, but ran into a problem:
I'd need the complete definitions of <fs>_args in <sys/mount.h>, but I
can't include, e.g., <nfs/nfs.h> because the latter includes the
former (<sys/mount.h>)!

The patch below kind of implements this functionality.  I only export
nfs_args (not <otherfs>_args), and I only modified mount(8) to print
the NFS version, but printing the transport and others is simple from
there.  To work around the above problem, I pasted the struct nfs_args
definition into mount.h.  It is *horribly* ugly, but it does work.

If some other people display intrest in this, and someone can suggest
a less ugly way of getting the definitions of <fs>_args into mount.h
(the only other way I can think of is to just move all of them from
<fs>/<fs>.h to mount.h permamently), I'll implement this stuff in the
other filesystems.

Regards

                                        Dima Dorfman
                                        [EMAIL PROTECTED]

P.S.  If you want to try the patch, you'll need to rebuild at least
the kernel, libc, mount, mountd, and amd, since the size of struct
statfs changes.  I only did those, and it seems to work on my system.

Index: sys/sys/mount.h
===================================================================
RCS file: /st/src/FreeBSD/src/sys/sys/mount.h,v
retrieving revision 1.102
diff -u -r1.102 mount.h
--- sys/sys/mount.h     2001/03/01 20:59:59     1.102
+++ sys/sys/mount.h     2001/03/24 22:03:13
@@ -69,6 +69,44 @@
 #define        MNAMELEN        72      /* length of buffer for returned name */
 #endif
 
+/* XXXDD: from src/sys/nfs/nfs.h! fixme! */
+/*
+ * Arguments to mount NFS
+ */
+#ifndef NFS_ARGS_DEFINED
+#define NFS_ARGS_DEFINED
+#define NFS_ARGSVERSION        3               /* change when nfs_args changes */
+struct nfs_args {
+       int             version;        /* args structure version number */
+       struct sockaddr *addr;          /* file server address */
+       int             addrlen;        /* length of address */
+       int             sotype;         /* Socket type */
+       int             proto;          /* and Protocol */
+       u_char          *fh;            /* File handle to be mounted */
+       int             fhsize;         /* Size, in bytes, of fh */
+       int             flags;          /* flags */
+       int             wsize;          /* write size in bytes */
+       int             rsize;          /* read size in bytes */
+       int             readdirsize;    /* readdir size in bytes */
+       int             timeo;          /* initial timeout in .1 secs */
+       int             retrans;        /* times to retry send */
+       int             maxgrouplist;   /* Max. size of group list */
+       int             readahead;      /* # of blocks to readahead */
+       int             leaseterm;      /* Term (sec) of lease */
+       int             deadthresh;     /* Retrans threshold */
+       char            *hostname;      /* server's name */
+       int             acregmin;       /* cache attrs for reg files min time */
+       int             acregmax;       /* cache attrs for reg files max time */
+       int             acdirmin;       /* cache attrs for dirs min time */
+       int             acdirmax;       /* cache attrs for dirs max time */
+};
+#endif /* !NFS_ARGS_DEFINED */
+
+/* filesystem-specific mount options */
+union mount_info {
+       struct nfs_args nfs;
+};
+
 struct statfs {
        long    f_spare2;               /* placeholder */
        long    f_bsize;                /* fundamental file system block size */
@@ -92,6 +130,7 @@
        char    f_mntfromname[MNAMELEN];/* mounted filesystem */
        short   f_spares2;              /* unused spare */
        long    f_spare[2];             /* unused spare */
+       union mount_info f_mtinfo;      /* filesystem-specific mount info */
 };
 
 #ifdef _KERNEL
Index: sys/nfs/nfs.h
===================================================================
RCS file: /st/src/FreeBSD/src/sys/nfs/nfs.h,v
retrieving revision 1.57
diff -u -r1.57 nfs.h
--- sys/nfs/nfs.h       2001/02/18 13:30:19     1.57
+++ sys/nfs/nfs.h       2001/03/24 22:03:13
@@ -116,6 +116,8 @@
 /*
  * Arguments to mount NFS
  */
+#ifndef NFS_ARGS_DEFINED
+#define NFS_ARGS_DEFINED
 #define NFS_ARGSVERSION        3               /* change when nfs_args changes */
 struct nfs_args {
        int             version;        /* args structure version number */
@@ -141,6 +143,7 @@
        int             acdirmin;       /* cache attrs for dirs min time */
        int             acdirmax;       /* cache attrs for dirs max time */
 };
+#endif /* !NFS_ARGS_DEFINED */
 
 /*
  * NFS mount option flags
Index: sys/nfs/nfs_vfsops.c
===================================================================
RCS file: /st/src/FreeBSD/src/sys/nfs/nfs_vfsops.c,v
retrieving revision 1.94
diff -u -r1.94 nfs_vfsops.c
--- sys/nfs/nfs_vfsops.c        2001/03/01 20:59:19     1.94
+++ sys/nfs/nfs_vfsops.c        2001/03/24 22:03:14
@@ -307,6 +307,9 @@
                sbp->f_type = mp->mnt_vfc->vfc_typenum;
                bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
                bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
+               bcopy((caddr_t)&mp->mnt_stat.f_mtinfo.nfs,
+                   (caddr_t)&sbp->f_mtinfo.nfs,
+                   sizeof(mp->mnt_stat.f_mtinfo.nfs));
        }
        nfsm_reqdone;
        vput(vp);
@@ -892,6 +895,7 @@
        bcopy((caddr_t)argp->fh, (caddr_t)nmp->nm_fh, argp->fhsize);
        bcopy(hst, mp->mnt_stat.f_mntfromname, MNAMELEN);
        bcopy(pth, mp->mnt_stat.f_mntonname, MNAMELEN);
+       bcopy(argp, &mp->mnt_stat.f_mtinfo.nfs, sizeof(*argp));
        nmp->nm_nam = nam;
        /* Set up the sockets and per-host congestion */
        nmp->nm_sotype = argp->sotype;
Index: sbin/mount/mount.c
===================================================================
RCS file: /st/src/FreeBSD/src/sbin/mount/mount.c,v
retrieving revision 1.41
diff -u -r1.41 mount.c
--- sbin/mount/mount.c  2000/11/22 17:54:56     1.41
+++ sbin/mount/mount.c  2001/03/24 22:03:14
@@ -50,6 +50,9 @@
 #include <sys/stat.h>
 #include <sys/wait.h>
 
+#include <nfs/rpcv2.h>
+#include <nfs/nfs.h>
+
 #include <err.h>
 #include <errno.h>
 #include <fstab.h>
@@ -530,6 +533,20 @@
                        (void)printf(", reads: sync %ld async %ld",
                            sfp->f_syncreads, sfp->f_asyncreads);
        }
+
+       /*
+        * File-system specific options.
+        */
+       if (strcmp(sfp->f_fstypename, "nfs") == 0) {
+               struct nfs_args *nfsa = &sfp->f_mtinfo.nfs;
+
+               if (nfsa->version != NFS_ARGSVERSION) {
+                       (void)printf("\n");
+                       errx(1, "nfs_args version mismatch");
+               }
+               (void)printf(", %s",
+                   (nfsa->flags & NFSMNT_NFSV3) ? "v3" : "v2");
+       }
        (void)printf(")\n");
 }
 

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to