qdev: Eliminate get_pointer(), set_pointer()
We stopped using get_pointer() and set_pointer() for netdev in commit23120b13c6
"net: don't use set/get_pointer() in set/get_netdev()" (v2.3.0), and for chardev in commitbecdfa00cf
"char: replace PROP_CHR with CharBackend" (v2.8.0). With only the drive user left, they're not helpful anymore. Eliminate. Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20200622094227.1271650-10-armbru@redhat.com>
This commit is contained in:
parent
a1b40bda08
commit
466c2983f8
|
@ -25,29 +25,45 @@
|
||||||
#include "sysemu/iothread.h"
|
#include "sysemu/iothread.h"
|
||||||
#include "sysemu/tpm_backend.h"
|
#include "sysemu/tpm_backend.h"
|
||||||
|
|
||||||
static void get_pointer(Object *obj, Visitor *v, Property *prop,
|
/* --- drive --- */
|
||||||
char *(*print)(void *ptr),
|
|
||||||
const char *name, Error **errp)
|
static void get_drive(Object *obj, Visitor *v, const char *name, void *opaque,
|
||||||
|
Error **errp)
|
||||||
{
|
{
|
||||||
DeviceState *dev = DEVICE(obj);
|
DeviceState *dev = DEVICE(obj);
|
||||||
|
Property *prop = opaque;
|
||||||
void **ptr = qdev_get_prop_ptr(dev, prop);
|
void **ptr = qdev_get_prop_ptr(dev, prop);
|
||||||
|
const char *value;
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
p = *ptr ? print(*ptr) : g_strdup("");
|
if (*ptr) {
|
||||||
|
value = blk_name(*ptr);
|
||||||
|
if (!*value) {
|
||||||
|
BlockDriverState *bs = blk_bs(*ptr);
|
||||||
|
if (bs) {
|
||||||
|
value = bdrv_get_node_name(bs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
value = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
p = g_strdup(value);
|
||||||
visit_type_str(v, name, &p, errp);
|
visit_type_str(v, name, &p, errp);
|
||||||
g_free(p);
|
g_free(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_pointer(Object *obj, Visitor *v, Property *prop,
|
static void set_drive_helper(Object *obj, Visitor *v, const char *name,
|
||||||
void (*parse)(DeviceState *dev, const char *str,
|
void *opaque, bool iothread, Error **errp)
|
||||||
void **ptr, const char *propname,
|
|
||||||
Error **errp),
|
|
||||||
const char *name, Error **errp)
|
|
||||||
{
|
{
|
||||||
DeviceState *dev = DEVICE(obj);
|
DeviceState *dev = DEVICE(obj);
|
||||||
|
Property *prop = opaque;
|
||||||
Error *local_err = NULL;
|
Error *local_err = NULL;
|
||||||
void **ptr = qdev_get_prop_ptr(dev, prop);
|
void **ptr = qdev_get_prop_ptr(dev, prop);
|
||||||
char *str;
|
char *str;
|
||||||
|
BlockBackend *blk;
|
||||||
|
bool blk_created = false;
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (dev->realized) {
|
if (dev->realized) {
|
||||||
qdev_prop_set_after_realize(dev, name, errp);
|
qdev_prop_set_after_realize(dev, name, errp);
|
||||||
|
@ -59,23 +75,12 @@ static void set_pointer(Object *obj, Visitor *v, Property *prop,
|
||||||
error_propagate(errp, local_err);
|
error_propagate(errp, local_err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!*str) {
|
if (!*str) {
|
||||||
g_free(str);
|
g_free(str);
|
||||||
*ptr = NULL;
|
*ptr = NULL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
parse(dev, str, ptr, prop->name, errp);
|
|
||||||
g_free(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* --- drive --- */
|
|
||||||
|
|
||||||
static void do_parse_drive(DeviceState *dev, const char *str, void **ptr,
|
|
||||||
const char *propname, bool iothread, Error **errp)
|
|
||||||
{
|
|
||||||
BlockBackend *blk;
|
|
||||||
bool blk_created = false;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
blk = blk_by_name(str);
|
blk = blk_by_name(str);
|
||||||
if (!blk) {
|
if (!blk) {
|
||||||
|
@ -101,7 +106,7 @@ static void do_parse_drive(DeviceState *dev, const char *str, void **ptr,
|
||||||
}
|
}
|
||||||
if (!blk) {
|
if (!blk) {
|
||||||
error_setg(errp, "Property '%s.%s' can't find value '%s'",
|
error_setg(errp, "Property '%s.%s' can't find value '%s'",
|
||||||
object_get_typename(OBJECT(dev)), propname, str);
|
object_get_typename(OBJECT(dev)), prop->name, str);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
if (blk_attach_dev(blk, dev) < 0) {
|
if (blk_attach_dev(blk, dev) < 0) {
|
||||||
|
@ -126,18 +131,20 @@ fail:
|
||||||
/* If we need to keep a reference, blk_attach_dev() took it */
|
/* If we need to keep a reference, blk_attach_dev() took it */
|
||||||
blk_unref(blk);
|
blk_unref(blk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_free(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parse_drive(DeviceState *dev, const char *str, void **ptr,
|
static void set_drive(Object *obj, Visitor *v, const char *name, void *opaque,
|
||||||
const char *propname, Error **errp)
|
Error **errp)
|
||||||
{
|
{
|
||||||
do_parse_drive(dev, str, ptr, propname, false, errp);
|
set_drive_helper(obj, v, name, opaque, false, errp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parse_drive_iothread(DeviceState *dev, const char *str, void **ptr,
|
static void set_drive_iothread(Object *obj, Visitor *v, const char *name,
|
||||||
const char *propname, Error **errp)
|
void *opaque, Error **errp)
|
||||||
{
|
{
|
||||||
do_parse_drive(dev, str, ptr, propname, true, errp);
|
set_drive_helper(obj, v, name, opaque, true, errp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void release_drive(Object *obj, const char *name, void *opaque)
|
static void release_drive(Object *obj, const char *name, void *opaque)
|
||||||
|
@ -156,38 +163,6 @@ static void release_drive(Object *obj, const char *name, void *opaque)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *print_drive(void *ptr)
|
|
||||||
{
|
|
||||||
const char *name;
|
|
||||||
|
|
||||||
name = blk_name(ptr);
|
|
||||||
if (!*name) {
|
|
||||||
BlockDriverState *bs = blk_bs(ptr);
|
|
||||||
if (bs) {
|
|
||||||
name = bdrv_get_node_name(bs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return g_strdup(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void get_drive(Object *obj, Visitor *v, const char *name, void *opaque,
|
|
||||||
Error **errp)
|
|
||||||
{
|
|
||||||
get_pointer(obj, v, opaque, print_drive, name, errp);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void set_drive(Object *obj, Visitor *v, const char *name, void *opaque,
|
|
||||||
Error **errp)
|
|
||||||
{
|
|
||||||
set_pointer(obj, v, opaque, parse_drive, name, errp);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void set_drive_iothread(Object *obj, Visitor *v, const char *name,
|
|
||||||
void *opaque, Error **errp)
|
|
||||||
{
|
|
||||||
set_pointer(obj, v, opaque, parse_drive_iothread, name, errp);
|
|
||||||
}
|
|
||||||
|
|
||||||
const PropertyInfo qdev_prop_drive = {
|
const PropertyInfo qdev_prop_drive = {
|
||||||
.name = "str",
|
.name = "str",
|
||||||
.description = "Node name or ID of a block device to use as a backend",
|
.description = "Node name or ID of a block device to use as a backend",
|
||||||
|
|
Loading…
Reference in a new issue