All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC] kvm tools: Make kvm__arch_setup_firmware to return error code
@ 2011-12-18 20:24 Cyrill Gorcunov
  0 siblings, 0 replies; only message in thread
From: Cyrill Gorcunov @ 2011-12-18 20:24 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: Sasha Levin, Asias He, Ingo Molnar, KVM-ML

If some of subsequent calls fails we better to return error
code instead of dying with a message. This is a first step
in getting rid of number of die() calls we have in code.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
---
 tools/kvm/builtin-run.c             |    5 ++++-
 tools/kvm/include/kvm/kvm.h         |    2 +-
 tools/kvm/powerpc/kvm.c             |    4 +++-
 tools/kvm/x86/include/kvm/mptable.h |    2 +-
 tools/kvm/x86/kvm.c                 |    4 ++--
 tools/kvm/x86/mptable.c             |   10 +++++++---
 6 files changed, 18 insertions(+), 9 deletions(-)

Index: linux-2.6.git/tools/kvm/builtin-run.c
===================================================================
--- linux-2.6.git.orig/tools/kvm/builtin-run.c
+++ linux-2.6.git/tools/kvm/builtin-run.c
@@ -1121,7 +1121,9 @@ int kvm_cmd_run(int argc, const char **a
 
 	kvm__start_timer(kvm);
 
-	kvm__arch_setup_firmware(kvm);
+	exit_code = kvm__arch_setup_firmware(kvm);
+	if (exit_code)
+		goto err;
 
 	for (i = 0; i < nrcpus; i++) {
 		kvm_cpus[i] = kvm_cpu__init(kvm, i);
@@ -1151,6 +1153,7 @@ int kvm_cmd_run(int argc, const char **a
 			exit_code = 1;
 	}
 
+err:
 	compat__print_all_messages();
 
 	fb__stop();
Index: linux-2.6.git/tools/kvm/include/kvm/kvm.h
===================================================================
--- linux-2.6.git.orig/tools/kvm/include/kvm/kvm.h
+++ linux-2.6.git/tools/kvm/include/kvm/kvm.h
@@ -55,7 +55,7 @@ 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, const char *hugetlbfs_path, u64 ram_size, const char *name);
-void kvm__arch_setup_firmware(struct kvm *kvm);
+int kvm__arch_setup_firmware(struct kvm *kvm);
 bool kvm__arch_cpu_supports_vm(void);
 void kvm__arch_periodic_poll(struct kvm *kvm);
 
Index: linux-2.6.git/tools/kvm/powerpc/kvm.c
===================================================================
--- linux-2.6.git.orig/tools/kvm/powerpc/kvm.c
+++ linux-2.6.git/tools/kvm/powerpc/kvm.c
@@ -176,7 +176,7 @@ static void setup_fdt(struct kvm *kvm)
 /**
  * kvm__arch_setup_firmware
  */
-void kvm__arch_setup_firmware(struct kvm *kvm)
+int kvm__arch_setup_firmware(struct kvm *kvm)
 {
 	/* Load RTAS */
 
@@ -184,4 +184,6 @@ void kvm__arch_setup_firmware(struct kvm
 
 	/* Init FDT */
 	setup_fdt(kvm);
+
+	return 0;
 }
Index: linux-2.6.git/tools/kvm/x86/include/kvm/mptable.h
===================================================================
--- linux-2.6.git.orig/tools/kvm/x86/include/kvm/mptable.h
+++ linux-2.6.git/tools/kvm/x86/include/kvm/mptable.h
@@ -3,6 +3,6 @@
 
 struct kvm;
 
-void mptable_setup(struct kvm *kvm, unsigned int ncpus);
+int mptable_setup(struct kvm *kvm, unsigned int ncpus);
 
 #endif /* KVM_MPTABLE_H_ */
Index: linux-2.6.git/tools/kvm/x86/kvm.c
===================================================================
--- linux-2.6.git.orig/tools/kvm/x86/kvm.c
+++ linux-2.6.git/tools/kvm/x86/kvm.c
@@ -349,7 +349,7 @@ bool load_bzimage(struct kvm *kvm, int f
  * This function is a main routine where we poke guest memory
  * and install BIOS there.
  */
-void kvm__arch_setup_firmware(struct kvm *kvm)
+int kvm__arch_setup_firmware(struct kvm *kvm)
 {
 	/* standart minimal configuration */
 	setup_bios(kvm);
@@ -357,7 +357,7 @@ void kvm__arch_setup_firmware(struct kvm
 	/* FIXME: SMP, ACPI and friends here */
 
 	/* MP table */
-	mptable_setup(kvm, kvm->nrcpus);
+	return mptable_setup(kvm, kvm->nrcpus);
 }
 
 void kvm__arch_periodic_poll(struct kvm *kvm)
Index: linux-2.6.git/tools/kvm/x86/mptable.c
===================================================================
--- linux-2.6.git.orig/tools/kvm/x86/mptable.c
+++ linux-2.6.git/tools/kvm/x86/mptable.c
@@ -71,7 +71,7 @@ static void mptable_add_irq_src(struct m
 /**
  * mptable_setup - create mptable and fill guest memory with it
  */
-void mptable_setup(struct kvm *kvm, unsigned int ncpus)
+int mptable_setup(struct kvm *kvm, unsigned int ncpus)
 {
 	unsigned long real_mpc_table, real_mpf_intel, size;
 	struct mpf_intel *mpf_intel;
@@ -264,8 +264,11 @@ void mptable_setup(struct kvm *kvm, unsi
 	 */
 
 	if (size > (unsigned long)(MB_BIOS_END - bios_rom_size) ||
-	    size > MPTABLE_MAX_SIZE)
-		die("MP table is too big");
+	    size > MPTABLE_MAX_SIZE) {
+		free(mpc_table);
+		pr_err("MP table is too big");
+		return -1;
+	}
 
 	/*
 	 * OK, it is time to move it to guest memory.
@@ -273,4 +276,5 @@ void mptable_setup(struct kvm *kvm, unsi
 	memcpy(guest_flat_to_host(kvm, real_mpc_table), mpc_table, size);
 
 	free(mpc_table);
+	return 0;
 }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-12-18 20:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-18 20:24 [RFC] kvm tools: Make kvm__arch_setup_firmware to return error code Cyrill Gorcunov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.