svn commit: r212126 - head/sys/boot/i386/libi386

Rick Macklem rmacklem at FreeBSD.org
Thu Sep 2 01:05:11 UTC 2010


Author: rmacklem
Date: Thu Sep  2 01:05:10 2010
New Revision: 212126
URL: http://svn.freebsd.org/changeset/base/212126

Log:
  Modify pxe.c to use the version of nfs_getrootfh() that returns
  the file handle's size and was recently committed to
  lib/libstand/nfs.c. This allows pxeboot to use NFSv3 and work
  correcty for non-FreeBSD as well as FreeBSD NFS servers.
  If built with OLD_NFSV2 defined, the old
  code that predated this patch will be used.
  
  Tested by:	danny at cs.huji.ac.il

Modified:
  head/sys/boot/i386/libi386/pxe.c

Modified: head/sys/boot/i386/libi386/pxe.c
==============================================================================
--- head/sys/boot/i386/libi386/pxe.c	Thu Sep  2 01:00:13 2010	(r212125)
+++ head/sys/boot/i386/libi386/pxe.c	Thu Sep  2 01:05:10 2010	(r212126)
@@ -409,6 +409,7 @@ pxe_perror(int err)
  * Reach inside the libstand NFS code and dig out an NFS handle
  * for the root filesystem.
  */
+#ifdef OLD_NFSV2
 struct nfs_iodesc {
 	struct	iodesc	*iodesc;
 	off_t	off;
@@ -456,6 +457,64 @@ pxe_setnfshandle(char *rootpath)
 	sprintf(cp, "X");
 	setenv("boot.nfsroot.nfshandle", buf, 1);
 }
+#else	/* !OLD_NFSV2 */
+
+#define	NFS_V3MAXFHSIZE		64
+
+struct nfs_iodesc {
+	struct iodesc *iodesc;
+	off_t off;
+	uint32_t fhsize;
+	u_char fh[NFS_V3MAXFHSIZE];
+	/* structure truncated */
+};
+extern struct nfs_iodesc nfs_root_node;
+extern int rpc_port;
+
+static void
+pxe_rpcmountcall()
+{
+	struct iodesc *d;
+	int error;
+
+	if (!(d = socktodesc(pxe_sock)))
+		return;
+        d->myport = htons(--rpc_port);
+        d->destip = rootip;
+	if ((error = nfs_getrootfh(d, rootpath, &nfs_root_node.fhsize,
+	    nfs_root_node.fh)) != 0) {
+		printf("NFS MOUNT RPC error: %d\n", error);
+		nfs_root_node.fhsize = 0;
+	}
+	nfs_root_node.iodesc = d;
+}
+
+static void
+pxe_setnfshandle(char *rootpath)
+{
+	int i;
+	u_char *fh;
+	char buf[2 * NFS_V3MAXFHSIZE + 3], *cp;
+
+	/*
+	 * If NFS files were never opened, we need to do mount call
+	 * ourselves. Use nfs_root_node.iodesc as flag indicating
+	 * previous NFS usage.
+	 */
+	if (nfs_root_node.iodesc == NULL)
+		pxe_rpcmountcall();
+
+	fh = &nfs_root_node.fh[0];
+	buf[0] = 'X';
+	cp = &buf[1];
+	for (i = 0; i < nfs_root_node.fhsize; i++, cp += 2)
+		sprintf(cp, "%02x", fh[i]);
+	sprintf(cp, "X");
+	setenv("boot.nfsroot.nfshandle", buf, 1);
+	sprintf(buf, "%d", nfs_root_node.fhsize);
+	setenv("boot.nfsroot.nfshandlelen", buf, 1);
+}
+#endif	/* OLD_NFSV2 */
 
 void
 pxenv_call(int func)


More information about the svn-src-all mailing list