net/announce: Allow optional list of interfaces

Allow the caller to restrict the set of interfaces that announces are
sent on.  The default is still to send on all interfaces.

e.g.

  { "execute": "announce-self", "arguments": { "initial": 50, "max": 550, "rounds": 5, "step": 50, "interfaces": ["vn2", "vn1"] } }

This doesn't affect the behaviour of migraiton announcments.

Note: There's still only one timer for the qmp command, so that
performing an 'announce-self' on one list of interfaces followed
by another 'announce-self' on another list will stop the announces
on the existing set.

Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
This commit is contained in:
Dr. David Alan Gilbert 2019-06-20 19:47:02 +01:00 committed by Jason Wang
parent 4623027d86
commit ef2fdbfb4d
4 changed files with 42 additions and 12 deletions

View File

@ -22,7 +22,7 @@ struct AnnounceTimer {
/* Returns: update the timer to the next time point */
int64_t qemu_announce_timer_step(AnnounceTimer *timer);
/* Delete the underlying timer */
/* Delete the underlying timer and other data */
void qemu_announce_timer_del(AnnounceTimer *timer);
/*

View File

@ -38,6 +38,8 @@ void qemu_announce_timer_del(AnnounceTimer *timer)
timer_free(timer->tm);
timer->tm = NULL;
}
qapi_free_strList(timer->params.interfaces);
timer->params.interfaces = NULL;
}
/*
@ -96,24 +98,47 @@ static int announce_self_create(uint8_t *buf,
static void qemu_announce_self_iter(NICState *nic, void *opaque)
{
AnnounceTimer *timer = opaque;
uint8_t buf[60];
int len;
bool skip;
trace_qemu_announce_self_iter(qemu_ether_ntoa(&nic->conf->macaddr));
len = announce_self_create(buf, nic->conf->macaddr.a);
if (timer->params.has_interfaces) {
strList *entry = timer->params.interfaces;
/* Skip unless we find our name in the requested list */
skip = true;
qemu_send_packet_raw(qemu_get_queue(nic), buf, len);
while (entry) {
if (!strcmp(entry->value, nic->ncs->name)) {
/* Found us */
skip = false;
break;
}
entry = entry->next;
}
} else {
skip = false;
}
/* if the NIC provides it's own announcement support, use it as well */
if (nic->ncs->info->announce) {
nic->ncs->info->announce(nic->ncs);
trace_qemu_announce_self_iter(nic->ncs->name,
qemu_ether_ntoa(&nic->conf->macaddr), skip);
if (!skip) {
len = announce_self_create(buf, nic->conf->macaddr.a);
qemu_send_packet_raw(qemu_get_queue(nic), buf, len);
/* if the NIC provides it's own announcement support, use it as well */
if (nic->ncs->info->announce) {
nic->ncs->info->announce(nic->ncs);
}
}
}
static void qemu_announce_self_once(void *opaque)
{
AnnounceTimer *timer = (AnnounceTimer *)opaque;
qemu_foreach_nic(qemu_announce_self_iter, NULL);
qemu_foreach_nic(qemu_announce_self_iter, timer);
if (--timer->round) {
qemu_announce_timer_step(timer);

View File

@ -1,7 +1,7 @@
# See docs/devel/tracing.txt for syntax documentation.
# announce.c
qemu_announce_self_iter(const char *mac) "%s"
qemu_announce_self_iter(const char *name, const char *mac, int skip) "%s:%s skip: %d"
# vhost-user.c
vhost_user_event(const char *chr, int event) "chr: %s got event: %d"

View File

@ -699,6 +699,9 @@
#
# @step: Delay increase (in ms) after each self-announcement attempt
#
# @interfaces: An optional list of interface names, which restricts the
# announcement to the listed interfaces. (Since 4.1)
#
# Since: 4.0
##
@ -706,7 +709,8 @@
'data': { 'initial': 'int',
'max': 'int',
'rounds': 'int',
'step': 'int' } }
'step': 'int',
'*interfaces': ['str'] } }
##
# @announce-self:
@ -718,9 +722,10 @@
#
# Example:
#
# -> { "execute": "announce-self"
# -> { "execute": "announce-self",
# "arguments": {
# "initial": 50, "max": 550, "rounds": 10, "step": 50 } }
# "initial": 50, "max": 550, "rounds": 10, "step": 50,
# "interfaces": ["vn2", "vn3"] } }
# <- { "return": {} }
#
# Since: 4.0