From patchwork Thu Feb 4 11:49:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Mammedov X-Patchwork-Id: 8220411 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 4F177BEEED for ; Thu, 4 Feb 2016 11:53:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A6CD220221 for ; Thu, 4 Feb 2016 11:53:58 +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 EA33920306 for ; Thu, 4 Feb 2016 11:53:57 +0000 (UTC) Received: from localhost ([::1]:41095 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRIU1-0000Tq-F6 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 04 Feb 2016 06:53:57 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49978) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRIPX-0002Yc-GU for qemu-devel@nongnu.org; Thu, 04 Feb 2016 06:49:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aRIPT-0000YV-Fq for qemu-devel@nongnu.org; Thu, 04 Feb 2016 06:49:19 -0500 Received: from mx1.redhat.com ([209.132.183.28]:65285) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRIPT-0000YP-9v for qemu-devel@nongnu.org; Thu, 04 Feb 2016 06:49:15 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id CD14E7AE9A; Thu, 4 Feb 2016 11:49:14 +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-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u14BnDrq003446; Thu, 4 Feb 2016 06:49:13 -0500 From: Igor Mammedov To: qemu-devel@nongnu.org Date: Thu, 4 Feb 2016 12:49:12 +0100 Message-Id: <1454586552-10251-1-git-send-email-imammedo@redhat.com> In-Reply-To: <1454586455-10202-1-git-send-email-imammedo@redhat.com> References: <1454586455-10202-1-git-send-email-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: pbonzini@redhat.com, ehabkost@redhat.com, afaerber@suse.de, mst@redhat.com Subject: [Qemu-devel] [PATCH 1/9] 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 942ac06..d72246d 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 8f537a4..e66989b 100644 --- a/qom/cpu.c +++ b/qom/cpu.c @@ -26,7 +26,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; @@ -34,10 +34,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; }