Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/nfs Get rid of dependency on fs_nfs.h, i.e. source modul...



details:   https://anonhg.NetBSD.org/src/rev/271d01c58303
branches:  trunk
changeset: 752655:271d01c58303
user:      pooka <pooka%NetBSD.org@localhost>
date:      Tue Mar 02 23:19:09 2010 +0000

description:
Get rid of dependency on fs_nfs.h, i.e. source modules with
conditional content depending on if the NFS client is wanted or
not.  The server can now be made an independent module not depending
on the nfs client.

Tested with rump_nfs (standalone client), rump_nfsd (standalone
nfsd) and a qemu installation with both the client and the server.

diffstat:

 sys/nfs/files.nfs        |     4 +-
 sys/nfs/nfs.h            |     5 +-
 sys/nfs/nfs_bootparam.c  |     5 +-
 sys/nfs/nfs_clntsocket.c |  1011 ++++++++++++++++++++++++++++++++++++++++++++++
 sys/nfs/nfs_clntsubs.c   |   546 ++++++++++++++++++++++++
 sys/nfs/nfs_socket.c     |   990 +--------------------------------------------
 sys/nfs/nfs_subs.c       |   472 +---------------------
 sys/nfs/nfs_var.h        |    43 +-
 sys/nfs/nfs_vfsops.c     |    34 +-
 9 files changed, 1663 insertions(+), 1447 deletions(-)

diffs (truncated from 3344 to 300 lines):

diff -r 4e137fc06b5a -r 271d01c58303 sys/nfs/files.nfs
--- a/sys/nfs/files.nfs Tue Mar 02 22:00:32 2010 +0000
+++ b/sys/nfs/files.nfs Tue Mar 02 23:19:09 2010 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.nfs,v 1.11 2009/12/31 19:38:16 christos Exp $
+#      $NetBSD: files.nfs,v 1.12 2010/03/02 23:19:09 pooka Exp $
 
 deffs  fs_nfs.h                NFS
 
@@ -22,6 +22,8 @@
 file   nfs/nfs_bootdhcp.c      nfs & (nfs_boot_bootp | nfs_boot_dhcp)
 file   nfs/nfs_bootparam.c     nfs & nfs_boot_bootparam
 file   nfs/nfs_bootstatic.c    nfs & nfs_boot_bootstatic
+file   nfs/nfs_clntsocket.c    nfs
+file   nfs/nfs_clntsubs.c      nfs
 file   nfs/nfs_export.c        nfsserver
 file   nfs/nfs_iod.c           nfs
 file   nfs/nfs_kq.c            nfs
diff -r 4e137fc06b5a -r 271d01c58303 sys/nfs/nfs.h
--- a/sys/nfs/nfs.h     Tue Mar 02 22:00:32 2010 +0000
+++ b/sys/nfs/nfs.h     Tue Mar 02 23:19:09 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nfs.h,v 1.71 2010/01/19 13:29:40 yamt Exp $    */
+/*     $NetBSD: nfs.h,v 1.72 2010/03/02 23:19:09 pooka Exp $   */
 /*
  * Copyright (c) 1989, 1993, 1995
  *     The Regents of the University of California.  All rights reserved.
@@ -68,6 +68,9 @@
 #define        NFS_TRYLATERDELMAX (1*60)       /* Maximum try later delay (sec) */
 #define        NFS_TRYLATERDELMUL 2            /* Exponential backoff multiplier */
 
