From nobody Sat May 18 09:01:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1697636533; cv=none; d=zohomail.com; s=zohoarc; b=DfDscKT70X0GsO2bci52ylRNQBsVDc0EZuAetzdAYQgXKZkl4lAP4PUyVG8IrUkIl1jyQavJ1meAIotpZ5rJBjzk54CryEaDpveVpS+dyJbmRR8R9i9eIeW4HP9+t7nv9X1ws3jnhnoG7gZ3HuTAy3srrYC/K2aUkT6/p+fa4pg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697636533; h=Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=oSOg7E04cHgarCqEsW/N7A+qfWi3fgjB94knxbihj4k=; b=hgWTsHVbrdtsHdZiBNmAScwwsK1ZJ4FmjtQOZLZHPq3ixJMgiV/34w4iX4ylj7iu8UBp/s+VKjXfS3aFk+2y0e/xlLhd2SsWBZrfLEPc+hfYa9VUAPi8trYlo7OJdiDzumNaYF3dQAEV0jr2zwfSp9mIZN8UyawAPnekP+n8BvQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1697636533791935.896165501866; Wed, 18 Oct 2023 06:42:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qt6mw-0004Jf-Vp; Wed, 18 Oct 2023 09:40:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qt6mu-0004HA-3S for qemu-devel@nongnu.org; Wed, 18 Oct 2023 09:40:40 -0400 Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qt6mr-0006hy-1m for qemu-devel@nongnu.org; Wed, 18 Oct 2023 09:40:39 -0400 Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39ICxGdl015416; Wed, 18 Oct 2023 13:40:34 GMT Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3tqjy1fh13-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 18 Oct 2023 13:40:34 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 39ID0X1l040556; Wed, 18 Oct 2023 13:40:32 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3trfyns2gu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 18 Oct 2023 13:40:32 +0000 Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 39IDeWxh020006; Wed, 18 Oct 2023 13:40:32 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 3trfyns2fd-1; Wed, 18 Oct 2023 13:40:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2023-03-30; bh=oSOg7E04cHgarCqEsW/N7A+qfWi3fgjB94knxbihj4k=; b=bcwmH0EJvwJUf8ODjDYw6XCvBWCC+NkgtGT5mRDaZG88CKwfj4z2tmQ9ydRufvwNGIbf AJ2sc0ARUDF5TUzB0o0BzRg9rAbE5WCc+W1X3nfPyt1YDCVKN74Zo/UMr4qZ/+L3atuV m8vIuvSoM4ZrRNTuIxDngqnyHbYOVDRiOv8y3CzADoqTwNQjUC7Xe072LfkNO9qKuw4q UpzhdAUmVV0eXuilRxIiJM1+r41mZc+tdgcerkwaJ4dUL2NkXB286DA9DJOa0QTmhbbH JdbSHiVoa3hwse/lHrOcJ3ZNJyKfmYkU9PW8ann0bNAQ+DJERcH47KtczOHdvSCqTOjo 9g== From: Steve Sistare To: qemu-devel@nongnu.org Cc: Juan Quintela , "Michael S. Tsirkin" , Alex Williamson , Fabiano Rosas , Leonardo Bras , Steve Sistare Subject: [PATCH V4] migration: simplify notifiers Date: Wed, 18 Oct 2023 06:40:30 -0700 Message-Id: <1697636430-87083-1-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-18_12,2023-10-18_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 phishscore=0 spamscore=0 suspectscore=0 malwarescore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310180114 X-Proofpoint-GUID: pQkeEfM67M1b_hMHIcmTtpcBM4gT8-Xz X-Proofpoint-ORIG-GUID: pQkeEfM67M1b_hMHIcmTtpcBM4gT8-Xz Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=205.220.165.32; envelope-from=steven.sistare@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @oracle.com) X-ZM-MESSAGEID: 1697636536091100005 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Pass the callback function to add_migration_state_change_notifier so that migration can initialize the notifier on add and clear it on delete, which simplifies the call sites. Shorten the function names so the extra arg can be added more legibly. Hide the global notifier list in a new function migration_call_notifiers, and make it externally visible so future live update code can call it. No functional change. Signed-off-by: Steve Sistare Tested-by: Michael Galaxy Reviewed-by: Michael Galaxy Reviewed-by: Peter Xu --- hw/net/virtio-net.c | 6 +++--- hw/vfio/migration.c | 6 +++--- include/migration/misc.h | 6 ++++-- migration/migration.c | 22 ++++++++++++++++------ net/vhost-vdpa.c | 7 ++++--- ui/spice-core.c | 3 +-- 6 files changed, 31 insertions(+), 19 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 29e33ea..b85c794 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -3624,8 +3624,8 @@ static void virtio_net_device_realize(DeviceState *de= v, Error **errp) n->primary_listener.hide_device =3D failover_hide_primary_device; qatomic_set(&n->failover_primary_hidden, true); device_listener_register(&n->primary_listener); - n->migration_state.notify =3D virtio_net_migration_state_notifier; - add_migration_state_change_notifier(&n->migration_state); + migration_add_notifier(&n->migration_state, + virtio_net_migration_state_notifier); n->host_features |=3D (1ULL << VIRTIO_NET_F_STANDBY); } =20 @@ -3788,7 +3788,7 @@ static void virtio_net_device_unrealize(DeviceState *= dev) if (n->failover) { qobject_unref(n->primary_opts); device_listener_unregister(&n->primary_listener); - remove_migration_state_change_notifier(&n->migration_state); + migration_remove_notifier(&n->migration_state); } else { assert(n->primary_opts =3D=3D NULL); } diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index 0aaad65..28d422b 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -872,8 +872,8 @@ static int vfio_migration_init(VFIODevice *vbasedev) NULL; migration->vm_state =3D qdev_add_vm_change_state_handler_full( vbasedev->dev, vfio_vmstate_change, prepare_cb, vbasedev); - migration->migration_state.notify =3D vfio_migration_state_notifier; - add_migration_state_change_notifier(&migration->migration_state); + migration_add_notifier(&migration->migration_state, + vfio_migration_state_notifier); =20 return 0; } @@ -882,7 +882,7 @@ static void vfio_migration_deinit(VFIODevice *vbasedev) { VFIOMigration *migration =3D vbasedev->migration; =20 - remove_migration_state_change_notifier(&migration->migration_state); + migration_remove_notifier(&migration->migration_state); qemu_del_vm_change_state_handler(migration->vm_state); unregister_savevm(VMSTATE_IF(vbasedev->dev), "vfio", vbasedev); vfio_migration_free(vbasedev); diff --git a/include/migration/misc.h b/include/migration/misc.h index 7dcc0b5..673ac49 100644 --- a/include/migration/misc.h +++ b/include/migration/misc.h @@ -60,8 +60,10 @@ void migration_object_init(void); void migration_shutdown(void); bool migration_is_idle(void); bool migration_is_active(MigrationState *); -void add_migration_state_change_notifier(Notifier *notify); -void remove_migration_state_change_notifier(Notifier *notify); +void migration_add_notifier(Notifier *notify, + void (*func)(Notifier *notifier, void *data)); +void migration_remove_notifier(Notifier *notify); +void migration_call_notifiers(MigrationState *s); bool migration_in_setup(MigrationState *); bool migration_has_finished(MigrationState *); bool migration_has_failed(MigrationState *); diff --git a/migration/migration.c b/migration/migration.c index 65f9791..29a69bf 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1204,7 +1204,7 @@ static void migrate_fd_cleanup(MigrationState *s) /* It is used on info migrate. We can't free it */ error_report_err(error_copy(s->error)); } - notifier_list_notify(&migration_state_notifiers, s); + migration_call_notifiers(s); block_cleanup_parameters(); yank_unregister_instance(MIGRATION_YANK_INSTANCE); } @@ -1308,14 +1308,24 @@ static void migrate_fd_cancel(MigrationState *s) } } =20 -void add_migration_state_change_notifier(Notifier *notify) +void migration_add_notifier(Notifier *notify, + void (*func)(Notifier *notifier, void *data)) { + notify->notify =3D func; notifier_list_add(&migration_state_notifiers, notify); } =20 -void remove_migration_state_change_notifier(Notifier *notify) +void migration_remove_notifier(Notifier *notify) { - notifier_remove(notify); + if (notify->notify) { + notifier_remove(notify); + notify->notify =3D NULL; + } +} + +void migration_call_notifiers(MigrationState *s) +{ + notifier_list_notify(&migration_state_notifiers, s); } =20 bool migration_in_setup(MigrationState *s) @@ -2231,7 +2241,7 @@ static int postcopy_start(MigrationState *ms, Error *= *errp) * spice needs to trigger a transition now */ ms->postcopy_after_devices =3D true; - notifier_list_notify(&migration_state_notifiers, ms); + migration_call_notifiers(ms); =20 ms->downtime =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME) - time_at_sto= p; =20 @@ -3265,7 +3275,7 @@ void migrate_fd_connect(MigrationState *s, Error *err= or_in) rate_limit =3D migrate_max_bandwidth(); =20 /* Notify before starting migration thread */ - notifier_list_notify(&migration_state_notifiers, s); + migration_call_notifiers(s); } =20 migration_rate_set(rate_limit); diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 939c984..0f2e6fc 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -339,7 +339,8 @@ static void vhost_vdpa_net_data_start_first(VhostVDPASt= ate *s) { struct vhost_vdpa *v =3D &s->vhost_vdpa; =20 - add_migration_state_change_notifier(&s->migration_state); + migration_add_notifier(&s->migration_state, + vdpa_net_migration_state_notifier); if (v->shadow_vqs_enabled) { v->iova_tree =3D vhost_iova_tree_new(v->iova_range.first, v->iova_range.last); @@ -399,7 +400,7 @@ static void vhost_vdpa_net_client_stop(NetClientState *= nc) assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA); =20 if (s->vhost_vdpa.index =3D=3D 0) { - remove_migration_state_change_notifier(&s->migration_state); + migration_remove_notifier(&s->migration_state); } =20 dev =3D s->vhost_vdpa.dev; @@ -1456,7 +1457,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientS= tate *peer, s->vhost_vdpa.device_fd =3D vdpa_device_fd; s->vhost_vdpa.index =3D queue_pair_index; s->always_svq =3D svq; - s->migration_state.notify =3D vdpa_net_migration_state_notifier; + s->migration_state.notify =3D NULL; s->vhost_vdpa.shadow_vqs_enabled =3D svq; s->vhost_vdpa.iova_range =3D iova_range; s->vhost_vdpa.shadow_data =3D svq; diff --git a/ui/spice-core.c b/ui/spice-core.c index 52a5938..db21db2 100644 --- a/ui/spice-core.c +++ b/ui/spice-core.c @@ -821,8 +821,7 @@ static void qemu_spice_init(void) }; using_spice =3D 1; =20 - migration_state.notify =3D migration_state_notifier; - add_migration_state_change_notifier(&migration_state); + migration_add_notifier(&migration_state, migration_state_notifier); spice_migrate.base.sif =3D &migrate_interface.base; qemu_spice.add_interface(&spice_migrate.base); =20 --=20 1.8.3.1