From nobody Sat Feb 7 04:47:28 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1618932279; cv=none; d=zohomail.com; s=zohoarc; b=X8jEXUeE8HM6gf/jddMQ/bI+jEfZRkFVfDCHg+vS9LRv85tOsXdtBaWXodnSN1Yxyk/+mG5fSI3S6OrGMOo9a0+RATjkpnaT+l8xnPCcIw9XhVK1YFa/WkolFEucrkDFqPxNPss5gb+c0pq14ot30alm9QVeVjCNrqD2rOyi3JY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618932279; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0fne1+C65r/QRG8MVcKDgHZSLwctuZ7XWejS/aZD7rE=; b=kXb98M+C4mn9OO8zeHQ/FdPdF4MjX3ikPTmW0KKLESUzZa6KDPwmGvnYqj1ZGF8MZVI8D5k1L9AdCn241dVsxiq7SSaZ47EKrCdTpvoYmdHzx9ssp2YrtZg9hji67t+REVmyYxvW30GDerHfMJLoKESNRk7Dzqi7qSqbL0tTWbQ= ARC-Authentication-Results: i=1; mx.zohomail.com; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1618932279151281.9661476211653; Tue, 20 Apr 2021 08:24:39 -0700 (PDT) Received: from localhost ([::1]:39430 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lYsEv-0007jU-S4 for importer@patchew.org; Tue, 20 Apr 2021 11:24:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50308) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYsCW-0005jB-P6 for qemu-devel@nongnu.org; Tue, 20 Apr 2021 11:22:09 -0400 Received: from mga05.intel.com ([192.55.52.43]:37566) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYsCU-0004ah-9E for qemu-devel@nongnu.org; Tue, 20 Apr 2021 11:22:08 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Apr 2021 08:22:05 -0700 Received: from unknown (HELO tkid-nvme.lan) ([10.239.13.19]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Apr 2021 08:22:02 -0700 IronPort-SDR: bFbqxyWAkna8lQpX70EJyGgNipd4f6FiFeGRFwgXfJuALEQ4jq6mSXLhwFDNmWsoO0oUbUfO9z W/9El8t1vVEQ== X-IronPort-AV: E=McAfee;i="6200,9189,9960"; a="280854232" X-IronPort-AV: E=Sophos;i="5.82,237,1613462400"; d="scan'208";a="280854232" IronPort-SDR: mR+Ouolb66+uVwDMmIiilcXdG/qtHPUK3Mz1XTkD0dyqr38yfvn+QxeyQ5gc5gU7lKqrHboDQ3 EIZAuACHcEFA== X-IronPort-AV: E=Sophos;i="5.82,237,1613462400"; d="scan'208";a="523846734" From: Zhang Chen To: Jason Wang , qemu-dev , Eric Blake , "Dr. David Alan Gilbert" , Markus Armbruster , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Gerd Hoffmann , Li Zhijian Subject: [PATCH V6 4/6] net/colo-compare: Move data structure and define to .h file. Date: Tue, 20 Apr 2021 23:15:35 +0800 Message-Id: <20210420151537.64360-5-chen.zhang@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210420151537.64360-1-chen.zhang@intel.com> References: <20210420151537.64360-1-chen.zhang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=192.55.52.43; envelope-from=chen.zhang@intel.com; helo=mga05.intel.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhang Chen , Lukas Straub , Zhang Chen Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Rename structure with COLO index and move it to .h file, It make other modules can reuse COLO code. Signed-off-by: Zhang Chen --- net/colo-compare.c | 134 +++++---------------------------------------- net/colo-compare.h | 106 +++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+), 120 deletions(-) diff --git a/net/colo-compare.c b/net/colo-compare.c index 9d1ad99941..b51b1437ef 100644 --- a/net/colo-compare.c +++ b/net/colo-compare.c @@ -17,44 +17,24 @@ #include "qemu/error-report.h" #include "trace.h" #include "qapi/error.h" -#include "net/net.h" #include "net/eth.h" #include "qom/object_interfaces.h" #include "qemu/iov.h" #include "qom/object.h" #include "net/queue.h" -#include "chardev/char-fe.h" #include "qemu/sockets.h" -#include "colo.h" -#include "sysemu/iothread.h" #include "net/colo-compare.h" -#include "migration/colo.h" -#include "migration/migration.h" #include "util.h" =20 #include "block/aio-wait.h" #include "qemu/coroutine.h" =20 -#define TYPE_COLO_COMPARE "colo-compare" -typedef struct CompareState CompareState; -DECLARE_INSTANCE_CHECKER(CompareState, COLO_COMPARE, - TYPE_COLO_COMPARE) - static QTAILQ_HEAD(, CompareState) net_compares =3D QTAILQ_HEAD_INITIALIZER(net_compares); =20 static NotifierList colo_compare_notifiers =3D NOTIFIER_LIST_INITIALIZER(colo_compare_notifiers); =20 -#define COMPARE_READ_LEN_MAX NET_BUFSIZE -#define MAX_QUEUE_SIZE 1024 - -#define COLO_COMPARE_FREE_PRIMARY 0x01 -#define COLO_COMPARE_FREE_SECONDARY 0x02 - -#define REGULAR_PACKET_CHECK_MS 1000 -#define DEFAULT_TIME_OUT_MS 3000 - /* #define DEBUG_COLO_PACKETS */ =20 static QemuMutex colo_compare_mutex; @@ -64,92 +44,6 @@ static QemuCond event_complete_cond; static int event_unhandled_count; static uint32_t max_queue_size; =20 -/* - * + CompareState ++ - * | | - * +---------------+ +---------------+ +---------------+ - * | conn list + - > conn + ------- > conn + -- > .= ..... - * +---------------+ +---------------+ +---------------+ - * | | | | | | - * +---------------+ +---v----+ +---v----+ +---v----+ +---v----+ - * |primary | |secondary |primary | |secondary - * |packet | |packet + |packet | |packet + - * +--------+ +--------+ +--------+ +--------+ - * | | | | - * +---v----+ +---v----+ +---v----+ +---v----+ - * |primary | |secondary |primary | |secondary - * |packet | |packet + |packet | |packet + - * +--------+ +--------+ +--------+ +--------+ - * | | | | - * +---v----+ +---v----+ +---v----+ +---v----+ - * |primary | |secondary |primary | |secondary - * |packet | |packet + |packet | |packet + - * +--------+ +--------+ +--------+ +--------+ - */ - -typedef struct SendCo { - Coroutine *co; - struct CompareState *s; - CharBackend *chr; - GQueue send_list; - bool notify_remote_frame; - bool done; - int ret; -} SendCo; - -typedef struct SendEntry { - uint32_t size; - uint32_t vnet_hdr_len; - uint8_t *buf; -} SendEntry; - -struct CompareState { - Object parent; - - char *pri_indev; - char *sec_indev; - char *outdev; - char *notify_dev; - CharBackend chr_pri_in; - CharBackend chr_sec_in; - CharBackend chr_out; - CharBackend chr_notify_dev; - SocketReadState pri_rs; - SocketReadState sec_rs; - SocketReadState notify_rs; - SendCo out_sendco; - SendCo notify_sendco; - bool vnet_hdr; - uint64_t compare_timeout; - uint32_t expired_scan_cycle; - - /* - * Record the connection that through the NIC - * Element type: Connection - */ - GQueue conn_list; - /* Record the connection without repetition */ - GHashTable *connection_track_table; - - IOThread *iothread; - GMainContext *worker_context; - QEMUTimer *packet_check_timer; - - QEMUBH *event_bh; - enum colo_event event; - - QTAILQ_ENTRY(CompareState) next; -}; - -typedef struct CompareClass { - ObjectClass parent_class; -} CompareClass; - -enum { - PRIMARY_IN =3D 0, - SECONDARY_IN, -}; - static const char *colo_mode[] =3D { [PRIMARY_IN] =3D "primary", [SECONDARY_IN] =3D "secondary", @@ -737,19 +631,19 @@ static void colo_compare_connection(void *opaque, voi= d *user_data) =20 static void coroutine_fn _compare_chr_send(void *opaque) { - SendCo *sendco =3D opaque; + COLOSendCo *sendco =3D opaque; CompareState *s =3D sendco->s; int ret =3D 0; =20 while (!g_queue_is_empty(&sendco->send_list)) { - SendEntry *entry =3D g_queue_pop_tail(&sendco->send_list); + COLOSendEntry *entry =3D g_queue_pop_tail(&sendco->send_list); uint32_t len =3D htonl(entry->size); =20 ret =3D qemu_chr_fe_write_all(sendco->chr, (uint8_t *)&len, sizeof= (len)); =20 if (ret !=3D sizeof(len)) { g_free(entry->buf); - g_slice_free(SendEntry, entry); + g_slice_free(COLOSendEntry, entry); goto err; } =20 @@ -766,7 +660,7 @@ static void coroutine_fn _compare_chr_send(void *opaque) =20 if (ret !=3D sizeof(len)) { g_free(entry->buf); - g_slice_free(SendEntry, entry); + g_slice_free(COLOSendEntry, entry); goto err; } } @@ -777,12 +671,12 @@ static void coroutine_fn _compare_chr_send(void *opaq= ue) =20 if (ret !=3D entry->size) { g_free(entry->buf); - g_slice_free(SendEntry, entry); + g_slice_free(COLOSendEntry, entry); goto err; } =20 g_free(entry->buf); - g_slice_free(SendEntry, entry); + g_slice_free(COLOSendEntry, entry); } =20 sendco->ret =3D 0; @@ -790,9 +684,9 @@ static void coroutine_fn _compare_chr_send(void *opaque) =20 err: while (!g_queue_is_empty(&sendco->send_list)) { - SendEntry *entry =3D g_queue_pop_tail(&sendco->send_list); + COLOSendEntry *entry =3D g_queue_pop_tail(&sendco->send_list); g_free(entry->buf); - g_slice_free(SendEntry, entry); + g_slice_free(COLOSendEntry, entry); } sendco->ret =3D ret < 0 ? ret : -EIO; out: @@ -808,8 +702,8 @@ static int compare_chr_send(CompareState *s, bool notify_remote_frame, bool zero_copy) { - SendCo *sendco; - SendEntry *entry; + COLOSendCo *sendco; + COLOSendEntry *entry; =20 if (notify_remote_frame) { sendco =3D &s->notify_sendco; @@ -821,7 +715,7 @@ static int compare_chr_send(CompareState *s, return 0; } =20 - entry =3D g_slice_new(SendEntry); + entry =3D g_slice_new(COLOSendEntry); entry->size =3D size; entry->vnet_hdr_len =3D vnet_hdr_len; if (zero_copy) { @@ -1274,17 +1168,17 @@ static void colo_compare_complete(UserCreatable *uc= , Error **errp) =20 if (!s->compare_timeout) { /* Set default value to 3000 MS */ - s->compare_timeout =3D DEFAULT_TIME_OUT_MS; + s->compare_timeout =3D COLO_DEFAULT_TIME_OUT_MS; } =20 if (!s->expired_scan_cycle) { /* Set default value to 3000 MS */ - s->expired_scan_cycle =3D REGULAR_PACKET_CHECK_MS; + s->expired_scan_cycle =3D COLO_REGULAR_PACKET_CHECK_MS; } =20 if (!max_queue_size) { /* Set default queue size to 1024 */ - max_queue_size =3D MAX_QUEUE_SIZE; + max_queue_size =3D MAX_COLO_QUEUE_SIZE; } =20 if (find_and_check_chardev(&chr, s->pri_indev, errp) || diff --git a/net/colo-compare.h b/net/colo-compare.h index 22ddd512e2..ab649c9dbe 100644 --- a/net/colo-compare.h +++ b/net/colo-compare.h @@ -17,6 +17,112 @@ #ifndef QEMU_COLO_COMPARE_H #define QEMU_COLO_COMPARE_H =20 +#include "net/net.h" +#include "chardev/char-fe.h" +#include "migration/colo.h" +#include "migration/migration.h" +#include "sysemu/iothread.h" +#include "colo.h" + +#define TYPE_COLO_COMPARE "colo-compare" +typedef struct CompareState CompareState; +DECLARE_INSTANCE_CHECKER(CompareState, COLO_COMPARE, + TYPE_COLO_COMPARE) + +#define COMPARE_READ_LEN_MAX NET_BUFSIZE +#define MAX_COLO_QUEUE_SIZE 1024 + +#define COLO_COMPARE_FREE_PRIMARY 0x01 +#define COLO_COMPARE_FREE_SECONDARY 0x02 + +#define COLO_REGULAR_PACKET_CHECK_MS 1000 +#define COLO_DEFAULT_TIME_OUT_MS 3000 + +typedef struct COLOSendCo { + Coroutine *co; + struct CompareState *s; + CharBackend *chr; + GQueue send_list; + bool notify_remote_frame; + bool done; + int ret; +} COLOSendCo; + +typedef struct COLOSendEntry { + uint32_t size; + uint32_t vnet_hdr_len; + uint8_t *buf; +} COLOSendEntry; + +/* + * + CompareState ++ + * | | + * +---------------+ +---------------+ +---------------+ + * | conn list + - > conn + ------- > conn + -- > .= ..... + * +---------------+ +---------------+ +---------------+ + * | | | | | | + * +---------------+ +---v----+ +---v----+ +---v----+ +---v----+ + * |primary | |secondary |primary | |secondary + * |packet | |packet + |packet | |packet + + * +--------+ +--------+ +--------+ +--------+ + * | | | | + * +---v----+ +---v----+ +---v----+ +---v----+ + * |primary | |secondary |primary | |secondary + * |packet | |packet + |packet | |packet + + * +--------+ +--------+ +--------+ +--------+ + * | | | | + * +---v----+ +---v----+ +---v----+ +---v----+ + * |primary | |secondary |primary | |secondary + * |packet | |packet + |packet | |packet + + * +--------+ +--------+ +--------+ +--------+ + */ +struct CompareState { + Object parent; + + char *pri_indev; + char *sec_indev; + char *outdev; + char *notify_dev; + CharBackend chr_pri_in; + CharBackend chr_sec_in; + CharBackend chr_out; + CharBackend chr_notify_dev; + SocketReadState pri_rs; + SocketReadState sec_rs; + SocketReadState notify_rs; + COLOSendCo out_sendco; + COLOSendCo notify_sendco; + bool vnet_hdr; + uint64_t compare_timeout; + uint32_t expired_scan_cycle; + + /* + * Record the connection that through the NIC + * Element type: Connection + */ + GQueue conn_list; + /* Record the connection without repetition */ + GHashTable *connection_track_table; + + IOThread *iothread; + GMainContext *worker_context; + QEMUTimer *packet_check_timer; + + QEMUBH *event_bh; + enum colo_event event; + + QTAILQ_ENTRY(CompareState) next; +}; + +typedef struct CompareClass { + ObjectClass parent_class; +} CompareClass; + +enum { + PRIMARY_IN =3D 0, + SECONDARY_IN, +}; + void colo_notify_compares_event(void *opaque, int event, Error **errp); void colo_compare_register_notifier(Notifier *notify); void colo_compare_unregister_notifier(Notifier *notify); --=20 2.25.1