From owner-freebsd-virtualization@FreeBSD.ORG Mon Oct 7 06:31:31 2013 Return-Path: Delivered-To: freebsd-virtualization@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 ESMTP id A227BAD3; Mon, 7 Oct 2013 06:31:31 +0000 (UTC) (envelope-from crodr001@gmail.com) Received: from mail-lb0-x22c.google.com (mail-lb0-x22c.google.com [IPv6:2a00:1450:4010:c04::22c]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id DDAB62757; Mon, 7 Oct 2013 06:31:30 +0000 (UTC) Received: by mail-lb0-f172.google.com with SMTP id x18so5215062lbi.31 for ; Sun, 06 Oct 2013 23:31:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=XJokHoaB+jM18btcyj5/fAhgxk28IqpOsXXCzyYRLK8=; b=BjFGMpbHYKGRGy/MSOVq2Pa41HyQhknn5t2oGMVE0Gfd57PFksQxd8DOekmdpeNABh 2DM/GvZfeaQastcJRfWO7VuFSs0STPjcv9+hVvA4IWq/BgwR1fA9qk3iR3KfUuLolL7s NjWcTdpTMRs4ZDsqCRMDY7YAJv6C/t6nineTn5iFjAHefCL/jZLJ6bfeuTJYqVJlBm87 0WpyLsP/Cdnhk28c6xVSPriYlJK5Xxia1+dkQe4KcW0JmjFw+/+dBOnMrpPr05nmJ52z jcDmuUKhr4SCzaLokRXnsaLWXp3h/gryZp2elEP2rYCTyJdDOoDpmDnvfBq1ggngIE+E S3hw== MIME-Version: 1.0 X-Received: by 10.152.7.100 with SMTP id i4mr317260laa.35.1381127488793; Sun, 06 Oct 2013 23:31:28 -0700 (PDT) Sender: crodr001@gmail.com Received: by 10.112.139.132 with HTTP; Sun, 6 Oct 2013 23:31:28 -0700 (PDT) In-Reply-To: <524F27A5.5010307@freebsd.org> References: <524F27A5.5010307@freebsd.org> Date: Sun, 6 Oct 2013 23:31:28 -0700 X-Google-Sender-Auth: QJMESrPt6nW4xZNdwk3g5pHM0bs Message-ID: Subject: Re: Use humanize_number() inside bhyveload? From: Craig Rodrigues To: Peter Grehan Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.14 Cc: "freebsd-virtualization@freebsd.org" X-BeenThere: freebsd-virtualization@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Discussion of various virtualization techniques FreeBSD supports." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 Oct 2013 06:31:31 -0000 On Fri, Oct 4, 2013 at 1:40 PM, Peter Grehan wrote: > Hi Craig, > > > Can we use expand_number() in bhyve_load? >> > > Please commit this change :) > > later, > > Peter. > > Here is a bigger patch, which uses expand_number() in bhyveload and bhyve, and also changes comments in vmrun.sh to reflect the change. Index: share/examples/bhyve/vmrun.sh =================================================================== --- share/examples/bhyve/vmrun.sh (revision 256073) +++ share/examples/bhyve/vmrun.sh (working copy) @@ -31,7 +31,7 @@ BHYVECTL=/usr/sbin/bhyvectl FBSDRUN=/usr/sbin/bhyve -DEFAULT_MEMSIZE=512 +DEFAULT_MEMSIZE=512M DEFAULT_CPUS=2 DEFAULT_TAPDEV=tap0 @@ -47,7 +47,7 @@ echo " -g: listen for connection from kgdb at " echo " -i: force boot of the Installation CDROM image" echo " -I: Installation CDROM image location (default is ${DEFAULT_ISOFILE})" - echo " -m: memory size in MB (default is ${DEFAULT_MEMSIZE}MB)" + echo " -m: memory size (default is ${DEFAULT_MEMSIZE})" echo " -t: tap device for virtio-net (default is $DEFAULT_TAPDEV)" echo "" echo " This script needs to be executed with superuser privileges" Index: usr.sbin/bhyve/Makefile =================================================================== --- usr.sbin/bhyve/Makefile (revision 256073) +++ usr.sbin/bhyve/Makefile (working copy) @@ -17,8 +17,8 @@ NO_MAN= -DPADD= ${LIBVMMAPI} ${LIBMD} ${LIBPTHREAD} -LDADD= -lvmmapi -lmd -lpthread +DPADD= ${LIBVMMAPI} ${LIBMD} ${LIBUTIL} ${LIBPTHREAD} +LDADD= -lvmmapi -lmd -lutil -lpthread WARNS?= 2 Index: usr.sbin/bhyve/bhyverun.c =================================================================== --- usr.sbin/bhyve/bhyverun.c (revision 256073) +++ usr.sbin/bhyve/bhyverun.c (working copy) @@ -37,7 +37,9 @@ #include #include +#include #include +#include #include #include #include @@ -541,6 +543,9 @@ break; case 'm': memsize = strtoul(optarg, NULL, 0) * MB; + if (expand_number(optarg, &memsize) == -1) + errx(EXIT_FAILURE, + "invalid size argument `%s'", optarg); break; case 'H': guest_vmexit_on_hlt = 1; Index: usr.sbin/bhyveload/Makefile =================================================================== --- usr.sbin/bhyveload/Makefile (revision 256073) +++ usr.sbin/bhyveload/Makefile (working copy) @@ -4,8 +4,8 @@ SRCS= bhyveload.c MAN= bhyveload.8 -DPADD+= ${LIBVMMAPI} -LDADD+= -lvmmapi +DPADD+= ${LIBVMMAPI} ${LIBUTIL} +LDADD+= -lvmmapi -lutil WARNS?= 3 Index: usr.sbin/bhyveload/bhyveload.8 =================================================================== --- usr.sbin/bhyveload/bhyveload.8 (revision 256073) +++ usr.sbin/bhyveload/bhyveload.8 (working copy) @@ -1,4 +1,4 @@ -.\" +\" .\" Copyright (c) 2012 NetApp Inc .\" All rights reserved. .\" @@ -60,13 +60,29 @@ .Sh OPTIONS The following options are available: .Bl -tag -width indent -.It Fl m Ar mem-size +.It Fl m Ar mem-size Xo +.Sm off +.Op Cm K | k | M | m | G | g | T | t +.Xc +.Sm on .Ar mem-size -is the amount of memory allocated to the guest in units of megabytes. +is the amount of memory allocated to the guest. .Pp +The +.Ar mem-size +argument may be suffixed with one of +.Cm K , +.Cm M , +.Cm G +or +.Cm T +(either upper or lower case) to indicate a multiple of +Kilobytes, Megabytes, Gigabytes or Terabytes +respectively. +.Pp The default value of .Ar mem-size -is 256. +is 256M. .It Fl d Ar disk-path The .Ar disk-path @@ -83,7 +99,7 @@ .Pa /freebsd/release.iso and has 1GB memory allocated to it: .Pp -.Dl "bhyveload -m 1024 -d /freebsd/release.iso freebsd-vm" +.Dl "bhyveload -m 1G -d /freebsd/release.iso freebsd-vm" .Sh SEE ALSO .Xr bhyve 4 , .Xr bhyve 8 , Index: usr.sbin/bhyveload/bhyveload.c =================================================================== --- usr.sbin/bhyveload/bhyveload.c (revision 256073) +++ usr.sbin/bhyveload/bhyveload.c (working copy) @@ -67,9 +67,11 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -581,7 +583,9 @@ break; case 'm': - mem_size = strtoul(optarg, NULL, 0) * MB; + if (expand_number(optarg, &mem_size) == -1) + errx(EXIT_FAILURE, + "invalid size argument `%s'", optarg); break; case '?':