From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45986) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGqym-0006hH-1X for qemu-devel@nongnu.org; Thu, 29 Jan 2015 10:26:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YGqyj-0006l6-7F for qemu-devel@nongnu.org; Thu, 29 Jan 2015 10:25:59 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52851) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGqyi-0006l0-Oe for qemu-devel@nongnu.org; Thu, 29 Jan 2015 10:25:57 -0500 Date: Thu, 29 Jan 2015 16:25:44 +0100 From: Igor Mammedov Message-ID: <20150129162544.2d718750@nial.brq.redhat.com> In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v3 7/7] i386/cpu: add instance finalize callback List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Zhu Guihua Cc: qemu-devel@nongnu.org, tangchen@cn.fujitsu.com, guz.fnst@cn.fujitsu.com, isimatu.yasuaki@jp.fujitsu.com, chen.fan.fnst@cn.fujitsu.com, anshul.makkar@profitbricks.com, afaerber@suse.de On Wed, 14 Jan 2015 15:27:30 +0800 Zhu Guihua wrote: > From: Gu Zheng > > Add a func to finalize a cpu's instance. When cpu's device_add failed, > and cpu's device_del executed, this func would be invoked. > > Signed-off-by: Gu Zheng > Signed-off-by: Zhu Guihua > --- > include/qom/cpu.h | 1 + > target-i386/cpu.c | 8 ++++++++ > 2 files changed, 9 insertions(+) > > diff --git a/include/qom/cpu.h b/include/qom/cpu.h > index 936afcd..f663199 100644 > --- a/include/qom/cpu.h > +++ b/include/qom/cpu.h > @@ -305,6 +305,7 @@ struct CPUState { > QTAILQ_HEAD(CPUTailQ, CPUState); > extern struct CPUTailQ cpus; > #define CPU_NEXT(cpu) QTAILQ_NEXT(cpu, node) > +#define CPU_REMOVE(cpu) QTAILQ_REMOVE(&cpus, cpu, node) > #define CPU_FOREACH(cpu) QTAILQ_FOREACH(cpu, &cpus, node) > #define CPU_FOREACH_SAFE(cpu, next_cpu) \ > QTAILQ_FOREACH_SAFE(cpu, &cpus, node, next_cpu) > diff --git a/target-i386/cpu.c b/target-i386/cpu.c > index 4347948..4746814 100644 > --- a/target-i386/cpu.c > +++ b/target-i386/cpu.c > @@ -2983,6 +2983,13 @@ static void x86_cpu_initfn(Object *obj) > } > } > > +static void x86_cpu_finalizefn(Object *obj) > +{ > + CPUState *cs = CPU(obj); > + > + CPU_REMOVE(cs); > +} issue with reliance on cpu_index is not solved completely, There is still a lot of places that use cpu_index and when we start ignore it in x86 CPU, the rest of the places probably would have a broken logic. Please look at that call sites, and if they are fine with it, especially common files shared with other targets. > + > static int64_t x86_cpu_get_arch_id(CPUState *cs) > { > X86CPU *cpu = X86_CPU(cs); > @@ -3095,6 +3102,7 @@ static const TypeInfo x86_cpu_type_info = { > .parent = TYPE_CPU, > .instance_size = sizeof(X86CPU), > .instance_init = x86_cpu_initfn, > + .instance_finalize = x86_cpu_finalizefn, > .abstract = true, > .class_size = sizeof(X86CPUClass), > .class_init = x86_cpu_common_class_init,