All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <levinsasha928@gmail.com>
To: penberg@kernel.org
Cc: mingo@elte.hu, gorcunov@gmail.com, asias.hejun@gmail.com,
	kvm@vger.kernel.org, Sasha Levin <levinsasha928@gmail.com>
Subject: [RFC 01/12] kvm tools: Split kvm_cmd_run into init, work and uninit
Date: Mon, 19 Dec 2011 15:58:23 +0200	[thread overview]
Message-ID: <1324303114-5948-2-git-send-email-levinsasha928@gmail.com> (raw)
In-Reply-To: <1324303114-5948-1-git-send-email-levinsasha928@gmail.com>

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
 tools/kvm/builtin-run.c |   38 ++++++++++++++++++++++++++++++--------
 1 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 524ca16..0234879 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -845,15 +845,13 @@ static void kvm_run_write_sandbox_cmd(const char **argv, int argc)
 	close(fd);
 }
 
-int kvm_cmd_run(int argc, const char **argv, const char *prefix)
+static int kvm_cmd_run_init(int argc, const char **argv)
 {
 	static char real_cmdline[2048], default_name[20];
 	struct framebuffer *fb = NULL;
 	unsigned int nr_online_cpus;
-	int exit_code = 0;
 	int max_cpus, recommended_cpus;
 	int i;
-	void *ret;
 
 	signal(SIGALRM, handle_sigalrm);
 	kvm_ipc__register_handler(KVM_IPC_DEBUG, handle_debug);
@@ -1132,6 +1130,14 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
 	thread_pool__init(nr_online_cpus);
 	ioeventfd__start();
 
+	return 0;
+}
+
+static int kvm_cmd_run_work(void)
+{
+	int i, r = -1;
+	void *ret = NULL;
+
 	for (i = 0; i < nrcpus; i++) {
 		if (pthread_create(&kvm_cpus[i]->thread, NULL, kvm_cpu_thread, kvm_cpus[i]) != 0)
 			die("unable to create KVM VCPU thread");
@@ -1139,7 +1145,7 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
 
 	/* Only VCPU #0 is going to exit by itself when shutting down */
 	if (pthread_join(kvm_cpus[0]->thread, &ret) != 0)
-		exit_code = 1;
+		r = 0;
 
 	for (i = 1; i < nrcpus; i++) {
 		if (kvm_cpus[i]->is_running) {
@@ -1147,10 +1153,15 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
 			if (pthread_join(kvm_cpus[i]->thread, &ret) != 0)
 				die("pthread_join");
 		}
-		if (ret != NULL)
-			exit_code = 1;
+		if (ret == NULL)
+			r = 0;
 	}
 
+	return r;
+}
+
+static int kvm_cmd_run_uninit(int guest_ret)
+{
 	compat__print_all_messages();
 
 	fb__stop();
@@ -1161,8 +1172,19 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
 	disk_image__close_all(kvm->disks, image_count);
 	kvm__delete(kvm);
 
-	if (!exit_code)
+	if (guest_ret == 0)
 		printf("\n  # KVM session ended normally.\n");
 
-	return exit_code;
+	return 0;
+}
+
+int kvm_cmd_run(int argc, const char **argv, const char *prefix)
+{
+	int r, ret;
+
+	r = kvm_cmd_run_init(argc, argv);
+	ret = kvm_cmd_run_work();
+	r = kvm_cmd_run_uninit(ret);
+
+	return ret;
 }
-- 
1.7.8


  reply	other threads:[~2011-12-19 13:58 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-19 13:58 [RFC 00/12] Overhaul of error handling and module init/uninit Sasha Levin
2011-12-19 13:58 ` Sasha Levin [this message]
2011-12-19 21:26   ` [RFC 01/12] kvm tools: Split kvm_cmd_run into init, work and uninit Pekka Enberg
2011-12-20 10:09     ` Sasha Levin
2011-12-20  8:55       ` Asias He
2011-12-19 13:58 ` [RFC 02/12] kvm tools: Fixes for symbol resolving module Sasha Levin
2011-12-19 13:58 ` [RFC 03/12] kvm tools: Fixes for IRQ module Sasha Levin
2011-12-19 13:58 ` [RFC 04/12] kvm tools: Fixes for UI modules Sasha Levin
2011-12-19 13:58 ` [RFC 05/12] kvm tools: Fixes for ioport module Sasha Levin
2011-12-19 13:58 ` [RFC 06/12] kvm tools: Fixes for ioeventfd module Sasha Levin
2011-12-19 13:58 ` [RFC 07/12] kvm tools: Fixes for serial module Sasha Levin
2011-12-19 13:58 ` [RFC 08/12] kvm tools: Fixes for mptable module Sasha Levin
2011-12-19 13:58 ` [RFC 09/12] kvm tools: Fixes for ioeventfd module Sasha Levin
2011-12-19 13:58 ` [RFC 10/12] kvm tools: Fixes for disk image module Sasha Levin
2011-12-19 13:58 ` [RFC 11/12] kvm tools: Fixes for rtc module Sasha Levin
2011-12-19 13:58 ` [RFC 12/12] kvm tools: Fixes for ioeventfd module Sasha Levin
2011-12-19 21:29 ` [RFC 00/12] Overhaul of error handling and module init/uninit Pekka Enberg

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=1324303114-5948-2-git-send-email-levinsasha928@gmail.com \
    --to=levinsasha928@gmail.com \
    --cc=asias.hejun@gmail.com \
    --cc=gorcunov@gmail.com \
    --cc=kvm@vger.kernel.org \
    --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 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.