Skip to content

Commit

Permalink
bootindex: add a setter/getter functions wrapper for bootindex property
Browse files Browse the repository at this point in the history
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 <arei.gonglei@huawei.com>
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
  • Loading branch information
gongleiarei authored and kraxel committed Oct 15, 2014
1 parent a598f2f commit 12da309
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
73 changes: 73 additions & 0 deletions bootdevice.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/

#include "sysemu/sysemu.h"
#include "qapi/visitor.h"

typedef struct FWBootEntry FWBootEntry;

Expand Down Expand Up @@ -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);
}
3 changes: 3 additions & 0 deletions include/sysemu/sysemu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 12da309

Please sign in to comment.