Index: nfs_syscalls.c =================================================================== RCS file: /cvsroot/src/sys/nfs/nfs_syscalls.c,v retrieving revision 1.155 diff -p -u -r1.155 nfs_syscalls.c --- nfs_syscalls.c 5 Sep 2014 09:22:30 -0000 1.155 +++ nfs_syscalls.c 22 Jun 2015 03:44:46 -0000 @@ -99,11 +99,61 @@ struct nfssvc_sock *nfs_udp6sock; static struct nfssvc_sock *nfsrv_sockalloc(void); static void nfsrv_sockfree(struct nfssvc_sock *); static void nfsd_rt(int, struct nfsrv_descript *, int); +static int nfssvc_nfsd(struct nfssvc_copy_ops *, struct nfsd_srvargs *, void *, + struct lwp *); + +static int nfssvc_addsock_in(struct nfsd_args *, const void *); +static int nfssvc_setexports_in(struct mountd_exports_list *, const void *); +static int nfssvc_nsd_in(struct nfsd_srvargs *, const void *); +static int nfssvc_nsd_out(void *, const struct nfsd_srvargs *); +static int nfssvc_exp_in(struct export_args *, const void *, size_t); + +static int +nfssvc_addsock_in(struct nfsd_args *nfsdarg, const void *argp) +{ + + return copyin(argp, nfsdarg, sizeof *nfsdarg); +} + +static int +nfssvc_setexports_in(struct mountd_exports_list *mel, const void *argp) +{ + + return copyin(argp, mel, sizeof *mel); +} + +static int +nfssvc_nsd_in(struct nfsd_srvargs *nsd, const void *argp) +{ + + return copyin(argp, nsd, sizeof *nsd); +} + +static int +nfssvc_nsd_out(void *argp, const struct nfsd_srvargs *nsd) +{ + + return copyout(nsd, argp, sizeof *nsd); +} + +static int +nfssvc_exp_in(struct export_args *exp, const void *argp, size_t nexports) +{ + + return copyin(argp, exp, sizeof(*exp) * nexports); +} /* * NFS server system calls */ +static struct nfssvc_copy_ops native_ops = { + .addsock_in = nfssvc_addsock_in, + .setexports_in = nfssvc_setexports_in, + .nsd_in = nfssvc_nsd_in, + .nsd_out = nfssvc_nsd_out, + .exp_in = nfssvc_exp_in, +}; /* * Nfs server pseudo system call for the nfsd's @@ -112,6 +162,7 @@ static void nfsd_rt(int, struct nfsrv_de * - remains in the kernel as an nfsd * - remains in the kernel as an nfsiod */ + int sys_nfssvc(struct lwp *l, const struct sys_nfssvc_args *uap, register_t *retval) { @@ -119,6 +170,15 @@ sys_nfssvc(struct lwp *l, const struct s syscallarg(int) flag; syscallarg(void *) argp; } */ + int flag = SCARG(uap, flag); + void *argp = SCARG(uap, argp); + + return do_nfssvc(&native_ops, l, flag, argp, retval); +} + +int +do_nfssvc(struct nfssvc_copy_ops *ops, struct lwp *l, int flag, void *argp, register_t *retval) +{ int error; file_t *fp; struct mbuf *nam; @@ -139,14 +199,13 @@ sys_nfssvc(struct lwp *l, const struct s } mutex_exit(&nfsd_lock); - if (SCARG(uap, flag) & NFSSVC_BIOD) { + if (flag & NFSSVC_BIOD) { /* Dummy implementation of nfsios for 1.4 and earlier. */ error = kpause("nfsbiod", true, 0, NULL); - } else if (SCARG(uap, flag) & NFSSVC_MNTD) { + } else if (flag & NFSSVC_MNTD) { error = ENOSYS; - } else if (SCARG(uap, flag) & NFSSVC_ADDSOCK) { - error = copyin(SCARG(uap, argp), (void *)&nfsdarg, - sizeof(nfsdarg)); + } else if (flag & NFSSVC_ADDSOCK) { + error = ops->addsock_in(&nfsdarg, argp); if (error) return (error); /* getsock() will use the descriptor for us */ @@ -171,18 +230,17 @@ sys_nfssvc(struct lwp *l, const struct s } error = nfssvc_addsock(fp, nam); fd_putfile(nfsdarg.sock); - } else if (SCARG(uap, flag) & NFSSVC_SETEXPORTSLIST) { + } else if (flag & NFSSVC_SETEXPORTSLIST) { struct export_args *args; struct mountd_exports_list mel; - error = copyin(SCARG(uap, argp), &mel, sizeof(mel)); + error = ops->setexports_in(&mel, argp); if (error != 0) return error; args = (struct export_args *)malloc(mel.mel_nexports * sizeof(struct export_args), M_TEMP, M_WAITOK); - error = copyin(mel.mel_exports, args, mel.mel_nexports * - sizeof(struct export_args)); + error = ops->exp_in(args, mel.mel_exports, mel.mel_nexports); if (error != 0) { free(args, M_TEMP); return error; @@ -193,10 +251,10 @@ sys_nfssvc(struct lwp *l, const struct s free(args, M_TEMP); } else { - error = copyin(SCARG(uap, argp), (void *)nsd, sizeof (*nsd)); + error = ops->nsd_in(nsd, argp); if (error) return (error); - if ((SCARG(uap, flag) & NFSSVC_AUTHIN) && + if ((flag & NFSSVC_AUTHIN) && ((nfsd = nsd->nsd_nfsd)) != NULL && (nfsd->nfsd_slp->ns_flags & SLP_VALID)) { slp = nfsd->nfsd_slp; @@ -280,10 +338,10 @@ sys_nfssvc(struct lwp *l, const struct s } } } - if ((SCARG(uap, flag) & NFSSVC_AUTHINFAIL) && + if ((flag & NFSSVC_AUTHINFAIL) && (nfsd = nsd->nsd_nfsd)) nfsd->nfsd_flag |= NFSD_AUTHFAIL; - error = nfssvc_nfsd(nsd, SCARG(uap, argp), l); + error = nfssvc_nfsd(ops, nsd, argp, l); } if (error == EINTR || error == ERESTART) error = 0; @@ -415,8 +473,8 @@ nfssvc_addsock(file_t *fp, struct mbuf * * Called by nfssvc() for nfsds. Just loops around servicing rpc requests * until it is killed by a signal. */ -int -nfssvc_nfsd(struct nfsd_srvargs *nsd, void *argp, struct lwp *l) +static int +nfssvc_nfsd(struct nfssvc_copy_ops *ops, struct nfsd_srvargs *nsd, void *argp, struct lwp *l) { struct timeval tv; struct mbuf *m; @@ -564,7 +622,7 @@ nfssvc_nfsd(struct nfsd_srvargs *nsd, vo nsd->nsd_authstr, nfsd->nfsd_authlen) && !copyout(nfsd->nfsd_verfstr, nsd->nsd_verfstr, nfsd->nfsd_verflen) && - !copyout(nsd, argp, sizeof (*nsd))) { + !ops->nsd_out(argp, nsd)) { return (ENEEDAUTH); } cacherep = RC_DROPIT; Index: nfs_var.h =================================================================== RCS file: /cvsroot/src/sys/nfs/nfs_var.h,v retrieving revision 1.92 diff -p -u -r1.92 nfs_var.h --- nfs_var.h 30 May 2014 08:47:45 -0000 1.92 +++ nfs_var.h 22 Jun 2015 03:44:46 -0000 @@ -323,7 +323,6 @@ struct sys_nfssvc_args; int sys_getfh(struct lwp *, const struct sys_getfh_args *, register_t *); int sys_nfssvc(struct lwp *, const struct sys_nfssvc_args *, register_t *); int nfssvc_addsock(struct file *, struct mbuf *); -int nfssvc_nfsd(struct nfsd_srvargs *, void *, struct lwp *); void nfsrv_zapsock(struct nfssvc_sock *); void nfsrv_slpderef(struct nfssvc_sock *); void nfsrv_init(int); @@ -337,6 +336,18 @@ int nfs_getnickauth(struct nfsmount *, k int); int nfs_savenickauth(struct nfsmount *, kauth_cred_t, int, NFSKERBKEY_T, struct mbuf **, char **, struct mbuf *); +/* + * Backend copyin/out functions for nfssvc(2), so that netbsd32 can + * easily access NFS. + */ +struct nfssvc_copy_ops { + int (*addsock_in)(struct nfsd_args *, const void *); + int (*setexports_in)(struct mountd_exports_list *, const void *); + int (*nsd_in)(struct nfsd_srvargs *, const void *); + int (*nsd_out)(void *, const struct nfsd_srvargs *); + int (*exp_in)(struct export_args *, const void *, size_t); +}; +int do_nfssvc(struct nfssvc_copy_ops *, struct lwp *, int, void *, register_t *); /* nfs_export.c */ extern struct nfs_public nfs_pub;