kvm tools: Make kvm__arch_setup_firmware to return error code
RFC 1/1 kvm tools: Make kvm__arch_setup_firmware to return error code
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 <[email protected]>
--- 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(-)
tools/kvm/builtin-run.c +4 -1
@@ -1121,7 +1121,9 @@ int kvm_cmd_run(int argc, const char **akvm__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 ();
tools/kvm/include/kvm/kvm.h +1 -1
@@ -55,7 +55,7 @@ void kvm__remove_socket(const char *namevoid 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);
tools/kvm/powerpc/kvm.c +3 -1
@@ -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 ; }
tools/kvm/x86/include/kvm/mptable.h +1 -1
@@ -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_ */
tools/kvm/x86/kvm.c +2 -2
@@ -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)
tools/kvm/x86/mptable.c +7 -3
@@ -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, unsimemcpy (guest_flat_to_host (kvm, real_mpc_table), mpc_table, size);free (mpc_table); +return 0 ; }