summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/vmctl/main.c63
-rw-r--r--usr.sbin/vmctl/vmctl.819
2 files changed, 33 insertions, 49 deletions
diff --git a/usr.sbin/vmctl/main.c b/usr.sbin/vmctl/main.c
index 7065e690889..1269b4eaf91 100644
--- a/usr.sbin/vmctl/main.c
+++ b/usr.sbin/vmctl/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.55 2019/03/18 20:27:12 kn Exp $ */
+/* $OpenBSD: main.c,v 1.56 2019/05/29 21:32:43 reyk Exp $ */
/*
* Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org>
@@ -72,7 +72,7 @@ int ctl_receive(struct parse_result *, int, char *[]);
struct ctl_command ctl_commands[] = {
{ "console", CMD_CONSOLE, ctl_console, "id" },
{ "create", CMD_CREATE, ctl_create,
- "disk [-b base | -i disk] [-s size]", 1 },
+ "[-b base | -i disk] [-s size] disk", 1 },
{ "load", CMD_LOAD, ctl_load, "filename" },
{ "log", CMD_LOG, ctl_log, "[brief | verbose]" },
{ "pause", CMD_PAUSE, ctl_pause, "id" },
@@ -81,11 +81,11 @@ struct ctl_command ctl_commands[] = {
{ "reset", CMD_RESET, ctl_reset, "[all | switches | vms]" },
{ "send", CMD_SEND, ctl_send, "id", 1},
{ "show", CMD_STATUS, ctl_status, "[id]" },
- { "start", CMD_START, ctl_start, "id | name"
+ { "start", CMD_START, ctl_start,
" [-cL] [-B device] [-b path] [-d disk] [-i count]\n"
- "\t\t[-m size] [-n switch] [-r path] [-t name]" },
+ "\t\t[-m size] [-n switch] [-r path] [-t name] id | name" },
{ "status", CMD_STATUS, ctl_status, "[id]" },
- { "stop", CMD_STOP, ctl_stop, "[id | -a] [-fw]" },
+ { "stop", CMD_STOP, ctl_stop, "[-fw] [id | -a]" },
{ "unpause", CMD_UNPAUSE, ctl_unpause, "id" },
{ "wait", CMD_WAITFOR, ctl_waitfor, "id" },
{ NULL }
@@ -561,21 +561,7 @@ int
ctl_create(struct parse_result *res, int argc, char *argv[])
{
int ch, ret, type;
- const char *disk, *format, *base, *input;
-
- if (argc < 2)
- ctl_usage(res->ctl);
-
- base = input = NULL;
- type = parse_disktype(argv[1], &disk);
-
- if (pledge("stdio rpath wpath cpath unveil", NULL) == -1)
- err(1, "pledge");
- if (unveil(disk, "rwc") == -1)
- err(1, "unveil");
-
- argc--;
- argv++;
+ const char *disk, *format, *base = NULL, *input = NULL;
while ((ch = getopt(argc, argv, "b:i:s:")) != -1) {
switch (ch) {
@@ -601,9 +587,16 @@ ctl_create(struct parse_result *res, int argc, char *argv[])
argc -= optind;
argv += optind;
- if (argc > 0)
+ if (argc < 1)
ctl_usage(res->ctl);
+ type = parse_disktype(argv[0], &disk);
+
+ if (pledge("stdio rpath wpath cpath unveil", NULL) == -1)
+ err(1, "pledge");
+ if (unveil(disk, "rwc") == -1)
+ err(1, "unveil");
+
if (input) {
if (base && input)
errx(1, "conflicting -b and -i arguments");
@@ -839,15 +832,6 @@ ctl_start(struct parse_result *res, int argc, char *argv[])
char path[PATH_MAX];
const char *s;
- if (argc < 2)
- ctl_usage(res->ctl);
-
- if (parse_vmid(res, argv[1], 0) == -1)
- errx(1, "invalid id: %s", argv[1]);
-
- argc--;
- argv++;
-
while ((ch = getopt(argc, argv, "b:B:cd:i:Lm:n:r:t:")) != -1) {
switch (ch) {
case 'b':
@@ -920,9 +904,12 @@ ctl_start(struct parse_result *res, int argc, char *argv[])
argc -= optind;
argv += optind;
- if (argc > 0)
+ if (argc != 1)
ctl_usage(res->ctl);
+ if (parse_vmid(res, argv[0], 0) == -1)
+ errx(1, "invalid id: %s", argv[0]);
+
for (i = res->nnets; i < res->nifs; i++) {
/* Add interface that is not attached to a switch */
if (parse_network(res, "") == -1)
@@ -939,14 +926,6 @@ ctl_stop(struct parse_result *res, int argc, char *argv[])
{
int ch, ret;
- if (argc < 2)
- ctl_usage(res->ctl);
-
- if ((ret = parse_vmid(res, argv[1], 0)) == 0) {
- argc--;
- argv++;
- }
-
while ((ch = getopt(argc, argv, "afw")) != -1) {
switch (ch) {
case 'f':
@@ -966,8 +945,12 @@ ctl_stop(struct parse_result *res, int argc, char *argv[])
argc -= optind;
argv += optind;
- if (argc > 0)
+ if (argc > 1)
ctl_usage(res->ctl);
+ else if (argc == 1)
+ ret = parse_vmid(res, argv[0], 0);
+ else
+ ret = -1;
/* VM id is only expected without the -a flag */
if ((res->action != CMD_STOPALL && ret == -1) ||
diff --git a/usr.sbin/vmctl/vmctl.8 b/usr.sbin/vmctl/vmctl.8
index 6f2bff78656..d915414880b 100644
--- a/usr.sbin/vmctl/vmctl.8
+++ b/usr.sbin/vmctl/vmctl.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: vmctl.8,v 1.66 2019/05/14 12:47:17 schwarze Exp $
+.\" $OpenBSD: vmctl.8,v 1.67 2019/05/29 21:32:43 reyk Exp $
.\"
.\" Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org>
.\"
@@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: May 14 2019 $
+.Dd $Mdocdate: May 29 2019 $
.Dt VMCTL 8
.Os
.Sh NAME
@@ -73,7 +73,7 @@ Using
.Xr cu 1
connect to the console of the VM with the specified
.Ar id .
-.It Cm create Ar disk Oo Fl b Ar base | Fl i Ar disk Oc Op Fl s Ar size
+.It Cm create Oo Fl b Ar base | Fl i Ar disk Oc Oo Fl s Ar size Oc Ar disk
Create a VM disk image file with the specified
.Ar disk
path.
@@ -144,7 +144,7 @@ under the same path.
An alias for the
.Cm status
command.
-.It Xo Cm start Ar id | name
+.It Xo Cm start
.Op Fl cL
.Bk -words
.Op Fl B Ar device
@@ -155,6 +155,7 @@ command.
.Op Fl n Ar switch
.Op Fl r Ar path
.Op Fl t Ar name
+.Ar id | name
.Ek
.Xc
Start a new VM
@@ -240,7 +241,7 @@ interface names.
.It Cm status Op Ar id
List VMs running on the host, optionally listing just the selected VM
.Ar id .
-.It Cm stop Oo Ar id | Fl a Oc Op Fl fw
+.It Cm stop Oo Fl fw Oc Oo Fl a | Ar id Oc
Stop (terminate) a VM defined by the specified VM
.Ar id
or all running VMs
@@ -394,7 +395,7 @@ A requested VM-based operation could not be completed.
.Sh EXAMPLES
Create a 4.5 Gigabyte disk image, disk.img:
.Bd -literal -offset indent
-$ vmctl create disk.img -s 4.5G
+$ vmctl create -s 4.5G disk.img
.Ed
.Pp
Convert a disk image from the
@@ -402,19 +403,19 @@ Convert a disk image from the
format to
.Sq qcow2 :
.Bd -literal -offset indent
-$ vmctl create disk.qcow2 -i disk.img
+$ vmctl create -i disk.img disk.qcow2
.Ed
.Pp
Create a new VM with 1GB memory, one network interface, one disk image
('disk.img') and boot from kernel '/bsd':
.Bd -literal -offset indent
-# vmctl start "myvm" -m 1G -i 1 -b /bsd -d disk.img
+# vmctl start -m 1G -i 1 -b /bsd -d disk.img "myvm"
.Ed
.Pp
Start a new VM instance with the name 'myvm' from a pre-configured
VM 'openbsd.4G':
.Bd -literal -offset indent
-# vmctl start "myvm" -t "openbsd.4G" -d mydisk.img
+# vmctl start -t "openbsd.4G" -d mydisk.img "myvm"
.Ed
.Pp
Terminate VM number 1: