Skip to contentSkip to conversation

kvm tools: Support for multiple virtio-blk

PATCH Superseded Sasha Levin 6 participants 13 messages May 4, 2011 KVM

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover kvm tools: Support for multiple virtio-blk

Following patches add support for multiple virtio-blk devices. Sample cmdline for testing:
./kvm run --image <img1.raw> --readonly --image2 <img2.raw> --readonly2

Changes in V2:
- Multiple device support is now fully working.
- Fixed code styling and formatting.
- Each virtio-blk gets it's own IRQ line, updated mptable.c.
- New issue: How do we pass multiple disk params? Currently the parser we took from perf doesn't support multiple arguments.

#1 lore raw

PATCH v2 1/3 kvm tools: Move disk_image into virtio-blk

There may be multiple disk images on a running guest, each associated with a virtio-blk.

Move disk_image into virtio-blk in preperation for multiple disk images.

---
 tools/kvm/include/kvm/kvm.h        |    1 -
 tools/kvm/include/kvm/virtio-blk.h |    4 +++-
 tools/kvm/kvm-run.c                |    9 ++++-----
 tools/kvm/virtio-blk.c             |   13 ++++++++-----
 4 files changed, 15 insertions(+), 12 deletions(-)
tools/kvm/include/kvm/kvm.h +0 -1
index 327a1ab..d239f49 100644
@@ -16,7 +16,6 @@ struct kvm {
 
 	int			nrcpus;		/* Number of cpus to run */
 
-	struct disk_image	*disk_image;
 	uint64_t		ram_size;
 	void			*ram_start;
 
tools/kvm/include/kvm/virtio-blk.h +3 -1
index f82bbc7..f21a0e4 100644
@@ -1,8 +1,10 @@
 #ifndef KVM__BLK_VIRTIO_H
 #define KVM__BLK_VIRTIO_H
 
+#include "kvm/disk-image.h"
+
 struct kvm;
 
-void virtio_blk__init(struct kvm *self);
+void virtio_blk__init(struct kvm *self, struct disk_image *disk);
 
 #endif /* KVM__BLK_VIRTIO_H */
tools/kvm/kvm-run.c +4 -5
index 6fd46ed..b92232d 100644
@@ -409,9 +409,11 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
 		strlcat(real_cmdline, " root=/dev/vda rw ", sizeof(real_cmdline));
 
 	if (image_filename) {
-		kvm->disk_image	= disk_image__open(image_filename, readonly_image);
-		if (!kvm->disk_image)
+		struct disk_image *disk = disk_image__open(image_filename, readonly_image);
+		if (!disk)
 			die("unable to load disk image %s", image_filename);
+
+		virtio_blk__init(kvm, disk);
 	}
 	free(hi);
 
@@ -429,8 +431,6 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
 
 	pci__init();
 
-	virtio_blk__init(kvm);
-
 	virtio_console__init(kvm);
 
 	if (virtio_rng)
@@ -487,7 +487,6 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
 			exit_code	= 1;
 	}
 
-	disk_image__close(kvm->disk_image);
 	kvm__delete(kvm);
 
 	if (!exit_code)
