Skip to content

Commit

Permalink
net/announce: Allow optional list of interfaces
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
dagrh authored and jasowang committed Jul 2, 2019
1 parent 4623027 commit ef2fdbf
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
2 changes: 1 addition & 1 deletion include/net/announce.h
Expand Up @@ -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);

/*
Expand Down
39 changes: 32 additions & 7 deletions net/announce.c
Expand Up @@ -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;
}

/*
Expand Down Expand Up @@ -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;

if (timer->params.has_interfaces) {
strList *entry = timer->params.interfaces;
/* Skip unless we find our name in the requested list */
skip = true;

while (entry) {
if (!strcmp(entry->value, nic->ncs->name)) {
/* Found us */
skip = false;
break;
}
entry = entry->next;
}
} else {
skip = false;
}

trace_qemu_announce_self_iter(nic->ncs->name,
qemu_ether_ntoa(&nic->conf->macaddr), skip);

trace_qemu_announce_self_iter(qemu_ether_ntoa(&nic->conf->macaddr));
len = announce_self_create(buf, nic->conf->macaddr.a);
if (!skip) {
len = announce_self_create(buf, nic->conf->macaddr.a);

qemu_send_packet_raw(qemu_get_queue(nic), buf, len);
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);
/* 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);
Expand Down
2 changes: 1 addition & 1 deletion net/trace-events
@@ -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"
Expand Down
11 changes: 8 additions & 3 deletions qapi/net.json
Expand Up @@ -699,14 +699,18 @@
#
# @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
##

{ 'struct': 'AnnounceParameters',
'data': { 'initial': 'int',
'max': 'int',
'rounds': 'int',
'step': 'int' } }
'step': 'int',
'*interfaces': ['str'] } }

##
# @announce-self:
Expand All @@ -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
Expand Down

0 comments on commit ef2fdbf

Please sign in to comment.