From owner-svn-src-head@FreeBSD.ORG Thu Sep 2 01:05:11 2010 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0BE6A10656C2; Thu, 2 Sep 2010 01:05:11 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id D4B3A8FC17; Thu, 2 Sep 2010 01:05:10 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o8215AS0087185; Thu, 2 Sep 2010 01:05:10 GMT (envelope-from rmacklem@svn.freebsd.org) Received: (from rmacklem@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o8215AVd087183; Thu, 2 Sep 2010 01:05:10 GMT (envelope-from rmacklem@svn.freebsd.org) Message-Id: <201009020105.o8215AVd087183@svn.freebsd.org> From: Rick Macklem Date: Thu, 2 Sep 2010 01:05:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212126 - head/sys/boot/i386/libi386 X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Sep 2010 01:05:11 -0000 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)