From patchwork Fri Feb 22 14:55:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 1046981 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 445Zyp00Kzz9s9L for ; Sat, 23 Feb 2019 02:29:53 +1100 (AEDT) Received: from localhost ([127.0.0.1]:52715 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxClr-0000HK-TI for incoming@patchwork.ozlabs.org; Fri, 22 Feb 2019 10:29:51 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34801) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxCH5-0000QT-Eb for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:58:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gxCF6-0007gg-GL for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:56:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59990) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gxCF6-0006H9-3X for qemu-devel@nongnu.org; Fri, 22 Feb 2019 09:56:00 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6E4F530C1A41; Fri, 22 Feb 2019 14:55:28 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (ovpn-12-32.pek2.redhat.com [10.72.12.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id B80531A7DD; Fri, 22 Feb 2019 14:55:26 +0000 (UTC) From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Fri, 22 Feb 2019 22:55:09 +0800 Message-Id: <1550847320-25110-3-git-send-email-jasowang@redhat.com> In-Reply-To: <1550847320-25110-1-git-send-email-jasowang@redhat.com> References: <1550847320-25110-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Fri, 22 Feb 2019 14:55:28 +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 02/13] net: Introduce announce timer X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: "Dr. David Alan Gilbert" The 'announce timer' will be used by migration, and explicit requests for qemu to perform network announces. Based on the work by Germano Veit Michel and Vlad Yasevich Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Michael S. Tsirkin Signed-off-by: Jason Wang --- include/net/announce.h | 39 ++++++++++++++++++++++++++++++++ include/qemu/typedefs.h | 1 + migration/migration.c | 1 + net/Makefile.objs | 1 + net/announce.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++ qapi/net.json | 23 +++++++++++++++++++ 6 files changed, 125 insertions(+) create mode 100644 include/net/announce.h create mode 100644 net/announce.c diff --git a/include/net/announce.h b/include/net/announce.h new file mode 100644 index 0000000..b89f1c2 --- /dev/null +++ b/include/net/announce.h @@ -0,0 +1,39 @@ +/* + * Self-announce facility + * (c) 2017-2019 Red Hat, Inc. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#ifndef QEMU_NET_ANNOUNCE_H +#define QEMU_NET_ANNOUNCE_H + +#include "qemu-common.h" +#include "qapi/qapi-types-net.h" +#include "qemu/timer.h" + +struct AnnounceTimer { + QEMUTimer *tm; + AnnounceParameters params; + QEMUClockType type; + int round; +}; + +/* Returns: update the timer to the next time point */ +int64_t qemu_announce_timer_step(AnnounceTimer *timer); + +/* Delete the underlying timer */ +void qemu_announce_timer_del(AnnounceTimer *timer); + +/* + * Under BQL/main thread + * Reset the timer to the given parameters/type/notifier. + */ +void qemu_announce_timer_reset(AnnounceTimer *timer, + AnnounceParameters *params, + QEMUClockType type, + QEMUTimerCB *cb, + void *opaque); + +#endif diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h index 5d1a2d8..e4a0a65 100644 --- a/include/qemu/typedefs.h +++ b/include/qemu/typedefs.h @@ -8,6 +8,7 @@ typedef struct AdapterInfo AdapterInfo; typedef struct AddressSpace AddressSpace; typedef struct AioContext AioContext; +typedef struct AnnounceTimer AnnounceTimer; typedef struct BdrvDirtyBitmap BdrvDirtyBitmap; typedef struct BdrvDirtyBitmapIter BdrvDirtyBitmapIter; typedef struct BlockBackend BlockBackend; diff --git a/migration/migration.c b/migration/migration.c index 37e06b7..a9c4c6f 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -45,6 +45,7 @@ #include "migration/colo.h" #include "hw/boards.h" #include "monitor/monitor.h" +#include "net/announce.h" #define MAX_THROTTLE (32 << 20) /* Migration transfer speed throttling */ diff --git a/net/Makefile.objs b/net/Makefile.objs index b2bf88a..b363fe9 100644 --- a/net/Makefile.objs +++ b/net/Makefile.objs @@ -2,6 +2,7 @@ common-obj-y = net.o queue.o checksum.o util.o hub.o common-obj-y += socket.o common-obj-y += dump.o common-obj-y += eth.o +common-obj-y += announce.o common-obj-$(CONFIG_L2TPV3) += l2tpv3.o common-obj-$(CONFIG_POSIX) += vhost-user.o common-obj-$(CONFIG_SLIRP) += slirp.o diff --git a/net/announce.c b/net/announce.c new file mode 100644 index 0000000..8876eb6 --- /dev/null +++ b/net/announce.c @@ -0,0 +1,60 @@ +/* + * Self-announce + * (c) 2017-2019 Red Hat, Inc. + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "net/announce.h" +#include "qapi/clone-visitor.h" +#include "qapi/qapi-visit-net.h" + +int64_t qemu_announce_timer_step(AnnounceTimer *timer) +{ + int64_t step; + + step = timer->params.initial + + (timer->params.rounds - timer->round - 1) * + timer->params.step; + + if (step < 0 || step > timer->params.max) { + step = timer->params.max; + } + timer_mod(timer->tm, qemu_clock_get_ms(timer->type) + step); + + return step; +} + +void qemu_announce_timer_del(AnnounceTimer *timer) +{ + if (timer->tm) { + timer_del(timer->tm); + timer_free(timer->tm); + timer->tm = NULL; + } +} + +/* + * Under BQL/main thread + * Reset the timer to the given parameters/type/notifier. + */ +void qemu_announce_timer_reset(AnnounceTimer *timer, + AnnounceParameters *params, + QEMUClockType type, + QEMUTimerCB *cb, + void *opaque) +{ + /* + * 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); + + QAPI_CLONE_MEMBERS(AnnounceParameters, &timer->params, params); + timer->round = params->rounds; + timer->type = type; + timer->tm = timer_new_ms(type, cb, opaque); +} diff --git a/qapi/net.json b/qapi/net.json index a1a0f39..5face0c 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -684,3 +684,26 @@ ## { 'event': 'NIC_RX_FILTER_CHANGED', 'data': { '*name': 'str', 'path': 'str' } } + +## +# @AnnounceParameters: +# +# Parameters for self-announce timers +# +# @initial: Initial delay (in ms) before sending the first GARP/RARP +# announcement +# +# @max: Maximum delay (in ms) between GARP/RARP announcement packets +# +# @rounds: Number of self-announcement attempts +# +# @step: Delay increase (in ms) after each self-announcement attempt +# +# Since: 4.0 +## + +{ 'struct': 'AnnounceParameters', + 'data': { 'initial': 'int', + 'max': 'int', + 'rounds': 'int', + 'step': 'int' } }