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 <asias.he...@gmail.com>
---
 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);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to