diff mbox

[v1,1/3] kvm tools: Close the disk images after the guest shuts down

Message ID 1305713837-18889-1-git-send-email-prasadjoshi124@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Prasad Joshi May 18, 2011, 10:17 a.m. UTC
Signed-off-by: Prasad Joshi <prasadjoshi124@gmail.com>
---
 tools/kvm/kvm-run.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

Comments

Sasha Levin May 18, 2011, 10:31 a.m. UTC | #1
On Wed, 2011-05-18 at 11:17 +0100, Prasad Joshi wrote:
> Signed-off-by: Prasad Joshi <prasadjoshi124@gmail.com>
> ---
>  tools/kvm/kvm-run.c |    7 +++++++
>  1 files changed, 7 insertions(+), 0 deletions(-)
> 
> diff --git a/tools/kvm/kvm-run.c b/tools/kvm/kvm-run.c
> index ba8e5ce..ef180e4 100644
> --- a/tools/kvm/kvm-run.c
> +++ b/tools/kvm/kvm-run.c
> @@ -46,6 +46,7 @@
>  #define MAX_DISK_IMAGES		4
>  
>  static struct kvm *kvm;
> +static struct disk_image *image_disks[MAX_DISK_IMAGES];

You already have image_filename[] which holds image filenames, and
image_count which tells you how many images are loaded.

>  static struct kvm_cpu *kvm_cpus[KVM_NR_CPUS];
>  static __thread struct kvm_cpu *current_kvm_cpu;
>  
> @@ -504,6 +505,7 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
>  				die("unable to load disk image %s", image_filename[i]);
>  
>  			virtio_blk__init(kvm, disk);
> +			image_disks[i] = disk;
>  		}
>  	}
>  	free(hi);
> @@ -583,6 +585,11 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
>  			exit_code	= 1;
>  	}
>  
> +	for (i = 0; i < MAX_DISK_IMAGES; i++) {
> +		if (image_disks[i])
> +			disk_image__close(image_disks[i]);
> +	}
> +
>  	kvm__delete(kvm);
>  
>  	if (!exit_code)
Prasad Joshi May 18, 2011, 10:36 a.m. UTC | #2
On Wed, May 18, 2011 at 11:31 AM, Sasha Levin <levinsasha928@gmail.com> wrote:
> On Wed, 2011-05-18 at 11:17 +0100, Prasad Joshi wrote:
>> Signed-off-by: Prasad Joshi <prasadjoshi124@gmail.com>
>> ---
>>  tools/kvm/kvm-run.c |    7 +++++++
>>  1 files changed, 7 insertions(+), 0 deletions(-)
>>
>> diff --git a/tools/kvm/kvm-run.c b/tools/kvm/kvm-run.c
>> index ba8e5ce..ef180e4 100644
>> --- a/tools/kvm/kvm-run.c
>> +++ b/tools/kvm/kvm-run.c
>> @@ -46,6 +46,7 @@
>>  #define MAX_DISK_IMAGES              4
>>
>>  static struct kvm *kvm;
>> +static struct disk_image *image_disks[MAX_DISK_IMAGES];
>
> You already have image_filename[] which holds image filenames, and

The disk close operation needs struct disk_image *. This array holds
those pointers.

> image_count which tells you how many images are loaded.

Ya missed that.
Thanks.

>
>>  static struct kvm_cpu *kvm_cpus[KVM_NR_CPUS];
>>  static __thread struct kvm_cpu *current_kvm_cpu;
>>
>> @@ -504,6 +505,7 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
>>                               die("unable to load disk image %s", image_filename[i]);
>>
>>                       virtio_blk__init(kvm, disk);
>> +                     image_disks[i] = disk;
>>               }
>>       }
>>       free(hi);
>> @@ -583,6 +585,11 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
>>                       exit_code       = 1;
>>       }
>>
>> +     for (i = 0; i < MAX_DISK_IMAGES; i++) {
>> +             if (image_disks[i])
>> +                     disk_image__close(image_disks[i]);
>> +     }
>> +
>>       kvm__delete(kvm);
>>
>>       if (!exit_code)
>
>
> --
>
> Sasha.
>
>
--
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
Ingo Molnar May 18, 2011, 11:15 a.m. UTC | #3
* Prasad Joshi <prasadjoshi124@gmail.com> wrote:

> @@ -583,6 +585,11 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
>  			exit_code	= 1;
>  	}
>  
> +	for (i = 0; i < MAX_DISK_IMAGES; i++) {
> +		if (image_disks[i])
> +			disk_image__close(image_disks[i]);
> +	}

Isnt this a method that the disk/image subsystem wants to provide? Or at least 
it should move into an inline - kvm_cmd_run() is *way* too big already at 200 
lines and these patches are how it grows!

it should split into several helpers, setting up various aspects of the 
context, then one separate helper doing the vcpu startup and waiting.

Thanks,

	Ingo
--
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
diff mbox

Patch

diff --git a/tools/kvm/kvm-run.c b/tools/kvm/kvm-run.c
index ba8e5ce..ef180e4 100644
--- a/tools/kvm/kvm-run.c
+++ b/tools/kvm/kvm-run.c
@@ -46,6 +46,7 @@ 
 #define MAX_DISK_IMAGES		4
 
 static struct kvm *kvm;
+static struct disk_image *image_disks[MAX_DISK_IMAGES];
 static struct kvm_cpu *kvm_cpus[KVM_NR_CPUS];
 static __thread struct kvm_cpu *current_kvm_cpu;
 
@@ -504,6 +505,7 @@  int kvm_cmd_run(int argc, const char **argv, const char *prefix)
 				die("unable to load disk image %s", image_filename[i]);
 
 			virtio_blk__init(kvm, disk);
+			image_disks[i] = disk;
 		}
 	}
 	free(hi);
@@ -583,6 +585,11 @@  int kvm_cmd_run(int argc, const char **argv, const char *prefix)
 			exit_code	= 1;
 	}
 
+	for (i = 0; i < MAX_DISK_IMAGES; i++) {
+		if (image_disks[i])
+			disk_image__close(image_disks[i]);
+	}
+
 	kvm__delete(kvm);
 
 	if (!exit_code)