From patchwork Wed Jul 11 17:16:50 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Asias He X-Patchwork-Id: 1184511 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 88673DF25A for ; Wed, 11 Jul 2012 17:16:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751508Ab2GKRQ1 (ORCPT ); Wed, 11 Jul 2012 13:16:27 -0400 Received: from mail-gh0-f174.google.com ([209.85.160.174]:64842 "EHLO mail-gh0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750962Ab2GKRQ0 (ORCPT ); Wed, 11 Jul 2012 13:16:26 -0400 Received: by ghrr11 with SMTP id r11so1460934ghr.19 for ; Wed, 11 Jul 2012 10:16:26 -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; bh=jVMUVJTE1xMhTB47BYzZBtOAj9XGF25MbWT8bPV7rW8=; b=sHI6BXnrzv3MjqElRuQHa1pZ7QSAq9YoiHpYRnqBhEOxXxuVZp9AtKDhSB7kg7QN0K Lma8FfNyt2DhghS6NUr/k6MSUgJRIlty3fzQpczRc/RXK3ObkU2kxDyN6uv9trMd4Wmg AblwQHLiJhpBRYMmCXlqSimdV90v8IWFLucC2f8B0nFGV7rpSE1HbIcbM7DseoKKebQI 46PpJn4AN6ucweNzFlehUS2Yb+edjPYS8XIcfi2s89pJwYJhjO4zMBzoGBCit0KFYDB/ O/mjFM8/k5bQ2PqVvlbmqGcE+5ZiQCf6fXlwbitqwJ1NuYK443cKUfdg7B8lDI5y9rma 1HHw== Received: by 10.66.85.36 with SMTP id e4mr83268195paz.32.1342026985561; Wed, 11 Jul 2012 10:16:25 -0700 (PDT) Received: from localhost.localdomain ([58.194.229.69]) by mx.google.com with ESMTPS id tq4sm2059988pbc.11.2012.07.11.10.16.22 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 11 Jul 2012 10:16:25 -0700 (PDT) From: Asias He To: Pekka Enberg Cc: Sasha Levin , Ingo Molnar , Cyrill Gorcunov , kvm@vger.kernel.org, Asias He Subject: [PATCH 1/1] kvm tools: Introduce struct disk_image_params Date: Thu, 12 Jul 2012 01:16:50 +0800 Message-Id: <1342027010-5601-1-git-send-email-asias.hejun@gmail.com> X-Mailer: git-send-email 1.7.10.4 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Introduce struct disk_image_params to contain all the disk image parameters. This is useful for adding more disk image parameters, e.g. disk image cache mode. Signed-off-by: Asias He --- tools/kvm/builtin-run.c | 11 +++++------ tools/kvm/disk/core.c | 15 +++++++++------ tools/kvm/include/kvm/disk-image.h | 7 ++++++- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c index 4f6ea15..a120fe2 100644 --- a/tools/kvm/builtin-run.c +++ b/tools/kvm/builtin-run.c @@ -68,6 +68,7 @@ struct kvm *kvm; struct kvm_cpu **kvm_cpus; __thread struct kvm_cpu *current_kvm_cpu; +static struct disk_image_params disk_image[MAX_DISK_IMAGES]; static u64 ram_size; static u8 image_count; static u8 num_net_devices; @@ -77,7 +78,6 @@ static const char *kernel_filename; static const char *vmlinux_filename; static const char *initrd_filename; static const char *firmware_filename; -static const char *image_filename[MAX_DISK_IMAGES]; static const char *console; static const char *dev; static const char *network; @@ -92,7 +92,6 @@ static const char *hugetlbfs_path; static const char *custom_rootfs_name = "default"; static struct virtio_net_params *net_params; static bool single_step; -static bool readonly_image[MAX_DISK_IMAGES]; static bool vnc; static bool sdl; static bool balloon; @@ -169,11 +168,11 @@ static int img_name_parser(const struct option *opt, const char *arg, int unset) if (image_count >= MAX_DISK_IMAGES) die("Currently only 4 images are supported"); - image_filename[image_count] = arg; + disk_image[image_count].filename = arg; sep = strstr(arg, ","); if (sep) { if (strcmp(sep + 1, "ro") == 0) - readonly_image[image_count] = 1; + disk_image[image_count].readonly = true; *sep = 0; } @@ -1099,7 +1098,7 @@ static int kvm_cmd_run_init(int argc, const char **argv) if (kernel_cmdline) strlcat(real_cmdline, kernel_cmdline, sizeof(real_cmdline)); - if (!using_rootfs && !image_filename[0] && !initrd_filename) { + if (!using_rootfs && !disk_image[0].filename && !initrd_filename) { char tmp[PATH_MAX]; kvm_setup_create_new(custom_rootfs_name); @@ -1131,7 +1130,7 @@ static int kvm_cmd_run_init(int argc, const char **argv) if (image_count) { kvm->nr_disks = image_count; - kvm->disks = disk_image__open_all(image_filename, readonly_image, image_count); + kvm->disks = disk_image__open_all((struct disk_image_params *)&disk_image, image_count); if (IS_ERR(kvm->disks)) { r = PTR_ERR(kvm->disks); pr_err("disk_image__open_all() failed with error %ld\n", diff --git a/tools/kvm/disk/core.c b/tools/kvm/disk/core.c index 2739dcd..5542d42 100644 --- a/tools/kvm/disk/core.c +++ b/tools/kvm/disk/core.c @@ -111,12 +111,13 @@ struct disk_image *disk_image__open(const char *filename, bool readonly) return ERR_PTR(-ENOSYS); } -struct disk_image **disk_image__open_all(const char **filenames, - bool *readonly, int count) +struct disk_image **disk_image__open_all(struct disk_image_params *params, int count) { struct disk_image **disks; - int i; + const char *filename; + bool readonly; void *err; + int i; if (!count) return ERR_PTR(-EINVAL); @@ -128,12 +129,14 @@ struct disk_image **disk_image__open_all(const char **filenames, return ERR_PTR(-ENOMEM); for (i = 0; i < count; i++) { - if (!filenames[i]) + filename = params[i].filename; + readonly = params[i].readonly; + if (!filename) continue; - disks[i] = disk_image__open(filenames[i], readonly[i]); + disks[i] = disk_image__open(filename, readonly); if (IS_ERR_OR_NULL(disks[i])) { - pr_err("Loading disk image '%s' failed", filenames[i]); + pr_err("Loading disk image '%s' failed", filename); err = disks[i]; goto error; } diff --git a/tools/kvm/include/kvm/disk-image.h b/tools/kvm/include/kvm/disk-image.h index 9671438..5d09875 100644 --- a/tools/kvm/include/kvm/disk-image.h +++ b/tools/kvm/include/kvm/disk-image.h @@ -39,6 +39,11 @@ struct disk_image_operations { int (*close)(struct disk_image *disk); }; +struct disk_image_params { + const char *filename; + bool readonly; +}; + struct disk_image { int fd; u64 size; @@ -54,7 +59,7 @@ struct disk_image { }; struct disk_image *disk_image__open(const char *filename, bool readonly); -struct disk_image **disk_image__open_all(const char **filenames, bool *readonly, int count); +struct disk_image **disk_image__open_all(struct disk_image_params *params, int count); 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);