poky/scripts/runqemu-export-rootfs
Cody P Schafer 6bb9860ef7 runqemu-export-rootfs: don't change RPC ports
RPC ports (also known as rpc program numbers) are values:

 - given to rpcbind (aka portmapper) to allow nfsv3 clients that don't
   know the tcp/udp port number of nfsd and mountd to look it up the
   tcp/udp port number, and to

 - allow a single transport (ie: tcp/udp port) to provide multiple
   sunrpc services.

OE has carried patches to nfsutils & linux for some time to support the
mountprog & nfsprog options.

In the case of runqemu-export-rootfs, we don't need to use custom rpc
program numbers because runqemu-export-rootfs tells unfsd not to
register with the portmapper, and unfsd runs the nfs and mount rpc
services on tcp/udp ports unfsd binds itself (iow: the tcp/udp ports are
not shared in the sunrpc sense).

Linux's nfs client does not query rpcbind when tcp/udp port numbers are
specified (in net/sunrpc/clnt.c, call_bind checks for the tcp/udp port
with xprt_bound() and skips the call to rpcbind if xprtsock.c's
xs_setup_udp() or xs_setup_tcp() has found a non-zero tcp/udp port).

The program numbers _are_ sent over the mount & nfs protocol (really,
over sunrpc), and checked to match at both ends. As a result, even when
rpcbind is unused, using different program numbers in unfsd vs linux
nfs client causes mounts to fail (and nfsroot mounts to timeout).

The result is that specifying custom program numbers in
runqemu-export-rootfs doesn't solve any conflicts, it simply requires
that users of runqemu-export-rootfs carry a kernel patch & adds 2 extra
parameters to the kernel command line unnecessarily.

Change runqemu-export-rootfs to use the default program numbers.

For now, I have not dropped the custom program number patches to linux,
nfs-utils, and unfsd just in case someone is using them in a
non-runqemu-export-rootfs context.

CC: Bruce Ashfield <bruce.ashfield@gmail.com>
CC: Mark Hatle <mark.hatle@windriver.com>
(From OE-Core rev: 9c91df324dfe58273f5a1d1d33dba1d34a180db7)

Signed-off-by: Cody P Schafer <dev@codyps.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2017-06-12 15:08:32 +01:00

157 lines
4.4 KiB
Bash
Executable File

