diff mbox

[3/3,V2] kvm tools: Add cmdline options for loading multiple images

Message ID 1304516717-24512-4-git-send-email-levinsasha928@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Sasha Levin May 4, 2011, 1:45 p.m. UTC
This is a simple cmdline addition to allow loading multiple images.
perf's cmdline parser doesn't support having multiple args
with the same name (i.e. --image <img1> --image <img2>), so
we have to choose either to extend the parser, or find a diiferent
way to assign multiple images.

Sample cmdline for loading 2 images:
./kvm run --image=image1.raw --readonly --image2=image2.raw --readonly2

NOTE NOTE NOTE - If testing, Please take notice of the
--readonly param changes so you won't destroy your image/disk.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
 tools/kvm/kvm-run.c |   36 ++++++++++++++++++++++++------------
 1 files changed, 24 insertions(+), 12 deletions(-)

Comments

David Ahern May 4, 2011, 2:51 p.m. UTC | #1
On 05/04/11 07:45, Sasha Levin wrote:
> This is a simple cmdline addition to allow loading multiple images.
> perf's cmdline parser doesn't support having multiple args
> with the same name (i.e. --image <img1> --image <img2>), so
> we have to choose either to extend the parser, or find a diiferent
> way to assign multiple images.
> 
> Sample cmdline for loading 2 images:
> ./kvm run --image=image1.raw --readonly --image2=image2.raw --readonly2

syntax is getting a bit unwieldy. Why not use a scheme similar to qemu
and concatenate related arguments into one and handle multiple usages?
e.g., --image=image1.raw,ro --image=image2.raw,ro

David


