]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: Introduce struct disk_image_params
authorAsias He <asias.hejun@gmail.com>
Wed, 11 Jul 2012 17:16:50 +0000 (01:16 +0800)
committerPekka Enberg <penberg@kernel.org>
Thu, 12 Jul 2012 07:09:36 +0000 (10:09 +0300)
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.hejun@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/builtin-run.c
tools/kvm/disk/core.c
tools/kvm/include/kvm/disk-image.h

index 4f6ea15fba1f019c049a9272818f8e232de886dd..a120fe27ab3b0aaeb84e905c81cf15df5b33d294 100644 (file)
@@ -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",
index 2739dcdb6f8aac65e35e3adc260d3646d65e793a..5542d42919679985285666846d23124360db8ba2 100644 (file)
@@ -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;
                }
index 9671438268cba9d39ea7778469d0d72d131d51c6..5d098757bd9897677725ce55b7f75443ddf7f057 100644 (file)
@@ -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);