aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandru Elisei <alexandru.elisei@arm.com>2021-09-23 15:44:59 +0100
committerWill Deacon <will@kernel.org>2021-10-12 09:40:46 +0100
commitcce9616484bd92f76a2b79739ecadaae220940cf (patch)
treefa1dd68eb82a6499b671c56f2fbf9e8ab28a6d8e
parent638630c9f7a364a7601e6ee8b50cd1299e6f9e7d (diff)
downloadkvmtool-cce9616484bd92f76a2b79739ecadaae220940cf.tar.gz
builtin-run: Abstract argument validation into a separate function
kvm_cmd_run_init() is a complex function which parses the command line arguments, configures various aspects of a VM (the size of the RAM, the number of CPUs, the network, the active console, the kernel command line, creates a custom rootfs, etc), and after the recent patches, also does a few checks against mutually exclusive kvmtool arguments. Make the function just that little bit easier to read by moving the argument validation into a separate function. No functional change intended. Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com> Link: https://lore.kernel.org/r/20210923144505.60776-5-alexandru.elisei@arm.com Signed-off-by: Will Deacon <will@kernel.org>
-rw-r--r--builtin-run.c30
1 files changed, 17 insertions, 13 deletions
diff --git a/builtin-run.c b/builtin-run.c
index 6a55e34a..2a14723b 100644
--- a/builtin-run.c
+++ b/builtin-run.c
@@ -455,6 +455,19 @@ static void kvm_run_write_sandbox_cmd(struct kvm *kvm, const char **argv, int ar
close(fd);
}
+static void kvm_run_validate_cfg(struct kvm *kvm)
+{
+ if (kvm->cfg.kernel_filename && kvm->cfg.firmware_filename)
+ die("Only one of --kernel or --firmware can be specified");
+
+ if ((kvm->cfg.vnc && (kvm->cfg.sdl || kvm->cfg.gtk)) ||
+ (kvm->cfg.sdl && kvm->cfg.gtk))
+ die("Only one of --vnc, --sdl or --gtk can be specified");
+
+ if (kvm->cfg.firmware_filename && kvm->cfg.initrd_filename)
+ pr_warning("Ignoring initrd file when loading a firmware image");
+}
+
static struct kvm *kvm_cmd_run_init(int argc, const char **argv)
{
static char real_cmdline[2048], default_name[20];
@@ -511,13 +524,9 @@ static struct kvm *kvm_cmd_run_init(int argc, const char **argv)
}
- kvm->nr_disks = kvm->cfg.image_count;
-
- if (kvm->cfg.kernel_filename && kvm->cfg.firmware_filename)
- die("Only one of --kernel or --firmware can be specified");
+ kvm_run_validate_cfg(kvm);
- if (kvm->cfg.firmware_filename && kvm->cfg.initrd_filename)
- pr_warning("Ignoring initrd file when loading a firmware image");
+ kvm->nr_disks = kvm->cfg.image_count;
if (!kvm->cfg.kernel_filename && !kvm->cfg.firmware_filename) {
kvm->cfg.kernel_filename = find_kernel();
@@ -552,13 +561,6 @@ static struct kvm *kvm_cmd_run_init(int argc, const char **argv)
if (!kvm->cfg.console)
kvm->cfg.console = DEFAULT_CONSOLE;
- video = kvm->cfg.vnc || kvm->cfg.sdl || kvm->cfg.gtk;
- if (video) {
- if ((kvm->cfg.vnc && (kvm->cfg.sdl || kvm->cfg.gtk)) ||
- (kvm->cfg.sdl && kvm->cfg.gtk))
- die("Only one of --vnc, --sdl or --gtk can be specified");
- }
-
if (!strncmp(kvm->cfg.console, "virtio", 6))
kvm->cfg.active_console = CONSOLE_VIRTIO;
else if (!strncmp(kvm->cfg.console, "serial", 6))
@@ -586,6 +588,8 @@ static struct kvm *kvm_cmd_run_init(int argc, const char **argv)
if (!kvm->cfg.network)
kvm->cfg.network = DEFAULT_NETWORK;
+ video = kvm->cfg.vnc || kvm->cfg.sdl || kvm->cfg.gtk;
+
memset(real_cmdline, 0, sizeof(real_cmdline));
kvm__arch_set_cmdline(real_cmdline, video);