Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 17 Dec 2001 22:05:47 +0000
From:      Ian Dowse <iedowse@maths.tcd.ie>
To:        stable@FreeBSD.ORG
Subject:   Re: Waaaarg, we just blew out the kernel again.. 
Message-ID:   <200112172205.aa56337@salmon.maths.tcd.ie>
In-Reply-To: Your message of "Mon, 17 Dec 2001 14:13:36 GMT." <200112171413.aa87921@salmon.maths.tcd.ie> 

next in thread | previous in thread | raw e-mail | index | archive | help
In message <200112171413.aa87921@salmon.maths.tcd.ie>, Ian Dowse writes:
>I tried Matt's suggestion of moving some NFS macros into functions,
>and it looks we can get 10k or so off the compressed kernel that
>way by changing just 4 macros.

Here's the basic NFS patch, which takes approx 8.5k off the compressed
size of the floppy kernel. It splits the macros nfsm_build(),
nfsm_dissect(), nfsm_postop_attr(), nfsm_wcc_data(), nfsm_fhtom()
and nfsm_v3attrbuild() each into a function and a wrapper macro.
The functions are as close as possible to being identical to the
corresponding functions in -current, so this would effectively be
a partial MFC of some of the changes there (one exception is a
simplification of the handling of the `tl' variable, which I hope
to commit to -current first).

Applying this causes a large number of local variables throughout
the NFS code to become unused, and it also generates a lot of
`address of register variable X requested' compiler warnings.
Since those require purely mechanical changes, that part of the
patch is not included below.

Any comments? Is this worth doing for 8.5k, or should we just
ditch some more drivers from GENERIC?

Ian


Index: nfs_subs.c
===================================================================
RCS file: /dump/FreeBSD-CVS/src/sys/nfs/Attic/nfs_subs.c,v
retrieving revision 1.90.2.2
diff -u -r1.90.2.2 nfs_subs.c
--- nfs_subs.c	2001/10/25 19:18:53	1.90.2.2
+++ nfs_subs.c	2001/12/17 21:28:18
@@ -2154,6 +2154,190 @@
 	splx(s);
 }
 
