From nobody Fri Apr 11 19:09:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1562040499; cv=none; d=zoho.com; s=zohoarc; b=V1/WQ2aWWqvqmyrIVrOvSPYiJS4WF/48IJLiQyC4KID1UekavT3TJNsjFhUHvibYzqwxvVA/TpgWoW40Xa0tMLgOpdPAUvHBkHCmC/QmEZsxCZgpbbKMThlN42HFlVQ/yGObm551jowT1BhsISk3vD70MSvC03gfp42FKzxxR9s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562040499; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=BBAV4waYzSpqLd2zmKwKT4OA3PRp+wnqn4l5ZCkCyb8=; b=k2PwE4ABo/QoJENKIAFy8yLrsigF8OkRuQhtA0CSBb3nb7aJ9C3Cf6mheFNXSTrXk/YrDAIs6FgaQxkK3sTStXiGoTg02daqtk2cqODaTzNuK6pSkzgRRCxI3IMugY04yz+7p6uy3F932zWTRzdU43SR8vcdMQoUJM/l0yDwVUo= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1562040499411555.5615191638398; Mon, 1 Jul 2019 21:08:19 -0700 (PDT) Received: from localhost ([::1]:48464 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hiA5a-0001qg-97 for importer@patchew.org; Tue, 02 Jul 2019 00:08:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50479) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hi8aM-0004w5-0S for qemu-devel@nongnu.org; Mon, 01 Jul 2019 22:31:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hi8aK-0003h4-HO for qemu-devel@nongnu.org; Mon, 01 Jul 2019 22:31:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36448) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hi8aK-0003gm-8Y for qemu-devel@nongnu.org; Mon, 01 Jul 2019 22:31:56 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3DBED85363; Tue, 2 Jul 2019 02:31:55 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-232.pek2.redhat.com [10.72.12.232]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9D3BB60C43; Tue, 2 Jul 2019 02:31:53 +0000 (UTC) From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Tue, 2 Jul 2019 10:31:22 +0800 Message-Id: <1562034689-6539-11-git-send-email-jasowang@redhat.com> In-Reply-To: <1562034689-6539-1-git-send-email-jasowang@redhat.com> References: <1562034689-6539-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 02 Jul 2019 02:31:55 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 10/17] net/announce: Add optional ID X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Wang , "Dr. David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" 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 Signed-off-by: Jason Wang --- hw/net/virtio-net.c | 4 ++-- include/net/announce.h | 8 ++++++-- net/announce.c | 52 +++++++++++++++++++++++++++++++++++++++++++---= ---- net/trace-events | 3 ++- qapi/net.json | 9 +++++++-- 5 files changed, 62 insertions(+), 14 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index c3f5fcc..b9e1cd7 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -2360,7 +2360,7 @@ static int virtio_net_post_load_device(void *opaque, = int version_id) timer_mod(n->announce_timer.tm, qemu_clock_get_ms(n->announce_timer.type)); } else { - qemu_announce_timer_del(&n->announce_timer); + qemu_announce_timer_del(&n->announce_timer, false); } } =20 @@ -2784,7 +2784,7 @@ static void virtio_net_device_unrealize(DeviceState *= dev, Error **errp) virtio_net_del_queue(n, i); } =20 - qemu_announce_timer_del(&n->announce_timer); + qemu_announce_timer_del(&n->announce_timer, false); g_free(n->vqs); qemu_del_nic(n->nic); virtio_net_rsc_cleanup(n); diff --git a/include/net/announce.h b/include/net/announce.h index 7734704..3d90c83 100644 --- a/include/net/announce.h +++ b/include/net/announce.h @@ -22,8 +22,12 @@ struct AnnounceTimer { /* Returns: update the timer to the next time point */ int64_t qemu_announce_timer_step(AnnounceTimer *timer); =20 -/* Delete the underlying timer and other data */ -void qemu_announce_timer_del(AnnounceTimer *timer); +/* + * Delete the underlying timer and other data + * If 'free_named' true and the timer is a named timer, then remove + * it from the list of named timers and free the AnnounceTimer itself. + */ +void qemu_announce_timer_del(AnnounceTimer *timer, bool free_named); =20 /* * Under BQL/main thread diff --git a/net/announce.c b/net/announce.c index 1ce42b5..db90d3b 100644 --- a/net/announce.c +++ b/net/announce.c @@ -15,6 +15,8 @@ #include "qapi/qapi-commands-net.h" #include "trace.h" =20 +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; } =20 -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 =3D 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 =3D 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 =3D g_datalist_get_data(&named_timers, timer->params.id= ); + assert(timer =3D=3D list_timer); + free_timer =3D 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 =3D NULL; + + if (free_timer) { + g_free(timer); + } } =20 /* @@ -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); =20 QAPI_CLONE_MEMBERS(AnnounceParameters, &timer->params, params); timer->round =3D params->rounds; @@ -120,7 +145,8 @@ static void qemu_announce_self_iter(NICState *nic, void= *opaque) skip =3D false; } =20 - 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), sk= ip); =20 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); } } =20 @@ -154,12 +180,24 @@ void qemu_announce_self(AnnounceTimer *timer, Announc= eParameters *params) if (params->rounds) { qemu_announce_self_once(timer); } else { - qemu_announce_timer_del(timer); + qemu_announce_timer_del(timer, true); } } =20 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 =3D g_strdup(""); + params->has_id =3D true; + } + + named_timer =3D g_datalist_get_data(&named_timers, params->id); + + if (!named_timer) { + named_timer =3D g_new0(AnnounceTimer, 1); + g_datalist_set_data(&named_timers, params->id, named_timer); + } + + qemu_announce_self(named_timer, params); } diff --git a/net/trace-events b/net/trace-events index 875ef2a..ac57056 100644 --- a/net/trace-events +++ b/net/trace-events @@ -1,7 +1,8 @@ # See docs/devel/tracing.txt for syntax documentation. =20 # announce.c -qemu_announce_self_iter(const char *name, const char *mac, int skip) "%s:%= s skip: %d" +qemu_announce_self_iter(const char *id, const char *name, const char *mac,= int skip) "%s:%s:%s skip: %d" +qemu_announce_timer_del(bool free_named, bool free_timer, char *id) "free = named: %d free timer: %d id: %s" =20 # vhost-user.c vhost_user_event(const char *chr, int event) "chr: %s got event: %d" diff --git a/qapi/net.json b/qapi/net.json index 6f2cd4f..728990f 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -702,6 +702,10 @@ # @interfaces: An optional list of interface names, which restricts the # announcement to the listed interfaces. (Since 4.1) # +# @id: A name to be used to identify an instance of announce-timers +# and to allow it to modified later. Not for use as +# part of the migration parameters. (Since 4.1) +# # Since: 4.0 ## =20 @@ -710,7 +714,8 @@ 'max': 'int', 'rounds': 'int', 'step': 'int', - '*interfaces': ['str'] } } + '*interfaces': ['str'], + '*id' : 'str' } } =20 ## # @announce-self: @@ -725,7 +730,7 @@ # -> { "execute": "announce-self", # "arguments": { # "initial": 50, "max": 550, "rounds": 10, "step": 50, -# "interfaces": ["vn2", "vn3"] } } +# "interfaces": ["vn2", "vn3"], "id": "bob" } } # <- { "return": {} } # # Since: 4.0 --=20 2.5.0