[tip:tools/kvm] kvm tools: carefully send and handle balloon ipc

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

 



Commit-ID:  34e41766d2e2716b0708694fe7877c54cdf09f74
Gitweb:     http://git.kernel.org/tip/34e41766d2e2716b0708694fe7877c54cdf09f74
Author:     Lai Jiangshan <laijs@xxxxxxxxxxxxxx>
AuthorDate: Tue, 20 Dec 2011 17:08:54 +0800
Committer:  Pekka Enberg <penberg@xxxxxxxxxx>
CommitDate: Wed, 21 Dec 2011 22:28:09 +0200

kvm tools: carefully send and handle balloon ipc

Remove struct balloon_cmd and use kvm_ipc__send_msg().

Signed-off-by: Lai Jiangshan <laijs@xxxxxxxxxxxxxx>
Signed-off-by: Pekka Enberg <penberg@xxxxxxxxxx>
---
 tools/kvm/builtin-balloon.c |   18 +++++-------------
 tools/kvm/virtio/balloon.c  |    6 +++++-
 2 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/tools/kvm/builtin-balloon.c b/tools/kvm/builtin-balloon.c
index 3f3056e..5bd2291 100644
--- a/tools/kvm/builtin-balloon.c
+++ b/tools/kvm/builtin-balloon.c
@@ -13,12 +13,6 @@ static const char *instance_name;
 static u64 inflate;
 static u64 deflate;
 
-struct balloon_cmd {
-	u32 type;
-	u32 len;
-	int amount;
-};
-
 static const char * const balloon_usage[] = {
 	"lkvm balloon [-n name] [-p pid] [-i amount] [-d amount]",
 	NULL
@@ -50,9 +44,9 @@ static void parse_balloon_options(int argc, const char **argv)
 
 int kvm_cmd_balloon(int argc, const char **argv, const char *prefix)
 {
-	struct balloon_cmd cmd;
 	int instance;
 	int r;
+	int amount;
 
 	parse_balloon_options(argc, argv);
 
@@ -67,17 +61,15 @@ int kvm_cmd_balloon(int argc, const char **argv, const char *prefix)
 	if (instance <= 0)
 		die("Failed locating instance");
 
-	cmd.type = KVM_IPC_BALLOON;
-	cmd.len = sizeof(cmd.amount);
-
 	if (inflate)
-		cmd.amount = inflate;
+		amount = inflate;
 	else if (deflate)
-		cmd.amount = -deflate;
+		amount = -deflate;
 	else
 		kvm_balloon_help();
 
-	r = write(instance, &cmd, sizeof(cmd));
+	r = kvm_ipc__send_msg(instance, KVM_IPC_BALLOON,
+			sizeof(amount), (u8 *)&amount);
 
 	close(instance);
 
diff --git a/tools/kvm/virtio/balloon.c b/tools/kvm/virtio/balloon.c
index 556f0ec..bd984b7 100644
--- a/tools/kvm/virtio/balloon.c
+++ b/tools/kvm/virtio/balloon.c
@@ -154,8 +154,12 @@ static void virtio_bln__print_stats(int fd, u32 type, u32 len, u8 *msg)
 
 static void handle_mem(int fd, u32 type, u32 len, u8 *msg)
 {
-	int mem = *(int *)msg;
+	int mem;
 
+	if (WARN_ON(type != KVM_IPC_BALLOON || len != sizeof(int)))
+		return;
+
+	mem = *(int *)msg;
 	if (mem > 0) {
 		bdev.config.num_pages += 256 * mem;
 	} else if (mem < 0) {
--
To unsubscribe from this list: send the line "unsubscribe linux-tip-commits" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Stable Commits]     [Linux Stable Kernel]     [Linux Kernel]     [Linux USB Devel]     [Linux Video &Media]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux