From patchwork Wed Jun 29 18:02:17 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 929932 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p5TI4kqY005646 for ; Wed, 29 Jun 2011 18:04:46 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757226Ab1F2SEn (ORCPT ); Wed, 29 Jun 2011 14:04:43 -0400 Received: from mail-qw0-f46.google.com ([209.85.216.46]:41584 "EHLO mail-qw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757014Ab1F2SEk (ORCPT ); Wed, 29 Jun 2011 14:04:40 -0400 Received: by mail-qw0-f46.google.com with SMTP id 3so740259qwk.19 for ; Wed, 29 Jun 2011 11:04:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=ZvzCwoMEDmEjUW38tJxMeketOh06lVmuMpVjfvg9QCc=; b=BVfCY8zic2bARVgkMcTLwtLVykAM3E9nD431EWVtYyXmpZcgpqtEixNhsX0mAoE3P+ LcTL1VWXxhWmPHpM/JYVKtWrMSrvnTeW3GvRPsvZtbaTAlKvwAYr2V0WSdrdnoKf2Epb gTkUCvb+23GneXCxzEqO6ALnCggAN5B+P3nVQ= Received: by 10.224.215.129 with SMTP id he1mr894041qab.58.1309370679862; Wed, 29 Jun 2011 11:04:39 -0700 (PDT) Received: from localhost.localdomain (c-71-232-157-243.hsd1.ma.comcast.net [71.232.157.243]) by mx.google.com with ESMTPS id e18sm1067677qcs.29.2011.06.29.11.04.38 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 29 Jun 2011 11:04:39 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org Cc: kvm@vger.kernel.org, mingo@elte.hu, asias.hejun@gmail.com, gorcunov@gmail.com, prasadjoshi124@gmail.com, Sasha Levin Subject: [PATCH 8/9] kvm tools: Add 'kvm balloon' command Date: Wed, 29 Jun 2011 14:02:17 -0400 Message-Id: <1309370538-7947-8-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.6 In-Reply-To: <1309370538-7947-1-git-send-email-levinsasha928@gmail.com> References: <1309370538-7947-1-git-send-email-levinsasha928@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Wed, 29 Jun 2011 18:04:47 +0000 (UTC) Add a command to allow easily inflate/deflate the balloon driver in running instances. Usage: kvm balloon [command] [instance name] [size] command is either inflate or deflate, and size is represented in MB. Target instance must be named (started with '--name'). Signed-off-by: Sasha Levin --- tools/kvm/Makefile | 1 + tools/kvm/include/kvm/kvm-balloon.h | 6 ++++++ tools/kvm/kvm-balloon.c | 34 ++++++++++++++++++++++++++++++++++ tools/kvm/kvm-cmd.c | 12 +++++++----- tools/kvm/virtio/balloon.c | 8 ++++---- 5 files changed, 52 insertions(+), 9 deletions(-) create mode 100644 tools/kvm/include/kvm/kvm-balloon.h create mode 100644 tools/kvm/kvm-balloon.c diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile index a1b2f4c..4823c77 100644 --- a/tools/kvm/Makefile +++ b/tools/kvm/Makefile @@ -50,6 +50,7 @@ OBJS += kvm-cmd.o OBJS += kvm-debug.o OBJS += kvm-help.o OBJS += kvm-pause.o +OBJS += kvm-balloon.o OBJS += kvm-run.o OBJS += mptable.o OBJS += rbtree.o diff --git a/tools/kvm/include/kvm/kvm-balloon.h b/tools/kvm/include/kvm/kvm-balloon.h new file mode 100644 index 0000000..f5f92b9 --- /dev/null +++ b/tools/kvm/include/kvm/kvm-balloon.h @@ -0,0 +1,6 @@ +#ifndef KVM__BALLOON_H +#define KVM__BALLOON_H + +int kvm_cmd_balloon(int argc, const char **argv, const char *prefix); + +#endif diff --git a/tools/kvm/kvm-balloon.c b/tools/kvm/kvm-balloon.c new file mode 100644 index 0000000..277cada --- /dev/null +++ b/tools/kvm/kvm-balloon.c @@ -0,0 +1,34 @@ +#include +#include +#include + +#include +#include +#include +#include + +int kvm_cmd_balloon(int argc, const char **argv, const char *prefix) +{ + int pid; + int amount, i; + int inflate = 0; + + if (argc != 3) + die("Usage: kvm balloon [command] [instance name] [amount]\n"); + + pid = kvm__get_pid_by_instance(argv[1]); + if (pid < 0) + die("Failed locating instance name"); + + if (strcmp(argv[0], "inflate") == 0) + inflate = 1; + else if (strcmp(argv[0], "deflate")) + die("command can be either 'inflate' or 'deflate'"); + + amount = atoi(argv[2]); + + for (i = 0; i < amount; i++) + kill(pid, inflate ? SIGKVMADDMEM : SIGKVMDELMEM); + + return 0; +} diff --git a/tools/kvm/kvm-cmd.c b/tools/kvm/kvm-cmd.c index ffbc4ff..1598781 100644 --- a/tools/kvm/kvm-cmd.c +++ b/tools/kvm/kvm-cmd.c @@ -7,16 +7,18 @@ /* user defined header files */ #include "kvm/kvm-debug.h" #include "kvm/kvm-pause.h" +#include "kvm/kvm-balloon.h" #include "kvm/kvm-help.h" #include "kvm/kvm-cmd.h" #include "kvm/kvm-run.h" struct cmd_struct kvm_commands[] = { - { "pause", kvm_cmd_pause, NULL, 0 }, - { "debug", kvm_cmd_debug, NULL, 0 }, - { "help", kvm_cmd_help, NULL, 0 }, - { "run", kvm_cmd_run, kvm_run_help, 0 }, - { NULL, NULL, NULL, 0 }, + { "pause", kvm_cmd_pause, NULL, 0 }, + { "debug", kvm_cmd_debug, NULL, 0 }, + { "balloon", kvm_cmd_balloon, NULL, 0 }, + { "help", kvm_cmd_help, NULL, 0 }, + { "run", kvm_cmd_run, kvm_run_help, 0 }, + { NULL, NULL, NULL, 0 }, }; /* diff --git a/tools/kvm/virtio/balloon.c b/tools/kvm/virtio/balloon.c index ab9ccb7..854d04b 100644 --- a/tools/kvm/virtio/balloon.c +++ b/tools/kvm/virtio/balloon.c @@ -39,7 +39,7 @@ struct bln_dev { /* virtio queue */ u16 queue_selector; struct virt_queue vqs[NUM_VIRT_QUEUES]; - void *jobs[NUM_VIRT_QUEUES]; + struct thread_pool__job jobs[NUM_VIRT_QUEUES]; struct virtio_balloon_config config; }; @@ -174,13 +174,13 @@ static bool virtio_bln_pci_io_out(struct ioport *ioport, struct kvm *kvm, u16 po vring_init(&queue->vring, VIRTIO_BLN_QUEUE_SIZE, p, VIRTIO_PCI_VRING_ALIGN); - bdev.jobs[bdev.queue_selector] = thread_pool__add_job(kvm, virtio_bln_do_io, queue); + thread_pool__init_job(&bdev.jobs[bdev.queue_selector], kvm, virtio_bln_do_io, queue); ioevent = (struct ioevent) { .io_addr = bdev.base_addr + VIRTIO_PCI_QUEUE_NOTIFY, .io_len = sizeof(u16), .fn = ioevent_callback, - .fn_ptr = bdev.jobs[bdev.queue_selector], + .fn_ptr = &bdev.jobs[bdev.queue_selector], .datamatch = bdev.queue_selector, .fn_kvm = kvm, .fd = eventfd(0, 0), @@ -196,7 +196,7 @@ static bool virtio_bln_pci_io_out(struct ioport *ioport, struct kvm *kvm, u16 po case VIRTIO_PCI_QUEUE_NOTIFY: { u16 queue_index; queue_index = ioport__read16(data); - thread_pool__do_job(bdev.jobs[queue_index]); + thread_pool__do_job(&bdev.jobs[queue_index]); break; } case VIRTIO_PCI_STATUS: