diff options
author | neel <neel@FreeBSD.org> | 2013-10-09 03:56:07 +0000 |
---|---|---|
committer | neel <neel@FreeBSD.org> | 2013-10-09 03:56:07 +0000 |
commit | f9f9a7e61707f80f49be34d2c1af7490549580f9 (patch) | |
tree | acc9a278b9f141070d676a08d2877d23277d20e2 /lib/libvmmapi | |
parent | 97e97b35c8417bc9679c023105f5f38512994440 (diff) | |
download | FreeBSD-src-f9f9a7e61707f80f49be34d2c1af7490549580f9.zip FreeBSD-src-f9f9a7e61707f80f49be34d2c1af7490549580f9.tar.gz |
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)
Diffstat (limited to 'lib/libvmmapi')
-rw-r--r-- | lib/libvmmapi/vmmapi.c | 27 | ||||
-rw-r--r-- | lib/libvmmapi/vmmapi.h | 1 |
2 files changed, 28 insertions, 0 deletions
diff --git a/lib/libvmmapi/vmmapi.c b/lib/libvmmapi/vmmapi.c index 5559803..810b39e 100644 --- a/lib/libvmmapi/vmmapi.c +++ b/lib/libvmmapi/vmmapi.c @@ -43,11 +43,14 @@ __FBSDID("$FreeBSD$"); #include <fcntl.h> #include <unistd.h> +#include <libutil.h> + #include <machine/vmm.h> #include <machine/vmm_dev.h> #include "vmmapi.h" +#define MB (1024 * 1024UL) #define GB (1024 * 1024 * 1024UL) struct vmctx { @@ -124,6 +127,30 @@ vm_destroy(struct vmctx *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 vm_get_memory_seg(struct vmctx *ctx, vm_paddr_t gpa, size_t *ret_len, int *wired) { diff --git a/lib/libvmmapi/vmmapi.h b/lib/libvmmapi/vmmapi.h index 8b53ae0..0720e2e 100644 --- a/lib/libvmmapi/vmmapi.h +++ b/lib/libvmmapi/vmmapi.h @@ -45,6 +45,7 @@ enum vm_mmap_style { 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); |