diff options
author | Dave Voutila <dv@cvs.openbsd.org> | 2022-05-03 21:39:20 +0000 |
---|---|---|
committer | Dave Voutila <dv@cvs.openbsd.org> | 2022-05-03 21:39:20 +0000 |
commit | d479378255c624fc6c59decbdb6d7bb1e8116f90 (patch) | |
tree | caf894147d0004510e88894ede3de641155504ff /usr.sbin/vmctl | |
parent | 0f1c45970db92052b0289d483f6692318feda2f8 (diff) |
vmm/vmd/vmctl: standardize memory units to bytes
At different points in the vm lifecycle vmm(4), vmctl(8), and vmd(8)
refer to a vm's memory range sizes in either bytes or megabytes.
This is needlessly complex.
Switch to using bytes everywhere and adjust types and constants
accordingly. While this makes it possible to specify vm's with
memory in fractions of megabytes, the logic requiring whole
megabyte values remains.
Feedback from deraadt@, mlarkin@, and Matthew Martin.
ok mlarkin@
Diffstat (limited to 'usr.sbin/vmctl')
-rw-r--r-- | usr.sbin/vmctl/main.c | 31 | ||||
-rw-r--r-- | usr.sbin/vmctl/vmctl.c | 6 | ||||
-rw-r--r-- | usr.sbin/vmctl/vmctl.h | 6 |
3 files changed, 29 insertions, 14 deletions
diff --git a/usr.sbin/vmctl/main.c b/usr.sbin/vmctl/main.c index 0f7e4329a00..37fc4dc642a 100644 --- a/usr.sbin/vmctl/main.c +++ b/usr.sbin/vmctl/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.68 2021/07/12 15:09:22 beck Exp $ */ +/* $OpenBSD: main.c,v 1.69 2022/05/03 21:39:18 dv Exp $ */ /* * Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org> @@ -404,23 +404,38 @@ parse_network(struct parse_result *res, char *word) int parse_size(struct parse_result *res, char *word) { - long long val = 0; + char result[FMT_SCALED_STRSIZE]; + long long val = 0; if (word != NULL) { if (scan_scaled(word, &val) != 0) { - warn("invalid size: %s", word); + warn("invalid memory size: %s", word); return (-1); } } if (val < (1024 * 1024)) { - warnx("size must be at least one megabyte"); + warnx("memory size must be at least 1MB"); return (-1); - } else - res->size = val / 1024 / 1024; + } - if ((res->size * 1024 * 1024) != val) - warnx("size rounded to %lld megabytes", res->size); + if (val > VMM_MAX_VM_MEM_SIZE) { + if (fmt_scaled(VMM_MAX_VM_MEM_SIZE, result) == 0) + warnx("memory size too large (limit is %s)", result); + else + warnx("memory size too large"); + return (-1); + } + + /* Round down to the megabyte. */ + res->size = (val / (1024 * 1024)) * (1024 * 1024); + + if (res->size != (size_t)val) { + if (fmt_scaled(res->size, result) == 0) + warnx("memory size rounded to %s", result); + else + warnx("memory size rounded to %zu bytes", res->size); + } return (0); } diff --git a/usr.sbin/vmctl/vmctl.c b/usr.sbin/vmctl/vmctl.c index 4c0b62fc6e1..b1977f95051 100644 --- a/usr.sbin/vmctl/vmctl.c +++ b/usr.sbin/vmctl/vmctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmctl.c,v 1.79 2021/06/10 19:50:05 dv Exp $ */ +/* $OpenBSD: vmctl.c,v 1.80 2022/05/03 21:39:18 dv Exp $ */ /* * Copyright (c) 2014 Mike Larkin <mlarkin@openbsd.org> @@ -73,7 +73,7 @@ struct imsgbuf *ibuf; * ENOMEM if a memory allocation failure occurred. */ int -vm_start(uint32_t start_id, const char *name, int memsize, int nnics, +vm_start(uint32_t start_id, const char *name, size_t memsize, int nnics, char **nics, int ndisks, char **disks, int *disktypes, char *kernel, char *iso, char *instance, unsigned int bootdevice) { @@ -122,7 +122,7 @@ vm_start(uint32_t start_id, const char *name, int memsize, int nnics, /* * XXX: vmd(8) fills in the actual memory ranges. vmctl(8) - * just passes in the actual memory size in MB here. + * just passes in the actual memory size here. */ vcp->vcp_nmemranges = 1; vcp->vcp_memranges[0].vmr_size = memsize; diff --git a/usr.sbin/vmctl/vmctl.h b/usr.sbin/vmctl/vmctl.h index 4fd2b787deb..6d84c7b1c6c 100644 --- a/usr.sbin/vmctl/vmctl.h +++ b/usr.sbin/vmctl/vmctl.h @@ -1,4 +1,4 @@ -/* $OpenBSD: vmctl.h,v 1.34 2021/01/27 07:21:12 deraadt Exp $ */ +/* $OpenBSD: vmctl.h,v 1.35 2022/05/03 21:39:18 dv Exp $ */ /* * Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org> @@ -48,7 +48,7 @@ struct parse_result { char *name; char *path; char *isopath; - long long size; + size_t size; int nifs; char **nets; int nnets; @@ -93,7 +93,7 @@ int open_imagefile(int, const char *, int, int create_imagefile(int, const char *, const char *, long, const char **); int create_raw_imagefile(const char *, long); int create_qc2_imagefile(const char *, const char *, long); -int vm_start(uint32_t, const char *, int, int, char **, int, +int vm_start(uint32_t, const char *, size_t, int, char **, int, char **, int *, char *, char *, char *, unsigned int); int vm_start_complete(struct imsg *, int *, int); void terminate_vm(uint32_t, const char *, unsigned int); |