-/* $OpenBSD: main.c,v 1.69 2022/05/03 21:39:18 dv Exp $ */
+/* $OpenBSD: main.c,v 1.70 2022/05/04 23:17:25 dv Exp $ */
/*
* Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org>
return (0);
}
-int
-parse_size(struct parse_result *res, char *word)
+void
+parse_size(struct parse_result *res, char *word, const char *type)
{
char result[FMT_SCALED_STRSIZE];
long long val = 0;
if (word != NULL) {
- if (scan_scaled(word, &val) != 0) {
- warn("invalid memory size: %s", word);
- return (-1);
- }
+ if (scan_scaled(word, &val) != 0)
+ err(1, "invalid %s size: %s", type, word);
}
- if (val < (1024 * 1024)) {
- warnx("memory size must be at least 1MB");
- return (-1);
- }
+ if (val < (1024 * 1024))
+ errx(1, "%s size must be at least 1MB", type);
- if (val > VMM_MAX_VM_MEM_SIZE) {
+ if (strcmp("memory", type) == 0 && 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);
+ errx(1, "memory size too large (limit is %s)", result);
else
- warnx("memory size too large");
- return (-1);
+ errx(1, "memory size too large");
}
/* Round down to the megabyte. */
if (res->size != (size_t)val) {
if (fmt_scaled(res->size, result) == 0)
- warnx("memory size rounded to %s", result);
+ warnx("%s size rounded to %s", type, result);
else
- warnx("memory size rounded to %zu bytes", res->size);
+ warnx("%s size rounded to %zuB", type, res->size);
}
-
- return (0);
}
int
input = optarg;
break;
case 's':
- if (parse_size(res, optarg) != 0)
- errx(1, "invalid size: %s", optarg);
+ parse_size(res, optarg, "disk");
break;
default:
ctl_usage(res->ctl);
case 'm':
if (res->size)
errx(1, "memory specified multiple times");
- if (parse_size(res, optarg) != 0)
- errx(1, "invalid memory size: %s", optarg);
+ parse_size(res, optarg, "memory");
break;
case 'n':
if (parse_network(res, optarg) != 0)
-/* $OpenBSD: vmctl.c,v 1.81 2022/05/04 02:24:26 dv Exp $ */
+/* $OpenBSD: vmctl.c,v 1.82 2022/05/04 23:17:25 dv Exp $ */
/*
* Copyright (c) 2014 Mike Larkin <mlarkin@openbsd.org>
* Parameters:
* start_id: optional ID of the VM
* name: optional name of the VM
- * memsize: memory size (MB) of the VM to create
+ * memsize: memory size (in bytes) of the VM to create
* nnics: number of vionet network interfaces to create
* nics: switch names of the network interfaces to create
* ndisks: number of disk images
* type : format of the image file
* imgfile_path: path to the image file to create
* base_path : path to the qcow2 base image
- * imgsize : size of the image file to create (in MB)
+ * imgsize : size of the image file to create (in bytes)
* format : string identifying the format
*
* Return:
-/* $OpenBSD: vmctl.h,v 1.35 2022/05/03 21:39:18 dv Exp $ */
+/* $OpenBSD: vmctl.h,v 1.36 2022/05/04 23:17:25 dv Exp $ */
/*
* Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org>
int vmmaction(struct parse_result *);
int parse_ifs(struct parse_result *, char *, int);
int parse_network(struct parse_result *, char *);
-int parse_size(struct parse_result *, char *);
+void parse_size(struct parse_result *, char *, const char *);
int parse_disktype(const char *, const char **);
int parse_disk(struct parse_result *, char *, int);
int parse_vmid(struct parse_result *, char *, int);
-/* $OpenBSD: parse.y,v 1.60 2022/05/03 21:39:18 dv Exp $ */
+/* $OpenBSD: parse.y,v 1.61 2022/05/04 23:17:25 dv Exp $ */
/*
* Copyright (c) 2007-2016 Reyk Floeter <reyk@openbsd.org>
if (size != val) {
if (fmt_scaled(size, result) == 0)
- log_warnx("memory size rounded to %s", result);
+ log_debug("memory size rounded to %s", result);
else
- log_warnx("memory size rounded to %zd bytes", size);
+ log_debug("memory size rounded to %zd bytes", size);
}
return ((ssize_t)size);
-/* $OpenBSD: vioqcow2.c,v 1.17 2022/01/04 15:21:40 claudio Exp $ */
+/* $OpenBSD: vioqcow2.c,v 1.18 2022/05/04 23:17:25 dv Exp $ */
/*
* Copyright (c) 2018 Ori Bernstein <ori@eigenstate.org>
*/
int
virtio_qcow2_create(const char *imgfile_path,
- const char *base_path, long imgsize)
+ const char *base_path, uint64_t disksz)
{
struct qcheader hdr, basehdr;
int fd, ret;
ssize_t base_len;
- uint64_t l1sz, refsz, disksz, initsz, clustersz;
+ uint64_t l1sz, refsz, initsz, clustersz;
uint64_t l1off, refoff, v, i, l1entrysz, refentrysz;
uint16_t refs;
- disksz = 1024 * 1024 * imgsize;
-
if (base_path) {
fd = open(base_path, O_RDONLY);
if (read(fd, &basehdr, sizeof(basehdr)) != sizeof(basehdr))
-/* $OpenBSD: vioraw.c,v 1.6 2021/06/16 16:55:02 dv Exp $ */
+/* $OpenBSD: vioraw.c,v 1.7 2022/05/04 23:17:25 dv Exp $ */
/*
* Copyright (c) 2018 Ori Bernstein <ori@eigenstate.org>
*
*
* Parameters:
* imgfile_path: path to the image file to create
- * imgsize : size of the image file to create (in MB)
+ * imgsize : size of the image file to create (in bytes)
*
* Return:
* EEXIST: The requested image file already exists
* Exxxx : Various other Exxxx errno codes due to other I/O errors
*/
int
-virtio_raw_create(const char *imgfile_path, long imgsize)
+virtio_raw_create(const char *imgfile_path, uint64_t imgsize)
{
int fd, ret;
return (errno);
/* Extend to desired size */
- if (ftruncate(fd, (off_t)imgsize * 1024 * 1024) == -1) {
+ if (ftruncate(fd, (off_t)imgsize) == -1) {
ret = errno;
close(fd);
unlink(imgfile_path);
-/* $OpenBSD: virtio.h,v 1.41 2021/07/16 16:21:22 dv Exp $ */
+/* $OpenBSD: virtio.h,v 1.42 2022/05/04 23:17:25 dv Exp $ */
/*
* Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org>
int viornd_notifyq(void);
ssize_t virtio_qcow2_get_base(int, char *, size_t, const char *);
-int virtio_qcow2_create(const char *, const char *, long);
+int virtio_qcow2_create(const char *, const char *, uint64_t);
int virtio_qcow2_init(struct virtio_backing *, off_t *, int*, size_t);
-int virtio_raw_create(const char *, long);
+int virtio_raw_create(const char *, uint64_t);
int virtio_raw_init(struct virtio_backing *, off_t *, int*, size_t);
int virtio_blk_io(int, uint16_t, uint32_t *, uint8_t *, void *, uint8_t);