#!/bin/bash
#
# Copyright (c) 2005-2009 Wind River Systems, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
usage() {
echo "Usage: $0 {start|stop|restart} <nfs-export-dir>"
}
if [ $# != 2 ]; then
usage
exit 1
fi
if [[ "$1" != "start" && "$1" != "stop" && "$1" != "restart" ]]; then
echo "Unknown command '$1'"
usage
exit 1
fi
if [ ! -d "$2" ]; then
echo "Error: '$2' does not exist"
usage
exit 1
fi
# Ensure the nfs-export-dir is an absolute path
NFS_EXPORT_DIR=$(cd "$2" && pwd)
SYSROOT_SETUP_SCRIPT=`which oe-find-native-sysroot 2> /dev/null`
if [ -z "$SYSROOT_SETUP_SCRIPT" ]; then
echo "Error: Unable to find the oe-find-native-sysroot script"
echo "Did you forget to source your build environment setup script?"
exit 1
fi
. $SYSROOT_SETUP_SCRIPT meta-ide-support
if [ ! -e "$OECORE_NATIVE_SYSROOT/usr/bin/unfsd" ]; then
echo "Error: Unable to find unfsd binary in $OECORE_NATIVE_SYSROOT/usr/bin/"
if [ "x$OECORE_DISTRO_VERSION" = "x" ]; then
echo "Have you run 'bitbake meta-ide-support'?"
else
echo "This shouldn't happen - something is missing from your toolchain installation"
fi
exit 1
fi
if [ ! -d ~/.runqemu-sdk ]; then
mkdir -p ~/.runqemu-sdk
fi
NFS_INSTANCE=${NFS_INSTANCE:=0}
EXPORTS=~/.runqemu-sdk/exports$NFS_INSTANCE
RMTAB=~/.runqemu-sdk/rmtab$NFS_INSTANCE
NFSPID=~/.runqemu-sdk/nfs$NFS_INSTANCE.pid
MOUNTPID=~/.runqemu-sdk/mount$NFS_INSTANCE.pid
PSEUDO_OPTS="-P $OECORE_NATIVE_SYSROOT/usr"
PSEUDO_LOCALSTATEDIR="$NFS_EXPORT_DIR/../$(basename $NFS_EXPORT_DIR).pseudo_state"
export PSEUDO_LOCALSTATEDIR
if [ ! -d "$PSEUDO_LOCALSTATEDIR" ]; then
echo "Error: $PSEUDO_LOCALSTATEDIR does not exist."
echo "Did you create the export directory using runqemu-extract-sdk?"
exit 1
fi
# NFS server port number
NFSD_PORT=${NFSD_PORT:=$[ 3049 + 2 * $NFS_INSTANCE ]}
# mountd port number
MOUNTD_PORT=${MOUNTD_PORT:=$[ 3048 + 2 * $NFS_INSTANCE ]}
## For debugging you would additionally add
## --debug all
UNFSD_OPTS="-p -N -i $NFSPID -e $EXPORTS -n $NFSD_PORT -m $MOUNTD_PORT"
# See how we were called.
case "$1" in
start)
PORTMAP_RUNNING=`ps -ef | grep portmap | grep -v grep`
RPCBIND_RUNNING=`ps -ef | grep rpcbind | grep -v grep`
if [[ "x$PORTMAP_RUNNING" = "x" && "x$RPCBIND_RUNNING" = "x" ]]; then
echo "======================================================="
echo "Error: neither rpcbind nor portmap appear to be running"
echo "Please install and start one of these services first"
echo "======================================================="
echo "Tip: for recent Ubuntu hosts, run:"
echo " sudo apt-get install rpcbind"
echo "Then add OPTIONS=\"-i -w\" to /etc/default/rpcbind and run"
echo " sudo service portmap restart"
exit 1
fi
echo "Creating exports file..."
echo "$NFS_EXPORT_DIR (rw,no_root_squash,no_all_squash,insecure)" > $EXPORTS
echo "Starting User Mode nfsd"
echo " $PSEUDO $PSEUDO_OPTS $OECORE_NATIVE_SYSROOT/usr/bin/unfsd $UNFSD_OPTS"
$PSEUDO $PSEUDO_OPTS $OECORE_NATIVE_SYSROOT/usr/bin/unfsd $UNFSD_OPTS
if [ ! $? = 0 ]; then
echo "Error starting nfsd"
exit 1
fi
# Check to make sure everything started ok.
if [ ! -f $NFSPID ]; then
echo "rpc.nfsd did not start correctly"
exit 1
fi
ps -fp `cat $NFSPID` > /dev/null 2> /dev/null
if [ ! $? = 0 ]; then
echo "rpc.nfsd did not start correctly"
exit 1
fi
echo " "
echo "On your target please remember to add the following options for NFS"
echo "nfsroot=IP_ADDRESS:$NFS_EXPORT_DIR,nfsvers=3,port=$NFSD_PORT,udp,mountport=$MOUNTD_PORT"
;;
stop)
if [ -f "$NFSPID" ]; then
echo "Stopping rpc.nfsd"
kill `cat $NFSPID`
rm -f $NFSPID
else
echo "No PID file, not stopping rpc.nfsd"
fi
if [ -f "$EXPORTS" ]; then
echo "Removing exports file"
rm -f $EXPORTS
fi
;;
restart)
$0 stop $NFS_EXPORT_DIR
$0 start $NFS_EXPORT_DIR
if [ ! $? = 0 ]; then
exit 1
fi
;;
*)
echo "$0 {start|stop|restart} <nfs-export-dir>"
;;
esac
exit 0