From patchwork Wed Sep 5 08:31:36 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 1406421 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 00A9540220 for ; Wed, 5 Sep 2012 08:32:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756996Ab2IEIcB (ORCPT ); Wed, 5 Sep 2012 04:32:01 -0400 Received: from mail-we0-f174.google.com ([74.125.82.174]:45317 "EHLO mail-we0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750999Ab2IEIby (ORCPT ); Wed, 5 Sep 2012 04:31:54 -0400 Received: by weyx8 with SMTP id x8so220516wey.19 for ; Wed, 05 Sep 2012 01:31:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=Z1OYBavkaHJlOJblg7AcIsXC88S97/4liz3pfzrd0YA=; b=zNPchOXTo+NX//tS9szGfZJ+n/KoqQk4HITKyxFJYRVXAu6ECeZ5QWwsE1ORbEGiJp MAM3q4FbMGhznxYxt3MBiTY5HTi2D9XaG/w+j+KkS8Ozn2JZ95YAvjMel0q6yH+24ONP ciCm5LBl+9PHH6YpI437Atb13AbA9bEAVCHsHbPaRSLt/ISNJB1QpTSypwrzrSCbvH+n 6kVBDU/Pm7bGNwIYjTvqNnRnN1Ll3cSBCiiKqhBWfX4pVItmwnVHyPEwOet4n+0TrXCj vdO3OHb2klVsd1xwoFQX1x4bYzq5au/U37IYUrhS7mgOnIyd12GG+BtizVMbNmYEVDQY iuUg== Received: by 10.216.54.146 with SMTP id i18mr12687236wec.187.1346833912850; Wed, 05 Sep 2012 01:31:52 -0700 (PDT) Received: from lappy.capriciverd.com (20.Red-80-59-140.staticIP.rima-tde.net. [80.59.140.20]) by mx.google.com with ESMTPS id q4sm27971068wix.9.2012.09.05.01.31.50 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 05 Sep 2012 01:31:52 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org Cc: asias.hejun@gmail.com, mingo@elte.hu, gorcunov@openvz.org, kvm@vger.kernel.org, Sasha Levin Subject: [PATCH 02/33] kvm tools: generate command line options dynamically Date: Wed, 5 Sep 2012 10:31:36 +0200 Message-Id: <1346833927-15740-3-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.12 In-Reply-To: <1346833927-15740-1-git-send-email-levinsasha928@gmail.com> References: <1346833927-15740-1-git-send-email-levinsasha928@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Since we now store options in a struct, we should generate the command line options dynamically. This is a pre-requisite to the following patch moving the options into struct kvm. Signed-off-by: Sasha Levin --- tools/kvm/builtin-run.c | 132 ++++++++++++++++++++++++++---------------------- 1 file changed, 72 insertions(+), 60 deletions(-) diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c index 19260c3..db5ae4b 100644 --- a/tools/kvm/builtin-run.c +++ b/tools/kvm/builtin-run.c @@ -455,66 +455,76 @@ static int shmem_parser(const struct option *opt, const char *arg, int unset) return 0; } -static const struct option options[] = { - OPT_GROUP("Basic options:"), - OPT_STRING('\0', "name", &cfg.guest_name, "guest name", - "A name for the guest"), - OPT_INTEGER('c', "cpus", &nrcpus, "Number of CPUs"), - OPT_U64('m', "mem", &cfg.ram_size, "Virtual machine memory size in MiB."), - OPT_CALLBACK('\0', "shmem", NULL, - "[pci:]:[:handle=][:create]", - "Share host shmem with guest via pci device", - shmem_parser), - OPT_CALLBACK('d', "disk", NULL, "image or rootfs_dir", "Disk image or rootfs directory", img_name_parser), - OPT_BOOLEAN('\0', "balloon", &cfg.balloon, "Enable virtio balloon"), - OPT_BOOLEAN('\0', "vnc", &cfg.vnc, "Enable VNC framebuffer"), - OPT_BOOLEAN('\0', "sdl", &cfg.sdl, "Enable SDL framebuffer"), - OPT_BOOLEAN('\0', "rng", &cfg.virtio_rng, "Enable virtio Random Number Generator"), - OPT_CALLBACK('\0', "9p", NULL, "dir_to_share,tag_name", - "Enable virtio 9p to share files between host and guest", virtio_9p_rootdir_parser), - OPT_STRING('\0', "console", &cfg.console, "serial, virtio or hv", - "Console to use"), - OPT_STRING('\0', "dev", &cfg.dev, "device_file", "KVM device file"), - OPT_CALLBACK('\0', "tty", NULL, "tty id", - "Remap guest TTY into a pty on the host", - tty_parser), - OPT_STRING('\0', "sandbox", &cfg.sandbox, "script", - "Run this script when booting into custom rootfs"), - OPT_STRING('\0', "hugetlbfs", &cfg.hugetlbfs_path, "path", "Hugetlbfs path"), - - OPT_GROUP("Kernel options:"), - OPT_STRING('k', "kernel", &cfg.kernel_filename, "kernel", - "Kernel to boot in virtual machine"), - OPT_STRING('i', "initrd", &cfg.initrd_filename, "initrd", - "Initial RAM disk image"), - OPT_STRING('p', "params", &cfg.kernel_cmdline, "params", - "Kernel command line arguments"), - OPT_STRING('f', "firmware", &cfg.firmware_filename, "firmware", - "Firmware image to boot in virtual machine"), - - OPT_GROUP("Networking options:"), - OPT_CALLBACK_DEFAULT('n', "network", NULL, "network params", - "Create a new guest NIC", - netdev_parser, NULL), - OPT_BOOLEAN('\0', "no-dhcp", &cfg.no_dhcp, "Disable kernel DHCP in rootfs mode"), - - OPT_GROUP("BIOS options:"), - OPT_INTEGER('\0', "vidmode", &vidmode, - "Video mode"), - - OPT_GROUP("Debug options:"), - OPT_BOOLEAN('\0', "debug", &do_debug_print, - "Enable debug messages"), - OPT_BOOLEAN('\0', "debug-single-step", &cfg.single_step, - "Enable single stepping"), - OPT_BOOLEAN('\0', "debug-ioport", &ioport_debug, - "Enable ioport debugging"), - OPT_BOOLEAN('\0', "debug-mmio", &mmio_debug, - "Enable MMIO debugging"), - OPT_INTEGER('\0', "debug-iodelay", &debug_iodelay, - "Delay IO by millisecond"), - OPT_END() -}; +#define BUILD_OPTIONS(name, cfg) \ + struct option name[] = { \ + OPT_GROUP("Basic options:"), \ + OPT_STRING('\0', "name", &(cfg)->guest_name, "guest name", \ + "A name for the guest"), \ + OPT_INTEGER('c', "cpus", &nrcpus, "Number of CPUs"), \ + OPT_U64('m', "mem", &(cfg)->ram_size, "Virtual machine memory size\ + in MiB."), \ + OPT_CALLBACK('\0', "shmem", NULL, \ + "[pci:]:[:handle=][:create]", \ + "Share host shmem with guest via pci device", \ + shmem_parser), \ + OPT_CALLBACK('d', "disk", NULL, "image or rootfs_dir", "Disk \ + image or rootfs directory", img_name_parser), \ + OPT_BOOLEAN('\0', "balloon", &(cfg)->balloon, "Enable virtio \ + balloon"), \ + OPT_BOOLEAN('\0', "vnc", &(cfg)->vnc, "Enable VNC framebuffer"),\ + OPT_BOOLEAN('\0', "sdl", &(cfg)->sdl, "Enable SDL framebuffer"),\ + OPT_BOOLEAN('\0', "rng", &(cfg)->virtio_rng, "Enable virtio Random\ + Number Generator"), \ + OPT_CALLBACK('\0', "9p", NULL, "dir_to_share,tag_name", \ + "Enable virtio 9p to share files between host and \ + guest", virtio_9p_rootdir_parser), \ + OPT_STRING('\0', "console", &(cfg)->console, "serial, virtio or \ + hv", "Console to use"), \ + OPT_STRING('\0', "dev", &(cfg)->dev, "device_file", \ + "KVM device file"), \ + OPT_CALLBACK('\0', "tty", NULL, "tty id", \ + "Remap guest TTY into a pty on the host", \ + tty_parser), \ + OPT_STRING('\0', "sandbox", &(cfg)->sandbox, "script", \ + "Run this script when booting into custom \ + rootfs"), \ + OPT_STRING('\0', "hugetlbfs", &(cfg)->hugetlbfs_path, "path", \ + "Hugetlbfs path"), \ + \ + OPT_GROUP("Kernel options:"), \ + OPT_STRING('k', "kernel", &(cfg)->kernel_filename, "kernel", \ + "Kernel to boot in virtual machine"), \ + OPT_STRING('i', "initrd", &(cfg)->initrd_filename, "initrd", \ + "Initial RAM disk image"), \ + OPT_STRING('p', "params", &(cfg)->kernel_cmdline, "params", \ + "Kernel command line arguments"), \ + OPT_STRING('f', "firmware", &(cfg)->firmware_filename, "firmware",\ + "Firmware image to boot in virtual machine"), \ + \ + OPT_GROUP("Networking options:"), \ + OPT_CALLBACK_DEFAULT('n', "network", NULL, "network params", \ + "Create a new guest NIC", \ + netdev_parser, NULL), \ + OPT_BOOLEAN('\0', "no-dhcp", &(cfg)->no_dhcp, "Disable kernel DHCP\ + in rootfs mode"), \ + \ + OPT_GROUP("BIOS options:"), \ + OPT_INTEGER('\0', "vidmode", &vidmode, \ + "Video mode"), \ + \ + OPT_GROUP("Debug options:"), \ + OPT_BOOLEAN('\0', "debug", &do_debug_print, \ + "Enable debug messages"), \ + OPT_BOOLEAN('\0', "debug-single-step", &(cfg)->single_step, \ + "Enable single stepping"), \ + OPT_BOOLEAN('\0', "debug-ioport", &ioport_debug, \ + "Enable ioport debugging"), \ + OPT_BOOLEAN('\0', "debug-mmio", &mmio_debug, \ + "Enable MMIO debugging"), \ + OPT_INTEGER('\0', "debug-iodelay", &debug_iodelay, \ + "Delay IO by millisecond"), \ + OPT_END() \ + }; /* * Serialize debug printout so that the output of multiple vcpus does not @@ -806,6 +816,7 @@ static const char *find_vmlinux(void) void kvm_run_help(void) { + BUILD_OPTIONS(options, &cfg); usage_with_options(run_usage, options); } @@ -947,6 +958,7 @@ static int kvm_cmd_run_init(int argc, const char **argv) unsigned int nr_online_cpus; int max_cpus, recommended_cpus; int i, r; + BUILD_OPTIONS(options, &cfg); signal(SIGALRM, handle_sigalrm); kvm_ipc__register_handler(KVM_IPC_DEBUG, handle_debug);