diff mbox

[v3,2/4] kvm tools: Close the disk images after the guest shuts down

Message ID 1305916909-21734-2-git-send-email-prasadjoshi124@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Prasad Joshi May 20, 2011, 6:41 p.m. UTC
Signed-off-by: Prasad Joshi <prasadjoshi124@gmail.com>
---
 tools/kvm/disk/core.c              |   11 +++++++++++
 tools/kvm/include/kvm/disk-image.h |    1 +
 tools/kvm/kvm-run.c                |    1 +
 3 files changed, 13 insertions(+), 0 deletions(-)
diff mbox

Patch

diff --git a/tools/kvm/disk/core.c b/tools/kvm/disk/core.c
index fa603cc..4a9d0c9 100644
--- a/tools/kvm/disk/core.c
+++ b/tools/kvm/disk/core.c
@@ -118,6 +118,17 @@  int disk_image__close(struct disk_image *disk)
 	return 0;
 }
 
+void disk_image__close_all(struct disk_image **disks, int count)
+{
+	if (count <= 0)
+		return;
+
+	while (count)
+		disk_image__close(disks[--count]);
+
+	free(disks);
+}
+
 /*
  * Fill iov with disk data, starting from sector 'sector'.
  * Return amount of bytes read.
diff --git a/tools/kvm/include/kvm/disk-image.h b/tools/kvm/include/kvm/disk-image.h
index bf2bfa9..1363fe1 100644
--- a/tools/kvm/include/kvm/disk-image.h
+++ b/tools/kvm/include/kvm/disk-image.h
@@ -55,6 +55,7 @@  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__new(int fd, u64 size, struct disk_image_operations *ops, int mmap);
 int disk_image__close(struct disk_image *disk);
+void disk_image__close_all(struct disk_image **disks, int count);
 int disk_image__flush(struct disk_image *disk);
 ssize_t disk_image__read(struct disk_image *disk, u64 sector, const struct iovec *iov, int iovcount);
 ssize_t disk_image__write(struct disk_image *disk, u64 sector, const struct iovec *iov, int iovcount);
diff --git a/tools/kvm/kvm-run.c b/tools/kvm/kvm-run.c
index 28e3ed6..32b34fe 100644
--- a/tools/kvm/kvm-run.c
+++ b/tools/kvm/kvm-run.c
@@ -615,6 +615,7 @@  int kvm_cmd_run(int argc, const char **argv, const char *prefix)
 			exit_code = 1;
 	}
 
+	disk_image__close_all(kvm->disks, image_count);
 	kvm__delete(kvm);
 
 	if (!exit_code)