From patchwork Fri Feb 5 18:06:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Mammedov X-Patchwork-Id: 8237831 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 94F3C9F4DD for ; Fri, 5 Feb 2016 18:07:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E693F20397 for ; Fri, 5 Feb 2016 18:07:27 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3070020392 for ; Fri, 5 Feb 2016 18:07:27 +0000 (UTC) Received: from localhost ([::1]:49767 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRkn0-0007hF-2y for patchwork-qemu-devel@patchwork.kernel.org; Fri, 05 Feb 2016 13:07:26 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37947) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRkmo-0007gb-2U for qemu-devel@nongnu.org; Fri, 05 Feb 2016 13:07:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aRkmk-0008Fb-Vw for qemu-devel@nongnu.org; Fri, 05 Feb 2016 13:07:13 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55805) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRkmk-0008FW-QQ for qemu-devel@nongnu.org; Fri, 05 Feb 2016 13:07:10 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 765B4C60E8; Fri, 5 Feb 2016 18:07:10 +0000 (UTC) Received: from dell-r430-03.lab.eng.brq.redhat.com (dell-r430-03.lab.eng.brq.redhat.com [10.34.112.60]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u15I762M026672; Fri, 5 Feb 2016 13:07:09 -0500 From: Igor Mammedov To: qemu-devel@nongnu.org Date: Fri, 5 Feb 2016 19:06:57 +0100 Message-Id: <1454695626-70225-2-git-send-email-imammedo@redhat.com> In-Reply-To: <1454695626-70225-1-git-send-email-imammedo@redhat.com> References: <1454695626-70225-1-git-send-email-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: pbonzini@redhat.com, marcel.apfelbaum@gmail.com, ehabkost@redhat.com, afaerber@suse.de, mst@redhat.com Subject: [Qemu-devel] [PATCH v2 01/10] cpu: rename cpu_exists() to qemu_get_cpu_by_arch_id() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP cpu_exists() already does CPU lookup but discards found CPU and returns boolean instead. Make it more useful by returning a found CPU and also rename it more descriptive name. Signed-off-by: Igor Mammedov Reviewed-by: Eduardo Habkost --- hw/i386/pc.c | 2 +- include/qom/cpu.h | 10 +++++----- qom/cpu.c | 6 +++--- target-i386/cpu.c | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index fd8524f..9227bde 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1088,7 +1088,7 @@ void pc_hot_add_cpu(const int64_t id, Error **errp) return; } - if (cpu_exists(apic_id)) { + if (qemu_get_cpu_by_arch_id(apic_id)) { error_setg(errp, "Unable to add CPU: %" PRIi64 ", it already exists", id); return; diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 035179c..bd26bf5 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -622,14 +622,14 @@ void async_run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data); CPUState *qemu_get_cpu(int index); /** - * cpu_exists: - * @id: Guest-exposed CPU ID to lookup. + * qemu_get_cpu_by_arch_id: + * @id: Guest-exposed CPU ID to lookup returned by CPUState@get_arch_id() * - * Search for CPU with specified ID. + * Gets a CPU matching @id. * - * Returns: %true - CPU is found, %false - CPU isn't found. + * Returns: The CPU or %NULL if there is no matching CPU. */ -bool cpu_exists(int64_t id); +CPUState *qemu_get_cpu_by_arch_id(int id); /** * cpu_throttle_set: diff --git a/qom/cpu.c b/qom/cpu.c index 38dc713..2c4a4e3 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -27,7 +27,7 @@ #include "qemu/error-report.h" #include "sysemu/sysemu.h" -bool cpu_exists(int64_t id) +CPUState *qemu_get_cpu_by_arch_id(int id) { CPUState *cpu; @@ -35,10 +35,10 @@ bool cpu_exists(int64_t id) CPUClass *cc = CPU_GET_CLASS(cpu); if (cc->get_arch_id(cpu) == id) { - return true; + return cpu; } } - return false; + return NULL; } CPUState *cpu_generic_init(const char *typename, const char *cpu_model) diff --git a/target-i386/cpu.c b/target-i386/cpu.c index b255644..3918f01 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -1789,7 +1789,7 @@ static void x86_cpuid_set_apic_id(Object *obj, Visitor *v, void *opaque, return; } - if ((value != cpu->apic_id) && cpu_exists(value)) { + if ((value != cpu->apic_id) && qemu_get_cpu_by_arch_id(value)) { error_setg(errp, "CPU with APIC ID %" PRIi64 " exists", value); return; }