+void *
+nfsm_build_xx(int s, struct mbuf **mb, caddr_t *bpos)
+{
+	struct mbuf *mb2;
+	void *ret;
+
+	if (s > M_TRAILINGSPACE(*mb)) {
+		MGET(mb2, M_WAIT, MT_DATA);
+		if (s > MLEN)
+			panic("build > MLEN");
+		(*mb)->m_next = mb2;
+		*mb = mb2;
+		(*mb)->m_len = 0;
+		*bpos = mtod(*mb, caddr_t);
+	}
+	ret = *bpos;
+	(*mb)->m_len += s;
+	*bpos += s;
+	return ret;
+}
+
+void *
+nfsm_dissect_xx(int s, struct mbuf **md, caddr_t *dpos)
+{
+	int t1;
+	char *cp2;
+	void *ret;
+
+	t1 = mtod(*md, caddr_t) + (*md)->m_len - *dpos;
+	if (t1 >= s) {
+		ret = *dpos;
+		*dpos += s;
+		return ret;
+	}
+	if (nfsm_disct(md, dpos, s, t1, &cp2) != 0)
+		return NULL;
+	return cp2;
+}
+
+int
+nfsm_postop_attr_xx(struct vnode **v, int *f, struct mbuf **md,
+    caddr_t *dpos)
+{
+	u_int32_t *tl;
+	int t1;
+
+	struct vnode *ttvp = *v;
+	tl = nfsm_dissect_xx(NFSX_UNSIGNED, md, dpos);
+	if (tl == NULL)
+		return EBADRPC;
+	*f = fxdr_unsigned(int, *tl);
+	if (*f != 0) {
+		t1 = nfs_loadattrcache(&ttvp, md, dpos, (struct vattr *)0, 1);
+		if (t1 != 0) {
+			*f = 0;
+			return t1;
+		}
+		*v = ttvp;
+	}
+	return 0;
+}
+
+int
+nfsm_wcc_data_xx(struct vnode **v, int *f, struct mbuf **md, caddr_t *dpos)
+{
+	u_int32_t *tl;
+	int ttattrf, ttretf = 0;
+	int t1;
+
+	tl = nfsm_dissect_xx(NFSX_UNSIGNED, md, dpos);
+	if (tl == NULL)
+		return EBADRPC;
+	if (*tl == nfs_true) {
+		tl = nfsm_dissect_xx(6 * NFSX_UNSIGNED, md, dpos);
+		if (tl == NULL)
+			return EBADRPC;
+		if (*f)
+			ttretf = (VTONFS(*v)->n_mtime ==
+			    fxdr_unsigned(u_int32_t, *(tl + 2)));
+	}
+	t1 = nfsm_postop_attr_xx(v, &ttattrf, md, dpos);
+	if (t1)
+		return t1;
+	if (*f)
+		*f = ttretf;
+	else
+		*f = ttattrf;
+	return 0;
+}
+
+int
+nfsm_fhtom_xx(struct vnode *v, int v3, struct mbuf **mb, caddr_t *bpos)
+{
+	u_int32_t *tl;
+	int t1;
+	caddr_t cp;
+
+	if (v3) {
+		t1 = nfsm_rndup(VTONFS(v)->n_fhsize) + NFSX_UNSIGNED;
+		if (t1 < M_TRAILINGSPACE(*mb)) {
+			tl = nfsm_build_xx(t1, mb, bpos);
+			*tl++ = txdr_unsigned(VTONFS(v)->n_fhsize);
+			*(tl + ((t1 >> 2) - 2)) = 0;
+			bcopy(VTONFS(v)->n_fhp, tl, VTONFS(v)->n_fhsize);
+		} else {
+			t1 = nfsm_strtmbuf(mb, bpos,
+			    (const char *)VTONFS(v)->n_fhp,
+			    VTONFS(v)->n_fhsize);
+			if (t1 != 0)
+				return t1;
+		}
+	} else {
+		cp = nfsm_build_xx(NFSX_V2FH, mb, bpos);
+		bcopy(VTONFS(v)->n_fhp, cp, NFSX_V2FH);
+	}
+	return 0;
+}
+
+void
+nfsm_v3attrbuild_xx(struct vattr *va, int full, struct mbuf **mb,
+    caddr_t *bpos)
+{
+	u_int32_t *tl;
+
+	if (va->va_mode != (mode_t)VNOVAL) {
+		tl = nfsm_build_xx(2 * NFSX_UNSIGNED, mb, bpos);
+		*tl++ = nfs_true;
+		*tl = txdr_unsigned(va->va_mode);
+	} else {
+		tl = nfsm_build_xx(NFSX_UNSIGNED, mb, bpos);
+		*tl = nfs_false;
+	}
+	if (full && va->va_uid != (uid_t)VNOVAL) {
+		tl = nfsm_build_xx(2 * NFSX_UNSIGNED, mb, bpos);
+		*tl++ = nfs_true;
+		*tl = txdr_unsigned(va->va_uid);
+	} else {
+		tl = nfsm_build_xx(NFSX_UNSIGNED, mb, bpos);
+		*tl = nfs_false;
+	}
+	if (full && va->va_gid != (gid_t)VNOVAL) {
+		tl = nfsm_build_xx(2 * NFSX_UNSIGNED, mb, bpos);
+		*tl++ = nfs_true;
+		*tl = txdr_unsigned(va->va_gid);
+	} else {
+		tl = nfsm_build_xx(NFSX_UNSIGNED, mb, bpos);
+		*tl = nfs_false;
+	}
+	if (full && va->va_size != VNOVAL) {
+		tl = nfsm_build_xx(3 * NFSX_UNSIGNED, mb, bpos);
+		*tl++ = nfs_true;
+		txdr_hyper(va->va_size, tl);
+	} else {
+		tl = nfsm_build_xx(NFSX_UNSIGNED, mb, bpos);
+		*tl = nfs_false;
+	}
+	if (va->va_atime.tv_sec != VNOVAL) {
+		if (va->va_atime.tv_sec != time_second) {
+			tl = nfsm_build_xx(3 * NFSX_UNSIGNED, mb, bpos);
+			*tl++ = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT);
+			txdr_nfsv3time(&va->va_atime, tl);
+		} else {
+			tl = nfsm_build_xx(NFSX_UNSIGNED, mb, bpos);
+			*tl = txdr_unsigned(NFSV3SATTRTIME_TOSERVER);
+		}
+	} else {
+		tl = nfsm_build_xx(NFSX_UNSIGNED, mb, bpos);
+		*tl = txdr_unsigned(NFSV3SATTRTIME_DONTCHANGE);
+	}
+	if (va->va_mtime.tv_sec != VNOVAL) {
+		if (va->va_mtime.tv_sec != time_second) {
+			tl = nfsm_build_xx(3 * NFSX_UNSIGNED, mb, bpos);
+			*tl++ = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT);
+			txdr_nfsv3time(&va->va_mtime, tl);
+		} else {
+			tl = nfsm_build_xx(NFSX_UNSIGNED, mb, bpos);
+			*tl = txdr_unsigned(NFSV3SATTRTIME_TOSERVER);
+		}
+	} else {
+		tl = nfsm_build_xx(NFSX_UNSIGNED, mb, bpos);
+		*tl = txdr_unsigned(NFSV3SATTRTIME_DONTCHANGE);
+	}
+}
+
 #ifndef NFS_NOSERVER
 /*
  * Map errnos to NFS error numbers. For Version 3 also filter out error
Index: nfsm_subs.h
===================================================================
RCS file: /dump/FreeBSD-CVS/src/sys/nfs/Attic/nfsm_subs.h,v
retrieving revision 1.27.2.1
diff -u -r1.27.2.1 nfsm_subs.h
--- nfsm_subs.h	2000/10/28 16:27:27	1.27.2.1
+++ nfsm_subs.h	2001/12/17 19:33:42
@@ -60,6 +60,16 @@
 			       int verf_len, char *verf_str,
 			       struct mbuf *mrest, int mrest_len,
 			       struct mbuf **mbp, u_int32_t *xidp));
+void	*nfsm_build_xx __P((int s, struct mbuf **mbp, caddr_t *bposp));
+void	*nfsm_dissect_xx __P((int s, struct mbuf **mdp, caddr_t *dposp));
+int	nfsm_fhtom_xx __P((struct vnode *v, int v3, struct mbuf **mbp,
+	    caddr_t *bposp));
+int	nfsm_postop_attr_xx __P((struct vnode **vp, int *f, struct mbuf **mdp,
+	    caddr_t *dposp));
+int	nfsm_wcc_data_xx __P((struct vnode **vp, int *f, struct mbuf **mdp,
+	    caddr_t *dposp));
+void	nfsm_v3attrbuild_xx __P((struct vattr *va, int full, struct mbuf **mbp,
+	    caddr_t *bposp));
 
 #define	M_HASCL(m)	((m)->m_flags & M_EXT)
 #define	NFSMINOFF(m) \
@@ -92,56 +102,26 @@
  */
 
 #define	nfsm_build(a,c,s) \
