diff --git a/NEWS b/NEWS index 495f12eda8..82b30951d2 100644 --- a/NEWS +++ b/NEWS @@ -329,8 +329,8 @@ CHANGES WITH 260 in spe: the same switch in systemd-nspawn. * systemd-vmspawn gained a new switch --image-format= for selecting the - image format (i.e. support qcow2 in additin to raw) to boot - from. --extra-drive= now takes the image format as a colon separated + image format (i.e. support qcow2 in additin to raw) to boot from. + Also --extra-drive= now takes the image format as a colon separated parameter. Changes in systemd-nsresourced/systemd-mountfsd: diff --git a/man/systemd-vmspawn.xml b/man/systemd-vmspawn.xml index 0b4fef2314..136bd65340 100644 --- a/man/systemd-vmspawn.xml +++ b/man/systemd-vmspawn.xml @@ -489,12 +489,13 @@ - + Takes a disk image or block device on the host and supplies it to the virtual - machine as another drive. Optionally, the image format can be specified by appending a colon and - the format (raw or qcow2). Defaults to raw. - Note that qcow2 is only supported for regular files, not block devices. + machine as another drive. Optionally, the image format can be specified by prefixing the path with + raw or qcow2 and a colon. The format defaults to + raw. Note that qcow2 is only supported for regular files, not + block devices. diff --git a/src/vmspawn/vmspawn.c b/src/vmspawn/vmspawn.c index d68a621e06..fc647b1563 100644 --- a/src/vmspawn/vmspawn.c +++ b/src/vmspawn/vmspawn.c @@ -238,9 +238,9 @@ static int help(void) { " Mount a file or directory from the host into the VM\n" " --bind-ro=SOURCE[:TARGET]\n" " Mount a file or directory, but read-only\n" - " --extra-drive=PATH[:FORMAT]\n" + " --extra-drive=[FORMAT:]PATH\n" " Adds an additional disk to the virtual machine\n" - " (format: raw, qcow2; default: raw)\n" + " (FORMAT: raw, qcow2; default: raw)\n" " --bind-user=NAME Bind user from host to virtual machine\n" " --bind-user-shell=BOOL|PATH\n" " Configure the shell to use for --bind-user= users\n" @@ -559,23 +559,26 @@ static int parse_argv(int argc, char *argv[]) { break; case ARG_EXTRA_DRIVE: { - _cleanup_free_ char *buf = NULL, *drive_path = NULL; ImageFormat format = IMAGE_FORMAT_RAW; + const char *dp = optarg; - const char *colon = strrchr(optarg, ':'); + const char *colon = strchr(dp, ':'); if (colon) { - ImageFormat f = image_format_from_string(colon + 1); + _cleanup_free_ char *fs = strndup(optarg, colon - optarg); + if (!fs) + return log_oom(); + + ImageFormat f = image_format_from_string(fs); if (f < 0) - log_debug_errno(f, "Failed to parse image format '%s', assuming it is a part of path, ignoring: %m", colon + 1); + log_debug_errno(f, "Cannot parse '%s' as an image format, assuming it is a part of path, ignoring.", fs); else { format = f; - buf = strndup(optarg, colon - optarg); - if (!buf) - return log_oom(); + dp = colon + 1; } } - r = parse_path_argument(buf ?: optarg, /* suppress_root= */ false, &drive_path); + _cleanup_free_ char *drive_path = NULL; + r = parse_path_argument(dp, /* suppress_root= */ false, &drive_path); if (r < 0) return r;