nfsm_subs.h revision 138496
11541Srgrimes/*
21541Srgrimes * Copyright (c) 1989, 1993
31541Srgrimes *	The Regents of the University of California.  All rights reserved.
41541Srgrimes *
51541Srgrimes * This code is derived from software contributed to Berkeley by
61541Srgrimes * Rick Macklem at The University of Guelph.
71541Srgrimes *
81541Srgrimes * Redistribution and use in source and binary forms, with or without
91541Srgrimes * modification, are permitted provided that the following conditions
101541Srgrimes * are met:
111541Srgrimes * 1. Redistributions of source code must retain the above copyright
121541Srgrimes *    notice, this list of conditions and the following disclaimer.
131541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
141541Srgrimes *    notice, this list of conditions and the following disclaimer in the
151541Srgrimes *    documentation and/or other materials provided with the distribution.
161541Srgrimes * 4. Neither the name of the University nor the names of its contributors
171541Srgrimes *    may be used to endorse or promote products derived from this software
181541Srgrimes *    without specific prior written permission.
191541Srgrimes *
201541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
211541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
221541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
231541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
241541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
251541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
261541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
271541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
281541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
291541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
301541Srgrimes * SUCH DAMAGE.
311541Srgrimes *
3222521Sdyson *	@(#)nfsm_subs.h	8.2 (Berkeley) 3/30/95
3350477Speter * $FreeBSD: head/sys/nfsclient/nfsm_subs.h 138496 2004-12-06 21:11:15Z ps $
341541Srgrimes */
351541Srgrimes
3683651Speter#ifndef _NFSCLIENT_NFSM_SUBS_H_
3783651Speter#define _NFSCLIENT_NFSM_SUBS_H_
3822521Sdyson
3983651Speter#include <nfs/nfs_common.h>
402175Spaul
4183651Speter#define	nfsv2tov_type(a)	nv2tov_type[fxdr_unsigned(u_int32_t,(a))&0x7]
4283651Speter
4333054Sbdestruct ucred;
4433054Sbdestruct vnode;
459336Sdfr
461541Srgrimes/*
471541Srgrimes * These macros do strange and peculiar things to mbuf chains for
481541Srgrimes * the assistance of the nfs code. To attempt to use them for any
491541Srgrimes * other purpose will be dangerous. (they make weird assumptions)
501541Srgrimes */
511541Srgrimes
521541Srgrimes/*
531541Srgrimes * First define what the actual subs. return
541541Srgrimes */
5583651Speterstruct mbuf *nfsm_reqhead(struct vnode *vp, u_long procid, int hsiz);
5683651Speterstruct mbuf *nfsm_rpchead(struct ucred *cr, int nmflag, int procid,
5783651Speter			  int auth_type, int auth_len,
5883651Speter			  struct mbuf *mrest, int mrest_len,
5983651Speter			  struct mbuf **mbp, u_int32_t *xidp);
601541Srgrimes
611541Srgrimes#define	M_HASCL(m)	((m)->m_flags & M_EXT)
621541Srgrimes#define	NFSMINOFF(m) \
6350053Speter	do { \
641541Srgrimes		if (M_HASCL(m)) \
651541Srgrimes			(m)->m_data = (m)->m_ext.ext_buf; \
661541Srgrimes		else if ((m)->m_flags & M_PKTHDR) \
671541Srgrimes			(m)->m_data = (m)->m_pktdat; \
681541Srgrimes		else \
6950053Speter			(m)->m_data = (m)->m_dat; \
7050053Speter	} while (0)
711541Srgrimes#define	NFSMSIZ(m)	((M_HASCL(m))?MCLBYTES: \
721541Srgrimes				(((m)->m_flags & M_PKTHDR)?MHLEN:MLEN))
731541Srgrimes
741541Srgrimes/*
751541Srgrimes * Now for the macros that do the simple stuff and call the functions
761541Srgrimes * for the hard stuff.
771541Srgrimes * These macros use several vars. declared in nfsm_reqhead and these
781541Srgrimes * vars. must not be used elsewhere unless you are careful not to corrupt
791541Srgrimes * them. The vars. starting with pN and tN (N=1,2,3,..) are temporaries
801541Srgrimes * that may be used so long as the value is not expected to retained
811541Srgrimes * after a macro.
821541Srgrimes * I know, this is kind of dorkey, but it makes the actual op functions
831541Srgrimes * fairly clean and deals with the mess caused by the xdr discriminating
841541Srgrimes * unions.
851541Srgrimes */
861541Srgrimes
8784079Speter
8884079Speter/* *********************************** */
8984079Speter/* Request generation phase macros */
9084079Speter
9188091Siedowseint	nfsm_fhtom_xx(struct vnode *v, int v3, struct mbuf **mb,
9288091Siedowse	    caddr_t *bpos);
9388091Siedowsevoid	nfsm_v3attrbuild_xx(struct vattr *va, int full, struct mbuf **mb,
9488091Siedowse	    caddr_t *bpos);
9588091Siedowseint	nfsm_strtom_xx(const char *a, int s, int m, struct mbuf **mb,
9688091Siedowse	    caddr_t *bpos);
971541Srgrimes
9884079Speter#define nfsm_bcheck(t1, mreq) \
9983651Speterdo { \
10083651Speter	if (t1) { \
10183651Speter		error = t1; \
10283651Speter		m_freem(mreq); \
10383651Speter		goto nfsmout; \
10483651Speter	} \
10583651Speter} while (0)
1061541Srgrimes
10784079Speter#define nfsm_fhtom(v, v3) \
10884079Speterdo { \
10984079Speter	int32_t t1; \
11088091Siedowse	t1 = nfsm_fhtom_xx((v), (v3), &mb, &bpos); \
11184079Speter	nfsm_bcheck(t1, mreq); \
11284079Speter} while (0)
11384079Speter
11484079Speter/* If full is true, set all fields, otherwise just set mode and time fields */
11584079Speter#define nfsm_v3attrbuild(a, full) \
11688091Siedowse	nfsm_v3attrbuild_xx(a, full, &mb, &bpos)
11784079Speter
11884079Speter#define nfsm_uiotom(p, s) \
11984079Speterdo { \
12084079Speter	int t1; \
12184079Speter	t1 = nfsm_uiotombuf((p), &mb, (s), &bpos); \
12284079Speter	nfsm_bcheck(t1, mreq); \
12384079Speter} while (0)
12484079Speter
12584079Speter#define	nfsm_strtom(a, s, m) \
12684079Speterdo { \
12784079Speter	int t1; \
12888091Siedowse	t1 = nfsm_strtom_xx((a), (s), (m), &mb, &bpos); \
12984079Speter	nfsm_bcheck(t1, mreq); \
13084079Speter} while (0)
13184079Speter
13284079Speter/* *********************************** */
13384079Speter/* Send the request */
13484079Speter
13584079Speter#define	nfsm_request(v, t, p, c) \
13684079Speterdo { \
137138496Sps	sigset_t oldset; \
138138496Sps	nfs_set_sigmask(p, &oldset); \
13984079Speter	error = nfs_request((v), mreq, (t), (p), (c), &mrep, &md, &dpos); \
140138496Sps	nfs_restore_sigmask(p, &oldset); \
14184079Speter	if (error != 0) { \
14284079Speter		if (error & NFSERR_RETERR) \
14384079Speter			error &= ~NFSERR_RETERR; \
14484079Speter		else \
14584079Speter			goto nfsmout; \
14684079Speter	} \
14784079Speter} while (0)
14884079Speter
149122698Salfred#define	nfsm_request_mnt(n, t, p, c) \
150122698Salfreddo { \
151122698Salfred	error = nfs4_request_mnt((n), mreq, (t), (p), (c), &mrep, &md, &dpos); \
152122698Salfred	if (error != 0) { \
153122698Salfred		if (error & NFSERR_RETERR) \
154122698Salfred			error &= ~NFSERR_RETERR; \
155122698Salfred		else \
156122698Salfred			goto nfsmout; \
157122698Salfred	} \
158122698Salfred} while (0)
159122698Salfred
16084079Speter/* *********************************** */
16184079Speter/* Reply interpretation phase macros */
16284079Speter
16384079Speterint	nfsm_mtofh_xx(struct vnode *d, struct vnode **v, int v3, int *f,
16484079Speter	    struct mbuf **md, caddr_t *dpos);
16588091Siedowseint	nfsm_getfh_xx(nfsfh_t **f, int *s, int v3, struct mbuf **md,
16688091Siedowse	    caddr_t *dpos);
16788091Siedowseint	nfsm_loadattr_xx(struct vnode **v, struct vattr *va, struct mbuf **md,
16888091Siedowse	    caddr_t *dpos);
16988091Siedowseint	nfsm_postop_attr_xx(struct vnode **v, int *f, struct mbuf **md,
17088091Siedowse	    caddr_t *dpos);
17188091Siedowseint	nfsm_wcc_data_xx(struct vnode **v, int *f, struct mbuf **md,
17288091Siedowse	    caddr_t *dpos);
17384079Speter
1749336Sdfr#define nfsm_mtofh(d, v, v3, f) \
17583651Speterdo { \
17683651Speter	int32_t t1; \
17788091Siedowse	t1 = nfsm_mtofh_xx((d), &(v), (v3), &(f), &md, &dpos); \
17884079Speter	nfsm_dcheck(t1, mrep); \
17983651Speter} while (0)
1801541Srgrimes
1819336Sdfr#define nfsm_getfh(f, s, v3) \
18283651Speterdo { \
18383651Speter	int32_t t1; \
18488091Siedowse	t1 = nfsm_getfh_xx(&(f), &(s), (v3), &md, &dpos); \
18584079Speter	nfsm_dcheck(t1, mrep); \
18683651Speter} while (0)
1879336Sdfr
1889336Sdfr#define	nfsm_loadattr(v, a) \
18983651Speterdo { \
19083651Speter	int32_t t1; \
19188091Siedowse	t1 = nfsm_loadattr_xx(&v, a, &md, &dpos); \
19284079Speter	nfsm_dcheck(t1, mrep); \
19383651Speter} while (0)
1941541Srgrimes
1959336Sdfr#define	nfsm_postop_attr(v, f) \
19683651Speterdo { \
19783651Speter	int32_t t1; \
19888091Siedowse	t1 = nfsm_postop_attr_xx(&v, &f, &md, &dpos); \
19984079Speter	nfsm_dcheck(t1, mrep); \
20083651Speter} while (0)
2019336Sdfr
2029336Sdfr/* Used as (f) for nfsm_wcc_data() */
2039336Sdfr#define NFSV3_WCCRATTR	0
2049336Sdfr#define NFSV3_WCCCHK	1
2059336Sdfr
2069336Sdfr#define	nfsm_wcc_data(v, f) \
20783651Speterdo { \
20883651Speter	int32_t t1; \
20988091Siedowse	t1 = nfsm_wcc_data_xx(&v, &f, &md, &dpos); \
21084079Speter	nfsm_dcheck(t1, mrep); \
21183651Speter} while (0)
2129336Sdfr
2132175Spaul#endif
214