From owner-svn-src-head@FreeBSD.ORG Tue Jun 17 00:53:01 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 407D29A6; Tue, 17 Jun 2014 00:53:01 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 2D0E02104; Tue, 17 Jun 2014 00:53:01 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s5H0r1Kn033490; Tue, 17 Jun 2014 00:53:01 GMT (envelope-from alfred@svn.freebsd.org) Received: (from alfred@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s5H0r1GB033489; Tue, 17 Jun 2014 00:53:01 GMT (envelope-from alfred@svn.freebsd.org) Message-Id: <201406170053.s5H0r1GB033489@svn.freebsd.org> From: Alfred Perlstein Date: Tue, 17 Jun 2014 00:53:01 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r267559 - head/share/examples/bhyve X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18 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: Tue, 17 Jun 2014 00:53:01 -0000 Author: alfred Date: Tue Jun 17 00:53:00 2014 New Revision: 267559 URL: http://svnweb.freebsd.org/changeset/base/267559 Log: Support for multiple disks and tap devices. This allows you to give a bhyve instance multiple network devices and disk devices easily by specifying additional "-d " and "-t " options. Reviewed by: neel Sponsored by: Norse Modified: head/share/examples/bhyve/vmrun.sh Modified: head/share/examples/bhyve/vmrun.sh ============================================================================== --- head/share/examples/bhyve/vmrun.sh Mon Jun 16 22:59:18 2014 (r267558) +++ head/share/examples/bhyve/vmrun.sh Tue Jun 17 00:53:00 2014 (r267559) @@ -78,8 +78,8 @@ isofile=${DEFAULT_ISOFILE} memsize=${DEFAULT_MEMSIZE} console=${DEFAULT_CONSOLE} cpus=${DEFAULT_CPUS} -virtio_diskdev=${DEFAULT_VIRTIO_DISK} -tapdev=${DEFAULT_TAPDEV} +tap_total=0 +disk_total=0 apic_opt="" gdbport=0 loader_opt="" @@ -96,7 +96,8 @@ while getopts ac:C:d:e:g:hH:iI:m:t: c ; console=${OPTARG} ;; d) - virtio_diskdev=${OPTARG} + eval "disk_dev${disk_total}=\"${OPTARG}\"" + disk_total=$(($disk_total + 1)) ;; e) loader_opt="${loader_opt} -e ${OPTARG}" @@ -117,7 +118,8 @@ while getopts ac:C:d:e:g:hH:iI:m:t: c ; memsize=${OPTARG} ;; t) - tapdev=${OPTARG} + eval "tap_dev${tap_total}=\"${OPTARG}\"" + tap_total=$(($tap_total + 1)) ;; *) usage @@ -125,6 +127,16 @@ while getopts ac:C:d:e:g:hH:iI:m:t: c ; esac done +if [ $tap_total -eq 0 ] ; then + tap_total=1 + tap_dev0="${DEFAULT_TAPDEV}" +fi +if [ $disk_total -eq 0 ] ; then + disk_total=1 + disk_dev0="${DEFAULT_VIRTIO_DISK}" + +fi + shift $((${OPTIND} - 1)) if [ $# -ne 1 ]; then @@ -136,25 +148,31 @@ if [ -n "${host_base}" ]; then loader_opt="${loader_opt} -h ${host_base}" fi -# Create the virtio diskdev file if needed -if [ ! -f ${virtio_diskdev} ]; then - echo "virtio disk device file \"${virtio_diskdev}\" does not exist." - echo "Creating it ..." - truncate -s 8G ${virtio_diskdev} > /dev/null -fi - -if [ ! -r ${virtio_diskdev} ]; then - echo "virtio disk device file \"${virtio_diskdev}\" is not readable" - exit 1 -fi - -if [ ! -w ${virtio_diskdev} ]; then - echo "virtio disk device file \"${virtio_diskdev}\" is not writable" - exit 1 -fi +make_and_check_diskdev() +{ + local virtio_diskdev="$1" + # Create the virtio diskdev file if needed + if [ ! -f ${virtio_diskdev} ]; then + echo "virtio disk device file \"${virtio_diskdev}\" does not exist." + echo "Creating it ..." + truncate -s 8G ${virtio_diskdev} > /dev/null + fi + + if [ ! -r ${virtio_diskdev} ]; then + echo "virtio disk device file \"${virtio_diskdev}\" is not readable" + exit 1 + fi + + if [ ! -w ${virtio_diskdev} ]; then + echo "virtio disk device file \"${virtio_diskdev}\" is not writable" + exit 1 + fi +} echo "Launching virtual machine \"$vmname\" ..." +virtio_diskdev="$disk_dev0" + while [ 1 ]; do ${BHYVECTL} --vm=${vmname} --destroy > /dev/null 2>&1 @@ -189,12 +207,33 @@ while [ 1 ]; do break fi + # + # Build up args for additional tap and disk devices now. + # + nextslot=2 # slot 0 is hostbridge, slot 1 is lpc + devargs="" # accumulate disk/tap args here + i=0 + while [ $i -lt $tap_total ] ; do + eval "tapname=\$tap_dev${i}" + devargs="$devargs -s $nextslot:0,virtio-net,${tapname} " + nextslot=$(($nextslot + 1)) + i=$(($i + 1)) + done + + i=0 + while [ $i -lt $disk_total ] ; do + eval "disk=\$disk_dev${i}" + make_and_check_diskdev "${disk}" + devargs="$devargs -s $nextslot:0,virtio-blk,${disk} " + nextslot=$(($nextslot + 1)) + i=$(($i + 1)) + done + ${FBSDRUN} -c ${cpus} -m ${memsize} ${apic_opt} -A -H -P \ -g ${gdbport} \ -s 0:0,hostbridge \ -s 1:0,lpc \ - -s 2:0,virtio-net,${tapdev} \ - -s 3:0,virtio-blk,${virtio_diskdev} \ + ${devargs} \ -l com1,${console} \ ${installer_opt} \ ${vmname}