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}
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "[email protected]"

Reply via email to