Re: [Xen-devel] [PATCH v2 1/4] qapi: net: Add query-netdevs command

2020-03-05 Thread Alexey Kirillov


05.03.2020, 15:03, "Markus Armbruster" :
> Alexey Kirillov  writes:
>
>>  Add a qmp command that provides information about currently attached
>>  network devices and their configuration.
>
> Closes a gap in QMP; appreciated!
>
>>  Signed-off-by: Alexey Kirillov 
>
> [...]
>>  diff --git a/qapi/net.json b/qapi/net.json
>>  index 1cb9a7d782..4f329a1de0 100644
>>  --- a/qapi/net.json
>>  +++ b/qapi/net.json
>>  @@ -750,3 +750,92 @@
>>   ##
>>   { 'event': 'FAILOVER_NEGOTIATED',
>> 'data': {'device-id': 'str'} }
>>  +
>>  +##
>>  +# @NetdevInfo:
>>  +#
>>  +# Configuration of a network device.
>>  +#
>>  +# @id: Device identifier.
>>  +#
>>  +# @type: Specify the driver used for interpreting remaining arguments.
>>  +#
>>  +# @peer: Connected network device.
>
> @peer is optional. I assume its present when the device is connected
> (frontend to backend or vice versa). Correct?
>

Yes, this field stores connected frontend/backend device @id.

>>  +#
>>  +# @queues-count: Number of queues.
>
> We use plain @queues elsewhere in the schema.
>

It can conflict with fields inside Netdev*Options, isn't it?

>>  +#
>>  +# @hub: hubid of hub, if connected to.
>
> How @hub is related to @peer is not quite obvious to me. Can you give
> an example where @hub is present?
>

NetdevHubPortOptions has an option @hubid. @hub gives that id, if
netdev is connected to the hub via hubport. As example:

HMP:

hub 0
 \ hub0port1: socket.0: index=0,type=socket,
 \ hub0port0: virtio-net-pci.0: 
index=0,type=nic,model=virtio-net-pci,macaddr=52:54:00:12:34:56

QMP:

[
  {
"peer": "hub0port0",
"netdev": "hub0port0",
"hub": 0,
"model": "virtio-net-pci",
"macaddr": "52:54:00:12:34:56",
"type": "nic",
"queues-count": 1,
"id": "virtio-net-pci.0"
  },
  {
"peer": "hub0port1",
"listen": "127.0.0.1:90",
"hub": 0,
"type": "socket",
"queues-count": 1,
"id": "socket.0"
  },
  {
"peer": "socket.0",
"netdev": "socket.0",
"hub": 0,
"hubid": 0,
"type": "hubport",
"queues-count": 1,
"id": "hub0port1"
  },
  {
"peer": "virtio-net-pci.0",
"netdev": "virtio-net-pci.0",
"hub": 0,
"hubid": 0,
"type": "hubport",
"queues-count": 1,
"id": "hub0port0"
  }
]

>>  +#
>>  +# @perm-mac: Original MAC address.
>
> What does "perm-" mean?
>
> It's optional. When exactly is it present?
>

@perm-mac is the permanent (original) MAC address. It only used
for nic, because most of nic realizations can change MAC at
runtime and/or reset it to default (permanent) value.

>>  +#
>>  +# Since: 5.0
>>  +##
>>  +{ 'union': 'NetdevInfo',
>>  + 'base': { 'id': 'str',
>>  + 'type': 'NetClientDriver',
>>  + '*peer': 'str',
>>  + 'queues-count': 'int',
>>  + '*hub': 'int',
>>  + '*perm-mac': 'str' },
>>  + 'discriminator': 'type',
>>  + 'data': {
>>  + 'nic': 'NetLegacyNicOptions',
>>  + 'user': 'NetdevUserOptions',
>>  + 'tap': 'NetdevTapOptions',
>>  + 'l2tpv3': 'NetdevL2TPv3Options',
>>  + 'socket': 'NetdevSocketOptions',
>>  + 'vde': 'NetdevVdeOptions',
>>  + 'bridge': 'NetdevBridgeOptions',
>>  + 'hubport': 'NetdevHubPortOptions',
>>  + 'netmap': 'NetdevNetmapOptions',
>>  + 'vhost-user': 'NetdevVhostUserOptions' } }
>
> This is a copy of union 'Netdev' with a few additional common members
> (@peer, @queues-count, @hub, @perm-mac). I can't see how to avoid the
> duplication without adding nesting on the wire.
>
>>  +
>>  +##
>>  +# @query-netdevs:
>>  +#
>>  +# Get a list of @NetdevInfo for all virtual network devices.
>>  +#
>>  +# Returns: a list of @NetdevInfo describing each virtual network device.
>>  +#
>>  +# Since: 5.0
>>  +#
>>  +# Example:
>>  +#
>>  +# -> { "execute": "query-netdevs" }
>>  +# <- { "return": [
>>  +# {
>>  +# "peer": "netdev0",
>>  +# "netdev": "netdev0",
>>  +# "perm-mac": "52:54:00:12:34:56"
>>  +# "model": "virtio-net-pci",
>>  +# "macaddr": "52:54:00:12:34:56",
>>  +# "queues-count": 1,
>>  +# "type": "nic",
>>  +# "id": "net0"
>>  +# },
>>  +# {
>>  +# "peer": "net0",
>>  +# "ipv6": true,
>>  +# "ipv4": true,
>>  +# "host": "10.0.2.2",
>>  +# "queues-count": 1,
>>  +# "ipv6-dns": "fec0::3",
>>  +# "ipv6-prefix": "fec0::",
>>  +# "net": "10.0.2.0/255.255.255.0",
>>  +# "ipv6-host": "fec0::2",
>>  +# "type": "user",
>>  +# "dns": "10.0.2.3",
>>  +# "hostfwd": [
>>  +# {
>>  +# "str": "tcp::20004-:22"
>>  +# }
>>  +# ],
>>  +# "ipv6-prefixlen": 64,
>>  +# "id": "netdev0",
>>  +# "restrict": false
>>  +# }
>>  +# ]
>>  +# }
>>  +#
>>  +##
>>  +{ 'command': 'query-netdevs', 'returns': ['NetdevInfo'] }
>
> Like HMP "info network" and -net, this mixes frontends ("type": "nic")
> and backends. Unlike query-chardev and query-block. Hmm.
>
> A long time ago, all we had was -net: "-net nic" for configuring
> frontends, "-net none" for suppressing a default frontend + backend, and
> "-net anything-else" for configuring backends. "info network" showed
> the stuff set up with -net.
>
> In v0.12, we got -device for configuring frontends, and -net

Re: [Xen-devel] [PATCH v2 1/4] qapi: net: Add query-netdevs command

2020-03-05 Thread Alexey Kirillov


04.03.2020, 18:57, "Laurent Vivier" :
> On 04/03/2020 14:06, Alexey Kirillov wrote:
>>  Add a qmp command that provides information about currently attached
>>  network devices and their configuration.
>>
>>  Signed-off-by: Alexey Kirillov 
>>  ---
>>   include/net/net.h | 1 +
>>   net/hub.c | 8 +++
>>   net/l2tpv3.c | 19 +++
>>   net/net.c | 91 +
>>   net/netmap.c | 13 +
>>   net/slirp.c | 126 ++
>>   net/socket.c | 71 ++
>>   net/tap-win32.c | 9 
>>   net/tap.c | 103 +++--
>>   net/vde.c | 26 ++
>>   net/vhost-user.c | 18 +--
>>   qapi/net.json | 89 
>>   12 files changed, 566 insertions(+), 8 deletions(-)
>
> ...
>>  diff --git a/net/net.c b/net/net.c
>>  index 9e93c3f8a1..01e0548295 100644
>>  --- a/net/net.c
>>  +++ b/net/net.c
>>  @@ -54,6 +54,7 @@
>>   #include "sysemu/sysemu.h"
>>   #include "net/filter.h"
>>   #include "qapi/string-output-visitor.h"
>>  +#include "qapi/clone-visitor.h"
>>
>>   /* Net bridge is currently not supported for W32. */
>>   #if !defined(_WIN32)
>>  @@ -128,6 +129,12 @@ char *qemu_mac_strdup_printf(const uint8_t *macaddr)
>>
>>   void qemu_format_nic_info_str(NetClientState *nc, uint8_t macaddr[6])
>>   {
>>  + g_assert(nc->stored_config);
>>  +
>>  + g_free(nc->stored_config->u.nic.macaddr);
>>  + nc->stored_config->u.nic.macaddr = g_strdup_printf(MAC_FMT,
>>  + MAC_ARG(macaddr));
>>  +
>
> Why do you use this rather than the qemu_mac_strdup_printf() function
> defined above?
>
> qemu_mac_strdup_printf():
>   890ee6abb385 ("net: add MAC address string printer")
>
> MAC_FMT/MAC_ARG:
>   6d1d4939a647 ("net: Add macros for MAC address tracing")
>
> MAC_FMT/MAC_ARG seems to be reserved for tracing.
>
> Thanks,
> Laurent

Somehow, I managed not to notice this feature.
Thank you for pointing this out, I will definitely fix this place.

-- 
Alexey Kirillov
Yandex.Cloud


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH v2 1/4] qapi: net: Add query-netdevs command

2020-03-05 Thread Markus Armbruster
Alexey Kirillov  writes:

> Add a qmp command that provides information about currently attached
> network devices and their configuration.

Closes a gap in QMP; appreciated!

> Signed-off-by: Alexey Kirillov 
[...]
> diff --git a/qapi/net.json b/qapi/net.json
> index 1cb9a7d782..4f329a1de0 100644
> --- a/qapi/net.json
> +++ b/qapi/net.json
> @@ -750,3 +750,92 @@
>  ##
>  { 'event': 'FAILOVER_NEGOTIATED',
>'data': {'device-id': 'str'} }
> +
> +##
> +# @NetdevInfo:
> +#
> +# Configuration of a network device.
> +#
> +# @id: Device identifier.
> +#
> +# @type: Specify the driver used for interpreting remaining arguments.
> +#
> +# @peer: Connected network device.

@peer is optional.  I assume its present when the device is connected
(frontend to backend or vice versa).  Correct?

> +#
> +# @queues-count: Number of queues.

We use plain @queues elsewhere in the schema.

> +#
> +# @hub: hubid of hub, if connected to.

How @hub is related to @peer is not quite obvious to me.  Can you give
an example where @hub is present?

> +#
> +# @perm-mac: Original MAC address.

What does "perm-" mean?

It's optional.  When exactly is it present?

> +#
> +# Since: 5.0
> +##
> +{ 'union': 'NetdevInfo',
> +  'base': { 'id': 'str',
> +'type': 'NetClientDriver',
> +'*peer': 'str',
> +'queues-count': 'int',
> +'*hub': 'int',
> +'*perm-mac': 'str' },
> +  'discriminator': 'type',
> +  'data': {
> +  'nic':'NetLegacyNicOptions',
> +  'user':   'NetdevUserOptions',
> +  'tap':'NetdevTapOptions',
> +  'l2tpv3': 'NetdevL2TPv3Options',
> +  'socket': 'NetdevSocketOptions',
> +  'vde':'NetdevVdeOptions',
> +  'bridge': 'NetdevBridgeOptions',
> +  'hubport':'NetdevHubPortOptions',
> +  'netmap': 'NetdevNetmapOptions',
> +  'vhost-user': 'NetdevVhostUserOptions' } }

This is a copy of union 'Netdev' with a few additional common members
(@peer, @queues-count, @hub, @perm-mac).  I can't see how to avoid the
duplication without adding nesting on the wire.

