mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-06 17:23:56 -06:00
net/announce: Add optional ID
Previously there was a single instance of the timer used by monitor triggered announces, that's OK, but when combined with the previous change that lets you have announces for subsets of interfaces it's a bit restrictive if you want to do different things to different interfaces. Add an 'id' field to the announce, and maintain a list of the timers based on id. This allows you to for example: a) Start an announce going on interface eth0 for a long time b) Start an announce going on interface eth1 for a long time c) Kill the announce on eth0 while leaving eth1 going. Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com> Signed-off-by: Jason Wang <jasowang@redhat.com>
This commit is contained in:
parent
0852827115
commit
944458b659
5 changed files with 62 additions and 14 deletions
|
@ -15,6 +15,8 @@
|
|||
#include "qapi/qapi-commands-net.h"
|
||||
#include "trace.h"
|
||||
|
||||
static GData *named_timers;
|
||||
|
||||
int64_t qemu_announce_timer_step(AnnounceTimer *timer)
|
||||
{
|
||||
int64_t step;
|
||||
|
@ -31,8 +33,13 @@ int64_t qemu_announce_timer_step(AnnounceTimer *timer)
|
|||
return step;
|
||||
}
|
||||
|
||||
void qemu_announce_timer_del(AnnounceTimer *timer)
|
||||
/*
|
||||
* If 'free_named' is true, then remove the timer from the list
|
||||
* and free the timer itself.
|
||||
*/
|
||||
void qemu_announce_timer_del(AnnounceTimer *timer, bool free_named)
|
||||
{
|
||||
bool free_timer = false;
|
||||
if (timer->tm) {
|
||||
timer_del(timer->tm);
|
||||
timer_free(timer->tm);
|
||||
|
@ -40,6 +47,24 @@ void qemu_announce_timer_del(AnnounceTimer *timer)
|
|||
}
|
||||
qapi_free_strList(timer->params.interfaces);
|
||||
timer->params.interfaces = NULL;
|
||||
if (free_named && timer->params.has_id) {
|
||||
AnnounceTimer *list_timer;
|
||||
/*
|
||||
* Sanity check: There should only be one timer on the list with
|
||||
* the id.
|
||||
*/
|
||||
list_timer = g_datalist_get_data(&named_timers, timer->params.id);
|
||||
assert(timer == list_timer);
|
||||
free_timer = true;
|
||||
g_datalist_remove_data(&named_timers, timer->params.id);
|
||||
}
|
||||
trace_qemu_announce_timer_del(free_named, free_timer, timer->params.id);
|
||||
g_free(timer->params.id);
|
||||
timer->params.id = NULL;
|
||||
|
||||
if (free_timer) {
|
||||
g_free(timer);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -56,7 +81,7 @@ void qemu_announce_timer_reset(AnnounceTimer *timer,
|
|||
* We're under the BQL, so the current timer can't
|
||||
* be firing, so we should be able to delete it.
|
||||
*/
|
||||
qemu_announce_timer_del(timer);
|
||||
qemu_announce_timer_del(timer, false);
|
||||
|
||||
QAPI_CLONE_MEMBERS(AnnounceParameters, &timer->params, params);
|
||||
timer->round = params->rounds;
|
||||
|
@ -120,7 +145,8 @@ static void qemu_announce_self_iter(NICState *nic, void *opaque)
|
|||
skip = false;
|
||||
}
|
||||
|
||||
trace_qemu_announce_self_iter(nic->ncs->name,
|
||||
trace_qemu_announce_self_iter(timer->params.has_id ? timer->params.id : "_",
|
||||
nic->ncs->name,
|
||||
qemu_ether_ntoa(&nic->conf->macaddr), skip);
|
||||
|
||||
if (!skip) {
|
||||
|
@ -143,7 +169,7 @@ static void qemu_announce_self_once(void *opaque)
|
|||
if (--timer->round) {
|
||||
qemu_announce_timer_step(timer);
|
||||
} else {
|
||||
qemu_announce_timer_del(timer);
|
||||
qemu_announce_timer_del(timer, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -154,12 +180,24 @@ void qemu_announce_self(AnnounceTimer *timer, AnnounceParameters *params)
|
|||
if (params->rounds) {
|
||||
qemu_announce_self_once(timer);
|
||||
} else {
|
||||
qemu_announce_timer_del(timer);
|
||||
qemu_announce_timer_del(timer, true);
|
||||
}
|
||||
}
|
||||
|
||||
void qmp_announce_self(AnnounceParameters *params, Error **errp)
|
||||
{
|
||||
static AnnounceTimer announce_timer;
|
||||
qemu_announce_self(&announce_timer, params);
|
||||
AnnounceTimer *named_timer;
|
||||
if (!params->has_id) {
|
||||
params->id = g_strdup("");
|
||||
params->has_id = true;
|
||||
}
|
||||
|
||||
named_timer = g_datalist_get_data(&named_timers, params->id);
|
||||
|
||||
if (!named_timer) {
|
||||
named_timer = g_new0(AnnounceTimer, 1);
|
||||
g_datalist_set_data(&named_timers, params->id, named_timer);
|
||||
}
|
||||
|
||||
qemu_announce_self(named_timer, params);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue