From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44037) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XcBgD-0000z8-MT for qemu-devel@nongnu.org; Thu, 09 Oct 2014 07:14:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XcBg8-0003CW-7m for qemu-devel@nongnu.org; Thu, 09 Oct 2014 07:14:45 -0400 Received: from mail-qg0-x231.google.com ([2607:f8b0:400d:c04::231]:59660) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XcBg8-0003CH-1e for qemu-devel@nongnu.org; Thu, 09 Oct 2014 07:14:40 -0400 Received: by mail-qg0-f49.google.com with SMTP id a108so1417111qge.36 for ; Thu, 09 Oct 2014 04:14:39 -0700 (PDT) Sender: Paolo Bonzini Message-ID: <54366E17.7060505@redhat.com> Date: Thu, 09 Oct 2014 13:14:31 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1412668838-8656-1-git-send-email-arei.gonglei@huawei.com> <1412668838-8656-8-git-send-email-arei.gonglei@huawei.com> In-Reply-To: <1412668838-8656-8-git-send-email-arei.gonglei@huawei.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v11 07/34] bootindex: add a setter/getter functions wrapper for bootindex property List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: arei.gonglei@huawei.com, qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, weidong.huang@huawei.com, mst@redhat.com, aik@ozlabs.ru, agraf@suse.de, kraxel@redhat.com, dmitry@daynix.com, akong@redhat.com, armbru@redhat.com, lersek@redhat.com, ehabkost@redhat.com, marcel.a@redhat.com, somlo@cmu.edu, luonengjun@huawei.com, peter.huangpeng@huawei.com, alex.williamson@redhat.com, stefanha@redhat.com, lcapitulino@redhat.com, rth@twiddle.net, kwolf@redhat.com, peter.crosthwaite@xilinx.com, chenliang88@huawei.com, imammedo@redhat.com, afaerber@suse.de Il 07/10/2014 10:00, arei.gonglei@huawei.com ha scritto: > From: Gonglei > > when we remove bootindex form qdev.property to qom.property, > we can use those functions set/get bootindex property for all > correlative devices. Meanwhile set the initial value of > bootindex to -1. > > Signed-off-by: Gonglei > Reviewed-by: Gerd Hoffmann > --- > bootdevice.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++ > include/sysemu/sysemu.h | 3 ++ > 2 files changed, 76 insertions(+) > > diff --git a/bootdevice.c b/bootdevice.c > index a38479a..69cffd8 100644 > --- a/bootdevice.c > +++ b/bootdevice.c > @@ -23,6 +23,7 @@ > */ > > #include "sysemu/sysemu.h" > +#include "qapi/visitor.h" > > typedef struct FWBootEntry FWBootEntry; > > @@ -178,3 +179,75 @@ char *get_boot_devices_list(size_t *size, bool ignore_suffixes) > } > return list; > } > + > +typedef struct { > + int32_t *bootindex; > + const char *suffix; > + DeviceState *dev; > +} BootIndexProperty; > + > +static void device_get_bootindex(Object *obj, Visitor *v, void *opaque, > + const char *name, Error **errp) > +{ > + BootIndexProperty *prop = opaque; > + visit_type_int32(v, prop->bootindex, name, errp); > +} > + > +static void device_set_bootindex(Object *obj, Visitor *v, void *opaque, > + const char *name, Error **errp) > +{ > + BootIndexProperty *prop = opaque; > + int32_t boot_index; > + Error *local_err = NULL; > + > + visit_type_int32(v, &boot_index, name, &local_err); > + if (local_err) { > + goto out; > + } > + /* check whether bootindex is present in fw_boot_order list */ > + check_boot_index(boot_index, &local_err); > + if (local_err) { > + goto out; > + } > + /* change bootindex to a new one */ > + *prop->bootindex = boot_index; > + > +out: > + if (local_err) { > + error_propagate(errp, local_err); > + } > +} > + > +static void property_release_bootindex(Object *obj, const char *name, > + void *opaque) > + > +{ > + BootIndexProperty *prop = opaque; > + g_free(prop); > +} > + > +void device_add_bootindex_property(Object *obj, int32_t *bootindex, > + const char *name, const char *suffix, > + DeviceState *dev, Error **errp) > +{ > + Error *local_err = NULL; > + BootIndexProperty *prop = g_malloc0(sizeof(*prop)); > + > + prop->bootindex = bootindex; > + prop->suffix = suffix; > + prop->dev = dev; > + > + object_property_add(obj, name, "int32", > + device_get_bootindex, > + device_set_bootindex, > + property_release_bootindex, > + prop, &local_err); > + > + if (local_err) { > + error_propagate(errp, local_err); > + g_free(prop); > + return; > + } > + /* initialize devices' bootindex property to -1 */ > + object_property_set_int(obj, -1, name, NULL); > +} > diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h > index b3489be..0037a69 100644 > --- a/include/sysemu/sysemu.h > +++ b/include/sysemu/sysemu.h > @@ -215,6 +215,9 @@ char *get_boot_devices_list(size_t *size, bool ignore_suffixes); > DeviceState *get_boot_device(uint32_t position); > void check_boot_index(int32_t bootindex, Error **errp); > void del_boot_device_path(DeviceState *dev, const char *suffix); > +void device_add_bootindex_property(Object *obj, int32_t *bootindex, > + const char *name, const char *suffix, > + DeviceState *dev, Error **errp); > > QemuOpts *qemu_get_machine_opts(void); > > Acked-by: Paolo Bonzini