Source-Changes-HG archive

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

[src/trunk]: src/sys add netbsd32 support for nfssvc(2). we do this by defin...



details:   https://anonhg.NetBSD.org/src/rev/f01ca3bbe3f9
branches:  trunk
changeset: 339017:f01ca3bbe3f9
user:      mrg <mrg%NetBSD.org@localhost>
date:      Mon Jun 22 10:35:00 2015 +0000

description:
add netbsd32 support for nfssvc(2).  we do this by defining 5 copyin/out
functions that do all the ugly work, are just plain copyin/out for the
native system calls, and do the necessary translations for netbsd32.

with this i'm able to run 32 bit nfsd and mountd on 64 bit kernel and
mount the file systems remotely.

diffstat:

 sys/compat/netbsd32/files.netbsd32           |    3 +-
 sys/compat/netbsd32/netbsd32.h               |   50 +++++++-
 sys/compat/netbsd32/netbsd32_conv.h          |    3 +-
 sys/compat/netbsd32/netbsd32_nfssvc.c        |  185 +++++++++++++++++++++++++++
 sys/compat/netbsd32/netbsd32_syscall.h       |    5 +-
 sys/compat/netbsd32/netbsd32_syscallargs.h   |   10 +-
 sys/compat/netbsd32/netbsd32_syscalls.c      |    6 +-
 sys/compat/netbsd32/netbsd32_sysent.c        |    9 +-
 sys/compat/netbsd32/netbsd32_systrace_args.c |   28 +++-
 sys/compat/netbsd32/syscalls.master          |    4 +-
 sys/nfs/nfs_syscalls.c                       |   95 +++++++++++--
 sys/nfs/nfs_var.h                            |   18 ++-
 12 files changed, 380 insertions(+), 36 deletions(-)

diffs (truncated from 715 to 300 lines):

diff -r 98a69f5b9aab -r f01ca3bbe3f9 sys/compat/netbsd32/files.netbsd32
--- a/sys/compat/netbsd32/files.netbsd32        Mon Jun 22 08:51:42 2015 +0000
+++ b/sys/compat/netbsd32/files.netbsd32        Mon Jun 22 10:35:00 2015 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.netbsd32,v 1.35 2015/06/20 19:58:40 martin Exp $
+#      $NetBSD: files.netbsd32,v 1.36 2015/06/22 10:35:00 mrg Exp $
 #
 # config file description for machine-independent netbsd32 compat code.
 # included by ports that need it.
@@ -20,6 +20,7 @@
 file   compat/netbsd32/netbsd32_module.c       compat_netbsd32
 file   compat/netbsd32/netbsd32_mod.c          compat_netbsd32
 file   compat/netbsd32/netbsd32_mqueue.c       compat_netbsd32
+file   compat/netbsd32/netbsd32_nfssvc.c       compat_netbsd32 & nfsserver
 file   compat/netbsd32/netbsd32_select.c       compat_netbsd32
 file   compat/netbsd32/netbsd32_sem.c          compat_netbsd32
 file   compat/netbsd32/netbsd32_signal.c       compat_netbsd32
diff -r 98a69f5b9aab -r f01ca3bbe3f9 sys/compat/netbsd32/netbsd32.h
--- a/sys/compat/netbsd32/netbsd32.h    Mon Jun 22 08:51:42 2015 +0000
+++ b/sys/compat/netbsd32/netbsd32.h    Mon Jun 22 10:35:00 2015 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: netbsd32.h,v 1.106 2015/06/21 14:03:38 mrg Exp $       */
+/*     $NetBSD: netbsd32.h,v 1.107 2015/06/22 10:35:00 mrg Exp $       */
 
 /*
- * Copyright (c) 1998, 2001, 2008 Matthew R. Green
+ * Copyright (c) 1998, 2001, 2008, 2015 Matthew R. Green
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -50,6 +50,8 @@
 #include <compat/sys/mount.h>
 #include <compat/sys/signal.h>
 
+#include <nfs/rpcv2.h>
+
 /*
  * first, define the basic types we need.
  */
@@ -945,6 +947,48 @@
        netbsd32_u_long         size;
 };
 
