@@ -33,6 +33,7 @@ struct kvm {
const char *vmlinux;
struct disk_image **disks;
+ int ndisks;
};
struct kvm *kvm__init(const char *kvm_dev, unsigned long ram_size);
@@ -6,5 +6,6 @@
struct kvm;
void virtio_blk__init(struct kvm *kvm, struct disk_image *disk);
+void virtio_blk__init_all(struct kvm *kvm);
#endif /* KVM__BLK_VIRTIO_H */
@@ -529,14 +529,14 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
if (!strstr(real_cmdline, "root="))
strlcat(real_cmdline, " root=/dev/vda rw ", sizeof(real_cmdline));
+ kvm->ndisks = image_count;
kvm->disks = disk_image__open_all(image_filename, readonly_image, image_count);
if (!kvm->disks)
die("unable to load disk image");
free(hi);
- for (i = 0; i < image_count; i++)
- virtio_blk__init(kvm, kvm->disks[i]);
+ virtio_blk__init_all(kvm);
printf(" # kvm run -k %s -m %Lu -c %d\n", kernel_filename, ram_size / 1024 / 1024, nrcpus);
@@ -320,3 +320,11 @@ void virtio_blk__init(struct kvm *kvm, struct disk_image *disk)
ioport__register(blk_dev_base_addr, &virtio_blk_io_ops, IOPORT_VIRTIO_BLK_SIZE);
}
+
+void virtio_blk__init_all(struct kvm *kvm)
+{
+ int i;
+
+ for (i = 0; i < kvm->ndisks; i++)
+ virtio_blk__init(kvm, kvm->disks[i]);
+}
The patch moves the code for initialization of all of the virtio block devices to virtio subsystem. Signed-off-by: Prasad Joshi <prasadjoshi124@gmail.com> --- tools/kvm/include/kvm/kvm.h | 1 + tools/kvm/include/kvm/virtio-blk.h | 1 + tools/kvm/kvm-run.c | 4 ++-- tools/kvm/virtio/blk.c | 8 ++++++++ 4 files changed, 12 insertions(+), 2 deletions(-)