[PATCH v1 2/3] kvm tools: Release memoty allocated during virtio block initialization

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add a new function virtio_blk__fini() which goes
through array of block devices and releases
memory allocated for block device.

Signed-off-by: Prasad Joshi <prasadjoshi124@xxxxxxxxx>
---
 tools/kvm/include/kvm/virtio-blk.h |    1 +
 tools/kvm/kvm-run.c                |    2 ++
 tools/kvm/virtio/blk.c             |    9 +++++++++
 3 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/tools/kvm/include/kvm/virtio-blk.h b/tools/kvm/include/kvm/virtio-blk.h
index 22983e8..61fe404 100644
--- a/tools/kvm/include/kvm/virtio-blk.h
+++ b/tools/kvm/include/kvm/virtio-blk.h
@@ -6,5 +6,6 @@
 struct kvm;
 
 void virtio_blk__init(struct kvm *kvm, struct disk_image *disk);
+void virtio_blk__fini(struct kvm *kvm);
 
 #endif /* KVM__BLK_VIRTIO_H */
diff --git a/tools/kvm/kvm-run.c b/tools/kvm/kvm-run.c
index ef180e4..1a1eccc 100644
--- a/tools/kvm/kvm-run.c
+++ b/tools/kvm/kvm-run.c
@@ -585,6 +585,8 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
 			exit_code	= 1;
 	}
 
+	virtio_blk__fini(kvm);
+
 	for (i = 0; i < MAX_DISK_IMAGES; i++) {
 		if (image_disks[i])
 			disk_image__close(image_disks[i]);
diff --git a/tools/kvm/virtio/blk.c b/tools/kvm/virtio/blk.c
index 6c9eb19..2e541ef 100644
--- a/tools/kvm/virtio/blk.c
+++ b/tools/kvm/virtio/blk.c
@@ -262,6 +262,15 @@ static int virtio_blk_find_empty_dev(void)
 	return -1;
 }
 
+
+void virtio_blk__fini(struct kvm *kvm)
+{
+	int i;
+
+	for (i = 0; i < VIRTIO_BLK_MAX_DEV; i++)
+		free(bdevs[i]);
+}
+
 void virtio_blk__init(struct kvm *kvm, struct disk_image *disk)
 {
 	u16 blk_dev_base_addr;
-- 
1.7.4.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux