static void set_uint64(Object *obj, Visitor *v, void *opaque, const char *name, Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; uint64_t *ptr = qdev_get_prop_ptr(dev, prop); if (dev->realized) { error_set(errp, QERR_PERMISSION_DENIED); return; } visit_type_uint64(v, ptr, name, errp); }
static void set_enum(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; int *ptr = qdev_get_prop_ptr(dev, prop); if (dev->realized) { qdev_prop_set_after_realize(dev, name, errp); return; } visit_type_enum(v, prop->name, ptr, prop->info->enum_table, errp); }
static void get_string(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; char **ptr = qdev_get_prop_ptr(dev, prop); if (!*ptr) { char *str = (char *)""; visit_type_str(v, name, &str, errp); } else { visit_type_str(v, name, ptr, errp); } }
static void set_int32(Object *obj, Visitor *v, void *opaque, const char *name, Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; int32_t *ptr = qdev_get_prop_ptr(dev, prop); if (dev->state != DEV_STATE_CREATED) { error_set(errp, QERR_PERMISSION_DENIED); return; } visit_type_int32(v, ptr, name, errp); }
static void set_uint32(Object *obj, Visitor *v, void *opaque, const char *name, Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; uint32_t *ptr = qdev_get_prop_ptr(dev, prop); if (dev->realized) { qdev_prop_set_after_realize(dev, name, errp); return; } visit_type_uint32(v, ptr, name, errp); }
/* * accepted syntax versions: * 01:02:03:04:05:06 * 01-02-03-04-05-06 */ static void get_mac(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; MACAddr *mac = qdev_get_prop_ptr(dev, prop); char buffer[2 * 6 + 5 + 1]; char *p = buffer; snprintf(buffer, sizeof(buffer), "%02x:%02x:%02x:%02x:%02x:%02x", mac->a[0], mac->a[1], mac->a[2], mac->a[3], mac->a[4], mac->a[5]); visit_type_str(v, name, &p, errp); }
static void release_drive(Object *obj, const char *name, void *opaque) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; BlockBackend **ptr = qdev_get_prop_ptr(dev, prop); if (*ptr) { AioContext *ctx = blk_get_aio_context(*ptr); aio_context_acquire(ctx); blockdev_auto_del(*ptr); blk_detach_dev(*ptr, dev); aio_context_release(ctx); } }
/* * bus-local address, i.e. "$slot" or "$slot.$fn" */ static void set_pci_devfn(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; int32_t value, *ptr = qdev_get_prop_ptr(dev, prop); unsigned int slot, fn, n; Error *local_err = NULL; char *str; if (dev->realized) { qdev_prop_set_after_realize(dev, name, errp); return; } visit_type_str(v, name, &str, &local_err); if (local_err) { error_free(local_err); local_err = NULL; visit_type_int32(v, name, &value, &local_err); if (local_err) { error_propagate(errp, local_err); } else if (value < -1 || value > 255) { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : "null", "pci_devfn"); } else { *ptr = value; } return; } if (sscanf(str, "%x.%x%n", &slot, &fn, &n) != 2) { fn = 0; if (sscanf(str, "%x%n", &slot, &n) != 1) { goto invalid; } } if (str[n] != '\0' || fn > 7 || slot > 31) { goto invalid; } *ptr = slot << 3 | fn; g_free(str); return; invalid: error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str); g_free(str); }
static int parse_hex64(DeviceState *dev, Property *prop, const char *str) { uint64_t *ptr = qdev_get_prop_ptr(dev, prop); char *end; if (str[0] != '0' || str[1] != 'x') { return -EINVAL; } *ptr = strtoull(str, &end, 16); if ((*end != '\0') || (end == str)) { return -EINVAL; } return 0; }
static void set_mac(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; MACAddr *mac = qdev_get_prop_ptr(dev, prop); Error *local_err = NULL; int i, pos; char *str, *p; if (dev->realized) { qdev_prop_set_after_realize(dev, name, errp); return; } visit_type_str(v, name, &str, &local_err); if (local_err) { error_propagate(errp, local_err); return; } for (i = 0, pos = 0; i < 6; i++, pos += 3) { if (!qemu_isxdigit(str[pos])) { goto inval; } if (!qemu_isxdigit(str[pos+1])) { goto inval; } if (i == 5) { if (str[pos+2] != '\0') { goto inval; } } else { if (str[pos+2] != ':' && str[pos+2] != '-') { goto inval; } } mac->a[i] = strtol(str+pos, &p, 16); } g_free(str); return; inval: error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str); g_free(str); }
static void get_vlan(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; NetClientState **ptr = qdev_get_prop_ptr(dev, prop); int32_t id = -1; if (*ptr) { int hub_id; if (!net_hub_id_for_client(*ptr, &hub_id)) { id = hub_id; } } visit_type_int32(v, name, &id, errp); }
/* * bus-local address, i.e. "$slot" or "$slot.$fn" */ static int parse_pci_devfn(DeviceState *dev, Property *prop, const char *str) { uint32_t *ptr = qdev_get_prop_ptr(dev, prop); unsigned int slot, fn, n; if (sscanf(str, "%x.%x%n", &slot, &fn, &n) != 2) { fn = 0; if (sscanf(str, "%x%n", &slot, &n) != 1) { return -EINVAL; } } if (str[n] != '\0') return -EINVAL; if (fn > 7) return -EINVAL; if (slot > 31) return -EINVAL; *ptr = slot << 3 | fn; return 0; }
static void set_mac(Object *obj, Visitor *v, void *opaque, const char *name, Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; MACAddr *mac = qdev_get_prop_ptr(dev, prop); Error *local_err = NULL; int i, pos; char *str, *p; if (dev->state != DEV_STATE_CREATED) { error_set(errp, QERR_PERMISSION_DENIED); return; } visit_type_str(v, &str, name, &local_err); if (local_err) { error_propagate(errp, local_err); return; } for (i = 0, pos = 0; i < 6; i++, pos += 3) { if (!qemu_isxdigit(str[pos])) goto inval; if (!qemu_isxdigit(str[pos+1])) goto inval; if (i == 5) { if (str[pos+2] != '\0') goto inval; } else { if (str[pos+2] != ':' && str[pos+2] != '-') goto inval; } mac->a[i] = strtol(str+pos, &p, 16); } return; inval: error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str); }
static void set_string(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; char **ptr = qdev_get_prop_ptr(dev, prop); Error *local_err = NULL; char *str; if (dev->realized) { qdev_prop_set_after_realize(dev, name, errp); return; } visit_type_str(v, name, &str, &local_err); if (local_err) { error_propagate(errp, local_err); return; } g_free(*ptr); *ptr = str; }
/* * accepted syntax versions: * 01:02:03:04:05:06 * 01-02-03-04-05-06 */ static int parse_mac(DeviceState *dev, Property *prop, const char *str) { MACAddr *mac = qdev_get_prop_ptr(dev, prop); int i, pos; char *p; for (i = 0, pos = 0; i < 6; i++, pos += 3) { if (!qemu_isxdigit(str[pos])) return -EINVAL; if (!qemu_isxdigit(str[pos+1])) return -EINVAL; if (i == 5) { if (str[pos+2] != '\0') return -EINVAL; } else { if (str[pos+2] != ':' && str[pos+2] != '-') return -EINVAL; } mac->a[i] = strtol(str+pos, &p, 16); } return 0; }
static void set_vlan(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; NICPeers *peers_ptr = qdev_get_prop_ptr(dev, prop); NetClientState **ptr = &peers_ptr->ncs[0]; Error *local_err = NULL; int32_t id; NetClientState *hubport; if (dev->realized) { qdev_prop_set_after_realize(dev, name, errp); return; } visit_type_int32(v, name, &id, &local_err); if (local_err) { error_propagate(errp, local_err); return; } if (id == -1) { *ptr = NULL; return; } if (*ptr) { error_set_from_qdev_prop_error(errp, -EINVAL, dev, prop, name); return; } hubport = net_hub_port_find(id); if (!hubport) { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name, prop->info->name); return; } *ptr = hubport; }
static void set_chr(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { DeviceState *dev = DEVICE(obj); Error *local_err = NULL; Property *prop = opaque; CharBackend *be = qdev_get_prop_ptr(dev, prop); CharDriverState *s; char *str; if (dev->realized) { qdev_prop_set_after_realize(dev, name, errp); return; } visit_type_str(v, name, &str, &local_err); if (local_err) { error_propagate(errp, local_err); return; } if (!*str) { g_free(str); be->chr = NULL; return; } s = qemu_chr_find(str); if (s == NULL) { error_setg(errp, "Property '%s.%s' can't find value '%s'", object_get_typename(obj), prop->name, str); } else if (!qemu_chr_fe_init(be, s, errp)) { error_prepend(errp, "Property '%s.%s' can't take value '%s': ", object_get_typename(obj), prop->name, str); } g_free(str); }
static void set_string(Object *obj, Visitor *v, void *opaque, const char *name, Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; char **ptr = qdev_get_prop_ptr(dev, prop); Error *local_err = NULL; char *str; if (dev->state != DEV_STATE_CREATED) { error_set(errp, QERR_PERMISSION_DENIED); return; } visit_type_str(v, &str, name, &local_err); if (local_err) { error_propagate(errp, local_err); return; } if (*ptr) { g_free(*ptr); } *ptr = str; }
static void set_netdev(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { DeviceState *dev = DEVICE(obj); Property *prop = opaque; NICPeers *peers_ptr = qdev_get_prop_ptr(dev, prop); NetClientState **ncs = peers_ptr->ncs; NetClientState *peers[MAX_QUEUE_NUM]; Error *local_err = NULL; int queues, err = 0, i = 0; char *str; if (dev->realized) { qdev_prop_set_after_realize(dev, name, errp); return; } visit_type_str(v, name, &str, &local_err); if (local_err) { error_propagate(errp, local_err); return; } queues = qemu_find_net_clients_except(str, peers, NET_CLIENT_DRIVER_NIC, MAX_QUEUE_NUM); if (queues == 0) { err = -ENOENT; goto out; } if (queues > MAX_QUEUE_NUM) { error_setg(errp, "queues of backend '%s'(%d) exceeds QEMU limitation(%d)", str, queues, MAX_QUEUE_NUM); goto out; } for (i = 0; i < queues; i++) { if (peers[i] == NULL) { err = -ENOENT; goto out; } if (peers[i]->peer) { err = -EEXIST; goto out; } if (ncs[i]) { err = -EINVAL; goto out; } ncs[i] = peers[i]; ncs[i]->queue_index = i; } peers_ptr->queues = queues; out: error_set_from_qdev_prop_error(errp, err, dev, prop, str); g_free(str); }
static int print_uint16(DeviceState *dev, Property *prop, char *dest, size_t len) { uint16_t *ptr = qdev_get_prop_ptr(dev, prop); return snprintf(dest, len, "%" PRIu16, *ptr); }
static int print_int32(DeviceState *dev, Property *prop, char *dest, size_t len) { int32_t *ptr = qdev_get_prop_ptr(dev, prop); return snprintf(dest, len, "%" PRId32, *ptr); }
static int print_hex64(DeviceState *dev, Property *prop, char *dest, size_t len) { uint64_t *ptr = qdev_get_prop_ptr(dev, prop); return snprintf(dest, len, "0x%" PRIx64, *ptr); }
static void free_string(DeviceState *dev, Property *prop) { g_free(*(char **)qdev_get_prop_ptr(dev, prop)); }
static int print_bit(DeviceState *dev, Property *prop, char *dest, size_t len) { uint32_t *p = qdev_get_prop_ptr(dev, prop); return snprintf(dest, len, (*p & qdev_get_prop_mask(prop)) ? "on" : "off"); }
static void release_string(Object *obj, const char *name, void *opaque) { Property *prop = opaque; g_free(*(char **)qdev_get_prop_ptr(DEVICE(obj), prop)); }
static int print_drive(DeviceState *dev, Property *prop, char *dest, size_t len) { BlockDriverState **ptr = qdev_get_prop_ptr(dev, prop); return snprintf(dest, len, "%s", *ptr ? bdrv_get_device_name(*ptr) : "<null>"); }