]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: Add 'kvm balloon' command
authorSasha Levin <levinsasha928@gmail.com>
Sat, 2 Jul 2011 23:52:10 +0000 (02:52 +0300)
committerPekka Enberg <penberg@kernel.org>
Sat, 2 Jul 2011 10:07:45 +0000 (13:07 +0300)
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 <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/Makefile
tools/kvm/include/kvm/kvm-balloon.h [new file with mode: 0644]
tools/kvm/kvm-balloon.c [new file with mode: 0644]
tools/kvm/kvm-cmd.c
tools/kvm/virtio/balloon.c

index 1ec75da2d5a167d44748531b38e25f97c95fefc1..90ad708bf3959195fff6e9f7524e7e372c3327d1 100644 (file)
@@ -58,6 +58,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 (file)
index 0000000..f5f92b9
--- /dev/null
@@ -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 (file)
index 0000000..277cada
--- /dev/null
@@ -0,0 +1,34 @@
+#include <stdio.h>
+#include <string.h>
+#include <signal.h>
+
+#include <kvm/util.h>
+#include <kvm/kvm-cmd.h>
+#include <kvm/kvm-balloon.h>
+#include <kvm/kvm.h>
+
+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;
+}
index ffbc4ff0dc4f18d20ed5de5d4d017a2b50dc0a62..1598781f843d333e164bd7426cedd4a940948130 100644 (file)
@@ -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 },
 };
 
 /*
index ab9ccb782f22922ad9d0bbe9220790dd343c448c..854d04bd46cfddf8ad793020a4e6a7259b58b492 100644 (file)
@@ -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: