diff options
author | ccardenas <ccardenas@cvs.openbsd.org> | 2018-09-11 04:03:17 +0000 |
---|---|---|
committer | ccardenas <ccardenas@cvs.openbsd.org> | 2018-09-11 04:03:17 +0000 |
commit | dc09af11d1b23f840f0fd3f0db1640dab5716def (patch) | |
tree | 69de72ca6407ec811a444d7d74b353e359c293e0 /usr.sbin/vmctl/main.c | |
parent | e5fa89ed80dfed368c51779e8128aa7908f98d17 (diff) |
Add ability to create qcow2 disk.
vmctl create now takes an optional disk format parameter: raw or qcow2.
If format is omitted, raw is used.
Many thanks to Ori Bernstein.
Diffstat (limited to 'usr.sbin/vmctl/main.c')
-rw-r--r-- | usr.sbin/vmctl/main.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/usr.sbin/vmctl/main.c b/usr.sbin/vmctl/main.c index 0652490cdb3..49d982f2ad0 100644 --- a/usr.sbin/vmctl/main.c +++ b/usr.sbin/vmctl/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.40 2018/09/09 04:09:32 ccardenas Exp $ */ +/* $OpenBSD: main.c,v 1.41 2018/09/11 04:03:16 ccardenas Exp $ */ /* * Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org> @@ -63,7 +63,8 @@ int ctl_receive(struct parse_result *, int, char *[]); struct ctl_command ctl_commands[] = { { "console", CMD_CONSOLE, ctl_console, "id" }, - { "create", CMD_CREATE, ctl_create, "\"path\" -s size", 1 }, + { "create", CMD_CREATE, ctl_create, + "\"path\" -s size [-f fmt]", 1 }, { "load", CMD_LOAD, ctl_load, "\"path\"" }, { "log", CMD_LOG, ctl_log, "(verbose|brief)" }, { "reload", CMD_RELOAD, ctl_reload, "" }, @@ -497,24 +498,28 @@ int ctl_create(struct parse_result *res, int argc, char *argv[]) { int ch, ret; - const char *paths[2]; + const char *paths[2], *format; if (argc < 2) ctl_usage(res->ctl); paths[0] = argv[1]; paths[1] = NULL; + format = "raw"; if (pledge("stdio rpath wpath cpath", NULL) == -1) err(1, "pledge"); argc--; argv++; - while ((ch = getopt(argc, argv, "s:")) != -1) { + while ((ch = getopt(argc, argv, "s:f:")) != -1) { switch (ch) { case 's': if (parse_size(res, optarg, 0) != 0) errx(1, "invalid size: %s", optarg); break; + case 'f': + format = optarg; + break; default: ctl_usage(res->ctl); /* NOTREACHED */ @@ -525,7 +530,12 @@ ctl_create(struct parse_result *res, int argc, char *argv[]) fprintf(stderr, "missing size argument\n"); ctl_usage(res->ctl); } - ret = create_imagefile(paths[0], res->size); + if (strcmp(format, "raw") == 0) + ret = create_raw_imagefile(paths[0], res->size); + else if (strcmp(format, "qcow2") == 0) + ret = create_qc2_imagefile(paths[0], res->size); + else + errx(1, "unknown image format %s", format); if (ret != 0) { errno = ret; err(1, "create imagefile operation failed"); |