+/* from <nfs/nfs.h> */
+struct netbsd32_nfsd_args {
+       int             sock;
+       netbsd32_voidp  name;
+       int             namelen;
+};
+
+typedef netbsd32_pointer_t netbsd32_nfsdp;
+struct netbsd32_nfsd_srvargs {
+       netbsd32_nfsdp  nsd_nfsd;
+       uid_t           nsd_uid;
+       u_int32_t       nsd_haddr;
+       struct uucred   nsd_cr;
+       int             nsd_authlen;
+       netbsd32_u_charp nsd_authstr;
+       int             nsd_verflen;
+       netbsd32_u_charp nsd_verfstr;
+       struct netbsd32_timeval nsd_timestamp;
+       u_int32_t       nsd_ttl;
+       NFSKERBKEY_T    nsd_key;
+};
+
+typedef netbsd32_pointer_t netbsd32_export_argsp;
+struct netbsd32_export_args {
+       int             ex_flags;
+       uid_t           ex_root;
+       struct uucred   ex_anon;
+       netbsd32_sockaddrp_t ex_addr;
+       int             ex_addrlen;
+       netbsd32_sockaddrp_t ex_mask;
+       int             ex_masklen;
+       netbsd32_charp  ex_indexfile;
+};
+
+struct netbsd32_mountd_exports_list {
+       const netbsd32_charp    mel_path;
+       netbsd32_size_t         mel_nexports;
+       netbsd32_export_argsp   mel_exports;
+};
+
+/* no struct export_args30 yet */
+
 /* from <nfs/nfsmount,h> */
 struct netbsd32_nfs_args {
        int32_t         version;        /* args structure version number */
@@ -966,6 +1010,8 @@
        int32_t         deadthresh;     /* Retrans threshold */
        netbsd32_charp  hostname;       /* server's name */
 };
+
+/* from <msdosfs/msdosfsmount.h> */
 struct netbsd32_msdosfs_args {
        netbsd32_charp  fspec;          /* blocks special holding the fs to mount */
        struct  netbsd32_export_args30 _pad1; /* compat with old userland tools */
diff -r 98a69f5b9aab -r f01ca3bbe3f9 sys/compat/netbsd32/netbsd32_conv.h
--- a/sys/compat/netbsd32/netbsd32_conv.h       Mon Jun 22 08:51:42 2015 +0000
+++ b/sys/compat/netbsd32/netbsd32_conv.h       Mon Jun 22 10:35:00 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: netbsd32_conv.h,v 1.29 2015/06/20 19:58:40 martin Exp $        */
+/*     $NetBSD: netbsd32_conv.h,v 1.30 2015/06/22 10:35:00 mrg Exp $   */
 
 /*
  * Copyright (c) 1998, 2001 Matthew R. Green
@@ -39,6 +39,7 @@
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/kernel.h>
+#include <sys/dirent.h>
 #include <sys/ipc.h>
 #include <sys/msg.h>
 #define msg __msg /* Don't ask me! */
diff -r 98a69f5b9aab -r f01ca3bbe3f9 sys/compat/netbsd32/netbsd32_nfssvc.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/compat/netbsd32/netbsd32_nfssvc.c     Mon Jun 22 10:35:00 2015 +0000
@@ -0,0 +1,185 @@
+/*     $NetBSD: netbsd32_nfssvc.c,v 1.1 2015/06/22 10:35:00 mrg Exp $  */
+
+/*
+ * Copyright (c) 2015 Matthew R. Green
+ * All rights reserved.
+ *
+ * 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. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_nfssvc.c,v 1.1 2015/06/22 10:35:00 mrg Exp $");
+
+#if defined(_KERNEL_OPT)
+#include "opt_nfs.h"
+#include "opt_compat_netbsd.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/vnode.h>
+#include <sys/filedesc.h>
+
+#include <compat/netbsd32/netbsd32.h>
+#include <compat/netbsd32/netbsd32_syscall.h>
+#include <compat/netbsd32/netbsd32_syscallargs.h>
+#include <compat/netbsd32/netbsd32_conv.h>
+
+#include <nfs/rpcv2.h>
+#include <nfs/nfsproto.h>
+#include <nfs/nfs.h>
+#include <nfs/nfs_var.h>
+
+static int nfssvc32_addsock_in(struct nfsd_args *, const void *);
+static int nfssvc32_setexports_in(struct mountd_exports_list *, const void *);
+static int nfssvc32_nsd_in(struct nfsd_srvargs *, const void *);
+static int nfssvc32_nsd_out(void *, const struct nfsd_srvargs *);
+static int nfssvc32_exp_in(struct export_args *, const void *, size_t);
+
+static int
+nfssvc32_addsock_in(struct nfsd_args *nfsdarg, const void *argp)
+{
+       struct netbsd32_nfsd_args args32;
+       int error;
+
+       error = copyin(argp, &args32, sizeof args32);
+       if (!error) {
+               nfsdarg->sock = args32.sock;
+               nfsdarg->name = NETBSD32PTR64(args32.name);
+               nfsdarg->namelen = args32.namelen;
+       }
+
+       return error;
+}
+
+static int
+nfssvc32_setexports_in(struct mountd_exports_list *mel, const void *argp)
+{
+       struct netbsd32_mountd_exports_list args32;
+       int error;
+
+       error = copyin(argp, &args32, sizeof args32);
+       if (!error) {
+               mel->mel_path = NETBSD32PTR64(args32.mel_path);
+               mel->mel_nexports = args32.mel_nexports;
+               mel->mel_exports = NETBSD32PTR64(args32.mel_exports);
+       }
+
+       return error;
+}
+
+static int
+nfssvc32_nsd_in(struct nfsd_srvargs *nsd, const void *argp)
+{
+       struct netbsd32_nfsd_srvargs args32;
+       int error;
+
+       error = copyin(argp, &args32, sizeof args32);
+       if (!error) {
+               nsd->nsd_nfsd = NETBSD32PTR64(args32.nsd_nfsd);
+               nsd->nsd_uid = args32.nsd_uid;
+               nsd->nsd_haddr = args32.nsd_haddr;
+               nsd->nsd_cr = args32.nsd_cr;
+               nsd->nsd_authlen = args32.nsd_authlen;
+               nsd->nsd_authstr = NETBSD32PTR64(args32.nsd_authstr);
+               nsd->nsd_verflen = args32.nsd_verflen;
+               nsd->nsd_uid = args32.nsd_uid;
+               netbsd32_to_timeval(&args32.nsd_timestamp, &nsd->nsd_timestamp);
+               nsd->nsd_ttl = args32.nsd_ttl;
+               nsd->nsd_key[0] = args32.nsd_key[0];
+               nsd->nsd_key[1] = args32.nsd_key[1];
+       }
+
+       return error;
+}
+
+static int
+nfssvc32_nsd_out(void *argp, const struct nfsd_srvargs *nsd)
+{
+       struct netbsd32_nfsd_srvargs args32;
+
+       NETBSD32PTR32(args32.nsd_nfsd, nsd->nsd_nfsd);
+       args32.nsd_uid = nsd->nsd_uid;
+       args32.nsd_haddr = nsd->nsd_haddr;
+       args32.nsd_cr = nsd->nsd_cr;
+       args32.nsd_authlen = nsd->nsd_authlen;
+       NETBSD32PTR32(args32.nsd_authstr, nsd->nsd_authstr);
+       args32.nsd_verflen = nsd->nsd_verflen;
+       args32.nsd_uid = nsd->nsd_uid;
+       netbsd32_from_timeval(&nsd->nsd_timestamp, &args32.nsd_timestamp);
+       args32.nsd_ttl = nsd->nsd_ttl;
+       args32.nsd_key[0] = nsd->nsd_key[0];
+       args32.nsd_key[1] = nsd->nsd_key[1];
+
+       return copyout(nsd, argp, sizeof *nsd);
+}
+
+static int
+nfssvc32_exp_in(struct export_args *exp, const void *argp, size_t nexports)
+{
+       struct netbsd32_export_args args32;
+       int error = 0;
+
+       for (size_t i = 0; i < nexports; i++) {
+               error = copyin(argp, &args32, sizeof args32);
+               if (error)
+                       break;
+               exp->ex_flags = args32.ex_flags;
+               exp->ex_root = args32.ex_root;
+               exp->ex_anon = args32.ex_anon;
+               exp->ex_addr = NETBSD32PTR64(args32.ex_addr);
+               exp->ex_addrlen = args32.ex_addrlen;
+               exp->ex_mask = NETBSD32PTR64(args32.ex_mask);
+               exp->ex_masklen = args32.ex_masklen;
+               exp->ex_indexfile = NETBSD32PTR64(args32.ex_indexfile);
+               exp++;
+       }
+
+       return error;
+}
+
+/*
+ * NFS server system calls
+ */
+
+static struct nfssvc_copy_ops netbsd32_ops = {
+       .addsock_in = nfssvc32_addsock_in,
+       .setexports_in = nfssvc32_setexports_in,
+       .nsd_in = nfssvc32_nsd_in,
+       .nsd_out = nfssvc32_nsd_out,
+       .exp_in = nfssvc32_exp_in,
+};
+
+int
+netbsd32_nfssvc(struct lwp *l, const struct netbsd32_nfssvc_args *uap,
+    register_t *retval)
+{
+       /* {
+               syscallarg(int) flag;
+               syscallarg(netbsd32_voidp *) argp;
+       } */
+       int     flag = SCARG(uap, flag);
+       void    *argp = SCARG_P32(uap, argp);



Home | Main Index | Thread Index | Old Index