Exemplo n.º 1
0
void visit_type_MigrationInfo(Visitor *m, MigrationInfo ** obj, const char *name, Error **errp)
{
    visit_start_struct(m, (void **)obj, "MigrationInfo", name, sizeof(MigrationInfo), errp);
    visit_start_optional(m, (obj && *obj) ? &(*obj)->has_status : NULL, "status", errp);
    if ((*obj)->has_status) {
        visit_type_str(m, (obj && *obj) ? &(*obj)->status : NULL, "status", errp);
    }
    visit_end_optional(m, errp);
    visit_start_optional(m, (obj && *obj) ? &(*obj)->has_ram : NULL, "ram", errp);
    if ((*obj)->has_ram) {
        visit_type_MigrationStats(m, (obj && *obj) ? &(*obj)->ram : NULL, "ram", errp);
    }
    visit_end_optional(m, errp);
    visit_start_optional(m, (obj && *obj) ? &(*obj)->has_disk : NULL, "disk", errp);
    if ((*obj)->has_disk) {
        visit_type_MigrationStats(m, (obj && *obj) ? &(*obj)->disk : NULL, "disk", errp);
    }
    visit_end_optional(m, errp);
    visit_end_struct(m, errp);
}
Exemplo n.º 2
0
static void visit_type_TestStruct(Visitor *v, TestStruct **obj,
                                  const char *name, Error **errp)
{
    Error *err = NULL;
    if (!error_is_set(errp)) {
        visit_start_struct(v, (void **)obj, "TestStruct", name, sizeof(TestStruct),
                           &err);
        if (!err) {
            visit_type_int(v, &(*obj)->integer, "integer", &err);
            visit_type_bool(v, &(*obj)->boolean, "boolean", &err);
            visit_type_str(v, &(*obj)->string, "string", &err);

            /* Always call end_struct if start_struct succeeded.  */
            error_propagate(errp, err);
            err = NULL;
            visit_end_struct(v, &err);
        }
        error_propagate(errp, err);
    }
}
Exemplo n.º 3
0
void visit_type_BalloonInfo(Visitor *m, BalloonInfo ** obj, const char *name, Error **errp)
{
    visit_start_struct(m, (void **)obj, "BalloonInfo", name, sizeof(BalloonInfo), errp);
    visit_type_int(m, (obj && *obj) ? &(*obj)->actual : NULL, "actual", errp);
    visit_start_optional(m, (obj && *obj) ? &(*obj)->has_mem_swapped_in : NULL, "mem_swapped_in", errp);
    if ((*obj)->has_mem_swapped_in) {
        visit_type_int(m, (obj && *obj) ? &(*obj)->mem_swapped_in : NULL, "mem_swapped_in", errp);
    }
    visit_end_optional(m, errp);
    visit_start_optional(m, (obj && *obj) ? &(*obj)->has_mem_swapped_out : NULL, "mem_swapped_out", errp);
    if ((*obj)->has_mem_swapped_out) {
        visit_type_int(m, (obj && *obj) ? &(*obj)->mem_swapped_out : NULL, "mem_swapped_out", errp);
    }
    visit_end_optional(m, errp);
    visit_start_optional(m, (obj && *obj) ? &(*obj)->has_major_page_faults : NULL, "major_page_faults", errp);
    if ((*obj)->has_major_page_faults) {
        visit_type_int(m, (obj && *obj) ? &(*obj)->major_page_faults : NULL, "major_page_faults", errp);
    }
    visit_end_optional(m, errp);
    visit_start_optional(m, (obj && *obj) ? &(*obj)->has_minor_page_faults : NULL, "minor_page_faults", errp);
    if ((*obj)->has_minor_page_faults) {
        visit_type_int(m, (obj && *obj) ? &(*obj)->minor_page_faults : NULL, "minor_page_faults", errp);
    }
    visit_end_optional(m, errp);
    visit_start_optional(m, (obj && *obj) ? &(*obj)->has_free_mem : NULL, "free_mem", errp);
    if ((*obj)->has_free_mem) {
        visit_type_int(m, (obj && *obj) ? &(*obj)->free_mem : NULL, "free_mem", errp);
    }
    visit_end_optional(m, errp);
    visit_start_optional(m, (obj && *obj) ? &(*obj)->has_total_mem : NULL, "total_mem", errp);
    if ((*obj)->has_total_mem) {
        visit_type_int(m, (obj && *obj) ? &(*obj)->total_mem : NULL, "total_mem", errp);
    }
    visit_end_optional(m, errp);
    visit_end_struct(m, errp);
}
Exemplo n.º 4
0
void visit_type_SpiceInfo(Visitor *m, SpiceInfo ** obj, const char *name, Error **errp)
{
    visit_start_struct(m, (void **)obj, "SpiceInfo", name, sizeof(SpiceInfo), errp);
    visit_type_bool(m, (obj && *obj) ? &(*obj)->enabled : NULL, "enabled", errp);
    visit_start_optional(m, (obj && *obj) ? &(*obj)->has_host : NULL, "host", errp);
    if ((*obj)->has_host) {
        visit_type_str(m, (obj && *obj) ? &(*obj)->host : NULL, "host", errp);
    }
    visit_end_optional(m, errp);
    visit_start_optional(m, (obj && *obj) ? &(*obj)->has_port : NULL, "port", errp);
    if ((*obj)->has_port) {
        visit_type_int(m, (obj && *obj) ? &(*obj)->port : NULL, "port", errp);
    }
    visit_end_optional(m, errp);
    visit_start_optional(m, (obj && *obj) ? &(*obj)->has_tls_port : NULL, "tls-port", errp);
    if ((*obj)->has_tls_port) {
        visit_type_int(m, (obj && *obj) ? &(*obj)->tls_port : NULL, "tls-port", errp);
    }
    visit_end_optional(m, errp);
    visit_start_optional(m, (obj && *obj) ? &(*obj)->has_auth : NULL, "auth", errp);
    if ((*obj)->has_auth) {
        visit_type_str(m, (obj && *obj) ? &(*obj)->auth : NULL, "auth", errp);
    }
    visit_end_optional(m, errp);
    visit_start_optional(m, (obj && *obj) ? &(*obj)->has_compiled_version : NULL, "compiled-version", errp);
    if ((*obj)->has_compiled_version) {
        visit_type_str(m, (obj && *obj) ? &(*obj)->compiled_version : NULL, "compiled-version", errp);
    }
    visit_end_optional(m, errp);
    visit_start_optional(m, (obj && *obj) ? &(*obj)->has_channels : NULL, "channels", errp);
    if ((*obj)->has_channels) {
        visit_type_SpiceChannelList(m, (obj && *obj) ? &(*obj)->channels : NULL, "channels", errp);
    }
    visit_end_optional(m, errp);
    visit_end_struct(m, errp);
}
Exemplo n.º 5
0
void visit_type_BlockInfo(Visitor *m, BlockInfo ** obj, const char *name, Error **errp)
{
    visit_start_struct(m, (void **)obj, "BlockInfo", name, sizeof(BlockInfo), errp);
    visit_type_str(m, (obj && *obj) ? &(*obj)->device : NULL, "device", errp);
    visit_type_str(m, (obj && *obj) ? &(*obj)->type : NULL, "type", errp);
    visit_type_bool(m, (obj && *obj) ? &(*obj)->removable : NULL, "removable", errp);
    visit_type_bool(m, (obj && *obj) ? &(*obj)->locked : NULL, "locked", errp);
    visit_start_optional(m, (obj && *obj) ? &(*obj)->has_inserted : NULL, "inserted", errp);
    if ((*obj)->has_inserted) {
        visit_type_BlockDeviceInfo(m, (obj && *obj) ? &(*obj)->inserted : NULL, "inserted", errp);
    }
    visit_end_optional(m, errp);
    visit_start_optional(m, (obj && *obj) ? &(*obj)->has_tray_open : NULL, "tray_open", errp);
    if ((*obj)->has_tray_open) {
        visit_type_bool(m, (obj && *obj) ? &(*obj)->tray_open : NULL, "tray_open", errp);
    }
    visit_end_optional(m, errp);
    visit_start_optional(m, (obj && *obj) ? &(*obj)->has_io_status : NULL, "io-status", errp);
    if ((*obj)->has_io_status) {
        visit_type_BlockDeviceIoStatus(m, (obj && *obj) ? &(*obj)->io_status : NULL, "io-status", errp);
    }
    visit_end_optional(m, errp);
    visit_end_struct(m, errp);
}
Exemplo n.º 6
0
Object *user_creatable_add_type(const char *type, const char *id,
                                const QDict *qdict,
                                Visitor *v, Error **errp)
{
    Object *obj;
    ObjectClass *klass;
    const QDictEntry *e;
    Error *local_err = NULL;

    klass = object_class_by_name(type);
    if (!klass) {
        error_setg(errp, "invalid object type: %s", type);
        return NULL;
    }

    if (!object_class_dynamic_cast(klass, TYPE_USER_CREATABLE)) {
        error_setg(errp, "object type '%s' isn't supported by object-add",
                   type);
        return NULL;
    }

    if (object_class_is_abstract(klass)) {
        error_setg(errp, "object type '%s' is abstract", type);
        return NULL;
    }

    assert(qdict);
    obj = object_new(type);
    visit_start_struct(v, NULL, NULL, 0, &local_err);
    if (local_err) {
        goto out;
    }
    for (e = qdict_first(qdict); e; e = qdict_next(qdict, e)) {
        object_property_set(obj, v, e->key, &local_err);
        if (local_err) {
            break;
        }
    }
    if (!local_err) {
        visit_check_struct(v, &local_err);
    }
    visit_end_struct(v, NULL);
    if (local_err) {
        goto out;
    }

    if (id != NULL) {
        object_property_add_child(object_get_objects_root(),
                                  id, obj, &local_err);
        if (local_err) {
            goto out;
        }
    }

    user_creatable_complete(USER_CREATABLE(obj), &local_err);
    if (local_err) {
        if (id != NULL) {
            object_property_del(object_get_objects_root(),
                                id, &error_abort);
        }
        goto out;
    }
out:
    if (local_err) {
        error_propagate(errp, local_err);
        object_unref(obj);
        return NULL;
    }
    return obj;
}
Exemplo n.º 7
0
void visit_type_CommandInfo(Visitor *m, CommandInfo ** obj, const char *name, Error **errp)
{
    visit_start_struct(m, (void **)obj, "CommandInfo", name, sizeof(CommandInfo), errp);
    visit_type_str(m, (obj && *obj) ? &(*obj)->name : NULL, "name", errp);
    visit_end_struct(m, errp);
}
Exemplo n.º 8
0
void visit_type_UuidInfo(Visitor *m, UuidInfo ** obj, const char *name, Error **errp)
{
    visit_start_struct(m, (void **)obj, "UuidInfo", name, sizeof(UuidInfo), errp);
    visit_type_str(m, (obj && *obj) ? &(*obj)->UUID : NULL, "UUID", errp);
    visit_end_struct(m, errp);
}
Exemplo n.º 9
0
static void cpu_model_from_info(S390CPUModel *model, const CpuModelInfo *info,
                                Error **errp)
{
    const QDict *qdict = NULL;
    const QDictEntry *e;
    Visitor *visitor;
    ObjectClass *oc;
    S390CPU *cpu;
    Object *obj;

    if (info->props) {
        qdict = qobject_to_qdict(info->props);
        if (!qdict) {
            error_setg(errp, QERR_INVALID_PARAMETER_TYPE, "props", "dict");
            return;
        }
    }

    oc = cpu_class_by_name(TYPE_S390_CPU, info->name);
    if (!oc) {
        error_setg(errp, "The CPU definition \'%s\' is unknown.", info->name);
        return;
    }
    if (S390_CPU_CLASS(oc)->kvm_required && !kvm_enabled()) {
        error_setg(errp, "The CPU definition '%s' requires KVM", info->name);
        return;
    }
    obj = object_new(object_class_get_name(oc));
    cpu = S390_CPU(obj);

    if (!cpu->model) {
        error_setg(errp, "Details about the host CPU model are not available, "
                         "it cannot be used.");
        object_unref(obj);
        return;
    }

    if (qdict) {
        visitor = qobject_input_visitor_new(info->props);
        visit_start_struct(visitor, NULL, NULL, 0, errp);
        if (*errp) {
            object_unref(obj);
            return;
        }
        for (e = qdict_first(qdict); e; e = qdict_next(qdict, e)) {
            object_property_set(obj, visitor, e->key, errp);
            if (*errp) {
                break;
            }
        }
        if (!*errp) {
            visit_check_struct(visitor, errp);
        }
        visit_end_struct(visitor, NULL);
        visit_free(visitor);
        if (*errp) {
            object_unref(obj);
            return;
        }
    }

    /* copy the model and throw the cpu away */
    memcpy(model, cpu->model, sizeof(*model));
    object_unref(obj);
}
Exemplo n.º 10
0
static void prop_get_fdt(Object *obj, Visitor *v, void *opaque,
                        const char *name, Error **errp)
{
    sPAPRDRConnector *drc = SPAPR_DR_CONNECTOR(obj);
    Error *err = NULL;
    int fdt_offset_next, fdt_offset, fdt_depth;
    void *fdt;

    if (!drc->fdt) {
        visit_start_struct(v, NULL, NULL, name, 0, &err);
        if (!err) {
            visit_end_struct(v, &err);
        }
        error_propagate(errp, err);
        return;
    }

    fdt = drc->fdt;
    fdt_offset = drc->fdt_start_offset;
    fdt_depth = 0;

    do {
        const char *name = NULL;
        const struct fdt_property *prop = NULL;
        int prop_len = 0, name_len = 0;
        uint32_t tag;

        tag = fdt_next_tag(fdt, fdt_offset, &fdt_offset_next);
        switch (tag) {
        case FDT_BEGIN_NODE:
            fdt_depth++;
            name = fdt_get_name(fdt, fdt_offset, &name_len);
            visit_start_struct(v, NULL, NULL, name, 0, &err);
            if (err) {
                error_propagate(errp, err);
                return;
            }
            break;
        case FDT_END_NODE:
            /* shouldn't ever see an FDT_END_NODE before FDT_BEGIN_NODE */
            g_assert(fdt_depth > 0);
            visit_end_struct(v, &err);
            if (err) {
                error_propagate(errp, err);
                return;
            }
            fdt_depth--;
            break;
        case FDT_PROP: {
            int i;
            prop = fdt_get_property_by_offset(fdt, fdt_offset, &prop_len);
            name = fdt_string(fdt, fdt32_to_cpu(prop->nameoff));
            visit_start_list(v, name, &err);
            if (err) {
                error_propagate(errp, err);
                return;
            }
            for (i = 0; i < prop_len; i++) {
                visit_type_uint8(v, (uint8_t *)&prop->data[i], NULL, &err);
                if (err) {
                    error_propagate(errp, err);
                    return;
                }
            }
            visit_end_list(v, &err);
            if (err) {
                error_propagate(errp, err);
                return;
            }
            break;
        }
        default:
            error_setg(&error_abort, "device FDT in unexpected state: %d", tag);
        }
        fdt_offset = fdt_offset_next;
    } while (fdt_depth != 0);
}