[PATCH 21/28] kvm tools: Add --hugetlbfs option to specify memory

Matt Evans
2011-12-06T03:41:58Z

Some architectures may want to use hugetlbfs to mmap() their guest memory, so
allow a path to be specified on the commandline and pass it to kvm__arch_init().

Signed-off-by: Matt Evans <matt@ozlabs.org>
---
tools/kvm/builtin-run.c | 4 +++-
tools/kvm/include/kvm/kvm.h | 4 ++--
tools/kvm/kvm.c | 4 ++--
tools/kvm/x86/kvm.c | 2 +-
4 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 84aa931..4c88169 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -84,6 +84,7 @@ static const char *guest_mac;
static const char *host_mac;
static const char *script;
static const char *guest_name;
+static const char *hugetlbfs_path;
static struct virtio_net_params *net_params;
static bool single_step;
static bool readonly_image[MAX_DISK_IMAGES];
@@ -422,6 +423,7 @@ static const struct option options[] = {
OPT_CALLBACK('\0', "tty", NULL, "tty id",
"Remap guest TTY into a pty on the host",
tty_parser),
+ OPT_STRING('\0', "hugetlbfs", &hugetlbfs_path, "path", "Hugetlbfs path"),

OPT_GROUP("Kernel options:"),
OPT_STRING('k', "kernel", &kernel_filename, "kernel",
@@ -808,7 +810,7 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
guest_name = default_name;
}

- kvm = kvm__init(dev, ram_size, guest_name);
+ kvm = kvm__init(dev, hugetlbfs_path, ram_size, guest_name);

kvm->single_step = single_step;

diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h
index 5fe6e75..7159952 100644
--- a/tools/kvm/include/kvm/kvm.h
+++ b/tools/kvm/include/kvm/kvm.h
@@ -30,7 +30,7 @@ struct kvm_ext {
void kvm__set_dir(const char *fmt, ...);
const char *kvm__get_dir(void);

-struct kvm *kvm__init(const char *kvm_dev, u64 ram_size, const char *name);
+struct kvm *kvm__init(const char *kvm_dev, const char *hugetlbfs_path, u64 ram_size, const char *name);
int kvm__recommended_cpus(struct kvm *kvm);
int kvm__max_cpus(struct kvm *kvm);
void kvm__init_ram(struct kvm *kvm);
@@ -54,7 +54,7 @@ int kvm__enumerate_instances(int (*callback)(const char *name, int pid));
void kvm__remove_socket(const char *name);

void kvm__arch_set_cmdline(char *cmdline, bool video);
-void kvm__arch_init(struct kvm *kvm, const char *kvm_dev, u64 ram_size, const char *name);
+void kvm__arch_init(struct kvm *kvm, const char *kvm_dev, const char *hugetlbfs_path, u64 ram_size, const char *name);
void kvm__arch_setup_firmware(struct kvm *kvm);
bool kvm__arch_cpu_supports_vm(void);
void kvm__arch_periodic_poll(struct kvm *kvm);
diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
index 6f33e1a..503ceae 100644
--- a/tools/kvm/kvm.c
+++ b/tools/kvm/kvm.c
@@ -272,7 +272,7 @@ static void kvm__pid(int fd, u32 type, u32 len, u8 *msg)
pr_warning("Failed sending PID");
}

-struct kvm *kvm__init(const char *kvm_dev, u64 ram_size, const char *name)
+struct kvm *kvm__init(const char *kvm_dev, const char *hugetlbfs_path, u64 ram_size, const char *name)
{
struct kvm *kvm;
int ret;
@@ -305,7 +305,7 @@ struct kvm *kvm__init(const char *kvm_dev, u64 ram_size, const char *name)
if (kvm__check_extensions(kvm))
die("A required KVM extention is not supported by OS");

- kvm__arch_init(kvm, kvm_dev, ram_size, name);
+ kvm__arch_init(kvm, kvm_dev, hugetlbfs_path, ram_size, name);

kvm->name = name;

diff --git a/tools/kvm/x86/kvm.c b/tools/kvm/x86/kvm.c
index 4ac21c0..76f805f 100644
--- a/tools/kvm/x86/kvm.c
+++ b/tools/kvm/x86/kvm.c
@@ -161,7 +161,7 @@ void kvm__arch_set_cmdline(char *cmdline, bool video)
}

/* Architecture-specific KVM init */
-void kvm__arch_init(struct kvm *kvm, const char *kvm_dev, u64 ram_size, const char *name)
+void kvm__arch_init(struct kvm *kvm, const char *kvm_dev, const char *hugetlbfs_path, u64 ram_size, const char *name)
{
struct kvm_pit_config pit_config = { .flags = 0, };
int ret;