mac programming over macvtap
v3 cover mac programming over macvtap
This patchset introduces a QMP event and a monitor command. The event is used to notify management when rx-filter configuration is changed by guest. Management can use the new monitor command to query rx-filter information, and sync the changes to macvtap devices.
There maybe exist an uncontrollable delay, guests normally expect rx-mode updates immediately, but it's another separate issue, we can investigate it after Libvirt work is done.
Patches are based on Michael's patchset [1], you can also find patches in my github [2].
[1] [PATCH v3 00/11] qapi: add support for lists of native types
[2] https://github.com/kongove/qemu/tree/01-query-rxfilter
v2: add argument to filter mac-table info of single nic (Stefan)
update the document
add event notification
V3: rename to rx-filter, add main mac, avoid event flooding (MST)
fix error process (Stefan)
fix qmp interface (Eric)
Amos Kong (2):
net: introduce RX_FILTER_CHANGED event
net: introduce command to query rx-filter information
QMP/qmp-events.txt | 14 +++++++ hmp-commands.hx | 2 + hmp.c | 49 +++++++++++++++++++++++++ hmp.h | 1 + hw/net/virtio-net.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++ include/monitor/monitor.h | 1 + include/net/net.h | 2 + monitor.c | 9 +++++ net/net.c | 47 ++++++++++++++++++++++++ qapi-schema.json | 73 +++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 55 ++++++++++++++++++++++++++++ 11 files changed, 346 insertions(+)
Signature · 1 line
1.8.1.4
PATCH v3 1/2 net: introduce RX_FILTER_CHANGED event
Introduce this new QMP event to notify management after guest changes rx-filter configuration.
--- QMP/qmp-events.txt | 14 ++++++++++++++ include/monitor/monitor.h | 1 + monitor.c | 1 + 3 files changed, 16 insertions(+)
QMP/qmp-events.txt +14 -0
@@ -154,6 +154,20 @@ Data: "path": "/machine/peripheral/virtio-net-pci-0" }, "timestamp": { "seconds": 1265044230, "microseconds": 450486 } } +RX_FILTER_CHANGED +----------------- + +Emitted when rx-filter configuration is changed by the guest. + +Data: + +- "name": net client name (json-string) + +{ "event": "RX_FILTER_CHANGED", + "data": { "name": "vnet0" }, + "timestamp": { "seconds": 1368697518, "microseconds": 326866 }} +} + DEVICE_TRAY_MOVED -----------------
include/monitor/monitor.h +1 -0
@@ -40,6 +40,7 @@ typedef enum MonitorEvent {QEVENT_BLOCK_JOB_ERROR ,QEVENT_BLOCK_JOB_READY ,QEVENT_DEVICE_DELETED , +QEVENT_RX_FILTER_CHANGED ,QEVENT_DEVICE_TRAY_MOVED ,QEVENT_SUSPEND , QEVENT_SUSPEND_DISK,
monitor.c +1 -0
@@ -489,6 +489,7 @@ static const char *monitor_event_names[] = { [QEVENT_BLOCK_JOB_ERROR] = "BLOCK_JOB_ERROR", [QEVENT_BLOCK_JOB_READY] = "BLOCK_JOB_READY", [QEVENT_DEVICE_DELETED] = "DEVICE_DELETED", + [QEVENT_RX_FILTER_CHANGED] = "RX_FILTER_CHANGED", [QEVENT_DEVICE_TRAY_MOVED] = "DEVICE_TRAY_MOVED", [QEVENT_SUSPEND] = "SUSPEND", [QEVENT_SUSPEND_DISK] = "SUSPEND_DISK",
Signature · 1 line
1.8.1.4
PATCH v3 2/2 net: introduce command to query rx-filter information
In reply to Amos KongWe want to implement mac programming over macvtap through Libvirt, related rx-filter configuration contains main mac, some of rx-mode and mac-table.
The previous patch adds QMP event to notify management of rx-filter change. This patch adds a monitor command to query rx-filter information.
A flag is used to avoid events flooding, if user don't query rx-filter after receives one event, new events won't be sent to qmp monitor.
(qemu) info rx-filter vnet0
vnet0:
\ promiscuous: on
\ multicast: normal
\ unicast: normal
\ broadcast-allowed: off
\ multicast-overflow: off
\ unicast-overflow: off
\ main-mac: 52:54:00:12:34:56
\ unicast-table:
\ multicast-table:
01:00:5e:00:00:01
33:33:00:00:00:01
33:33:ff:12:34:56--- hmp-commands.hx | 2 ++ hmp.c | 49 ++++++++++++++++++++++++++++ hmp.h | 1 + hw/net/virtio-net.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++ include/net/net.h | 2 ++ monitor.c | 8 +++++ net/net.c | 47 +++++++++++++++++++++++++++ qapi-schema.json | 73 +++++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 55 +++++++++++++++++++++++++++++++ 9 files changed, 330 insertions(+)
hmp-commands.hx +2 -0
@@ -1639,6 +1639,8 @@ show qdev device model list show roms @item info tpm show the TPM device +@item info rx-filter [net client name] +show the rx-filter information for all nics (or for the given nic) @end table ETEXI
hmp.c +49 -0
55 lines not on this page · raw message
hmp.h +1 -0
@@ -37,6 +37,7 @@ void hmp_info_balloon(Monitor *mon, const QDict *qdict);void hmp_info_pci (Monitor *mon,const QDict *qdict);void hmp_info_block_jobs (Monitor *mon,const QDict *qdict);void hmp_info_tpm (Monitor *mon,const QDict *qdict); +void hmp_info_rx_filter (Monitor *mon,const QDict *qdict);void hmp_quit (Monitor *mon,const QDict *qdict);void hmp_stop (Monitor *mon,const QDict *qdict);void hmp_system_reset (Monitor *mon,const QDict *qdict);
hw/net/virtio-net.c +93 -0
129 lines not on this page · raw message
include/net/net.h +2 -0
@@ -49,6 +49,7 @@ typedef ssize_t (NetReceiveIOV)(NetClientState *, const struct iovec *, int);typedef void (NetCleanup ) (NetClientState *);typedef void (LinkStatusChanged )(NetClientState *);typedef void (NetClientDestructor )(NetClientState *); +typedef RxFilterInfo *(QueryRxFilter )(NetClientState *); typedef struct NetClientInfo { NetClientOptionsKind type;
@@ -59,6 +60,7 @@ typedef struct NetClientInfo {NetCanReceive *can_receive;NetCleanup *cleanup;LinkStatusChanged *link_status_changed; +QueryRxFilter *query_rx_filter;NetPoll *poll; } NetClientInfo;
monitor.c +8 -0
@@ -2764,6 +2764,14 @@ static mon_cmd_t info_cmds[] = { .mhandler.cmd = hmp_info_tpm, }, { + .name = "rx-filter", + .args_type = "name:s?", + .params = "[net client name]", + .help = "show the rx-filter information for all nics (or" + " for the given nic)", + .mhandler.cmd = hmp_info_rx_filter, + }, + { .name = NULL, }, };
net/net.c +47 -0
53 lines not on this page · raw message
qapi-schema.json +73 -0
76 lines not on this page · raw message
qmp-commands.hx +55 -0
58 lines not on this page · raw message
Signature · 1 line
1.8.1.4
Re: [Qemu-devel] [PATCH v3 2/2] net: introduce command to query rx-filter information
Quoted 139 lines · Amos Kong
We want to implement mac programming over macvtap through Libvirt, related rx-filter configuration contains main mac, some of rx-mode and mac-table.
The previous patch adds QMP event to notify management of rx-filter change. This patch adds a monitor command to query rx-filter information.
A flag is used to avoid events flooding, if user don't query rx-filter after receives one event, new events won't be sent to qmp monitor.
(qemu) info rx-filter vnet0
vnet0:
\ promiscuous: on
\ multicast: normal
\ unicast: normal
\ broadcast-allowed: off
\ multicast-overflow: off
\ unicast-overflow: off
\ main-mac: 52:54:00:12:34:56
\ unicast-table:
\ multicast-table:01:00:5e:00:00:01 33:33:00:00:00:01 33:33:ff:12:34:56Signed-off-by Amos Kong <[email protected]>--- hmp-commands.hx | 2 ++ hmp.c | 49 ++++++++++++++++++++++++++++ hmp.h | 1 + hw/net/virtio-net.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++ include/net/net.h | 2 ++ monitor.c | 8 +++++ net/net.c | 47 +++++++++++++++++++++++++++ qapi-schema.json | 73 +++++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 55 +++++++++++++++++++++++++++++++ 9 files changed, 330 insertions(+)hmp-commands.hx +2
-0@@ -1639,6 +1639,8 @@ show qdev device model list show roms @item info tpm show the TPM device +@item info rx-filter [net client name] +show the rx-filter information for all nics (or for the given nic) @end table ETEXIhmp.c +49
-0@@ -653,6 +653,55 @@ void hmp_info_tpm(Monitor *mon, const QDict *qdict)qapi_free_TPMInfoList (info_list); } +void hmp_info_rx_filter (Monitor *mon,const QDict *qdict) +{ +RxFilterInfoList *filter_list, *entry; +strList *str_entry; +bool has_name =qdict_haskey (qdict,"name" ); +const char *name =NULL ; + +if (has_name) { + name =qdict_get_str (qdict,"name" ); + } + + filter_list =qmp_query_rx_filter (has_name, name,NULL ); + entry = filter_list; + +while (entry) { +monitor_printf (mon,"%s:\n" , entry->value->name); +monitor_printf (mon," \\ promiscuous: %s\n" , + entry->value->promiscuous ?"on" :"off" ); +monitor_printf (mon," \\ multicast: %s\n" , + RxState_lookup[entry->value->multicast]); +monitor_printf (mon," \\ unicast: %s\n" , + RxState_lookup[entry->value->unicast]); +monitor_printf (mon," \\ broadcast-allowed: %s\n" , + entry->value->broadcast_allowed ?"on" :"off" ); +monitor_printf (mon," \\ multicast-overflow: %s\n" , + entry->value->multicast_overflow ?"on" :"off" ); +monitor_printf (mon," \\ unicast-overflow: %s\n" , + entry->value->unicast_overflow ?"on" :"off" ); +monitor_printf (mon," \\ main-mac: %s\n" , entry->value->main_mac); + + str_entry = entry->value->unicast_table; +monitor_printf (mon," \\ unicast-table:\n" ); +while (str_entry) { +monitor_printf (mon," %s\n" , str_entry->value); + str_entry = str_entry->next; + } + + str_entry = entry->value->multicast_table; +monitor_printf (mon," \\ multicast-table:\n" ); +while (str_entry) { +monitor_printf (mon," %s\n" , str_entry->value); + str_entry = str_entry->next; + } + + entry = entry->next; + } +qapi_free_RxFilterInfoList (filter_list); +} +void hmp_quit (Monitor *mon,const QDict *qdict) {monitor_suspend (mon);hmp.h +1
-0@@ -37,6 +37,7 @@ void hmp_info_balloon(Monitor *mon, const QDict *qdict);void hmp_info_pci (Monitor *mon,const QDict *qdict);void hmp_info_block_jobs (Monitor *mon,const QDict *qdict);void hmp_info_tpm (Monitor *mon,const QDict *qdict); +void hmp_info_rx_filter (Monitor *mon,const QDict *qdict);void hmp_quit (Monitor *mon,const QDict *qdict);void hmp_stop (Monitor *mon,const QDict *qdict);void hmp_system_reset (Monitor *mon,const QDict *qdict);hw/net/virtio-net.c +2
-0@@ -21,6 +21,8 @@#include "hw/virtio/virtio-net.h" #include "net/vhost_net.h" #include "hw/virtio/virtio-bus.h" +#include "qapi/qmp/qjson.h" +#include "monitor/monitor.h" #define VIRTIO_NET_VM_VERSION 11
hw/net/virtio-net.c static void virtio_net_set_link_status(NetClientState *nc) · line 197
Quoted 4 lines
hw/net/virtio-net.c +1
-0@@ -192,6 +194,90 @@ static void virtio_net_set_link_status(NetClientState *nc)virtio_net_set_status (vdev, vdev->status); } +static bool notify_enabled = true;
Please, make this part of the device state, not a global variable. E.g. if I query rxfilter for device X, no need to resend events for device Y.
And rename to rxfilter_notify_enabled.
Quoted 38 lines
hw/net/virtio-net.c +38
-0+ +static void rxfilter_notify (const char *name) +{ +QObject *event_data; + +if (notify_enabled) { + event_data =qobject_from_jsonf ("{ 'name': %s }" , name); +monitor_protocol_event (QEVENT_RX_FILTER_CHANGED , event_data); +qobject_decref (event_data); +/* disable event notification to avoid events flooding */ + notify_enabled = false; + } +} + +static RxFilterInfo *virtio_net_query_rxfilter (NetClientState *nc) +{ +VirtIONet *n =qemu_get_nic_opaque (nc); +RxFilterInfo *info; +strList *str_list =NULL ; +strList *entry; +int i; + + info =g_malloc0 (sizeof (*info)); + info->name =g_strdup (nc->name); + info->promiscuous = n->promisc; + +if (n->nouni) { + info->unicast =RX_STATE_NO ; + }else if (n->alluni) { + info->unicast =RX_STATE_ALL ; + }else { + info->unicast =RX_STATE_NORMAL ; + } + +if (n->nomulti) { + info->multicast =RX_STATE_NO ; + }else if (n->allmulti) { + info->multicast =RX_STATE_ALL ;
hw/net/virtio-net.c static void virtio_net_set_link_status(NetClientState *nc) · line 245
Quoted 10 lines
hw/net/virtio-net.c +10
-0+ }else { + info->multicast =RX_STATE_NORMAL ; + } + + info->broadcast_allowed = n->nobcast; + info->multicast_overflow = n->mac_table.multi_overflow; + info->unicast_overflow = n->mac_table.uni_overflow; + info->main_mac =g_strdup_printf ("%.2x:%.2x:%.2x:%.2x:%.2x:%.2x" , + n->mac[0 ], n->mac[1 ], n->mac[2 ], + n->mac[3 ], n->mac[4 ], n->mac[5 ]);
We really want a helper for this g_strdup_printf thing IMO.
Quoted 316 lines
hw/net/virtio-net.c +42
-0+ +for (i =0 ; i < n->mac_table.first_multi; i++) { + entry =g_malloc0 (sizeof (*entry)); + entry->value =g_strdup_printf ("%.2x:%.2x:%.2x:%.2x:%.2x:%.2x" , + n->mac_table.macs[i *ETH_ALEN ], + n->mac_table.macs[i *ETH_ALEN +1 ], + n->mac_table.macs[i *ETH_ALEN +2 ], + n->mac_table.macs[i *ETH_ALEN +3 ], + n->mac_table.macs[i *ETH_ALEN +4 ], + n->mac_table.macs[i *ETH_ALEN +5 ]); + entry->next = str_list; + str_list = entry; + } + info->unicast_table = str_list; + + str_list =NULL ; +for (i = n->mac_table.first_multi; i < n->mac_table.in_use; i++) { + entry =g_malloc0 (sizeof (*entry)); + entry->value =g_strdup_printf ("%.2x:%.2x:%.2x:%.2x:%.2x:%.2x" , + n->mac_table.macs[i *ETH_ALEN ], + n->mac_table.macs[i *ETH_ALEN +1 ], + n->mac_table.macs[i *ETH_ALEN +2 ], + n->mac_table.macs[i *ETH_ALEN +3 ], + n->mac_table.macs[i *ETH_ALEN +4 ], + n->mac_table.macs[i *ETH_ALEN +5 ]); + entry->next = str_list; + str_list = entry; + } + info->multicast_table = str_list; +/* enable event notification after query */ + notify_enabled = true; + +return info; +} +static void virtio_net_reset (VirtIODevice *vdev) {VirtIONet *n =VIRTIO_NET (vdev);@@ -442,6 +528,8 @@ static int virtio_net_handle_rx_mode(VirtIONet *n, uint8_t cmd,return VIRTIO_NET_ERR ; } +rxfilter_notify (n->netclient_name); +return VIRTIO_NET_OK ; }@@ -495,6 +583,8 @@ static int virtio_net_handle_mac(VirtIONet *n, uint8_t cmd, s =iov_to_buf (iov, iov_cnt,0 , &n->mac,sizeof (n->mac));assert (s ==sizeof (n->mac));qemu_format_nic_info_str (qemu_get_queue (n->nic), n->mac); +rxfilter_notify (n->netclient_name); +return VIRTIO_NET_OK ; }@@ -559,6 +649,8 @@ static int virtio_net_handle_mac(VirtIONet *n, uint8_t cmd, n->mac_table.multi_overflow =1 ; } +rxfilter_notify (n->netclient_name); +return VIRTIO_NET_OK ; }@@ -1312,6 +1404,7 @@ static NetClientInfo net_virtio_info = { .receive = virtio_net_receive, .cleanup = virtio_net_cleanup, .link_status_changed = virtio_net_set_link_status, + .query_rx_filter = virtio_net_query_rxfilter, };static bool virtio_net_guest_notifier_pending (VirtIODevice *vdev,int idx)include/net/net.h +2
-0@@ -49,6 +49,7 @@ typedef ssize_t (NetReceiveIOV)(NetClientState *, const struct iovec *, int);typedef void (NetCleanup ) (NetClientState *);typedef void (LinkStatusChanged )(NetClientState *);typedef void (NetClientDestructor )(NetClientState *); +typedef RxFilterInfo *(QueryRxFilter )(NetClientState *); typedef struct NetClientInfo { NetClientOptionsKind type;@@ -59,6 +60,7 @@ typedef struct NetClientInfo {NetCanReceive *can_receive;NetCleanup *cleanup;LinkStatusChanged *link_status_changed; +QueryRxFilter *query_rx_filter;NetPoll *poll; } NetClientInfo;monitor.c +8
-0@@ -2764,6 +2764,14 @@ static mon_cmd_t info_cmds[] = { .mhandler.cmd = hmp_info_tpm, }, { + .name = "rx-filter", + .args_type = "name:s?", + .params = "[net client name]", + .help = "show the rx-filter information for all nics (or" + " for the given nic)", + .mhandler.cmd = hmp_info_rx_filter, + }, + { .name = NULL, }, };net/net.c +47
-0@@ -961,6 +961,53 @@ void print_net_client(Monitor *mon, NetClientState *nc) nc->info_str); } +RxFilterInfoList *qmp_query_rx_filter (bool has_name,const char *name, +Error **errp) +{ +NetClientState *nc; +RxFilterInfoList *filter_list =NULL , *last_entry =NULL ; + + QTAILQ_FOREACH(nc, &net_clients, next) { +RxFilterInfoList *entry; +RxFilterInfo *info; + +if (nc->info->type !=NET_CLIENT_OPTIONS_KIND_NIC ) { +continue ; + } +if (has_name &&strcmp (nc->name, name) !=0 ) { +continue ; + } + +if (nc->info->query_rx_filter) { + info = nc->info->query_rx_filter (nc); + entry =g_malloc0 (sizeof (*entry)); + entry->value = info; + +if (!filter_list) { + filter_list = entry; + }else { + last_entry->next = entry; + } + last_entry = entry; + }else if (has_name) { +error_setg (errp,"net client(%s) doesn't support" +" rx-filter querying" , name); +break ; + } + + } + +if (filter_list ==NULL && !error_is_set (errp)) { +if (has_name) { +error_setg (errp,"invalid net client name: %s" , name); + }else { +error_setg (errp,"no net client supports rx-filter querying" ); + } + } + +return filter_list; +} +void do_info_network (Monitor *mon,const QDict *qdict) {NetClientState *nc, *peer;qapi-schema.json +73
-0@@ -3619,3 +3619,76 @@ '*cpuid-input-ecx': 'int', 'cpuid-register': 'X86CPURegister32', 'features': 'int' } } + +## +# @RxState: +# +# Packets receiving state +# +# @normal: filter assigned packets according to the mac-table +# +# @no: don't receive any assigned packet +# +# @all: receive all assigned packets +# +## +{ 'enum': 'RxState', 'data': [ 'normal', 'no', 'all' ] } + +## +# @RxFilterInfo: +# +# Rx-filter information for a net client, it contains main mac, some +# of rx-mode items and mac-table. +# +# @name: net client name +# +# @promiscuous: whether to ether promiscuous mode +# +# @multicast: multicast receive state +# +# @unicast: unicast receive state +# +# @broadcast-allowed: whether to receive broadcast +# +# @multicast-overflow: multicast table is overflow or not +# +# @unicast-overflow: unicast table is overflow or not +# +# @main-mac: the main macaddr string +# +# @unicast-table: a list of unicast macaddr string +# +# @multicast-table: a list of multicast macaddr string +# +# Since 1.6 +## + +{ 'type': 'RxFilterInfo', + 'data': { + 'name': 'str', + 'promiscuous': 'bool', + 'multicast': 'RxState', + 'unicast': 'RxState', + 'broadcast-allowed': 'bool', + 'multicast-overflow': 'bool', + 'unicast-overflow': 'bool', + 'main-mac': 'str', + 'unicast-table': ['str'], + 'multicast-table': ['str'] }} + +## +# @query-rx-filter: +# +# Return rx-filter information for all nics (or for the given nic). +# +# @name: #optional net client name +# +# Returns: list of @RxFilterInfo for all nics (or for the given nic). +# Returns an error if the given @name doesn't exist, or given +# nic doesn't support rx-filter querying, or no net client +# supports rx-filter querying +# +# Since: 1.6 +## +{ 'command': 'query-rx-filter', 'data': { '*name': 'str' }, + 'returns': ['RxFilterInfo'] }qmp-commands.hx +55
-0@@ -2932,3 +2932,58 @@ Example: <- { "return": {} } EQMP + { + .name = "query-rx-filter", + .args_type = "name:s?", + .mhandler.cmd_new = qmp_marshal_input_query_rx_filter, + }, + +SQMP +query-rx-filter +--------------- + +Show rx-filter information. + +Returns a json-array of rx-filter information for all nics (or for the +given nic), returning an error if the given nic doesn't exist, or +given nic doesn't support rx-filter querying, or no net client +supports rx-filter querying. + +Each array entry contains the following: + +- "name": net client name (jaso-string) +- "promiscuous": enter promiscuous mode (json-bool) +- "multicast": multicast receive state (one of 'normal', 'no', 'all') +- "unicast": unicast receive state (one of 'normal', 'no', 'all') +- "broadcast-allowed": allow to receive broadcast (json-bool) +- "multicast-overflow": multicast table is overflow (json-bool) +- "unicast-overflow": unicast table is overflow (json-bool) +- "main-mac": main macaddr string (jaso-string) +- "unicast-table": a json-array of unicast macaddr string +- "multicast-table": a json-array of multicast macaddr string + +Example: + +-> { "execute": "query-rx-filter", "arguments": { "name": "vnet0" }} +<- { "return": [ + { + "promiscuous": true, + "name": "vnet0", + "main-mac": "52:54:00:12:34:56", + "unicast": "normal", + "unicast-table": [ + ], + "multicast": "normal", + "multicast-overflow": false, + "unicast-overflow": false, + "multicast-table": [ + "01:00:5e:00:00:01", + "33:33:00:00:00:01", + "33:33:ff:12:34:56" + ], + "broadcast-allowed": false + } + ] + } + +EQMPSignature · 1 line
1.8.1.4
Re: [Qemu-devel] [PATCH v3 1/2] net: introduce RX_FILTER_CHANGED event
In reply to Amos KongQuoted 15 lines · Amos Kong
Introduce this new QMP event to notify management after guest changes rx-filter configuration.
Signed-off-by Amos Kong <[email protected]>--- QMP/qmp-events.txt | 14 ++++++++++++++ include/monitor/monitor.h | 1 + monitor.c | 1 + 3 files changed, 16 insertions(+)QMP/qmp-events.txt +0
-0
QMP/qmp-events.txt Data: · line 160
Quoted 7 lines
QMP/qmp-events.txt +4
-0@@ -154,6 +154,20 @@ Data: "path": "/machine/peripheral/virtio-net-pci-0" }, "timestamp": { "seconds": 1265044230, "microseconds": 450486 } } +RX_FILTER_CHANGED +----------------- + +Emitted when rx-filter configuration is changed by the guest.
Please stress this is only for the NIC. It does not apply to non-NIC netclients.
QMP/qmp-events.txt Data: · line 164
Quoted 4 lines
QMP/qmp-events.txt +4
-0+ +Data: + +- "name": net client name (json-string)
Maybe a device path here as well?
Quoted 35 lines
QMP/qmp-events.txt +6
-0+ +{ "event": "RX_FILTER_CHANGED", + "data": { "name": "vnet0" }, + "timestamp": { "seconds": 1368697518, "microseconds": 326866 }} +} + DEVICE_TRAY_MOVED -----------------include/monitor/monitor.h +1
-0@@ -40,6 +40,7 @@ typedef enum MonitorEvent {QEVENT_BLOCK_JOB_ERROR ,QEVENT_BLOCK_JOB_READY ,QEVENT_DEVICE_DELETED , +QEVENT_RX_FILTER_CHANGED ,QEVENT_DEVICE_TRAY_MOVED ,QEVENT_SUSPEND , QEVENT_SUSPEND_DISK,monitor.c +1
-0@@ -489,6 +489,7 @@ static const char *monitor_event_names[] = { [QEVENT_BLOCK_JOB_ERROR] = "BLOCK_JOB_ERROR", [QEVENT_BLOCK_JOB_READY] = "BLOCK_JOB_READY", [QEVENT_DEVICE_DELETED] = "DEVICE_DELETED", + [QEVENT_RX_FILTER_CHANGED] = "RX_FILTER_CHANGED", [QEVENT_DEVICE_TRAY_MOVED] = "DEVICE_TRAY_MOVED", [QEVENT_SUSPEND] = "SUSPEND", [QEVENT_SUSPEND_DISK] = "SUSPEND_DISK",Signature · 1 line
1.8.1.4
Re: [Qemu-devel] [PATCH v3 1/2] net: introduce RX_FILTER_CHANGED event
In reply to Amos KongQuoted 15 lines · Amos Kong
Introduce this new QMP event to notify management after guest changes rx-filter configuration.
Signed-off-by Amos Kong <[email protected]>--- QMP/qmp-events.txt | 14 ++++++++++++++ include/monitor/monitor.h | 1 + monitor.c | 1 + 3 files changed, 16 insertions(+)QMP/qmp-events.txt +0
-0
QMP/qmp-events.txt Data: · line 162
Quoted 9 lines
QMP/qmp-events.txt +3
-0@@ -154,6 +154,20 @@ Data: "path": "/machine/peripheral/virtio-net-pci-0" }, "timestamp": { "seconds": 1265044230, "microseconds": 450486 } } +RX_FILTER_CHANGED +----------------- + DEVICE_TRAY_MOVED -----------------
Isn't this file supposed to be kept in sorted order, to minimize merge conflicts when backporting events?
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v3 2/2] net: introduce command to query rx-filter information
In reply to Amos KongQuoted 9 lines · Amos Kong
We want to implement mac programming over macvtap through Libvirt, related rx-filter configuration contains main mac, some of rx-mode and mac-table.
The previous patch adds QMP event to notify management of rx-filter change. This patch adds a monitor command to query rx-filter information.
A flag is used to avoid events flooding, if user don't query
s/don't/doesn't/
Quoted 1 line
rx-filter after receives one event, new events won't be sent
s/after/after it/
Quoted 11 lines
to qmp monitor.
+++
b/net/net.cnet/net.c +4
-0@@ -961,6 +961,53 @@ void print_net_client(Monitor *mon, NetClientState *nc) nc->info_str); } +RxFilterInfoList *qmp_query_rx_filter (bool has_name,const char *name, +Error **errp) +{ +NetClientState *nc;
net/net.c void print_net_client(Monitor *mon, NetClientState *nc) · line 977
Quoted 10 lines
net/net.c +10
-0+RxFilterInfoList *filter_list =NULL , *last_entry =NULL ; + + QTAILQ_FOREACH(nc, &net_clients, next) { +RxFilterInfoList *entry; +RxFilterInfo *info; + +if (nc->info->type !=NET_CLIENT_OPTIONS_KIND_NIC ) { +continue ; + } +if (has_name &&strcmp (nc->name, name) !=0 ) {
Do you need the has_name argument here, or can you ensure that the caller passes NULL when the caller's has_name was false, for one less parameter and the same amount of information?
Quoted 9 lines
qapi-schema.json +5
-0+++ b/qapi-schema.json@@ -3619,3 +3619,76 @@ '*cpuid-input-ecx': 'int', 'cpuid-register': 'X86CPURegister32', 'features': 'int' } } + +## +# @RxState: +#
qapi-schema.json line 3635
Quoted 10 lines
qapi-schema.json +10
-0+# Packets receiving state +# +# @normal: filter assigned packets according to the mac-table +# +# @no: don't receive any assigned packet +# +# @all: receive all assigned packets +# +## +{ 'enum': 'RxState', 'data': [ 'normal', 'no', 'all' ] }
I think s/no/none/ would make slightly more sense (usually, you pair no/yes and none/all, not no/all).
qapi-schema.json line 3645
Quoted 10 lines
qapi-schema.json +10
-0+ +## +# @RxFilterInfo: +# +# Rx-filter information for a net client, it contains main mac, some +# of rx-mode items and mac-table. +# +# @name: net client name +# +# @promiscuous: whether to ether promiscuous mode
s/to ether//; s/$/is enabled/
Quoted 6 lines
qapi-schema.json +6
-0+# +# @multicast: multicast receive state +# +# @unicast: unicast receive state +# +# @broadcast-allowed: whether to receive broadcast
qapi-schema.json line 3661
Quoted 10 lines
qapi-schema.json +10
-0+# +# @multicast-overflow: multicast table is overflow or not +# +# @unicast-overflow: unicast table is overflow or not +# +# @main-mac: the main macaddr string +# +# @unicast-table: a list of unicast macaddr string +# +# @multicast-table: a list of multicast macaddr string
Naming is reasonable; thanks for improving things from v1.
Quoted 23 lines
qapi-schema.json +23
-0+# +# Since 1.6 +## + +{ 'type': 'RxFilterInfo', + 'data': { + 'name': 'str', + 'promiscuous': 'bool', + 'multicast': 'RxState', + 'unicast': 'RxState', + 'broadcast-allowed': 'bool', + 'multicast-overflow': 'bool', + 'unicast-overflow': 'bool', + 'main-mac': 'str', + 'unicast-table': ['str'], + 'multicast-table': ['str'] }} + +## +# @query-rx-filter: +# +# Return rx-filter information for all nics (or for the given nic). +# +# @name: #optional net client name
qapi-schema.json line 3694
Quoted 10 lines
qapi-schema.json +10
-0+# +# Returns: list of @RxFilterInfo for all nics (or for the given nic). +# Returns an error if the given @name doesn't exist, or given +# nic doesn't support rx-filter querying, or no net client +# supports rx-filter querying +# +# Since: 1.6 +## +{ 'command': 'query-rx-filter', 'data': { '*name': 'str' }, + 'returns': ['RxFilterInfo'] }
Interface looks reasonable. I didn't check the code closely, but agree with Michael's assessment that the event-suppression flag has to be per-device, not global.
qmp-commands.hx Example: · line 2959
Quoted 9 lines
qmp-commands.hx +9
-0+ +Each array entry contains the following: + +- "name": net client name (jaso-string) +- "promiscuous": enter promiscuous mode (json-bool) +- "multicast": multicast receive state (one of 'normal', 'no', 'all') +- "unicast": unicast receive state (one of 'normal', 'no', 'all') +- "broadcast-allowed": allow to receive broadcast (json-bool) +- "multicast-overflow": multicast table is overflow (json-bool)
s/is overflow/overflowed/
Quoted 1 line
+- "unicast-overflow": unicast table is overflow (json-bool)
and again
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v3 1/2] net: introduce RX_FILTER_CHANGED event
In reply to Michael S. TsirkinQuoted 19 lines · On Thu, 23 May 2013 13:24:59 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 18 lines · Amos Kong
Introduce this new QMP event to notify management after guest changes rx-filter configuration.
Signed-off-by Amos Kong <[email protected]>--- QMP/qmp-events.txt | 14 ++++++++++++++ include/monitor/monitor.h | 1 + monitor.c | 1 + 3 files changed, 16 insertions(+)QMP/qmp-events.txt +0
-0@@ -154,6 +154,20 @@ Data: "path": "/machine/peripheral/virtio-net-pci-0" }, "timestamp": { "seconds": 1265044230, "microseconds": 450486 } }
Quoted 7 lines
QMP/qmp-events.txt Data: · line 160
Quoted 4 lines
QMP/qmp-events.txt +4
-0+RX_FILTER_CHANGED +----------------- + +Emitted when rx-filter configuration is changed by the guest.Please stress this is only for the NIC. It does not apply to non-NIC netclients.
Stress it in the event name too, please. I find RX_FILTER_CHANGED a bit generic.
Also, although I haven't reviewed the next patch yet, I think you should move the event trigger to this patch.
Quoted 44 lines
QMP/qmp-events.txt Data: · line 164
Quoted 5 lines
QMP/qmp-events.txt +4
-0+ +Data: + +- "name": net client name (json-string)Maybe a device path here as well?
Quoted 35 lines
QMP/qmp-events.txt +6
-0+ +{ "event": "RX_FILTER_CHANGED", + "data": { "name": "vnet0" }, + "timestamp": { "seconds": 1368697518, "microseconds": 326866 }} +} + DEVICE_TRAY_MOVED -----------------include/monitor/monitor.h +1
-0@@ -40,6 +40,7 @@ typedef enum MonitorEvent {QEVENT_BLOCK_JOB_ERROR ,QEVENT_BLOCK_JOB_READY ,QEVENT_DEVICE_DELETED , +QEVENT_RX_FILTER_CHANGED ,QEVENT_DEVICE_TRAY_MOVED ,QEVENT_SUSPEND , QEVENT_SUSPEND_DISK,monitor.c +1
-0@@ -489,6 +489,7 @@ static const char *monitor_event_names[] = { [QEVENT_BLOCK_JOB_ERROR] = "BLOCK_JOB_ERROR", [QEVENT_BLOCK_JOB_READY] = "BLOCK_JOB_READY", [QEVENT_DEVICE_DELETED] = "DEVICE_DELETED", + [QEVENT_RX_FILTER_CHANGED] = "RX_FILTER_CHANGED", [QEVENT_DEVICE_TRAY_MOVED] = "DEVICE_TRAY_MOVED", [QEVENT_SUSPEND] = "SUSPEND", [QEVENT_SUSPEND_DISK] = "SUSPEND_DISK",Signature · 1 line
1.8.1.4
Re: [Qemu-devel] [PATCH v3 1/2] net: introduce RX_FILTER_CHANGED event
Quoted 30 lines · Luiz Capitulino
Quoted 19 lines · On Thu, 23 May 2013 13:24:59 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 18 lines · Amos Kong
Introduce this new QMP event to notify management after guest changes rx-filter configuration.
Signed-off-by Amos Kong <[email protected]>--- QMP/qmp-events.txt | 14 ++++++++++++++ include/monitor/monitor.h | 1 + monitor.c | 1 + 3 files changed, 16 insertions(+)QMP/qmp-events.txt +0
-0@@ -154,6 +154,20 @@ Data: "path": "/machine/peripheral/virtio-net-pci-0" }, "timestamp": { "seconds": 1265044230, "microseconds": 450486 } }Quoted 7 lines
QMP/qmp-events.txt Data: · line 160
Quoted 4 lines
QMP/qmp-events.txt +4
-0+RX_FILTER_CHANGED +----------------- + +Emitted when rx-filter configuration is changed by the guest.Please stress this is only for the NIC. It does not apply to non-NIC netclients.
Quoted 2 lines
Stress it in the event name too, please. I find
RX_FILTER_CHANGEDa bit generic.
What do you suggest?NIC_RX_FILTER_CHANGED ?
Quoted 2 lines
Also, although I haven't reviewed the next patch yet, I think you should move the event trigger to this patch.
That's hard because of the flag that's shared with the query command.
Quoted 44 lines
Quoted 44 lines
QMP/qmp-events.txt Data: · line 164
Quoted 5 lines
QMP/qmp-events.txt +4
-0+ +Data: + +- "name": net client name (json-string)Maybe a device path here as well?
Quoted 35 lines
QMP/qmp-events.txt +6
-0+ +{ "event": "RX_FILTER_CHANGED", + "data": { "name": "vnet0" }, + "timestamp": { "seconds": 1368697518, "microseconds": 326866 }} +} + DEVICE_TRAY_MOVED -----------------include/monitor/monitor.h +1
-0@@ -40,6 +40,7 @@ typedef enum MonitorEvent {QEVENT_BLOCK_JOB_ERROR ,QEVENT_BLOCK_JOB_READY ,QEVENT_DEVICE_DELETED , +QEVENT_RX_FILTER_CHANGED ,QEVENT_DEVICE_TRAY_MOVED ,QEVENT_SUSPEND , QEVENT_SUSPEND_DISK,monitor.c +1
-0@@ -489,6 +489,7 @@ static const char *monitor_event_names[] = { [QEVENT_BLOCK_JOB_ERROR] = "BLOCK_JOB_ERROR", [QEVENT_BLOCK_JOB_READY] = "BLOCK_JOB_READY", [QEVENT_DEVICE_DELETED] = "DEVICE_DELETED", + [QEVENT_RX_FILTER_CHANGED] = "RX_FILTER_CHANGED", [QEVENT_DEVICE_TRAY_MOVED] = "DEVICE_TRAY_MOVED", [QEVENT_SUSPEND] = "SUSPEND", [QEVENT_SUSPEND_DISK] = "SUSPEND_DISK",Signature · 1 line
1.8.1.4
Re: [Qemu-devel] [PATCH v3 1/2] net: introduce RX_FILTER_CHANGED event
Quoted 8 lines · Michael S. Tsirkin
Quoted 5 lines
Quoted 2 lines
Please stress this is only for the NIC. It does not apply to non-NIC netclients.
Stress it in the event name too, please. I find
RX_FILTER_CHANGEDa bit generic.What do you suggest?
NIC_RX_FILTER_CHANGED?
Yes, that might work. (And whatever name we bikeshed, insert it in the correct sorted order in the file)
Quoted 6 lines
Quoted 3 lines
Also, although I haven't reviewed the next patch yet, I think you should move the event trigger to this patch.
That's hard because of the flag that's shared with the query command.
It's fine if this patch declares and sets the flag, but the event is one-shot until the next patch adds the query to clear the flag. And again, the flag should be per-device, not global.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v3 1/2] net: introduce RX_FILTER_CHANGED event
Quoted 17 lines · Eric Blake
Quoted 8 lines · Michael S. Tsirkin
Quoted 5 lines
Quoted 2 lines
Please stress this is only for the NIC. It does not apply to non-NIC netclients.
Stress it in the event name too, please. I find
RX_FILTER_CHANGEDa bit generic.What do you suggest?
NIC_RX_FILTER_CHANGED?Yes, that might work. (And whatever name we bikeshed, insert it in the correct sorted order in the file)
Quoted 4 lines
Quoted 3 lines
Also, although I haven't reviewed the next patch yet, I think you should move the event trigger to this patch.
Quoted 6 lines
Quoted 2 lines
That's hard because of the flag that's shared with the query command.
It's fine if this patch declares and sets the flag, but the event is one-shot until the next patch adds the query to clear the flag. And again, the flag should be per-device, not global.
Maybe just merge both patches together. They are pretty small anyway.
Quoted 4 lines
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v3 1/2] net: introduce RX_FILTER_CHANGED event
Quoted 18 lines · On Thu, 23 May 2013 17:57:56 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 17 lines · Eric Blake
Quoted 8 lines · Michael S. Tsirkin
Quoted 5 lines
Quoted 2 lines
Please stress this is only for the NIC. It does not apply to non-NIC netclients.
Stress it in the event name too, please. I find
RX_FILTER_CHANGEDa bit generic.What do you suggest?
NIC_RX_FILTER_CHANGED?Yes, that might work. (And whatever name we bikeshed, insert it in the correct sorted order in the file)
Quoted 4 lines
Quoted 3 lines
Also, although I haven't reviewed the next patch yet, I think you should move the event trigger to this patch.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
That's hard because of the flag that's shared with the query command.
It's fine if this patch declares and sets the flag, but the event is one-shot until the next patch adds the query to clear the flag. And again, the flag should be per-device, not global.
Maybe just merge both patches together. They are pretty small anyway.
That's what I was going to suggest if it's really hard to move the event to this patch.
Re: [Qemu-devel] [PATCH v3 2/2] net: introduce command to query rx-filter information
In reply to Amos KongQuoted 23 lines · On Thu, 23 May 2013 17:08:00 +0800 Amos Kong <[email protected]> wrote:
We want to implement mac programming over macvtap through Libvirt, related rx-filter configuration contains main mac, some of rx-mode and mac-table.
The previous patch adds QMP event to notify management of rx-filter change. This patch adds a monitor command to query rx-filter information.
A flag is used to avoid events flooding, if user don't query rx-filter after receives one event, new events won't be sent to qmp monitor.
(qemu) info rx-filter vnet0
vnet0:
\ promiscuous: on
\ multicast: normal
\ unicast: normal
\ broadcast-allowed: off
\ multicast-overflow: off
\ unicast-overflow: off
\ main-mac: 52:54:00:12:34:56
\ unicast-table:
\ multicast-table:
Quoted 5 lines
01:00:5e:00:00:01 33:33:00:00:00:01 33:33:ff:12:34:56Signed-off-by Amos Kong <[email protected]>
Looks good in general. I have some comments below and restarted the dicussion about notify_enabled.
Quoted 35 lines
--- hmp-commands.hx | 2 ++ hmp.c | 49 ++++++++++++++++++++++++++++ hmp.h | 1 + hw/net/virtio-net.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++ include/net/net.h | 2 ++ monitor.c | 8 +++++ net/net.c | 47 +++++++++++++++++++++++++++ qapi-schema.json | 73 +++++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 55 +++++++++++++++++++++++++++++++ 9 files changed, 330 insertions(+)hmp-commands.hx +2
-0@@ -1639,6 +1639,8 @@ show qdev device model list show roms @item info tpm show the TPM device +@item info rx-filter [net client name] +show the rx-filter information for all nics (or for the given nic) @end table ETEXIhmp.c +2
-0@@ -653,6 +653,55 @@ void hmp_info_tpm(Monitor *mon, const QDict *qdict)qapi_free_TPMInfoList (info_list); } +void hmp_info_rx_filter (Monitor *mon,const QDict *qdict) +{
hmp.c void hmp_info_tpm(Monitor *mon, const QDict *qdict) · line 667
Quoted 10 lines
hmp.c +10
-0+RxFilterInfoList *filter_list, *entry; +strList *str_entry; +bool has_name =qdict_haskey (qdict,"name" ); +const char *name =NULL ; + +if (has_name) { + name =qdict_get_str (qdict,"name" ); + } + + filter_list =qmp_query_rx_filter (has_name, name,NULL );
qmp_query_rx_filter() can fail.
Quoted 21 lines
hmp.c +21
-0+ entry = filter_list; + +while (entry) { +monitor_printf (mon,"%s:\n" , entry->value->name); +monitor_printf (mon," \\ promiscuous: %s\n" , + entry->value->promiscuous ?"on" :"off" ); +monitor_printf (mon," \\ multicast: %s\n" , + RxState_lookup[entry->value->multicast]); +monitor_printf (mon," \\ unicast: %s\n" , + RxState_lookup[entry->value->unicast]); +monitor_printf (mon," \\ broadcast-allowed: %s\n" , + entry->value->broadcast_allowed ?"on" :"off" ); +monitor_printf (mon," \\ multicast-overflow: %s\n" , + entry->value->multicast_overflow ?"on" :"off" ); +monitor_printf (mon," \\ unicast-overflow: %s\n" , + entry->value->unicast_overflow ?"on" :"off" ); +monitor_printf (mon," \\ main-mac: %s\n" , entry->value->main_mac); + + str_entry = entry->value->unicast_table; +monitor_printf (mon," \\ unicast-table:\n" ); +while (str_entry) {
hmp.c void hmp_info_tpm(Monitor *mon, const QDict *qdict) · line 698
Quoted 10 lines
hmp.c +10
-0+monitor_printf (mon," %s\n" , str_entry->value); + str_entry = str_entry->next; + } + + str_entry = entry->value->multicast_table; +monitor_printf (mon," \\ multicast-table:\n" ); +while (str_entry) { +monitor_printf (mon," %s\n" , str_entry->value); + str_entry = str_entry->next; + }
Can't that loop be moved to a function?
Quoted 213 lines
hmp.c +6
-0+ + entry = entry->next; + } +qapi_free_RxFilterInfoList (filter_list); +} +void hmp_quit (Monitor *mon,const QDict *qdict) {monitor_suspend (mon);hmp.h +1
-0@@ -37,6 +37,7 @@ void hmp_info_balloon(Monitor *mon, const QDict *qdict);void hmp_info_pci (Monitor *mon,const QDict *qdict);void hmp_info_block_jobs (Monitor *mon,const QDict *qdict);void hmp_info_tpm (Monitor *mon,const QDict *qdict); +void hmp_info_rx_filter (Monitor *mon,const QDict *qdict);void hmp_quit (Monitor *mon,const QDict *qdict);void hmp_stop (Monitor *mon,const QDict *qdict);void hmp_system_reset (Monitor *mon,const QDict *qdict);hw/net/virtio-net.c +93
-0@@ -21,6 +21,8 @@#include "hw/virtio/virtio-net.h" #include "net/vhost_net.h" #include "hw/virtio/virtio-bus.h" +#include "qapi/qmp/qjson.h" +#include "monitor/monitor.h" #define VIRTIO_NET_VM_VERSION 11@@ -192,6 +194,90 @@ static void virtio_net_set_link_status(NetClientState *nc)virtio_net_set_status (vdev, vdev->status); } +static bool notify_enabled = true; + +static void rxfilter_notify (const char *name) +{ +QObject *event_data; + +if (notify_enabled) { + event_data =qobject_from_jsonf ("{ 'name': %s }" , name); +monitor_protocol_event (QEVENT_RX_FILTER_CHANGED , event_data); +qobject_decref (event_data); +/* disable event notification to avoid events flooding */ + notify_enabled = false; + } +} + +static RxFilterInfo *virtio_net_query_rxfilter (NetClientState *nc) +{ +VirtIONet *n =qemu_get_nic_opaque (nc); +RxFilterInfo *info; +strList *str_list =NULL ; +strList *entry; +int i; + + info =g_malloc0 (sizeof (*info)); + info->name =g_strdup (nc->name); + info->promiscuous = n->promisc; + +if (n->nouni) { + info->unicast =RX_STATE_NO ; + }else if (n->alluni) { + info->unicast =RX_STATE_ALL ; + }else { + info->unicast =RX_STATE_NORMAL ; + } + +if (n->nomulti) { + info->multicast =RX_STATE_NO ; + }else if (n->allmulti) { + info->multicast =RX_STATE_ALL ; + }else { + info->multicast =RX_STATE_NORMAL ; + } + + info->broadcast_allowed = n->nobcast; + info->multicast_overflow = n->mac_table.multi_overflow; + info->unicast_overflow = n->mac_table.uni_overflow; + info->main_mac =g_strdup_printf ("%.2x:%.2x:%.2x:%.2x:%.2x:%.2x" , + n->mac[0 ], n->mac[1 ], n->mac[2 ], + n->mac[3 ], n->mac[4 ], n->mac[5 ]); + +for (i =0 ; i < n->mac_table.first_multi; i++) { + entry =g_malloc0 (sizeof (*entry)); + entry->value =g_strdup_printf ("%.2x:%.2x:%.2x:%.2x:%.2x:%.2x" , + n->mac_table.macs[i *ETH_ALEN ], + n->mac_table.macs[i *ETH_ALEN +1 ], + n->mac_table.macs[i *ETH_ALEN +2 ], + n->mac_table.macs[i *ETH_ALEN +3 ], + n->mac_table.macs[i *ETH_ALEN +4 ], + n->mac_table.macs[i *ETH_ALEN +5 ]); + entry->next = str_list; + str_list = entry; + } + info->unicast_table = str_list; + + str_list =NULL ; +for (i = n->mac_table.first_multi; i < n->mac_table.in_use; i++) { + entry =g_malloc0 (sizeof (*entry)); + entry->value =g_strdup_printf ("%.2x:%.2x:%.2x:%.2x:%.2x:%.2x" , + n->mac_table.macs[i *ETH_ALEN ], + n->mac_table.macs[i *ETH_ALEN +1 ], + n->mac_table.macs[i *ETH_ALEN +2 ], + n->mac_table.macs[i *ETH_ALEN +3 ], + n->mac_table.macs[i *ETH_ALEN +4 ], + n->mac_table.macs[i *ETH_ALEN +5 ]); + entry->next = str_list; + str_list = entry; + } + info->multicast_table = str_list; +/* enable event notification after query */ + notify_enabled = true; + +return info; +} +static void virtio_net_reset (VirtIODevice *vdev) {VirtIONet *n =VIRTIO_NET (vdev);@@ -442,6 +528,8 @@ static int virtio_net_handle_rx_mode(VirtIONet *n, uint8_t cmd,return VIRTIO_NET_ERR ; } +rxfilter_notify (n->netclient_name); +return VIRTIO_NET_OK ; }@@ -495,6 +583,8 @@ static int virtio_net_handle_mac(VirtIONet *n, uint8_t cmd, s =iov_to_buf (iov, iov_cnt,0 , &n->mac,sizeof (n->mac));assert (s ==sizeof (n->mac));qemu_format_nic_info_str (qemu_get_queue (n->nic), n->mac); +rxfilter_notify (n->netclient_name); +return VIRTIO_NET_OK ; }@@ -559,6 +649,8 @@ static int virtio_net_handle_mac(VirtIONet *n, uint8_t cmd, n->mac_table.multi_overflow =1 ; } +rxfilter_notify (n->netclient_name); +return VIRTIO_NET_OK ; }@@ -1312,6 +1404,7 @@ static NetClientInfo net_virtio_info = { .receive = virtio_net_receive, .cleanup = virtio_net_cleanup, .link_status_changed = virtio_net_set_link_status, + .query_rx_filter = virtio_net_query_rxfilter, };static bool virtio_net_guest_notifier_pending (VirtIODevice *vdev,int idx)include/net/net.h +2
-0@@ -49,6 +49,7 @@ typedef ssize_t (NetReceiveIOV)(NetClientState *, const struct iovec *, int);typedef void (NetCleanup ) (NetClientState *);typedef void (LinkStatusChanged )(NetClientState *);typedef void (NetClientDestructor )(NetClientState *); +typedef RxFilterInfo *(QueryRxFilter )(NetClientState *); typedef struct NetClientInfo { NetClientOptionsKind type;@@ -59,6 +60,7 @@ typedef struct NetClientInfo {NetCanReceive *can_receive;NetCleanup *cleanup;LinkStatusChanged *link_status_changed; +QueryRxFilter *query_rx_filter;NetPoll *poll; } NetClientInfo;monitor.c +8
-0@@ -2764,6 +2764,14 @@ static mon_cmd_t info_cmds[] = { .mhandler.cmd = hmp_info_tpm, }, { + .name = "rx-filter", + .args_type = "name:s?", + .params = "[net client name]", + .help = "show the rx-filter information for all nics (or" + " for the given nic)", + .mhandler.cmd = hmp_info_rx_filter, + }, + { .name = NULL, }, };net/net.c +6
-0@@ -961,6 +961,53 @@ void print_net_client(Monitor *mon, NetClientState *nc) nc->info_str); } +RxFilterInfoList *qmp_query_rx_filter (bool has_name,const char *name, +Error **errp) +{ +NetClientState *nc; +RxFilterInfoList *filter_list =NULL , *last_entry =NULL ; +
net/net.c void print_net_client(Monitor *mon, NetClientState *nc) · line 979
Quoted 10 lines
net/net.c +10
-0+ QTAILQ_FOREACH(nc, &net_clients, next) { +RxFilterInfoList *entry; +RxFilterInfo *info; + +if (nc->info->type !=NET_CLIENT_OPTIONS_KIND_NIC ) { +continue ; + } +if (has_name &&strcmp (nc->name, name) !=0 ) { +continue ; + }
I don't think we need this argument. This command is quite simple in its response, let's do this filtering in HMP only.
Quoted 178 lines
net/net.c +31
-0+ +if (nc->info->query_rx_filter) { + info = nc->info->query_rx_filter (nc); + entry =g_malloc0 (sizeof (*entry)); + entry->value = info; + +if (!filter_list) { + filter_list = entry; + }else { + last_entry->next = entry; + } + last_entry = entry; + }else if (has_name) { +error_setg (errp,"net client(%s) doesn't support" +" rx-filter querying" , name); +break ; + } + + } + +if (filter_list ==NULL && !error_is_set (errp)) { +if (has_name) { +error_setg (errp,"invalid net client name: %s" , name); + }else { +error_setg (errp,"no net client supports rx-filter querying" ); + } + } + +return filter_list; +} +void do_info_network (Monitor *mon,const QDict *qdict) {NetClientState *nc, *peer;qapi-schema.json +73
-0@@ -3619,3 +3619,76 @@ '*cpuid-input-ecx': 'int', 'cpuid-register': 'X86CPURegister32', 'features': 'int' } } + +## +# @RxState: +# +# Packets receiving state +# +# @normal: filter assigned packets according to the mac-table +# +# @no: don't receive any assigned packet +# +# @all: receive all assigned packets +# +## +{ 'enum': 'RxState', 'data': [ 'normal', 'no', 'all' ] } + +## +# @RxFilterInfo: +# +# Rx-filter information for a net client, it contains main mac, some +# of rx-mode items and mac-table. +# +# @name: net client name +# +# @promiscuous: whether to ether promiscuous mode +# +# @multicast: multicast receive state +# +# @unicast: unicast receive state +# +# @broadcast-allowed: whether to receive broadcast +# +# @multicast-overflow: multicast table is overflow or not +# +# @unicast-overflow: unicast table is overflow or not +# +# @main-mac: the main macaddr string +# +# @unicast-table: a list of unicast macaddr string +# +# @multicast-table: a list of multicast macaddr string +# +# Since 1.6 +## + +{ 'type': 'RxFilterInfo', + 'data': { + 'name': 'str', + 'promiscuous': 'bool', + 'multicast': 'RxState', + 'unicast': 'RxState', + 'broadcast-allowed': 'bool', + 'multicast-overflow': 'bool', + 'unicast-overflow': 'bool', + 'main-mac': 'str', + 'unicast-table': ['str'], + 'multicast-table': ['str'] }} + +## +# @query-rx-filter: +# +# Return rx-filter information for all nics (or for the given nic). +# +# @name: #optional net client name +# +# Returns: list of @RxFilterInfo for all nics (or for the given nic). +# Returns an error if the given @name doesn't exist, or given +# nic doesn't support rx-filter querying, or no net client +# supports rx-filter querying +# +# Since: 1.6 +## +{ 'command': 'query-rx-filter', 'data': { '*name': 'str' }, + 'returns': ['RxFilterInfo'] }qmp-commands.hx +55
-0@@ -2932,3 +2932,58 @@ Example: <- { "return": {} } EQMP + { + .name = "query-rx-filter", + .args_type = "name:s?", + .mhandler.cmd_new = qmp_marshal_input_query_rx_filter, + }, + +SQMP +query-rx-filter +--------------- + +Show rx-filter information. + +Returns a json-array of rx-filter information for all nics (or for the +given nic), returning an error if the given nic doesn't exist, or +given nic doesn't support rx-filter querying, or no net client +supports rx-filter querying. + +Each array entry contains the following: + +- "name": net client name (jaso-string) +- "promiscuous": enter promiscuous mode (json-bool) +- "multicast": multicast receive state (one of 'normal', 'no', 'all') +- "unicast": unicast receive state (one of 'normal', 'no', 'all') +- "broadcast-allowed": allow to receive broadcast (json-bool) +- "multicast-overflow": multicast table is overflow (json-bool) +- "unicast-overflow": unicast table is overflow (json-bool) +- "main-mac": main macaddr string (jaso-string) +- "unicast-table": a json-array of unicast macaddr string +- "multicast-table": a json-array of multicast macaddr string + +Example: + +-> { "execute": "query-rx-filter", "arguments": { "name": "vnet0" }} +<- { "return": [ + { + "promiscuous": true, + "name": "vnet0", + "main-mac": "52:54:00:12:34:56", + "unicast": "normal", + "unicast-table": [ + ], + "multicast": "normal", + "multicast-overflow": false, + "unicast-overflow": false, + "multicast-table": [ + "01:00:5e:00:00:01", + "33:33:00:00:00:01", + "33:33:ff:12:34:56" + ], + "broadcast-allowed": false + } + ] + } + +EQMP
Re: [Qemu-devel] [PATCH v3 2/2] net: introduce command to query rx-filter information
In reply to Eric BlakeQuoted 11 lines · Eric Blake
Quoted 9 lines · Amos Kong
net/net.c +9
-0+RxFilterInfoList *qmp_query_rx_filter (bool has_name,const char *name, +Error **errp) +{ +NetClientState *nc; +RxFilterInfoList *filter_list =NULL , *last_entry =NULL ; + + QTAILQ_FOREACH(nc, &net_clients, next) { +RxFilterInfoList *entry; +RxFilterInfo *info;
Quoted 8 lines
net/net.c void print_net_client(Monitor *mon, NetClientState *nc) · line 977
Quoted 5 lines
net/net.c +5
-0+ +if (nc->info->type !=NET_CLIENT_OPTIONS_KIND_NIC ) { +continue ; + } +if (has_name &&strcmp (nc->name, name) !=0 ) {Do you need the
has_nameargument here, or can you ensure that the caller passes NULL when the caller'shas_namewas false,
hmp_info_rx_filter() passes NULL name when has_name is false. 'has_name' is need here. Or we can change it to:
if (name && strcmp(nc->name, name) != 0) { I think using 'has_name' is clearer.
Quoted 1 line
for one less parameter and the same amount of information?
qmp_query_rx_filter() define is generated by QAPI infrastructure, the parameters are fixed. We also use it in hmp_info_rx_filter().
Signature · 1 line
Amos.
Re: [Qemu-devel] [PATCH v3 2/2] net: introduce command to query rx-filter information
In reply to Luiz CapitulinoQuoted 19 lines · Luiz Capitulino
Quoted 16 lines · On Thu, 23 May 2013 17:08:00 +0800 Amos Kong <[email protected]> wrote:
A flag is used to avoid events flooding, if user don't query rx-filter after receives one event, new events won't be sent to qmp monitor.
net/net.c +11
-0+RxFilterInfoList *qmp_query_rx_filter (bool has_name,const char *name, +Error **errp) +{ +NetClientState *nc; +RxFilterInfoList *filter_list =NULL , *last_entry =NULL ; + + QTAILQ_FOREACH(nc, &net_clients, next) { +RxFilterInfoList *entry; +RxFilterInfo *info; + +if (nc->info->type !=NET_CLIENT_OPTIONS_KIND_NIC ) {
Quoted 8 lines
net/net.c void print_net_client(Monitor *mon, NetClientState *nc) · line 979
Quoted 5 lines
net/net.c +5
-0+continue ; + } +if (has_name &&strcmp (nc->name, name) !=0 ) { +continue ; + }I don't think we need this argument. This command is quite simple in its response, let's do this filtering in HMP only.
Event message contains the net client name, management might only want to query the single net client.
And we plan to use a flag for _each nic_ to control the event notification, querying single net client will only clear it's flag.
So we need to support query by net-client-name.
Signature · 1 line
Amos.
Re: [Qemu-devel] [PATCH v3 1/2] net: introduce RX_FILTER_CHANGED event
In reply to Luiz CapitulinoQuoted 8 lines · Luiz Capitulino
Quoted 5 lines · On Thu, 23 May 2013 17:57:56 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 4 lines · Eric Blake
Quoted 3 lines · Michael S. Tsirkin
Quoted 3 lines
Quoted 2 lines
Please stress this is only for the NIC. It does not apply to non-NIC netclients.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Stress it in the event name too, please. I find
RX_FILTER_CHANGEDa bit generic.What do you suggest?
NIC_RX_FILTER_CHANGED?Yes, that might work. (And whatever name we bikeshed, insert it in the correct sorted order in the file)
Reasonable.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines
Also, although I haven't reviewed the next patch yet, I think you should move the event trigger to this patch.
That's hard because of the flag that's shared with the query command.
It's fine if this patch declares and sets the flag, but the event is one-shot until the next patch adds the query to clear the flag. And again, the flag should be per-device, not global.
It works.
Quoted 4 lines
Quoted 1 line
Maybe just merge both patches together. They are pretty small anyway.
That's what I was going to suggest if it's really hard to move the event to this patch.
Ok, I will merge those two patches together, and give a detail/whole description in one patch.
Signature · 1 line
Amos.
Re: [Qemu-devel] [PATCH v3 2/2] net: introduce command to query rx-filter information
In reply to Michael S. TsirkinQuoted 10 lines · Michael S. Tsirkin
hw/net/virtio-net.c static void virtio_net_set_link_status(NetClientState *nc) · line 245
Quoted 6 lines · Amos Kong
hw/net/virtio-net.c +6
-0+ info->broadcast_allowed = n->nobcast; + info->multicast_overflow = n->mac_table.multi_overflow; + info->unicast_overflow = n->mac_table.uni_overflow; + info->main_mac =g_strdup_printf ("%.2x:%.2x:%.2x:%.2x:%.2x:%.2x" , + n->mac[0 ], n->mac[1 ], n->mac[2 ], + n->mac[3 ], n->mac[4 ], n->mac[5 ]);We really want a helper for this
g_strdup_printfthing IMO.
entry->value = mac_strdup_printf(n->mac_table.macs + i * ETH_ALEN);
static char *mac_strdup_printf(uint8_t *mac)
{
return g_strdup_printf("%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", mac[0],
mac[1], mac[2], mac[3], mac[4], mac[5]);
}Signature · 1 line
Amos.
Re: [Qemu-devel] [PATCH v3 2/2] net: introduce command to query rx-filter information
In reply to Amos KongQuoted 29 lines · On Fri, 24 May 2013 11:08:13 +0800 Amos Kong <[email protected]> wrote:
Quoted 19 lines · Luiz Capitulino
Quoted 16 lines · On Thu, 23 May 2013 17:08:00 +0800 Amos Kong <[email protected]> wrote:
A flag is used to avoid events flooding, if user don't query rx-filter after receives one event, new events won't be sent to qmp monitor.
net/net.c +11
-0+RxFilterInfoList *qmp_query_rx_filter (bool has_name,const char *name, +Error **errp) +{ +NetClientState *nc; +RxFilterInfoList *filter_list =NULL , *last_entry =NULL ; + + QTAILQ_FOREACH(nc, &net_clients, next) { +RxFilterInfoList *entry; +RxFilterInfo *info; + +if (nc->info->type !=NET_CLIENT_OPTIONS_KIND_NIC ) {Quoted 8 lines
net/net.c void print_net_client(Monitor *mon, NetClientState *nc) · line 979
Quoted 5 lines
net/net.c +5
-0+continue ; + } +if (has_name &&strcmp (nc->name, name) !=0 ) { +continue ; + }I don't think we need this argument. This command is quite simple in its response, let's do this filtering in HMP only.
Quoted 2 lines
Event message contains the net client name, management might only want to query the single net client.
The client can do the filtering itself.
Quoted 6 lines
And we plan to use a flag for
_eachnic_to control the event notification, querying single net client will only clear it's flag.So we need to support query by net-client-name.
Re: [Qemu-devel] [PATCH v3 2/2] net: introduce command to query rx-filter information
Quoted 7 lines · Luiz Capitulino
Quoted 5 lines
Quoted 2 lines
I don't think we need this argument. This command is quite simple in its response, let's do this filtering in HMP only.
Event message contains the net client name, management might only want to query the single net client.
The client can do the filtering itself.
If we're arguing that we want this to be as responsive as possible, then the less data we send over the wire, the faster management can react to the guest's request for a particular NIC. That is, if libvirt is listening to events that says NIC2 wants to change rx-filter, libvirt would rather do a filtered query where it knows the JSON array of 1 element matches NIC2 data, rather than do a global query and search through the returned array until it finds NIC2.
Filtering is relatively easy to add, whether you do it in QMP or make every client add it. Libvirt will survive if you don't have filtering, but I don't see why we can't have it in QMP. Also, if you DO decide to rip filtering out of QMP, you STILL need to keep a per-NIC flag. Since the events say which NIC is requesting a change, even if the query reads all nics, libvirt will only change the macvtap settings of the nic(s) for which it has received an event (it doesn't make sense to waste time requesting a (no-op) change to macvtap settings on a nic that hasn't requested a change). But if you argue that having no filtering in the QMP command means that you can get away with a single flag instead of a per-nic flag, then you will fail to emit an event for NIC2 if it changes in between the time that NIC1 fired an event and libvirt finally does the query, and libvirt wouldn't realize that NIC2 also needs a macvtap change.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v3 2/2] net: introduce command to query rx-filter information
Quoted 9 lines · On Fri, 24 May 2013 06:55:44 -0600 Eric Blake <[email protected]> wrote:
Quoted 7 lines · Luiz Capitulino
Quoted 5 lines
Quoted 2 lines
I don't think we need this argument. This command is quite simple in its response, let's do this filtering in HMP only.
Event message contains the net client name, management might only want to query the single net client.
The client can do the filtering itself.
Quoted 7 lines
If we're arguing that we want this to be as responsive as possible, then the less data we send over the wire, the faster management can react to the guest's request for a particular NIC. That is, if libvirt is listening to events that says NIC2 wants to change rx-filter, libvirt would rather do a filtered query where it knows the JSON array of 1 element matches NIC2 data, rather than do a global query and search through the returned array until it finds NIC2.
This sounds like premature optimization to me, but I wonder if instead of cluttering commands with arguments to do the filtering we could add some standard way of doing this in the QAPI.
It was you who suggested a filter command?
Quoted 15 lines
Filtering is relatively easy to add, whether you do it in QMP or make every client add it. Libvirt will survive if you don't have filtering, but I don't see why we can't have it in QMP. Also, if you DO decide to rip filtering out of QMP, you STILL need to keep a per-NIC flag. Since the events say which NIC is requesting a change, even if the query reads all nics, libvirt will only change the macvtap settings of the nic(s) for which it has received an event (it doesn't make sense to waste time requesting a (no-op) change to macvtap settings on a nic that hasn't requested a change). But if you argue that having no filtering in the QMP command means that you can get away with a single flag instead of a per-nic flag, then you will fail to emit an event for NIC2 if it changes in between the time that NIC1 fired an event and libvirt finally does the query, and libvirt wouldn't realize that NIC2 also needs a macvtap change.
Re: [Qemu-devel] [PATCH v3 2/2] net: introduce command to query rx-filter information
Quoted 3 lines · Luiz Capitulino
This sounds like premature optimization to me, but I wonder if instead of cluttering commands with arguments to do the filtering we could add some standard way of doing this in the QAPI.
Maybe we could make QAPI support generic filtering for all query-* commands. But there's still a cost with making all query-* commands malloc the space for an entire list only to then have a QAPI layer on top of it do filtering before handing back the single element over the wire, compared to passing the filtering down to the query-* implementation to do the filtering in place.
Quoted 2 lines
It was you who suggested a filter command?
No, Stefan suggested it on v1:
https://lists.gnu.org/archive/html/qemu-devel/2013-04/msg03102.html
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v3 2/2] net: introduce command to query rx-filter information
In reply to Eric BlakeQuoted 17 lines · Eric Blake
Quoted 7 lines · Luiz Capitulino
Quoted 5 lines
Quoted 2 lines
I don't think we need this argument. This command is quite simple in its response, let's do this filtering in HMP only.
Event message contains the net client name, management might only want to query the single net client.
The client can do the filtering itself.
If we're arguing that we want this to be as responsive as possible, then the less data we send over the wire, the faster management can react to the guest's request for a particular NIC. That is, if libvirt is listening to events that says NIC2 wants to change rx-filter, libvirt would rather do a filtered query where it knows the JSON array of 1 element matches NIC2 data, rather than do a global query and search through the returned array until it finds NIC2.
Quoted 14 lines
Filtering is relatively easy to add, whether you do it in QMP or make every client add it. Libvirt will survive if you don't have filtering, but I don't see why we can't have it in QMP. Also, if you DO decide to rip filtering out of QMP, you STILL need to keep a per-NIC flag. Since the events say which NIC is requesting a change, even if the query reads all nics, libvirt will only change the macvtap settings of the nic(s) for which it has received an event (it doesn't make sense to waste time requesting a (no-op) change to macvtap settings on a nic that hasn't requested a change). But if you argue that having no filtering in the QMP command means that you can get away with a single flag instead of a per-nic flag, then you will fail to emit an event for NIC2 if it changes in between the time that NIC1 fired an event and libvirt finally does the query, and libvirt wouldn't realize that NIC2 also needs a macvtap change.
No disagreement on the need for a per-NIC flag.
I'm not sure I buy the responsiveness argument. Sure, the fastest I/O is no I/O, but whether you read and parse 100 bytes or 1000 from a Unix domain socket once in a great while shouldn't make a difference.
My main concern is to keep the external interface simple. I'm rather reluctant to have query commands grow options.
In a case where we need the "give me everything" query anyway, the "give me this particular part" option is additional complexity. Needs justification, say arguments involving throughput, latency or client complexity.
Perhaps cases exist where we never want to ask for everything. Then the "give me everything" query is useless, and the option should be mandatory.
Re: [Qemu-devel] [PATCH v3 2/2] net: introduce command to query rx-filter information
Quoted 43 lines · Markus Armbruster
Quoted 17 lines · Eric Blake
Quoted 7 lines · Luiz Capitulino
Quoted 5 lines
Quoted 2 lines
I don't think we need this argument. This command is quite simple in its response, let's do this filtering in HMP only.
Event message contains the net client name, management might only want to query the single net client.
The client can do the filtering itself.
If we're arguing that we want this to be as responsive as possible, then the less data we send over the wire, the faster management can react to the guest's request for a particular NIC. That is, if libvirt is listening to events that says NIC2 wants to change rx-filter, libvirt would rather do a filtered query where it knows the JSON array of 1 element matches NIC2 data, rather than do a global query and search through the returned array until it finds NIC2.
Quoted 14 lines
Filtering is relatively easy to add, whether you do it in QMP or make every client add it. Libvirt will survive if you don't have filtering, but I don't see why we can't have it in QMP. Also, if you DO decide to rip filtering out of QMP, you STILL need to keep a per-NIC flag. Since the events say which NIC is requesting a change, even if the query reads all nics, libvirt will only change the macvtap settings of the nic(s) for which it has received an event (it doesn't make sense to waste time requesting a (no-op) change to macvtap settings on a nic that hasn't requested a change). But if you argue that having no filtering in the QMP command means that you can get away with a single flag instead of a per-nic flag, then you will fail to emit an event for NIC2 if it changes in between the time that NIC1 fired an event and libvirt finally does the query, and libvirt wouldn't realize that NIC2 also needs a macvtap change.
No disagreement on the need for a per-NIC flag.
I'm not sure I buy the responsiveness argument. Sure, the fastest I/O is no I/O, but whether you read and parse 100 bytes or 1000 from a Unix domain socket once in a great while shouldn't make a difference.
My main concern is to keep the external interface simple. I'm rather reluctant to have query commands grow options.
Quoted 8 lines
In a case where we need the "give me everything" query anyway, the "give me this particular part" option is additional complexity. Needs justification, say arguments involving throughput, latency or client complexity.
Perhaps cases exist where we never want to ask for everything. Then the "give me everything" query is useless, and the option should be mandatory.
We need the query for macvtap devices. We don't need it for tap devices. In that case you don't want tap device info.
Maybe some libvirt guys can tell us whether they prefer a per device query or a global one with info for all NICs?
I think for HMP it's best to have nic optional. Is it a good idea to make QMP match HMP closely?
Signature · 1 line
MST
Re: [Qemu-devel] [PATCH v3 2/2] net: introduce command to query rx-filter information
Quoted 10 lines · Michael S. Tsirkin
Quoted 10 lines
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines
Event message contains the net client name, management might only want to query the single net client.
The client can do the filtering itself.
I'm not sure I buy the responsiveness argument. Sure, the fastest I/O is no I/O, but whether you read and parse 100 bytes or 1000 from a Unix domain socket once in a great while shouldn't make a difference.
And the time spent malloc'ing the larger message to send from qemu, as well as the time spent malloc'ing the libvirt side that parses the qemu string into C code for use, and the time spent strcmp'ing every entry to find the right one...
It really IS more efficient to filter as low down in the stack as possible, once it is determined that filtering is desirable.
Whether filtering makes a difference in performance is a different question - you may be right that always returning the entire list and making libvirt do its own filtering will still not add any more noticeable delay compared to libvirt doing a filtered query, if the bottleneck lies elsewhere (such as libvirt telling macvtap its new configration).
Quoted 4 lines
Quoted 4 lines
My main concern is to keep the external interface simple. I'm rather reluctant to have query commands grow options.
Quoted 8 lines
Quoted 8 lines
In a case where we need the "give me everything" query anyway, the "give me this particular part" option is additional complexity. Needs justification, say arguments involving throughput, latency or client complexity.
Perhaps cases exist where we never want to ask for everything. Then the "give me everything" query is useless, and the option should be mandatory.
For this _particular_ interface, I'm not sure whether libvirt will ever use an unfiltered query - that is, the rx-filter query will probably always be invoked in response to an event, at which point libvirt only cares about the filter status of the nic named in the event. And ultimately libvirt knows what nics it passed to the guest, so even if there isn't a global query and I guessed wrong about libvirt never wanting all state at once, it would still be possible for libvirt to iterate over one query per nic. On the other hand, consistency with other query-* QMP commands says that most of them return as much information as possible all the time, and generally libvirt likes this - even the newly-added query-command-line-options has a filtering option, but current libvirt.git only uses it once in global mode rather than once-per-option in filtered mode.
Quoted 6 lines
We need the query for macvtap devices. We don't need it for tap devices. In that case you don't want tap device info.
Maybe some libvirt guys can tell us whether they prefer a per device query or a global one with info for all NICs?
Libvirt can cope either way. I personally like the idea of allowing both global and filtered queries, without second-guessing what management apps will prefer to use, and don't think filtering adds that much complexity. But if you want to insist on avoiding filtering, I'd rather have a global query than a mandatory name argument, for consistency with other query-* commands, even if libvirt then ends up doing its own filtering.
If we get introspection into qemu 1.6 at the same time as the new query for rx-filters, it really won't matter whether you start with global-only or mandatory name-only; either way, if we change our mind and add the other mode in qemu 1.7, libvirt will still be able to use introspection to determine whether the argument is present in one direction (going from global-only to optional filtering), or whether the argument has been made optionl in the other direction (going from mandatory name to optional global).
Quoted 1 line
I think for HMP it's best to have nic optional.
This is true, no matter what we decide for QMP.
Quoted 1 line
Is it a good idea to make QMP match HMP closely?
QMP has to provide enough information for HMP to do its job. How will HMP do global listing if QMP doesn't provide a way to get all the devices at once? Remember, libvirt knows what devices it told qemu to create, but I don't know that HMP has the same visibility into the list of possible devices that can be queried. So you may need a global mode to begin with.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v3 2/2] net: introduce command to query rx-filter information
Quoted 36 lines · On Fri, 24 May 2013 12:05:12 -0600 Eric Blake <[email protected]> wrote:
Quoted 10 lines · Michael S. Tsirkin
Quoted 10 lines
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines
Event message contains the net client name, management might only want to query the single net client.
The client can do the filtering itself.
I'm not sure I buy the responsiveness argument. Sure, the fastest I/O is no I/O, but whether you read and parse 100 bytes or 1000 from a Unix domain socket once in a great while shouldn't make a difference.
And the time spent malloc'ing the larger message to send from qemu, as well as the time spent malloc'ing the libvirt side that parses the qemu string into C code for use, and the time spent strcmp'ing every entry to find the right one...
It really IS more efficient to filter as low down in the stack as possible, once it is determined that filtering is desirable.
Whether filtering makes a difference in performance is a different question - you may be right that always returning the entire list and making libvirt do its own filtering will still not add any more noticeable delay compared to libvirt doing a filtered query, if the bottleneck lies elsewhere (such as libvirt telling macvtap its new configration).
Quoted 9 lines
Quoted 9 lines
My main concern is to keep the external interface simple. I'm rather reluctant to have query commands grow options.
In a case where we need the "give me everything" query anyway, the "give me this particular part" option is additional complexity. Needs justification, say arguments involving throughput, latency or client complexity.
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
Perhaps cases exist where we never want to ask for everything. Then the "give me everything" query is useless, and the option should be mandatory.
For this _particular_ interface, I'm not sure whether libvirt will ever use an unfiltered query -
If having the argument is useful for libvirt, then it's fine to have it.
But I'd be very reluctant to buy any performance argument w/o real numbers to back them up.
Re: [Qemu-devel] [PATCH v3 2/2] net: introduce command to query rx-filter information
Quoted 43 lines · Luiz Capitulino
Quoted 40 lines · On Fri, 24 May 2013 12:05:12 -0600 Eric Blake <[email protected]> wrote:
Quoted 10 lines · Michael S. Tsirkin
Quoted 10 lines
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines
Event message contains the net client name, management might only want to query the single net client.
The client can do the filtering itself.
I'm not sure I buy the responsiveness argument. Sure, the fastest I/O is no I/O, but whether you read and parse 100 bytes or 1000 from a Unix domain socket once in a great while shouldn't make a difference.
And the time spent malloc'ing the larger message to send from qemu, as well as the time spent malloc'ing the libvirt side that parses the qemu string into C code for use, and the time spent strcmp'ing every entry to find the right one...
It really IS more efficient to filter as low down in the stack as possible, once it is determined that filtering is desirable.
Whether filtering makes a difference in performance is a different question - you may be right that always returning the entire list and making libvirt do its own filtering will still not add any more noticeable delay compared to libvirt doing a filtered query, if the bottleneck lies elsewhere (such as libvirt telling macvtap its new configration).
Quoted 12 lines
Quoted 12 lines
My main concern is to keep the external interface simple. I'm rather reluctant to have query commands grow options.
In a case where we need the "give me everything" query anyway, the "give me this particular part" option is additional complexity. Needs justification, say arguments involving throughput, latency or client complexity.
Perhaps cases exist where we never want to ask for everything. Then the "give me everything" query is useless, and the option should be mandatory.
Quoted 7 lines
Quoted 2 lines
For this _particular_ interface, I'm not sure whether libvirt will ever use an unfiltered query -
If having the argument is useful for libvirt, then it's fine to have it.
But I'd be very reluctant to buy any performance argument w/o real numbers to back them up.
Me too. I think it's more convenience than performance.
Signature · 1 line
MST
Re: [Qemu-devel] [PATCH v3 2/2] net: introduce command to query rx-filter information
Quoted 47 lines · Michael S. Tsirkin
Quoted 46 lines · Luiz Capitulino
Quoted 42 lines · On Fri, 24 May 2013 12:05:12 -0600 Eric Blake <[email protected]> wrote:
Quoted 10 lines · Michael S. Tsirkin
Quoted 10 lines
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines
Event message contains the net client name, management might only want to query the single net client.
The client can do the filtering itself.
I'm not sure I buy the responsiveness argument. Sure, the fastest I/O is no I/O, but whether you read and parse 100 bytes or 1000 from a Unix domain socket once in a great while shouldn't make a difference.
And the time spent malloc'ing the larger message to send from qemu, as well as the time spent malloc'ing the libvirt side that parses the qemu string into C code for use, and the time spent strcmp'ing every entry to find the right one...
It really IS more efficient to filter as low down in the stack as possible, once it is determined that filtering is desirable.
Whether filtering makes a difference in performance is a different question - you may be right that always returning the entire list and making libvirt do its own filtering will still not add any more noticeable delay compared to libvirt doing a filtered query, if the bottleneck lies elsewhere (such as libvirt telling macvtap its new configration).
Quoted 4 lines
Quoted 4 lines
My main concern is to keep the external interface simple. I'm rather reluctant to have query commands grow options.
Quoted 8 lines
Quoted 8 lines
In a case where we need the "give me everything" query anyway, the "give me this particular part" option is additional complexity. Needs justification, say arguments involving throughput, latency or client complexity.
Perhaps cases exist where we never want to ask for everything. Then the "give me everything" query is useless, and the option should be mandatory.
For this _particular_ interface, I'm not sure whether libvirt will ever use an unfiltered query -
Quoted 6 lines
Quoted 4 lines
If having the argument is useful for libvirt, then it's fine to have it.
But I'd be very reluctant to buy any performance argument w/o real numbers to back them up.
Me too. I think it's more convenience than performance.
Agreed. I suggested filtering on a NIC for usability rather than performance reasons.
QMP should be easy to use. Requiring every client to fish for the right NIC in a bunch of output that gets discarded is not convenient.
Stefan
Re: [Qemu-devel] [PATCH v3 1/2] net: introduce RX_FILTER_CHANGED event
In reply to Eric BlakeQuoted 22 lines · Eric Blake
Quoted 20 lines · Amos Kong
Introduce this new QMP event to notify management after guest changes rx-filter configuration.
Signed-off-by Amos Kong <[email protected]>--- QMP/qmp-events.txt | 14 ++++++++++++++ include/monitor/monitor.h | 1 + monitor.c | 1 + 3 files changed, 16 insertions(+)QMP/qmp-events.txt +2
-0@@ -154,6 +154,20 @@ Data: "path": "/machine/peripheral/virtio-net-pci-0" }, "timestamp": { "seconds": 1265044230, "microseconds": 450486 } } +RX_FILTER_CHANGED +-----------------
Quoted 6 lines
QMP/qmp-events.txt Data: · line 172
Quoted 3 lines
QMP/qmp-events.txt +1
-0+ DEVICE_TRAY_MOVED -----------------Isn't this file supposed to be kept in sorted order, to minimize merge conflicts when backporting events?
Yes, please. Also helps humans navigate.
GUEST_PANICKED is out of order, needs fixing.
Re: [Qemu-devel] [PATCH v3 2/2] net: introduce command to query rx-filter information
In reply to Eric BlakeQuoted 34 lines · Eric Blake
Quoted 9 lines · Amos Kong
We want to implement mac programming over macvtap through Libvirt, related rx-filter configuration contains main mac, some of rx-mode and mac-table.
The previous patch adds QMP event to notify management of rx-filter change. This patch adds a monitor command to query rx-filter information.
A flag is used to avoid events flooding, if user don't query
s/don't/doesn't/
Quoted 1 line
rx-filter after receives one event, new events won't be sent
s/after/after it/
Quoted 17 lines
to qmp monitor.
+++
b/net/net.cnet/net.c +10
-0@@ -961,6 +961,53 @@ void print_net_client(Monitor *mon, NetClientState *nc) nc->info_str); } +RxFilterInfoList *qmp_query_rx_filter (bool has_name,const char *name, +Error **errp) +{ +NetClientState *nc; +RxFilterInfoList *filter_list =NULL , *last_entry =NULL ; + + QTAILQ_FOREACH(nc, &net_clients, next) { +RxFilterInfoList *entry; +RxFilterInfo *info; +
Quoted 8 lines
net/net.c void print_net_client(Monitor *mon, NetClientState *nc) · line 977
Quoted 4 lines
net/net.c +4
-0+if (nc->info->type !=NET_CLIENT_OPTIONS_KIND_NIC ) { +continue ; + } +if (has_name &&strcmp (nc->name, name) !=0 ) {Do you need the
has_nameargument here, or can you ensure that the caller passes NULL when the caller'shas_namewas false, for one less parameter and the same amount of information?
QAPI always generates a has_FOO parameter for an optional FOO parameter, even when FOO is a pointer, which has the perfectly obvious special "not given" value NULL. I hate that.
[...]
Re: [Qemu-devel] [PATCH v3 2/2] net: introduce command to query rx-filter information
In reply to Eric BlakeQuoted 11 lines · Eric Blake
Quoted 3 lines · Luiz Capitulino
This sounds like premature optimization to me, but I wonder if instead of cluttering commands with arguments to do the filtering we could add some standard way of doing this in the QAPI.
Maybe we could make QAPI support generic filtering for all query-* commands. But there's still a cost with making all query-* commands malloc the space for an entire list only to then have a QAPI layer on top of it do filtering before handing back the single element over the wire, compared to passing the filtering down to the query-* implementation to do the filtering in place.
I'd expect the time spent on malloc to be dwarved several times over by I/O latency.
If we worry about malloc impacting our latency, then we should not be using QAPI! It's really, really malloc-happy.
In QMP, we generally don't.
Quoted 4 lines
Quoted 1 line
It was you who suggested a filter command?
No, Stefan suggested it on v1:
https://lists.gnu.org/archive/html/qemu-devel/2013-04/msg03102.html
So far, I'm with Luiz here.
Re: [Qemu-devel] [PATCH v3 2/2] net: introduce command to query rx-filter information
In reply to Amos KongQuoted 45 lines · Amos Kong
We want to implement mac programming over macvtap through Libvirt, related rx-filter configuration contains main mac, some of rx-mode and mac-table.
The previous patch adds QMP event to notify management of rx-filter change. This patch adds a monitor command to query rx-filter information.
A flag is used to avoid events flooding, if user don't query rx-filter after receives one event, new events won't be sent to qmp monitor.
(qemu) info rx-filter vnet0
vnet0:
\ promiscuous: on
\ multicast: normal
\ unicast: normal
\ broadcast-allowed: off
\ multicast-overflow: off
\ unicast-overflow: off
\ main-mac: 52:54:00:12:34:56
\ unicast-table:
\ multicast-table:01:00:5e:00:00:01 33:33:00:00:00:01 33:33:ff:12:34:56Signed-off-by Amos Kong <[email protected]>--- hmp-commands.hx | 2 ++ hmp.c | 49 ++++++++++++++++++++++++++++ hmp.h | 1 + hw/net/virtio-net.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++ include/net/net.h | 2 ++ monitor.c | 8 +++++ net/net.c | 47 +++++++++++++++++++++++++++ qapi-schema.json | 73 +++++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 55 +++++++++++++++++++++++++++++++ 9 files changed, 330 insertions(+)hmp-commands.hx +0
-0
hmp-commands.hx show qdev device model list · line 1643
Quoted 5 lines
hmp-commands.hx +2
-0@@ -1639,6 +1639,8 @@ show qdev device model list show roms @item info tpm show the TPM device +@item info rx-filter [net client name] +show the rx-filter information for all nics (or for the given nic)
Humor me: spell it NICs and NIC, because it's an acronym.
Quoted 13 lines
hmp-commands.hx +0
-0@end table ETEXIhmp.c +2
-0@@ -653,6 +653,55 @@ void hmp_info_tpm(Monitor *mon, const QDict *qdict)qapi_free_TPMInfoList (info_list); } +void hmp_info_rx_filter (Monitor *mon,const QDict *qdict) +{
hmp.c void hmp_info_tpm(Monitor *mon, const QDict *qdict) · line 667
Quoted 10 lines
hmp.c +10
-0+RxFilterInfoList *filter_list, *entry; +strList *str_entry; +bool has_name =qdict_haskey (qdict,"name" ); +const char *name =NULL ; + +if (has_name) { + name =qdict_get_str (qdict,"name" ); + } + + filter_list =qmp_query_rx_filter (has_name, name,NULL );
Rather roundabout way to do
const char *name = qdict_get_str(qdict, "name");
filter_list = qmp_query_rx_filter(name != NULL, name);hmp.c void hmp_info_tpm(Monitor *mon, const QDict *qdict) · line 670
Quoted 3 lines
hmp.c +3
-0+ entry = filter_list; + +while (entry) {
Recommend to put the loop control in one place:
for (entry = filter_list; entry; entry = entry->next) {Quoted 98 lines
hmp.c +34
-0+monitor_printf (mon,"%s:\n" , entry->value->name); +monitor_printf (mon," \\ promiscuous: %s\n" , + entry->value->promiscuous ?"on" :"off" ); +monitor_printf (mon," \\ multicast: %s\n" , + RxState_lookup[entry->value->multicast]); +monitor_printf (mon," \\ unicast: %s\n" , + RxState_lookup[entry->value->unicast]); +monitor_printf (mon," \\ broadcast-allowed: %s\n" , + entry->value->broadcast_allowed ?"on" :"off" ); +monitor_printf (mon," \\ multicast-overflow: %s\n" , + entry->value->multicast_overflow ?"on" :"off" ); +monitor_printf (mon," \\ unicast-overflow: %s\n" , + entry->value->unicast_overflow ?"on" :"off" ); +monitor_printf (mon," \\ main-mac: %s\n" , entry->value->main_mac); + + str_entry = entry->value->unicast_table; +monitor_printf (mon," \\ unicast-table:\n" ); +while (str_entry) { +monitor_printf (mon," %s\n" , str_entry->value); + str_entry = str_entry->next; + } + + str_entry = entry->value->multicast_table; +monitor_printf (mon," \\ multicast-table:\n" ); +while (str_entry) { +monitor_printf (mon," %s\n" , str_entry->value); + str_entry = str_entry->next; + } + + entry = entry->next; + } +qapi_free_RxFilterInfoList (filter_list); +} +void hmp_quit (Monitor *mon,const QDict *qdict) {monitor_suspend (mon);hmp.h +1
-0@@ -37,6 +37,7 @@ void hmp_info_balloon(Monitor *mon, const QDict *qdict);void hmp_info_pci (Monitor *mon,const QDict *qdict);void hmp_info_block_jobs (Monitor *mon,const QDict *qdict);void hmp_info_tpm (Monitor *mon,const QDict *qdict); +void hmp_info_rx_filter (Monitor *mon,const QDict *qdict);void hmp_quit (Monitor *mon,const QDict *qdict);void hmp_stop (Monitor *mon,const QDict *qdict);void hmp_system_reset (Monitor *mon,const QDict *qdict);hw/net/virtio-net.c +34
-0@@ -21,6 +21,8 @@#include "hw/virtio/virtio-net.h" #include "net/vhost_net.h" #include "hw/virtio/virtio-bus.h" +#include "qapi/qmp/qjson.h" +#include "monitor/monitor.h" #define VIRTIO_NET_VM_VERSION 11@@ -192,6 +194,90 @@ static void virtio_net_set_link_status(NetClientState *nc)virtio_net_set_status (vdev, vdev->status); } +static bool notify_enabled = true; + +static void rxfilter_notify (const char *name) +{ +QObject *event_data; + +if (notify_enabled) { + event_data =qobject_from_jsonf ("{ 'name': %s }" , name); +monitor_protocol_event (QEVENT_RX_FILTER_CHANGED , event_data); +qobject_decref (event_data); +/* disable event notification to avoid events flooding */ + notify_enabled = false; + } +} + +static RxFilterInfo *virtio_net_query_rxfilter (NetClientState *nc) +{ +VirtIONet *n =qemu_get_nic_opaque (nc); +RxFilterInfo *info; +strList *str_list =NULL ; +strList *entry; +int i; + + info =g_malloc0 (sizeof (*info)); + info->name =g_strdup (nc->name); + info->promiscuous = n->promisc; + +if (n->nouni) { + info->unicast =RX_STATE_NO ; + }else if (n->alluni) { + info->unicast =RX_STATE_ALL ; + }else {
hw/net/virtio-net.c static void virtio_net_set_link_status(NetClientState *nc) · line 238
Quoted 10 lines
hw/net/virtio-net.c +10
-0+ info->unicast =RX_STATE_NORMAL ; + } + +if (n->nomulti) { + info->multicast =RX_STATE_NO ; + }else if (n->allmulti) { + info->multicast =RX_STATE_ALL ; + }else { + info->multicast =RX_STATE_NORMAL ; + }
Makes me wonder whether replacing VirtIONet members noFOO and allFOO by an enum RxState would make things clearer there. Outside the scope of this patch.
hw/net/virtio-net.c static void virtio_net_set_link_status(NetClientState *nc) · line 246
Quoted 8 lines
hw/net/virtio-net.c +8
-0+ + info->broadcast_allowed = n->nobcast; + info->multicast_overflow = n->mac_table.multi_overflow; + info->unicast_overflow = n->mac_table.uni_overflow; + info->main_mac =g_strdup_printf ("%.2x:%.2x:%.2x:%.2x:%.2x:%.2x" , + n->mac[0 ], n->mac[1 ], n->mac[2 ], + n->mac[3 ], n->mac[4 ], n->mac[5 ]); +
Please initialize str_list here rather than at its declaration, because that'll make the loop's workings more locally obvious, and because...
Quoted 4 lines
hw/net/virtio-net.c +4
-0+for (i =0 ; i < n->mac_table.first_multi; i++) { + entry =g_malloc0 (sizeof (*entry)); + entry->value = g_strdup_printf("%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", + n->mac_table.macs[i * ETH_ALEN],
hw/net/virtio-net.c static void virtio_net_set_link_status(NetClientState *nc) · line 260
Quoted 10 lines
hw/net/virtio-net.c +10
-0+ n->mac_table.macs[i *ETH_ALEN +1 ], + n->mac_table.macs[i *ETH_ALEN +2 ], + n->mac_table.macs[i *ETH_ALEN +3 ], + n->mac_table.macs[i *ETH_ALEN +4 ], + n->mac_table.macs[i * ETH_ALEN + 5]); + entry->next = str_list; + str_list = entry; + } + info->unicast_table = str_list; +
... it's how this loop works.
Actually, the two loops are duplicates. Consider factoring out a helper function.
Quoted 6 lines
hw/net/virtio-net.c +6
-0+ str_list =NULL ; +for (i = n->mac_table.first_multi; i < n->mac_table.in_use; i++) { + entry =g_malloc0 (sizeof (*entry)); + entry->value = g_strdup_printf("%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", + n->mac_table.macs[i * ETH_ALEN], + n->mac_table.macs[i * ETH_ALEN + 1],
hw/net/virtio-net.c static void virtio_net_set_link_status(NetClientState *nc) · line 276
Quoted 10 lines
hw/net/virtio-net.c +10
-0+ n->mac_table.macs[i *ETH_ALEN +2 ], + n->mac_table.macs[i *ETH_ALEN +3 ], + n->mac_table.macs[i *ETH_ALEN +4 ], + n->mac_table.macs[i * ETH_ALEN + 5]); + entry->next = str_list; + str_list = entry; + } + info->multicast_table = str_list; +/* enable event notification after query */ + notify_enabled = true;
Combined with the optional argument, this leads to rather weird behavior:
1. Querying all NICs reenables the event for all NICs. Okay.
2. Querying a single virtio-net NIC reenables the event for all virtio-net NICs. Weird.
Currently, only virtio-net NICs support the event, so the weirdness isn't visible.
Regardless, please clean this up:
* Either move notify_enabled into device state, or
* Move notify_enabled somewhere global, along with rxfilter_notify().
Quoted 26 lines
hw/net/virtio-net.c +8
-0+ +return info; +} +static void virtio_net_reset (VirtIODevice *vdev) {VirtIONet *n =VIRTIO_NET (vdev);@@ -442,6 +528,8 @@ static int virtio_net_handle_rx_mode(VirtIONet *n, uint8_t cmd,return VIRTIO_NET_ERR ; } +rxfilter_notify (n->netclient_name); +return VIRTIO_NET_OK ; }@@ -495,6 +583,8 @@ static int virtio_net_handle_mac(VirtIONet *n, uint8_t cmd, s =iov_to_buf (iov, iov_cnt,0 , &n->mac,sizeof (n->mac));assert (s ==sizeof (n->mac));qemu_format_nic_info_str (qemu_get_queue (n->nic), n->mac); +rxfilter_notify (n->netclient_name); +return VIRTIO_NET_OK ; }
hw/net/virtio-net.c static int virtio_net_handle_mac(VirtIONet *n, uint8_t cmd, · line 656
Quoted 8 lines
hw/net/virtio-net.c +2
-0@@ -559,6 +649,8 @@ static int virtio_net_handle_mac(VirtIONet *n, uint8_t cmd, n->mac_table.multi_overflow =1 ; } +rxfilter_notify (n->netclient_name); +return VIRTIO_NET_OK ; }
The error returns don't trigger the event. We can fail after clearing n->mac_table. Why is that okay?
Quoted 33 lines
hw/net/virtio-net.c +1
-0@@ -1312,6 +1404,7 @@ static NetClientInfo net_virtio_info = { .receive = virtio_net_receive, .cleanup = virtio_net_cleanup, .link_status_changed = virtio_net_set_link_status, + .query_rx_filter = virtio_net_query_rxfilter, };static bool virtio_net_guest_notifier_pending (VirtIODevice *vdev,int idx)include/net/net.h +2
-0@@ -49,6 +49,7 @@ typedef ssize_t (NetReceiveIOV)(NetClientState *, const struct iovec *, int);typedef void (NetCleanup ) (NetClientState *);typedef void (LinkStatusChanged )(NetClientState *);typedef void (NetClientDestructor )(NetClientState *); +typedef RxFilterInfo *(QueryRxFilter )(NetClientState *); typedef struct NetClientInfo { NetClientOptionsKind type;@@ -59,6 +60,7 @@ typedef struct NetClientInfo {NetCanReceive *can_receive;NetCleanup *cleanup;LinkStatusChanged *link_status_changed; +QueryRxFilter *query_rx_filter;NetPoll *poll; } NetClientInfo;monitor.c +0
-0
monitor.c static mon_cmd_t info_cmds[] = { · line 2767
Quoted 4 lines
monitor.c +1
-0@@ -2764,6 +2764,14 @@ static mon_cmd_t info_cmds[] = { .mhandler.cmd = hmp_info_tpm, }, { + .name = "rx-filter",
nic-rx-filter?
monitor.c static mon_cmd_t info_cmds[] = { · line 2771
Quoted 4 lines
monitor.c +4
-0+ .args_type = "name:s?", + .params = "[net client name]", + .help ="show the rx-filter information for all nics (or" + " for the given nic)",
NICs, NIC.
Quoted 45 lines
monitor.c +3
-0+ .mhandler.cmd = hmp_info_rx_filter, + }, + { .name = NULL, }, };net/net.c +31
-0@@ -961,6 +961,53 @@ void print_net_client(Monitor *mon, NetClientState *nc) nc->info_str); } +RxFilterInfoList *qmp_query_rx_filter (bool has_name,const char *name, +Error **errp) +{ +NetClientState *nc; +RxFilterInfoList *filter_list =NULL , *last_entry =NULL ; + + QTAILQ_FOREACH(nc, &net_clients, next) { +RxFilterInfoList *entry; +RxFilterInfo *info; + +if (nc->info->type !=NET_CLIENT_OPTIONS_KIND_NIC ) { +continue ; + } +if (has_name &&strcmp (nc->name, name) !=0 ) { +continue ; + } + +if (nc->info->query_rx_filter) { + info = nc->info->query_rx_filter (nc); + entry =g_malloc0 (sizeof (*entry)); + entry->value = info; + +if (!filter_list) { + filter_list = entry; + }else { + last_entry->next = entry; + } + last_entry = entry; + }else if (has_name) { +error_setg (errp,"net client(%s) doesn't support" +" rx-filter querying" , name);
net/net.c void print_net_client(Monitor *mon, NetClientState *nc) · line 1004
Quoted 10 lines
net/net.c +10
-0+break ; + } + + } + +if (filter_list ==NULL && !error_is_set (errp)) { +if (has_name) { +error_setg (errp,"invalid net client name: %s" , name); + }else { +error_setg (errp,"no net client supports rx-filter querying" );
Why is this an error?
Quoted 75 lines
net/net.c +6
-0+ } + } + +return filter_list; +} +void do_info_network (Monitor *mon,const QDict *qdict) {NetClientState *nc, *peer;qapi-schema.json +58
-0@@ -3619,3 +3619,76 @@ '*cpuid-input-ecx': 'int', 'cpuid-register': 'X86CPURegister32', 'features': 'int' } } + +## +# @RxState: +# +# Packets receiving state +# +# @normal: filter assigned packets according to the mac-table +# +# @no: don't receive any assigned packet +# +# @all: receive all assigned packets +# +## +{ 'enum': 'RxState', 'data': [ 'normal', 'no', 'all' ] } + +## +# @RxFilterInfo: +# +# Rx-filter information for a net client, it contains main mac, some +# of rx-mode items and mac-table. +# +# @name: net client name +# +# @promiscuous: whether to ether promiscuous mode +# +# @multicast: multicast receive state +# +# @unicast: unicast receive state +# +# @broadcast-allowed: whether to receive broadcast +# +# @multicast-overflow: multicast table is overflow or not +# +# @unicast-overflow: unicast table is overflow or not +# +# @main-mac: the main macaddr string +# +# @unicast-table: a list of unicast macaddr string +# +# @multicast-table: a list of multicast macaddr string +# +# Since 1.6 +## + +{ 'type': 'RxFilterInfo', + 'data': { + 'name': 'str', + 'promiscuous': 'bool', + 'multicast': 'RxState', + 'unicast': 'RxState', + 'broadcast-allowed': 'bool', + 'multicast-overflow': 'bool', + 'unicast-overflow': 'bool', + 'main-mac': 'str', + 'unicast-table': ['str'], + 'multicast-table': ['str'] }} + +##
qapi-schema.json line 3689
Quoted 10 lines
qapi-schema.json +10
-0+# @query-rx-filter: +# +# Return rx-filter information for all nics (or for the given nic). +# +# @name: #optional net client name +# +# Returns: list of @RxFilterInfo for all nics (or for the given nic). +# Returns an error if the given @name doesn't exist, or given +# nic doesn't support rx-filter querying, or no net client +# supports rx-filter querying
NICs, NIC.
The case "no net client supports rx-filter querying" should return an empty list, not throw an error.
I think the case "@name exists but isn't a NIC" should be a separate error.
qapi-schema.json line 3693
Quoted 4 lines
qapi-schema.json +4
-0+# +# Since: 1.6 +## +{ 'command': 'query-rx-filter', 'data': { '*name': 'str' },
query-nic-rx-filter?
Do we want to complicate the QMP interface with the optional argument? Discussed elsewhere in the thread, no need to answer again here.
Quoted 15 lines
qapi-schema.json +1
-0+ 'returns': ['RxFilterInfo'] }qmp-commands.hx +6
-0@@ -2932,3 +2932,58 @@ Example: <- { "return": {} } EQMP + { + .name = "query-rx-filter", + .args_type = "name:s?", + .mhandler.cmd_new = qmp_marshal_input_query_rx_filter, + }, +
qmp-commands.hx Example: · line 2950
Quoted 10 lines
qmp-commands.hx +10
-0+SQMP +query-rx-filter +--------------- + +Show rx-filter information. + +Returns a json-array of rx-filter information for all nics (or for the +given nic), returning an error if the given nic doesn't exist, or +given nic doesn't support rx-filter querying, or no net client +supports rx-filter querying.
Comments on @query-rx-filter in qapi-schema.json apply.
qmp-commands.hx Example: · line 2954
Quoted 4 lines
qmp-commands.hx +4
-0+ +Each array entry contains the following: + +- "name": net client name (jaso-string)
json-string
qmp-commands.hx Example: · line 2961
Quoted 7 lines
qmp-commands.hx +7
-0+- "promiscuous": enter promiscuous mode (json-bool) +- "multicast": multicast receive state (one of 'normal', 'no', 'all') +- "unicast": unicast receive state (one of 'normal', 'no', 'all') +- "broadcast-allowed": allow to receive broadcast (json-bool) +- "multicast-overflow": multicast table is overflow (json-bool) +- "unicast-overflow": unicast table is overflow (json-bool) +- "main-mac": main macaddr string (jaso-string)
json-string
Quoted 18 lines
qmp-commands.hx +18
-0+- "unicast-table": a json-array of unicast macaddr string +- "multicast-table": a json-array of multicast macaddr string + +Example: + +-> { "execute": "query-rx-filter", "arguments": { "name": "vnet0" }} +<- { "return": [ + { + "promiscuous": true, + "name": "vnet0", + "main-mac": "52:54:00:12:34:56", + "unicast": "normal", + "unicast-table": [ + ], + "multicast": "normal", + "multicast-overflow": false, + "unicast-overflow": false, + "multicast-table": [
qmp-commands.hx Example: · line 2989
Quoted 10 lines
qmp-commands.hx +10
-0+ "01:00:5e:00:00:01", + "33:33:00:00:00:01", + "33:33:ff:12:34:56" + ], + "broadcast-allowed": false + } + ] + } + +EQMP
This interface is abstract in the sense that it applies to all NICs. At this time, it's implemented only virtio-net implements it. I'm habitually wary of abstractions based on just one concrete instance, which makes me ask:
1. Ignorant question first: could the feature make sense for other NICs, too, or is it specific to virtio-net?
2. If the former, are you reasonably sure this object will do for other NICs?
Re: [Qemu-devel] [PATCH v3 2/2] net: introduce command to query rx-filter information
Meh, I got confused and reviewed an out-of-date version. Hope it's not entirely noise.
Re: [Qemu-devel] [PATCH v3 1/2] net: introduce RX_FILTER_CHANGED event
In reply to Markus ArmbrusterQuoted 28 lines · On Wed, 26 Jun 2013 08:54:46 +0200 Markus Armbruster <[email protected]> wrote:
Quoted 26 lines · Eric Blake
Quoted 24 lines · Amos Kong
Introduce this new QMP event to notify management after guest changes rx-filter configuration.
Signed-off-by Amos Kong <[email protected]>--- QMP/qmp-events.txt | 14 ++++++++++++++ include/monitor/monitor.h | 1 + monitor.c | 1 + 3 files changed, 16 insertions(+)QMP/qmp-events.txt +3
-0@@ -154,6 +154,20 @@ Data: "path": "/machine/peripheral/virtio-net-pci-0" }, "timestamp": { "seconds": 1265044230, "microseconds": 450486 } } +RX_FILTER_CHANGED +----------------- + DEVICE_TRAY_MOVED -----------------
Quoted 6 lines
Quoted 2 lines
Isn't this file supposed to be kept in sorted order, to minimize merge conflicts when backporting events?
Yes, please. Also helps humans navigate.
GUEST_PANICKEDis out of order, needs fixing.
The ultimate fix would be to add event support to the qapi.
Re: [Qemu-devel] [PATCH v3 2/2] net: introduce command to query rx-filter information
In reply to Markus ArmbrusterQuoted 2 lines · On Wed, 26 Jun 2013 14:00:30 +0200 Markus Armbruster <[email protected]> wrote:
Meh, I got confused and reviewed an out-of-date version. Hope it's not entirely noise.
I don't think it is. But this series got applied to Michael's tree, so if you want your comments addressed before applying to master (I think we do) then it's better to state it clearly.
Re: [Qemu-devel] [PATCH v3 2/2] net: introduce command to query rx-filter information
Quoted 9 lines · Luiz Capitulino
Quoted 2 lines · On Wed, 26 Jun 2013 14:00:30 +0200 Markus Armbruster <[email protected]> wrote:
Meh, I got confused and reviewed an out-of-date version. Hope it's not entirely noise.
I don't think it is. But this series got applied to Michael's tree, so if you want your comments addressed before applying to master (I think we do) then it's better to state it clearly.
Michael, please give Amos a chance to reply to my review.
Re: [Qemu-devel] [PATCH v3 2/2] net: introduce command to query rx-filter information
Quoted 5 lines · Markus Armbruster
Quoted 3 lines · Luiz Capitulino
On Wed, 26 Jun 2013 14:00:30 +0200
Markus Armbruster <[email protected]> wrote:
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Meh, I got confused and reviewed an out-of-date version. Hope it's not entirely noise.
I don't think it is. But this series got applied to Michael's tree, so if you want your comments addressed before applying to master (I think we do) then it's better to state it clearly.
Michael, please give Amos a chance to reply to my review.
Looks like the pull request is already live but had issues; meanwhile, I also found an issue when reviewing the pull request:
https://lists.gnu.org/archive/html/qemu-devel/2013-06/msg05127.html
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v3 2/2] net: introduce command to query rx-filter information
Quoted 13 lines · Eric Blake
Quoted 12 lines · Markus Armbruster
Quoted 9 lines · Luiz Capitulino
Quoted 2 lines · On Wed, 26 Jun 2013 14:00:30 +0200 Markus Armbruster <[email protected]> wrote:
Meh, I got confused and reviewed an out-of-date version. Hope it's not entirely noise.
I don't think it is. But this series got applied to Michael's tree, so if you want your comments addressed before applying to master (I think we do) then it's better to state it clearly.
Quoted 5 lines
Quoted 1 line
Michael, please give Amos a chance to reply to my review.
Looks like the pull request is already live but had issues; meanwhile, I also found an issue when reviewing the pull request:
https://lists.gnu.org/archive/html/qemu-devel/2013-06/msg05127.html
Missed it, thanks!
Re: [Qemu-devel] [PATCH v3 2/2] net: introduce command to query rx-filter information
Quoted 15 lines · Markus Armbruster
Quoted 13 lines · Eric Blake
Quoted 12 lines · Markus Armbruster
Quoted 9 lines · Luiz Capitulino
Quoted 2 lines · On Wed, 26 Jun 2013 14:00:30 +0200 Markus Armbruster <[email protected]> wrote:
Meh, I got confused and reviewed an out-of-date version. Hope it's not entirely noise.
I don't think it is. But this series got applied to Michael's tree, so if you want your comments addressed before applying to master (I think we do) then it's better to state it clearly.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Michael, please give Amos a chance to reply to my review.
Looks like the pull request is already live but had issues; meanwhile, I also found an issue when reviewing the pull request:
https://lists.gnu.org/archive/html/qemu-devel/2013-06/msg05127.htmlMissed it, thanks!
In mst's v2 pull, it still contains my patch, it's not merged to master by Anthony. I think mst should re-send a v3 without my patch as said in changelog.
I will fix the problem in your reply, thanks.
Signature · 1 line
Amos.
Re: [Qemu-devel] [PATCH v3 2/2] net: introduce command to query rx-filter information
In reply to Markus ArmbrusterQuoted 29 lines · Markus Armbruster
Quoted 27 lines · Amos Kong
We want to implement mac programming over macvtap through Libvirt, related rx-filter configuration contains main mac, some of rx-mode and mac-table.
The previous patch adds QMP event to notify management of rx-filter change. This patch adds a monitor command to query rx-filter information.
A flag is used to avoid events flooding, if user don't query rx-filter after receives one event, new events won't be sent to qmp monitor.
(qemu) info rx-filter vnet0
vnet0:
\ promiscuous: on
\ multicast: normal
\ unicast: normal
\ broadcast-allowed: off
\ multicast-overflow: off
\ unicast-overflow: off
\ main-mac: 52:54:00:12:34:56
\ unicast-table:
\ multicast-table:01:00:5e:00:00:01 33:33:00:00:00:01 33:33:ff:12:34:56
Quoted 1 line
Quoted 1 line
Signed-off-by Amos Kong <[email protected]>
Thanks for your comments, some comments are out-of-data, I removed them in this reply.
Quoted 23 lines
Quoted 23 lines
hw/net/virtio-net.c +23
-0+static RxFilterInfo *virtio_net_query_rxfilter (NetClientState *nc) +{ +VirtIONet *n =qemu_get_nic_opaque (nc); +RxFilterInfo *info; +strList *str_list =NULL ; +strList *entry; +int i; + + info =g_malloc0 (sizeof (*info)); + info->name =g_strdup (nc->name); + info->promiscuous = n->promisc; + +if (n->nouni) { + info->unicast =RX_STATE_NO ; + }else if (n->alluni) { + info->unicast =RX_STATE_ALL ; + }else { + info->unicast =RX_STATE_NORMAL ; + } + +if (n->nomulti) { + info->multicast =RX_STATE_NO ; + }else if (n->allmulti) {
Quoted 8 lines
hw/net/virtio-net.c static void virtio_net_set_link_status(NetClientState *nc) · line 238
Quoted 4 lines
hw/net/virtio-net.c +4
-0+ info->multicast =RX_STATE_ALL ; + }else { + info->multicast =RX_STATE_NORMAL ; + }Makes me wonder whether replacing VirtIONet members noFOO and allFOO by an enum RxState would make things clearer there. Outside the scope of this patch.
Good suggestion, added to my todolist.
Quoted 59 lines
hw/net/virtio-net.c static void virtio_net_set_link_status(NetClientState *nc) · line 246
Quoted 8 lines
hw/net/virtio-net.c +8
-0+ + info->broadcast_allowed = n->nobcast; + info->multicast_overflow = n->mac_table.multi_overflow; + info->unicast_overflow = n->mac_table.uni_overflow; + info->main_mac =g_strdup_printf ("%.2x:%.2x:%.2x:%.2x:%.2x:%.2x" , + n->mac[0 ], n->mac[1 ], n->mac[2 ], + n->mac[3 ], n->mac[4 ], n->mac[5 ]); +Please initialize
str_listhere rather than at its declaration, because that'll make the loop's workings more locally obvious, and because...Quoted 4 lines
hw/net/virtio-net.c +4
-0+for (i =0 ; i < n->mac_table.first_multi; i++) { + entry =g_malloc0 (sizeof (*entry)); + entry->value = g_strdup_printf("%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", + n->mac_table.macs[i * ETH_ALEN],hw/net/virtio-net.c static void virtio_net_set_link_status(NetClientState *nc) · line 260
Quoted 10 lines
hw/net/virtio-net.c +10
-0+ n->mac_table.macs[i *ETH_ALEN +1 ], + n->mac_table.macs[i *ETH_ALEN +2 ], + n->mac_table.macs[i *ETH_ALEN +3 ], + n->mac_table.macs[i *ETH_ALEN +4 ], + n->mac_table.macs[i * ETH_ALEN + 5]); + entry->next = str_list; + str_list = entry; + } + info->unicast_table = str_list; +... it's how this loop works.
Actually, the two loops are duplicates. Consider factoring out a helper function.
Quoted 28 lines
hw/net/virtio-net.c +7
-0+return info; +} +static void virtio_net_reset (VirtIODevice *vdev) {VirtIONet *n =VIRTIO_NET (vdev);@@ -442,6 +528,8 @@ static int virtio_net_handle_rx_mode(VirtIONet *n, uint8_t cmd,return VIRTIO_NET_ERR ; } +rxfilter_notify (n->netclient_name); +return VIRTIO_NET_OK ; }@@ -495,6 +583,8 @@ static int virtio_net_handle_mac(VirtIONet *n, uint8_t cmd, s =iov_to_buf (iov, iov_cnt,0 , &n->mac,sizeof (n->mac));assert (s ==sizeof (n->mac));qemu_format_nic_info_str (qemu_get_queue (n->nic), n->mac); +rxfilter_notify (n->netclient_name); +return VIRTIO_NET_OK ; }@@ -559,6 +649,8 @@ static int virtio_net_handle_mac(VirtIONet *n, uint8_t cmd, n->mac_table.multi_overflow =1 ; }
Quoted 8 lines
hw/net/virtio-net.c static int virtio_net_handle_rx_mode(VirtIONet *n, uint8_t cmd, · line 535
Quoted 5 lines
hw/net/virtio-net.c +2
-0+rxfilter_notify (n->netclient_name); +return VIRTIO_NET_OK ; }The error returns don't trigger the event. We can fail after clearing
n->mac_table. Why is that okay?
We should notify in error path if n->mac_table is changed.
Quoted 72 lines
Quoted 72 lines
hw/net/virtio-net.c +1
-0@@ -1312,6 +1404,7 @@ static NetClientInfo net_virtio_info = { .receive = virtio_net_receive, .cleanup = virtio_net_cleanup, .link_status_changed = virtio_net_set_link_status, + .query_rx_filter = virtio_net_query_rxfilter, };static bool virtio_net_guest_notifier_pending (VirtIODevice *vdev,int idx)include/net/net.h +2
-0@@ -49,6 +49,7 @@ typedef ssize_t (NetReceiveIOV)(NetClientState *, const struct iovec *, int);typedef void (NetCleanup ) (NetClientState *);typedef void (LinkStatusChanged )(NetClientState *);typedef void (NetClientDestructor )(NetClientState *); +typedef RxFilterInfo *(QueryRxFilter )(NetClientState *); typedef struct NetClientInfo { NetClientOptionsKind type;@@ -59,6 +60,7 @@ typedef struct NetClientInfo {NetCanReceive *can_receive;NetCleanup *cleanup;LinkStatusChanged *link_status_changed; +QueryRxFilter *query_rx_filter;NetPoll *poll; } NetClientInfo;net/net.c +35
-0@@ -961,6 +961,53 @@ void print_net_client(Monitor *mon, NetClientState *nc) nc->info_str); } +RxFilterInfoList *qmp_query_rx_filter (bool has_name,const char *name, +Error **errp) +{ +NetClientState *nc; +RxFilterInfoList *filter_list =NULL , *last_entry =NULL ; + + QTAILQ_FOREACH(nc, &net_clients, next) { +RxFilterInfoList *entry; +RxFilterInfo *info; + +if (nc->info->type !=NET_CLIENT_OPTIONS_KIND_NIC ) { +continue ; + } +if (has_name &&strcmp (nc->name, name) !=0 ) { +continue ; + } + +if (nc->info->query_rx_filter) { + info = nc->info->query_rx_filter (nc); + entry =g_malloc0 (sizeof (*entry)); + entry->value = info; + +if (!filter_list) { + filter_list = entry; + }else { + last_entry->next = entry; + } + last_entry = entry; + }else if (has_name) { +error_setg (errp,"net client(%s) doesn't support" +" rx-filter querying" , name); +break ; + } + + }
Quoted 8 lines
net/net.c void print_net_client(Monitor *mon, NetClientState *nc) · line 1004
Quoted 6 lines
net/net.c +6
-0+ +if (filter_list ==NULL && !error_is_set (errp)) { +if (has_name) { +error_setg (errp,"invalid net client name: %s" , name); + }else { +error_setg (errp,"no net client supports rx-filter querying" );Why is this an error?
Return an error note is bettr than a NULL list. Management should not query the rx-filter info if there is no net client supports it.
{
"return": [
]
}NULL list might be misread to that it supports rx-filter querying, but the rx-filter config has no item.
Quoted 88 lines
Quoted 75 lines
net/net.c +6
-0+ } + } + +return filter_list; +} +void do_info_network (Monitor *mon,const QDict *qdict) {NetClientState *nc, *peer;qapi-schema.json +58
-0@@ -3619,3 +3619,76 @@ '*cpuid-input-ecx': 'int', 'cpuid-register': 'X86CPURegister32', 'features': 'int' } } + +## +# @RxState: +# +# Packets receiving state +# +# @normal: filter assigned packets according to the mac-table +# +# @no: don't receive any assigned packet +# +# @all: receive all assigned packets +# +## +{ 'enum': 'RxState', 'data': [ 'normal', 'no', 'all' ] } + +## +# @RxFilterInfo: +# +# Rx-filter information for a net client, it contains main mac, some +# of rx-mode items and mac-table. +# +# @name: net client name +# +# @promiscuous: whether to ether promiscuous mode +# +# @multicast: multicast receive state +# +# @unicast: unicast receive state +# +# @broadcast-allowed: whether to receive broadcast +# +# @multicast-overflow: multicast table is overflow or not +# +# @unicast-overflow: unicast table is overflow or not +# +# @main-mac: the main macaddr string +# +# @unicast-table: a list of unicast macaddr string +# +# @multicast-table: a list of multicast macaddr string +# +# Since 1.6 +## + +{ 'type': 'RxFilterInfo', + 'data': { + 'name': 'str', + 'promiscuous': 'bool', + 'multicast': 'RxState', + 'unicast': 'RxState', + 'broadcast-allowed': 'bool', + 'multicast-overflow': 'bool', + 'unicast-overflow': 'bool', + 'main-mac': 'str', + 'unicast-table': ['str'], + 'multicast-table': ['str'] }} + +##qapi-schema.json line 3689
Quoted 10 lines
qapi-schema.json +10
-0+# @query-rx-filter: +# +# Return rx-filter information for all nics (or for the given nic). +# +# @name: #optional net client name +# +# Returns: list of @RxFilterInfo for all nics (or for the given nic). +# Returns an error if the given @name doesn't exist, or given +# nic doesn't support rx-filter querying, or no net client +# supports rx-filter queryingNICs, NIC.
Quoted 7 lines
The case "no net client supports rx-filter querying" should return an empty list, not throw an error.
I think the case "@name exists but isn't a NIC" should be a separate error.
Reasonable.
Quoted 31 lines
Quoted 15 lines
qapi-schema.json +15
-0+Example: + +-> { "execute": "query-rx-filter", "arguments": { "name": "vnet0" }} +<- { "return": [ + { + "promiscuous": true, + "name": "vnet0", + "main-mac": "52:54:00:12:34:56", + "unicast": "normal", + "unicast-table": [ + ], + "multicast": "normal", + "multicast-overflow": false, + "unicast-overflow": false, + "multicast-table": [qapi-schema.json
Quoted 10 lines
qapi-schema.json +10
-0+ "01:00:5e:00:00:01", + "33:33:00:00:00:01", + "33:33:ff:12:34:56" + ], + "broadcast-allowed": false + } + ] + } + +EQMPThis interface is abstract in the sense that it applies to all NICs. At this time, it's implemented only virtio-net implements it. I'm habitually wary of abstractions based on just one concrete instance, which makes me ask:
Quoted 2 lines
1. Ignorant question first: could the feature make sense for other NICs, too, or is it specific to virtio-net?
We will not.
It's ugly to check if nic is virtio-net nic in net/net.c, so I register the query function to NetClientInfo. Traversal the net client list in net/net.c, and execute query of each virtio-net instance in virtio-net.c
Quoted 2 lines
2. If the former, are you reasonably sure this object will do for other NICs?
No.
Signature · 1 line
Amos.
Re: [Qemu-devel] [PATCH v3 2/2] net: introduce command to query rx-filter information
Quoted 30 lines · Amos Kong
Quoted 29 lines · Markus Armbruster
Quoted 27 lines · Amos Kong
We want to implement mac programming over macvtap through Libvirt, related rx-filter configuration contains main mac, some of rx-mode and mac-table.
The previous patch adds QMP event to notify management of rx-filter change. This patch adds a monitor command to query rx-filter information.
A flag is used to avoid events flooding, if user don't query rx-filter after receives one event, new events won't be sent to qmp monitor.
(qemu) info rx-filter vnet0
vnet0:
\ promiscuous: on
\ multicast: normal
\ unicast: normal
\ broadcast-allowed: off
\ multicast-overflow: off
\ unicast-overflow: off
\ main-mac: 52:54:00:12:34:56
\ unicast-table:
\ multicast-table:01:00:5e:00:00:01 33:33:00:00:00:01 33:33:ff:12:34:56
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Signed-off-by Amos Kong <[email protected]>Thanks for your comments, some comments are out-of-data, I removed them in this reply.
Okay :)
Quoted 185 lines
Quoted 23 lines
Quoted 23 lines
hw/net/virtio-net.c +23
-0+static RxFilterInfo *virtio_net_query_rxfilter (NetClientState *nc) +{ +VirtIONet *n =qemu_get_nic_opaque (nc); +RxFilterInfo *info; +strList *str_list =NULL ; +strList *entry; +int i; + + info =g_malloc0 (sizeof (*info)); + info->name =g_strdup (nc->name); + info->promiscuous = n->promisc; + +if (n->nouni) { + info->unicast =RX_STATE_NO ; + }else if (n->alluni) { + info->unicast =RX_STATE_ALL ; + }else { + info->unicast =RX_STATE_NORMAL ; + } + +if (n->nomulti) { + info->multicast =RX_STATE_NO ; + }else if (n->allmulti) {Quoted 8 lines
hw/net/virtio-net.c static void virtio_net_set_link_status(NetClientState *nc) · line 238
Quoted 4 lines
hw/net/virtio-net.c +4
-0+ info->multicast =RX_STATE_ALL ; + }else { + info->multicast =RX_STATE_NORMAL ; + }Makes me wonder whether replacing VirtIONet members noFOO and allFOO by an enum RxState would make things clearer there. Outside the scope of this patch.
Good suggestion, added to my todolist.
Quoted 59 lines
hw/net/virtio-net.c static void virtio_net_set_link_status(NetClientState *nc) · line 246
Quoted 8 lines
hw/net/virtio-net.c +8
-0+ + info->broadcast_allowed = n->nobcast; + info->multicast_overflow = n->mac_table.multi_overflow; + info->unicast_overflow = n->mac_table.uni_overflow; + info->main_mac =g_strdup_printf ("%.2x:%.2x:%.2x:%.2x:%.2x:%.2x" , + n->mac[0 ], n->mac[1 ], n->mac[2 ], + n->mac[3 ], n->mac[4 ], n->mac[5 ]); +Please initialize
str_listhere rather than at its declaration, because that'll make the loop's workings more locally obvious, and because...Quoted 4 lines
hw/net/virtio-net.c +4
-0+for (i =0 ; i < n->mac_table.first_multi; i++) { + entry =g_malloc0 (sizeof (*entry)); + entry->value = g_strdup_printf("%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", + n->mac_table.macs[i * ETH_ALEN],hw/net/virtio-net.c static void virtio_net_set_link_status(NetClientState *nc) · line 260
Quoted 10 lines
hw/net/virtio-net.c +10
-0+ n->mac_table.macs[i *ETH_ALEN +1 ], + n->mac_table.macs[i *ETH_ALEN +2 ], + n->mac_table.macs[i *ETH_ALEN +3 ], + n->mac_table.macs[i *ETH_ALEN +4 ], + n->mac_table.macs[i * ETH_ALEN + 5]); + entry->next = str_list; + str_list = entry; + } + info->unicast_table = str_list; +... it's how this loop works.
Actually, the two loops are duplicates. Consider factoring out a helper function.
Quoted 28 lines
hw/net/virtio-net.c +7
-0+return info; +} +static void virtio_net_reset (VirtIODevice *vdev) {VirtIONet *n =VIRTIO_NET (vdev);@@ -442,6 +528,8 @@ static int virtio_net_handle_rx_mode(VirtIONet *n, uint8_t cmd,return VIRTIO_NET_ERR ; } +rxfilter_notify (n->netclient_name); +return VIRTIO_NET_OK ; }@@ -495,6 +583,8 @@ static int virtio_net_handle_mac(VirtIONet *n, uint8_t cmd, s =iov_to_buf (iov, iov_cnt,0 , &n->mac,sizeof (n->mac));assert (s ==sizeof (n->mac));qemu_format_nic_info_str (qemu_get_queue (n->nic), n->mac); +rxfilter_notify (n->netclient_name); +return VIRTIO_NET_OK ; }@@ -559,6 +649,8 @@ static int virtio_net_handle_mac(VirtIONet *n, uint8_t cmd, n->mac_table.multi_overflow =1 ; }Quoted 8 lines
hw/net/virtio-net.c static int virtio_net_handle_rx_mode(VirtIONet *n, uint8_t cmd, · line 535
Quoted 5 lines
hw/net/virtio-net.c +2
-0+rxfilter_notify (n->netclient_name); +return VIRTIO_NET_OK ; }The error returns don't trigger the event. We can fail after clearing
n->mac_table. Why is that okay?We should notify in error path if
n->mac_tableis changed.Quoted 72 lines
Quoted 72 lines
hw/net/virtio-net.c +1
-0@@ -1312,6 +1404,7 @@ static NetClientInfo net_virtio_info = { .receive = virtio_net_receive, .cleanup = virtio_net_cleanup, .link_status_changed = virtio_net_set_link_status, + .query_rx_filter = virtio_net_query_rxfilter, };static bool virtio_net_guest_notifier_pending (VirtIODevice *vdev,int idx)include/net/net.h +2
-0@@ -49,6 +49,7 @@ typedef ssize_t (NetReceiveIOV)(NetClientState *, const struct iovec *, int);typedef void (NetCleanup ) (NetClientState *);typedef void (LinkStatusChanged )(NetClientState *);typedef void (NetClientDestructor )(NetClientState *); +typedef RxFilterInfo *(QueryRxFilter )(NetClientState *); typedef struct NetClientInfo { NetClientOptionsKind type;@@ -59,6 +60,7 @@ typedef struct NetClientInfo {NetCanReceive *can_receive;NetCleanup *cleanup;LinkStatusChanged *link_status_changed; +QueryRxFilter *query_rx_filter;NetPoll *poll; } NetClientInfo;net/net.c +35
-0@@ -961,6 +961,53 @@ void print_net_client(Monitor *mon, NetClientState *nc) nc->info_str); } +RxFilterInfoList *qmp_query_rx_filter (bool has_name,const char *name, +Error **errp) +{ +NetClientState *nc; +RxFilterInfoList *filter_list =NULL , *last_entry =NULL ; + + QTAILQ_FOREACH(nc, &net_clients, next) { +RxFilterInfoList *entry; +RxFilterInfo *info; + +if (nc->info->type !=NET_CLIENT_OPTIONS_KIND_NIC ) { +continue ; + } +if (has_name &&strcmp (nc->name, name) !=0 ) { +continue ; + } + +if (nc->info->query_rx_filter) { + info = nc->info->query_rx_filter (nc); + entry =g_malloc0 (sizeof (*entry)); + entry->value = info; + +if (!filter_list) { + filter_list = entry; + }else { + last_entry->next = entry; + } + last_entry = entry; + }else if (has_name) { +error_setg (errp,"net client(%s) doesn't support" +" rx-filter querying" , name); +break ; + } + + }Quoted 8 lines
net/net.c void print_net_client(Monitor *mon, NetClientState *nc) · line 1004
Quoted 6 lines
net/net.c +6
-0+ +if (filter_list ==NULL && !error_is_set (errp)) { +if (has_name) { +error_setg (errp,"invalid net client name: %s" , name); + }else { +error_setg (errp,"no net client supports rx-filter querying" );Why is this an error?
Quoted 2 lines
Return an error note is bettr than a NULL list. Management should not query the rx-filter info if there is no net client supports it.
I disagree. If a management application asks a question we can answer, we should give it a straight answer, not an error.
ls of an empty directory prints nothing and succeeds. It doesn't concern itself with whether I should or should not ask for the directory's contents, say because nobody but me can access the directory, and I therefore should know perfectly well that it's empty.
Quoted 7 lines
{ "return": [ ] }NULL list might be misread to that it supports rx-filter querying, but the rx-filter config has no item.
If such a misunderstanding is possible, the command's specification needs fixing.
If I read the specification correctly, the returned list has one element per selected NIC that supports rx-filter querying, and no more.
Without the optional argument, all NICs are selected. With the optional argument, just the NIC identified by the argument is selected.
Whether the "rx-filter config has no item" shouldn't matter. I don't even understand what that means :)
Quoted 132 lines
Quoted 88 lines
Quoted 75 lines
net/net.c +6
-0+ } + } + +return filter_list; +} +void do_info_network (Monitor *mon,const QDict *qdict) {NetClientState *nc, *peer;qapi-schema.json +58
-0@@ -3619,3 +3619,76 @@ '*cpuid-input-ecx': 'int', 'cpuid-register': 'X86CPURegister32', 'features': 'int' } } + +## +# @RxState: +# +# Packets receiving state +# +# @normal: filter assigned packets according to the mac-table +# +# @no: don't receive any assigned packet +# +# @all: receive all assigned packets +# +## +{ 'enum': 'RxState', 'data': [ 'normal', 'no', 'all' ] } + +## +# @RxFilterInfo: +# +# Rx-filter information for a net client, it contains main mac, some +# of rx-mode items and mac-table. +# +# @name: net client name +# +# @promiscuous: whether to ether promiscuous mode +# +# @multicast: multicast receive state +# +# @unicast: unicast receive state +# +# @broadcast-allowed: whether to receive broadcast +# +# @multicast-overflow: multicast table is overflow or not +# +# @unicast-overflow: unicast table is overflow or not +# +# @main-mac: the main macaddr string +# +# @unicast-table: a list of unicast macaddr string +# +# @multicast-table: a list of multicast macaddr string +# +# Since 1.6 +## + +{ 'type': 'RxFilterInfo', + 'data': { + 'name': 'str', + 'promiscuous': 'bool', + 'multicast': 'RxState', + 'unicast': 'RxState', + 'broadcast-allowed': 'bool', + 'multicast-overflow': 'bool', + 'unicast-overflow': 'bool', + 'main-mac': 'str', + 'unicast-table': ['str'], + 'multicast-table': ['str'] }} + +##qapi-schema.json line 3689
Quoted 10 lines
qapi-schema.json +10
-0+# @query-rx-filter: +# +# Return rx-filter information for all nics (or for the given nic). +# +# @name: #optional net client name +# +# Returns: list of @RxFilterInfo for all nics (or for the given nic). +# Returns an error if the given @name doesn't exist, or given +# nic doesn't support rx-filter querying, or no net client +# supports rx-filter queryingNICs, NIC.
Quoted 7 lines
The case "no net client supports rx-filter querying" should return an empty list, not throw an error.
I think the case "@name exists but isn't a NIC" should be a separate error.
Reasonable.
Quoted 31 lines
Quoted 15 lines
qapi-schema.json +15
-0+Example: + +-> { "execute": "query-rx-filter", "arguments": { "name": "vnet0" }} +<- { "return": [ + { + "promiscuous": true, + "name": "vnet0", + "main-mac": "52:54:00:12:34:56", + "unicast": "normal", + "unicast-table": [ + ], + "multicast": "normal", + "multicast-overflow": false, + "unicast-overflow": false, + "multicast-table": [qapi-schema.json
Quoted 10 lines
qapi-schema.json +10
-0+ "01:00:5e:00:00:01", + "33:33:00:00:00:01", + "33:33:ff:12:34:56" + ], + "broadcast-allowed": false + } + ] + } + +EQMPThis interface is abstract in the sense that it applies to all NICs. At this time, it's implemented only virtio-net implements it. I'm habitually wary of abstractions based on just one concrete instance, which makes me ask:
Quoted 2 lines
1. Ignorant question first: could the feature make sense for other NICs, too, or is it specific to virtio-net?
Quoted 6 lines
We will not.
It's ugly to check if nic is virtio-net nic in
net/net.c, so I register the query function to NetClientInfo. Traversal the net client list innet/net.c, and execute query of each virtio-net instance invirtio-net.c
Implementing the feature as an optional callback is fine.
Let me rephrase my question: could this feature be implemented for other NICs? I'm *not* asking you to do that, just whether it would be possible.
I'm asking because my review of the QAPI schema depends on the answer.
Quoted 4 lines
Quoted 2 lines
2. If the former, are you reasonably sure this object will do for other NICs?
No.
I'm not sure I understand you. Do you mean to say that the feature could be implemented for other NICs, but RxFilterInfo would probably not fit for them?
Re: [Qemu-devel] [PATCH v3 2/2] net: introduce command to query rx-filter information
Quoted 57 lines · Markus Armbruster
Quoted 52 lines · Amos Kong
Quoted 43 lines
Quoted 43 lines
net/net.c +35
-0@@ -961,6 +961,53 @@ void print_net_client(Monitor *mon, NetClientState *nc) nc->info_str); } +RxFilterInfoList *qmp_query_rx_filter (bool has_name,const char *name, +Error **errp) +{ +NetClientState *nc; +RxFilterInfoList *filter_list =NULL , *last_entry =NULL ; + + QTAILQ_FOREACH(nc, &net_clients, next) { +RxFilterInfoList *entry; +RxFilterInfo *info; + +if (nc->info->type !=NET_CLIENT_OPTIONS_KIND_NIC ) { +continue ; + } +if (has_name &&strcmp (nc->name, name) !=0 ) { +continue ; + } + +if (nc->info->query_rx_filter) { + info = nc->info->query_rx_filter (nc); + entry =g_malloc0 (sizeof (*entry)); + entry->value = info; + +if (!filter_list) { + filter_list = entry; + }else { + last_entry->next = entry; + } + last_entry = entry; + }else if (has_name) { +error_setg (errp,"net client(%s) doesn't support" +" rx-filter querying" , name); +break ; + } + + }Quoted 8 lines
net/net.c void print_net_client(Monitor *mon, NetClientState *nc) · line 1004
Quoted 6 lines
net/net.c +6
-0+ +if (filter_list ==NULL && !error_is_set (errp)) { +if (has_name) { +error_setg (errp,"invalid net client name: %s" , name); + }else { +error_setg (errp,"no net client supports rx-filter querying" );Why is this an error?
Quoted 2 lines
Return an error note is bettr than a NULL list. Management should not query the rx-filter info if there is no net client supports it.
Quoted 7 lines
I disagree. If a management application asks a question we can answer, we should give it a straight answer, not an error.
ls of an empty directory prints nothing and succeeds. It doesn't concern itself with whether I should or should not ask for the directory's contents, say because nobody but me can access the directory, and I therefore should know perfectly well that it's empty.
Reasonable.
Quoted 8 lines
Quoted 7 lines
{ "return": [ ] }NULL list might be misread to that it supports rx-filter querying, but the rx-filter config has no item.
Quoted 8 lines
If such a misunderstanding is possible, the command's specification needs fixing.
If I read the specification correctly, the returned list has one element per selected NIC that supports rx-filter querying, and no more.
Without the optional argument, all NICs are selected. With the optional argument, just the NIC identified by the argument is selected.
We don't support filter by net client name in latest version.
Quoted 2 lines
Whether the "rx-filter config has no item" shouldn't matter. I don't even understand what that means :)
I'm wrong, if one nic doesn't have rx-filter config entry, a NULL dict will also be returned.
"return": [
{ }
]I will return NULL table in this case.
Quoted 57 lines
Quoted 42 lines
Quoted 39 lines
Quoted 23 lines
net/net.c +21
-0+ } + } + +return filter_list; +} + +Example: + +-> { "execute": "query-rx-filter", "arguments": { "name": "vnet0" }} +<- { "return": [ + { + "promiscuous": true, + "name": "vnet0", + "main-mac": "52:54:00:12:34:56", + "unicast": "normal", + "unicast-table": [ + ], + "multicast": "normal", + "multicast-overflow": false, + "unicast-overflow": false, + "multicast-table": [net/net.c void print_net_client(Monitor *mon, NetClientState *nc)
Quoted 10 lines
net/net.c +10
-0+ "01:00:5e:00:00:01", + "33:33:00:00:00:01", + "33:33:ff:12:34:56" + ], + "broadcast-allowed": false + } + ] + } + +EQMP This interface is abstract in the sense that it applies to all NICs. At this time, it's implemented only virtio-net implements it. I'm habitually wary of abstractions based on just one concrete instance, which makes me ask:
Quoted 2 lines
1. Ignorant question first: could the feature make sense for other NICs, too, or is it specific to virtio-net?
Quoted 6 lines
We will not.
It's ugly to check if nic is virtio-net nic in
net/net.c, so I register the query function to NetClientInfo. Traversal the net client list innet/net.c, and execute query of each virtio-net instance invirtio-net.cImplementing the feature as an optional callback is fine.
Let me rephrase my question: could this feature be implemented for other NICs? I'm *not* asking you to do that, just whether it would be possible.
I'm asking because my review of the QAPI schema depends on the answer.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
2. If the former, are you reasonably sure this object will do for other NICs?
No.
I'm not sure I understand you. Do you mean to say that the feature could be implemented for other NICs, but RxFilterInfo would probably not fit for them?
We will not implement the feature to other NICs, no request.
We notify the management of virtio-net rx-filter change, because we want to sync the the rx-filter change to macvtap device.
Signature · 1 line
Amos.
Re: [Qemu-devel] [PATCH v3 2/2] net: introduce command to query rx-filter information
Quoted 2 lines · Amos Kong
Quoted 1 line · Markus Armbruster
Amos Kong <[email protected]> writes:
[...]
Quoted 28 lines
Quoted 28 lines
Quoted 8 lines
Quoted 7 lines
This interface is abstract in the sense that it applies to all NICs. At this time, it's implemented only virtio-net implements it. I'm habitually wary of abstractions based on just one concrete instance, which makes me ask:
1. Ignorant question first: could the feature make sense for other NICs, too, or is it specific to virtio-net?
Quoted 6 lines
We will not.
It's ugly to check if nic is virtio-net nic in
net/net.c, so I register the query function to NetClientInfo. Traversal the net client list innet/net.c, and execute query of each virtio-net instance invirtio-net.cImplementing the feature as an optional callback is fine.
Let me rephrase my question: could this feature be implemented for other NICs? I'm *not* asking you to do that, just whether it would be possible.
I'm asking because my review of the QAPI schema depends on the answer.
Quoted 4 lines
Quoted 2 lines
2. If the former, are you reasonably sure this object will do for other NICs?
No.
Quoted 8 lines
Quoted 3 lines
I'm not sure I understand you. Do you mean to say that the feature could be implemented for other NICs, but RxFilterInfo would probably not fit for them?
We will not implement the feature to other NICs, no request.
We notify the management of virtio-net rx-filter change, because we want to sync the the rx-filter change to macvtap device.
I understand there are no plans to implement this feature for other NICs. But I'm not asking whether we *want* to implement it for other NICs, I'm asking whether we *could*.
Or rephrased yet another way: what exactly makes this feature applicable to virtio-net only?
If the answer is "nothing", then we *could* implement it for other NICs. Else, implementing it for other NICs would be impossible.
Once again, I'm not asking because I want it implemented for other NICs. I'm asking because the answer affects my review of the schema.
Re: [Qemu-devel] [PATCH v3 2/2] net: introduce command to query rx-filter information
Quoted 37 lines · Markus Armbruster
Quoted 2 lines · Amos Kong
Quoted 1 line · Markus Armbruster
Amos Kong <[email protected]> writes:
[...]
Quoted 32 lines
Quoted 31 lines
Quoted 8 lines
Quoted 7 lines
This interface is abstract in the sense that it applies to all NICs. At this time, it's implemented only virtio-net implements it. I'm habitually wary of abstractions based on just one concrete instance, which makes me ask:
1. Ignorant question first: could the feature make sense for other NICs, too, or is it specific to virtio-net?
Quoted 6 lines
We will not.
It's ugly to check if nic is virtio-net nic in
net/net.c, so I register the query function to NetClientInfo. Traversal the net client list innet/net.c, and execute query of each virtio-net instance invirtio-net.cImplementing the feature as an optional callback is fine.
Let me rephrase my question: could this feature be implemented for other NICs? I'm *not* asking you to do that, just whether it would be possible.
I'm asking because my review of the QAPI schema depends on the answer.
Quoted 4 lines
Quoted 2 lines
2. If the former, are you reasonably sure this object will do for other NICs?
No.
I'm not sure I understand you. Do you mean to say that the feature could be implemented for other NICs, but RxFilterInfo would probably not fit for them?
Quoted 8 lines
Quoted 4 lines
We will not implement the feature to other NICs, no request.
We notify the management of virtio-net rx-filter change, because we want to sync the the rx-filter change to macvtap device.
I understand there are no plans to implement this feature for other NICs. But I'm not asking whether we *want* to implement it for other NICs, I'm asking whether we *could*.
In theory, we can.
Quoted 2 lines
Or rephrased yet another way: what exactly makes this feature applicable to virtio-net only?
Macvtap can only be used by virtio-net, not other emulated nic. It's meaningless for management to know the rx-filter change of non-virtio-net NICs.
Quoted 5 lines
If the answer is "nothing", then we *could* implement it for other NICs. Else, implementing it for other NICs would be impossible.
Once again, I'm not asking because I want it implemented for other NICs. I'm asking because the answer affects my review of the schema.
Signature · 1 line
Amos.
Re: [Qemu-devel] [PATCH v3 2/2] net: introduce command to query rx-filter information
Quoted 47 lines · Amos Kong
Quoted 37 lines · Markus Armbruster
Quoted 2 lines · Amos Kong
Quoted 1 line · Markus Armbruster
Amos Kong <[email protected]> writes:
[...]
Quoted 32 lines
Quoted 31 lines
Quoted 8 lines
Quoted 7 lines
This interface is abstract in the sense that it applies to all NICs. At this time, it's implemented only virtio-net implements it. I'm habitually wary of abstractions based on just one concrete instance, which makes me ask:
1. Ignorant question first: could the feature make sense for other NICs, too, or is it specific to virtio-net?
Quoted 6 lines
We will not.
It's ugly to check if nic is virtio-net nic in
net/net.c, so I register the query function to NetClientInfo. Traversal the net client list innet/net.c, and execute query of each virtio-net instance invirtio-net.cImplementing the feature as an optional callback is fine.
Let me rephrase my question: could this feature be implemented for other NICs? I'm *not* asking you to do that, just whether it would be possible.
I'm asking because my review of the QAPI schema depends on the answer.
Quoted 4 lines
Quoted 2 lines
2. If the former, are you reasonably sure this object will do for other NICs?
No.
I'm not sure I understand you. Do you mean to say that the feature could be implemented for other NICs, but RxFilterInfo would probably not fit for them?
Quoted 8 lines
Quoted 4 lines
We will not implement the feature to other NICs, no request.
We notify the management of virtio-net rx-filter change, because we want to sync the the rx-filter change to macvtap device.
I understand there are no plans to implement this feature for other NICs. But I'm not asking whether we *want* to implement it for other NICs, I'm asking whether we *could*.
Quoted 8 lines
In theory, we can.
Quoted 2 lines
Or rephrased yet another way: what exactly makes this feature applicable to virtio-net only?
Macvtap can only be used by virtio-net, not other emulated nic. It's meaningless for management to know the rx-filter change of non-virtio-net NICs.
I'm having trouble squaring "in theory, we can" with "meaningless". So I'm rephrasing my question yet again.
Do NICs other than virtio-net have rx-filters?
If yes, what have these NIC rx-filters in common, and how do they differ?
Why would anybody want to query rx-filters? Use cases, please.
Why is querying rx-filters "meaningless" for anything but virtio-net? The dictionary explains "meaningless" as "having no meaning; of no value". Thus, for the query to be meaningless, the answer must carry no information, or at least none of value. Is querying rx-filters really meaningless? Or is it just something we don't need right now, and can't see being needed in the future?
Quoted 5 lines
Quoted 5 lines
If the answer is "nothing", then we *could* implement it for other NICs. Else, implementing it for other NICs would be impossible.
Once again, I'm not asking because I want it implemented for other NICs. I'm asking because the answer affects my review of the schema.
Re: [Qemu-devel] [PATCH v3 2/2] net: introduce command to query rx-filter information
Quoted 54 lines · Markus Armbruster
Quoted 52 lines · Amos Kong
Quoted 37 lines · Markus Armbruster
Quoted 2 lines · Amos Kong
Quoted 1 line · Markus Armbruster
Amos Kong <[email protected]> writes:
[...]
Quoted 32 lines
Quoted 31 lines
Quoted 8 lines
Quoted 7 lines
This interface is abstract in the sense that it applies to all NICs. At this time, it's implemented only virtio-net implements it. I'm habitually wary of abstractions based on just one concrete instance, which makes me ask:
1. Ignorant question first: could the feature make sense for other NICs, too, or is it specific to virtio-net?
Quoted 6 lines
We will not.
It's ugly to check if nic is virtio-net nic in
net/net.c, so I register the query function to NetClientInfo. Traversal the net client list innet/net.c, and execute query of each virtio-net instance invirtio-net.cImplementing the feature as an optional callback is fine.
Let me rephrase my question: could this feature be implemented for other NICs? I'm *not* asking you to do that, just whether it would be possible.
I'm asking because my review of the QAPI schema depends on the answer.
Quoted 4 lines
Quoted 2 lines
2. If the former, are you reasonably sure this object will do for other NICs?
No.
I'm not sure I understand you. Do you mean to say that the feature could be implemented for other NICs, but RxFilterInfo would probably not fit for them?
Quoted 8 lines
Quoted 4 lines
We will not implement the feature to other NICs, no request.
We notify the management of virtio-net rx-filter change, because we want to sync the the rx-filter change to macvtap device.
I understand there are no plans to implement this feature for other NICs. But I'm not asking whether we *want* to implement it for other NICs, I'm asking whether we *could*.
In theory, we can.
Quoted 2 lines
Or rephrased yet another way: what exactly makes this feature applicable to virtio-net only?
Quoted 8 lines
Quoted 3 lines
Macvtap can only be used by virtio-net, not other emulated nic. It's meaningless for management to know the rx-filter change of non-virtio-net NICs.
I'm having trouble squaring "in theory, we can" with "meaningless". So I'm rephrasing my question yet again.
Do NICs other than virtio-net have rx-filters?
Yes.
Talked with Jason, upstream kernel fixed some bugs, then we can also use e1000 with macvtap. In this case, we should also implement a .query_rx_filter function for e1000. We can do it by another patchset.
Quoted 4 lines
If yes, what have these NIC rx-filters in common, and how do they differ?
Why would anybody want to query rx-filters? Use cases, please.
It's a way to tell management the rx-filter setup in guest nic. Management query the rx-filter setup of guest, then change the setup of macvtap device, macvtap uses same rx-filter setup as virtual nic.
Quoted 6 lines
Why is querying rx-filters "meaningless" for anything but virtio-net? The dictionary explains "meaningless" as "having no meaning; of no value". Thus, for the query to be meaningless, the answer must carry no information, or at least none of value. Is querying rx-filters really meaningless? Or is it just something we don't need right now, and can't see being needed in the future?
Signature · 1 line
Amos.
Re: [Qemu-devel] [PATCH v3 2/2] net: introduce command to query rx-filter information
Quoted 65 lines · Amos Kong
Quoted 64 lines · Markus Armbruster
Quoted 50 lines · Amos Kong
Quoted 40 lines · Markus Armbruster
Quoted 2 lines · Amos Kong
Quoted 1 line · Markus Armbruster
Amos Kong <[email protected]> writes:
[...]
Quoted 35 lines
Quoted 34 lines
Quoted 10 lines
Quoted 9 lines
This interface is abstract in the sense that it applies to all NICs. At
this time, it's implemented only virtio-net implements it. I'm habitually wary of abstractions based on just one concrete instance, which makes me ask:1. Ignorant question first: could the feature make sense for other NICs,
too, or is it specific to virtio-net?Quoted 6 lines
We will not.
It's ugly to check if nic is virtio-net nic in
net/net.c, so I register the query function to NetClientInfo. Traversal the net client list innet/net.c, and execute query of each virtio-net instance invirtio-net.cImplementing the feature as an optional callback is fine.
Let me rephrase my question: could this feature be implemented for other NICs? I'm *not* asking you to do that, just whether it would be possible.
I'm asking because my review of the QAPI schema depends on the answer.
Quoted 5 lines
Quoted 3 lines
2. If the former, are you reasonably sure this object will do for other
NICs?No.
I'm not sure I understand you. Do you mean to say that the feature could be implemented for other NICs, but RxFilterInfo would probably not fit for them?
Quoted 8 lines
Quoted 4 lines
We will not implement the feature to other NICs, no request.
We notify the management of virtio-net rx-filter change, because we want to sync the the rx-filter change to macvtap device.
I understand there are no plans to implement this feature for other NICs. But I'm not asking whether we *want* to implement it for other NICs, I'm asking whether we *could*.
Quoted 8 lines
In theory, we can.
Quoted 2 lines
Or rephrased yet another way: what exactly makes this feature applicable to virtio-net only?
Macvtap can only be used by virtio-net, not other emulated nic. It's meaningless for management to know the rx-filter change of non-virtio-net NICs.
I'm having trouble squaring "in theory, we can" with "meaningless". So I'm rephrasing my question yet again.
Quoted 7 lines
Quoted 1 line
Do NICs other than virtio-net have rx-filters?
Yes.
Talked with Jason, upstream kernel fixed some bugs, then we can also use e1000 with macvtap. In this case, we should also implement a .query_rx_filter function for e1000. We can do it by another patchset.
Yes. Just to avoid misunderstandings: I'm not asking you for that. I merely asked whether it's possible, and you answered that.
Quoted 9 lines
Quoted 4 lines
If yes, what have these NIC rx-filters in common, and how do they differ?
Why would anybody want to query rx-filters? Use cases, please.
It's a way to tell management the rx-filter setup in guest nic. Management query the rx-filter setup of guest, then change the setup of macvtap device, macvtap uses same rx-filter setup as virtual nic.
So this use case is "mirror the virtual NIC's rx-filter setup to macvtap". Makes sense.
This leads me to the question I've been aiming for all along: will your definition of RxFilterInfo do for devices other than virtio-net?
It should do if it contains only stuff that all NICs with an rx-filter have. Is that the case?
[...]
Re: [Qemu-devel] [PATCH v3 2/2] net: introduce command to query rx-filter information
Quoted 88 lines · Markus Armbruster
Quoted 65 lines · Amos Kong
Quoted 64 lines · Markus Armbruster
Quoted 50 lines · Amos Kong
Quoted 40 lines · Markus Armbruster
Quoted 2 lines · Amos Kong
Quoted 1 line · Markus Armbruster
Amos Kong <[email protected]> writes:
[...]
Quoted 35 lines
Quoted 34 lines
Quoted 10 lines
Quoted 9 lines
This interface is abstract in the sense that it applies to all NICs. At
this time, it's implemented only virtio-net implements it. I'm habitually wary of abstractions based on just one concrete instance, which makes me ask:1. Ignorant question first: could the feature make sense for other NICs,
too, or is it specific to virtio-net?Quoted 6 lines
We will not.
It's ugly to check if nic is virtio-net nic in
net/net.c, so I register the query function to NetClientInfo. Traversal the net client list innet/net.c, and execute query of each virtio-net instance invirtio-net.cImplementing the feature as an optional callback is fine.
Let me rephrase my question: could this feature be implemented for other NICs? I'm *not* asking you to do that, just whether it would be possible.
I'm asking because my review of the QAPI schema depends on the answer.
Quoted 5 lines
Quoted 3 lines
2. If the former, are you reasonably sure this object will do for other
NICs?No.
I'm not sure I understand you. Do you mean to say that the feature could be implemented for other NICs, but RxFilterInfo would probably not fit for them?
Quoted 8 lines
Quoted 4 lines
We will not implement the feature to other NICs, no request.
We notify the management of virtio-net rx-filter change, because we want to sync the the rx-filter change to macvtap device.
I understand there are no plans to implement this feature for other NICs. But I'm not asking whether we *want* to implement it for other NICs, I'm asking whether we *could*.
Quoted 8 lines
In theory, we can.
Quoted 2 lines
Or rephrased yet another way: what exactly makes this feature applicable to virtio-net only?
Macvtap can only be used by virtio-net, not other emulated nic. It's meaningless for management to know the rx-filter change of non-virtio-net NICs.
I'm having trouble squaring "in theory, we can" with "meaningless". So I'm rephrasing my question yet again.
Quoted 7 lines
Quoted 1 line
Do NICs other than virtio-net have rx-filters?
Yes.
Talked with Jason, upstream kernel fixed some bugs, then we can also use e1000 with macvtap. In this case, we should also implement a .query_rx_filter function for e1000. We can do it by another patchset.
Yes. Just to avoid misunderstandings: I'm not asking you for that. I merely asked whether it's possible, and you answered that.
Quoted 9 lines
Quoted 4 lines
If yes, what have these NIC rx-filters in common, and how do they differ?
Why would anybody want to query rx-filters? Use cases, please.
It's a way to tell management the rx-filter setup in guest nic. Management query the rx-filter setup of guest, then change the setup of macvtap device, macvtap uses same rx-filter setup as virtual nic.
Quoted 5 lines
So this use case is "mirror the virtual NIC's rx-filter setup to macvtap". Makes sense.
This leads me to the question I've been aiming for all along: will your definition of RxFilterInfo do for devices other than virtio-net?
query_rx_filter() returns the address of nic's RxFilterInfo. RxFilterInfo is general.
Quoted 2 lines
It should do if it contains only stuff that all NICs with an rx-filter have. Is that the case?
Yes.
Signature · 1 line
Amos.