From nobody Sat Nov 23 20:41:43 2024 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1731871358699140.1981929081635; Sun, 17 Nov 2024 11:22:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tCkqP-0002jU-FP; Sun, 17 Nov 2024 14:22:01 -0500 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 1tCkqN-0002j7-OB for qemu-devel@nongnu.org; Sun, 17 Nov 2024 14:21:59 -0500 Received: from vps-ovh.mhejs.net ([145.239.82.108]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tCkqM-0005uD-8j for qemu-devel@nongnu.org; Sun, 17 Nov 2024 14:21:59 -0500 Received: from MUA by vps-ovh.mhejs.net with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.98) (envelope-from ) id 1tCkqJ-00000002GUE-0OxZ; Sun, 17 Nov 2024 20:21:55 +0100 From: "Maciej S. Szmigiero" To: Peter Xu , Fabiano Rosas Cc: Alex Williamson , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Eric Blake , Markus Armbruster , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Avihai Horon , Joao Martins , qemu-devel@nongnu.org Subject: [PATCH v3 09/24] migration/multifd: Split packet into header and RAM data Date: Sun, 17 Nov 2024 20:20:04 +0100 Message-ID: <8cb65952e475c0236d66047270fd3ed907f7404e.1731773021.git.maciej.szmigiero@oracle.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: 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: none client-ip=145.239.82.108; envelope-from=mhej@vps-ovh.mhejs.net; helo=vps-ovh.mhejs.net X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=no 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-ZM-MESSAGEID: 1731871360088116600 Content-Type: text/plain; charset="utf-8" From: "Maciej S. Szmigiero" Read packet header first so in the future we will be able to differentiate between a RAM multifd packet and a device state multifd packet. Since these two are of different size we can't read the packet body until we know which packet type it is. Signed-off-by: Maciej S. Szmigiero --- migration/multifd.c | 49 +++++++++++++++++++++++++++++++++++---------- migration/multifd.h | 5 +++++ 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index 498e71fd1024..999b88b7ebcb 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -209,10 +209,10 @@ void multifd_send_fill_packet(MultiFDSendParams *p) =20 memset(packet, 0, p->packet_len); =20 - packet->magic =3D cpu_to_be32(MULTIFD_MAGIC); - packet->version =3D cpu_to_be32(MULTIFD_VERSION); + packet->hdr.magic =3D cpu_to_be32(MULTIFD_MAGIC); + packet->hdr.version =3D cpu_to_be32(MULTIFD_VERSION); =20 - packet->flags =3D cpu_to_be32(p->flags); + packet->hdr.flags =3D cpu_to_be32(p->flags); packet->next_packet_size =3D cpu_to_be32(p->next_packet_size); =20 packet_num =3D qatomic_fetch_inc(&multifd_send_state->packet_num); @@ -228,12 +228,12 @@ void multifd_send_fill_packet(MultiFDSendParams *p) p->flags, p->next_packet_size); } =20 -static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp) +static int multifd_recv_unfill_packet_header(MultiFDRecvParams *p, + const MultiFDPacketHdr_t *hdr, + Error **errp) { - const MultiFDPacket_t *packet =3D p->packet; - uint32_t magic =3D be32_to_cpu(packet->magic); - uint32_t version =3D be32_to_cpu(packet->version); - int ret =3D 0; + uint32_t magic =3D be32_to_cpu(hdr->magic); + uint32_t version =3D be32_to_cpu(hdr->version); =20 if (magic !=3D MULTIFD_MAGIC) { error_setg(errp, "multifd: received packet magic %x, expected %x", @@ -247,7 +247,16 @@ static int multifd_recv_unfill_packet(MultiFDRecvParam= s *p, Error **errp) return -1; } =20 - p->flags =3D be32_to_cpu(packet->flags); + p->flags =3D be32_to_cpu(hdr->flags); + + return 0; +} + +static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp) +{ + const MultiFDPacket_t *packet =3D p->packet; + int ret =3D 0; + p->next_packet_size =3D be32_to_cpu(packet->next_packet_size); p->packet_num =3D be64_to_cpu(packet->packet_num); p->packets_recved++; @@ -1126,8 +1135,12 @@ static void *multifd_recv_thread(void *opaque) rcu_register_thread(); =20 while (true) { + MultiFDPacketHdr_t hdr; uint32_t flags =3D 0; bool has_data =3D false; + uint8_t *pkt_buf; + size_t pkt_len; + p->normal_num =3D 0; =20 if (use_packets) { @@ -1135,8 +1148,22 @@ static void *multifd_recv_thread(void *opaque) break; } =20 - ret =3D qio_channel_read_all_eof(p->c, (void *)p->packet, - p->packet_len, &local_err); + ret =3D qio_channel_read_all_eof(p->c, (void *)&hdr, + sizeof(hdr), &local_err); + if (ret =3D=3D 0 || ret =3D=3D -1) { /* 0: EOF -1: Error */ + break; + } + + ret =3D multifd_recv_unfill_packet_header(p, &hdr, &local_err); + if (ret) { + break; + } + + pkt_buf =3D (uint8_t *)p->packet + sizeof(hdr); + pkt_len =3D p->packet_len - sizeof(hdr); + + ret =3D qio_channel_read_all_eof(p->c, (char *)pkt_buf, pkt_le= n, + &local_err); if (ret =3D=3D 0 || ret =3D=3D -1) { /* 0: EOF -1: Error */ break; } diff --git a/migration/multifd.h b/migration/multifd.h index 50d58c0c9cec..106a48496dc6 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -53,6 +53,11 @@ typedef struct { uint32_t magic; uint32_t version; uint32_t flags; +} __attribute__((packed)) MultiFDPacketHdr_t; + +typedef struct { + MultiFDPacketHdr_t hdr; + /* maximum number of allocated pages */ uint32_t pages_alloc; /* non zero pages */