> +
> +##
> +# @query-netdevs:
> +#
> +# Get a list of @NetdevInfo for all virtual network devices.
> +#
> +# Returns: a list of @NetdevInfo describing each virtual network device.
> +#
> +# Since: 5.0
> +#
> +# Example:
> +#
> +# -> { "execute": "query-netdevs" }
> +# <- { "return": [
> +#  {
> +#  "peer": "netdev0",
> +#  "netdev": "netdev0",
> +#  "perm-mac": "52:54:00:12:34:56"
> +#  "model": "virtio-net-pci",
> +#  "macaddr": "52:54:00:12:34:56",
> +#  "queues-count": 1,
> +#  "type": "nic",
> +#  "id": "net0"
> +#  },
> +#  {
> +#  "peer": "net0",
> +#  "ipv6": true,
> +#  "ipv4": true,
> +#  "host": "10.0.2.2",
> +#  "queues-count": 1,
> +#  "ipv6-dns": "fec0::3",
> +#  "ipv6-prefix": "fec0::",
> +#  "net": "10.0.2.0/255.255.255.0",
> +#  "ipv6-host": "fec0::2",
> +#  "type": "user",
> +#  "dns": "10.0.2.3",
> +#  "hostfwd": [
> +#  {
> +#  "str": "tcp::20004-:22"
> +#  }
> +#  ],
> +#  "ipv6-prefixlen": 64,
> +#  "id": "netdev0",
> +#  "restrict": false
> +#  }
> +#  ]
> +#}
> +#
> +##
> +{ 'command': 'query-netdevs', 'returns': ['NetdevInfo'] }

Like HMP "info network" and -net, this mixes frontends ("type": "nic")
and backends.  Unlike query-chardev and query-block.  Hmm.

A long time ago, all we had was -net: "-net nic" for configuring
frontends, "-net none" for suppressing a default frontend + backend, and
"-net anything-else" for configuring backends.  "info network" showed
the stuff set up with -net.

In v0.12, we got -device for configuring frontends, and -netdev for
backends.  -netdev is like -net less "none", "nic", and the hub
weirdness.  "info network" was extended to also show all this.

In v2.12, we got -nic, replacing -net nic.

Unless I'm missing something, -net is just for backward compatibility
now.

What's the use case for query-networks reporting frontends?


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Re: [Xen-devel] [PATCH v2 1/4] qapi: net: Add query-netdevs command

2020-03-04 Thread Laurent Vivier
On 04/03/2020 14:06, Alexey Kirillov wrote:
> Add a qmp command that provides information about currently attached
> network devices and their configuration.
> 
> Signed-off-by: Alexey Kirillov 
> ---
>  include/net/net.h |   1 +
>  net/hub.c |   8 +++
>  net/l2tpv3.c  |  19 +++
>  net/net.c |  91 +
>  net/netmap.c  |  13 +
>  net/slirp.c   | 126 ++
>  net/socket.c  |  71 ++
>  net/tap-win32.c   |   9 
>  net/tap.c | 103 +++--
>  net/vde.c |  26 ++
>  net/vhost-user.c  |  18 +--
>  qapi/net.json |  89 
>  12 files changed, 566 insertions(+), 8 deletions(-)
> 
...
> diff --git a/net/net.c b/net/net.c
> index 9e93c3f8a1..01e0548295 100644
> --- a/net/net.c
> +++ b/net/net.c
> @@ -54,6 +54,7 @@
>  #include "sysemu/sysemu.h"
>  #include "net/filter.h"
>  #include "qapi/string-output-visitor.h"
> +#include "qapi/clone-visitor.h"
>  
>  /* Net bridge is currently not supported for W32. */
>  #if !defined(_WIN32)
> @@ -128,6 +129,12 @@ char *qemu_mac_strdup_printf(const uint8_t *macaddr)
>  
>  void qemu_format_nic_info_str(NetClientState *nc, uint8_t macaddr[6])
>  {
> +g_assert(nc->stored_config);
> +
> +g_free(nc->stored_config->u.nic.macaddr);
> +nc->stored_config->u.nic.macaddr = g_strdup_printf(MAC_FMT,
> +   MAC_ARG(macaddr));
> +

Why do you use this rather than the qemu_mac_strdup_printf() function
defined above?

qemu_mac_strdup_printf():
  890ee6abb385 ("net: add MAC address string printer")

MAC_FMT/MAC_ARG:
  6d1d4939a647 ("net: Add macros for MAC address tracing")

MAC_FMT/MAC_ARG seems to be reserved for tracing.

Thanks,
Laurent


___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel