17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5da6c28aaSamw * Common Development and Distribution License (the "License").
6da6c28aaSamw * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
22*9fe74b0bSGary Mills * Copyright 2014 Gary Mills
23d3d50737SRafael Vanoni * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate /*
287c478bd9Sstevel@tonic-gate * Dump memory to NFS swap file after a panic.
297c478bd9Sstevel@tonic-gate * We have no timeouts, context switches, etc.
307c478bd9Sstevel@tonic-gate */
31d3d50737SRafael Vanoni
327c478bd9Sstevel@tonic-gate #include <rpc/types.h>
337c478bd9Sstevel@tonic-gate #include <sys/param.h>
347c478bd9Sstevel@tonic-gate #include <sys/errno.h>
357c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
367c478bd9Sstevel@tonic-gate #include <sys/bootconf.h>
377c478bd9Sstevel@tonic-gate #include <nfs/nfs.h>
387c478bd9Sstevel@tonic-gate #include <rpc/auth.h>
397c478bd9Sstevel@tonic-gate #include <rpc/xdr.h>
407c478bd9Sstevel@tonic-gate #include <rpc/rpc_msg.h>
417c478bd9Sstevel@tonic-gate #include <rpc/clnt.h>
427c478bd9Sstevel@tonic-gate #include <netinet/in.h>
437c478bd9Sstevel@tonic-gate #include <sys/tiuser.h>
447c478bd9Sstevel@tonic-gate #include <nfs/nfs_clnt.h>
457c478bd9Sstevel@tonic-gate #include <sys/t_kuser.h>
467c478bd9Sstevel@tonic-gate #include <sys/file.h>
477c478bd9Sstevel@tonic-gate #include <sys/netconfig.h>
487c478bd9Sstevel@tonic-gate #include <sys/utsname.h>
497c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
507c478bd9Sstevel@tonic-gate #include <sys/thread.h>
517c478bd9Sstevel@tonic-gate #include <sys/cred.h>
527c478bd9Sstevel@tonic-gate #include <sys/strsubr.h>
537c478bd9Sstevel@tonic-gate #include <nfs/rnode.h>
547c478bd9Sstevel@tonic-gate #include <sys/varargs.h>
557c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
567c478bd9Sstevel@tonic-gate #include <sys/systm.h>
577c478bd9Sstevel@tonic-gate #include <sys/dumphdr.h>
587c478bd9Sstevel@tonic-gate #include <sys/debug.h>
597c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gate #define TIMEOUT (2 * hz)
627c478bd9Sstevel@tonic-gate #define RETRIES (5)
637c478bd9Sstevel@tonic-gate #define HDR_SIZE (256)
647c478bd9Sstevel@tonic-gate
657c478bd9Sstevel@tonic-gate static struct knetconfig nfsdump_cf;
667c478bd9Sstevel@tonic-gate static struct netbuf nfsdump_addr;
677c478bd9Sstevel@tonic-gate static fhandle_t nfsdump_fhandle2;
687c478bd9Sstevel@tonic-gate static nfs_fh3 nfsdump_fhandle3;
697c478bd9Sstevel@tonic-gate static int nfsdump_maxcount;
707c478bd9Sstevel@tonic-gate static rpcvers_t nfsdump_version;
717c478bd9Sstevel@tonic-gate
727c478bd9Sstevel@tonic-gate /*
737c478bd9Sstevel@tonic-gate * nonzero dumplog enables nd_log messages
747c478bd9Sstevel@tonic-gate */
757c478bd9Sstevel@tonic-gate static int dumplog = 0;
767c478bd9Sstevel@tonic-gate
777c478bd9Sstevel@tonic-gate static int nd_init(vnode_t *, TIUSER **);
787c478bd9Sstevel@tonic-gate static int nd_poll(TIUSER *, int, int *);
797c478bd9Sstevel@tonic-gate static int nd_send_data(TIUSER *, caddr_t, int, XDR *, uint32_t *);
807c478bd9Sstevel@tonic-gate static int nd_get_reply(TIUSER *, XDR *, uint32_t, int *);
817c478bd9Sstevel@tonic-gate static int nd_auth_marshall(XDR *);
827c478bd9Sstevel@tonic-gate
837c478bd9Sstevel@tonic-gate static void nd_log(const char *, ...) __KPRINTFLIKE(1);
847c478bd9Sstevel@tonic-gate
857c478bd9Sstevel@tonic-gate /*PRINTFLIKE1*/
867c478bd9Sstevel@tonic-gate static void
nd_log(const char * fmt,...)877c478bd9Sstevel@tonic-gate nd_log(const char *fmt, ...)
887c478bd9Sstevel@tonic-gate {
897c478bd9Sstevel@tonic-gate if (dumplog) {
907c478bd9Sstevel@tonic-gate va_list adx;
917c478bd9Sstevel@tonic-gate
927c478bd9Sstevel@tonic-gate va_start(adx, fmt);
937c478bd9Sstevel@tonic-gate vprintf(fmt, adx);
947c478bd9Sstevel@tonic-gate va_end(adx);
957c478bd9Sstevel@tonic-gate }
967c478bd9Sstevel@tonic-gate }
977c478bd9Sstevel@tonic-gate
98da6c28aaSamw /* ARGSUSED */
997c478bd9Sstevel@tonic-gate int
nfs_dump(vnode_t * dumpvp,caddr_t addr,offset_t bn,offset_t count,caller_context_t * ct)100d7334e51Srm15945 nfs_dump(vnode_t *dumpvp, caddr_t addr, offset_t bn, offset_t count,
101d7334e51Srm15945 caller_context_t *ct)
1027c478bd9Sstevel@tonic-gate {
1037c478bd9Sstevel@tonic-gate static TIUSER *tiptr;
1047c478bd9Sstevel@tonic-gate XDR xdrs;
1057c478bd9Sstevel@tonic-gate int reply;
1067c478bd9Sstevel@tonic-gate int badmsg;
1077c478bd9Sstevel@tonic-gate uint32_t call_xid;
1087c478bd9Sstevel@tonic-gate int retry = 0;
1097c478bd9Sstevel@tonic-gate int error;
1107c478bd9Sstevel@tonic-gate int i;
1117c478bd9Sstevel@tonic-gate
112d7334e51Srm15945 nd_log("nfs_dump: addr=%p bn=%lld count=%lld\n",
113d7334e51Srm15945 (void *)addr, bn, count);
1147c478bd9Sstevel@tonic-gate
1157c478bd9Sstevel@tonic-gate if (error = nd_init(dumpvp, &tiptr))
1167c478bd9Sstevel@tonic-gate return (error);
1177c478bd9Sstevel@tonic-gate
1187c478bd9Sstevel@tonic-gate for (i = 0; i < count; i += ptod(1), addr += ptob(1)) {
1197c478bd9Sstevel@tonic-gate do {
1207c478bd9Sstevel@tonic-gate error = nd_send_data(tiptr, addr, (int)dbtob(bn + i),
1217c478bd9Sstevel@tonic-gate &xdrs, &call_xid);
1227c478bd9Sstevel@tonic-gate if (error)
1237c478bd9Sstevel@tonic-gate return (error);
1247c478bd9Sstevel@tonic-gate
1257c478bd9Sstevel@tonic-gate do {
1267c478bd9Sstevel@tonic-gate if (error = nd_poll(tiptr, retry, &reply))
1277c478bd9Sstevel@tonic-gate return (error);
1287c478bd9Sstevel@tonic-gate
1297c478bd9Sstevel@tonic-gate if (!reply) {
1307c478bd9Sstevel@tonic-gate retry++;
1317c478bd9Sstevel@tonic-gate break;
1327c478bd9Sstevel@tonic-gate }
1337c478bd9Sstevel@tonic-gate retry = 0;
1347c478bd9Sstevel@tonic-gate
1357c478bd9Sstevel@tonic-gate error = nd_get_reply(tiptr, &xdrs, call_xid,
1367c478bd9Sstevel@tonic-gate &badmsg);
1377c478bd9Sstevel@tonic-gate if (error)
1387c478bd9Sstevel@tonic-gate return (error);
1397c478bd9Sstevel@tonic-gate } while (badmsg);
1407c478bd9Sstevel@tonic-gate } while (retry);
1417c478bd9Sstevel@tonic-gate }
1427c478bd9Sstevel@tonic-gate
1437c478bd9Sstevel@tonic-gate return (0);
1447c478bd9Sstevel@tonic-gate }
1457c478bd9Sstevel@tonic-gate
1467c478bd9Sstevel@tonic-gate static int
nd_init(vnode_t * dumpvp,TIUSER ** tiptr)1477c478bd9Sstevel@tonic-gate nd_init(vnode_t *dumpvp, TIUSER **tiptr)
1487c478bd9Sstevel@tonic-gate {
1497c478bd9Sstevel@tonic-gate int error;
1507c478bd9Sstevel@tonic-gate
1517c478bd9Sstevel@tonic-gate if (*tiptr)
1527c478bd9Sstevel@tonic-gate return (0);
1537c478bd9Sstevel@tonic-gate
1547c478bd9Sstevel@tonic-gate /*
1557c478bd9Sstevel@tonic-gate * If dump info hasn't yet been initialized (because dump
1567c478bd9Sstevel@tonic-gate * device was chosen at user-level, rather than at boot time
1577c478bd9Sstevel@tonic-gate * in nfs_swapvp) fill it in now.
1587c478bd9Sstevel@tonic-gate */
1597c478bd9Sstevel@tonic-gate if (nfsdump_maxcount == 0) {
1607c478bd9Sstevel@tonic-gate nfsdump_version = VTOMI(dumpvp)->mi_vers;
1617c478bd9Sstevel@tonic-gate switch (nfsdump_version) {
1627c478bd9Sstevel@tonic-gate case NFS_VERSION:
1637c478bd9Sstevel@tonic-gate nfsdump_fhandle2 = *VTOFH(dumpvp);
1647c478bd9Sstevel@tonic-gate break;
1657c478bd9Sstevel@tonic-gate case NFS_V3:
1667c478bd9Sstevel@tonic-gate nfsdump_fhandle3 = *VTOFH3(dumpvp);
1677c478bd9Sstevel@tonic-gate break;
1687c478bd9Sstevel@tonic-gate default:
1697c478bd9Sstevel@tonic-gate return (EIO);
1707c478bd9Sstevel@tonic-gate }
1717c478bd9Sstevel@tonic-gate nfsdump_maxcount = (int)dumpvp_size;
1727c478bd9Sstevel@tonic-gate nfsdump_addr = VTOMI(dumpvp)->mi_curr_serv->sv_addr;
1737c478bd9Sstevel@tonic-gate nfsdump_cf = *(VTOMI(dumpvp)->mi_curr_serv->sv_knconf);
1747c478bd9Sstevel@tonic-gate if (nfsdump_cf.knc_semantics != NC_TPI_CLTS) {
1757c478bd9Sstevel@tonic-gate int v6 = 1;
1767c478bd9Sstevel@tonic-gate nd_log("nfs_dump: not connectionless!\n");
1777c478bd9Sstevel@tonic-gate if ((strcmp(nfsdump_cf.knc_protofmly, NC_INET) == 0) ||
1787c478bd9Sstevel@tonic-gate ((v6 = strcmp(nfsdump_cf.knc_protofmly, NC_INET6))\
1797c478bd9Sstevel@tonic-gate == 0)) {
1807c478bd9Sstevel@tonic-gate major_t clone_maj;
1817c478bd9Sstevel@tonic-gate
1827c478bd9Sstevel@tonic-gate nfsdump_cf.knc_proto = NC_UDP;
1837c478bd9Sstevel@tonic-gate nfsdump_cf.knc_semantics = NC_TPI_CLTS;
1847c478bd9Sstevel@tonic-gate nd_log("nfs_dump: grabbing UDP major number\n");
1857c478bd9Sstevel@tonic-gate clone_maj = ddi_name_to_major("clone");
1867c478bd9Sstevel@tonic-gate nd_log("nfs_dump: making UDP device\n");
1877c478bd9Sstevel@tonic-gate nfsdump_cf.knc_rdev = makedevice(clone_maj,
1887c478bd9Sstevel@tonic-gate ddi_name_to_major(v6?"udp":"udp6"));
1897c478bd9Sstevel@tonic-gate } else {
1907c478bd9Sstevel@tonic-gate error = EIO;
1917c478bd9Sstevel@tonic-gate nfs_perror(error, "\nnfs_dump: cannot dump over"
1927c478bd9Sstevel@tonic-gate " protocol %s: %m\n", nfsdump_cf.knc_proto);
1937c478bd9Sstevel@tonic-gate return (error);
1947c478bd9Sstevel@tonic-gate }
1957c478bd9Sstevel@tonic-gate }
1967c478bd9Sstevel@tonic-gate }
1977c478bd9Sstevel@tonic-gate
1987c478bd9Sstevel@tonic-gate nd_log("nfs_dump: calling t_kopen\n");
1997c478bd9Sstevel@tonic-gate
2007c478bd9Sstevel@tonic-gate if (error = t_kopen(NULL, nfsdump_cf.knc_rdev,
2017c478bd9Sstevel@tonic-gate FREAD|FWRITE|FNDELAY, tiptr, CRED())) {
2027c478bd9Sstevel@tonic-gate nfs_perror(error, "\nnfs_dump: t_kopen failed: %m\n");
2037c478bd9Sstevel@tonic-gate return (EIO);
2047c478bd9Sstevel@tonic-gate }
2057c478bd9Sstevel@tonic-gate
2067c478bd9Sstevel@tonic-gate if ((strcmp(nfsdump_cf.knc_protofmly, NC_INET) == 0) ||
2077c478bd9Sstevel@tonic-gate (strcmp(nfsdump_cf.knc_protofmly, NC_INET6) == 0)) {
2087c478bd9Sstevel@tonic-gate nd_log("nfs_dump: calling bindresvport\n");
2097c478bd9Sstevel@tonic-gate if (error = bindresvport(*tiptr, NULL, NULL, FALSE)) {
2107c478bd9Sstevel@tonic-gate nfs_perror(error,
2117c478bd9Sstevel@tonic-gate "\nnfs_dump: bindresvport failed: %m\n");
2127c478bd9Sstevel@tonic-gate return (EIO);
2137c478bd9Sstevel@tonic-gate }
2147c478bd9Sstevel@tonic-gate } else {
2157c478bd9Sstevel@tonic-gate nd_log("nfs_dump: calling t_kbind\n");
2167c478bd9Sstevel@tonic-gate if ((error = t_kbind(*tiptr, NULL, NULL)) != 0) {
2177c478bd9Sstevel@tonic-gate nfs_perror(error, "\nnfs_dump: t_kbind failed: %m\n");
2187c478bd9Sstevel@tonic-gate return (EIO);
2197c478bd9Sstevel@tonic-gate }
2207c478bd9Sstevel@tonic-gate }
2217c478bd9Sstevel@tonic-gate return (0);
2227c478bd9Sstevel@tonic-gate }
2237c478bd9Sstevel@tonic-gate
2247c478bd9Sstevel@tonic-gate static int
nd_send_data(TIUSER * tiptr,caddr_t addr,int offset,XDR * xdrp,uint32_t * xidp)2257c478bd9Sstevel@tonic-gate nd_send_data(TIUSER *tiptr, caddr_t addr, int offset, XDR *xdrp, uint32_t *xidp)
2267c478bd9Sstevel@tonic-gate {
2277c478bd9Sstevel@tonic-gate static struct rpc_msg call_msg;
2287c478bd9Sstevel@tonic-gate static uchar_t header[HDR_SIZE];
2297c478bd9Sstevel@tonic-gate static struct t_kunitdata sudata;
2307c478bd9Sstevel@tonic-gate static uchar_t *dumpbuf;
2317c478bd9Sstevel@tonic-gate int procnum;
2327c478bd9Sstevel@tonic-gate stable_how stable = FILE_SYNC;
2337c478bd9Sstevel@tonic-gate mblk_t *mblk_p;
2347c478bd9Sstevel@tonic-gate int error;
2357c478bd9Sstevel@tonic-gate int tsize = ptob(1);
2367c478bd9Sstevel@tonic-gate uint64 offset3;
2377c478bd9Sstevel@tonic-gate
2387c478bd9Sstevel@tonic-gate if (!dumpbuf) {
2397c478bd9Sstevel@tonic-gate call_msg.rm_direction = CALL;
2407c478bd9Sstevel@tonic-gate call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
2417c478bd9Sstevel@tonic-gate call_msg.rm_call.cb_prog = NFS_PROGRAM;
2427c478bd9Sstevel@tonic-gate call_msg.rm_call.cb_vers = nfsdump_version;
2437c478bd9Sstevel@tonic-gate
2447c478bd9Sstevel@tonic-gate if (!(dumpbuf = kmem_alloc(ptob(1), KM_NOSLEEP))) {
2457c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "\tnfs_dump: cannot allocate dump buffer");
2467c478bd9Sstevel@tonic-gate return (ENOMEM);
2477c478bd9Sstevel@tonic-gate }
2487c478bd9Sstevel@tonic-gate }
2497c478bd9Sstevel@tonic-gate
2507c478bd9Sstevel@tonic-gate nd_log("nfs_dump: calling esballoc for header\n");
2517c478bd9Sstevel@tonic-gate
2527c478bd9Sstevel@tonic-gate if (!(mblk_p = esballoc(header, HDR_SIZE, BPRI_HI, &frnop))) {
2537c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "\tnfs_dump: out of mblks");
2547c478bd9Sstevel@tonic-gate return (ENOBUFS);
2557c478bd9Sstevel@tonic-gate }
2567c478bd9Sstevel@tonic-gate
2577c478bd9Sstevel@tonic-gate xdrmem_create(xdrp, (caddr_t)header, HDR_SIZE, XDR_ENCODE);
2587c478bd9Sstevel@tonic-gate
2597c478bd9Sstevel@tonic-gate call_msg.rm_xid = alloc_xid();
2607c478bd9Sstevel@tonic-gate *xidp = call_msg.rm_xid;
2617c478bd9Sstevel@tonic-gate
2627c478bd9Sstevel@tonic-gate if (!xdr_callhdr(xdrp, &call_msg)) {
2637c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "\tnfs_dump: cannot serialize header");
2647c478bd9Sstevel@tonic-gate return (EIO);
2657c478bd9Sstevel@tonic-gate }
2667c478bd9Sstevel@tonic-gate
2677c478bd9Sstevel@tonic-gate if (nfsdump_maxcount) {
2687c478bd9Sstevel@tonic-gate /*
2697c478bd9Sstevel@tonic-gate * Do not extend the dump file if it is also
2707c478bd9Sstevel@tonic-gate * the swap file.
2717c478bd9Sstevel@tonic-gate */
2727c478bd9Sstevel@tonic-gate if (offset >= nfsdump_maxcount) {
2737c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "\tnfs_dump: end of file");
2747c478bd9Sstevel@tonic-gate return (EIO);
2757c478bd9Sstevel@tonic-gate }
2767c478bd9Sstevel@tonic-gate if (offset + tsize > nfsdump_maxcount)
2777c478bd9Sstevel@tonic-gate tsize = nfsdump_maxcount - offset;
2787c478bd9Sstevel@tonic-gate }
2797c478bd9Sstevel@tonic-gate switch (nfsdump_version) {
2807c478bd9Sstevel@tonic-gate case NFS_VERSION:
2817c478bd9Sstevel@tonic-gate procnum = RFS_WRITE;
2827c478bd9Sstevel@tonic-gate if (!XDR_PUTINT32(xdrp, (int32_t *)&procnum) ||
2837c478bd9Sstevel@tonic-gate !nd_auth_marshall(xdrp) ||
2847c478bd9Sstevel@tonic-gate !xdr_fhandle(xdrp, &nfsdump_fhandle2) ||
2857c478bd9Sstevel@tonic-gate /*
2867c478bd9Sstevel@tonic-gate * Following four values are:
2877c478bd9Sstevel@tonic-gate * beginoffset
2887c478bd9Sstevel@tonic-gate * offset
2897c478bd9Sstevel@tonic-gate * length
2907c478bd9Sstevel@tonic-gate * bytes array length
2917c478bd9Sstevel@tonic-gate */
2927c478bd9Sstevel@tonic-gate !XDR_PUTINT32(xdrp, (int32_t *)&offset) ||
2937c478bd9Sstevel@tonic-gate !XDR_PUTINT32(xdrp, (int32_t *)&offset) ||
2947c478bd9Sstevel@tonic-gate !XDR_PUTINT32(xdrp, (int32_t *)&tsize) ||
2957c478bd9Sstevel@tonic-gate !XDR_PUTINT32(xdrp, (int32_t *)&tsize)) {
2967c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "\tnfs_dump: serialization failed");
2977c478bd9Sstevel@tonic-gate return (EIO);
2987c478bd9Sstevel@tonic-gate }
2997c478bd9Sstevel@tonic-gate break;
3007c478bd9Sstevel@tonic-gate case NFS_V3:
3017c478bd9Sstevel@tonic-gate procnum = NFSPROC3_WRITE;
3027c478bd9Sstevel@tonic-gate offset3 = offset;
3037c478bd9Sstevel@tonic-gate if (!XDR_PUTINT32(xdrp, (int32_t *)&procnum) ||
3047c478bd9Sstevel@tonic-gate !nd_auth_marshall(xdrp) ||
3057c478bd9Sstevel@tonic-gate !xdr_nfs_fh3(xdrp, &nfsdump_fhandle3) ||
3067c478bd9Sstevel@tonic-gate /*
3077c478bd9Sstevel@tonic-gate * Following four values are:
3087c478bd9Sstevel@tonic-gate * offset
3097c478bd9Sstevel@tonic-gate * count
3107c478bd9Sstevel@tonic-gate * stable
3117c478bd9Sstevel@tonic-gate * bytes array length
3127c478bd9Sstevel@tonic-gate */
3137c478bd9Sstevel@tonic-gate !xdr_u_longlong_t(xdrp, &offset3) ||
3147c478bd9Sstevel@tonic-gate !XDR_PUTINT32(xdrp, (int32_t *)&tsize) ||
3157c478bd9Sstevel@tonic-gate !XDR_PUTINT32(xdrp, (int32_t *)&stable) ||
3167c478bd9Sstevel@tonic-gate !XDR_PUTINT32(xdrp, (int32_t *)&tsize)) {
3177c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "\tnfs_dump: serialization failed");
3187c478bd9Sstevel@tonic-gate return (EIO);
3197c478bd9Sstevel@tonic-gate }
3207c478bd9Sstevel@tonic-gate break;
3217c478bd9Sstevel@tonic-gate default:
3227c478bd9Sstevel@tonic-gate return (EIO);
3237c478bd9Sstevel@tonic-gate }
3247c478bd9Sstevel@tonic-gate
3257c478bd9Sstevel@tonic-gate bcopy(addr, (caddr_t)dumpbuf, tsize);
3267c478bd9Sstevel@tonic-gate
3277c478bd9Sstevel@tonic-gate mblk_p->b_wptr += (int)XDR_GETPOS(xdrp);
3287c478bd9Sstevel@tonic-gate
3297c478bd9Sstevel@tonic-gate mblk_p->b_cont = esballoc((uchar_t *)dumpbuf, ptob(1), BPRI_HI, &frnop);
3307c478bd9Sstevel@tonic-gate
3317c478bd9Sstevel@tonic-gate if (!mblk_p->b_cont) {
3327c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "\tnfs_dump: out of mblks");
3337c478bd9Sstevel@tonic-gate return (ENOBUFS);
3347c478bd9Sstevel@tonic-gate }
3357c478bd9Sstevel@tonic-gate mblk_p->b_cont->b_wptr += ptob(1);
3367c478bd9Sstevel@tonic-gate
3377c478bd9Sstevel@tonic-gate sudata.addr = nfsdump_addr; /* structure copy */
3387c478bd9Sstevel@tonic-gate sudata.udata.buf = (char *)NULL;
3397c478bd9Sstevel@tonic-gate sudata.udata.maxlen = 0;
3407c478bd9Sstevel@tonic-gate sudata.udata.len = 1; /* needed for t_ksndudata */
3417c478bd9Sstevel@tonic-gate sudata.udata.udata_mp = mblk_p;
3427c478bd9Sstevel@tonic-gate
3437c478bd9Sstevel@tonic-gate nd_log("nfs_dump: calling t_ksndudata\n");
3447c478bd9Sstevel@tonic-gate
3457c478bd9Sstevel@tonic-gate if (error = t_ksndudata(tiptr, &sudata, (frtn_t *)NULL)) {
3467c478bd9Sstevel@tonic-gate nfs_perror(error, "\nnfs_dump: t_ksndudata failed: %m\n");
3477c478bd9Sstevel@tonic-gate return (error);
3487c478bd9Sstevel@tonic-gate }
3497c478bd9Sstevel@tonic-gate return (0);
3507c478bd9Sstevel@tonic-gate }
3517c478bd9Sstevel@tonic-gate
3527c478bd9Sstevel@tonic-gate static int
nd_get_reply(TIUSER * tiptr,XDR * xdrp,uint32_t call_xid,int * badmsg)3537c478bd9Sstevel@tonic-gate nd_get_reply(TIUSER *tiptr, XDR *xdrp, uint32_t call_xid, int *badmsg)
3547c478bd9Sstevel@tonic-gate {
3557c478bd9Sstevel@tonic-gate static struct rpc_msg reply_msg;
3567c478bd9Sstevel@tonic-gate static struct rpc_err rpc_err;
3577c478bd9Sstevel@tonic-gate static struct nfsattrstat na;
3587c478bd9Sstevel@tonic-gate static struct WRITE3res wres;
3597c478bd9Sstevel@tonic-gate static struct t_kunitdata rudata;
3607c478bd9Sstevel@tonic-gate int uderr;
3617c478bd9Sstevel@tonic-gate int type;
3627c478bd9Sstevel@tonic-gate int error;
3637c478bd9Sstevel@tonic-gate
3647c478bd9Sstevel@tonic-gate *badmsg = 0;
3657c478bd9Sstevel@tonic-gate
3667c478bd9Sstevel@tonic-gate rudata.addr.maxlen = 0;
3677c478bd9Sstevel@tonic-gate rudata.opt.maxlen = 0;
3687c478bd9Sstevel@tonic-gate rudata.udata.udata_mp = (mblk_t *)NULL;
3697c478bd9Sstevel@tonic-gate
3707c478bd9Sstevel@tonic-gate nd_log("nfs_dump: calling t_krcvudata\n");
3717c478bd9Sstevel@tonic-gate
3727c478bd9Sstevel@tonic-gate if (error = t_krcvudata(tiptr, &rudata, &type, &uderr)) {
373*9fe74b0bSGary Mills if (error == EBADMSG) {
374*9fe74b0bSGary Mills cmn_err(CE_WARN, "\tnfs_dump: received EBADMSG");
375*9fe74b0bSGary Mills *badmsg = 1;
376*9fe74b0bSGary Mills return (0);
377*9fe74b0bSGary Mills }
3787c478bd9Sstevel@tonic-gate nfs_perror(error, "\nnfs_dump: t_krcvudata failed: %m\n");
3797c478bd9Sstevel@tonic-gate return (EIO);
3807c478bd9Sstevel@tonic-gate }
3817c478bd9Sstevel@tonic-gate if (type != T_DATA) {
3827c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "\tnfs_dump: received type %d", type);
3837c478bd9Sstevel@tonic-gate *badmsg = 1;
3847c478bd9Sstevel@tonic-gate return (0);
3857c478bd9Sstevel@tonic-gate }
3867c478bd9Sstevel@tonic-gate if (!rudata.udata.udata_mp) {
3877c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "\tnfs_dump: null receive");
3887c478bd9Sstevel@tonic-gate *badmsg = 1;
3897c478bd9Sstevel@tonic-gate return (0);
3907c478bd9Sstevel@tonic-gate }
3917c478bd9Sstevel@tonic-gate
3927c478bd9Sstevel@tonic-gate /*
3937c478bd9Sstevel@tonic-gate * Decode results.
3947c478bd9Sstevel@tonic-gate */
3957c478bd9Sstevel@tonic-gate xdrmblk_init(xdrp, rudata.udata.udata_mp, XDR_DECODE, 0);
3967c478bd9Sstevel@tonic-gate
3977c478bd9Sstevel@tonic-gate reply_msg.acpted_rply.ar_verf = _null_auth;
3987c478bd9Sstevel@tonic-gate switch (nfsdump_version) {
3997c478bd9Sstevel@tonic-gate case NFS_VERSION:
4007c478bd9Sstevel@tonic-gate reply_msg.acpted_rply.ar_results.where = (caddr_t)&na;
4017c478bd9Sstevel@tonic-gate reply_msg.acpted_rply.ar_results.proc = xdr_attrstat;
4027c478bd9Sstevel@tonic-gate break;
4037c478bd9Sstevel@tonic-gate case NFS_V3:
4047c478bd9Sstevel@tonic-gate reply_msg.acpted_rply.ar_results.where = (caddr_t)&wres;
4057c478bd9Sstevel@tonic-gate reply_msg.acpted_rply.ar_results.proc = xdr_WRITE3res;
4067c478bd9Sstevel@tonic-gate break;
4077c478bd9Sstevel@tonic-gate default:
4087c478bd9Sstevel@tonic-gate return (EIO);
4097c478bd9Sstevel@tonic-gate }
4107c478bd9Sstevel@tonic-gate
4117c478bd9Sstevel@tonic-gate if (!xdr_replymsg(xdrp, &reply_msg)) {
4127c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "\tnfs_dump: xdr_replymsg failed");
4137c478bd9Sstevel@tonic-gate return (EIO);
4147c478bd9Sstevel@tonic-gate }
4157c478bd9Sstevel@tonic-gate
4167c478bd9Sstevel@tonic-gate if (reply_msg.rm_xid != call_xid) {
4177c478bd9Sstevel@tonic-gate *badmsg = 1;
4187c478bd9Sstevel@tonic-gate return (0);
4197c478bd9Sstevel@tonic-gate }
4207c478bd9Sstevel@tonic-gate
4217c478bd9Sstevel@tonic-gate _seterr_reply(&reply_msg, &rpc_err);
4227c478bd9Sstevel@tonic-gate
4237c478bd9Sstevel@tonic-gate if (rpc_err.re_status != RPC_SUCCESS) {
4247c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "\tnfs_dump: RPC error %d (%s)",
4257c478bd9Sstevel@tonic-gate rpc_err.re_status, clnt_sperrno(rpc_err.re_status));
4267c478bd9Sstevel@tonic-gate return (EIO);
4277c478bd9Sstevel@tonic-gate }
4287c478bd9Sstevel@tonic-gate
4297c478bd9Sstevel@tonic-gate switch (nfsdump_version) {
4307c478bd9Sstevel@tonic-gate case NFS_VERSION:
4317c478bd9Sstevel@tonic-gate if (na.ns_status) {
4327c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "\tnfs_dump: status %d", na.ns_status);
4337c478bd9Sstevel@tonic-gate return (EIO);
4347c478bd9Sstevel@tonic-gate }
4357c478bd9Sstevel@tonic-gate break;
4367c478bd9Sstevel@tonic-gate case NFS_V3:
4377c478bd9Sstevel@tonic-gate if (wres.status != NFS3_OK) {
4387c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "\tnfs_dump: status %d", wres.status);
4397c478bd9Sstevel@tonic-gate return (EIO);
4407c478bd9Sstevel@tonic-gate }
4417c478bd9Sstevel@tonic-gate break;
4427c478bd9Sstevel@tonic-gate default:
4437c478bd9Sstevel@tonic-gate return (EIO);
4447c478bd9Sstevel@tonic-gate }
4457c478bd9Sstevel@tonic-gate
4467c478bd9Sstevel@tonic-gate if (reply_msg.acpted_rply.ar_verf.oa_base != NULL) {
4477c478bd9Sstevel@tonic-gate /* free auth handle */
4487c478bd9Sstevel@tonic-gate xdrp->x_op = XDR_FREE;
4497c478bd9Sstevel@tonic-gate (void) xdr_opaque_auth(xdrp, &(reply_msg.acpted_rply.ar_verf));
4507c478bd9Sstevel@tonic-gate }
4517c478bd9Sstevel@tonic-gate
4527c478bd9Sstevel@tonic-gate freemsg(rudata.udata.udata_mp);
4537c478bd9Sstevel@tonic-gate
4547c478bd9Sstevel@tonic-gate return (0);
4557c478bd9Sstevel@tonic-gate }
4567c478bd9Sstevel@tonic-gate
4577c478bd9Sstevel@tonic-gate static int
nd_poll(TIUSER * tiptr,int retry,int * eventp)4587c478bd9Sstevel@tonic-gate nd_poll(TIUSER *tiptr, int retry, int *eventp)
4597c478bd9Sstevel@tonic-gate {
460d3d50737SRafael Vanoni clock_t start_bolt = ddi_get_lbolt();
4617c478bd9Sstevel@tonic-gate clock_t timout = TIMEOUT * (retry + 1);
4627c478bd9Sstevel@tonic-gate int error;
4637c478bd9Sstevel@tonic-gate
4647c478bd9Sstevel@tonic-gate nd_log("nfs_dump: calling t_kspoll\n");
4657c478bd9Sstevel@tonic-gate
4667c478bd9Sstevel@tonic-gate *eventp = 0;
4677c478bd9Sstevel@tonic-gate
468d3d50737SRafael Vanoni while (!*eventp && ((ddi_get_lbolt() - start_bolt) < timout)) {
4697c478bd9Sstevel@tonic-gate /*
4707c478bd9Sstevel@tonic-gate * Briefly enable interrupts before checking for a reply;
4717c478bd9Sstevel@tonic-gate * the network transports do not yet support do_polled_io.
4727c478bd9Sstevel@tonic-gate */
4737c478bd9Sstevel@tonic-gate int s = spl0();
4747c478bd9Sstevel@tonic-gate splx(s);
4757c478bd9Sstevel@tonic-gate
4767c478bd9Sstevel@tonic-gate if (error = t_kspoll(tiptr, 0, READWAIT, eventp)) {
4777c478bd9Sstevel@tonic-gate nfs_perror(error,
4787c478bd9Sstevel@tonic-gate "\nnfs_dump: t_kspoll failed: %m\n");
4797c478bd9Sstevel@tonic-gate return (EIO);
4807c478bd9Sstevel@tonic-gate }
4817c478bd9Sstevel@tonic-gate runqueues();
4827c478bd9Sstevel@tonic-gate }
4837c478bd9Sstevel@tonic-gate
4847c478bd9Sstevel@tonic-gate if (retry == RETRIES && !*eventp) {
4857c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "\tnfs_dump: server not responding");
4867c478bd9Sstevel@tonic-gate return (EIO);
4877c478bd9Sstevel@tonic-gate }
4887c478bd9Sstevel@tonic-gate
4897c478bd9Sstevel@tonic-gate return (0);
4907c478bd9Sstevel@tonic-gate }
4917c478bd9Sstevel@tonic-gate
4927c478bd9Sstevel@tonic-gate static int
nd_auth_marshall(XDR * xdrp)4937c478bd9Sstevel@tonic-gate nd_auth_marshall(XDR *xdrp)
4947c478bd9Sstevel@tonic-gate {
4957c478bd9Sstevel@tonic-gate int credsize;
4967c478bd9Sstevel@tonic-gate int32_t *ptr;
4977c478bd9Sstevel@tonic-gate int hostnamelen;
4987c478bd9Sstevel@tonic-gate
4997c478bd9Sstevel@tonic-gate hostnamelen = (int)strlen(utsname.nodename);
5007c478bd9Sstevel@tonic-gate credsize = 4 + 4 + roundup(hostnamelen, 4) + 4 + 4 + 4;
5017c478bd9Sstevel@tonic-gate
5027c478bd9Sstevel@tonic-gate ptr = XDR_INLINE(xdrp, 4 + 4 + credsize + 4 + 4);
5037c478bd9Sstevel@tonic-gate if (!ptr) {
5047c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "\tnfs_dump: auth_marshall failed");
5057c478bd9Sstevel@tonic-gate return (0);
5067c478bd9Sstevel@tonic-gate }
5077c478bd9Sstevel@tonic-gate /*
5087c478bd9Sstevel@tonic-gate * We can do the fast path.
5097c478bd9Sstevel@tonic-gate */
5107c478bd9Sstevel@tonic-gate IXDR_PUT_INT32(ptr, AUTH_UNIX); /* cred flavor */
5117c478bd9Sstevel@tonic-gate IXDR_PUT_INT32(ptr, credsize); /* cred len */
5127c478bd9Sstevel@tonic-gate IXDR_PUT_INT32(ptr, gethrestime_sec());
5137c478bd9Sstevel@tonic-gate IXDR_PUT_INT32(ptr, hostnamelen);
5147c478bd9Sstevel@tonic-gate
5157c478bd9Sstevel@tonic-gate bcopy(utsname.nodename, ptr, hostnamelen);
5167c478bd9Sstevel@tonic-gate ptr += roundup(hostnamelen, 4) / 4;
5177c478bd9Sstevel@tonic-gate
5187c478bd9Sstevel@tonic-gate IXDR_PUT_INT32(ptr, 0); /* uid */
5197c478bd9Sstevel@tonic-gate IXDR_PUT_INT32(ptr, 0); /* gid */
5207c478bd9Sstevel@tonic-gate IXDR_PUT_INT32(ptr, 0); /* gid list length (empty) */
5217c478bd9Sstevel@tonic-gate IXDR_PUT_INT32(ptr, AUTH_NULL); /* verf flavor */
5227c478bd9Sstevel@tonic-gate IXDR_PUT_INT32(ptr, 0); /* verf len */
5237c478bd9Sstevel@tonic-gate
5247c478bd9Sstevel@tonic-gate return (1);
5257c478bd9Sstevel@tonic-gate }
526