+#define NFS_CWNDSCALE   256             
+#define NFS_MAXCWND     (NFS_CWNDSCALE * 32)    
+
 /*
  * These can be overridden through <machine/param.h>, included via
  * <sys/param.h>. This means that <sys/param.h> should always be
diff -r 4e137fc06b5a -r 271d01c58303 sys/nfs/nfs_bootparam.c
--- a/sys/nfs/nfs_bootparam.c   Tue Mar 02 22:00:32 2010 +0000
+++ b/sys/nfs/nfs_bootparam.c   Tue Mar 02 23:19:09 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nfs_bootparam.c,v 1.35 2008/11/19 18:36:09 ad Exp $    */
+/*     $NetBSD: nfs_bootparam.c,v 1.36 2010/03/02 23:19:09 pooka Exp $ */
 
 /*-
  * Copyright (c) 1995, 1997 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nfs_bootparam.c,v 1.35 2008/11/19 18:36:09 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nfs_bootparam.c,v 1.36 2010/03/02 23:19:09 pooka Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_nfs_boot.h"
@@ -51,6 +51,7 @@
 #include <sys/reboot.h>
 #include <sys/socket.h>
 #include <sys/socketvar.h>
+#include <sys/vnode.h>
 
 #include <net/if.h>
 #include <net/if_types.h>
diff -r 4e137fc06b5a -r 271d01c58303 sys/nfs/nfs_clntsocket.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/nfs/nfs_clntsocket.c  Tue Mar 02 23:19:09 2010 +0000
@@ -0,0 +1,1011 @@
+/*     $NetBSD: nfs_clntsocket.c,v 1.1 2010/03/02 23:19:09 pooka Exp $ */
+
+/*
+ * Copyright (c) 1989, 1991, 1993, 1995
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Rick Macklem at The University of Guelph.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *     @(#)nfs_socket.c        8.5 (Berkeley) 3/30/95
+ */
+
+/*
+ * Socket operations for use by nfs
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: nfs_clntsocket.c,v 1.1 2010/03/02 23:19:09 pooka Exp $");
+
+#ifdef _KERNEL_OPT
+#include "opt_nfs.h"
+#include "opt_mbuftrace.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/evcnt.h>
+#include <sys/callout.h>
+#include <sys/proc.h>
+#include <sys/mount.h>
+#include <sys/kernel.h>
+#include <sys/kmem.h>
+#include <sys/mbuf.h>
+#include <sys/vnode.h>
+#include <sys/domain.h>
+#include <sys/protosw.h>
+#include <sys/socket.h>
+#include <sys/socketvar.h>
+#include <sys/syslog.h>
+#include <sys/tprintf.h>
+#include <sys/namei.h>
+#include <sys/signal.h>
+#include <sys/signalvar.h>
+#include <sys/kauth.h>
+
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+
+#include <nfs/rpcv2.h>
+#include <nfs/nfsproto.h>
+#include <nfs/nfs.h>
+#include <nfs/xdr_subs.h>
+#include <nfs/nfsm_subs.h>
+#include <nfs/nfsmount.h>
+#include <nfs/nfsnode.h>
+#include <nfs/nfsrtt.h>
+#include <nfs/nfs_var.h>
+
+static int nfs_sndlock(struct nfsmount *, struct nfsreq *);
+static void nfs_sndunlock(struct nfsmount *);
+
+/*
+ * Receive a Sun RPC Request/Reply. For SOCK_DGRAM, the work is all
+ * done by soreceive(), but for SOCK_STREAM we must deal with the Record
+ * Mark and consolidate the data into a new mbuf list.
+ * nb: Sometimes TCP passes the data up to soreceive() in long lists of
+ *     small mbufs.
+ * For SOCK_STREAM we must be very careful to read an entire record once
+ * we have read any of it, even if the system call has been interrupted.
+ */
+static int
+nfs_receive(struct nfsreq *rep, struct mbuf **aname, struct mbuf **mp,
+    struct lwp *l)
+{
+       struct socket *so;
+       struct uio auio;
+       struct iovec aio;
+       struct mbuf *m;
+       struct mbuf *control;
+       u_int32_t len;
+       struct mbuf **getnam;
+       int error, sotype, rcvflg;
+
+       /*
+        * Set up arguments for soreceive()
+        */
+       *mp = NULL;
+       *aname = NULL;
+       sotype = rep->r_nmp->nm_sotype;
+
+       /*
+        * For reliable protocols, lock against other senders/receivers
+        * in case a reconnect is necessary.
+        * For SOCK_STREAM, first get the Record Mark to find out how much
+        * more there is to get.
+        * We must lock the socket against other receivers
+        * until we have an entire rpc request/reply.
+        */
+       if (sotype != SOCK_DGRAM) {
+               error = nfs_sndlock(rep->r_nmp, rep);
+               if (error)
+                       return (error);
+tryagain:
+               /*
+                * Check for fatal errors and resending request.
+                */
+               /*
+                * Ugh: If a reconnect attempt just happened, nm_so
+                * would have changed. NULL indicates a failed
+                * attempt that has essentially shut down this
+                * mount point.
+                */
+               if (rep->r_mrep || (rep->r_flags & R_SOFTTERM)) {
+                       nfs_sndunlock(rep->r_nmp);
+                       return (EINTR);
+               }
+               so = rep->r_nmp->nm_so;
+               if (!so) {
+                       error = nfs_reconnect(rep);
+                       if (error) {
+                               nfs_sndunlock(rep->r_nmp);
+                               return (error);
+                       }
+                       goto tryagain;
+               }
+               while (rep->r_flags & R_MUSTRESEND) {
+                       m = m_copym(rep->r_mreq, 0, M_COPYALL, M_WAIT);
+                       nfsstats.rpcretries++;
+                       rep->r_rtt = 0;
+                       rep->r_flags &= ~R_TIMING;
+                       error = nfs_send(so, rep->r_nmp->nm_nam, m, rep, l);
+                       if (error) {
+                               if (error == EINTR || error == ERESTART ||
+                                   (error = nfs_reconnect(rep)) != 0) {
+                                       nfs_sndunlock(rep->r_nmp);
+                                       return (error);
+                               }
+                               goto tryagain;
+                       }
+               }
+               nfs_sndunlock(rep->r_nmp);
+               if (sotype == SOCK_STREAM) {
+                       aio.iov_base = (void *) &len;
+                       aio.iov_len = sizeof(u_int32_t);
+                       auio.uio_iov = &aio;
+                       auio.uio_iovcnt = 1;
+                       auio.uio_rw = UIO_READ;
+                       auio.uio_offset = 0;
+                       auio.uio_resid = sizeof(u_int32_t);
+                       UIO_SETUP_SYSSPACE(&auio);
+                       do {
+                          rcvflg = MSG_WAITALL;
+                          error = (*so->so_receive)(so, NULL, &auio,
+                               NULL, NULL, &rcvflg);
+                          if (error == EWOULDBLOCK && rep) {
+                               if (rep->r_flags & R_SOFTTERM)
+                                       return (EINTR);
+                               /*
+                                * if it seems that the server died after it
+                                * received our request, set EPIPE so that
+                                * we'll reconnect and retransmit requests.
+                                */
+                               if (rep->r_rexmit >= rep->r_nmp->nm_retry) {
+                                       nfsstats.rpctimeouts++;
+                                       error = EPIPE;
+                               }
+                          }
+                       } while (error == EWOULDBLOCK);
+                       if (!error && auio.uio_resid > 0) {
+                           /*
+                            * Don't log a 0 byte receive; it means
+                            * that the socket has been closed, and
+                            * can happen during normal operation
+                            * (forcible unmount or Solaris server).
+                            */
+                           if (auio.uio_resid != sizeof (u_int32_t))
+                             log(LOG_INFO,
+                                "short receive (%lu/%lu) from nfs server %s\n",
+                                (u_long)sizeof(u_int32_t) - auio.uio_resid,
+                                (u_long)sizeof(u_int32_t),
+                                rep->r_nmp->nm_mountp->mnt_stat.f_mntfromname);
+                           error = EPIPE;
+                       }
+                       if (error)
+                               goto errout;
+                       len = ntohl(len) & ~0x80000000;
+                       /*
+                        * This is SERIOUS! We are out of sync with the sender
+                        * and forcing a disconnect/reconnect is all I can do.
+                        */
+                       if (len > NFS_MAXPACKET) {
+                           log(LOG_ERR, "%s (%d) from nfs server %s\n",
+                               "impossible packet length",
+                               len,
+                               rep->r_nmp->nm_mountp->mnt_stat.f_mntfromname);
+                           error = EFBIG;
+                           goto errout;
+                       }
+                       auio.uio_resid = len;
+                       do {
+                           rcvflg = MSG_WAITALL;
+                           error =  (*so->so_receive)(so, NULL,
+                               &auio, mp, NULL, &rcvflg);
+                       } while (error == EWOULDBLOCK || error == EINTR ||
+                                error == ERESTART);
+                       if (!error && auio.uio_resid > 0) {
+                           if (len != auio.uio_resid)
+                             log(LOG_INFO,
+                               "short receive (%lu/%d) from nfs server %s\n",



Home | Main Index | Thread Index | Old Index