From patchwork Wed Sep 5 08:31:44 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 1406511 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 4E37940220 for ; Wed, 5 Sep 2012 08:32:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758035Ab2IEIcr (ORCPT ); Wed, 5 Sep 2012 04:32:47 -0400 Received: from mail-wg0-f44.google.com ([74.125.82.44]:56730 "EHLO mail-wg0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751494Ab2IEIcp (ORCPT ); Wed, 5 Sep 2012 04:32:45 -0400 Received: by wgbdr13 with SMTP id dr13so389214wgb.1 for ; Wed, 05 Sep 2012 01:32:44 -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=kN1z26WGxg5eG6h6e4DF9kKEytTA4e6UzM6OF7RasZU=; b=EafaeWEzxzh8bjfH5B4nrTGo1JA5gEDJCz5XUkUymxJ68yEeav/qFc5+aLtQl77rKu 890CqEZJJ6s+aBeUKIa3BpuHUfoeQWbgLVq6kJbEKLHrZgNrIirW3W1y6EUNnsITTYum qoKdCMWVxHGMtFn6YAeVwONkuapLF8fIhI9Toh+o1oR0J91SLo9WnKKem+SiYdc0zimr dYkSt4ZZdmPIYD+Q2mq3X09IJTs6U7Jwi9W4bjfqb8ANYBjmQGb9vFWjAQ5CB8lcbAAl abh8fXCWOSvXe4Bpq0XdZKcENS5bYxCwHhTxRvTSoW8rLMhkad+hZri9+/BIH+pxSmNP ZVRg== Received: by 10.180.106.130 with SMTP id gu2mr309941wib.20.1346833963755; Wed, 05 Sep 2012 01:32:43 -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.32.12 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 05 Sep 2012 01:32:42 -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 10/33] kvm tools: disk image related cleanup Date: Wed, 5 Sep 2012 10:31:44 +0200 Message-Id: <1346833927-15740-11-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 Move io debug delay into kvm_config, the parser out of builtin-run into the disk code and make the init/exit functions match the rest of the code in style. Signed-off-by: Sasha Levin --- tools/kvm/builtin-run.c | 75 ++++++++++---------------------------- tools/kvm/disk/core.c | 71 ++++++++++++++++++++++++++++++++++-- tools/kvm/include/kvm/disk-image.h | 9 +++-- tools/kvm/include/kvm/kvm-config.h | 1 + 4 files changed, 92 insertions(+), 64 deletions(-) diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c index 52e0190..cb48ead 100644 --- a/tools/kvm/builtin-run.c +++ b/tools/kvm/builtin-run.c @@ -58,7 +58,6 @@ struct kvm_cpu **kvm_cpus; __thread struct kvm_cpu *current_kvm_cpu; static int kvm_run_wrapper; -extern int debug_iodelay; bool do_debug_print = false; @@ -78,17 +77,11 @@ enum { KVM_RUN_SANDBOX, }; -void kvm_run_set_wrapper_sandbox(void) -{ - kvm_run_wrapper = KVM_RUN_SANDBOX; -} - static int img_name_parser(const struct option *opt, const char *arg, int unset) { char path[PATH_MAX]; - const char *cur; struct stat st; - char *sep; + struct kvm *kvm = opt->ptr; if (stat(arg, &st) == 0 && S_ISDIR(st.st_mode)) { @@ -124,39 +117,12 @@ static int img_name_parser(const struct option *opt, const char *arg, int unset) return 0; } - if (kvm->cfg.image_count >= MAX_DISK_IMAGES) - die("Currently only 4 images are supported"); - - kvm->cfg.disk_image[kvm->cfg.image_count].filename = arg; - cur = arg; - - if (strncmp(arg, "scsi:", 5) == 0) { - sep = strstr(arg, ":"); - if (sep) - kvm->cfg.disk_image[kvm->cfg.image_count].wwpn = sep + 1; - sep = strstr(sep + 1, ":"); - if (sep) { - *sep = 0; - kvm->cfg.disk_image[kvm->cfg.image_count].tpgt = sep + 1; - } - cur = sep + 1; - } - - do { - sep = strstr(cur, ","); - if (sep) { - if (strncmp(sep + 1, "ro", 2) == 0) - kvm->cfg.disk_image[kvm->cfg.image_count].readonly = true; - else if (strncmp(sep + 1, "direct", 6) == 0) - kvm->cfg.disk_image[kvm->cfg.image_count].direct = true; - *sep = 0; - cur = sep + 1; - } - } while (sep); - - kvm->cfg.image_count++; + return disk_img_name_parser(opt, arg, unset); +} - return 0; +void kvm_run_set_wrapper_sandbox(void) +{ + kvm_run_wrapper = KVM_RUN_SANDBOX; } static int virtio_9p_rootdir_parser(const struct option *opt, const char *arg, int unset) @@ -406,7 +372,7 @@ static int shmem_parser(const struct option *opt, const char *arg, int unset) return 0; } -#define BUILD_OPTIONS(name, cfg) \ +#define BUILD_OPTIONS(name, cfg, kvm) \ struct option name[] = { \ OPT_GROUP("Basic options:"), \ OPT_STRING('\0', "name", &(cfg)->guest_name, "guest name", \ @@ -420,7 +386,7 @@ static int shmem_parser(const struct option *opt, const char *arg, int unset) shmem_parser, NULL), \ OPT_CALLBACK('d', "disk", kvm, "image or rootfs_dir", "Disk \ image or rootfs directory", img_name_parser, \ - NULL), \ + kvm), \ OPT_BOOLEAN('\0', "balloon", &(cfg)->balloon, "Enable virtio \ balloon"), \ OPT_BOOLEAN('\0', "vnc", &(cfg)->vnc, "Enable VNC framebuffer"),\ @@ -473,7 +439,7 @@ static int shmem_parser(const struct option *opt, const char *arg, int unset) "Enable ioport debugging"), \ OPT_BOOLEAN('\0', "debug-mmio", &(cfg)->mmio_debug, \ "Enable MMIO debugging"), \ - OPT_INTEGER('\0', "debug-iodelay", &debug_iodelay, \ + OPT_INTEGER('\0', "debug-iodelay", &(cfg)->debug_iodelay, \ "Delay IO by millisecond"), \ OPT_END() \ }; @@ -768,7 +734,7 @@ static const char *find_vmlinux(void) void kvm_run_help(void) { - BUILD_OPTIONS(options, &kvm->cfg); + BUILD_OPTIONS(options, &kvm->cfg, kvm); usage_with_options(run_usage, options); } @@ -927,7 +893,7 @@ static int kvm_cmd_run_init(int argc, const char **argv) kvm->cfg.custom_rootfs_name = "default"; while (argc != 0) { - BUILD_OPTIONS(options, &kvm->cfg); + BUILD_OPTIONS(options, &kvm->cfg, kvm); argc = parse_options(argc, argv, options, run_usage, PARSE_OPT_STOP_AT_NON_OPTION | PARSE_OPT_KEEP_DASHDASH); @@ -969,6 +935,8 @@ static int kvm_cmd_run_init(int argc, const char **argv) } + kvm->nr_disks = kvm->cfg.image_count; + if (!kvm->cfg.kernel_filename) kvm->cfg.kernel_filename = find_kernel(); @@ -1130,15 +1098,10 @@ static int kvm_cmd_run_init(int argc, const char **argv) strlcat(real_cmdline, " root=/dev/vda rw ", sizeof(real_cmdline)); } - if (kvm->cfg.image_count) { - kvm->nr_disks = kvm->cfg.image_count; - kvm->disks = disk_image__open_all((struct disk_image_params *)&kvm->cfg.disk_image, kvm->cfg.image_count); - if (IS_ERR(kvm->disks)) { - r = PTR_ERR(kvm->disks); - pr_err("disk_image__open_all() failed with error %ld\n", - PTR_ERR(kvm->disks)); - goto fail; - } + r = disk_image__init(kvm); + if (r < 0) { + pr_err("disk_image__init() failed with error %d\n", r); + goto fail; } printf(" # %s run -k %s -m %Lu -c %d --name %s\n", KVM_BINARY_NAME, @@ -1342,9 +1305,9 @@ static void kvm_cmd_run_exit(int guest_ret) if (r < 0) pr_warning("virtio_rng__exit() failed with error %d\n", r); - r = disk_image__close_all(kvm->disks, kvm->cfg.image_count); + r = disk_image__exit(kvm); if (r < 0) - pr_warning("disk_image__close_all() failed with error %d\n", r); + pr_warning("disk_image__exit() failed with error %d\n", r); r = serial8250__exit(kvm); if (r < 0) diff --git a/tools/kvm/disk/core.c b/tools/kvm/disk/core.c index f7e2c7f..639b7b3 100644 --- a/tools/kvm/disk/core.c +++ b/tools/kvm/disk/core.c @@ -1,6 +1,7 @@ #include "kvm/disk-image.h" #include "kvm/qcow.h" #include "kvm/virtio-blk.h" +#include "kvm/kvm.h" #include #include @@ -10,6 +11,49 @@ int debug_iodelay; +static int disk_image__close(struct disk_image *disk); + +int disk_img_name_parser(const struct option *opt, const char *arg, int unset) +{ + const char *cur; + char *sep; + struct kvm *kvm = opt->ptr; + + if (kvm->cfg.image_count >= MAX_DISK_IMAGES) + die("Currently only 4 images are supported"); + + kvm->cfg.disk_image[kvm->cfg.image_count].filename = arg; + cur = arg; + + if (strncmp(arg, "scsi:", 5) == 0) { + sep = strstr(arg, ":"); + if (sep) + kvm->cfg.disk_image[kvm->cfg.image_count].wwpn = sep + 1; + sep = strstr(sep + 1, ":"); + if (sep) { + *sep = 0; + kvm->cfg.disk_image[kvm->cfg.image_count].tpgt = sep + 1; + } + cur = sep + 1; + } + + do { + sep = strstr(cur, ","); + if (sep) { + if (strncmp(sep + 1, "ro", 2) == 0) + kvm->cfg.disk_image[kvm->cfg.image_count].readonly = true; + else if (strncmp(sep + 1, "direct", 6) == 0) + kvm->cfg.disk_image[kvm->cfg.image_count].direct = true; + *sep = 0; + cur = sep + 1; + } + } while (sep); + + kvm->cfg.image_count++; + + return 0; +} + #ifdef CONFIG_HAS_AIO static void *disk_image__thread(void *param) { @@ -75,7 +119,7 @@ struct disk_image *disk_image__new(int fd, u64 size, return disk; } -struct disk_image *disk_image__open(const char *filename, bool readonly, bool direct) +static struct disk_image *disk_image__open(const char *filename, bool readonly, bool direct) { struct disk_image *disk; struct stat st; @@ -118,7 +162,7 @@ struct disk_image *disk_image__open(const char *filename, bool readonly, bool di return ERR_PTR(-ENOSYS); } -struct disk_image **disk_image__open_all(struct disk_image_params *params, int count) +static struct disk_image **disk_image__open_all(struct kvm *kvm) { struct disk_image **disks; const char *filename; @@ -128,6 +172,8 @@ struct disk_image **disk_image__open_all(struct disk_image_params *params, int c bool direct; void *err; int i; + struct disk_image_params *params = (struct disk_image_params *)&kvm->cfg.disk_image; + int count = kvm->cfg.image_count; if (!count) return ERR_PTR(-EINVAL); @@ -163,6 +209,7 @@ struct disk_image **disk_image__open_all(struct disk_image_params *params, int c err = disks[i]; goto error; } + disks[i]->debug_iodelay = kvm->cfg.debug_iodelay; } return disks; @@ -183,7 +230,7 @@ int disk_image__flush(struct disk_image *disk) return fsync(disk->fd); } -int disk_image__close(struct disk_image *disk) +static int disk_image__close(struct disk_image *disk) { /* If there was no disk image then there's nothing to do: */ if (!disk) @@ -200,7 +247,7 @@ int disk_image__close(struct disk_image *disk) return 0; } -int disk_image__close_all(struct disk_image **disks, int count) +static int disk_image__close_all(struct disk_image **disks, int count) { while (count) disk_image__close(disks[--count]); @@ -287,3 +334,19 @@ void disk_image__set_callback(struct disk_image *disk, { disk->disk_req_cb = disk_req_cb; } + +int disk_image__init(struct kvm *kvm) +{ + if (kvm->cfg.image_count) { + kvm->disks = disk_image__open_all(kvm); + if (IS_ERR(kvm->disks)) + return PTR_ERR(kvm->disks); + } + + return 0; +} + +int disk_image__exit(struct kvm *kvm) +{ + return disk_image__close_all(kvm->disks, kvm->nr_disks); +} diff --git a/tools/kvm/include/kvm/disk-image.h b/tools/kvm/include/kvm/disk-image.h index 83fc725..b728052 100644 --- a/tools/kvm/include/kvm/disk-image.h +++ b/tools/kvm/include/kvm/disk-image.h @@ -3,6 +3,7 @@ #include "kvm/read-write.h" #include "kvm/util.h" +#include "kvm/parse-options.h" #include #include /* for BLKGETSIZE64 */ @@ -65,13 +66,13 @@ struct disk_image { #endif const char *wwpn; const char *tpgt; + int debug_iodelay; }; -struct disk_image *disk_image__open(const char *filename, bool readonly, bool direct); -struct disk_image **disk_image__open_all(struct disk_image_params *params, int count); +int disk_img_name_parser(const struct option *opt, const char *arg, int unset); +int disk_image__init(struct kvm *kvm); +int disk_image__exit(struct kvm *kvm); struct disk_image *disk_image__new(int fd, u64 size, struct disk_image_operations *ops, int mmap); -int disk_image__close(struct disk_image *disk); -int disk_image__close_all(struct disk_image **disks, int count); int disk_image__flush(struct disk_image *disk); ssize_t disk_image__read(struct disk_image *disk, u64 sector, const struct iovec *iov, int iovcount, void *param); diff --git a/tools/kvm/include/kvm/kvm-config.h b/tools/kvm/include/kvm/kvm-config.h index fd7a5cd..35cde48 100644 --- a/tools/kvm/include/kvm/kvm-config.h +++ b/tools/kvm/include/kvm/kvm-config.h @@ -23,6 +23,7 @@ struct kvm_config { u8 num_net_devices; bool virtio_rng; int active_console; + int debug_iodelay; const char *kernel_cmdline; const char *kernel_filename; const char *vmlinux_filename;