> 
> NOTE NOTE NOTE - If testing, Please take notice of the
> --readonly param changes so you won't destroy your image/disk.
> 
> Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
> ---
>  tools/kvm/kvm-run.c |   36 ++++++++++++++++++++++++------------
>  1 files changed, 24 insertions(+), 12 deletions(-)
> 
> diff --git a/tools/kvm/kvm-run.c b/tools/kvm/kvm-run.c
> index b92232d..5182735 100644
> --- a/tools/kvm/kvm-run.c
> +++ b/tools/kvm/kvm-run.c
> @@ -42,6 +42,7 @@
>  #define MB_SHIFT		(20)
>  #define MIN_RAM_SIZE_MB		(64ULL)
>  #define MIN_RAM_SIZE_BYTE	(MIN_RAM_SIZE_MB << MB_SHIFT)
> +#define MAX_DISK_IMAGES		4
>  
>  static struct kvm *kvm;
>  static struct kvm_cpu *kvm_cpus[KVM_NR_CPUS];
> @@ -51,7 +52,7 @@ static u64 ram_size = MIN_RAM_SIZE_MB;
>  static const char *kernel_cmdline;
>  static const char *kernel_filename;
>  static const char *initrd_filename;
> -static const char *image_filename;
> +static const char *image_filename[MAX_DISK_IMAGES];
>  static const char *console;
>  static const char *kvm_dev;
>  static const char *network;
> @@ -59,7 +60,7 @@ static const char *host_ip_addr;
>  static const char *guest_mac;
>  static const char *script;
>  static bool single_step;
> -static bool readonly_image;
> +static bool readonly_image[MAX_DISK_IMAGES];
>  static bool virtio_rng;
>  extern bool ioport_debug;
>  extern int  active_console;
> @@ -75,8 +76,17 @@ static const struct option options[] = {
>  	OPT_GROUP("Basic options:"),
>  	OPT_INTEGER('\0', "cpus", &nrcpus, "Number of CPUs"),
>  	OPT_U64('m', "mem", &ram_size, "Virtual machine memory size in MiB."),
> -	OPT_STRING('i', "image", &image_filename, "image", "Disk image"),
> -	OPT_BOOLEAN('\0', "readonly", &readonly_image,
> +	OPT_STRING('i', "image", &image_filename[0], "image", "Disk image"),
> +	OPT_BOOLEAN('\0', "readonly", &readonly_image[0],
> +			"Don't write changes back to disk image"),
> +	OPT_STRING('\0', "image2", &image_filename[1], "image", "Disk image"),
> +	OPT_BOOLEAN('\0', "readonly2", &readonly_image[1],
> +			"Don't write changes back to disk image"),
> +	OPT_STRING('\0', "image3", &image_filename[2], "image", "Disk image"),
> +	OPT_BOOLEAN('\0', "readonly3", &readonly_image[2],
> +			"Don't write changes back to disk image"),
> +	OPT_STRING('\0', "image4", &image_filename[3], "image", "Disk image"),
> +	OPT_BOOLEAN('\0', "readonly4", &readonly_image[3],
>  			"Don't write changes back to disk image"),
>  	OPT_STRING('c', "console", &console, "serial or virtio",
>  			"Console to use"),
> @@ -397,23 +407,25 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
>  		strlcat(real_cmdline, kernel_cmdline, sizeof(real_cmdline));
>  
>  	hi = NULL;
> -	if (!image_filename) {
> +	if (!image_filename[0]) {
>  		hi = host_image(real_cmdline, sizeof(real_cmdline));
>  		if (hi) {
> -			image_filename = hi;
> -			readonly_image = true;
> +			image_filename[0] = hi;
> +			readonly_image[0] = true;
>  		}
>  	}
>  
>  	if (!strstr(real_cmdline, "root="))
>  		strlcat(real_cmdline, " root=/dev/vda rw ", sizeof(real_cmdline));
>  
> -	if (image_filename) {
> -		struct disk_image *disk = disk_image__open(image_filename, readonly_image);
> -		if (!disk)
> -			die("unable to load disk image %s", image_filename);
> +	for (i = 0; i < MAX_DISK_IMAGES; i++) {
> +		if (image_filename[i]) {
> +			struct disk_image *disk = disk_image__open(image_filename[i], readonly_image[i]);
> +			if (!disk)
> +				die("unable to load disk image %s", image_filename[i]);
>  
> -		virtio_blk__init(kvm, disk);
> +			virtio_blk__init(kvm, disk);
> +		}
>  	}
>  	free(hi);
>  
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Sasha Levin May 4, 2011, 3:03 p.m. UTC | #2
On Wed, 2011-05-04 at 08:51 -0600, David Ahern wrote:
> 
> On 05/04/11 07:45, Sasha Levin wrote:
> > This is a simple cmdline addition to allow loading multiple images.
> > perf's cmdline parser doesn't support having multiple args
> > with the same name (i.e. --image <img1> --image <img2>), so
> > we have to choose either to extend the parser, or find a diiferent
> > way to assign multiple images.
> > 
> > Sample cmdline for loading 2 images:
> > ./kvm run --image=image1.raw --readonly --image2=image2.raw --readonly2
> 
> syntax is getting a bit unwieldy. Why not use a scheme similar to qemu
> and concatenate related arguments into one and handle multiple usages?
> e.g., --image=image1.raw,ro --image=image2.raw,ro

That'll probably how it'll end up being. Currently the cmdline parser
doesn't support it and I didn't want to mix parser changes with
virtio-blk patch.

This patch should just allow testing of the multiple virtio-blk feature.
David Ahern May 4, 2011, 3:33 p.m. UTC | #3
On 05/04/11 09:03, Sasha Levin wrote:
> On Wed, 2011-05-04 at 08:51 -0600, David Ahern wrote:
>>
>> On 05/04/11 07:45, Sasha Levin wrote:
>>> This is a simple cmdline addition to allow loading multiple images.
>>> perf's cmdline parser doesn't support having multiple args
>>> with the same name (i.e. --image <img1> --image <img2>), so
>>> we have to choose either to extend the parser, or find a diiferent
>>> way to assign multiple images.
>>>
>>> Sample cmdline for loading 2 images:
>>> ./kvm run --image=image1.raw --readonly --image2=image2.raw --readonly2
>>
>> syntax is getting a bit unwieldy. Why not use a scheme similar to qemu
>> and concatenate related arguments into one and handle multiple usages?
>> e.g., --image=image1.raw,ro --image=image2.raw,ro
> 
> That'll probably how it'll end up being. Currently the cmdline parser
> doesn't support it and I didn't want to mix parser changes with
> virtio-blk patch.

It's using the option parser from perf, so you need to change:

OPT_STRING('i', "image", &image_filename, "image", "Disk image"),

to OPT_CALLBACK and create a parser function specific to this input
argument. For example, checkout tools/perf/builtin-script.c,
parse_output_fields.

The parser is specific to the image argument and hence should be a part
of this change set.

David


> 
> This patch should just allow testing of the multiple virtio-blk feature.
> 
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Sasha Levin May 4, 2011, 7:38 p.m. UTC | #4
On Wed, 2011-05-04 at 09:33 -0600, David Ahern wrote:
> On 05/04/11 09:03, Sasha Levin wrote:
> > On Wed, 2011-05-04 at 08:51 -0600, David Ahern wrote:
> >>
> >> On 05/04/11 07:45, Sasha Levin wrote:
> >>> This is a simple cmdline addition to allow loading multiple images.
> >>> perf's cmdline parser doesn't support having multiple args
> >>> with the same name (i.e. --image <img1> --image <img2>), so
> >>> we have to choose either to extend the parser, or find a diiferent
> >>> way to assign multiple images.
> >>>
> >>> Sample cmdline for loading 2 images:
> >>> ./kvm run --image=image1.raw --readonly --image2=image2.raw --readonly2
> >>
> >> syntax is getting a bit unwieldy. Why not use a scheme similar to qemu
> >> and concatenate related arguments into one and handle multiple usages?
> >> e.g., --image=image1.raw,ro --image=image2.raw,ro
> > 
> > That'll probably how it'll end up being. Currently the cmdline parser
> > doesn't support it and I didn't want to mix parser changes with
> > virtio-blk patch.
> 
> It's using the option parser from perf, so you need to change:
> 
> OPT_STRING('i', "image", &image_filename, "image", "Disk image"),
> 
> to OPT_CALLBACK and create a parser function specific to this input
> argument. For example, checkout tools/perf/builtin-script.c,
> parse_output_fields.
> 
> The parser is specific to the image argument and hence should be a part
> of this change set.
> 
> David

Thanks!
diff mbox

Patch

diff --git a/tools/kvm/kvm-run.c b/tools/kvm/kvm-run.c
index b92232d..5182735 100644
--- a/tools/kvm/kvm-run.c
+++ b/tools/kvm/kvm-run.c
@@ -42,6 +42,7 @@ 
 #define MB_SHIFT		(20)
 #define MIN_RAM_SIZE_MB		(64ULL)
 #define MIN_RAM_SIZE_BYTE	(MIN_RAM_SIZE_MB << MB_SHIFT)
+#define MAX_DISK_IMAGES		4
 
 static struct kvm *kvm;
 static struct kvm_cpu *kvm_cpus[KVM_NR_CPUS];
@@ -51,7 +52,7 @@  static u64 ram_size = MIN_RAM_SIZE_MB;
 static const char *kernel_cmdline;
 static const char *kernel_filename;
 static const char *initrd_filename;
-static const char *image_filename;
+static const char *image_filename[MAX_DISK_IMAGES];
 static const char *console;
 static const char *kvm_dev;
 static const char *network;
@@ -59,7 +60,7 @@  static const char *host_ip_addr;
 static const char *guest_mac;
 static const char *script;
 static bool single_step;
-static bool readonly_image;
+static bool readonly_image[MAX_DISK_IMAGES];
 static bool virtio_rng;
 extern bool ioport_debug;
 extern int  active_console;
@@ -75,8 +76,17 @@  static const struct option options[] = {
 	OPT_GROUP("Basic options:"),
 	OPT_INTEGER('\0', "cpus", &nrcpus, "Number of CPUs"),
 	OPT_U64('m', "mem", &ram_size, "Virtual machine memory size in MiB."),
-	OPT_STRING('i', "image", &image_filename, "image", "Disk image"),
-	OPT_BOOLEAN('\0', "readonly", &readonly_image,
+	OPT_STRING('i', "image", &image_filename[0], "image", "Disk image"),
+	OPT_BOOLEAN('\0', "readonly", &readonly_image[0],
+			"Don't write changes back to disk image"),
+	OPT_STRING('\0', "image2", &image_filename[1], "image", "Disk image"),
+	OPT_BOOLEAN('\0', "readonly2", &readonly_image[1],
+			"Don't write changes back to disk image"),
+	OPT_STRING('\0', "image3", &image_filename[2], "image", "Disk image"),
+	OPT_BOOLEAN('\0', "readonly3", &readonly_image[2],
+			"Don't write changes back to disk image"),
+	OPT_STRING('\0', "image4", &image_filename[3], "image", "Disk image"),
+	OPT_BOOLEAN('\0', "readonly4", &readonly_image[3],
 			"Don't write changes back to disk image"),
 	OPT_STRING('c', "console", &console, "serial or virtio",
 			"Console to use"),
@@ -397,23 +407,25 @@  int kvm_cmd_run(int argc, const char **argv, const char *prefix)
 		strlcat(real_cmdline, kernel_cmdline, sizeof(real_cmdline));
 
 	hi = NULL;
-	if (!image_filename) {
+	if (!image_filename[0]) {
 		hi = host_image(real_cmdline, sizeof(real_cmdline));
 		if (hi) {
-			image_filename = hi;
-			readonly_image = true;
+			image_filename[0] = hi;
+			readonly_image[0] = true;
 		}
 	}
 
 	if (!strstr(real_cmdline, "root="))
 		strlcat(real_cmdline, " root=/dev/vda rw ", sizeof(real_cmdline));
 
-	if (image_filename) {
-		struct disk_image *disk = disk_image__open(image_filename, readonly_image);
-		if (!disk)
-			die("unable to load disk image %s", image_filename);
+	for (i = 0; i < MAX_DISK_IMAGES; i++) {
+		if (image_filename[i]) {
+			struct disk_image *disk = disk_image__open(image_filename[i], readonly_image[i]);
+			if (!disk)
+				die("unable to load disk image %s", image_filename[i]);
 
-		virtio_blk__init(kvm, disk);
+			virtio_blk__init(kvm, disk);
+		}
 	}
 	free(hi);