tools/kvm/virtio-blk.c +8 -5
index 9034abd..d7bda5f 100644
@@ -28,6 +28,7 @@ struct blk_device {
 	pthread_mutex_t			mutex;
 
 	struct virtio_blk_config	blk_config;
+	struct disk_image			*disk;
 	uint32_t			host_features;
 	uint32_t			guest_features;
 	uint16_t			config_vector;
@@ -130,11 +131,11 @@ static bool virtio_blk_do_io_request(struct kvm *self, struct virt_queue *queue)
 
 	switch (req->type) {
 	case VIRTIO_BLK_T_IN:
-		block_cnt = disk_image__read_sector_iov(self->disk_image, req->sector, iov + 1, in + out - 2);
+		block_cnt = disk_image__read_sector_iov(blk_device.disk, req->sector, iov + 1, in + out - 2);
 
 		break;
 	case VIRTIO_BLK_T_OUT:
-		block_cnt = disk_image__write_sector_iov(self->disk_image, req->sector, iov + 1, in + out - 2);
+		block_cnt = disk_image__write_sector_iov(blk_device.disk, req->sector, iov + 1, in + out - 2);
 
 		break;
 
@@ -243,12 +244,14 @@ static struct pci_device_header virtio_blk_pci_device = {
 
 #define PCI_VIRTIO_BLK_DEVNUM 1
 
-void virtio_blk__init(struct kvm *self)
+void virtio_blk__init(struct kvm *self, struct disk_image *disk)
 {
-	if (!self->disk_image)
+	if (!disk)
 		return;
 
-	blk_device.blk_config.capacity = self->disk_image->size / SECTOR_SIZE;
+	blk_device.disk = disk;
+
+	blk_device.blk_config.capacity = disk->size / SECTOR_SIZE;
 
 	pci__register(&virtio_blk_pci_device, PCI_VIRTIO_BLK_DEVNUM);
 
Signature · 1 line
1.7.5.rc3
#2 lore raw

PATCH v2 2/3 kvm tools: Add support for multiple virtio-blk

In reply to Sasha Levin

Add support for multiple blk_devices by un-globalizing the current blk_device and allow multiple blk_devices.

---
 tools/kvm/include/kvm/ioport.h |    2 +-
 tools/kvm/mptable.c            |   39 ++++++++-
 tools/kvm/virtio-blk.c         |  193 +++++++++++++++++++++++++---------------
 3 files changed, 162 insertions(+), 72 deletions(-)
tools/kvm/include/kvm/ioport.h +1 -1
index 6020124..98a880f 100644
@@ -7,7 +7,7 @@
 /* some ports we reserve for own use */
 #define IOPORT_DBG			0xe0
 #define IOPORT_VIRTIO_BLK		0xc200	/* Virtio block device */
-#define IOPORT_VIRTIO_BLK_SIZE		256
+#define IOPORT_VIRTIO_BLK_SIZE		0x200
 #define IOPORT_VIRTIO_CONSOLE		0xd200	/* Virtio console device */
 #define IOPORT_VIRTIO_CONSOLE_SIZE	256
 #define IOPORT_VIRTIO_NET		0xe200	/* Virtio network device */
tools/kvm/mptable.c +38 -1
index 5bbe7ea..e777f64 100644
@@ -181,6 +181,7 @@ void mptable_setup(struct kvm *kvm, unsigned int ncpus)
 	last_addr = (void *)&mpc_intsrc[1];
 	nentries++;
 
+	/* Currently we define 4 possible virtio-blk devices */
 	mpc_intsrc		= last_addr;
 	mpc_intsrc->type	= MP_INTSRC;
 	mpc_intsrc->irqtype	= mp_INT;
@@ -188,7 +189,43 @@ void mptable_setup(struct kvm *kvm, unsigned int ncpus)
 	mpc_intsrc->srcbus	= pcibusid;
 	mpc_intsrc->srcbusirq	= 1; /* virtio block irq pin */
 	mpc_intsrc->dstapic	= ioapicid;
-	mpc_intsrc->dstirq	= 15; /* VIRTIO_BLK_IRQ */
+	mpc_intsrc->dstirq	= 9; /* VIRTIO_BLK_IRQ */
+
+	last_addr = (void *)&mpc_intsrc[1];
+	nentries++;
+
+	mpc_intsrc		= last_addr;
+	mpc_intsrc->type	= MP_INTSRC;
+	mpc_intsrc->irqtype	= mp_INT;
+	mpc_intsrc->irqflag	= MP_IRQDIR_DEFAULT;
+	mpc_intsrc->srcbus	= pcibusid;
+	mpc_intsrc->srcbusirq	= 1; /* virtio block irq pin */
+	mpc_intsrc->dstapic	= ioapicid;
+	mpc_intsrc->dstirq	= 10; /* VIRTIO_BLK_IRQ */
+
+	last_addr = (void *)&mpc_intsrc[1];
+	nentries++;
+
+	mpc_intsrc		= last_addr;
+	mpc_intsrc->type	= MP_INTSRC;
+	mpc_intsrc->irqtype	= mp_INT;
+	mpc_intsrc->irqflag	= MP_IRQDIR_DEFAULT;
+	mpc_intsrc->srcbus	= pcibusid;
+	mpc_intsrc->srcbusirq	= 1; /* virtio block irq pin */
+	mpc_intsrc->dstapic	= ioapicid;
+	mpc_intsrc->dstirq	= 11; /* VIRTIO_BLK_IRQ */
+
+	last_addr = (void *)&mpc_intsrc[1];
+	nentries++;
+
+	mpc_intsrc		= last_addr;
+	mpc_intsrc->type	= MP_INTSRC;
+	mpc_intsrc->irqtype	= mp_INT;
+	mpc_intsrc->irqflag	= MP_IRQDIR_DEFAULT;
+	mpc_intsrc->srcbus	= pcibusid;
+	mpc_intsrc->srcbusirq	= 1; /* virtio block irq pin */
+	mpc_intsrc->dstapic	= ioapicid;
+	mpc_intsrc->dstirq	= 12; /* VIRTIO_BLK_IRQ */
 
 	last_addr = (void *)&mpc_intsrc[1];
 	nentries++;
tools/kvm/virtio-blk.c +123 -70

331 lines not on this page · raw message

Signature · 1 line
1.7.5.rc3
#3 lore raw

Re: [PATCH 2/3 V2] kvm tools: Add support for multiple virtio-blk

Quoted 2 lines · Sasha Levin

Add support for multiple blk_devices by un-globalizing the current blk_device and allow multiple blk_devices.

Very nice!

One nit:

Quoted 22 lines
tools/kvm/mptable.c +22 -0
+	mpc_intsrc		= last_addr;
+	mpc_intsrc->type	= MP_INTSRC;
+	mpc_intsrc->irqtype	= mp_INT;
+	mpc_intsrc->irqflag	= MP_IRQDIR_DEFAULT;
+	mpc_intsrc->srcbus	= pcibusid;
+	mpc_intsrc->srcbusirq	= 1; /* virtio block irq pin */
+	mpc_intsrc->dstapic	= ioapicid;
+	mpc_intsrc->dstirq	= 10; /* VIRTIO_BLK_IRQ */
+
+	last_addr = (void *)&mpc_intsrc[1];
+	nentries++;
+
+	mpc_intsrc		= last_addr;
+	mpc_intsrc->type	= MP_INTSRC;
+	mpc_intsrc->irqtype	= mp_INT;
+	mpc_intsrc->irqflag	= MP_IRQDIR_DEFAULT;
+	mpc_intsrc->srcbus	= pcibusid;
+	mpc_intsrc->srcbusirq	= 1; /* virtio block irq pin */
+	mpc_intsrc->dstapic	= ioapicid;
+	mpc_intsrc->dstirq	= 11; /* VIRTIO_BLK_IRQ */
+
+	last_addr = (void *)&mpc_intsrc[1];

tools/kvm/mptable.c void mptable_setup(struct kvm *kvm, unsigned int ncpus) · line 228

Quoted 10 lines
tools/kvm/mptable.c +10 -0
+	nentries++;
+
+	mpc_intsrc		= last_addr;
+	mpc_intsrc->type	= MP_INTSRC;
+	mpc_intsrc->irqtype	= mp_INT;
+	mpc_intsrc->irqflag	= MP_IRQDIR_DEFAULT;
+	mpc_intsrc->srcbus	= pcibusid;
+	mpc_intsrc->srcbusirq	= 1; /* virtio block irq pin */
+	mpc_intsrc->dstapic	= ioapicid;
+	mpc_intsrc->dstirq	= 12; /* VIRTIO_BLK_IRQ */

There should really be a helper function for these initializations - and a loop that creates VIRTIO_BLK_MAX_DEV of them, right?

Also, the IRQs used by kvm should be enumerated in an include file in a single place, with ranges allocated for specific purposes, otherwise we'll quickly lose track of them.

And a pet peeve of mine:

Quoted 7 lines
tools/kvm/virtio-blk.c +6 -0
+struct blk_device_job {
+	struct virt_queue	*vq;
+	struct blk_device	*blk_device;
+	void			*job_id;
+};
+
 struct blk_device {

tools/kvm/virtio-blk.c line 42

Quoted 10 lines
tools/kvm/virtio-blk.c +2 -1
 	pthread_mutex_t			mutex;
 
 	struct virtio_blk_config	blk_config;
-	struct disk_image			*disk;
+	struct disk_image		*disk;
 	uint32_t			host_features;
 	uint32_t			guest_features;
 	uint16_t			config_vector;
 	uint8_t				status;
+	u8				idx;

The vertical spacing of those two structures (blk_device_job and blk_device) is inconsistent.

tools/kvm/virtio-blk.c static bool virtio_blk_pci_io_device_specific_in(void *data, unsigned long offse · line 84

Quoted 6 lines

static bool virtio_blk_pci_io_in(struct kvm *self, uint16_t port, void *data, int size, uint32_t count) {

tools/kvm/virtio-blk.c +2 -1
-	unsigned long offset;
+	u16 offset, dev_idx;
 	bool ret = true;
+	struct blk_device *blk_device;

Suggestion: please standardize on shorter but still obvious variable names. For blk_device a good one could be 'bdev'.

Given how frequently it's used you might even abbreviate 'struct blk_device' to 'struct blk_dev' - even in that shortr form it's still very obvious what it means.

The new, standardized and streamlined naming convention should be propagated to all 'struct blk_device' using functions. (in separate patches)

Thanks,

Ingo

#4 lore raw

Re: [PATCH 2/3 V2] kvm tools: Add support for multiple virtio-blk

Quoted 3 lines · Ingo Molnar

Also, the IRQs used by kvm should be enumerated in an include file in a single place, with ranges allocated for specific purposes, otherwise we'll quickly lose track of them.

You'll also quickly run out of interrupts. To get lots of devices you can use level-triggered interrupts (this is really how the device is meant to be used, but is slow) or switch to MSI-X (fast but significantly more code needed).

Signature · 1 line
error compiling committee.c: too many arguments to function
#5 lore raw

Re: [PATCH 2/3 V2] kvm tools: Add support for multiple virtio-blk

Quoted 11 lines · Avi Kivity
Quoted 5 lines · Ingo Molnar

Also, the IRQs used by kvm should be enumerated in an include file in a single
place, with ranges allocated for specific purposes, otherwise we'll quickly
lose track of them.

You'll also quickly run out of interrupts. To get lots of devices you can use level-triggered interrupts (this is really how the device is meant to be used, but is slow) or switch to MSI-X (fast but significantly more code needed).

Sure, we will switch to MSI-X soon.

Signature · 2 lines
Best Regards,
Asias He
#6 lore raw

Re: [PATCH 2/3 V2] kvm tools: Add support for multiple virtio-blk

In reply to Ingo Molnar
Quoted 45 lines · Ingo Molnar
Quoted 2 lines · Sasha Levin

Add support for multiple blk_devices by un-globalizing the current blk_device and allow multiple blk_devices.

Very nice!

One nit:

Quoted 22 lines
tools/kvm/mptable.c +22 -0
+	mpc_intsrc		= last_addr;
+	mpc_intsrc->type	= MP_INTSRC;
+	mpc_intsrc->irqtype	= mp_INT;
+	mpc_intsrc->irqflag	= MP_IRQDIR_DEFAULT;
+	mpc_intsrc->srcbus	= pcibusid;
+	mpc_intsrc->srcbusirq	= 1; /* virtio block irq pin */
+	mpc_intsrc->dstapic	= ioapicid;
+	mpc_intsrc->dstirq	= 10; /* VIRTIO_BLK_IRQ */
+
+	last_addr = (void *)&mpc_intsrc[1];
+	nentries++;
+
+	mpc_intsrc		= last_addr;
+	mpc_intsrc->type	= MP_INTSRC;
+	mpc_intsrc->irqtype	= mp_INT;
+	mpc_intsrc->irqflag	= MP_IRQDIR_DEFAULT;
+	mpc_intsrc->srcbus	= pcibusid;
+	mpc_intsrc->srcbusirq	= 1; /* virtio block irq pin */
+	mpc_intsrc->dstapic	= ioapicid;
+	mpc_intsrc->dstirq	= 11; /* VIRTIO_BLK_IRQ */
+
+	last_addr = (void *)&mpc_intsrc[1];

tools/kvm/mptable.c void mptable_setup(struct kvm *kvm, unsigned int ncpus) · line 228

Quoted 10 lines
tools/kvm/mptable.c +10 -0
+	nentries++;
+
+	mpc_intsrc		= last_addr;
+	mpc_intsrc->type	= MP_INTSRC;
+	mpc_intsrc->irqtype	= mp_INT;
+	mpc_intsrc->irqflag	= MP_IRQDIR_DEFAULT;
+	mpc_intsrc->srcbus	= pcibusid;
+	mpc_intsrc->srcbusirq	= 1; /* virtio block irq pin */
+	mpc_intsrc->dstapic	= ioapicid;
+	mpc_intsrc->dstirq	= 12; /* VIRTIO_BLK_IRQ */

There should really be a helper function for these initializations - and a loop that creates VIRTIO_BLK_MAX_DEV of them, right?

Quoted 4 lines

Also, the IRQs used by kvm should be enumerated in an include file in a single place, with ranges allocated for specific purposes, otherwise we'll quickly lose track of them.

The plan is that mptable.c is going to change either way, Cyrill noted we need a way to manage IRQs earlier in that file. That's also why I tried not changing it too much.

Quoted 11 lines

And a pet peeve of mine:

Quoted 9 lines
tools/kvm/virtio-blk.c +6 -0
+struct blk_device_job {
+	struct virt_queue	*vq;
+	struct blk_device	*blk_device;
+	void			*job_id;
+};
+
 struct blk_device {
 	pthread_mutex_t			mutex;
Quoted 12 lines

tools/kvm/virtio-blk.c line 42

Quoted 8 lines
tools/kvm/virtio-blk.c +2 -1
 	struct virtio_blk_config	blk_config;
-	struct disk_image			*disk;
+	struct disk_image		*disk;
 	uint32_t			host_features;
 	uint32_t			guest_features;
 	uint16_t			config_vector;
 	uint8_t				status;
+	u8				idx;

The vertical spacing of those two structures (blk_device_job and blk_device) is inconsistent.

Will fix.

Quoted 10 lines

tools/kvm/virtio-blk.c static bool virtio_blk_pci_io_device_specific_in(void *data, unsigned long offse · line 84

Quoted 6 lines

static bool virtio_blk_pci_io_in(struct kvm *self, uint16_t port, void *data, int size, uint32_t count) {

tools/kvm/virtio-blk.c +2 -1
-	unsigned long offset;
+	u16 offset, dev_idx;
 	bool ret = true;
+	struct blk_device *blk_device;

Suggestion: please standardize on shorter but still obvious variable names. For blk_device a good one could be 'bdev'.

Quoted 6 lines

Given how frequently it's used you might even abbreviate 'struct blk_device' to 'struct blk_dev' - even in that shortr form it's still very obvious what it means.

The new, standardized and streamlined naming convention should be propagated to all 'struct blk_device' using functions. (in separate patches)

Will fix.

Signature · 1 line
Sasha.
#7 lore raw

Re: [PATCH 2/3 V2] kvm tools: Add support for multiple virtio-blk

On 05/04/2011 06:44 PM, Sasha Levin wrote:
...

Quoted 4 lines
Quoted 4 lines

There should really be a helper function for these initializations - and a loop that creates VIRTIO_BLK_MAX_DEV of them, right?

Quoted 9 lines
Quoted 4 lines

Also, the IRQs used by kvm should be enumerated in an include file in a single place, with ranges allocated for specific purposes, otherwise we'll quickly lose track of them.

The plan is that mptable.c is going to change either way, Cyrill noted we need a way to manage IRQs earlier in that file. That's also why I tried not changing it too much.

...

Sasha, I simply out of time, sorry guys. So if you can -- move irqs into
separate file and make loop for block devices this would be great I guess.

We need a global collector/manager for pins/irqs so caller would do something
like

irq_alloc(struct irq_cfg *req)

where

	struct irq_cfg {
		int flags;
		int vector;
		int pin;
	}

or something like that. I don't have a clear picture yet.

Ingo, on the other hands, maybe open-coded snippets would be fine for
a while?

Signature · 2 lines
Thanks,
  Cyrill
#8 lore raw

PATCH v2 3/3 kvm tools: Add cmdline options for loading multiple images

In reply to Sasha Levin

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.

---
 tools/kvm/kvm-run.c |   36 ++++++++++++++++++++++++------------
 1 files changed, 24 insertions(+), 12 deletions(-)
tools/kvm/kvm-run.c +24 -12
index b92232d..5182735 100644
@@ -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);
 
Signature · 1 line
1.7.5.rc3
#9 lore raw

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

Quoted 8 lines · Sasha Levin

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

Quoted 93 lines

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

---
 tools/kvm/kvm-run.c |   36 ++++++++++++++++++++++++------------
 1 files changed, 24 insertions(+), 12 deletions(-)
tools/kvm/kvm-run.c +24 -12
index b92232d..5182735 100644
@@ -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);
 
#10 lore raw

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

Quoted 8 lines · David Ahern
Quoted 6 lines · Sasha Levin

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.

Quoted 6 lines
Quoted 2 lines

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.

Signature · 1 line
Sasha.
#11 lore raw

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

Quoted 12 lines · Sasha Levin
Quoted 11 lines · David Ahern
Quoted 8 lines · Sasha Levin

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

Quoted 7 lines
Quoted 3 lines

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

Quoted 3 lines

This patch should just allow testing of the multiple virtio-blk feature.

#12 lore raw

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

Quoted 25 lines · David Ahern
Quoted 12 lines · Sasha Levin
Quoted 11 lines · David Ahern
Quoted 8 lines · Sasha Levin

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

Quoted 7 lines
Quoted 3 lines

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"),

Quoted 8 lines

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!

Signature · 1 line
Sasha.