Parse the memory size parameter using expand_number() to allow specifying
the memory size more intuitively (e.g. 512M, 4G etc). Submitted by: rodrigc Reviewed by: grehan Approved by: re (blanket)
This commit is contained in:
parent
490cbcd9cb
commit
200758f114
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=256176
@ -43,11 +43,14 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <libutil.h>
|
||||||
|
|
||||||
#include <machine/vmm.h>
|
#include <machine/vmm.h>
|
||||||
#include <machine/vmm_dev.h>
|
#include <machine/vmm_dev.h>
|
||||||
|
|
||||||
#include "vmmapi.h"
|
#include "vmmapi.h"
|
||||||
|
|
||||||
|
#define MB (1024 * 1024UL)
|
||||||
#define GB (1024 * 1024 * 1024UL)
|
#define GB (1024 * 1024 * 1024UL)
|
||||||
|
|
||||||
struct vmctx {
|
struct vmctx {
|
||||||
@ -123,6 +126,30 @@ vm_destroy(struct vmctx *vm)
|
|||||||
free(vm);
|
free(vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
int
|
||||||
vm_get_memory_seg(struct vmctx *ctx, vm_paddr_t gpa, size_t *ret_len,
|
vm_get_memory_seg(struct vmctx *ctx, vm_paddr_t gpa, size_t *ret_len,
|
||||||
int *wired)
|
int *wired)
|
||||||
|
@ -45,6 +45,7 @@ enum vm_mmap_style {
|
|||||||
int vm_create(const char *name);
|
int vm_create(const char *name);
|
||||||
struct vmctx *vm_open(const char *name);
|
struct vmctx *vm_open(const char *name);
|
||||||
void vm_destroy(struct vmctx *ctx);
|
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 vm_get_memory_seg(struct vmctx *ctx, vm_paddr_t gpa, size_t *ret_len,
|
||||||
int *wired);
|
int *wired);
|
||||||
int vm_setup_memory(struct vmctx *ctx, size_t len, enum vm_mmap_style s);
|
int vm_setup_memory(struct vmctx *ctx, size_t len, enum vm_mmap_style s);
|
||||||
|
@ -31,7 +31,7 @@ LOADER=/usr/sbin/bhyveload
|
|||||||
BHYVECTL=/usr/sbin/bhyvectl
|
BHYVECTL=/usr/sbin/bhyvectl
|
||||||
FBSDRUN=/usr/sbin/bhyve
|
FBSDRUN=/usr/sbin/bhyve
|
||||||
|
|
||||||
DEFAULT_MEMSIZE=512
|
DEFAULT_MEMSIZE=512M
|
||||||
DEFAULT_CPUS=2
|
DEFAULT_CPUS=2
|
||||||
DEFAULT_TAPDEV=tap0
|
DEFAULT_TAPDEV=tap0
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ usage() {
|
|||||||
echo " -g: listen for connection from kgdb at <gdbport>"
|
echo " -g: listen for connection from kgdb at <gdbport>"
|
||||||
echo " -i: force boot of the Installation CDROM image"
|
echo " -i: force boot of the Installation CDROM image"
|
||||||
echo " -I: Installation CDROM image location (default is ${DEFAULT_ISOFILE})"
|
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 " -t: tap device for virtio-net (default is $DEFAULT_TAPDEV)"
|
||||||
echo ""
|
echo ""
|
||||||
echo " This script needs to be executed with superuser privileges"
|
echo " This script needs to be executed with superuser privileges"
|
||||||
|
@ -17,8 +17,8 @@ SRCS+= vmm_instruction_emul.c
|
|||||||
|
|
||||||
NO_MAN=
|
NO_MAN=
|
||||||
|
|
||||||
DPADD= ${LIBVMMAPI} ${LIBMD} ${LIBPTHREAD}
|
DPADD= ${LIBVMMAPI} ${LIBMD} ${LIBUTIL} ${LIBPTHREAD}
|
||||||
LDADD= -lvmmapi -lmd -lpthread
|
LDADD= -lvmmapi -lmd -lutil -lpthread
|
||||||
|
|
||||||
WARNS?= 2
|
WARNS?= 2
|
||||||
|
|
||||||
|
@ -37,12 +37,14 @@ __FBSDID("$FreeBSD$");
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <err.h>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <pthread_np.h>
|
#include <pthread_np.h>
|
||||||
|
#include <sysexits.h>
|
||||||
|
|
||||||
#include <machine/vmm.h>
|
#include <machine/vmm.h>
|
||||||
#include <vmmapi.h>
|
#include <vmmapi.h>
|
||||||
@ -529,7 +531,9 @@ main(int argc, char *argv[])
|
|||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
memsize = strtoul(optarg, NULL, 0) * MB;
|
error = vm_parse_memsize(optarg, &memsize);
|
||||||
|
if (error)
|
||||||
|
errx(EX_USAGE, "invalid memsize '%s'", optarg);
|
||||||
break;
|
break;
|
||||||
case 'H':
|
case 'H':
|
||||||
guest_vmexit_on_hlt = 1;
|
guest_vmexit_on_hlt = 1;
|
||||||
|
@ -7,8 +7,8 @@ SRCS= bhyvectl.c
|
|||||||
|
|
||||||
NO_MAN=
|
NO_MAN=
|
||||||
|
|
||||||
DPADD= ${LIBVMMAPI}
|
DPADD= ${LIBVMMAPI} ${LIBUTIL}
|
||||||
LDADD= -lvmmapi
|
LDADD= -lvmmapi -lutil
|
||||||
|
|
||||||
WARNS?= 3
|
WARNS?= 3
|
||||||
|
|
||||||
|
@ -4,8 +4,8 @@ PROG= bhyveload
|
|||||||
SRCS= bhyveload.c
|
SRCS= bhyveload.c
|
||||||
MAN= bhyveload.8
|
MAN= bhyveload.8
|
||||||
|
|
||||||
DPADD+= ${LIBVMMAPI}
|
DPADD+= ${LIBVMMAPI} ${LIBUTIL}
|
||||||
LDADD+= -lvmmapi
|
LDADD+= -lvmmapi -lutil
|
||||||
|
|
||||||
WARNS?= 3
|
WARNS?= 3
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
.\"
|
\"
|
||||||
.\" Copyright (c) 2012 NetApp Inc
|
.\" Copyright (c) 2012 NetApp Inc
|
||||||
.\" All rights reserved.
|
.\" All rights reserved.
|
||||||
.\"
|
.\"
|
||||||
@ -60,13 +60,29 @@ and will be created if it does not already exist.
|
|||||||
.Sh OPTIONS
|
.Sh OPTIONS
|
||||||
The following options are available:
|
The following options are available:
|
||||||
.Bl -tag -width indent
|
.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
|
.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
|
.Pp
|
||||||
The default value of
|
The default value of
|
||||||
.Ar mem-size
|
.Ar mem-size
|
||||||
is 256.
|
is 256M.
|
||||||
.It Fl d Ar disk-path
|
.It Fl d Ar disk-path
|
||||||
The
|
The
|
||||||
.Ar disk-path
|
.Ar disk-path
|
||||||
@ -83,7 +99,7 @@ that boots off the ISO image
|
|||||||
.Pa /freebsd/release.iso
|
.Pa /freebsd/release.iso
|
||||||
and has 1GB memory allocated to it:
|
and has 1GB memory allocated to it:
|
||||||
.Pp
|
.Pp
|
||||||
.Dl "bhyveload -m 1024 -d /freebsd/release.iso freebsd-vm"
|
.Dl "bhyveload -m 1G -d /freebsd/release.iso freebsd-vm"
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr bhyve 4 ,
|
.Xr bhyve 4 ,
|
||||||
.Xr bhyve 8 ,
|
.Xr bhyve 8 ,
|
||||||
|
@ -67,12 +67,14 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <err.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sysexits.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
@ -581,9 +583,10 @@ main(int argc, char** argv)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'm':
|
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;
|
break;
|
||||||
|
|
||||||
case '?':
|
case '?':
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user