[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v6 1/5] qapi: net: Add query-netdev command



On 3/2/21 12:02 PM, Alexey Kirillov wrote:
> The query-netdev command is used to get the configuration of the current
> network device backends (netdevs).
> This is the QMP analog of the HMP command "info network" but only for netdevs
> (i.e. excluding NIC and hubports).
> 
> The query-netdev command returns an array of objects of the NetdevInfo type,
> which are an extension of Netdev type. It means that response can be used for
> netdev-add after small modification. This can be useful for recreate the same
> netdev configuration.
> 
> Information about the network device is filled in when it is created or
> modified and is available through the NetClientState->stored_config.
> 
> Signed-off-by: Alexey Kirillov <lekiravi@xxxxxxxxxxxxxx>
> Acked-by: Markus Armbruster <armbru@xxxxxxxxxx>
> ---

> +++ b/net/net.c

>  
> +NetdevInfoList *qmp_query_netdev(Error **errp)
> +{
> +    NetdevInfoList *list = NULL;
> +    NetClientState *nc;
> +
> +    QTAILQ_FOREACH(nc, &net_clients, next) {
> +        /*
> +         * Only look at netdevs (backend network devices), not for each queue
> +         * or NIC / hubport
> +         */
> +        if (nc->stored_config) {
> +            NetdevInfoList *node = g_new0(NetdevInfoList, 1);

Please use QAPI_LIST_PREPEND instead of open-coding it.

> +
> +            node->value = QAPI_CLONE(NetdevInfo, nc->stored_config);
> +            g_free(node->value->id); /* Need to dealloc default empty id */
> +            node->value->id = g_strdup(nc->name);
> +
> +            node->value->has_peer_id = nc->peer != NULL;
> +            if (node->value->has_peer_id) {
> +                node->value->peer_id = g_strdup(nc->peer->name);
> +            }
> +
> +            node->next = list;
> +            list = node;
> +        }
> +    }
> +

> +++ b/net/slirp.c
> @@ -345,6 +345,14 @@ static SaveVMHandlers savevm_slirp_state = {
>      .load_state = net_slirp_state_load,
>  };
>  
> +#define APPEND_STRINGLIST(tail, new_val) \
> +    do { \
> +        *(tail) = g_new0(StringList, 1); \
> +        (*(tail))->value = g_new0(String, 1); \
> +        (*(tail))->value->str = g_strdup((new_val)); \
> +        (tail) = &((*(tail))->next); \
> +    } while (0)

Please use QAPI_LIST_APPEND instead of re-coding it.

> +++ b/qapi/net.json
> @@ -714,3 +714,83 @@
>  ##
>  { 'event': 'FAILOVER_NEGOTIATED',
>    'data': {'device-id': 'str'} }
> +
> +##
> +# @NetBackend:
> +#
> +# Available netdev backend drivers.
> +#
> +# Since: 6.0
> +##
> +{ 'enum': 'NetBackend',
> +  'data': [ 'user', 'tap', 'l2tpv3', 'socket', 'vde', 'bridge', 'netmap',
> +            'vhost-user', 'vhost-vdpa' ] }

Is it worth alphabetizing this list?

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.