From nobody Tue Feb 10 15:46:00 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487258152458225.32100647185484; Thu, 16 Feb 2017 07:15:52 -0800 (PST) Received: from localhost ([::1]:47266 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceNmg-0004Qo-52 for importer@patchew.org; Thu, 16 Feb 2017 10:15:50 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51814) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceN6X-0003iG-LK for qemu-devel@nongnu.org; Thu, 16 Feb 2017 09:32:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ceN6V-00085L-5L for qemu-devel@nongnu.org; Thu, 16 Feb 2017 09:32:17 -0500 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]:32861) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ceN6U-00084l-VQ for qemu-devel@nongnu.org; Thu, 16 Feb 2017 09:32:15 -0500 Received: by mail-wr0-x242.google.com with SMTP id i10so2281066wrb.0 for ; Thu, 16 Feb 2017 06:32:14 -0800 (PST) Received: from 640k.lan (94-39-187-56.adsl-ull.clienti.tiscali.it. [94.39.187.56]) by smtp.gmail.com with ESMTPSA id g5sm9203365wrd.0.2017.02.16.06.32.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Feb 2017 06:32:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=CRNfbxLiiO7kW0F/rJMb1DkAER13sK3/rf7HPkFOWpQ=; b=mPQeMwIstnRyfd7934upO/ZGZjKWkXXP6tZFW7gY232g4JogX/kITa2rEvX4GF7lS0 H1z5KOGcD6eXE2cAXs2bUHmGCQ5XHxPhFDeFyMlIActV2lw2Wf9TK0c05WVE0JOxLlNk Ni64cbdK/7slSzWmcNGEDq1zK/G0LF0ILGVXAoCljV1cccGxYkRgnn9iKBeqMoohvBwu 6Y98SiKU+KPO6x9BQs1d0BHZP5RcQHRE6sL756R5YdVbjwCJPVtJ2Yw+1w5Z+PbvGebQ ym2cSwdysX2fiAmKvGNOePhmSKf9QpYu3vMh5Vb04FoaVfgre9jtVWCsarJCXAm9ZrQz 6OMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=CRNfbxLiiO7kW0F/rJMb1DkAER13sK3/rf7HPkFOWpQ=; b=TrrtOa8dDrkvvH+GL6Hv6OQrDausqMqPhe1nZ4CP5nuz0U3xJBu0j6Tf5ZsWgdZJOB OeHz43BHE8X4Ay3o8o5YHFQaCePMZmpiTYJXzeKA5nDbZkNaYpFrork/uctqIqZhEOmg Kc1xLaaV+wqV9IfgNjJTLrWjoXQQrT1QJDqEwuVIbTQKMHWD1w7Dw8ENxT5l4+w0/hzp RrUGmqSwesIQ7FnSbxms0s3YjRFHpEI5d2HE6/s6OyEVjCbJ+9I79B1vQAc1mKiqTJCY B5bjP/ENx52K9DN3y+/ILxoEImhn/KEp6LExPTV8Rp3CR+nAZBRQX8Uw3AhrC46T4rSG SHbA== X-Gm-Message-State: AMke39n7KciRWPMi6djMUJHhpeentYDuxiqs9N7ivMHqXHVHNeAJlBLaCM7CuAJp6ImQeQ== X-Received: by 10.223.136.50 with SMTP id d47mr2934473wrd.167.1487255533773; Thu, 16 Feb 2017 06:32:13 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 16 Feb 2017 15:31:32 +0100 Message-Id: <1487255507-106654-9-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1487255507-106654-1-git-send-email-pbonzini@redhat.com> References: <1487255507-106654-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c0c::242 Subject: [Qemu-devel] [PULL 08/23] move vm_start to cpus.c X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Claudio Imbrenda Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Claudio Imbrenda This patch: * moves vm_start to cpus.c. * exports qemu_vmstop_requested, since it's needed by vm_start. * extracts vm_prepare_start from vm_start; it does what vm_start did, except restarting the cpus. * vm_start now calls vm_prepare_start and then restarts the cpus. Signed-off-by: Claudio Imbrenda Message-Id: <1487092068-16562-2-git-send-email-imbrenda@linux.vnet.ibm.com> Signed-off-by: Paolo Bonzini --- cpus.c | 42 ++++++++++++++++++++++++++++++++++++++++++ include/sysemu/sysemu.h | 2 ++ vl.c | 30 +----------------------------- 3 files changed, 45 insertions(+), 29 deletions(-) diff --git a/cpus.c b/cpus.c index 71a82e5..0bcb5b5 100644 --- a/cpus.c +++ b/cpus.c @@ -1578,6 +1578,48 @@ int vm_stop(RunState state) return do_vm_stop(state); } =20 +/** + * Prepare for (re)starting the VM. + * Returns -1 if the vCPUs are not to be restarted (e.g. if they are alrea= dy + * running or in case of an error condition), 0 otherwise. + */ +int vm_prepare_start(void) +{ + RunState requested; + int res =3D 0; + + qemu_vmstop_requested(&requested); + if (runstate_is_running() && requested =3D=3D RUN_STATE__MAX) { + return -1; + } + + /* Ensure that a STOP/RESUME pair of events is emitted if a + * vmstop request was pending. The BLOCK_IO_ERROR event, for + * example, according to documentation is always followed by + * the STOP event. + */ + if (runstate_is_running()) { + qapi_event_send_stop(&error_abort); + res =3D -1; + } else { + replay_enable_events(); + cpu_enable_ticks(); + runstate_set(RUN_STATE_RUNNING); + vm_state_notify(1, RUN_STATE_RUNNING); + } + + /* We are sending this now, but the CPUs will be resumed shortly later= */ + qapi_event_send_resume(&error_abort); + return res; +} + +void vm_start(void) +{ + if (!vm_prepare_start()) { + resume_all_vcpus(); + } +} + /* does a state transition even if the VM is already stopped, current state is forgotten forever */ int vm_stop_force_state(RunState state) diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 4d50694..eda5241 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -37,6 +37,7 @@ void vm_state_notify(int running, RunState state); #define VMRESET_REPORT true =20 void vm_start(void); +int vm_prepare_start(void); int vm_stop(RunState state); int vm_stop_force_state(RunState state); =20 @@ -60,6 +61,7 @@ void qemu_register_powerdown_notifier(Notifier *notifier); void qemu_system_debug_request(void); void qemu_system_vmstop_request(RunState reason); void qemu_system_vmstop_request_prepare(void); +bool qemu_vmstop_requested(RunState *r); int qemu_shutdown_requested_get(void); int qemu_reset_requested_get(void); void qemu_system_killed(int signal, pid_t pid); diff --git a/vl.c b/vl.c index b4eaf03..0d866ad 100644 --- a/vl.c +++ b/vl.c @@ -724,7 +724,7 @@ StatusInfo *qmp_query_status(Error **errp) return info; } =20 -static bool qemu_vmstop_requested(RunState *r) +bool qemu_vmstop_requested(RunState *r) { qemu_mutex_lock(&vmstop_lock); *r =3D vmstop_requested; @@ -745,34 +745,6 @@ void qemu_system_vmstop_request(RunState state) qemu_notify_event(); } =20 -void vm_start(void) -{ - RunState requested; - - qemu_vmstop_requested(&requested); - if (runstate_is_running() && requested =3D=3D RUN_STATE__MAX) { - return; - } - - /* Ensure that a STOP/RESUME pair of events is emitted if a - * vmstop request was pending. The BLOCK_IO_ERROR event, for - * example, according to documentation is always followed by - * the STOP event. - */ - if (runstate_is_running()) { - qapi_event_send_stop(&error_abort); - } else { - replay_enable_events(); - cpu_enable_ticks(); - runstate_set(RUN_STATE_RUNNING); - vm_state_notify(1, RUN_STATE_RUNNING); - resume_all_vcpus(); - } - - qapi_event_send_resume(&error_abort); -} - - /***********************************************************/ /* real time host monotonic timer */ =20 --=20 1.8.3.1