-	do { \
-		if ((s) > M_TRAILINGSPACE(mb)) { \
-			MGET(mb2, M_WAIT, MT_DATA); \
-			if ((s) > MLEN) \
-				panic("build > MLEN"); \
-			mb->m_next = mb2; \
-			mb = mb2; \
-			mb->m_len = 0; \
-			bpos = mtod(mb, caddr_t); \
-		} \
-		(a) = (c)(bpos); \
-		mb->m_len += (s); \
-		bpos += (s); \
-	} while (0)
+	(a) = (c)nfsm_build_xx(s, &mb, &bpos);
 
 #define	nfsm_dissect(a, c, s) \
 	do { \
-		t1 = mtod(md, caddr_t)+md->m_len-dpos; \
-		if (t1 >= (s)) { \
-			(a) = (c)(dpos); \
-			dpos += (s); \
-		} else if ((t1 = nfsm_disct(&md, &dpos, (s), t1, &cp2)) != 0){ \
-			error = t1; \
+		void *ret; \
+		ret = nfsm_dissect_xx(s, &md, &dpos); \
+		if (ret == NULL) { \
+			error = EBADRPC; \
 			m_freem(mrep); \
 			goto nfsmout; \
-		} else { \
-			(a) = (c)cp2; \
 		} \
+		(a) = (c)ret; \
 	} while (0)
 
 #define nfsm_fhtom(v, v3) \
 	do { \
-		if (v3) { \
-			t2 = nfsm_rndup(VTONFS(v)->n_fhsize) + NFSX_UNSIGNED; \
-			if (t2 <= M_TRAILINGSPACE(mb)) { \
-				nfsm_build(tl, u_int32_t *, t2); \
-				*tl++ = txdr_unsigned(VTONFS(v)->n_fhsize); \
-				*(tl + ((t2>>2) - 2)) = 0; \
-				bcopy((caddr_t)VTONFS(v)->n_fhp,(caddr_t)tl, \
-					VTONFS(v)->n_fhsize); \
-			} else if ((t2 = nfsm_strtmbuf(&mb, &bpos, \
-				(caddr_t)VTONFS(v)->n_fhp, \
-				VTONFS(v)->n_fhsize)) != 0) { \
-				error = t2; \
-				m_freem(mreq); \
-				goto nfsmout; \
-			} \
-		} else { \
-			nfsm_build(cp, caddr_t, NFSX_V2FH); \
-			bcopy((caddr_t)VTONFS(v)->n_fhp, cp, NFSX_V2FH); \
+		if ((t2 = nfsm_fhtom_xx(v, v3, &mb, &bpos)) != 0) { \
+			error = t2; \
+			m_freem(mreq); \
+			goto nfsmout; \
 		} \
 	} while (0)
 
@@ -222,17 +202,11 @@
 
 #define	nfsm_postop_attr(v, f) \
 	do { \
-		struct vnode *ttvp = (v); \
-		nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
-		if (((f) = fxdr_unsigned(int, *tl)) != 0) { \
-			if ((t1 = nfs_loadattrcache(&ttvp, &md, &dpos, \
-				(struct vattr *)0, 1)) != 0) { \
-				error = t1; \
-				(f) = 0; \
-				m_freem(mrep); \
-				goto nfsmout; \
-			} \
-			(v) = ttvp; \
+		if ((t1 = nfsm_postop_attr_xx(&(v), &(f), &md, \
+		    &dpos)) != 0) { \
+			error = t1; \
+			m_freem(mrep); \
+			goto nfsmout; \
 		} \
 	} while (0)
 
@@ -242,85 +216,19 @@
 
 #define	nfsm_wcc_data(v, f) \
 	do { \
-		int ttattrf, ttretf = 0; \
-		nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
-		if (*tl == nfs_true) { \
-			nfsm_dissect(tl, u_int32_t *, 6 * NFSX_UNSIGNED); \
-			if (f) \
-				ttretf = (VTONFS(v)->n_mtime == \
-					fxdr_unsigned(u_int32_t, *(tl + 2))); \
-		} \
-		nfsm_postop_attr((v), ttattrf); \
-		if (f) { \
-			(f) = ttretf; \
-		} else { \
-			(f) = ttattrf; \
+		t1 = nfsm_wcc_data_xx(&(v), &(f), &(md), &(dpos)); \
+		if (t1) { \
+			error = t1; \
+			m_freem(mrep); \
+			goto nfsmout; \
 		} \
 	} while (0)
 
 /* If full is true, set all fields, otherwise just set mode and time fields */
 #define nfsm_v3attrbuild(a, full) \
 	do { \
-		if ((a)->va_mode != (mode_t)VNOVAL) {			\
-			nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED);	\
-			*tl++ = nfs_true;				\
-			*tl = txdr_unsigned((a)->va_mode);		\
-		} else {						\
-			nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);	\
-			*tl = nfs_false;				\
-		}							\
-		if ((full) && (a)->va_uid != (uid_t)VNOVAL) {		\
-			nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED);	\
-			*tl++ = nfs_true;				\
-			*tl = txdr_unsigned((a)->va_uid);		\
-		} else {						\
-			nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);	\
-			*tl = nfs_false;				\
-		}							\
-		if ((full) && (a)->va_gid != (gid_t)VNOVAL) {		\
-			nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED);	\
-			*tl++ = nfs_true;				\
-			*tl = txdr_unsigned((a)->va_gid);		\
-		} else {						\
-			nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);	\
-			*tl = nfs_false;				\
-		}							\
-		if ((full) && (a)->va_size != VNOVAL) {			\
-			nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED);	\
-			*tl++ = nfs_true;				\
-			txdr_hyper((a)->va_size, tl);			\
-		} else {						\
-			nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);	\
-			*tl = nfs_false;				\
-		}							\
-		if ((a)->va_atime.tv_sec != VNOVAL) {			\
-			if ((a)->va_atime.tv_sec != time_second) {	\
-				nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED);\
-				*tl++ = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT);\
-				txdr_nfsv3time(&(a)->va_atime, tl);	\
-			} else {					\
-				nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \
-				*tl = txdr_unsigned(NFSV3SATTRTIME_TOSERVER); \
-			}						\
-		} else {						\
-			nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);	\
-			*tl = txdr_unsigned(NFSV3SATTRTIME_DONTCHANGE);	\
-		}							\
-		if ((a)->va_mtime.tv_sec != VNOVAL) {			\
-			if ((a)->va_mtime.tv_sec != time_second) {	\
-				nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED);\
-				*tl++ = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT);\
-				txdr_nfsv3time(&(a)->va_mtime, tl);	\
-			} else {					\
-				nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \
-				*tl = txdr_unsigned(NFSV3SATTRTIME_TOSERVER); \
-			}						\
-		} else {						\
-			nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);	\
-			*tl = txdr_unsigned(NFSV3SATTRTIME_DONTCHANGE);	\
-		}							\
+		nfsm_v3attrbuild_xx(a, full, &mb, &bpos); \
 	} while (0)
-				
 
 #define	nfsm_strsiz(s,m) \
 	do { \

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-stable" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi? <200112172205.aa56337>