From nobody Tue May 14 00:18:53 2024 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1551274197825627.921037531624; Wed, 27 Feb 2019 05:29:57 -0800 (PST) Received: from localhost ([127.0.0.1]:43738 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyzHW-0005GI-Oz for importer@patchew.org; Wed, 27 Feb 2019 08:29:54 -0500 Received: from eggs.gnu.org ([209.51.188.92]:45763) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyzCM-00011C-PI for qemu-devel@nongnu.org; Wed, 27 Feb 2019 08:24:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gyzCL-0000Y2-Iz for qemu-devel@nongnu.org; Wed, 27 Feb 2019 08:24:34 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54978) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gyzCB-0000UP-6m for qemu-devel@nongnu.org; Wed, 27 Feb 2019 08:24:26 -0500 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 0201B309708E for ; Wed, 27 Feb 2019 13:24:18 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.36.118.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id C9DF060BF4; Wed, 27 Feb 2019 13:24:16 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, jasowang@redhat.com Date: Wed, 27 Feb 2019 13:24:05 +0000 Message-Id: <20190227132413.13213-2-dgilbert@redhat.com> In-Reply-To: <20190227132413.13213-1-dgilbert@redhat.com> References: <20190227132413.13213-1-dgilbert@redhat.com> MIME-Version: 1.0 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.43]); Wed, 27 Feb 2019 13:24:18 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PATCH v6 1/9] 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: thuth@redhat.com, armbru@redhat.com, quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" 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 --- 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 0000000000..b89f1c28b5 --- /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 late= r. + * 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 5d1a2d8329..e4a0a656d1 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 37e06b76dc..a9c4c6f01d 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" =20 #define MAX_THROTTLE (32 << 20) /* Migration transfer speed throttli= ng */ =20 diff --git a/net/Makefile.objs b/net/Makefile.objs index b2bf88a0ef..b363fe92d9 100644 --- a/net/Makefile.objs +++ b/net/Makefile.objs @@ -2,6 +2,7 @@ common-obj-y =3D net.o queue.o checksum.o util.o hub.o common-obj-y +=3D socket.o common-obj-y +=3D dump.o common-obj-y +=3D eth.o +common-obj-y +=3D announce.o common-obj-$(CONFIG_L2TPV3) +=3D l2tpv3.o common-obj-$(CONFIG_POSIX) +=3D vhost-user.o common-obj-$(CONFIG_SLIRP) +=3D slirp.o diff --git a/net/announce.c b/net/announce.c new file mode 100644 index 0000000000..8876eb62b6 --- /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 late= r. + * 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 =3D timer->params.initial + + (timer->params.rounds - timer->round - 1) * + timer->params.step; + + if (step < 0 || step > timer->params.max) { + step =3D 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 =3D 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 =3D params->rounds; + timer->type =3D type; + timer->tm =3D timer_new_ms(type, cb, opaque); +} diff --git a/qapi/net.json b/qapi/net.json index a1a0f39f74..5face0c14b 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' } } --=20 2.20.1 From nobody Tue May 14 00:18:53 2024 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1551274126225797.164585276575; Wed, 27 Feb 2019 05:28:46 -0800 (PST) Received: from localhost ([127.0.0.1]:43730 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyzGI-00044r-0D for importer@patchew.org; Wed, 27 Feb 2019 08:28:38 -0500 Received: from eggs.gnu.org ([209.51.188.92]:45875) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyzCQ-00016G-9Q for qemu-devel@nongnu.org; Wed, 27 Feb 2019 08:24:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gyzCN-0000ZA-Cw for qemu-devel@nongnu.org; Wed, 27 Feb 2019 08:24:38 -0500 Received: from mx1.redhat.com ([209.132.183.28]:5192) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gyzCM-0000Ut-QC for qemu-devel@nongnu.org; Wed, 27 Feb 2019 08:24:35 -0500 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 6DACE3DBE8 for ; Wed, 27 Feb 2019 13:24:19 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.36.118.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 47083619A4; Wed, 27 Feb 2019 13:24:18 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, jasowang@redhat.com Date: Wed, 27 Feb 2019 13:24:06 +0000 Message-Id: <20190227132413.13213-3-dgilbert@redhat.com> In-Reply-To: <20190227132413.13213-1-dgilbert@redhat.com> References: <20190227132413.13213-1-dgilbert@redhat.com> MIME-Version: 1.0 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.30]); Wed, 27 Feb 2019 13:24:19 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PATCH v6 2/9] migration: Add announce parameters 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: thuth@redhat.com, armbru@redhat.com, quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Add migration parameters that control RARP/GARP announcement timeouts. Based on earlier patches by myself and Vladislav Yasevich Signed-off-by: Dr. David Alan Gilbert Acked-by: Markus Armbruster Reviewed-by: Michael S. Tsirkin --- hmp.c | 28 +++++++++++ include/migration/misc.h | 2 + migration/migration.c | 100 +++++++++++++++++++++++++++++++++++++++ qapi/migration.json | 53 +++++++++++++++++++-- 4 files changed, 180 insertions(+), 3 deletions(-) diff --git a/hmp.c b/hmp.c index 1e006eeb49..f3db0bf5a2 100644 --- a/hmp.c +++ b/hmp.c @@ -334,6 +334,18 @@ void hmp_info_migrate_parameters(Monitor *mon, const Q= Dict *qdict) params =3D qmp_query_migrate_parameters(NULL); =20 if (params) { + monitor_printf(mon, "%s: %" PRIu64 " ms\n", + MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_INITIAL), + params->announce_initial); + monitor_printf(mon, "%s: %" PRIu64 " ms\n", + MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_MAX), + params->announce_max); + monitor_printf(mon, "%s: %" PRIu64 "\n", + MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_ROUNDS), + params->announce_rounds); + monitor_printf(mon, "%s: %" PRIu64 " ms\n", + MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_STEP), + params->announce_step); assert(params->has_compress_level); monitor_printf(mon, "%s: %u\n", MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL), @@ -1757,6 +1769,22 @@ void hmp_migrate_set_parameter(Monitor *mon, const Q= Dict *qdict) p->has_max_postcopy_bandwidth =3D true; visit_type_size(v, param, &p->max_postcopy_bandwidth, &err); break; + case MIGRATION_PARAMETER_ANNOUNCE_INITIAL: + p->has_announce_initial =3D true; + visit_type_size(v, param, &p->announce_initial, &err); + break; + case MIGRATION_PARAMETER_ANNOUNCE_MAX: + p->has_announce_max =3D true; + visit_type_size(v, param, &p->announce_max, &err); + break; + case MIGRATION_PARAMETER_ANNOUNCE_ROUNDS: + p->has_announce_rounds =3D true; + visit_type_size(v, param, &p->announce_rounds, &err); + break; + case MIGRATION_PARAMETER_ANNOUNCE_STEP: + p->has_announce_step =3D true; + visit_type_size(v, param, &p->announce_step, &err); + break; default: assert(0); } diff --git a/include/migration/misc.h b/include/migration/misc.h index 4ebf24c6c2..e837ab3042 100644 --- a/include/migration/misc.h +++ b/include/migration/misc.h @@ -15,6 +15,7 @@ #define MIGRATION_MISC_H =20 #include "qemu/notify.h" +#include "qapi/qapi-types-net.h" =20 /* migration/ram.c */ =20 @@ -38,6 +39,7 @@ int64_t self_announce_delay(int round) return 50 + (SELF_ANNOUNCE_ROUNDS - round - 1) * 100; } =20 +AnnounceParameters *migrate_announce_params(void); /* migration/savevm.c */ =20 void dump_vmstate_json_to_file(FILE *out_fp); diff --git a/migration/migration.c b/migration/migration.c index a9c4c6f01d..ca9c35a5cd 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -87,6 +87,15 @@ */ #define DEFAULT_MIGRATE_MAX_POSTCOPY_BANDWIDTH 0 =20 +/* + * Parameters for self_announce_delay giving a stream of RARP/ARP + * packets after migration. + */ +#define DEFAULT_MIGRATE_ANNOUNCE_INITIAL 50 +#define DEFAULT_MIGRATE_ANNOUNCE_MAX 550 +#define DEFAULT_MIGRATE_ANNOUNCE_ROUNDS 5 +#define DEFAULT_MIGRATE_ANNOUNCE_STEP 100 + static NotifierList migration_state_notifiers =3D NOTIFIER_LIST_INITIALIZER(migration_state_notifiers); =20 @@ -740,10 +749,32 @@ MigrationParameters *qmp_query_migrate_parameters(Err= or **errp) params->max_postcopy_bandwidth =3D s->parameters.max_postcopy_bandwidt= h; params->has_max_cpu_throttle =3D true; params->max_cpu_throttle =3D s->parameters.max_cpu_throttle; + params->has_announce_initial =3D true; + params->announce_initial =3D s->parameters.announce_initial; + params->has_announce_max =3D true; + params->announce_max =3D s->parameters.announce_max; + params->has_announce_rounds =3D true; + params->announce_rounds =3D s->parameters.announce_rounds; + params->has_announce_step =3D true; + params->announce_step =3D s->parameters.announce_step; =20 return params; } =20 +AnnounceParameters *migrate_announce_params(void) +{ + static AnnounceParameters ap; + + MigrationState *s =3D migrate_get_current(); + + ap.initial =3D s->parameters.announce_initial; + ap.max =3D s->parameters.announce_max; + ap.rounds =3D s->parameters.announce_rounds; + ap.step =3D s->parameters.announce_step; + + return ≈ +} + /* * Return true if we're already in the middle of a migration * (i.e. any of the active or setup states) @@ -1117,6 +1148,35 @@ static bool migrate_params_check(MigrationParameters= *params, Error **errp) return false; } =20 + if (params->has_announce_initial && + params->announce_initial > 100000) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, + "announce_initial", + "is invalid, it must be less than 100000 ms"); + return false; + } + if (params->has_announce_max && + params->announce_max > 100000) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, + "announce_max", + "is invalid, it must be less than 100000 ms"); + return false; + } + if (params->has_announce_rounds && + params->announce_rounds > 1000) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, + "announce_rounds", + "is invalid, it must be in the range of 0 to 1000"); + return false; + } + if (params->has_announce_step && + (params->announce_step < 1 || + params->announce_step > 10000)) { + error_setg(errp, QERR_INVALID_PARAMETER_VALUE, + "announce_step", + "is invalid, it must be in the range of 1 to 10000 ms"); + return false; + } return true; } =20 @@ -1191,6 +1251,18 @@ static void migrate_params_test_apply(MigrateSetPara= meters *params, if (params->has_max_cpu_throttle) { dest->max_cpu_throttle =3D params->max_cpu_throttle; } + if (params->has_announce_initial) { + dest->announce_initial =3D params->announce_initial; + } + if (params->has_announce_max) { + dest->announce_max =3D params->announce_max; + } + if (params->has_announce_rounds) { + dest->announce_rounds =3D params->announce_rounds; + } + if (params->has_announce_step) { + dest->announce_step =3D params->announce_step; + } } =20 static void migrate_params_apply(MigrateSetParameters *params, Error **err= p) @@ -1273,6 +1345,18 @@ static void migrate_params_apply(MigrateSetParameter= s *params, Error **errp) if (params->has_max_cpu_throttle) { s->parameters.max_cpu_throttle =3D params->max_cpu_throttle; } + if (params->has_announce_initial) { + s->parameters.announce_initial =3D params->announce_initial; + } + if (params->has_announce_max) { + s->parameters.announce_max =3D params->announce_max; + } + if (params->has_announce_rounds) { + s->parameters.announce_rounds =3D params->announce_rounds; + } + if (params->has_announce_step) { + s->parameters.announce_step =3D params->announce_step; + } } =20 void qmp_migrate_set_parameters(MigrateSetParameters *params, Error **errp) @@ -3275,6 +3359,18 @@ static Property migration_properties[] =3D { DEFINE_PROP_UINT8("max-cpu-throttle", MigrationState, parameters.max_cpu_throttle, DEFAULT_MIGRATE_MAX_CPU_THROTTLE), + DEFINE_PROP_SIZE("announce-initial", MigrationState, + parameters.announce_initial, + DEFAULT_MIGRATE_ANNOUNCE_INITIAL), + DEFINE_PROP_SIZE("announce-max", MigrationState, + parameters.announce_max, + DEFAULT_MIGRATE_ANNOUNCE_MAX), + DEFINE_PROP_SIZE("announce-rounds", MigrationState, + parameters.announce_rounds, + DEFAULT_MIGRATE_ANNOUNCE_ROUNDS), + DEFINE_PROP_SIZE("announce-step", MigrationState, + parameters.announce_step, + DEFAULT_MIGRATE_ANNOUNCE_STEP), =20 /* Migration capabilities */ DEFINE_PROP_MIG_CAP("x-xbzrle", MIGRATION_CAPABILITY_XBZRLE), @@ -3347,6 +3443,10 @@ static void migration_instance_init(Object *obj) params->has_xbzrle_cache_size =3D true; params->has_max_postcopy_bandwidth =3D true; params->has_max_cpu_throttle =3D true; + params->has_announce_initial =3D true; + params->has_announce_max =3D true; + params->has_announce_rounds =3D true; + params->has_announce_step =3D true; =20 qemu_sem_init(&ms->postcopy_pause_sem, 0); qemu_sem_init(&ms->postcopy_pause_rp_sem, 0); diff --git a/qapi/migration.json b/qapi/migration.json index 7a795ecc16..1fd7bbea9b 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -480,6 +480,18 @@ # # Migration parameters enumeration # +# @announce-initial: Initial delay (in milliseconds) before sending the fi= rst +# announce (Since 4.0) +# +# @announce-max: Maximum delay (in milliseconds) between packets in the +# announcement (Since 4.0) +# +# @announce-rounds: Number of self-announce packets sent after migration +# (Since 4.0) +# +# @announce-step: Increase in delay (in milliseconds) between subsequent +# packets in the announcement (Since 4.0) +# # @compress-level: Set the compression level to be used in live migration, # the compression level is an integer between 0 and 9, where 0 me= ans # no compression, 1 means the best compression speed, and 9 means= best @@ -557,10 +569,13 @@ # # @max-cpu-throttle: maximum cpu throttle percentage. # Defaults to 99. (Since 3.1) +# # Since: 2.4 ## { 'enum': 'MigrationParameter', - 'data': ['compress-level', 'compress-threads', 'decompress-threads', + 'data': ['announce-initial', 'announce-max', + 'announce-rounds', 'announce-step', + 'compress-level', 'compress-threads', 'decompress-threads', 'compress-wait-thread', 'cpu-throttle-initial', 'cpu-throttle-increment', 'tls-creds', 'tls-hostname', 'max-bandwidth', @@ -572,6 +587,18 @@ ## # @MigrateSetParameters: # +# @announce-initial: Initial delay (in milliseconds) before sending the fi= rst +# announce (Since 4.0) +# +# @announce-max: Maximum delay (in milliseconds) between packets in the +# announcement (Since 4.0) +# +# @announce-rounds: Number of self-announce packets sent after migration +# (Since 4.0) +# +# @announce-step: Increase in delay (in milliseconds) between subsequent +# packets in the announcement (Since 4.0) +# # @compress-level: compression level # # @compress-threads: compression thread count @@ -653,7 +680,11 @@ # TODO either fuse back into MigrationParameters, or make # MigrationParameters members mandatory { 'struct': 'MigrateSetParameters', - 'data': { '*compress-level': 'int', + 'data': { '*announce-initial': 'size', + '*announce-max': 'size', + '*announce-rounds': 'size', + '*announce-step': 'size', + '*compress-level': 'int', '*compress-threads': 'int', '*compress-wait-thread': 'bool', '*decompress-threads': 'int', @@ -692,6 +723,18 @@ # # The optional members aren't actually optional. # +# @announce-initial: Initial delay (in milliseconds) before sending the +# first announce (Since 4.0) +# +# @announce-max: Maximum delay (in milliseconds) between packets in the +# announcement (Since 4.0) +# +# @announce-rounds: Number of self-announce packets sent after migration +# (Since 4.0) +# +# @announce-step: Increase in delay (in milliseconds) between subsequent +# packets in the announcement (Since 4.0) +# # @compress-level: compression level # # @compress-threads: compression thread count @@ -769,7 +812,11 @@ # Since: 2.4 ## { 'struct': 'MigrationParameters', - 'data': { '*compress-level': 'uint8', + 'data': { '*announce-initial': 'size', + '*announce-max': 'size', + '*announce-rounds': 'size', + '*announce-step': 'size', + '*compress-level': 'uint8', '*compress-threads': 'uint8', '*compress-wait-thread': 'bool', '*decompress-threads': 'uint8', --=20 2.20.1 From nobody Tue May 14 00:18:53 2024 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1551274553292505.901052083403; Wed, 27 Feb 2019 05:35:53 -0800 (PST) Received: from localhost ([127.0.0.1]:43854 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyzNG-0000vR-7j for importer@patchew.org; Wed, 27 Feb 2019 08:35:50 -0500 Received: from eggs.gnu.org ([209.51.188.92]:45815) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyzCO-00014Q-7k for qemu-devel@nongnu.org; Wed, 27 Feb 2019 08:24:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gyzCM-0000Yj-RN for qemu-devel@nongnu.org; Wed, 27 Feb 2019 08:24:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59172) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gyzCM-0000V8-Ej for qemu-devel@nongnu.org; Wed, 27 Feb 2019 08:24:34 -0500 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 E1C1F313D672 for ; Wed, 27 Feb 2019 13:24:20 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.36.118.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id B7F8A60BF4; Wed, 27 Feb 2019 13:24:19 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, jasowang@redhat.com Date: Wed, 27 Feb 2019 13:24:07 +0000 Message-Id: <20190227132413.13213-4-dgilbert@redhat.com> In-Reply-To: <20190227132413.13213-1-dgilbert@redhat.com> References: <20190227132413.13213-1-dgilbert@redhat.com> MIME-Version: 1.0 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.49]); Wed, 27 Feb 2019 13:24:20 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PATCH v6 3/9] virtio-net: Switch to using 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: thuth@redhat.com, armbru@redhat.com, quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Switch virtio's self announcement to use the AnnounceTimer. It keeps it's own AnnounceTimer (per device), and starts running it using a migration post-load and a virtual clock; that way the announce happens once the guest is actually running. The timer uses the migration parameters to set the timing of the repeats. Based on earlier patches by myself and Vladislav Yasevich Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Michael S. Tsirkin --- hw/net/trace-events | 5 +++++ hw/net/virtio-net.c | 36 ++++++++++++++++++++++------------ include/hw/virtio/virtio-net.h | 4 ++-- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/hw/net/trace-events b/hw/net/trace-events index 9d49f62fa1..b237d9024c 100644 --- a/hw/net/trace-events +++ b/hw/net/trace-events @@ -359,3 +359,8 @@ sunhme_rx_filter_reject(void) "rejecting incoming frame" sunhme_rx_filter_accept(void) "accepting incoming frame" sunhme_rx_desc(uint32_t addr, int offset, uint32_t status, int len, int cr= , int nr) "addr 0x%"PRIx32"(+0x%x) status 0x%"PRIx32 " len %d (ring %d/%d)" sunhme_rx_xsum_calc(uint16_t xsum) "calculated incoming xsum as 0x%x" + +# hw/net/virtio-net.c +virtio_net_announce_timer(int round) "%d" +virtio_net_handle_announce(int round) "%d" +virtio_net_post_load_device(void) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 6e6b146022..38b8974144 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -21,12 +21,14 @@ #include "qemu/timer.h" #include "hw/virtio/virtio-net.h" #include "net/vhost_net.h" +#include "net/announce.h" #include "hw/virtio/virtio-bus.h" #include "qapi/error.h" #include "qapi/qapi-events-net.h" #include "hw/virtio/virtio-access.h" #include "migration/misc.h" #include "standard-headers/linux/ethtool.h" +#include "trace.h" =20 #define VIRTIO_NET_VM_VERSION 11 =20 @@ -152,8 +154,9 @@ static void virtio_net_announce_timer(void *opaque) { VirtIONet *n =3D opaque; VirtIODevice *vdev =3D VIRTIO_DEVICE(n); + trace_virtio_net_announce_timer(n->announce_timer.round); =20 - n->announce_counter--; + n->announce_timer.round--; n->status |=3D VIRTIO_NET_S_ANNOUNCE; virtio_notify_config(vdev); } @@ -467,8 +470,8 @@ static void virtio_net_reset(VirtIODevice *vdev) n->nobcast =3D 0; /* multiqueue is disabled by default */ n->curr_queues =3D 1; - timer_del(n->announce_timer); - n->announce_counter =3D 0; + timer_del(n->announce_timer.tm); + n->announce_timer.round =3D 0; n->status &=3D ~VIRTIO_NET_S_ANNOUNCE; =20 /* Flush any MAC and VLAN filter table state */ @@ -964,13 +967,12 @@ static int virtio_net_handle_vlan_table(VirtIONet *n,= uint8_t cmd, static int virtio_net_handle_announce(VirtIONet *n, uint8_t cmd, struct iovec *iov, unsigned int iov_= cnt) { + trace_virtio_net_handle_announce(n->announce_timer.round); if (cmd =3D=3D VIRTIO_NET_CTRL_ANNOUNCE_ACK && n->status & VIRTIO_NET_S_ANNOUNCE) { n->status &=3D ~VIRTIO_NET_S_ANNOUNCE; - if (n->announce_counter) { - timer_mod(n->announce_timer, - qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + - self_announce_delay(n->announce_counter)); + if (n->announce_timer.round) { + qemu_announce_timer_step(&n->announce_timer); } return VIRTIO_NET_OK; } else { @@ -2286,6 +2288,7 @@ static int virtio_net_post_load_device(void *opaque, = int version_id) VirtIODevice *vdev =3D VIRTIO_DEVICE(n); int i, link_down; =20 + trace_virtio_net_post_load_device(); virtio_net_set_mrg_rx_bufs(n, n->mergeable_rx_bufs, virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1)= ); @@ -2322,8 +2325,15 @@ static int virtio_net_post_load_device(void *opaque,= int version_id) =20 if (virtio_vdev_has_feature(vdev, VIRTIO_NET_F_GUEST_ANNOUNCE) && virtio_vdev_has_feature(vdev, VIRTIO_NET_F_CTRL_VQ)) { - n->announce_counter =3D SELF_ANNOUNCE_ROUNDS; - timer_mod(n->announce_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL)= ); + qemu_announce_timer_reset(&n->announce_timer, migrate_announce_par= ams(), + QEMU_CLOCK_VIRTUAL, + virtio_net_announce_timer, n); + if (n->announce_timer.round) { + timer_mod(n->announce_timer.tm, + qemu_clock_get_ms(n->announce_timer.type)); + } else { + qemu_announce_timer_del(&n->announce_timer); + } } =20 return 0; @@ -2679,8 +2689,9 @@ static void virtio_net_device_realize(DeviceState *de= v, Error **errp) qemu_macaddr_default_if_unset(&n->nic_conf.macaddr); memcpy(&n->mac[0], &n->nic_conf.macaddr, sizeof(n->mac)); n->status =3D VIRTIO_NET_S_LINK_UP; - n->announce_timer =3D timer_new_ms(QEMU_CLOCK_VIRTUAL, - virtio_net_announce_timer, n); + qemu_announce_timer_reset(&n->announce_timer, migrate_announce_params(= ), + QEMU_CLOCK_VIRTUAL, + virtio_net_announce_timer, n); =20 if (n->netclient_type) { /* @@ -2743,8 +2754,7 @@ static void virtio_net_device_unrealize(DeviceState *= dev, Error **errp) virtio_net_del_queue(n, i); } =20 - timer_del(n->announce_timer); - timer_free(n->announce_timer); + qemu_announce_timer_del(&n->announce_timer); g_free(n->vqs); qemu_del_nic(n->nic); virtio_net_rsc_cleanup(n); diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index a1a0be3bea..b96f0c643f 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -17,6 +17,7 @@ #include "qemu/units.h" #include "standard-headers/linux/virtio_net.h" #include "hw/virtio/virtio.h" +#include "net/announce.h" =20 #define TYPE_VIRTIO_NET "virtio-net-device" #define VIRTIO_NET(obj) \ @@ -181,8 +182,7 @@ struct VirtIONet { char *netclient_name; char *netclient_type; uint64_t curr_guest_offloads; - QEMUTimer *announce_timer; - int announce_counter; + AnnounceTimer announce_timer; bool needs_vnet_hdr_swap; bool mtu_bypass_backend; }; --=20 2.20.1 From nobody Tue May 14 00:18:53 2024 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1551274707872401.21432079245096; Wed, 27 Feb 2019 05:38:27 -0800 (PST) Received: from localhost ([127.0.0.1]:43871 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyzPk-0002Rz-Pt for importer@patchew.org; Wed, 27 Feb 2019 08:38:24 -0500 Received: from eggs.gnu.org ([209.51.188.92]:45811) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyzCO-00014O-6h for qemu-devel@nongnu.org; Wed, 27 Feb 2019 08:24:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gyzCM-0000YK-En for qemu-devel@nongnu.org; Wed, 27 Feb 2019 08:24:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:2492) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gyzCG-0000VQ-1j for qemu-devel@nongnu.org; Wed, 27 Feb 2019 08:24:30 -0500 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 5F3FF7BDC2 for ; Wed, 27 Feb 2019 13:24:22 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.36.118.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 37B0660BF4; Wed, 27 Feb 2019 13:24:21 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, jasowang@redhat.com Date: Wed, 27 Feb 2019 13:24:08 +0000 Message-Id: <20190227132413.13213-5-dgilbert@redhat.com> In-Reply-To: <20190227132413.13213-1-dgilbert@redhat.com> References: <20190227132413.13213-1-dgilbert@redhat.com> MIME-Version: 1.0 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.26]); Wed, 27 Feb 2019 13:24:22 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PATCH v6 4/9] migration: Switch to using 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: thuth@redhat.com, armbru@redhat.com, quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Switch the announcements to using the new announce timer. Move the code that does it to announce.c rather than savevm because it really has nothing to do with the actual migration. Migration starts the announce from bh's and so they're all in the main thread/bql, and so there's never any racing with the timers themselves. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Michael S. Tsirkin --- include/migration/misc.h | 10 ------ include/net/announce.h | 2 ++ include/sysemu/sysemu.h | 2 -- migration/migration.c | 2 +- migration/migration.h | 4 +++ migration/savevm.c | 72 ++-------------------------------------- migration/trace-events | 1 - net/announce.c | 68 +++++++++++++++++++++++++++++++++++++ net/trace-events | 3 ++ 9 files changed, 81 insertions(+), 83 deletions(-) diff --git a/include/migration/misc.h b/include/migration/misc.h index e837ab3042..0471e04d1f 100644 --- a/include/migration/misc.h +++ b/include/migration/misc.h @@ -29,16 +29,6 @@ void blk_mig_init(void); static inline void blk_mig_init(void) {} #endif =20 -#define SELF_ANNOUNCE_ROUNDS 5 - -static inline -int64_t self_announce_delay(int round) -{ - assert(round < SELF_ANNOUNCE_ROUNDS && round > 0); - /* delay 50ms, 150ms, 250ms, ... */ - return 50 + (SELF_ANNOUNCE_ROUNDS - round - 1) * 100; -} - AnnounceParameters *migrate_announce_params(void); /* migration/savevm.c */ =20 diff --git a/include/net/announce.h b/include/net/announce.h index b89f1c28b5..892d302b65 100644 --- a/include/net/announce.h +++ b/include/net/announce.h @@ -36,4 +36,6 @@ void qemu_announce_timer_reset(AnnounceTimer *timer, QEMUTimerCB *cb, void *opaque); =20 +void qemu_announce_self(AnnounceTimer *timer, AnnounceParameters *params); + #endif diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 4b5a6b77f9..89604a8328 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -81,8 +81,6 @@ extern bool machine_init_done; void qemu_add_machine_init_done_notifier(Notifier *notify); void qemu_remove_machine_init_done_notifier(Notifier *notify); =20 -void qemu_announce_self(void); - extern int autostart; =20 typedef enum { diff --git a/migration/migration.c b/migration/migration.c index ca9c35a5cd..c39d3054ec 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -374,7 +374,7 @@ static void process_incoming_migration_bh(void *opaque) * This must happen after all error conditions are dealt with and * we're sure the VM is going to be running on this host. */ - qemu_announce_self(); + qemu_announce_self(&mis->announce_timer, migrate_announce_params()); =20 if (multifd_load_cleanup(&local_err) !=3D 0) { error_report_err(local_err); diff --git a/migration/migration.h b/migration/migration.h index dcd05d9f87..c99154dea2 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -21,6 +21,7 @@ #include "qemu/coroutine_int.h" #include "hw/qdev.h" #include "io/channel.h" +#include "net/announce.h" =20 struct PostcopyBlocktimeContext; =20 @@ -36,6 +37,9 @@ struct MigrationIncomingState { */ QemuEvent main_thread_load_event; =20 + /* For network announces */ + AnnounceTimer announce_timer; + size_t largest_page_size; bool have_fault_thread; QemuThread fault_thread; diff --git a/migration/savevm.c b/migration/savevm.c index 322660438d..b3868f7fb5 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -57,13 +57,7 @@ #include "sysemu/replay.h" #include "qjson.h" #include "migration/colo.h" - -#ifndef ETH_P_RARP -#define ETH_P_RARP 0x8035 -#endif -#define ARP_HTYPE_ETH 0x0001 -#define ARP_PTYPE_IP 0x0800 -#define ARP_OP_REQUEST_REV 0x3 +#include "net/announce.h" =20 const unsigned int postcopy_ram_discard_version =3D 0; =20 @@ -125,67 +119,6 @@ static struct mig_cmd_args { * generic extendable format with an exception for two old entities. */ =20 -static int announce_self_create(uint8_t *buf, - uint8_t *mac_addr) -{ - /* Ethernet header. */ - memset(buf, 0xff, 6); /* destination MAC addr */ - memcpy(buf + 6, mac_addr, 6); /* source MAC addr */ - *(uint16_t *)(buf + 12) =3D htons(ETH_P_RARP); /* ethertype */ - - /* RARP header. */ - *(uint16_t *)(buf + 14) =3D htons(ARP_HTYPE_ETH); /* hardware addr spa= ce */ - *(uint16_t *)(buf + 16) =3D htons(ARP_PTYPE_IP); /* protocol addr spac= e */ - *(buf + 18) =3D 6; /* hardware addr length (ethernet) */ - *(buf + 19) =3D 4; /* protocol addr length (IPv4) */ - *(uint16_t *)(buf + 20) =3D htons(ARP_OP_REQUEST_REV); /* opcode */ - memcpy(buf + 22, mac_addr, 6); /* source hw addr */ - memset(buf + 28, 0x00, 4); /* source protocol addr */ - memcpy(buf + 32, mac_addr, 6); /* target hw addr */ - memset(buf + 38, 0x00, 4); /* target protocol addr */ - - /* Padding to get up to 60 bytes (ethernet min packet size, minus FCS)= . */ - memset(buf + 42, 0x00, 18); - - return 60; /* len (FCS will be added by hardware) */ -} - -static void qemu_announce_self_iter(NICState *nic, void *opaque) -{ - uint8_t buf[60]; - int len; - - trace_qemu_announce_self_iter(qemu_ether_ntoa(&nic->conf->macaddr)); - len =3D announce_self_create(buf, nic->conf->macaddr.a); - - qemu_send_packet_raw(qemu_get_queue(nic), buf, len); -} - - -static void qemu_announce_self_once(void *opaque) -{ - static int count =3D SELF_ANNOUNCE_ROUNDS; - QEMUTimer *timer =3D *(QEMUTimer **)opaque; - - qemu_foreach_nic(qemu_announce_self_iter, NULL); - - if (--count) { - /* delay 50ms, 150ms, 250ms, ... */ - timer_mod(timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + - self_announce_delay(count)); - } else { - timer_del(timer); - timer_free(timer); - } -} - -void qemu_announce_self(void) -{ - static QEMUTimer *timer; - timer =3D timer_new_ms(QEMU_CLOCK_REALTIME, qemu_announce_self_once, &= timer); - qemu_announce_self_once(&timer); -} - /***********************************************************/ /* savevm/loadvm support */ =20 @@ -1765,13 +1698,14 @@ static void loadvm_postcopy_handle_run_bh(void *opa= que) { Error *local_err =3D NULL; HandleRunBhData *data =3D opaque; + MigrationIncomingState *mis =3D migration_incoming_get_current(); =20 /* TODO we should move all of this lot into postcopy_ram.c or a shared= code * in migration.c */ cpu_synchronize_all_post_init(); =20 - qemu_announce_self(); + qemu_announce_self(&mis->announce_timer, migrate_announce_params()); =20 /* Make sure all file formats flush their mutable metadata. * If we get an error here, just don't restart the VM yet. */ diff --git a/migration/trace-events b/migration/trace-events index bd2d0cd25a..72e3fcb885 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -52,7 +52,6 @@ vmstate_save_state_top(const char *idstr) "%s" vmstate_subsection_save_loop(const char *name, const char *sub) "%s/%s" vmstate_subsection_save_top(const char *idstr) "%s" vmstate_load(const char *idstr, const char *vmsd_name) "%s, %s" -qemu_announce_self_iter(const char *mac) "%s" =20 # migration/vmstate.c vmstate_load_field_error(const char *field, int ret) "field \"%s\" load fa= iled, ret =3D %d" diff --git a/net/announce.c b/net/announce.c index 8876eb62b6..13ad9c2ba8 100644 --- a/net/announce.c +++ b/net/announce.c @@ -9,8 +9,10 @@ #include "qemu/osdep.h" #include "qemu-common.h" #include "net/announce.h" +#include "net/net.h" #include "qapi/clone-visitor.h" #include "qapi/qapi-visit-net.h" +#include "trace.h" =20 int64_t qemu_announce_timer_step(AnnounceTimer *timer) { @@ -58,3 +60,69 @@ void qemu_announce_timer_reset(AnnounceTimer *timer, timer->type =3D type; timer->tm =3D timer_new_ms(type, cb, opaque); } + +#ifndef ETH_P_RARP +#define ETH_P_RARP 0x8035 +#endif +#define ARP_HTYPE_ETH 0x0001 +#define ARP_PTYPE_IP 0x0800 +#define ARP_OP_REQUEST_REV 0x3 + +static int announce_self_create(uint8_t *buf, + uint8_t *mac_addr) +{ + /* Ethernet header. */ + memset(buf, 0xff, 6); /* destination MAC addr */ + memcpy(buf + 6, mac_addr, 6); /* source MAC addr */ + *(uint16_t *)(buf + 12) =3D htons(ETH_P_RARP); /* ethertype */ + + /* RARP header. */ + *(uint16_t *)(buf + 14) =3D htons(ARP_HTYPE_ETH); /* hardware addr spa= ce */ + *(uint16_t *)(buf + 16) =3D htons(ARP_PTYPE_IP); /* protocol addr spac= e */ + *(buf + 18) =3D 6; /* hardware addr length (ethernet) */ + *(buf + 19) =3D 4; /* protocol addr length (IPv4) */ + *(uint16_t *)(buf + 20) =3D htons(ARP_OP_REQUEST_REV); /* opcode */ + memcpy(buf + 22, mac_addr, 6); /* source hw addr */ + memset(buf + 28, 0x00, 4); /* source protocol addr */ + memcpy(buf + 32, mac_addr, 6); /* target hw addr */ + memset(buf + 38, 0x00, 4); /* target protocol addr */ + + /* Padding to get up to 60 bytes (ethernet min packet size, minus FCS)= . */ + memset(buf + 42, 0x00, 18); + + return 60; /* len (FCS will be added by hardware) */ +} + +static void qemu_announce_self_iter(NICState *nic, void *opaque) +{ + uint8_t buf[60]; + int len; + + trace_qemu_announce_self_iter(qemu_ether_ntoa(&nic->conf->macaddr)); + len =3D announce_self_create(buf, nic->conf->macaddr.a); + + qemu_send_packet_raw(qemu_get_queue(nic), buf, len); +} +static void qemu_announce_self_once(void *opaque) +{ + AnnounceTimer *timer =3D (AnnounceTimer *)opaque; + + qemu_foreach_nic(qemu_announce_self_iter, NULL); + + if (--timer->round) { + qemu_announce_timer_step(timer); + } else { + qemu_announce_timer_del(timer); + } +} + +void qemu_announce_self(AnnounceTimer *timer, AnnounceParameters *params) +{ + qemu_announce_timer_reset(timer, params, QEMU_CLOCK_REALTIME, + qemu_announce_self_once, timer); + if (params->rounds) { + qemu_announce_self_once(timer); + } else { + qemu_announce_timer_del(timer); + } +} diff --git a/net/trace-events b/net/trace-events index 7b594cfdd2..3417ac05b0 100644 --- a/net/trace-events +++ b/net/trace-events @@ -1,5 +1,8 @@ # See docs/devel/tracing.txt for syntax documentation. =20 +# net/announce.c +qemu_announce_self_iter(const char *mac) "%s" + # net/vhost-user.c vhost_user_event(const char *chr, int event) "chr: %s got event: %d" =20 --=20 2.20.1 From nobody Tue May 14 00:18:53 2024 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1551274461168478.6668666784666; Wed, 27 Feb 2019 05:34:21 -0800 (PST) Received: from localhost ([127.0.0.1]:43812 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyzLl-0008PU-6j for importer@patchew.org; Wed, 27 Feb 2019 08:34:17 -0500 Received: from eggs.gnu.org ([209.51.188.92]:45832) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyzCO-00014c-Hs for qemu-devel@nongnu.org; Wed, 27 Feb 2019 08:24:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gyzCN-0000ZD-Dl for qemu-devel@nongnu.org; Wed, 27 Feb 2019 08:24:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46286) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gyzCM-0000W2-TD for qemu-devel@nongnu.org; Wed, 27 Feb 2019 08:24:35 -0500 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 D019FCFDB for ; Wed, 27 Feb 2019 13:24:23 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.36.118.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id A84F560BF4; Wed, 27 Feb 2019 13:24:22 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, jasowang@redhat.com Date: Wed, 27 Feb 2019 13:24:09 +0000 Message-Id: <20190227132413.13213-6-dgilbert@redhat.com> In-Reply-To: <20190227132413.13213-1-dgilbert@redhat.com> References: <20190227132413.13213-1-dgilbert@redhat.com> MIME-Version: 1.0 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.30]); Wed, 27 Feb 2019 13:24:23 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PATCH v6 5/9] net: Add a network device specific self-announcement ability 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: thuth@redhat.com, armbru@redhat.com, quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Some network devices have a capability to do self announcements (ex: virtio-net). Add infrastructure that would allow devices to expose this ability. Signed-off-by: Vladislav Yasevich Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Michael S. Tsirkin --- include/net/net.h | 2 ++ net/announce.c | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/include/net/net.h b/include/net/net.h index 075cc01267..acf0451fc4 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -60,6 +60,7 @@ typedef int (SetVnetLE)(NetClientState *, bool); typedef int (SetVnetBE)(NetClientState *, bool); typedef struct SocketReadState SocketReadState; typedef void (SocketReadStateFinalize)(SocketReadState *rs); +typedef void (NetAnnounce)(NetClientState *); =20 typedef struct NetClientInfo { NetClientDriver type; @@ -80,6 +81,7 @@ typedef struct NetClientInfo { SetVnetHdrLen *set_vnet_hdr_len; SetVnetLE *set_vnet_le; SetVnetBE *set_vnet_be; + NetAnnounce *announce; } NetClientInfo; =20 struct NetClientState { diff --git a/net/announce.c b/net/announce.c index 13ad9c2ba8..070f37a7fa 100644 --- a/net/announce.c +++ b/net/announce.c @@ -102,6 +102,11 @@ static void qemu_announce_self_iter(NICState *nic, voi= d *opaque) len =3D announce_self_create(buf, nic->conf->macaddr.a); =20 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) { --=20 2.20.1 From nobody Tue May 14 00:18:53 2024 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1551274592355810.5643692370987; Wed, 27 Feb 2019 05:36:32 -0800 (PST) Received: from localhost ([127.0.0.1]:43859 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyzNn-0001IP-DM for importer@patchew.org; Wed, 27 Feb 2019 08:36:23 -0500 Received: from eggs.gnu.org ([209.51.188.92]:45841) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyzCP-00014z-1A for qemu-devel@nongnu.org; Wed, 27 Feb 2019 08:24:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gyzCN-0000Yv-By for qemu-devel@nongnu.org; Wed, 27 Feb 2019 08:24:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51186) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gyzCM-0000WE-Qc for qemu-devel@nongnu.org; Wed, 27 Feb 2019 08:24:35 -0500 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 5293130BD1C6 for ; Wed, 27 Feb 2019 13:24:25 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.36.118.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 25D3D60C9C; Wed, 27 Feb 2019 13:24:23 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, jasowang@redhat.com Date: Wed, 27 Feb 2019 13:24:10 +0000 Message-Id: <20190227132413.13213-7-dgilbert@redhat.com> In-Reply-To: <20190227132413.13213-1-dgilbert@redhat.com> References: <20190227132413.13213-1-dgilbert@redhat.com> MIME-Version: 1.0 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.42]); Wed, 27 Feb 2019 13:24:25 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PATCH v6 6/9] virtio-net: Allow qemu_announce_self to trigger virtio announcements 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: thuth@redhat.com, armbru@redhat.com, quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Expose the virtio-net self announcement capability and allow qemu_announce_self() to call it. These announces are caused by something external (i.e. the announce-self command); they won't trigger if the migration counter is triggering announces at the same time. Signed-off-by: Vladislav Yasevich Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Michael S. Tsirkin --- hw/net/trace-events | 1 + hw/net/virtio-net.c | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/hw/net/trace-events b/hw/net/trace-events index b237d9024c..3a86004154 100644 --- a/hw/net/trace-events +++ b/hw/net/trace-events @@ -361,6 +361,7 @@ sunhme_rx_desc(uint32_t addr, int offset, uint32_t stat= us, int len, int cr, int sunhme_rx_xsum_calc(uint16_t xsum) "calculated incoming xsum as 0x%x" =20 # hw/net/virtio-net.c +virtio_net_announce_notify(void) "" virtio_net_announce_timer(int round) "%d" virtio_net_handle_announce(int round) "%d" virtio_net_post_load_device(void) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 38b8974144..7e2c2a6f6a 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -150,15 +150,42 @@ static bool virtio_net_started(VirtIONet *n, uint8_t = status) (n->status & VIRTIO_NET_S_LINK_UP) && vdev->vm_running; } =20 +static void virtio_net_announce_notify(VirtIONet *net) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(net); + trace_virtio_net_announce_notify(); + + net->status |=3D VIRTIO_NET_S_ANNOUNCE; + virtio_notify_config(vdev); +} + static void virtio_net_announce_timer(void *opaque) { VirtIONet *n =3D opaque; - VirtIODevice *vdev =3D VIRTIO_DEVICE(n); trace_virtio_net_announce_timer(n->announce_timer.round); =20 n->announce_timer.round--; - n->status |=3D VIRTIO_NET_S_ANNOUNCE; - virtio_notify_config(vdev); + virtio_net_announce_notify(n); +} + +static void virtio_net_announce(NetClientState *nc) +{ + VirtIONet *n =3D qemu_get_nic_opaque(nc); + VirtIODevice *vdev =3D VIRTIO_DEVICE(n); + + /* + * Make sure the virtio migration announcement timer isn't running + * If it is, let it trigger announcement so that we do not cause + * confusion. + */ + if (n->announce_timer.round) { + return; + } + + if (virtio_vdev_has_feature(vdev, VIRTIO_NET_F_GUEST_ANNOUNCE) && + virtio_vdev_has_feature(vdev, VIRTIO_NET_F_CTRL_VQ)) { + virtio_net_announce_notify(n); + } } =20 static void virtio_net_vhost_status(VirtIONet *n, uint8_t status) @@ -2556,6 +2583,7 @@ static NetClientInfo net_virtio_info =3D { .receive =3D virtio_net_receive, .link_status_changed =3D virtio_net_set_link_status, .query_rx_filter =3D virtio_net_query_rxfilter, + .announce =3D virtio_net_announce, }; =20 static bool virtio_net_guest_notifier_pending(VirtIODevice *vdev, int idx) @@ -2692,6 +2720,7 @@ static void virtio_net_device_realize(DeviceState *de= v, Error **errp) qemu_announce_timer_reset(&n->announce_timer, migrate_announce_params(= ), QEMU_CLOCK_VIRTUAL, virtio_net_announce_timer, n); + n->announce_timer.round =3D 0; =20 if (n->netclient_type) { /* --=20 2.20.1 From nobody Tue May 14 00:18:53 2024 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1551274342363718.8439340128758; Wed, 27 Feb 2019 05:32:22 -0800 (PST) Received: from localhost ([127.0.0.1]:43791 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyzJq-0007DW-DW for importer@patchew.org; Wed, 27 Feb 2019 08:32:18 -0500 Received: from eggs.gnu.org ([209.51.188.92]:45782) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyzCN-00013q-Km for qemu-devel@nongnu.org; Wed, 27 Feb 2019 08:24:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gyzCM-0000Yh-RD for qemu-devel@nongnu.org; Wed, 27 Feb 2019 08:24:35 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51196) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gyzCM-0000WW-He for qemu-devel@nongnu.org; Wed, 27 Feb 2019 08:24:34 -0500 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 C048330BD1DB for ; Wed, 27 Feb 2019 13:24:26 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.36.118.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 98BB260BF4; Wed, 27 Feb 2019 13:24:25 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, jasowang@redhat.com Date: Wed, 27 Feb 2019 13:24:11 +0000 Message-Id: <20190227132413.13213-8-dgilbert@redhat.com> In-Reply-To: <20190227132413.13213-1-dgilbert@redhat.com> References: <20190227132413.13213-1-dgilbert@redhat.com> MIME-Version: 1.0 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.42]); Wed, 27 Feb 2019 13:24:26 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PATCH v6 7/9] qmp: Add announce-self command 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: thuth@redhat.com, armbru@redhat.com, quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Add a qmp command that can trigger guest announcements. It uses its own announce-timer instance, and parameters passed to it explicitly in the command. Like most qmp commands, it's in the main thread/bql, so there's no racing with any outstanding timer. Based on work of Germano Veit Michel and Vladislav Yasevich Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Michael S. Tsirkin --- net/announce.c | 7 +++++++ qapi/net.json | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/net/announce.c b/net/announce.c index 070f37a7fa..91e9a6e267 100644 --- a/net/announce.c +++ b/net/announce.c @@ -12,6 +12,7 @@ #include "net/net.h" #include "qapi/clone-visitor.h" #include "qapi/qapi-visit-net.h" +#include "qapi/qapi-commands-net.h" #include "trace.h" =20 int64_t qemu_announce_timer_step(AnnounceTimer *timer) @@ -131,3 +132,9 @@ void qemu_announce_self(AnnounceTimer *timer, AnnounceP= arameters *params) qemu_announce_timer_del(timer); } } + +void qmp_announce_self(AnnounceParameters *params, Error **errp) +{ + static AnnounceTimer announce_timer; + qemu_announce_self(&announce_timer, params); +} diff --git a/qapi/net.json b/qapi/net.json index 5face0c14b..372ae10168 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -707,3 +707,23 @@ 'max': 'int', 'rounds': 'int', 'step': 'int' } } + +## +# @announce-self: +# +# Trigger generation of broadcast RARP frames to update network switches. +# This can be useful when network bonds fail-over the active slave. +# +# @params: AnnounceParameters giving timing and repetition count of announ= ce +# +# Example: +# +# -> { "execute": "announce-self" +# "arguments": { +# "initial": 50, "max": 550, "rounds": 10, "step": 50 } } +# <- { "return": {} } +# +# Since: 4.0 +## +{ 'command': 'announce-self', 'boxed': true, + 'data' : 'AnnounceParameters'} --=20 2.20.1 From nobody Tue May 14 00:18:53 2024 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1551274001478304.7884942576038; Wed, 27 Feb 2019 05:26:41 -0800 (PST) Received: from localhost ([127.0.0.1]:43687 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyzEO-0002OP-CQ for importer@patchew.org; Wed, 27 Feb 2019 08:26:40 -0500 Received: from eggs.gnu.org ([209.51.188.92]:45837) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyzCO-00014l-NF for qemu-devel@nongnu.org; Wed, 27 Feb 2019 08:24:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gyzCN-0000Z3-DQ for qemu-devel@nongnu.org; Wed, 27 Feb 2019 08:24:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46318) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gyzCM-0000Wo-U8 for qemu-devel@nongnu.org; Wed, 27 Feb 2019 08:24:35 -0500 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 3D5F93B77E for ; Wed, 27 Feb 2019 13:24:28 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.36.118.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1601D60C9C; Wed, 27 Feb 2019 13:24:26 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, jasowang@redhat.com Date: Wed, 27 Feb 2019 13:24:12 +0000 Message-Id: <20190227132413.13213-9-dgilbert@redhat.com> In-Reply-To: <20190227132413.13213-1-dgilbert@redhat.com> References: <20190227132413.13213-1-dgilbert@redhat.com> MIME-Version: 1.0 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.30]); Wed, 27 Feb 2019 13:24:28 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PATCH v6 8/9] hmp: Add hmp_announce_self 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: thuth@redhat.com, armbru@redhat.com, quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Add an HMP command to trigger self annocements. Unlike the QMP command (which takes a set of parameters), the HMP command reuses the set of parameters used for migration. Signend-off-by: Vladislav Yasevich Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Michael S. Tsirkin --- hmp-commands.hx | 16 ++++++++++++++++ hmp.c | 5 +++++ hmp.h | 1 + tests/test-hmp.c | 1 + 4 files changed, 23 insertions(+) diff --git a/hmp-commands.hx b/hmp-commands.hx index ba71558c25..0648b1efa3 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -928,6 +928,22 @@ Bug: can screw up when the buffer contains invalid UTF= -8 sequences, NUL characters, after the ring buffer lost data, and when reading stops because the size limit is reached. =20 +ETEXI + + { + .name =3D "announce_self", + .args_type =3D "", + .params =3D "", + .help =3D "Trigger GARP/RARP announcements", + .cmd =3D hmp_announce_self, + }, + +STEXI +@item announce_self +@findex announce_self +Trigger a round of GARP/RARP broadcasts; this is useful for explicitly upd= ating the +network infrastructure after a reconfiguration or some forms of migration. +The timings of the round are set by the migration announce parameters. ETEXI =20 { diff --git a/hmp.c b/hmp.c index f3db0bf5a2..5f13b16e24 100644 --- a/hmp.c +++ b/hmp.c @@ -1570,6 +1570,11 @@ void hmp_info_snapshots(Monitor *mon, const QDict *q= dict) =20 } =20 +void hmp_announce_self(Monitor *mon, const QDict *qdict) +{ + qmp_announce_self(migrate_announce_params(), NULL); +} + void hmp_migrate_cancel(Monitor *mon, const QDict *qdict) { qmp_migrate_cancel(NULL); diff --git a/hmp.h b/hmp.h index 5f1addcca2..e0f32f04d3 100644 --- a/hmp.h +++ b/hmp.h @@ -46,6 +46,7 @@ void hmp_sync_profile(Monitor *mon, const QDict *qdict); void hmp_system_reset(Monitor *mon, const QDict *qdict); void hmp_system_powerdown(Monitor *mon, const QDict *qdict); void hmp_exit_preconfig(Monitor *mon, const QDict *qdict); +void hmp_announce_self(Monitor *mon, const QDict *qdict); void hmp_cpu(Monitor *mon, const QDict *qdict); void hmp_memsave(Monitor *mon, const QDict *qdict); void hmp_pmemsave(Monitor *mon, const QDict *qdict); diff --git a/tests/test-hmp.c b/tests/test-hmp.c index 1a3a9c5099..8c49d2fdf1 100644 --- a/tests/test-hmp.c +++ b/tests/test-hmp.c @@ -20,6 +20,7 @@ static int verbose; =20 static const char *hmp_cmds[] =3D { + "announce_self", "boot_set ndc", "chardev-add null,id=3Dtestchardev1", "chardev-send-break testchardev1", --=20 2.20.1 From nobody Tue May 14 00:18:53 2024 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1551274677997713.5074910154653; Wed, 27 Feb 2019 05:37:57 -0800 (PST) Received: from localhost ([127.0.0.1]:43869 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyzPG-000288-NX for importer@patchew.org; Wed, 27 Feb 2019 08:37:54 -0500 Received: from eggs.gnu.org ([209.51.188.92]:45846) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyzCP-00015D-92 for qemu-devel@nongnu.org; Wed, 27 Feb 2019 08:24:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gyzCN-0000ZK-GI for qemu-devel@nongnu.org; Wed, 27 Feb 2019 08:24:37 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49748) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gyzCM-0000X3-VD for qemu-devel@nongnu.org; Wed, 27 Feb 2019 08:24:35 -0500 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 AD4FE30BA311 for ; Wed, 27 Feb 2019 13:24:29 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.36.118.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 86ED0619A2; Wed, 27 Feb 2019 13:24:28 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, jasowang@redhat.com Date: Wed, 27 Feb 2019 13:24:13 +0000 Message-Id: <20190227132413.13213-10-dgilbert@redhat.com> In-Reply-To: <20190227132413.13213-1-dgilbert@redhat.com> References: <20190227132413.13213-1-dgilbert@redhat.com> MIME-Version: 1.0 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.47]); Wed, 27 Feb 2019 13:24:29 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PATCH v6 9/9] tests: Add a test for qemu self announcements 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: thuth@redhat.com, armbru@redhat.com, quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" We now expose qemu_announce_self through QMP and HMP. Add a test with some very basic packet validation (make sure we get a RARP). Signed-off-by: Vlad Yasevich Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Michael S. Tsirkin --- tests/Makefile.include | 3 ++ tests/test-announce-self.c | 82 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 tests/test-announce-self.c diff --git a/tests/Makefile.include b/tests/Makefile.include index e60488da7d..e9aa7ec258 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -226,6 +226,7 @@ check-qtest-i386-$(CONFIG_SLIRP) +=3D tests/test-netfil= ter$(EXESUF) check-qtest-i386-$(CONFIG_POSIX) +=3D tests/test-filter-mirror$(EXESUF) check-qtest-i386-$(CONFIG_RTL8139_PCI) +=3D tests/test-filter-redirector$(= EXESUF) check-qtest-i386-y +=3D tests/migration-test$(EXESUF) +check-qtest-i386-y +=3D tests/test-announce-self$(EXESUF) check-qtest-i386-y +=3D tests/test-x86-cpuid-compat$(EXESUF) check-qtest-i386-y +=3D tests/numa-test$(EXESUF) check-qtest-x86_64-y +=3D $(check-qtest-i386-y) @@ -263,6 +264,7 @@ check-qtest-ppc64-y +=3D $(check-qtest-ppc-y) check-qtest-ppc64-$(CONFIG_PSERIES) +=3D tests/spapr-phb-test$(EXESUF) check-qtest-ppc64-$(CONFIG_POWERNV) +=3D tests/pnv-xscom-test$(EXESUF) check-qtest-ppc64-y +=3D tests/migration-test$(EXESUF) +check-qtest-ppc64-y +=3D tests/test-announce-self$(EXESUF) check-qtest-ppc64-$(CONFIG_PSERIES) +=3D tests/rtas-test$(EXESUF) check-qtest-ppc64-$(CONFIG_SLIRP) +=3D tests/pxe-test$(EXESUF) check-qtest-ppc64-$(CONFIG_USB_OHCI) +=3D tests/usb-hcd-ohci-test$(EXESUF) @@ -776,6 +778,7 @@ tests/usb-hcd-ehci-test$(EXESUF): tests/usb-hcd-ehci-te= st.o $(libqos-usb-obj-y) tests/usb-hcd-xhci-test$(EXESUF): tests/usb-hcd-xhci-test.o $(libqos-usb-o= bj-y) tests/cpu-plug-test$(EXESUF): tests/cpu-plug-test.o tests/migration-test$(EXESUF): tests/migration-test.o +tests/test-announce-self$(EXESUF): tests/test-announce-self.o tests/vhost-user-test$(EXESUF): tests/vhost-user-test.o $(test-util-obj-y)= \ $(qtest-obj-y) $(test-io-obj-y) $(libqos-virtio-obj-y) $(libqos-pc-obj-y)= \ $(chardev-obj-y) diff --git a/tests/test-announce-self.c b/tests/test-announce-self.c new file mode 100644 index 0000000000..1644d34a3f --- /dev/null +++ b/tests/test-announce-self.c @@ -0,0 +1,82 @@ +/* + * QTest testcase for qemu_announce_self + * + * Copyright (c) 2017 Red hat, Inc. + * Copyright (c) 2014 SUSE LINUX Products GmbH + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "libqtest.h" +#include "qapi/qmp/qdict.h" +#include "qemu-common.h" +#include "qemu/sockets.h" +#include "qemu/iov.h" +#include "libqos/libqos-pc.h" +#include "libqos/libqos-spapr.h" + +#ifndef ETH_P_RARP +#define ETH_P_RARP 0x8035 +#endif + +static QTestState *test_init(int socket) +{ + char *args; + + args =3D g_strdup_printf("-netdev socket,fd=3D%d,id=3Dhs0 -device " + "virtio-net-pci,netdev=3Dhs0", socket); + + return qtest_start(args); +} + + +static void test_announce(int socket) +{ + char buffer[60]; + int len; + QDict *rsp; + int ret; + uint16_t *proto =3D (uint16_t *)&buffer[12]; + + rsp =3D qmp("{ 'execute' : 'announce-self', " + " 'arguments': {" + " 'initial': 50, 'max': 550," + " 'rounds': 10, 'step': 50 } }"); + assert(!qdict_haskey(rsp, "error")); + qobject_unref(rsp); + + /* Catch the packet and make sure it's a RARP */ + ret =3D qemu_recv(socket, &len, sizeof(len), 0); + g_assert_cmpint(ret, =3D=3D, sizeof(len)); + len =3D ntohl(len); + + ret =3D qemu_recv(socket, buffer, len, 0); + g_assert_cmpint(*proto, =3D=3D, htons(ETH_P_RARP)); +} + +static void setup(gconstpointer data) +{ + QTestState *qs; + void (*func) (int socket) =3D data; + int sv[2], ret; + + ret =3D socketpair(PF_UNIX, SOCK_STREAM, 0, sv); + g_assert_cmpint(ret, !=3D, -1); + + qs =3D test_init(sv[1]); + func(sv[0]); + + /* End test */ + close(sv[0]); + qtest_quit(qs); +} + +int main(int argc, char **argv) +{ + g_test_init(&argc, &argv, NULL); + qtest_add_data_func("/virtio/net/test_announce_self", test_announce, s= etup); + + return g_test_run(); +} --=20 2.20.1