- Subject: [tip:tools/kvm] kvm tools: Introduce struct disk_image_params
- From: tip-bot for Asias He <asias.hejun@xxxxxxxxx>
- Date: Wed, 18 Jul 2012 00:25:46 -0700
- Cc: hpa@xxxxxxxxx, mingo@xxxxxxxxxx, penberg@xxxxxxxxxx, tglx@xxxxxxxxxxxxx, asias.hejun@xxxxxxxxx
- Git-commit-id: d04dddfb6b4397939bbfe7b80e16d0d253324ce1
- Reply-to: linux-kernel@xxxxxxxxxxxxxxx, mingo@xxxxxxxxxx, hpa@xxxxxxxxx, penberg@xxxxxxxxxx, tglx@xxxxxxxxxxxxx, asias.hejun@xxxxxxxxx
- Robot-id: <tip-bot.git.kernel.org>
- Robot-unsubscribe: Contact <mailto:hpa@xxxxxxxxxx> to get blacklisted from these emails
Commit-ID: d04dddfb6b4397939bbfe7b80e16d0d253324ce1
Gitweb: http://git.kernel.org/tip/d04dddfb6b4397939bbfe7b80e16d0d253324ce1
Author: Asias He <asias.hejun@xxxxxxxxx>
AuthorDate: Thu, 12 Jul 2012 01:16:50 +0800
Committer: Pekka Enberg <penberg@xxxxxxxxxx>
CommitDate: Thu, 12 Jul 2012 10:09:36 +0300
kvm tools: Introduce struct disk_image_params
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@xxxxxxxxx>
Signed-off-by: Pekka Enberg <penberg@xxxxxxxxxx>
---
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);
--
To unsubscribe from this list: send the line "unsubscribe linux-tip-commits" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
[Linux USB Devel]
[Linux Video &Media]
[Video for Linux]
[Linux Audio Users]
[Photo]
[Yosemite News]
[Yosemite Photos]
[Free Online Dating]
[Linux Kernel]
[Linux SCSI]
[XFree86]