From: Cyrill Gorcunov <gorcunov@gmail.com>
To: Pekka Enberg <penberg@kernel.org>
Cc: Sasha Levin <levinsasha928@gmail.com>,
Asias He <asias.hejun@gmail.com>, Ingo Molnar <mingo@elte.hu>,
KVM-ML <kvm@vger.kernel.org>
Subject: [RFC] kvm tools: Make kvm__arch_setup_firmware to return error code
Date: Mon, 19 Dec 2011 00:24:56 +0400 [thread overview]
Message-ID: <20111218202456.GA17380@moon> (raw)
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;
}
reply other threads:[~2011-12-18 20:25 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20111218202456.GA17380@moon \
--to=gorcunov@gmail.com \
--cc=asias.hejun@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=levinsasha928@gmail.com \
--cc=mingo@elte.hu \
--cc=penberg@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox