Index: lib/libvmmapi/vmmapi.c =================================================================== --- lib/libvmmapi/vmmapi.c (revision 256156) +++ lib/libvmmapi/vmmapi.c (working copy) @@ -43,11 +43,14 @@ #include #include +#include + #include #include #include "vmmapi.h" +#define MB (1024 * 1024UL) #define GB (1024 * 1024 * 1024UL) struct vmctx { @@ -124,6 +127,30 @@ } int +vm_parse_memsize(const char *optarg, size_t *ret_memsize) +{ + char *endptr; + size_t optval; + int error; + + optval = strtoul(optarg, &endptr, 0); + if (*optarg != '\0' && *endptr == '\0') { + /* + * For the sake of backward compatibility if the memory size + * specified on the command line is less than a megabyte then + * it is interpreted as being in units of MB. + */ + if (optval < MB) + optval *= MB; + *ret_memsize = optval; + error = 0; + } else + error = expand_number(optarg, ret_memsize); + + return (error); +} + +int vm_get_memory_seg(struct vmctx *ctx, vm_paddr_t gpa, size_t *ret_len, int *wired) { Index: lib/libvmmapi/vmmapi.h =================================================================== --- lib/libvmmapi/vmmapi.h (revision 256156) +++ lib/libvmmapi/vmmapi.h (working copy) @@ -45,6 +45,7 @@ int vm_create(const char *name); struct vmctx *vm_open(const char *name); void vm_destroy(struct vmctx *ctx); +int vm_parse_memsize(const char *optarg, size_t *memsize); int vm_get_memory_seg(struct vmctx *ctx, vm_paddr_t gpa, size_t *ret_len, int *wired); int vm_setup_memory(struct vmctx *ctx, size_t len, enum vm_mmap_style s); Index: share/examples/bhyve/vmrun.sh =================================================================== --- share/examples/bhyve/vmrun.sh (revision 256156) +++ 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 256156) +++ 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 256156) +++ usr.sbin/bhyve/bhyverun.c (working copy) @@ -37,12 +37,14 @@ #include #include +#include #include #include #include #include #include #include +#include #include #include @@ -540,7 +542,9 @@ else break; case 'm': - memsize = strtoul(optarg, NULL, 0) * MB; + error = vm_parse_memsize(optarg, &memsize); + if (error) + errx(EX_USAGE, "invalid memsize '%s'", optarg); break; case 'H': guest_vmexit_on_hlt = 1; Index: usr.sbin/bhyvectl/Makefile =================================================================== --- usr.sbin/bhyvectl/Makefile (revision 256156) +++ usr.sbin/bhyvectl/Makefile (working copy) @@ -7,8 +7,8 @@ NO_MAN= -DPADD= ${LIBVMMAPI} -LDADD= -lvmmapi +DPADD= ${LIBVMMAPI} ${LIBUTIL} +LDADD= -lvmmapi -lutil WARNS?= 3 Index: usr.sbin/bhyveload/Makefile =================================================================== --- usr.sbin/bhyveload/Makefile (revision 256156) +++ 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 256156) +++ 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 256156) +++ usr.sbin/bhyveload/bhyveload.c (working copy) @@ -67,12 +67,14 @@ #include #include #include +#include #include #include #include #include #include #include +#include #include #include @@ -581,9 +583,10 @@ break; case 'm': - mem_size = strtoul(optarg, NULL, 0) * MB; + error = vm_parse_memsize(optarg, &mem_size); + if (error != 0) + errx(EX_USAGE, "Invalid memsize '%s'", optarg); break; - case '?': usage(); }