Received: from eggs.gnu.org ([2001:4830:134:3::10]:59968) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XRO88-0008HM-I2 for qemu-devel@nongnu.org; Tue, 09 Sep 2014 12:19:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XRO83-0002Zx-Mz for qemu-devel@nongnu.org; Tue, 09 Sep 2014 12:18:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34289) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XRO83-0002Zl-EU for qemu-devel@nongnu.org; Tue, 09 Sep 2014 12:18:51 -0400 Date: Tue, 9 Sep 2014 13:18:24 -0300 From: Eduardo Habkost Message-ID: <20140909161824.GP32084@thinpad.lan.raisama.net> References: <1409906256-11368-1-git-send-email-arei.gonglei@huawei.com> <1409906256-11368-25-git-send-email-arei.gonglei@huawei.com> <20140905183934.GM32084@thinpad.lan.raisama.net> <33183CC9F5247A488A2544077AF1902086DC838A@SZXEMA503-MBS.china.huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <33183CC9F5247A488A2544077AF1902086DC838A@SZXEMA503-MBS.china.huawei.com> Subject: Re: [Qemu-devel] [PATCH v7 24/28] ide: add bootindex to qom property List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Gonglei (Arei)" Cc: "chenliang (T)" , "Huangweidong (C)" , "mst@redhat.com" , "aik@ozlabs.ru" , "hutao@cn.fujitsu.com" , "qemu-devel@nongnu.org" , "agraf@suse.de" , "kraxel@redhat.com" , "akong@redhat.com" , Gonglei , "armbru@redhat.com" , "aliguori@amazon.com" , Luonengjun , "Huangpeng (Peter)" , "hani@linux.com" , "stefanha@redhat.com" , "pbonzini@redhat.com" , "lcapitulino@redhat.com" , "kwolf@redhat.com" , "peter.crosthwaite@xilinx.com" , "imammedo@redhat.com" , "afaerber@suse.de" On Tue, Sep 09, 2014 at 07:51:49AM +0000, Gonglei (Arei) wrote: > Hi, > > > Subject: RE: [Qemu-devel] [PATCH v7 24/28] ide: add bootindex to qom property > > > > > Subject: Re: [Qemu-devel] [PATCH v7 24/28] ide: add bootindex to qom > > property > > > > > > On Fri, Sep 05, 2014 at 04:37:32PM +0800, arei.gonglei@huawei.com wrote: > > > > From: Gonglei > > > > > > > > Add a qom property with the same name 'bootindex', > > > > when we remove it form qdev property, things will > > > > continue to work just fine, and we can use qom features > > > > which are not supported by qdev property. > > > > > > > > Signed-off-by: Gonglei > > > > --- > > > > hw/ide/qdev.c | 14 ++++++++++++++ > > > > 1 file changed, 14 insertions(+) > > > > > > > > diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c > > > > index efab95b..9e2ed40 100644 > > > > --- a/hw/ide/qdev.c > > > > +++ b/hw/ide/qdev.c > > > > @@ -191,6 +191,17 @@ static int ide_dev_initfn(IDEDevice *dev, > > > IDEDriveKind kind) > > > > return 0; > > > > } > > > > > > > > +static void ide_dev_instance_init(Object *obj) > > > > +{ > > > > + DeviceState *dev = DEVICE(obj); > > > > + IDEDevice *d = DO_UPCAST(IDEDevice, qdev, dev); > > > > + > > > > + device_add_bootindex_property(obj, &d->conf.bootindex, > > > > + "bootindex", > > > > + d->unit ? "/disk@1" : > > "/disk@0", > > > > + &d->qdev, NULL); > > > > +} > > > > + > Oops, I found a thorny issue that the d->unit parameter had not been initialized > in ide_dev_instance_init(). d->unit maybe is a random value, which will against > the original purpose in this situation. > > What's your opinion, Eduardo? Thanks! It looks like you can call add_boot_device_path() only on realize, on IDE. If IDE is the only case, we could just change IDE to not use device_add_bootindex_property(), having its own getter/setter and a call to add_boot_device_path() on realize(). Or, to keep the code generic, we could just make get_boot_devices_list() query the device for the suffix, instead of requiring the suffix to be set before device_add_bootindex_property() is called. With something like: typedef struct BootDeviceInfo { int bootindex; const char *suffix; } BootDeviceInfo; struct FWBootEntry { QTAILQ_ENTRY(FWBootEntry) link; DeviceState *dev; BootDeviceInfo *bootdev; }; void add_boot_device_path(DeviceState *dev, BootDeviceInfo *info); void del_boot_device_path(BootDeviceInfo *info); void device_add_bootindex_property(Object *obj, const char *property, DeviceState *dev, BootDeviceInfo *info, Error **errp); This way, the suffix can be set between device_add_bootindex_property() and get_boot_devices_list() if necessary: static void somedevice_instance_init(Object *obj) { SomeDevice *somedev = SOME_DEVICE(obj); device_add_bootindex_property(obj, DEVICE(obj), &somedev->bootinfo, &error_abort); } static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind) { [...] dev->bootinfo.suffix = dev->unit ? "/disk@1" : "/disk@0"; } -- Eduardo