net: don't use set/get_pointer() in set/get_netdev()
Commit 1ceef9f273
(net: multiqueue
support) tries to use set_pointer() and get_pointer() to set and get
NICPeers which is not a pointer defined in DEFINE_PROP_NETDEV. This
trick works but result a unclean and fragile implementation (e.g
print_netdev and parse_netdev).
This patch solves this issue by not using set/get_pinter() and set and
get netdev directly in set_netdev() and get_netdev(). After this the
parse_netdev() and print_netdev() were no longer used and dropped from
the source.
[Renamed 'err' label to 'out' as suggested by Markus Armbruster.
--Stefan]
Cc: Markus Armbruster <armbru@redhat.com>
Cc: Stefan Hajnoczi <stefanha@redhat.com>
Cc: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Jason Wang <jasowang@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
parent
756ae78b27
commit
23120b13c6
|
@ -177,42 +177,69 @@ PropertyInfo qdev_prop_chr = {
|
||||||
};
|
};
|
||||||
|
|
||||||
/* --- netdev device --- */
|
/* --- netdev device --- */
|
||||||
|
static void get_netdev(Object *obj, Visitor *v, void *opaque,
|
||||||
static int parse_netdev(DeviceState *dev, const char *str, void **ptr)
|
const char *name, Error **errp)
|
||||||
{
|
{
|
||||||
NICPeers *peers_ptr = (NICPeers *)ptr;
|
DeviceState *dev = DEVICE(obj);
|
||||||
|
Property *prop = opaque;
|
||||||
|
NICPeers *peers_ptr = qdev_get_prop_ptr(dev, prop);
|
||||||
|
char *p = g_strdup(peers_ptr->ncs[0] ? peers_ptr->ncs[0]->name : "");
|
||||||
|
|
||||||
|
visit_type_str(v, &p, name, errp);
|
||||||
|
g_free(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void set_netdev(Object *obj, Visitor *v, void *opaque,
|
||||||
|
const char *name, Error **errp)
|
||||||
|
{
|
||||||
|
DeviceState *dev = DEVICE(obj);
|
||||||
|
Property *prop = opaque;
|
||||||
|
NICPeers *peers_ptr = qdev_get_prop_ptr(dev, prop);
|
||||||
NetClientState **ncs = peers_ptr->ncs;
|
NetClientState **ncs = peers_ptr->ncs;
|
||||||
NetClientState *peers[MAX_QUEUE_NUM];
|
NetClientState *peers[MAX_QUEUE_NUM];
|
||||||
int queues, i = 0;
|
Error *local_err = NULL;
|
||||||
int ret;
|
int queues, err = 0, i = 0;
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
if (dev->realized) {
|
||||||
|
qdev_prop_set_after_realize(dev, name, errp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
visit_type_str(v, &str, name, &local_err);
|
||||||
|
if (local_err) {
|
||||||
|
error_propagate(errp, local_err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
queues = qemu_find_net_clients_except(str, peers,
|
queues = qemu_find_net_clients_except(str, peers,
|
||||||
NET_CLIENT_OPTIONS_KIND_NIC,
|
NET_CLIENT_OPTIONS_KIND_NIC,
|
||||||
MAX_QUEUE_NUM);
|
MAX_QUEUE_NUM);
|
||||||
if (queues == 0) {
|
if (queues == 0) {
|
||||||
ret = -ENOENT;
|
err = -ENOENT;
|
||||||
goto err;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (queues > MAX_QUEUE_NUM) {
|
if (queues > MAX_QUEUE_NUM) {
|
||||||
ret = -E2BIG;
|
error_setg(errp, "queues of backend '%s'(%d) exceeds QEMU limitation(%d)",
|
||||||
goto err;
|
str, queues, MAX_QUEUE_NUM);
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < queues; i++) {
|
for (i = 0; i < queues; i++) {
|
||||||
if (peers[i] == NULL) {
|
if (peers[i] == NULL) {
|
||||||
ret = -ENOENT;
|
err = -ENOENT;
|
||||||
goto err;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (peers[i]->peer) {
|
if (peers[i]->peer) {
|
||||||
ret = -EEXIST;
|
err = -EEXIST;
|
||||||
goto err;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ncs[i]) {
|
if (ncs[i]) {
|
||||||
ret = -EINVAL;
|
err = -EINVAL;
|
||||||
goto err;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
ncs[i] = peers[i];
|
ncs[i] = peers[i];
|
||||||
|
@ -221,30 +248,9 @@ static int parse_netdev(DeviceState *dev, const char *str, void **ptr)
|
||||||
|
|
||||||
peers_ptr->queues = queues;
|
peers_ptr->queues = queues;
|
||||||
|
|
||||||
return 0;
|
out:
|
||||||
|
error_set_from_qdev_prop_error(errp, err, dev, prop, str);
|
||||||
err:
|
g_free(str);
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *print_netdev(void *ptr)
|
|
||||||
{
|
|
||||||
NetClientState *netdev = ptr;
|
|
||||||
const char *val = netdev->name ? netdev->name : "";
|
|
||||||
|
|
||||||
return g_strdup(val);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void get_netdev(Object *obj, Visitor *v, void *opaque,
|
|
||||||
const char *name, Error **errp)
|
|
||||||
{
|
|
||||||
get_pointer(obj, v, opaque, print_netdev, name, errp);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void set_netdev(Object *obj, Visitor *v, void *opaque,
|
|
||||||
const char *name, Error **errp)
|
|
||||||
{
|
|
||||||
set_pointer(obj, v, opaque, parse_netdev, name, errp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PropertyInfo qdev_prop_netdev = {
|
PropertyInfo qdev_prop_netdev = {
|
||||||
|
|
Loading…
Reference in a new issue