From 44a2cc2aa288662c4ce12c0061f7303c17dde81c Mon Sep 17 00:00:00 2001 From: Sasha Levin Date: Sun, 3 Jul 2011 18:38:07 +0300 Subject: [PATCH] kvm tools: Give guest instances default name Name instances which aren't specifically named by the user (using the --name flag) with the following pattern: 'guest-' Suggested-by: Pekka Enberg Signed-off-by: Sasha Levin Signed-off-by: Pekka Enberg --- tools/kvm/kvm-run.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/kvm/kvm-run.c b/tools/kvm/kvm-run.c index a7f010c7e8c2..57791f5d43bc 100644 --- a/tools/kvm/kvm-run.c +++ b/tools/kvm/kvm-run.c @@ -466,7 +466,7 @@ void kvm_run_help(void) int kvm_cmd_run(int argc, const char **argv, const char *prefix) { struct virtio_net_parameters net_params; - static char real_cmdline[2048]; + static char real_cmdline[2048], default_name[20]; struct framebuffer *fb = NULL; unsigned int nr_online_cpus; int exit_code = 0; @@ -552,6 +552,11 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix) term_init(); + if (!guest_name) { + sprintf(default_name, "guest-%u", getpid()); + guest_name = default_name; + } + kvm = kvm__init(kvm_dev, ram_size, guest_name); ioeventfd__init(); @@ -609,7 +614,7 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix) free(hi); - printf(" # kvm run -k %s -m %Lu -c %d\n", kernel_filename, ram_size / 1024 / 1024, nrcpus); + printf(" # kvm run -k %s -m %Lu -c %d --name %s\n", kernel_filename, ram_size / 1024 / 1024, nrcpus, guest_name); if (!kvm__load_kernel(kvm, kernel_filename, initrd_filename, real_cmdline, vidmode)) -- 2.39.5