changeset 4001:4d632d6bcf85

6446158 Invalid I/O error can be happened due to wrong cast to nfs_fh4_fmt_t
author nr123932
date Tue, 10 Apr 2007 09:59:05 -0700
parents 282750a23d97
children d12f36b7c388
files usr/src/uts/common/fs/nfs/nfs4_state.c usr/src/uts/common/nfs/nfs4.h
diffstat 2 files changed, 50 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/uts/common/fs/nfs/nfs4_state.c	Mon Apr 09 19:26:23 2007 -0700
+++ b/usr/src/uts/common/fs/nfs/nfs4_state.c	Tue Apr 10 09:59:05 2007 -0700
@@ -19,7 +19,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -3648,9 +3648,14 @@
 {
 	rfs4_lo_state_t *lsp = (rfs4_lo_state_t *)u_entry;
 	struct exportinfo *exi = (struct exportinfo *)e;
-	nfs_fh4_fmt_t	*exi_fhp, *finfo_fhp;
-
-	exi_fhp = (nfs_fh4_fmt_t *)&exi->exi_fh;
+	nfs_fh4_fmt_t   fhfmt4, *exi_fhp, *finfo_fhp;
+	fhandle_t *efhp;
+
+	efhp = (fhandle_t *)&exi->exi_fh;
+	exi_fhp = (nfs_fh4_fmt_t *)&fhfmt4;
+
+	FH_TO_FMT4(efhp, exi_fhp);
+
 	finfo_fhp =
 		(nfs_fh4_fmt_t *)lsp->state->finfo->filehandle.nfs_fh4_val;
 
@@ -3677,9 +3682,14 @@
 {
 	rfs4_state_t *sp = (rfs4_state_t *)u_entry;
 	struct exportinfo *exi = (struct exportinfo *)e;
-	nfs_fh4_fmt_t	*exi_fhp, *finfo_fhp;
-
-	exi_fhp = (nfs_fh4_fmt_t *)&exi->exi_fh;
+	nfs_fh4_fmt_t   fhfmt4, *exi_fhp, *finfo_fhp;
+	fhandle_t *efhp;
+
+	efhp = (fhandle_t *)&exi->exi_fh;
+	exi_fhp = (nfs_fh4_fmt_t *)&fhfmt4;
+
+	FH_TO_FMT4(efhp, exi_fhp);
+
 	finfo_fhp =
 		(nfs_fh4_fmt_t *)sp->finfo->filehandle.nfs_fh4_val;
 
@@ -3705,9 +3715,14 @@
 {
 	rfs4_deleg_state_t *dsp = (rfs4_deleg_state_t *)u_entry;
 	struct exportinfo *exi = (struct exportinfo *)e;
-	nfs_fh4_fmt_t	*exi_fhp, *finfo_fhp;
-
-	exi_fhp = (nfs_fh4_fmt_t *)&exi->exi_fh;
+	nfs_fh4_fmt_t   fhfmt4, *exi_fhp, *finfo_fhp;
+	fhandle_t *efhp;
+
+	efhp = (fhandle_t *)&exi->exi_fh;
+	exi_fhp = (nfs_fh4_fmt_t *)&fhfmt4;
+
+	FH_TO_FMT4(efhp, exi_fhp);
+
 	finfo_fhp =
 		(nfs_fh4_fmt_t *)dsp->finfo->filehandle.nfs_fh4_val;
 
@@ -3731,9 +3746,14 @@
 {
 	rfs4_file_t *fp = (rfs4_file_t *)u_entry;
 	struct exportinfo *exi = (struct exportinfo *)e;
-	nfs_fh4_fmt_t *exi_fhp, *finfo_fhp;
-
-	exi_fhp = (nfs_fh4_fmt_t *)&exi->exi_fh;
+	nfs_fh4_fmt_t   fhfmt4, *exi_fhp, *finfo_fhp;
+	fhandle_t *efhp;
+
+	efhp = (fhandle_t *)&exi->exi_fh;
+	exi_fhp = (nfs_fh4_fmt_t *)&fhfmt4;
+
+	FH_TO_FMT4(efhp, exi_fhp);
+
 	finfo_fhp = (nfs_fh4_fmt_t *)fp->filehandle.nfs_fh4_val;
 
 	if (EQFSID(&finfo_fhp->fh4_fsid, &exi_fhp->fh4_fsid) &&
--- a/usr/src/uts/common/nfs/nfs4.h	Mon Apr 09 19:26:23 2007 -0700
+++ b/usr/src/uts/common/nfs/nfs4.h	Tue Apr 10 09:59:05 2007 -0700
@@ -19,7 +19,7 @@
  * CDDL HEADER END
  */
 /*
- * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -1005,6 +1005,22 @@
 
 #define	NFS_FH4_LEN	sizeof (nfs_fh4_fmt_t)
 
+/*
+ * Copy fields from external (fhandle_t) to in-memory (nfs_fh4_fmt_t)
+ * format to support export info checking.  It does not copy over
+ * the complete filehandle, just the fsid, xlen and xdata.  It may
+ * need to be changed to be used in other places.
+ *
+ * NOTE: The macro expects the space to be  pre-allocated for
+ * the contents of nfs_fh4_fmt_t.
+ */
+#define	FH_TO_FMT4(exifh, nfs_fmt) {				\
+	bzero((nfs_fmt), NFS_FH4_LEN);				\
+	(nfs_fmt)->fh4_fsid = (exifh)->fh_fsid;			\
+	(nfs_fmt)->fh4_xlen = (exifh)->fh_xlen;			\
+	bcopy((exifh)->fh_xdata, (nfs_fmt)->fh4_xdata,		\
+	    (exifh)->fh_xlen);					\
+}
 
 /*
  * A few definitions of repeatedly used constructs for nfsv4