From nobody Tue May 21 14:34:02 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1655977277; cv=none; d=zohomail.com; s=zohoarc; b=iFvoA816G354IXQEHtV5sC7OuZPHnesRul7pEVrVZwXtIzgkgWodV1zO9mWS/eFdFrrBA5W9fJ3PazBAOH8mlXDfzySGPb7PBdb4B4yOXvbXk+1pL6GseIFZHtyxpCOGqllTGQbkkN9WPw6cmsM6JjzGuMPQ8S4aWUpfVlrpBe8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655977277; h=Content-Type: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=f01KN6D3ybCuZtXxqbhgGmA11QdmFrIBHP/8pOhtUDc=; b=HYGuNVlW1+raUmXISk2nmflclhWlr3xCvYnCiHiJrqAHuD+WpXWKozRWTz/yfncW7Yk7HVD6L+TfONtl3iFfLTMPA/0EUjUwQ9cCOtTGWL+1s7jxVpo+kyJxtQZODhtZtPOo4JlCmf3e62el6tOEnmo6nRq7RM19LRCKrrwX+Cs= 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 165597727722972.24854031353709; Thu, 23 Jun 2022 02:41:17 -0700 (PDT) Received: from localhost ([::1]:58098 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o4JKu-0002ZS-89 for importer@patchew.org; Thu, 23 Jun 2022 05:41:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45000) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8U-0008MY-FL for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:29259) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8N-0004ru-Uj for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:22 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-502-FMUErxrSNFipANk52ksR_A-1; Thu, 23 Jun 2022 05:28:17 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6454E29ABA0A; Thu, 23 Jun 2022 09:28:17 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.33.36.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6613940D2853; Thu, 23 Jun 2022 09:28:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655976499; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=f01KN6D3ybCuZtXxqbhgGmA11QdmFrIBHP/8pOhtUDc=; b=GyBmc+sHxMpowyz72IWX+sv9rUTpz5BZlTG1J2zHiWokHGlOJXotIsl1HvpUsaFD7rFoUW GNPTF+MzThhBHtxUH5r2kyxoH5lOrDpCWk0899+HYuBkNl0q5bIw4VbVK1Z8CuydVUloZI kiUCG/jSxbNz5TklTK+7kB0Aq/R57M8= X-MC-Unique: FMUErxrSNFipANk52ksR_A-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, huangy81@chinatelecom.cn, quintela@redhat.com, leobras@redhat.com, peterx@redhat.com Cc: jdenemar@redhat.com Subject: [PULL 01/33] migration: Remove RDMA_UNREGISTRATION_EXAMPLE Date: Thu, 23 Jun 2022 10:27:38 +0100 Message-Id: <20220623092810.96234-2-dgilbert@redhat.com> In-Reply-To: <20220623092810.96234-1-dgilbert@redhat.com> References: <20220623092810.96234-1-dgilbert@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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=170.10.133.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1655977279008100001 From: Juan Quintela Nobody has ever showed up to unregister individual pages, and another set of patches written by Daniel P. Berrang=C3=A9 just remove qemu_rdma_signal_unregister() function needed here. Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Dr. David Alan Gilbert --- migration/rdma.c | 41 ----------------------------------------- 1 file changed, 41 deletions(-) diff --git a/migration/rdma.c b/migration/rdma.c index 672d1958a9..8504152f39 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -1370,30 +1370,6 @@ const char *print_wrid(int wrid) return wrid_desc[wrid]; } =20 -/* - * RDMA requires memory registration (mlock/pinning), but this is not good= for - * overcommitment. - * - * In preparation for the future where LRU information or workload-specific - * writable writable working set memory access behavior is available to QE= MU - * it would be nice to have in place the ability to UN-register/UN-pin - * particular memory regions from the RDMA hardware when it is determine t= hat - * those regions of memory will likely not be accessed again in the near f= uture. - * - * While we do not yet have such information right now, the following - * compile-time option allows us to perform a non-optimized version of this - * behavior. - * - * By uncommenting this option, you will cause *all* RDMA transfers to be - * unregistered immediately after the transfer completes on both sides of = the - * connection. This has no effect in 'rdma-pin-all' mode, only regular mod= e. - * - * This will have a terrible impact on migration performance, so until fut= ure - * workload information or LRU information is available, do not attempt to= use - * this feature except for basic testing. - */ -/* #define RDMA_UNREGISTRATION_EXAMPLE */ - /* * Perform a non-optimized memory unregistration after every transfer * for demonstration purposes, only if pin-all is not requested. @@ -1571,18 +1547,6 @@ static uint64_t qemu_rdma_poll(RDMAContext *rdma, st= ruct ibv_cq *cq, if (rdma->nb_sent > 0) { rdma->nb_sent--; } - - if (!rdma->pin_all) { - /* - * FYI: If one wanted to signal a specific chunk to be unregis= tered - * using LRU or workload-specific information, this is the fun= ction - * you would call to do so. That chunk would then get asynchro= nously - * unregistered later. - */ -#ifdef RDMA_UNREGISTRATION_EXAMPLE - qemu_rdma_signal_unregister(rdma, index, chunk, wc.wr_id); -#endif - } } else { trace_qemu_rdma_poll_other(print_wrid(wr_id), wr_id, rdma->nb_sent= ); } @@ -2137,11 +2101,6 @@ retry: =20 chunk_end =3D ram_chunk_end(block, chunk + chunks); =20 - if (!rdma->pin_all) { -#ifdef RDMA_UNREGISTRATION_EXAMPLE - qemu_rdma_unregister_waiting(rdma); -#endif - } =20 while (test_bit(chunk, block->transit_bitmap)) { (void)count; --=20 2.36.1 From nobody Tue May 21 14:34:02 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1655977636; cv=none; d=zohomail.com; s=zohoarc; b=DfguAEOSKs5jcKVSeWDr+AWhxCuNNDIlk+h+82GtIZCPrDgYVWrrj86VH4MQJtT173isg1cCjjpOoC70KWyetFgeVUbAo0a8pBZ2VaXn7RMPqTHja3wgiVD5BsA01B59RCcl0A7wl2oDfvDiRssIvoL5KdDZf0ixG942fNRMQHY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655977636; h=Content-Type: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=rdC8wzK3qRlsTGe76YoR1juFzydDpgy+3C0yW+4L/1Q=; b=l8MA5BtLo0QiEBmf70PZTsxuq9uT4Jp3yikZyhu6j3FlzoZqiJ/7cLCWgVoXaiGIz2Q6VoXpz79RG/FEF0be1dFjpK9Qv+KiWS0QegcjemEuVE5IbuSFGA/ZkUeTazMBBDbNURsutwJ71qdMg7xd/gmwfPC+dbWOfRBwiEiGhQg= 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 1655977636452816.3429842456933; Thu, 23 Jun 2022 02:47:16 -0700 (PDT) Received: from localhost ([::1]:38370 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o4JQh-000065-5A for importer@patchew.org; Thu, 23 Jun 2022 05:47:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45052) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8U-0008Pb-RV for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:25177) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8S-0004s2-A0 for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:26 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-622-mCl5eQ41Oy6anyb72Kxe4Q-1; Thu, 23 Jun 2022 05:28:19 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 93FD729ABA07; Thu, 23 Jun 2022 09:28:18 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.33.36.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9866140C1289; Thu, 23 Jun 2022 09:28:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655976500; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rdC8wzK3qRlsTGe76YoR1juFzydDpgy+3C0yW+4L/1Q=; b=QYgKPyrNDbPeOkzjq479rTBVKq9lKfaFUV1O8E/lGXrtxIqQ1r1E4bICgAuv+0zx68dTx7 xthCXgikfqK1rFWqY9StP0ceq+eJ9DCgPZTXTA7EEv1Abl9y5VUfRGPCPwVQy03FqWvEsm PlMpWdQeZ78jEd8AoO5QDd40HxYW9+Q= X-MC-Unique: mCl5eQ41Oy6anyb72Kxe4Q-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, huangy81@chinatelecom.cn, quintela@redhat.com, leobras@redhat.com, peterx@redhat.com Cc: jdenemar@redhat.com Subject: [PULL 02/33] QIOChannelSocket: Introduce assert and reduce ifdefs to improve readability Date: Thu, 23 Jun 2022 10:27:39 +0100 Message-Id: <20220623092810.96234-3-dgilbert@redhat.com> In-Reply-To: <20220623092810.96234-1-dgilbert@redhat.com> References: <20220623092810.96234-1-dgilbert@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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=170.10.133.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1655977637775100001 From: Leonardo Bras During implementation of MSG_ZEROCOPY feature, a lot of #ifdefs were introduced, particularly at qio_channel_socket_writev(). Rewrite some of those changes so it's easier to read. Also, introduce an assert to help detect incorrect zero-copy usage is when it's disabled on build. Signed-off-by: Leonardo Bras Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Juan Quintela Reviewed-by: Peter Xu Signed-off-by: Juan Quintela Signed-off-by: Dr. David Alan Gilbert dgilbert: Fixed up thinko'd g_assert_unreachable->g_assert_not_reached --- io/channel-socket.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/io/channel-socket.c b/io/channel-socket.c index dc9c165de1..b8c13dba7c 100644 --- a/io/channel-socket.c +++ b/io/channel-socket.c @@ -578,11 +578,17 @@ static ssize_t qio_channel_socket_writev(QIOChannel *= ioc, memcpy(CMSG_DATA(cmsg), fds, fdsize); } =20 -#ifdef QEMU_MSG_ZEROCOPY if (flags & QIO_CHANNEL_WRITE_FLAG_ZERO_COPY) { +#ifdef QEMU_MSG_ZEROCOPY sflags =3D MSG_ZEROCOPY; - } +#else + /* + * We expect QIOChannel class entry point to have + * blocked this code path already + */ + g_assert_not_reached(); #endif + } =20 retry: ret =3D sendmsg(sioc->fd, &msg, sflags); @@ -592,15 +598,13 @@ static ssize_t qio_channel_socket_writev(QIOChannel *= ioc, return QIO_CHANNEL_ERR_BLOCK; case EINTR: goto retry; -#ifdef QEMU_MSG_ZEROCOPY case ENOBUFS: - if (sflags & MSG_ZEROCOPY) { + if (flags & QIO_CHANNEL_WRITE_FLAG_ZERO_COPY) { error_setg_errno(errp, errno, "Process can't lock enough memory for usi= ng MSG_ZEROCOPY"); return -1; } break; -#endif } =20 error_setg_errno(errp, errno, --=20 2.36.1 From nobody Tue May 21 14:34:02 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1655976989; cv=none; d=zohomail.com; s=zohoarc; b=TL8nn1gGefeFOhxasugh1w2QZKZVwMxDov7KLRH/X41Ln++2xJEcHUxnHDnw2OEq1u8CfuJOBgpM5EgYArR8u1MZR+mLQb8bwbam3ZsvU8RwT9koRnbABZgWz3JFDPQ+jomVvUCC1ZLFoY7Q8Oo21TTNVEgQRhrmKKDhhQNPbL8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655976989; h=Content-Type: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=rZS2Qj8OGgQg6pZYnLbW8umeBCQiTi5i+/MP8qAvgLE=; b=FeMMLfLv6SKejLXVQM96xf7n55OnTfzjkzQkueY+Gsk+bDh+YALAc9ztej/nf7+ui03v+ZmU1lJNZBrr8ik4Wha1yv5xUw7Ful4l0sMQRB53Rll8/PknokTs5BKiGlAKJm0TfLLdSzLgKsqfolto6kcZ/6BWm2Z+wlcVqYqIo8U= 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 1655976989839426.51667837537843; Thu, 23 Jun 2022 02:36:29 -0700 (PDT) Received: from localhost ([::1]:50546 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o4JGG-0005bJ-P8 for importer@patchew.org; Thu, 23 Jun 2022 05:36:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45050) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8W-0008PW-Ed for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:37381) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8S-0004sB-9h for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:26 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-294-jmhIlBW8O-26enfN14IWcA-1; Thu, 23 Jun 2022 05:28:20 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C26CF8001EA; Thu, 23 Jun 2022 09:28:19 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.33.36.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id C6AAC40D2962; Thu, 23 Jun 2022 09:28:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655976501; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rZS2Qj8OGgQg6pZYnLbW8umeBCQiTi5i+/MP8qAvgLE=; b=WzZmELS+Xp92NZORIJtrtt5SriSMWp8rodAKWU7PJVAGGTpIMM3jw0R6OS9tV4AGqmEwxp +NdztWkUcYV7SIGp4N/0H3N6lBizFzTzB2DLbJV9Ud8vPEV34dH1Ny22o37iV9S/XflI00 faM7Xj2VbxmVEbmEcwemKr7B2VRUGPY= X-MC-Unique: jmhIlBW8O-26enfN14IWcA-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, huangy81@chinatelecom.cn, quintela@redhat.com, leobras@redhat.com, peterx@redhat.com Cc: jdenemar@redhat.com Subject: [PULL 03/33] QIOChannelSocket: Fix zero-copy send so socket flush works Date: Thu, 23 Jun 2022 10:27:40 +0100 Message-Id: <20220623092810.96234-4-dgilbert@redhat.com> In-Reply-To: <20220623092810.96234-1-dgilbert@redhat.com> References: <20220623092810.96234-1-dgilbert@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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=170.10.133.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1655976990867100001 From: Leonardo Bras Somewhere between v6 and v7 the of the zero-copy-send patchset a crucial part of the flushing mechanism got missing: incrementing zero_copy_queued. Without that, the flushing interface becomes a no-op, and there is no guarantee the buffer is really sent. This can go as bad as causing a corruption in RAM during migration. Fixes: 2bc58ffc2926 ("QIOChannelSocket: Implement io_writev zero copy flag = & io_flush for CONFIG_LINUX") Reported-by: =E5=BE=90=E9=97=AF Signed-off-by: Leonardo Bras Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela Signed-off-by: Dr. David Alan Gilbert --- io/channel-socket.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/io/channel-socket.c b/io/channel-socket.c index b8c13dba7c..4466bb1cd4 100644 --- a/io/channel-socket.c +++ b/io/channel-socket.c @@ -611,6 +611,11 @@ static ssize_t qio_channel_socket_writev(QIOChannel *i= oc, "Unable to write to socket"); return -1; } + + if (flags & QIO_CHANNEL_WRITE_FLAG_ZERO_COPY) { + sioc->zero_copy_queued++; + } + return ret; } #else /* WIN32 */ --=20 2.36.1 From nobody Tue May 21 14:34:02 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1655977660; cv=none; d=zohomail.com; s=zohoarc; b=Y0yk5RnBV6BRi8i+sYwiuHdQfqhJkWPZFuvHVMpdVcK+LNy5ddchtYXCOyVm44YQg6SNTlZiWc3l8ZPyCHBX8+zF5fVv4sdBRAMsKZDnWT12MMF1V89QjHYVMAzHQ2C8G9HCmv25OsJ65PXAo5nIRegJHtwKXZ5jRdlj6c87NUE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655977660; h=Content-Type: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=FLPVE62NxXG9LH47QW/57qaPPZAVyugkyDQy6DkO4CU=; b=k/nglwVPzNPIozHYcXlsS1V515geaZ2iqsu1Y9QMJY5eXQgaIk7U/cqsjrb+TM/tYw+cL2zsmwrzA3oFQ669qWlgFIruF/Rp3uKPFuGF9MiCPeC+CElZO09LMxEZCbIWl07zMOf72NLuBTeg4/CztgzWZXGIJzGAkbRhOc5+YH0= 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 1655977660803270.4754100491757; Thu, 23 Jun 2022 02:47:40 -0700 (PDT) Received: from localhost ([::1]:39856 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o4JR5-0001Lj-43 for importer@patchew.org; Thu, 23 Jun 2022 05:47:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45272) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8j-0000PB-0Y for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:29770) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8S-0004sL-B5 for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:40 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-16-poS8dvqkNGOV2QsLjPa7Nw-1; Thu, 23 Jun 2022 05:28:21 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 04D92185A7B2; Thu, 23 Jun 2022 09:28:21 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.33.36.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id 04A7B40C1289; Thu, 23 Jun 2022 09:28:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655976502; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FLPVE62NxXG9LH47QW/57qaPPZAVyugkyDQy6DkO4CU=; b=MLI9N0mtawZQkbp/mbQ6Kz1RtvKb8934yWnU1noEgJ1lkpUaG5z/dyE+I4Fv4agvG20jva rInAr5/4XOWS2CbDm1HEPnxh0WhJb7nAnhJgrKFXKpaWY7il+2kCJesSMAaTiFuVhGQG1i GOqIIy5N8sa/EG01hP/Z5lD/nVvWymA= X-MC-Unique: poS8dvqkNGOV2QsLjPa7Nw-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, huangy81@chinatelecom.cn, quintela@redhat.com, leobras@redhat.com, peterx@redhat.com Cc: jdenemar@redhat.com Subject: [PULL 04/33] migration: Change zero_copy_send from migration parameter to migration capability Date: Thu, 23 Jun 2022 10:27:41 +0100 Message-Id: <20220623092810.96234-5-dgilbert@redhat.com> In-Reply-To: <20220623092810.96234-1-dgilbert@redhat.com> References: <20220623092810.96234-1-dgilbert@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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=170.10.133.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1655977661802100001 Content-Type: text/plain; charset="utf-8" From: Leonardo Bras When originally implemented, zero_copy_send was designed as a Migration paramenter. But taking into account how is that supposed to work, and how the difference between a capability and a parameter, it only makes sense that zero-copy-send would work better as a capability. Taking into account how recently the change got merged, it was decided that it's still time to make it right, and convert zero_copy_send into a Migration capability. Signed-off-by: Leonardo Bras Reviewed-by: Juan Quintela Acked-by: Markus Armbruster Acked-by: Peter Xu Signed-off-by: Juan Quintela Signed-off-by: Dr. David Alan Gilbert dgilbert: always define the capability, even on non-Linux but error if set; avoids build problems with the capability --- migration/migration.c | 58 +++++++++++++++++++------------------------ monitor/hmp-cmds.c | 6 ----- qapi/migration.json | 33 +++++++----------------- 3 files changed, 34 insertions(+), 63 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 31739b2af9..5863af1b13 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -163,7 +163,8 @@ INITIALIZE_MIGRATE_CAPS_SET(check_caps_background_snaps= hot, MIGRATION_CAPABILITY_COMPRESS, MIGRATION_CAPABILITY_XBZRLE, MIGRATION_CAPABILITY_X_COLO, - MIGRATION_CAPABILITY_VALIDATE_UUID); + MIGRATION_CAPABILITY_VALIDATE_UUID, + MIGRATION_CAPABILITY_ZERO_COPY_SEND); =20 /* When we add fault tolerance, we could have several migrations at once. For now we don't need to add @@ -910,10 +911,6 @@ MigrationParameters *qmp_query_migrate_parameters(Erro= r **errp) params->multifd_zlib_level =3D s->parameters.multifd_zlib_level; params->has_multifd_zstd_level =3D true; params->multifd_zstd_level =3D s->parameters.multifd_zstd_level; -#ifdef CONFIG_LINUX - params->has_zero_copy_send =3D true; - params->zero_copy_send =3D s->parameters.zero_copy_send; -#endif params->has_xbzrle_cache_size =3D true; params->xbzrle_cache_size =3D s->parameters.xbzrle_cache_size; params->has_max_postcopy_bandwidth =3D true; @@ -1275,6 +1272,24 @@ static bool migrate_caps_check(bool *cap_list, } } =20 +#ifdef CONFIG_LINUX + if (cap_list[MIGRATION_CAPABILITY_ZERO_COPY_SEND] && + (!cap_list[MIGRATION_CAPABILITY_MULTIFD] || + migrate_use_compression() || + migrate_use_tls())) { + error_setg(errp, + "Zero copy only available for non-compressed non-TLS mu= ltifd migration"); + return false; + } +#else + if (cap_list[MIGRATION_CAPABILITY_ZERO_COPY_SEND]) { + error_setg(errp, + "Zero copy currently only available on Linux"); + return false; + } +#endif + + /* incoming side only */ if (runstate_check(RUN_STATE_INMIGRATE) && !migrate_multi_channels_is_allowed() && @@ -1497,16 +1512,6 @@ static bool migrate_params_check(MigrationParameters= *params, Error **errp) error_prepend(errp, "Invalid mapping given for block-bitmap-mappin= g: "); return false; } -#ifdef CONFIG_LINUX - if (params->zero_copy_send && - (!migrate_use_multifd() || - params->multifd_compression !=3D MULTIFD_COMPRESSION_NONE || - (params->tls_creds && *params->tls_creds))) { - error_setg(errp, - "Zero copy only available for non-compressed non-TLS mu= ltifd migration"); - return false; - } -#endif return true; } =20 @@ -1580,11 +1585,6 @@ static void migrate_params_test_apply(MigrateSetPara= meters *params, if (params->has_multifd_compression) { dest->multifd_compression =3D params->multifd_compression; } -#ifdef CONFIG_LINUX - if (params->has_zero_copy_send) { - dest->zero_copy_send =3D params->zero_copy_send; - } -#endif if (params->has_xbzrle_cache_size) { dest->xbzrle_cache_size =3D params->xbzrle_cache_size; } @@ -1697,11 +1697,6 @@ static void migrate_params_apply(MigrateSetParameter= s *params, Error **errp) if (params->has_multifd_compression) { s->parameters.multifd_compression =3D params->multifd_compression; } -#ifdef CONFIG_LINUX - if (params->has_zero_copy_send) { - s->parameters.zero_copy_send =3D params->zero_copy_send; - } -#endif if (params->has_xbzrle_cache_size) { s->parameters.xbzrle_cache_size =3D params->xbzrle_cache_size; xbzrle_cache_resize(params->xbzrle_cache_size, errp); @@ -2593,7 +2588,7 @@ bool migrate_use_zero_copy_send(void) =20 s =3D migrate_get_current(); =20 - return s->parameters.zero_copy_send; + return s->enabled_capabilities[MIGRATION_CAPABILITY_ZERO_COPY_SEND]; } #endif =20 @@ -4249,10 +4244,6 @@ static Property migration_properties[] =3D { DEFINE_PROP_UINT8("multifd-zstd-level", MigrationState, parameters.multifd_zstd_level, DEFAULT_MIGRATE_MULTIFD_ZSTD_LEVEL), -#ifdef CONFIG_LINUX - DEFINE_PROP_BOOL("zero_copy_send", MigrationState, - parameters.zero_copy_send, false), -#endif DEFINE_PROP_SIZE("xbzrle-cache-size", MigrationState, parameters.xbzrle_cache_size, DEFAULT_MIGRATE_XBZRLE_CACHE_SIZE), @@ -4290,6 +4281,10 @@ static Property migration_properties[] =3D { DEFINE_PROP_MIG_CAP("x-multifd", MIGRATION_CAPABILITY_MULTIFD), DEFINE_PROP_MIG_CAP("x-background-snapshot", MIGRATION_CAPABILITY_BACKGROUND_SNAPSHOT), +#ifdef CONFIG_LINUX + DEFINE_PROP_MIG_CAP("x-zero-copy-send", + MIGRATION_CAPABILITY_ZERO_COPY_SEND), +#endif =20 DEFINE_PROP_END_OF_LIST(), }; @@ -4350,9 +4345,6 @@ static void migration_instance_init(Object *obj) params->has_multifd_compression =3D true; params->has_multifd_zlib_level =3D true; params->has_multifd_zstd_level =3D true; -#ifdef CONFIG_LINUX - params->has_zero_copy_send =3D true; -#endif params->has_xbzrle_cache_size =3D true; params->has_max_postcopy_bandwidth =3D true; params->has_max_cpu_throttle =3D true; diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 47a27326ee..ca98df0495 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -1311,12 +1311,6 @@ void hmp_migrate_set_parameter(Monitor *mon, const Q= Dict *qdict) p->has_multifd_zstd_level =3D true; visit_type_uint8(v, param, &p->multifd_zstd_level, &err); break; -#ifdef CONFIG_LINUX - case MIGRATION_PARAMETER_ZERO_COPY_SEND: - p->has_zero_copy_send =3D true; - visit_type_bool(v, param, &p->zero_copy_send, &err); - break; -#endif case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE: p->has_xbzrle_cache_size =3D true; if (!visit_type_size(v, param, &cache_size, &err)) { diff --git a/qapi/migration.json b/qapi/migration.json index 6130cd9fae..7102e474a6 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -461,6 +461,13 @@ # procedure starts. The VM RAM is saved with running= VM. # (since 6.0) # +# @zero-copy-send: Controls behavior on sending memory pages on migration. +# When true, enables a zero-copy mechanism for sending +# memory pages, if host supports it. +# Requires that QEMU be permitted to use locked memory +# for guest RAM pages. +# (since 7.1) +# # Features: # @unstable: Members @x-colo and @x-ignore-shared are experimental. # @@ -474,7 +481,8 @@ 'block', 'return-path', 'pause-before-switchover', 'multifd', 'dirty-bitmaps', 'postcopy-blocktime', 'late-block-activate', { 'name': 'x-ignore-shared', 'features': [ 'unstable' ] }, - 'validate-uuid', 'background-snapshot'] } + 'validate-uuid', 'background-snapshot', + 'zero-copy-send'] } =20 ## # @MigrationCapabilityStatus: @@ -738,12 +746,6 @@ # will consume more CPU. # Defaults to 1. (Since 5.0) # -# @zero-copy-send: Controls behavior on sending memory pages on migration. -# When true, enables a zero-copy mechanism for sending -# memory pages, if host supports it. -# Requires that QEMU be permitted to use locked memory -# for guest RAM pages. -# Defaults to false. (Since 7.1) # # @block-bitmap-mapping: Maps block nodes and bitmaps on them to # aliases for the purpose of dirty bitmap migration= . Such @@ -784,7 +786,6 @@ 'xbzrle-cache-size', 'max-postcopy-bandwidth', 'max-cpu-throttle', 'multifd-compression', 'multifd-zlib-level' ,'multifd-zstd-level', - { 'name': 'zero-copy-send', 'if' : 'CONFIG_LINUX'}, 'block-bitmap-mapping' ] } =20 ## @@ -911,13 +912,6 @@ # will consume more CPU. # Defaults to 1. (Since 5.0) # -# @zero-copy-send: Controls behavior on sending memory pages on migration. -# When true, enables a zero-copy mechanism for sending -# memory pages, if host supports it. -# Requires that QEMU be permitted to use locked memory -# for guest RAM pages. -# Defaults to false. (Since 7.1) -# # @block-bitmap-mapping: Maps block nodes and bitmaps on them to # aliases for the purpose of dirty bitmap migration= . Such # aliases may for example be the corresponding name= s on the @@ -972,7 +966,6 @@ '*multifd-compression': 'MultiFDCompression', '*multifd-zlib-level': 'uint8', '*multifd-zstd-level': 'uint8', - '*zero-copy-send': { 'type': 'bool', 'if': 'CONFIG_LINUX' }, '*block-bitmap-mapping': [ 'BitmapMigrationNodeAlias' ] } } =20 ## @@ -1119,13 +1112,6 @@ # will consume more CPU. # Defaults to 1. (Since 5.0) # -# @zero-copy-send: Controls behavior on sending memory pages on migration. -# When true, enables a zero-copy mechanism for sending -# memory pages, if host supports it. -# Requires that QEMU be permitted to use locked memory -# for guest RAM pages. -# Defaults to false. (Since 7.1) -# # @block-bitmap-mapping: Maps block nodes and bitmaps on them to # aliases for the purpose of dirty bitmap migration= . Such # aliases may for example be the corresponding name= s on the @@ -1178,7 +1164,6 @@ '*multifd-compression': 'MultiFDCompression', '*multifd-zlib-level': 'uint8', '*multifd-zstd-level': 'uint8', - '*zero-copy-send': { 'type': 'bool', 'if': 'CONFIG_LINUX' }, '*block-bitmap-mapping': [ 'BitmapMigrationNodeAlias' ] } } =20 ## --=20 2.36.1 From nobody Tue May 21 14:34:02 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1655976840; cv=none; d=zohomail.com; s=zohoarc; b=d+p3X/PUWeGICEA4CgbRB6pYxpSYBm1fxYq9UXgvQ5CDcej6oDAQF9jvSsa9Zk0rccApzQpozXc70yICc5vzYXHNE4DFwXB0jqI2+23GRK65Og6MTMFtPaLUMj80ubH0Usu6iv9WKG72UU2s0OU7fXGf1zXG9zJ6keb0sebaQSQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655976840; h=Content-Type: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=g3lQjZ+KWEOw/oCbODdfnixrOec0JnPiAumb/enPmJg=; b=C8dfMUxmVSQxLMv2GRgq9T5s/CeLq0PRGQZoxUHTKfEYDwtWzGXukUWKRLKFJddiaWZeD5Rkgmkn5juCw8JD3muWz+B5vOFG/rWlS2M7tmm8694yHWcE/UVUm6qjEBWbQTmniaXKw17uwKgUYnm9AsM2aLIpGkbjqUKrCU1rHWo= 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 1655976840853406.7212496771168; Thu, 23 Jun 2022 02:34:00 -0700 (PDT) Received: from localhost ([::1]:47420 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o4JDq-0003SJ-Q6 for importer@patchew.org; Thu, 23 Jun 2022 05:33:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45092) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8X-0008Vx-CF for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:20089) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8U-0004sw-UW for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:29 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-49-Ml0xwZ6mOxyZIbnO3TVXUQ-1; Thu, 23 Jun 2022 05:28:22 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 38274294EDC8; Thu, 23 Jun 2022 09:28:22 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.33.36.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3823C40D2962; Thu, 23 Jun 2022 09:28:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655976505; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=g3lQjZ+KWEOw/oCbODdfnixrOec0JnPiAumb/enPmJg=; b=UhTpDTiUijBq1LIhAl4/6DgxgvzTuEcIgToaCM/BGZpMSXA/PXYM44nGJHb7Hkmkkgdheq txOCRy7iXMmNl8KkfgPMHinSnxjvpY0sRLUCTAWAsKp+IrC0EXYGd7KDHhm6/nq/eYL614 K5Ww5wAANmLg06d9hcdE1+RerjtgrPM= X-MC-Unique: Ml0xwZ6mOxyZIbnO3TVXUQ-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, huangy81@chinatelecom.cn, quintela@redhat.com, leobras@redhat.com, peterx@redhat.com Cc: jdenemar@redhat.com Subject: [PULL 05/33] io: add a QIOChannelNull equivalent to /dev/null Date: Thu, 23 Jun 2022 10:27:42 +0100 Message-Id: <20220623092810.96234-6-dgilbert@redhat.com> In-Reply-To: <20220623092810.96234-1-dgilbert@redhat.com> References: <20220623092810.96234-1-dgilbert@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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=170.10.129.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1655976841731100002 From: Daniel P. Berrang=C3=A9 This is for code which needs a portable equivalent to a QIOChannelFile connected to /dev/null. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela Signed-off-by: Dr. David Alan Gilbert --- include/io/channel-null.h | 55 +++++++ io/channel-null.c | 237 ++++++++++++++++++++++++++++++ io/meson.build | 1 + io/trace-events | 3 + tests/unit/meson.build | 1 + tests/unit/test-io-channel-null.c | 95 ++++++++++++ 6 files changed, 392 insertions(+) create mode 100644 include/io/channel-null.h create mode 100644 io/channel-null.c create mode 100644 tests/unit/test-io-channel-null.c diff --git a/include/io/channel-null.h b/include/io/channel-null.h new file mode 100644 index 0000000000..f6d54e63cf --- /dev/null +++ b/include/io/channel-null.h @@ -0,0 +1,55 @@ +/* + * QEMU I/O channels null driver + * + * Copyright (c) 2022 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + * + */ + +#ifndef QIO_CHANNEL_FILE_H +#define QIO_CHANNEL_FILE_H + +#include "io/channel.h" +#include "qom/object.h" + +#define TYPE_QIO_CHANNEL_NULL "qio-channel-null" +OBJECT_DECLARE_SIMPLE_TYPE(QIOChannelNull, QIO_CHANNEL_NULL) + + +/** + * QIOChannelNull: + * + * The QIOChannelNull object provides a channel implementation + * that discards all writes and returns EOF for all reads. + */ + +struct QIOChannelNull { + QIOChannel parent; + bool closed; +}; + + +/** + * qio_channel_null_new: + * + * Create a new IO channel object that discards all writes + * and returns EOF for all reads. + * + * Returns: the new channel object + */ +QIOChannelNull * +qio_channel_null_new(void); + +#endif /* QIO_CHANNEL_NULL_H */ diff --git a/io/channel-null.c b/io/channel-null.c new file mode 100644 index 0000000000..75e3781507 --- /dev/null +++ b/io/channel-null.c @@ -0,0 +1,237 @@ +/* + * QEMU I/O channels null driver + * + * Copyright (c) 2022 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + * + */ + +#include "qemu/osdep.h" +#include "io/channel-null.h" +#include "io/channel-watch.h" +#include "qapi/error.h" +#include "trace.h" +#include "qemu/iov.h" + +typedef struct QIOChannelNullSource QIOChannelNullSource; +struct QIOChannelNullSource { + GSource parent; + QIOChannel *ioc; + GIOCondition condition; +}; + + +QIOChannelNull * +qio_channel_null_new(void) +{ + QIOChannelNull *ioc; + + ioc =3D QIO_CHANNEL_NULL(object_new(TYPE_QIO_CHANNEL_NULL)); + + trace_qio_channel_null_new(ioc); + + return ioc; +} + + +static void +qio_channel_null_init(Object *obj) +{ + QIOChannelNull *ioc =3D QIO_CHANNEL_NULL(obj); + ioc->closed =3D false; +} + + +static ssize_t +qio_channel_null_readv(QIOChannel *ioc, + const struct iovec *iov, + size_t niov, + int **fds G_GNUC_UNUSED, + size_t *nfds G_GNUC_UNUSED, + Error **errp) +{ + QIOChannelNull *nioc =3D QIO_CHANNEL_NULL(ioc); + + if (nioc->closed) { + error_setg_errno(errp, EINVAL, + "Channel is closed"); + return -1; + } + + return 0; +} + + +static ssize_t +qio_channel_null_writev(QIOChannel *ioc, + const struct iovec *iov, + size_t niov, + int *fds G_GNUC_UNUSED, + size_t nfds G_GNUC_UNUSED, + int flags G_GNUC_UNUSED, + Error **errp) +{ + QIOChannelNull *nioc =3D QIO_CHANNEL_NULL(ioc); + + if (nioc->closed) { + error_setg_errno(errp, EINVAL, + "Channel is closed"); + return -1; + } + + return iov_size(iov, niov); +} + + +static int +qio_channel_null_set_blocking(QIOChannel *ioc G_GNUC_UNUSED, + bool enabled G_GNUC_UNUSED, + Error **errp G_GNUC_UNUSED) +{ + return 0; +} + + +static off_t +qio_channel_null_seek(QIOChannel *ioc G_GNUC_UNUSED, + off_t offset G_GNUC_UNUSED, + int whence G_GNUC_UNUSED, + Error **errp G_GNUC_UNUSED) +{ + return 0; +} + + +static int +qio_channel_null_close(QIOChannel *ioc, + Error **errp G_GNUC_UNUSED) +{ + QIOChannelNull *nioc =3D QIO_CHANNEL_NULL(ioc); + + nioc->closed =3D true; + return 0; +} + + +static void +qio_channel_null_set_aio_fd_handler(QIOChannel *ioc G_GNUC_UNUSED, + AioContext *ctx G_GNUC_UNUSED, + IOHandler *io_read G_GNUC_UNUSED, + IOHandler *io_write G_GNUC_UNUSED, + void *opaque G_GNUC_UNUSED) +{ +} + + +static gboolean +qio_channel_null_source_prepare(GSource *source G_GNUC_UNUSED, + gint *timeout) +{ + *timeout =3D -1; + + return TRUE; +} + + +static gboolean +qio_channel_null_source_check(GSource *source G_GNUC_UNUSED) +{ + return TRUE; +} + + +static gboolean +qio_channel_null_source_dispatch(GSource *source, + GSourceFunc callback, + gpointer user_data) +{ + QIOChannelFunc func =3D (QIOChannelFunc)callback; + QIOChannelNullSource *ssource =3D (QIOChannelNullSource *)source; + + return (*func)(ssource->ioc, + ssource->condition, + user_data); +} + + +static void +qio_channel_null_source_finalize(GSource *source) +{ + QIOChannelNullSource *ssource =3D (QIOChannelNullSource *)source; + + object_unref(OBJECT(ssource->ioc)); +} + + +GSourceFuncs qio_channel_null_source_funcs =3D { + qio_channel_null_source_prepare, + qio_channel_null_source_check, + qio_channel_null_source_dispatch, + qio_channel_null_source_finalize +}; + + +static GSource * +qio_channel_null_create_watch(QIOChannel *ioc, + GIOCondition condition) +{ + GSource *source; + QIOChannelNullSource *ssource; + + source =3D g_source_new(&qio_channel_null_source_funcs, + sizeof(QIOChannelNullSource)); + ssource =3D (QIOChannelNullSource *)source; + + ssource->ioc =3D ioc; + object_ref(OBJECT(ioc)); + + ssource->condition =3D condition; + + return source; +} + + +static void +qio_channel_null_class_init(ObjectClass *klass, + void *class_data G_GNUC_UNUSED) +{ + QIOChannelClass *ioc_klass =3D QIO_CHANNEL_CLASS(klass); + + ioc_klass->io_writev =3D qio_channel_null_writev; + ioc_klass->io_readv =3D qio_channel_null_readv; + ioc_klass->io_set_blocking =3D qio_channel_null_set_blocking; + ioc_klass->io_seek =3D qio_channel_null_seek; + ioc_klass->io_close =3D qio_channel_null_close; + ioc_klass->io_create_watch =3D qio_channel_null_create_watch; + ioc_klass->io_set_aio_fd_handler =3D qio_channel_null_set_aio_fd_handl= er; +} + + +static const TypeInfo qio_channel_null_info =3D { + .parent =3D TYPE_QIO_CHANNEL, + .name =3D TYPE_QIO_CHANNEL_NULL, + .instance_size =3D sizeof(QIOChannelNull), + .instance_init =3D qio_channel_null_init, + .class_init =3D qio_channel_null_class_init, +}; + + +static void +qio_channel_null_register_types(void) +{ + type_register_static(&qio_channel_null_info); +} + +type_init(qio_channel_null_register_types); diff --git a/io/meson.build b/io/meson.build index bbcd3c53a4..283b9b2bdb 100644 --- a/io/meson.build +++ b/io/meson.build @@ -3,6 +3,7 @@ io_ss.add(files( 'channel-buffer.c', 'channel-command.c', 'channel-file.c', + 'channel-null.c', 'channel-socket.c', 'channel-tls.c', 'channel-util.c', diff --git a/io/trace-events b/io/trace-events index c5e814eb44..3cc5cf1efd 100644 --- a/io/trace-events +++ b/io/trace-events @@ -10,6 +10,9 @@ qio_task_thread_result(void *task) "Task thread result ta= sk=3D%p" qio_task_thread_source_attach(void *task, void *source) "Task thread sourc= e attach task=3D%p source=3D%p" qio_task_thread_source_cancel(void *task, void *source) "Task thread sourc= e cancel task=3D%p source=3D%p" =20 +# channel-null.c +qio_channel_null_new(void *ioc) "Null new ioc=3D%p" + # channel-socket.c qio_channel_socket_new(void *ioc) "Socket new ioc=3D%p" qio_channel_socket_new_fd(void *ioc, int fd) "Socket new ioc=3D%p fd=3D%d" diff --git a/tests/unit/meson.build b/tests/unit/meson.build index 287b367ec3..b497a41378 100644 --- a/tests/unit/meson.build +++ b/tests/unit/meson.build @@ -88,6 +88,7 @@ if have_block 'test-io-channel-file': ['io-channel-helpers.c', io], 'test-io-channel-command': ['io-channel-helpers.c', io], 'test-io-channel-buffer': ['io-channel-helpers.c', io], + 'test-io-channel-null': [io], 'test-crypto-ivgen': [io], 'test-crypto-afsplit': [io], 'test-crypto-block': [io], diff --git a/tests/unit/test-io-channel-null.c b/tests/unit/test-io-channel= -null.c new file mode 100644 index 0000000000..b3aab17ccc --- /dev/null +++ b/tests/unit/test-io-channel-null.c @@ -0,0 +1,95 @@ +/* + * QEMU I/O channel null test + * + * Copyright (c) 2022 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + * + */ + +#include "qemu/osdep.h" +#include "io/channel-null.h" +#include "qapi/error.h" + +static gboolean test_io_channel_watch(QIOChannel *ioc, + GIOCondition condition, + gpointer opaque) +{ + GIOCondition *gotcond =3D opaque; + *gotcond =3D condition; + return G_SOURCE_REMOVE; +} + +static void test_io_channel_null_io(void) +{ + g_autoptr(QIOChannelNull) null =3D qio_channel_null_new(); + char buf[1024]; + GIOCondition gotcond =3D 0; + Error *local_err =3D NULL; + + g_assert(qio_channel_write(QIO_CHANNEL(null), + "Hello World", 11, + &error_abort) =3D=3D 11); + + g_assert(qio_channel_read(QIO_CHANNEL(null), + buf, sizeof(buf), + &error_abort) =3D=3D 0); + + qio_channel_add_watch(QIO_CHANNEL(null), + G_IO_IN, + test_io_channel_watch, + &gotcond, + NULL); + + g_main_context_iteration(NULL, false); + + g_assert(gotcond =3D=3D G_IO_IN); + + qio_channel_add_watch(QIO_CHANNEL(null), + G_IO_IN | G_IO_OUT, + test_io_channel_watch, + &gotcond, + NULL); + + g_main_context_iteration(NULL, false); + + g_assert(gotcond =3D=3D (G_IO_IN | G_IO_OUT)); + + qio_channel_close(QIO_CHANNEL(null), &error_abort); + + g_assert(qio_channel_write(QIO_CHANNEL(null), + "Hello World", 11, + &local_err) =3D=3D -1); + g_assert_nonnull(local_err); + + g_clear_pointer(&local_err, error_free); + + g_assert(qio_channel_read(QIO_CHANNEL(null), + buf, sizeof(buf), + &local_err) =3D=3D -1); + g_assert_nonnull(local_err); + + g_clear_pointer(&local_err, error_free); +} + +int main(int argc, char **argv) +{ + module_call_init(MODULE_INIT_QOM); + + g_test_init(&argc, &argv, NULL); + + g_test_add_func("/io/channel/null/io", test_io_channel_null_io); + + return g_test_run(); +} --=20 2.36.1 From nobody Tue May 21 14:34:02 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1655976839; cv=none; d=zohomail.com; s=zohoarc; b=kNpYhjvh69fJLA60pEUgFBWGMM+sMsAU7+QlNco0RutF+KT3Zgli0UqTWVWoTn2XMizhr57v5HFNeDornj/PW48gETdEKkASDhfM03tV4KWu3vaVErv5oTdd+gSRPx5rQHffu4YLpssJS6AaDEFL4ioIiANPjhgxrMGPDMmmyLA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655976839; h=Content-Type: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=uRIaADQjCBbHL0g9UpbAj8bjRQwiDz8AT7tOoYuzeRg=; b=B7Z8aMmgJ1QPq/4KQGrw7JvMgTV/KWIxs1PsQ5QWc9rkUR2GdN1QHgU3eQ7PJ2ZnXi+bx7LEfYk/M/bduiOyIxOzz8igZf17PrnBJJURGXvg64DkuQQ4p2CWTQH3qocjWLzV8QJfP2Jt2c9cfaqw6uRdJLrgx/ui81qzkV8eU/M= 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 16559768396985.843600480913551; Thu, 23 Jun 2022 02:33:59 -0700 (PDT) Received: from localhost ([::1]:47450 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o4JDq-0003TQ-2o for importer@patchew.org; Thu, 23 Jun 2022 05:33:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45086) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8X-0008VN-3L for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:53412) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8V-0004tD-CX for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:28 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-569-shRmA3hLMhetJMCIyZWZhg-1; Thu, 23 Jun 2022 05:28:23 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 65BDF8001EA; Thu, 23 Jun 2022 09:28:23 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.33.36.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6BC4440D2962; Thu, 23 Jun 2022 09:28:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655976506; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uRIaADQjCBbHL0g9UpbAj8bjRQwiDz8AT7tOoYuzeRg=; b=IyQOGCTpKTRwVkh/WYKpXHBzduGhC55z1qmac4LQv2cpEf4Iq6m8kz14uAnJMOI1k+xPbT Iq1oBcIj0+s0SnB/8vMLkIDoEkqQ14d2ffVTgJH/78W0ROOeOaNyIeIEcUJmiX+jOCaDcz mBjjIcGGuyhMKiFMlAqzhebk5DwYRKU= X-MC-Unique: shRmA3hLMhetJMCIyZWZhg-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, huangy81@chinatelecom.cn, quintela@redhat.com, leobras@redhat.com, peterx@redhat.com Cc: jdenemar@redhat.com Subject: [PULL 06/33] migration: switch to use QIOChannelNull for dummy channel Date: Thu, 23 Jun 2022 10:27:43 +0100 Message-Id: <20220623092810.96234-7-dgilbert@redhat.com> In-Reply-To: <20220623092810.96234-1-dgilbert@redhat.com> References: <20220623092810.96234-1-dgilbert@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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=170.10.129.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1655976841713100001 From: Daniel P. Berrang=C3=A9 This removes one further custom impl of QEMUFile, in favour of a QIOChannel based impl. Reviewed-by: Eric Blake Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela Signed-off-by: Dr. David Alan Gilbert --- migration/ram.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 5f5e37f64d..89082716d6 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -32,11 +32,13 @@ #include "qemu/bitmap.h" #include "qemu/madvise.h" #include "qemu/main-loop.h" +#include "io/channel-null.h" #include "xbzrle.h" #include "ram.h" #include "migration.h" #include "migration/register.h" #include "migration/misc.h" +#include "migration/qemu-file-channel.h" #include "qemu-file.h" #include "postcopy-ram.h" #include "page_cache.h" @@ -457,8 +459,6 @@ static QemuThread *compress_threads; */ static QemuMutex comp_done_lock; static QemuCond comp_done_cond; -/* The empty QEMUFileOps will be used by file in CompressParam */ -static const QEMUFileOps empty_ops =3D { }; =20 static QEMUFile *decomp_file; static DecompressParam *decomp_param; @@ -569,7 +569,8 @@ static int compress_threads_save_setup(void) /* comp_param[i].file is just used as a dummy buffer to save data, * set its ops to empty. */ - comp_param[i].file =3D qemu_fopen_ops(NULL, &empty_ops, false); + comp_param[i].file =3D qemu_fopen_channel_output( + QIO_CHANNEL(qio_channel_null_new())); comp_param[i].done =3D true; comp_param[i].quit =3D false; qemu_mutex_init(&comp_param[i].mutex); --=20 2.36.1 From nobody Tue May 21 14:34:02 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1655977251; cv=none; d=zohomail.com; s=zohoarc; b=ipEdoDQ2SAzzxInLKtl/HIBcLbEano4s/IEqFpenC6yrMUYq1BRH2zBclY6os1x1zD4/2kpXN322vAexpd7k/VNtUipd/JyuFQ2LtBe5VVh2TdUPaDpseMChNQ4Q/DIAunOHb2gD80pzVIwiae0QWaKyUfnAlgPXILZDHhE9cJc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655977251; h=Content-Type: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=+jPmpDSwRTFoYmOjQmvGMUYdM/c1OD/+RnzJ9cp02DA=; b=Olk5iDevKan9uKMx4EzBKt5YS9GFmEdeIZCWzZsL6RofMC/qRJRDhSrtIXjiiZr6jyED0TFyg77kwHBMtIXM5XcM1e3B72+TdNdXSztFoIxlrNmuHrE1Sy0qAChyvUx6cqynbZnoEOxxQVAFpWGE3D6TMfk1Bw7byXYzAnwf4HQ= 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 1655977251898800.9453014308687; Thu, 23 Jun 2022 02:40:51 -0700 (PDT) Received: from localhost ([::1]:56452 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o4JKU-0001N0-FM for importer@patchew.org; Thu, 23 Jun 2022 05:40:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45138) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8Y-000089-W9 for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:23983) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8X-0004uh-5P for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:30 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-537-dfO0-AAdNf-eHQwv8QkFiw-1; Thu, 23 Jun 2022 05:28:24 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 97261803D57; Thu, 23 Jun 2022 09:28:24 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.33.36.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id 98C0040D2962; Thu, 23 Jun 2022 09:28:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655976508; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+jPmpDSwRTFoYmOjQmvGMUYdM/c1OD/+RnzJ9cp02DA=; b=LYEl8tlLyYYLS4YQJ5jq6PGXdwgIYFfY61PgIr4lL4SCikLBK9b5sjRnfej+wBgd5utdML +dQW8lEIaFamJ1MBz37TU4yY/GIHvzOvwgrtHkXoWwCEnzVwN85kWmz3+SYwAvFPuNi7sM fAJYQ0P/3+Sde/K/4NT2JrExI4Gr9+E= X-MC-Unique: dfO0-AAdNf-eHQwv8QkFiw-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, huangy81@chinatelecom.cn, quintela@redhat.com, leobras@redhat.com, peterx@redhat.com Cc: jdenemar@redhat.com Subject: [PULL 07/33] migration: remove unreachble RDMA code in save_hook impl Date: Thu, 23 Jun 2022 10:27:44 +0100 Message-Id: <20220623092810.96234-8-dgilbert@redhat.com> In-Reply-To: <20220623092810.96234-1-dgilbert@redhat.com> References: <20220623092810.96234-1-dgilbert@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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=170.10.129.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1655977252692100003 From: Daniel P. Berrang=C3=A9 The QEMUFile 'save_hook' callback has a 'size_t size' parameter. The RDMA impl of this has logic that takes different actions depending on whether the value is zero or non-zero. It has commented out logic that would have taken further actions if the value was negative. The only place where the 'save_hook' callback is invoked is the ram_control_save_page() method, which passes 'size' through from its caller. The only caller of this method is in turn control_save_page(). This method unconditionally passes the 'TARGET_PAGE_SIZE' constant for the 'size' parameter. IOW, the only scenario for 'size' that can execute in the qemu_rdma_save_page method is 'size > 0'. The remaining code has been unreachable since RDMA support was first introduced 9 years ago. Reviewed-by: Eric Blake Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela Signed-off-by: Dr. David Alan Gilbert --- migration/rdma.c | 120 +++++++++-------------------------------------- 1 file changed, 21 insertions(+), 99 deletions(-) diff --git a/migration/rdma.c b/migration/rdma.c index 8504152f39..c5fa4a408a 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -1462,34 +1462,6 @@ static uint64_t qemu_rdma_make_wrid(uint64_t wr_id, = uint64_t index, return result; } =20 -/* - * Set bit for unregistration in the next iteration. - * We cannot transmit right here, but will unpin later. - */ -static void qemu_rdma_signal_unregister(RDMAContext *rdma, uint64_t index, - uint64_t chunk, uint64_t wr_id) -{ - if (rdma->unregistrations[rdma->unregister_next] !=3D 0) { - error_report("rdma migration: queue is full"); - } else { - RDMALocalBlock *block =3D &(rdma->local_ram_blocks.block[index]); - - if (!test_and_set_bit(chunk, block->unregister_bitmap)) { - trace_qemu_rdma_signal_unregister_append(chunk, - rdma->unregister_next= ); - - rdma->unregistrations[rdma->unregister_next++] =3D - qemu_rdma_make_wrid(wr_id, index, chunk); - - if (rdma->unregister_next =3D=3D RDMA_SIGNALED_SEND_MAX) { - rdma->unregister_next =3D 0; - } - } else { - trace_qemu_rdma_signal_unregister_already(chunk); - } - } -} - /* * Consult the connection manager to see a work request * (of any kind) has completed. @@ -3237,23 +3209,7 @@ qio_channel_rdma_shutdown(QIOChannel *ioc, * Offset is an offset to be added to block_offset and used * to also lookup the corresponding RAMBlock. * - * @size > 0 : - * Initiate an transfer this size. - * - * @size =3D=3D 0 : - * A 'hint' or 'advice' that means that we wish to speculatively - * and asynchronously unregister this memory. In this case, there i= s no - * guarantee that the unregister will actually happen, for example, - * if the memory is being actively transmitted. Additionally, the m= emory - * may be re-registered at any future time if a write within the sa= me - * chunk was requested again, even if you attempted to unregister it - * here. - * - * @size < 0 : TODO, not yet supported - * Unregister the memory NOW. This means that the caller does not - * expect there to be any future RDMA transfers and we just want to= clean - * things up. This is used in case the upper layer owns the memory = and - * cannot wait for qemu_fclose() to occur. + * @size : Number of bytes to transfer * * @bytes_sent : User-specificed pointer to indicate how many bytes were * sent. Usually, this will not be more than a few bytes = of @@ -3282,61 +3238,27 @@ static size_t qemu_rdma_save_page(QEMUFile *f, void= *opaque, =20 qemu_fflush(f); =20 - if (size > 0) { - /* - * Add this page to the current 'chunk'. If the chunk - * is full, or the page doesn't belong to the current chunk, - * an actual RDMA write will occur and a new chunk will be formed. - */ - ret =3D qemu_rdma_write(f, rdma, block_offset, offset, size); - if (ret < 0) { - error_report("rdma migration: write error! %d", ret); - goto err; - } - - /* - * We always return 1 bytes because the RDMA - * protocol is completely asynchronous. We do not yet know - * whether an identified chunk is zero or not because we're - * waiting for other pages to potentially be merged with - * the current chunk. So, we have to call qemu_update_position() - * later on when the actual write occurs. - */ - if (bytes_sent) { - *bytes_sent =3D 1; - } - } else { - uint64_t index, chunk; - - /* TODO: Change QEMUFileOps prototype to be signed: size_t =3D> lo= ng - if (size < 0) { - ret =3D qemu_rdma_drain_cq(f, rdma); - if (ret < 0) { - fprintf(stderr, "rdma: failed to synchronously drain" - " completion queue before unregistration.\= n"); - goto err; - } - } - */ - - ret =3D qemu_rdma_search_ram_block(rdma, block_offset, - offset, size, &index, &chunk); - - if (ret) { - error_report("ram block search failed"); - goto err; - } - - qemu_rdma_signal_unregister(rdma, index, chunk, 0); + /* + * Add this page to the current 'chunk'. If the chunk + * is full, or the page doesn't belong to the current chunk, + * an actual RDMA write will occur and a new chunk will be formed. + */ + ret =3D qemu_rdma_write(f, rdma, block_offset, offset, size); + if (ret < 0) { + error_report("rdma migration: write error! %d", ret); + goto err; + } =20 - /* - * TODO: Synchronous, guaranteed unregistration (should not occur = during - * fast-path). Otherwise, unregisters will process on the next cal= l to - * qemu_rdma_drain_cq() - if (size < 0) { - qemu_rdma_unregister_waiting(rdma); - } - */ + /* + * We always return 1 bytes because the RDMA + * protocol is completely asynchronous. We do not yet know + * whether an identified chunk is zero or not because we're + * waiting for other pages to potentially be merged with + * the current chunk. So, we have to call qemu_update_position() + * later on when the actual write occurs. + */ + if (bytes_sent) { + *bytes_sent =3D 1; } =20 /* --=20 2.36.1 From nobody Tue May 21 14:34:02 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1655978015; cv=none; d=zohomail.com; s=zohoarc; b=cwul28Pk2e0UfqJmKK5zId5Q6AMoscgro/1oXxDgYhvFdOM5cm+/LsfnA6S8VKte+lWWjTZxOmS/NYrS5pMLYtMO4IfgxhYEjwqZtZHwIn0wE5WSqzAaEDgRBxsFyuljcEftIif7KUUWjVl+Ex+HLveNXVZYqv4bYKqyS5hs8m8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655978015; h=Content-Type: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=5iuQG1I55xP1cM/emunkwVVX+jDe6tIbx145oh9Czg4=; b=YuPqsovhZbJcPmit2QObNXY1UphTjUEkRqp2FKD1C8rpX1IiMQ55FOCAp2SvllEgalguJD8ElPAEJ79bddr8GMtaO/PEqQtysaxA/zPe432AQ4xaX9kiVrRfUhzy9CZzp8Ru1wszq3nkjTVVpQRWpf2PdUkzzlG6pKH4pgqceA8= 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 1655978015873702.8140394958122; Thu, 23 Jun 2022 02:53:35 -0700 (PDT) Received: from localhost ([::1]:46662 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o4JWo-0006RT-FK for importer@patchew.org; Thu, 23 Jun 2022 05:53:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45128) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8Y-000077-Gd for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:54106) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8W-0004tN-0D for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:30 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-34-BNS7XD-qPE2Ethn8msdAQA-1; Thu, 23 Jun 2022 05:28:26 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C4EC2185A7B2; Thu, 23 Jun 2022 09:28:25 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.33.36.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id CB3EF40D2962; Thu, 23 Jun 2022 09:28:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655976507; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5iuQG1I55xP1cM/emunkwVVX+jDe6tIbx145oh9Czg4=; b=KukKeFLZ1w/yzMRmXl5cUclyag05h4OVbeo4dmgqyxGhtppUT77k0u+McMNhmAZYy/JB7M lZM9b9QdNlmRyOekes3XezGvKPchAnTnZCyJwrGChWypjR3M0QaG2iMs8voncLYdLgH9cs 9WpU8EA8HhQ1Zat6//cLt87RPV1jQmI= X-MC-Unique: BNS7XD-qPE2Ethn8msdAQA-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, huangy81@chinatelecom.cn, quintela@redhat.com, leobras@redhat.com, peterx@redhat.com Cc: jdenemar@redhat.com Subject: [PULL 08/33] migration: rename rate limiting fields in QEMUFile Date: Thu, 23 Jun 2022 10:27:45 +0100 Message-Id: <20220623092810.96234-9-dgilbert@redhat.com> In-Reply-To: <20220623092810.96234-1-dgilbert@redhat.com> References: <20220623092810.96234-1-dgilbert@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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=170.10.133.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1655978016350100001 From: Daniel P. Berrang=C3=A9 This renames the following QEMUFile fields * bytes_xfer -> rate_limit_used * xfer_limit -> rate_limit_max The intent is to make it clear that 'bytes_xfer' is specifically related to rate limiting of data and applies to data queued, which need not have been transferred on the wire yet if a flush hasn't taken place. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela Signed-off-by: Dr. David Alan Gilbert --- migration/qemu-file.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 1479cddad9..03f0b13a55 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -39,8 +39,16 @@ struct QEMUFile { const QEMUFileHooks *hooks; void *opaque; =20 - int64_t bytes_xfer; - int64_t xfer_limit; + /* + * Maximum amount of data in bytes to transfer during one + * rate limiting time window + */ + int64_t rate_limit_max; + /* + * Total amount of data in bytes queued for transfer + * during this rate limiting time window + */ + int64_t rate_limit_used; =20 int64_t pos; /* start of buffer when writing, end of buffer when reading */ @@ -304,7 +312,7 @@ size_t ram_control_save_page(QEMUFile *f, ram_addr_t bl= ock_offset, int ret =3D f->hooks->save_page(f, f->opaque, block_offset, offset, size, bytes_sent); if (ret !=3D RAM_SAVE_CONTROL_NOT_SUPP) { - f->bytes_xfer +=3D size; + f->rate_limit_used +=3D size; } =20 if (ret !=3D RAM_SAVE_CONTROL_DELAYED && @@ -457,7 +465,7 @@ void qemu_put_buffer_async(QEMUFile *f, const uint8_t *= buf, size_t size, return; } =20 - f->bytes_xfer +=3D size; + f->rate_limit_used +=3D size; add_to_iovec(f, buf, size, may_free); } =20 @@ -475,7 +483,7 @@ void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, s= ize_t size) l =3D size; } memcpy(f->buf + f->buf_index, buf, l); - f->bytes_xfer +=3D l; + f->rate_limit_used +=3D l; add_buf_to_iovec(f, l); if (qemu_file_get_error(f)) { break; @@ -492,7 +500,7 @@ void qemu_put_byte(QEMUFile *f, int v) } =20 f->buf[f->buf_index] =3D v; - f->bytes_xfer++; + f->rate_limit_used++; add_buf_to_iovec(f, 1); } =20 @@ -674,7 +682,7 @@ int qemu_file_rate_limit(QEMUFile *f) if (qemu_file_get_error(f)) { return 1; } - if (f->xfer_limit > 0 && f->bytes_xfer > f->xfer_limit) { + if (f->rate_limit_max > 0 && f->rate_limit_used > f->rate_limit_max) { return 1; } return 0; @@ -682,22 +690,22 @@ int qemu_file_rate_limit(QEMUFile *f) =20 int64_t qemu_file_get_rate_limit(QEMUFile *f) { - return f->xfer_limit; + return f->rate_limit_max; } =20 void qemu_file_set_rate_limit(QEMUFile *f, int64_t limit) { - f->xfer_limit =3D limit; + f->rate_limit_max =3D limit; } =20 void qemu_file_reset_rate_limit(QEMUFile *f) { - f->bytes_xfer =3D 0; + f->rate_limit_used =3D 0; } =20 void qemu_file_update_transfer(QEMUFile *f, int64_t len) { - f->bytes_xfer +=3D len; + f->rate_limit_used +=3D len; } =20 void qemu_put_be16(QEMUFile *f, unsigned int v) --=20 2.36.1 From nobody Tue May 21 14:34:02 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1655978813; cv=none; d=zohomail.com; s=zohoarc; b=jL6lytryE+5ywI9xv1y82d4lrC0rtuD0GaPGxnZwpueL/xxGeGYOkGIxFNNIXa3lFRtiWj1fhbdlR09ND+m0xlzMkPyH+ZvTOzzTJ44mXw2ySeRhRJNMbIEcoBU2tU3PnlIRsYnGRRt+Hwr1sNx5rwsm+P7bZf+j79C/4BrhC30= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655978813; h=Content-Type: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=XzYOGcOy1v/w7qlG3QUq+c89iqqIhsvwCuZxC/PtYlM=; b=m4N6KSaiV8vUwthzMtPeOM4RRvuGEheSvlWWW1qNnaRf/QzSTG8FEukfxIZR8nUI/FQtXjCwbtmgEnQTO3WdutiBE8/yPOG3nTvckTHzNZRWCALwuZzrRqWImOZ8hHwW+rRhhXljiU1bHESxSm7cmGm0omosU5MZ1fWDBRM/bcA= 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 1655978813937549.314317218882; Thu, 23 Jun 2022 03:06:53 -0700 (PDT) Received: from localhost ([::1]:44256 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o4Jjf-0007Y9-EH for importer@patchew.org; Thu, 23 Jun 2022 06:06:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45296) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8j-0000QG-ML for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:32820) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8g-0004wQ-IQ for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:41 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-114-aDtzNj_mPP-7xUXGOFdlTw-1; Thu, 23 Jun 2022 05:28:27 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F3875101AA45; Thu, 23 Jun 2022 09:28:26 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.33.36.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0356640D2962; Thu, 23 Jun 2022 09:28:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655976518; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XzYOGcOy1v/w7qlG3QUq+c89iqqIhsvwCuZxC/PtYlM=; b=a3e9CjwSAf9KlSMENe337xF5/uz0/2e2W0Lzh0Qu5jXA6Mcgo4nQ3pn3jx71mwsKxxCLYu P75SULyzfVufSwa1Au6XkdettAfsj3nTBw2JedbkafzOAberOY5I+3b5Y2WjEmvQtUTHkB QIV7Q+W1D2fJREiO7nkzMCeajF4v28g= X-MC-Unique: aDtzNj_mPP-7xUXGOFdlTw-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, huangy81@chinatelecom.cn, quintela@redhat.com, leobras@redhat.com, peterx@redhat.com Cc: jdenemar@redhat.com Subject: [PULL 09/33] migration: rename 'pos' field in QEMUFile to 'bytes_processed' Date: Thu, 23 Jun 2022 10:27:46 +0100 Message-Id: <20220623092810.96234-10-dgilbert@redhat.com> In-Reply-To: <20220623092810.96234-1-dgilbert@redhat.com> References: <20220623092810.96234-1-dgilbert@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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=170.10.133.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1655978815350100001 From: Daniel P. Berrang=C3=A9 The field name 'pos' gives the misleading impression that the QEMUFile objects are seekable. This is not the case, as in general we just have an opaque stream. The users of this method are only interested in the total bytes processed. This switches to a new name that reflects the intended usage. Every QIOChannel backed impl of QEMUFile is currently ignoring the 'pos' field. The only QEMUFile impl using 'pos' as an offset for I/O is the block device vmstate. A later patch is introducing a QIOChannel impl for the vmstate, and to handle this it is tracking a file offset itself internally to the QIOChannel impl. So when we later eliminate the QEMUFileOps callbacks later, the 'pos' field will no longer be used from any I/O read/write methods. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela Signed-off-by: Dr. David Alan Gilbert dgilbert: Fixed long line --- migration/qemu-file.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 03f0b13a55..eabc2d7c6e 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -50,8 +50,9 @@ struct QEMUFile { */ int64_t rate_limit_used; =20 - int64_t pos; /* start of buffer when writing, end of buffer - when reading */ + /* The sum of bytes transferred on the wire */ + int64_t total_transferred; + int buf_index; int buf_size; /* 0 when writing */ uint8_t buf[IO_BUF_SIZE]; @@ -241,14 +242,14 @@ void qemu_fflush(QEMUFile *f) } if (f->iovcnt > 0) { expect =3D iov_size(f->iov, f->iovcnt); - ret =3D f->ops->writev_buffer(f->opaque, f->iov, f->iovcnt, f->pos, - &local_error); + ret =3D f->ops->writev_buffer(f->opaque, f->iov, f->iovcnt, + f->total_transferred, &local_error); =20 qemu_iovec_release_ram(f); } =20 if (ret >=3D 0) { - f->pos +=3D ret; + f->total_transferred +=3D ret; } /* We expect the QEMUFile write impl to send the full * data set we requested, so sanity check that. @@ -357,11 +358,11 @@ static ssize_t qemu_fill_buffer(QEMUFile *f) return 0; } =20 - len =3D f->ops->get_buffer(f->opaque, f->buf + pending, f->pos, + len =3D f->ops->get_buffer(f->opaque, f->buf + pending, f->total_trans= ferred, IO_BUF_SIZE - pending, &local_error); if (len > 0) { f->buf_size +=3D len; - f->pos +=3D len; + f->total_transferred +=3D len; } else if (len =3D=3D 0) { qemu_file_set_error_obj(f, -EIO, local_error); } else if (len !=3D -EAGAIN) { @@ -375,7 +376,7 @@ static ssize_t qemu_fill_buffer(QEMUFile *f) =20 void qemu_update_position(QEMUFile *f, size_t size) { - f->pos +=3D size; + f->total_transferred +=3D size; } =20 /** Closes the file @@ -658,7 +659,7 @@ int qemu_get_byte(QEMUFile *f) =20 int64_t qemu_ftell_fast(QEMUFile *f) { - int64_t ret =3D f->pos; + int64_t ret =3D f->total_transferred; int i; =20 for (i =3D 0; i < f->iovcnt; i++) { @@ -671,7 +672,7 @@ int64_t qemu_ftell_fast(QEMUFile *f) int64_t qemu_ftell(QEMUFile *f) { qemu_fflush(f); - return f->pos; + return f->total_transferred; } =20 int qemu_file_rate_limit(QEMUFile *f) --=20 2.36.1 From nobody Tue May 21 14:34:03 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1655977250; cv=none; d=zohomail.com; s=zohoarc; b=LH4rZFYBumN778NDCXFlYcbuGncbmro4nKv7b+yK1REEVsDUteEE1u72ghgBgPkfcSJdwZ98iDi4GDgk9LgHugxIdprBZgAzGPwXLLfJjS4byx+tNwp1lLE4HytAoS41O6GPlNBOkTF3ZC13WqZRu7DojxxsJNNfm2YMjhCuB8s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655977250; h=Content-Type: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=6eHRitsnHgJFQROEy7UPRh0NmSvv+Aayd5UkWAWPSo0=; b=j5vo/kZ3dArqVWRA+VPE2Jcr5iUV5G5kS+SM91573ysyABR9a9LrRQbImlVFCOzQF4K7VDuJ2LkxtyUm+pOdDHcaKfH9yNlKG135//haxFNqULNICYrdroaJk3wd1AhRvOuJrFJnRFk70MILOLP6BKfd0U393Vf7tPaaQnf7rAE= 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 1655977250271822.7749286957305; Thu, 23 Jun 2022 02:40:50 -0700 (PDT) Received: from localhost ([::1]:56188 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o4JKS-0001AU-RV for importer@patchew.org; Thu, 23 Jun 2022 05:40:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45152) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8a-0000A4-2H for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:38147) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8Y-0004v2-9m for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:31 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-142-O5W2Ok3XOQuD6CQfNyEIyg-1; Thu, 23 Jun 2022 05:28:28 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2BBAE1C0519C; Thu, 23 Jun 2022 09:28:28 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.33.36.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id 324C940C141F; Thu, 23 Jun 2022 09:28:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655976509; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6eHRitsnHgJFQROEy7UPRh0NmSvv+Aayd5UkWAWPSo0=; b=J5FnYAEKpPzZK9xZrTYlFYv36WgfCRMhBJSzIGSEM0wnKC3xqgIdLdA3N3czOM9v2/wtD3 4DwVZ9CQMQaMuUHrEaW5UNvIDTiVL/IMd9ph6KjP63Dxlfkx89/raSvTP8s7eQISGPJXxi kNlcOm9lRh2aF0mxWWCCUp6AkKRpG3c= X-MC-Unique: O5W2Ok3XOQuD6CQfNyEIyg-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, huangy81@chinatelecom.cn, quintela@redhat.com, leobras@redhat.com, peterx@redhat.com Cc: jdenemar@redhat.com Subject: [PULL 10/33] migration: rename qemu_ftell to qemu_file_total_transferred Date: Thu, 23 Jun 2022 10:27:47 +0100 Message-Id: <20220623092810.96234-11-dgilbert@redhat.com> In-Reply-To: <20220623092810.96234-1-dgilbert@redhat.com> References: <20220623092810.96234-1-dgilbert@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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=170.10.133.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1655977250934100001 From: Daniel P. Berrang=C3=A9 The name 'ftell' gives the misleading impression that the QEMUFile objects are seekable. This is not the case, as in general we just have an opaque stream. The users of this method are only interested in the total bytes processed. This switches to a new name that reflects the intended usage. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela Signed-off-by: Dr. David Alan Gilbert dgilbert: Wrapped long line --- migration/block.c | 10 +++++----- migration/migration.c | 3 ++- migration/qemu-file.c | 4 ++-- migration/qemu-file.h | 33 +++++++++++++++++++++++++++++++-- migration/savevm.c | 6 +++--- migration/vmstate.c | 5 +++-- 6 files changed, 46 insertions(+), 15 deletions(-) diff --git a/migration/block.c b/migration/block.c index 077a413325..823453c977 100644 --- a/migration/block.c +++ b/migration/block.c @@ -756,8 +756,8 @@ static int block_save_setup(QEMUFile *f, void *opaque) static int block_save_iterate(QEMUFile *f, void *opaque) { int ret; - int64_t last_ftell =3D qemu_ftell(f); - int64_t delta_ftell; + int64_t last_bytes =3D qemu_file_total_transferred(f); + int64_t delta_bytes; =20 trace_migration_block_save("iterate", block_mig_state.submitted, block_mig_state.transferred); @@ -809,10 +809,10 @@ static int block_save_iterate(QEMUFile *f, void *opaq= ue) } =20 qemu_put_be64(f, BLK_MIG_FLAG_EOS); - delta_ftell =3D qemu_ftell(f) - last_ftell; - if (delta_ftell > 0) { + delta_bytes =3D qemu_file_total_transferred(f) - last_bytes; + if (delta_bytes > 0) { return 1; - } else if (delta_ftell < 0) { + } else if (delta_bytes < 0) { return -1; } else { return 0; diff --git a/migration/migration.c b/migration/migration.c index 5863af1b13..6d56eb1617 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -3539,7 +3539,8 @@ static MigThrError migration_detect_error(MigrationSt= ate *s) /* How many bytes have we transferred since the beginning of the migration= */ static uint64_t migration_total_bytes(MigrationState *s) { - return qemu_ftell(s->to_dst_file) + ram_counters.multifd_bytes; + return qemu_file_total_transferred(s->to_dst_file) + + ram_counters.multifd_bytes; } =20 static void migration_calculate_complete(MigrationState *s) diff --git a/migration/qemu-file.c b/migration/qemu-file.c index eabc2d7c6e..7ee9b5bf05 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -657,7 +657,7 @@ int qemu_get_byte(QEMUFile *f) return result; } =20 -int64_t qemu_ftell_fast(QEMUFile *f) +int64_t qemu_file_total_transferred_fast(QEMUFile *f) { int64_t ret =3D f->total_transferred; int i; @@ -669,7 +669,7 @@ int64_t qemu_ftell_fast(QEMUFile *f) return ret; } =20 -int64_t qemu_ftell(QEMUFile *f) +int64_t qemu_file_total_transferred(QEMUFile *f) { qemu_fflush(f); return f->total_transferred; diff --git a/migration/qemu-file.h b/migration/qemu-file.h index 3f36d4dc8c..05f6aef903 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -124,8 +124,37 @@ QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileO= ps *ops, bool has_ioc); void qemu_file_set_hooks(QEMUFile *f, const QEMUFileHooks *hooks); int qemu_get_fd(QEMUFile *f); int qemu_fclose(QEMUFile *f); -int64_t qemu_ftell(QEMUFile *f); -int64_t qemu_ftell_fast(QEMUFile *f); + +/* + * qemu_file_total_transferred: + * + * Report the total number of bytes transferred with + * this file. + * + * For writable files, any pending buffers will be + * flushed, so the reported value will be equal to + * the number of bytes transferred on the wire. + * + * For readable files, the reported value will be + * equal to the number of bytes transferred on the + * wire. + * + * Returns: the total bytes transferred + */ +int64_t qemu_file_total_transferred(QEMUFile *f); + +/* + * qemu_file_total_transferred_fast: + * + * As qemu_file_total_transferred except for writable + * files, where no flush is performed and the reported + * amount will include the size of any queued buffers, + * on top of the amount actually transferred. + * + * Returns: the total bytes transferred and queued + */ +int64_t qemu_file_total_transferred_fast(QEMUFile *f); + /* * put_buffer without copying the buffer. * The buffer should be available till it is sent asynchronously. diff --git a/migration/savevm.c b/migration/savevm.c index d9076897b8..75d05f1a84 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -916,9 +916,9 @@ static void vmstate_save_old_style(QEMUFile *f, SaveSta= teEntry *se, { int64_t old_offset, size; =20 - old_offset =3D qemu_ftell_fast(f); + old_offset =3D qemu_file_total_transferred_fast(f); se->ops->save_state(f, se->opaque); - size =3D qemu_ftell_fast(f) - old_offset; + size =3D qemu_file_total_transferred_fast(f) - old_offset; =20 if (vmdesc) { json_writer_int64(vmdesc, "size", size); @@ -2887,7 +2887,7 @@ bool save_snapshot(const char *name, bool overwrite, = const char *vmstate, goto the_end; } ret =3D qemu_savevm_state(f, errp); - vm_state_size =3D qemu_ftell(f); + vm_state_size =3D qemu_file_total_transferred(f); ret2 =3D qemu_fclose(f); if (ret < 0) { goto the_end; diff --git a/migration/vmstate.c b/migration/vmstate.c index 36ae8b9e19..924494bda3 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -360,7 +360,7 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDesc= ription *vmsd, void *curr_elem =3D first_elem + size * i; =20 vmsd_desc_field_start(vmsd, vmdesc_loop, field, i, n_elems= ); - old_offset =3D qemu_ftell_fast(f); + old_offset =3D qemu_file_total_transferred_fast(f); if (field->flags & VMS_ARRAY_OF_POINTER) { assert(curr_elem); curr_elem =3D *(void **)curr_elem; @@ -390,7 +390,8 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDesc= ription *vmsd, return ret; } =20 - written_bytes =3D qemu_ftell_fast(f) - old_offset; + written_bytes =3D qemu_file_total_transferred_fast(f) - + old_offset; vmsd_desc_field_end(vmsd, vmdesc_loop, field, written_byte= s, i); =20 /* Compressed arrays only care about the first element */ --=20 2.36.1 From nobody Tue May 21 14:34:03 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1655978212; cv=none; d=zohomail.com; s=zohoarc; b=RYesG9BV9sNsdRzeCUaChndDSLEoth6GN4pfCdEpAxhrv3BHASz+oa1jv7zpSF2np7yNB0nI7o/We+i/0C410+dl2A5w1mDgfsTXVkrM+MoIW4pOygWO5HhwlPhjpXsZQaMjYV8T1L1c5TB894IcNJ7JZ+sJYQ9/Fc0WwFQE6SM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655978212; h=Content-Type: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=m8UIex5y8Cqbvlnm8bpbZVn/LSkleyC/SRlNKq6rkKA=; b=XLLfV1eKsG6/LrbvLfpTEtOD/q19n9roUsdVGumulkwZUrX0r2cs0rXwDRZXW8L3BVYx6uqVYDZFRpmBcHmeaYdwiOLRAoRuvzTEpFs3rWvapVnBgfNLDt+Ujo2gf74ZwsMFM3MFN9/BAKTOIesfISft9Ko+SGPTYf204C/E9PM= 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 1655978212058371.0325439870594; Thu, 23 Jun 2022 02:56:52 -0700 (PDT) Received: from localhost ([::1]:55194 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o4JZy-0003sp-R4 for importer@patchew.org; Thu, 23 Jun 2022 05:56:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45174) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8b-0000Dj-6i for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:37599) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8Z-0004vT-HB for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:32 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-230-YTBxYEySNOe_w__noHoSpg-1; Thu, 23 Jun 2022 05:28:29 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5A7D4101AA45; Thu, 23 Jun 2022 09:28:29 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.33.36.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5EB9B40D282F; Thu, 23 Jun 2022 09:28:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655976510; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m8UIex5y8Cqbvlnm8bpbZVn/LSkleyC/SRlNKq6rkKA=; b=cgdpm7Ll7po0WSY00zCZ6qY+6CMMmzkI/0HAw86PAb5VMtDmr4bJDAdUw088RunlLMB/5y cfeVO27zu5ZRk71SQlOI6UYVZOJzG4HEkFxKzEQqL+IhwQVJdipYP9dYvxAdSG5We884EX OsYwnGNJ9O6BqWr5kGMACAuzgpJxR0I= X-MC-Unique: YTBxYEySNOe_w__noHoSpg-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, huangy81@chinatelecom.cn, quintela@redhat.com, leobras@redhat.com, peterx@redhat.com Cc: jdenemar@redhat.com Subject: [PULL 11/33] migration: rename qemu_update_position to qemu_file_credit_transfer Date: Thu, 23 Jun 2022 10:27:48 +0100 Message-Id: <20220623092810.96234-12-dgilbert@redhat.com> In-Reply-To: <20220623092810.96234-1-dgilbert@redhat.com> References: <20220623092810.96234-1-dgilbert@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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=170.10.133.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1655978213701100001 From: Daniel P. Berrang=C3=A9 The qemu_update_position method name gives the misleading impression that it is changing the current file offset. Most of the files are just streams, however, so there's no concept of a file offset in the general case. What this method is actually used for is to report on the number of bytes that have been transferred out of band from the main I/O methods. This new name better reflects this purpose. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela Signed-off-by: Dr. David Alan Gilbert --- migration/qemu-file.c | 4 ++-- migration/qemu-file.h | 9 ++++++++- migration/ram.c | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 7ee9b5bf05..f73b010d39 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -319,7 +319,7 @@ size_t ram_control_save_page(QEMUFile *f, ram_addr_t bl= ock_offset, if (ret !=3D RAM_SAVE_CONTROL_DELAYED && ret !=3D RAM_SAVE_CONTROL_NOT_SUPP) { if (bytes_sent && *bytes_sent > 0) { - qemu_update_position(f, *bytes_sent); + qemu_file_credit_transfer(f, *bytes_sent); } else if (ret < 0) { qemu_file_set_error(f, ret); } @@ -374,7 +374,7 @@ static ssize_t qemu_fill_buffer(QEMUFile *f) return len; } =20 -void qemu_update_position(QEMUFile *f, size_t size) +void qemu_file_credit_transfer(QEMUFile *f, size_t size) { f->total_transferred +=3D size; } diff --git a/migration/qemu-file.h b/migration/qemu-file.h index 05f6aef903..d96f5f7118 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -179,7 +179,14 @@ int qemu_put_qemu_file(QEMUFile *f_des, QEMUFile *f_sr= c); */ int qemu_peek_byte(QEMUFile *f, int offset); void qemu_file_skip(QEMUFile *f, int size); -void qemu_update_position(QEMUFile *f, size_t size); +/* + * qemu_file_credit_transfer: + * + * Report on a number of bytes that have been transferred + * out of band from the main file object I/O methods. This + * accounting information tracks the total migration traffic. + */ +void qemu_file_credit_transfer(QEMUFile *f, size_t size); void qemu_file_reset_rate_limit(QEMUFile *f); void qemu_file_update_transfer(QEMUFile *f, int64_t len); void qemu_file_set_rate_limit(QEMUFile *f, int64_t new_rate); diff --git a/migration/ram.c b/migration/ram.c index 89082716d6..bf321e1e72 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2301,7 +2301,7 @@ void acct_update_position(QEMUFile *f, size_t size, b= ool zero) } else { ram_counters.normal +=3D pages; ram_transferred_add(size); - qemu_update_position(f, size); + qemu_file_credit_transfer(f, size); } } =20 --=20 2.36.1 From nobody Tue May 21 14:34:03 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1655979294; cv=none; d=zohomail.com; s=zohoarc; b=EI8iG4bLltEMv40T48363YW9Pz3sgbRA6FIcK47neBOWjU/nZAIYXF74+kZ8/T2imtJ0QjojP3nyRg7DudK/S8kaMYGu9KxXlJ1m3lt0pTLvKDtvGx5htQ5NX3wlFbNM3nl0yP6YtYwiVnR1Hl5bKFSiMIYdocW0S91VwFEVqVs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655979294; h=Content-Type: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=170leAerIFjUR6yD5dJrC36oYfcy+tu4n5q2dGrdkuI=; b=dpTWQLrBnmLdZv7qv1e2E8slwJCtC5CVLw3MUAPXkcw2i5Zd7+fnBzh1DiV+po+eReQsdG6B6FFRkPWBM1efamXjLmwi6nnP90KbMwyp2NKEnmt8E+55KRp9jpMEDMWqhqrkOC32hWbmuScrfKfK+AgOETBf+7y5DHSe4r3sK6U= 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 1655979294082601.5064596597678; Thu, 23 Jun 2022 03:14:54 -0700 (PDT) Received: from localhost ([::1]:56618 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o4JrQ-00084C-7l for importer@patchew.org; Thu, 23 Jun 2022 06:14:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45634) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J94-0000wx-UB for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:29:05 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:35129) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J92-00051i-MF for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:29:02 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-631-DSf3lGQDPvWD38shZOoJYg-1; Thu, 23 Jun 2022 05:28:30 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 86DEC1C051A0; Thu, 23 Jun 2022 09:28:30 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.33.36.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8D9EE40C1289; Thu, 23 Jun 2022 09:28:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655976540; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=170leAerIFjUR6yD5dJrC36oYfcy+tu4n5q2dGrdkuI=; b=GSCjEh/SlvCJo4X8/GzHqytwZHkzQnarz4H+j0zIdpywiNhUb9jrqsDrpIAA50Wn2SO8SM QswE8soMvVouZ+R84derl3hB29wNZsSaB1fS8NYBtTpdAl7yy9kXOILlJK2txWc3sur2lC kZ7i5wGYbNdH4u2SQK9RWnW98iTIvKM= X-MC-Unique: DSf3lGQDPvWD38shZOoJYg-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, huangy81@chinatelecom.cn, quintela@redhat.com, leobras@redhat.com, peterx@redhat.com Cc: jdenemar@redhat.com Subject: [PULL 12/33] migration: rename qemu_file_update_transfer to qemu_file_acct_rate_limit Date: Thu, 23 Jun 2022 10:27:49 +0100 Message-Id: <20220623092810.96234-13-dgilbert@redhat.com> In-Reply-To: <20220623092810.96234-1-dgilbert@redhat.com> References: <20220623092810.96234-1-dgilbert@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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=170.10.129.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1655979295907100001 From: Daniel P. Berrang=C3=A9 The qemu_file_update_transfer name doesn't give a clear guide on what its purpose is, and how it differs from the qemu_file_credit_transfer method. The latter is specifically for accumulating for total migration traffic, while the former is specifically for accounting in thue rate limit calculations. The new name give better guidance on its usage. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela Signed-off-by: Dr. David Alan Gilbert --- migration/multifd.c | 4 ++-- migration/qemu-file.c | 2 +- migration/qemu-file.h | 9 ++++++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index 9282ab6aa4..684c014c86 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -435,7 +435,7 @@ static int multifd_send_pages(QEMUFile *f) p->pages =3D pages; transferred =3D ((uint64_t) pages->num) * qemu_target_page_size() + p->packet_len; - qemu_file_update_transfer(f, transferred); + qemu_file_acct_rate_limit(f, transferred); ram_counters.multifd_bytes +=3D transferred; ram_counters.transferred +=3D transferred; qemu_mutex_unlock(&p->mutex); @@ -610,7 +610,7 @@ int multifd_send_sync_main(QEMUFile *f) p->packet_num =3D multifd_send_state->packet_num++; p->flags |=3D MULTIFD_FLAG_SYNC; p->pending_job++; - qemu_file_update_transfer(f, p->packet_len); + qemu_file_acct_rate_limit(f, p->packet_len); ram_counters.multifd_bytes +=3D p->packet_len; ram_counters.transferred +=3D p->packet_len; qemu_mutex_unlock(&p->mutex); diff --git a/migration/qemu-file.c b/migration/qemu-file.c index f73b010d39..7fe0d9fa30 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -704,7 +704,7 @@ void qemu_file_reset_rate_limit(QEMUFile *f) f->rate_limit_used =3D 0; } =20 -void qemu_file_update_transfer(QEMUFile *f, int64_t len) +void qemu_file_acct_rate_limit(QEMUFile *f, int64_t len) { f->rate_limit_used +=3D len; } diff --git a/migration/qemu-file.h b/migration/qemu-file.h index d96f5f7118..901f2cf697 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -188,7 +188,14 @@ void qemu_file_skip(QEMUFile *f, int size); */ void qemu_file_credit_transfer(QEMUFile *f, size_t size); void qemu_file_reset_rate_limit(QEMUFile *f); -void qemu_file_update_transfer(QEMUFile *f, int64_t len); +/* + * qemu_file_acct_rate_limit: + * + * Report on a number of bytes the have been transferred + * out of band from the main file object I/O methods, and + * need to be applied to the rate limiting calcuations + */ +void qemu_file_acct_rate_limit(QEMUFile *f, int64_t len); void qemu_file_set_rate_limit(QEMUFile *f, int64_t new_rate); int64_t qemu_file_get_rate_limit(QEMUFile *f); int qemu_file_get_error_obj(QEMUFile *f, Error **errp); --=20 2.36.1 From nobody Tue May 21 14:34:03 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1655978482; cv=none; d=zohomail.com; s=zohoarc; b=bKDrNvkUQWavIn85A8qDa2G9im2Lr0VMqy5Vb/LDxOOck+HGEvZss/bDExSEo5M4thnFCyPLBQOYSGecSC7bhQwQwOz2MeCguWaOf0WnAdg/PO9iiBDgMJbBQAskeMIlWP/fmmsPEwTEKgcb7K9+VJMlQHT6G+VzWRXPVTXZ/MA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655978482; h=Content-Type: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=PAwBV1YL1LWzP9JrUQ98wNX66ZCcF7sPb0rTrPU9N7s=; b=OuE2NKabdZ2kjex6baPZcQm+M6Lrit8yPRUHmBAdWwkisjlecx92rivb3eNMB4O8q1HhpMM4dg9tbI2pULq0g/D19ueRhIsSP/o8P+Dh0cGfjWx1/mdNBTGWywMvH+iMToPoRKHhKhu2HU/hNiZexL2b2dSPk8Ckhbejq0jxrvU= 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 1655978482472124.97639977788663; Thu, 23 Jun 2022 03:01:22 -0700 (PDT) Received: from localhost ([::1]:35348 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o4JeL-0001DE-BT for importer@patchew.org; Thu, 23 Jun 2022 06:01:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45256) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8i-0000Od-NX for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:33896) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8g-0004w5-EN for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:40 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-342-eGro03i2Pn6BtDEdLD7snQ-1; Thu, 23 Jun 2022 05:28:32 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0254C18E6C4A; Thu, 23 Jun 2022 09:28:32 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.33.36.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB0C140D282F; Thu, 23 Jun 2022 09:28:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655976515; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PAwBV1YL1LWzP9JrUQ98wNX66ZCcF7sPb0rTrPU9N7s=; b=CB/eMVu9IdqBZmaZr+OJRpjUiEltMKfHfmUVOgWHSaylfITgdQpbanzJ1ai2cA+IapRDhE Aov+OBNx4AvpWH94Gs6CyaVVIGG8BlpLEhxBVQB47QefVnkujUEQlo108kEgGSRlICcI4L EhM3+/MWTtDXNvZH1KjhFqv6jt3kePU= X-MC-Unique: eGro03i2Pn6BtDEdLD7snQ-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, huangy81@chinatelecom.cn, quintela@redhat.com, leobras@redhat.com, peterx@redhat.com Cc: jdenemar@redhat.com Subject: [PULL 13/33] migration: introduce a QIOChannel impl for BlockDriverState VMState Date: Thu, 23 Jun 2022 10:27:50 +0100 Message-Id: <20220623092810.96234-14-dgilbert@redhat.com> In-Reply-To: <20220623092810.96234-1-dgilbert@redhat.com> References: <20220623092810.96234-1-dgilbert@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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=170.10.133.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1655978483829100001 From: Daniel P. Berrang=C3=A9 Introduce a QIOChannelBlock class that exposes the BlockDriverState VMState region for I/O. This is kept in the migration/ directory rather than io/, to avoid a mutual dependancy between block/ <-> io/ directories. Also the VMState should only be used by the migration code. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela Signed-off-by: Dr. David Alan Gilbert dgilbert: Fixed coding style in qio_channel_block_close --- migration/channel-block.c | 195 ++++++++++++++++++++++++++++++++++++++ migration/channel-block.h | 59 ++++++++++++ migration/meson.build | 1 + 3 files changed, 255 insertions(+) create mode 100644 migration/channel-block.c create mode 100644 migration/channel-block.h diff --git a/migration/channel-block.c b/migration/channel-block.c new file mode 100644 index 0000000000..c55c8c93ce --- /dev/null +++ b/migration/channel-block.c @@ -0,0 +1,195 @@ +/* + * QEMU I/O channels block driver + * + * Copyright (c) 2022 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + * + */ + +#include "qemu/osdep.h" +#include "migration/channel-block.h" +#include "qapi/error.h" +#include "block/block.h" +#include "trace.h" + +QIOChannelBlock * +qio_channel_block_new(BlockDriverState *bs) +{ + QIOChannelBlock *ioc; + + ioc =3D QIO_CHANNEL_BLOCK(object_new(TYPE_QIO_CHANNEL_BLOCK)); + + bdrv_ref(bs); + ioc->bs =3D bs; + + return ioc; +} + + +static void +qio_channel_block_finalize(Object *obj) +{ + QIOChannelBlock *ioc =3D QIO_CHANNEL_BLOCK(obj); + + g_clear_pointer(&ioc->bs, bdrv_unref); +} + + +static ssize_t +qio_channel_block_readv(QIOChannel *ioc, + const struct iovec *iov, + size_t niov, + int **fds, + size_t *nfds, + Error **errp) +{ + QIOChannelBlock *bioc =3D QIO_CHANNEL_BLOCK(ioc); + QEMUIOVector qiov; + int ret; + + qemu_iovec_init_external(&qiov, (struct iovec *)iov, niov); + ret =3D bdrv_readv_vmstate(bioc->bs, &qiov, bioc->offset); + if (ret < 0) { + return ret; + } + + bioc->offset +=3D qiov.size; + return qiov.size; +} + + +static ssize_t +qio_channel_block_writev(QIOChannel *ioc, + const struct iovec *iov, + size_t niov, + int *fds, + size_t nfds, + int flags, + Error **errp) +{ + QIOChannelBlock *bioc =3D QIO_CHANNEL_BLOCK(ioc); + QEMUIOVector qiov; + int ret; + + qemu_iovec_init_external(&qiov, (struct iovec *)iov, niov); + ret =3D bdrv_writev_vmstate(bioc->bs, &qiov, bioc->offset); + if (ret < 0) { + return ret; + } + + bioc->offset +=3D qiov.size; + return qiov.size; +} + + +static int +qio_channel_block_set_blocking(QIOChannel *ioc, + bool enabled, + Error **errp) +{ + if (!enabled) { + error_setg(errp, "Non-blocking mode not supported for block device= s"); + return -1; + } + return 0; +} + + +static off_t +qio_channel_block_seek(QIOChannel *ioc, + off_t offset, + int whence, + Error **errp) +{ + QIOChannelBlock *bioc =3D QIO_CHANNEL_BLOCK(ioc); + + switch (whence) { + case SEEK_SET: + bioc->offset =3D offset; + break; + case SEEK_CUR: + bioc->offset +=3D whence; + break; + case SEEK_END: + error_setg(errp, "Size of VMstate region is unknown"); + return (off_t)-1; + default: + g_assert_not_reached(); + } + + return bioc->offset; +} + + +static int +qio_channel_block_close(QIOChannel *ioc, + Error **errp) +{ + QIOChannelBlock *bioc =3D QIO_CHANNEL_BLOCK(ioc); + int rv =3D bdrv_flush(bioc->bs); + + if (rv < 0) { + error_setg_errno(errp, -rv, + "Unable to flush VMState"); + return -1; + } + + g_clear_pointer(&bioc->bs, bdrv_unref); + bioc->offset =3D 0; + + return 0; +} + + +static void +qio_channel_block_set_aio_fd_handler(QIOChannel *ioc, + AioContext *ctx, + IOHandler *io_read, + IOHandler *io_write, + void *opaque) +{ + /* XXX anything we can do here ? */ +} + + +static void +qio_channel_block_class_init(ObjectClass *klass, + void *class_data G_GNUC_UNUSED) +{ + QIOChannelClass *ioc_klass =3D QIO_CHANNEL_CLASS(klass); + + ioc_klass->io_writev =3D qio_channel_block_writev; + ioc_klass->io_readv =3D qio_channel_block_readv; + ioc_klass->io_set_blocking =3D qio_channel_block_set_blocking; + ioc_klass->io_seek =3D qio_channel_block_seek; + ioc_klass->io_close =3D qio_channel_block_close; + ioc_klass->io_set_aio_fd_handler =3D qio_channel_block_set_aio_fd_hand= ler; +} + +static const TypeInfo qio_channel_block_info =3D { + .parent =3D TYPE_QIO_CHANNEL, + .name =3D TYPE_QIO_CHANNEL_BLOCK, + .instance_size =3D sizeof(QIOChannelBlock), + .instance_finalize =3D qio_channel_block_finalize, + .class_init =3D qio_channel_block_class_init, +}; + +static void +qio_channel_block_register_types(void) +{ + type_register_static(&qio_channel_block_info); +} + +type_init(qio_channel_block_register_types); diff --git a/migration/channel-block.h b/migration/channel-block.h new file mode 100644 index 0000000000..31673824e6 --- /dev/null +++ b/migration/channel-block.h @@ -0,0 +1,59 @@ +/* + * QEMU I/O channels block driver + * + * Copyright (c) 2022 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + * + */ + +#ifndef QIO_CHANNEL_BLOCK_H +#define QIO_CHANNEL_BLOCK_H + +#include "io/channel.h" +#include "qom/object.h" + +#define TYPE_QIO_CHANNEL_BLOCK "qio-channel-block" +OBJECT_DECLARE_SIMPLE_TYPE(QIOChannelBlock, QIO_CHANNEL_BLOCK) + + +/** + * QIOChannelBlock: + * + * The QIOChannelBlock object provides a channel implementation + * that is able to perform I/O on the BlockDriverState objects + * to the VMState region. + */ + +struct QIOChannelBlock { + QIOChannel parent; + BlockDriverState *bs; + off_t offset; +}; + + +/** + * qio_channel_block_new: + * @bs: the block driver state + * + * Create a new IO channel object that can perform + * I/O on a BlockDriverState object to the VMState + * region + * + * Returns: the new channel object + */ +QIOChannelBlock * +qio_channel_block_new(BlockDriverState *bs); + +#endif /* QIO_CHANNEL_BLOCK_H */ diff --git a/migration/meson.build b/migration/meson.build index 6880b61b10..8d309f5849 100644 --- a/migration/meson.build +++ b/migration/meson.build @@ -13,6 +13,7 @@ softmmu_ss.add(migration_files) softmmu_ss.add(files( 'block-dirty-bitmap.c', 'channel.c', + 'channel-block.c', 'colo-failover.c', 'colo.c', 'exec.c', --=20 2.36.1 From nobody Tue May 21 14:34:03 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1655977350; cv=none; d=zohomail.com; s=zohoarc; b=Gr7PaB6DBgAZ0FbB7EYf004srR6K0dyIn3xS6lKH8NQB5eTqmMiPQigFpRQRV3bn5EY3iS/Lw4ondw1/t3lrC55SL9aDnAhchNpdSDeykjY10mp8b+K/mrR9e4xmj+2gUNmBy2HIFmMVuxh5VgCzX2xNVCZU57PhPezqhe4oEXo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655977350; h=Content-Type: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=wWMFylKVndR7Tbpxqd79fyCmIaxCGg+0VgMXEPxlDvk=; b=EIhvHaeUtCM3fM33eJE81QQbbaQEseouvH6GSrDWEykVcOYm3cG3FQLGunxLJKWJzG82CAaU8p/tGl8xD+W+apUjOS2PkPkG6NsgK00Vb2HlQXYaSG+azNBjtWZFP53IMY1H9ES+mSpaDyU3/AVJTiJLctz1jtQcDOSkbD7EZW8= 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 1655977350625273.55208679258556; Thu, 23 Jun 2022 02:42:30 -0700 (PDT) Received: from localhost ([::1]:59402 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o4JM5-0003Sx-Io for importer@patchew.org; Thu, 23 Jun 2022 05:42:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45242) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8i-0000NI-7W for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:40087) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8g-0004wE-FF for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:39 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-615-pBY-lOWyOKWlg8mchwCUTg-1; Thu, 23 Jun 2022 05:28:33 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2F6D329ABA1B; Thu, 23 Jun 2022 09:28:33 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.33.36.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id 34ACE404E4DC; Thu, 23 Jun 2022 09:28:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655976516; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wWMFylKVndR7Tbpxqd79fyCmIaxCGg+0VgMXEPxlDvk=; b=DDTo6VMHNftufdk5IIrK4cfFYde54Xet4HM+UeJEHvde8xDGpOPlihj+4tsKj2gdcqw82I qcH7aIgPRyfRi3g/jI1eBvcC1+/2VdVO6HbZHlJMQHYp2OnnB8Eu4RCIqy4mb6hnvEWCmA 19Kq/vb4+JSbM13vbqEHYBgWMFKUcx4= X-MC-Unique: pBY-lOWyOKWlg8mchwCUTg-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, huangy81@chinatelecom.cn, quintela@redhat.com, leobras@redhat.com, peterx@redhat.com Cc: jdenemar@redhat.com Subject: [PULL 14/33] migration: convert savevm to use QIOChannelBlock for VMState Date: Thu, 23 Jun 2022 10:27:51 +0100 Message-Id: <20220623092810.96234-15-dgilbert@redhat.com> In-Reply-To: <20220623092810.96234-1-dgilbert@redhat.com> References: <20220623092810.96234-1-dgilbert@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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=170.10.129.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1655977351170100001 From: Daniel P. Berrang=C3=A9 With this change, all QEMUFile usage is backed by QIOChannel at last. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela Signed-off-by: Dr. David Alan Gilbert dgilbert: Wrap long lines --- migration/savevm.c | 44 ++++++-------------------------------------- 1 file changed, 6 insertions(+), 38 deletions(-) diff --git a/migration/savevm.c b/migration/savevm.c index 75d05f1a84..3e9612121a 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -35,6 +35,7 @@ #include "migration/misc.h" #include "migration/register.h" #include "migration/global_state.h" +#include "migration/channel-block.h" #include "ram.h" #include "qemu-file-channel.h" #include "qemu-file.h" @@ -130,48 +131,15 @@ static struct mig_cmd_args { /***********************************************************/ /* savevm/loadvm support */ =20 -static ssize_t block_writev_buffer(void *opaque, struct iovec *iov, int io= vcnt, - int64_t pos, Error **errp) -{ - int ret; - QEMUIOVector qiov; - - qemu_iovec_init_external(&qiov, iov, iovcnt); - ret =3D bdrv_writev_vmstate(opaque, &qiov, pos); - if (ret < 0) { - return ret; - } - - return qiov.size; -} - -static ssize_t block_get_buffer(void *opaque, uint8_t *buf, int64_t pos, - size_t size, Error **errp) -{ - return bdrv_load_vmstate(opaque, buf, pos, size); -} - -static int bdrv_fclose(void *opaque, Error **errp) -{ - return bdrv_flush(opaque); -} - -static const QEMUFileOps bdrv_read_ops =3D { - .get_buffer =3D block_get_buffer, - .close =3D bdrv_fclose -}; - -static const QEMUFileOps bdrv_write_ops =3D { - .writev_buffer =3D block_writev_buffer, - .close =3D bdrv_fclose -}; - static QEMUFile *qemu_fopen_bdrv(BlockDriverState *bs, int is_writable) { if (is_writable) { - return qemu_fopen_ops(bs, &bdrv_write_ops, false); + return qemu_fopen_channel_output( + QIO_CHANNEL(qio_channel_block_new(bs))); + } else { + return qemu_fopen_channel_input( + QIO_CHANNEL(qio_channel_block_new(bs))); } - return qemu_fopen_ops(bs, &bdrv_read_ops, false); } =20 =20 --=20 2.36.1 From nobody Tue May 21 14:34:03 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1655977644; cv=none; d=zohomail.com; s=zohoarc; b=nFuPaB4H9HAkQP5N3vsuJFOhy7aCe3Dy3cM1xmwP9+99fHzp32MIVUxUGVddlpHH2KRXVxkFnzc3i8kuSH2E5hHUtY2s87YG/XO4HWvbVOQPN8AxFjp1efy+H+HZSk9xvHAutu8nIa4lpoktWfJuvDS4w8X9WReGopxz/K3zm4c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655977644; h=Content-Type: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=P8V7dCUpeQLsYbg+OAsasprIVrbyy53etlHxIkXU1gw=; b=etg+m4lR6wTkSKP8HU560OHikGeVdiv+LQZaJzTgSvKMBKXTLL1CZoQr/HxsTV93Ba9jluw4K78X8kBmG35IE3xoFnrH+AIB/MwHZA1Fkg/+ZLU5SH3BGyqyH3ec3trVjK7DMIOHow1+ICLEiliBWsz2b7hrzmSxHy5l29D93gs= 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 1655977644680844.752359487422; Thu, 23 Jun 2022 02:47:24 -0700 (PDT) Received: from localhost ([::1]:39072 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o4JQp-0000lT-Iy for importer@patchew.org; Thu, 23 Jun 2022 05:47:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45332) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8k-0000Sv-L9 for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:56448) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8h-0004wi-Bw for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:42 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-370-3mDtFI80OESP3fyuVC23QQ-1; Thu, 23 Jun 2022 05:28:34 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5D63C3AF42AF; Thu, 23 Jun 2022 09:28:34 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.33.36.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id 638C840D282F; Thu, 23 Jun 2022 09:28:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655976518; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P8V7dCUpeQLsYbg+OAsasprIVrbyy53etlHxIkXU1gw=; b=G52xui2buHlcmKOcK32/Pa7HUQ+gx5PU4ejmW2cvm75EX+PnkisEto5mUOB3V2RtCvnW7i inhvlDXQPMMN0sSExl5xYErHZdoUdY1CtuoBSdYJorMHibt/ivC3V+XaPnAXnYu5Sl9YwO 7N2GjK2Yo4NM9zCkMmxscG0dcKE6AR4= X-MC-Unique: 3mDtFI80OESP3fyuVC23QQ-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, huangy81@chinatelecom.cn, quintela@redhat.com, leobras@redhat.com, peterx@redhat.com Cc: jdenemar@redhat.com Subject: [PULL 15/33] migration: stop passing 'opaque' parameter to QEMUFile hooks Date: Thu, 23 Jun 2022 10:27:52 +0100 Message-Id: <20220623092810.96234-16-dgilbert@redhat.com> In-Reply-To: <20220623092810.96234-1-dgilbert@redhat.com> References: <20220623092810.96234-1-dgilbert@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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=170.10.133.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1655977645714100001 From: Daniel P. Berrang=C3=A9 The only user of the hooks is RDMA which provides a QIOChannel backed impl of QEMUFile. It can thus use the qemu_file_get_ioc() method. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela Signed-off-by: Dr. David Alan Gilbert --- migration/qemu-file.c | 8 ++++---- migration/qemu-file.h | 14 ++++++-------- migration/rdma.c | 19 ++++++++++--------- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 7fe0d9fa30..cdcb6e1788 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -266,7 +266,7 @@ void ram_control_before_iterate(QEMUFile *f, uint64_t f= lags) int ret =3D 0; =20 if (f->hooks && f->hooks->before_ram_iterate) { - ret =3D f->hooks->before_ram_iterate(f, f->opaque, flags, NULL); + ret =3D f->hooks->before_ram_iterate(f, flags, NULL); if (ret < 0) { qemu_file_set_error(f, ret); } @@ -278,7 +278,7 @@ void ram_control_after_iterate(QEMUFile *f, uint64_t fl= ags) int ret =3D 0; =20 if (f->hooks && f->hooks->after_ram_iterate) { - ret =3D f->hooks->after_ram_iterate(f, f->opaque, flags, NULL); + ret =3D f->hooks->after_ram_iterate(f, flags, NULL); if (ret < 0) { qemu_file_set_error(f, ret); } @@ -290,7 +290,7 @@ void ram_control_load_hook(QEMUFile *f, uint64_t flags,= void *data) int ret =3D -EINVAL; =20 if (f->hooks && f->hooks->hook_ram_load) { - ret =3D f->hooks->hook_ram_load(f, f->opaque, flags, data); + ret =3D f->hooks->hook_ram_load(f, flags, data); if (ret < 0) { qemu_file_set_error(f, ret); } @@ -310,7 +310,7 @@ size_t ram_control_save_page(QEMUFile *f, ram_addr_t bl= ock_offset, uint64_t *bytes_sent) { if (f->hooks && f->hooks->save_page) { - int ret =3D f->hooks->save_page(f, f->opaque, block_offset, + int ret =3D f->hooks->save_page(f, block_offset, offset, size, bytes_sent); if (ret !=3D RAM_SAVE_CONTROL_NOT_SUPP) { f->rate_limit_used +=3D size; diff --git a/migration/qemu-file.h b/migration/qemu-file.h index 901f2cf697..277f1d5a62 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -65,11 +65,9 @@ typedef ssize_t (QEMUFileWritevBufferFunc)(void *opaque,= struct iovec *iov, /* * This function provides hooks around different * stages of RAM migration. - * 'opaque' is the backend specific data in QEMUFile * 'data' is call specific data associated with the 'flags' value */ -typedef int (QEMURamHookFunc)(QEMUFile *f, void *opaque, uint64_t flags, - void *data); +typedef int (QEMURamHookFunc)(QEMUFile *f, uint64_t flags, void *data); =20 /* * Constants used by ram_control_* hooks @@ -84,11 +82,11 @@ typedef int (QEMURamHookFunc)(QEMUFile *f, void *opaque= , uint64_t flags, * This function allows override of where the RAM page * is saved (such as RDMA, for example.) */ -typedef size_t (QEMURamSaveFunc)(QEMUFile *f, void *opaque, - ram_addr_t block_offset, - ram_addr_t offset, - size_t size, - uint64_t *bytes_sent); +typedef size_t (QEMURamSaveFunc)(QEMUFile *f, + ram_addr_t block_offset, + ram_addr_t offset, + size_t size, + uint64_t *bytes_sent); =20 /* * Return a QEMUFile for comms in the opposite direction diff --git a/migration/rdma.c b/migration/rdma.c index c5fa4a408a..26a0cbbf40 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -3215,11 +3215,11 @@ qio_channel_rdma_shutdown(QIOChannel *ioc, * sent. Usually, this will not be more than a few bytes = of * the protocol because most transfers are sent asynchron= ously. */ -static size_t qemu_rdma_save_page(QEMUFile *f, void *opaque, +static size_t qemu_rdma_save_page(QEMUFile *f, ram_addr_t block_offset, ram_addr_t offs= et, size_t size, uint64_t *bytes_sent) { - QIOChannelRDMA *rioc =3D QIO_CHANNEL_RDMA(opaque); + QIOChannelRDMA *rioc =3D QIO_CHANNEL_RDMA(qemu_file_get_ioc(f)); RDMAContext *rdma; int ret; =20 @@ -3831,14 +3831,15 @@ rdma_block_notification_handle(QIOChannelRDMA *rioc= , const char *name) return 0; } =20 -static int rdma_load_hook(QEMUFile *f, void *opaque, uint64_t flags, void = *data) +static int rdma_load_hook(QEMUFile *f, uint64_t flags, void *data) { + QIOChannelRDMA *rioc =3D QIO_CHANNEL_RDMA(qemu_file_get_ioc(f)); switch (flags) { case RAM_CONTROL_BLOCK_REG: - return rdma_block_notification_handle(opaque, data); + return rdma_block_notification_handle(rioc, data); =20 case RAM_CONTROL_HOOK: - return qemu_rdma_registration_handle(f, opaque); + return qemu_rdma_registration_handle(f, rioc); =20 default: /* Shouldn't be called with any other values */ @@ -3846,10 +3847,10 @@ static int rdma_load_hook(QEMUFile *f, void *opaque= , uint64_t flags, void *data) } } =20 -static int qemu_rdma_registration_start(QEMUFile *f, void *opaque, +static int qemu_rdma_registration_start(QEMUFile *f, uint64_t flags, void *data) { - QIOChannelRDMA *rioc =3D QIO_CHANNEL_RDMA(opaque); + QIOChannelRDMA *rioc =3D QIO_CHANNEL_RDMA(qemu_file_get_ioc(f)); RDMAContext *rdma; =20 RCU_READ_LOCK_GUARD(); @@ -3875,10 +3876,10 @@ static int qemu_rdma_registration_start(QEMUFile *f= , void *opaque, * Inform dest that dynamic registrations are done for now. * First, flush writes, if any. */ -static int qemu_rdma_registration_stop(QEMUFile *f, void *opaque, +static int qemu_rdma_registration_stop(QEMUFile *f, uint64_t flags, void *data) { - QIOChannelRDMA *rioc =3D QIO_CHANNEL_RDMA(opaque); + QIOChannelRDMA *rioc =3D QIO_CHANNEL_RDMA(qemu_file_get_ioc(f)); RDMAContext *rdma; RDMAControlHeader head =3D { .len =3D 0, .repeat =3D 1 }; int ret =3D 0; --=20 2.36.1 From nobody Tue May 21 14:34:03 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1655979124; cv=none; d=zohomail.com; s=zohoarc; b=IKkZem2c6cBuaxqTR3KYK68lNtnc+0N0Cuo3NShGBR9y65JSr4Ee0Dk8pg9dcaZ21duDvKyTxwVQKl3LyjYN51NZbzz0u4pl9LKsEr9Y1hdoxctQ4UXbh7NQ6Gl4tpcaz6UEH5jha79vSlQ+IDk1/UKw/bDFA7TXasCln8RGA+E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655979124; h=Content-Type: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=cy2aE0ONl6TzmpKKKIFIhMcllMqaFaV5ep/oapj6t4o=; b=LsG3LFkCJXxbdkH98qpHXQktDTDXAUREIQtYC9EpEjnNZPanBXb0dr47+yPOZQ4zQL9FKJ4/R+6ZVCXyScarLrZ/7qdg7FZ3bjHCP/FpYR2kU6kDGWdzRUZ0UU3rkiICdVcvVSDflEE5OSD2352ZrvSvd8wPe+kIuZzzpcrrisU= 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 1655979124661578.8464496764205; Thu, 23 Jun 2022 03:12:04 -0700 (PDT) Received: from localhost ([::1]:52868 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o4Joh-0005IT-Hx for importer@patchew.org; Thu, 23 Jun 2022 06:12:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45304) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8j-0000QS-Rl for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:45853) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8g-0004wI-IG for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:41 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-402-Y2Yau3ruNxOV-g04l8VwQA-1; Thu, 23 Jun 2022 05:28:35 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8B2CC3C138B0; Thu, 23 Jun 2022 09:28:35 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.33.36.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id 90B4440C1289; Thu, 23 Jun 2022 09:28:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655976517; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cy2aE0ONl6TzmpKKKIFIhMcllMqaFaV5ep/oapj6t4o=; b=POb3jd3VRYMcziwh6arohwvl/bnu9GwBfXUKGrovaxf5oY/YYFlb1SrqbI69/BUooiZbI6 8+luApHNPArG6jvQs5xSRDlonikw46p8bweJIl/S9knvg/wBvQCaFk1hmWlOTOXtFsJfVf FCrXju3AfRJwHQTMGMWo5ZPQoUpWVxY= X-MC-Unique: Y2Yau3ruNxOV-g04l8VwQA-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, huangy81@chinatelecom.cn, quintela@redhat.com, leobras@redhat.com, peterx@redhat.com Cc: jdenemar@redhat.com Subject: [PULL 16/33] migration: hardcode assumption that QEMUFile is backed with QIOChannel Date: Thu, 23 Jun 2022 10:27:53 +0100 Message-Id: <20220623092810.96234-17-dgilbert@redhat.com> In-Reply-To: <20220623092810.96234-1-dgilbert@redhat.com> References: <20220623092810.96234-1-dgilbert@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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=170.10.133.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1655979126222100001 From: Daniel P. Berrang=C3=A9 The only callers of qemu_fopen_ops pass 'true' for the 'has_ioc' parameter, so hardcode this assumption in QEMUFile, by passing in the QIOChannel object as a non-opaque parameter. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela Signed-off-by: Dr. David Alan Gilbert dgilbert: Fixed long line --- migration/qemu-file-channel.c | 4 ++-- migration/qemu-file.c | 35 +++++++++++++++++------------------ migration/qemu-file.h | 2 +- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/migration/qemu-file-channel.c b/migration/qemu-file-channel.c index bb5a5752df..ce8eced417 100644 --- a/migration/qemu-file-channel.c +++ b/migration/qemu-file-channel.c @@ -184,11 +184,11 @@ static const QEMUFileOps channel_output_ops =3D { QEMUFile *qemu_fopen_channel_input(QIOChannel *ioc) { object_ref(OBJECT(ioc)); - return qemu_fopen_ops(ioc, &channel_input_ops, true); + return qemu_fopen_ops(ioc, &channel_input_ops); } =20 QEMUFile *qemu_fopen_channel_output(QIOChannel *ioc) { object_ref(OBJECT(ioc)); - return qemu_fopen_ops(ioc, &channel_output_ops, true); + return qemu_fopen_ops(ioc, &channel_output_ops); } diff --git a/migration/qemu-file.c b/migration/qemu-file.c index cdcb6e1788..30e2160041 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -37,7 +37,7 @@ struct QEMUFile { const QEMUFileOps *ops; const QEMUFileHooks *hooks; - void *opaque; + QIOChannel *ioc; =20 /* * Maximum amount of data in bytes to transfer during one @@ -65,8 +65,6 @@ struct QEMUFile { Error *last_error_obj; /* has the file has been shutdown */ bool shutdown; - /* Whether opaque points to a QIOChannel */ - bool has_ioc; }; =20 /* @@ -81,7 +79,7 @@ int qemu_file_shutdown(QEMUFile *f) if (!f->ops->shut_down) { return -ENOSYS; } - ret =3D f->ops->shut_down(f->opaque, true, true, NULL); + ret =3D f->ops->shut_down(f->ioc, true, true, NULL); =20 if (!f->last_error) { qemu_file_set_error(f, -EIO); @@ -98,7 +96,7 @@ QEMUFile *qemu_file_get_return_path(QEMUFile *f) if (!f->ops->get_return_path) { return NULL; } - return f->ops->get_return_path(f->opaque); + return f->ops->get_return_path(f->ioc); } =20 bool qemu_file_mode_is_not_valid(const char *mode) @@ -113,15 +111,15 @@ bool qemu_file_mode_is_not_valid(const char *mode) return false; } =20 -QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops, bool has_io= c) +QEMUFile *qemu_fopen_ops(QIOChannel *ioc, const QEMUFileOps *ops) { QEMUFile *f; =20 f =3D g_new0(QEMUFile, 1); =20 - f->opaque =3D opaque; + f->ioc =3D ioc; f->ops =3D ops; - f->has_ioc =3D has_ioc; + return f; } =20 @@ -242,7 +240,7 @@ void qemu_fflush(QEMUFile *f) } if (f->iovcnt > 0) { expect =3D iov_size(f->iov, f->iovcnt); - ret =3D f->ops->writev_buffer(f->opaque, f->iov, f->iovcnt, + ret =3D f->ops->writev_buffer(f->ioc, f->iov, f->iovcnt, f->total_transferred, &local_error); =20 qemu_iovec_release_ram(f); @@ -358,7 +356,7 @@ static ssize_t qemu_fill_buffer(QEMUFile *f) return 0; } =20 - len =3D f->ops->get_buffer(f->opaque, f->buf + pending, f->total_trans= ferred, + len =3D f->ops->get_buffer(f->ioc, f->buf + pending, f->total_transfer= red, IO_BUF_SIZE - pending, &local_error); if (len > 0) { f->buf_size +=3D len; @@ -394,7 +392,7 @@ int qemu_fclose(QEMUFile *f) ret =3D qemu_file_get_error(f); =20 if (f->ops->close) { - int ret2 =3D f->ops->close(f->opaque, NULL); + int ret2 =3D f->ops->close(f->ioc, NULL); if (ret >=3D 0) { ret =3D ret2; } @@ -861,18 +859,19 @@ void qemu_put_counted_string(QEMUFile *f, const char = *str) void qemu_file_set_blocking(QEMUFile *f, bool block) { if (f->ops->set_blocking) { - f->ops->set_blocking(f->opaque, block, NULL); + f->ops->set_blocking(f->ioc, block, NULL); } } =20 /* - * Return the ioc object if it's a migration channel. Note: it can return= NULL - * for callers passing in a non-migration qemufile. E.g. see qemu_fopen_b= drv() - * and its usage in e.g. load_snapshot(). So we need to check against NULL - * before using it. If without the check, migration_incoming_state_destro= y() - * could fail for load_snapshot(). + * qemu_file_get_ioc: + * + * Get the ioc object for the file, without incrementing + * the reference count. + * + * Returns: the ioc object */ QIOChannel *qemu_file_get_ioc(QEMUFile *file) { - return file->has_ioc ? QIO_CHANNEL(file->opaque) : NULL; + return file->ioc; } diff --git a/migration/qemu-file.h b/migration/qemu-file.h index 277f1d5a62..3a1ecc0e34 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -118,7 +118,7 @@ typedef struct QEMUFileHooks { QEMURamSaveFunc *save_page; } QEMUFileHooks; =20 -QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops, bool has_io= c); +QEMUFile *qemu_fopen_ops(QIOChannel *ioc, const QEMUFileOps *ops); void qemu_file_set_hooks(QEMUFile *f, const QEMUFileHooks *hooks); int qemu_get_fd(QEMUFile *f); int qemu_fclose(QEMUFile *f); --=20 2.36.1 From nobody Tue May 21 14:34:03 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1655977537; cv=none; d=zohomail.com; s=zohoarc; b=CHHK7Cudv/VhwlVuPbOdPBMUrJH7FxPsQp5ggO3s8VagXoar0dUdm88HotTPkgllhMfHNERLkUA1E9gq6QyX7kqaMnKsiTsYq4EMMHPl8bvulmdYzFS6Z6bODS+CTRnAyvugJje1MH9f+zpLjG+of+KNCZ9rKJqv7cap1Qnl3xk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655977537; h=Content-Type: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=vnuuJxp1JQdRXdU3c7OwH3ZR1JMW18zg+RAsQ+upqKY=; b=VdXbv+r/g8wXh8uSbmC2pI8FLDKJXuHDjCsWRwwvrZALomPZ16dSEjVKmAmU4cJoJo5D3uFPcF8UsXp2fzqkElPoTv45IPVaxo6/1dtWl18N5S6x9wZuj2joTm6FWUyXbs95HpeVGtQLveeUK+EMnJtnatNEuOHCldekziQJwC0= 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 1655977537439596.0046167780293; Thu, 23 Jun 2022 02:45:37 -0700 (PDT) Received: from localhost ([::1]:36800 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o4JP5-0007QH-O3 for importer@patchew.org; Thu, 23 Jun 2022 05:45:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45300) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8j-0000QQ-Oi for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:31238) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8h-0004wZ-1y for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:41 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-121-s61bWEEwNCy2U15KvIKfHA-1; Thu, 23 Jun 2022 05:28:37 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BA5A1804190; Thu, 23 Jun 2022 09:28:36 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.33.36.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id BCF4140D282F; Thu, 23 Jun 2022 09:28:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655976518; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vnuuJxp1JQdRXdU3c7OwH3ZR1JMW18zg+RAsQ+upqKY=; b=OUIFUgNwaIZWECqFM10AN3DRlz8jC1jlN8f7aUZ7LI6qAUFB7B7UR7gCXdn/AKRIqokPOq KW3Y29XoA5FbZs5YZJHyUsyKMzNcZ1ZxKjgOtHMuZElhrrJv5wph3orq6TuQ+wMK0wvcUb vt5M60z4WcdNGqWVZXICRtkZ57m1ISg= X-MC-Unique: s61bWEEwNCy2U15KvIKfHA-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, huangy81@chinatelecom.cn, quintela@redhat.com, leobras@redhat.com, peterx@redhat.com Cc: jdenemar@redhat.com Subject: [PULL 17/33] migration: introduce new constructors for QEMUFile Date: Thu, 23 Jun 2022 10:27:54 +0100 Message-Id: <20220623092810.96234-18-dgilbert@redhat.com> In-Reply-To: <20220623092810.96234-1-dgilbert@redhat.com> References: <20220623092810.96234-1-dgilbert@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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=170.10.129.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1655977539573100001 From: Daniel P. Berrang=C3=A9 Prepare for the elimination of QEMUFileOps by introducing a pair of new constructors. This lets us distinguish between an input and output file object explicitly rather than via the existance of specific callbacks. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela Signed-off-by: Dr. David Alan Gilbert --- migration/qemu-file-channel.c | 4 ++-- migration/qemu-file.c | 18 ++++++++++++++++-- migration/qemu-file.h | 3 ++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/migration/qemu-file-channel.c b/migration/qemu-file-channel.c index ce8eced417..5cb8ac93c0 100644 --- a/migration/qemu-file-channel.c +++ b/migration/qemu-file-channel.c @@ -184,11 +184,11 @@ static const QEMUFileOps channel_output_ops =3D { QEMUFile *qemu_fopen_channel_input(QIOChannel *ioc) { object_ref(OBJECT(ioc)); - return qemu_fopen_ops(ioc, &channel_input_ops); + return qemu_file_new_input(ioc, &channel_input_ops); } =20 QEMUFile *qemu_fopen_channel_output(QIOChannel *ioc) { object_ref(OBJECT(ioc)); - return qemu_fopen_ops(ioc, &channel_output_ops); + return qemu_file_new_output(ioc, &channel_output_ops); } diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 30e2160041..2d6ceb53af 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -38,6 +38,7 @@ struct QEMUFile { const QEMUFileOps *ops; const QEMUFileHooks *hooks; QIOChannel *ioc; + bool is_writable; =20 /* * Maximum amount of data in bytes to transfer during one @@ -111,7 +112,9 @@ bool qemu_file_mode_is_not_valid(const char *mode) return false; } =20 -QEMUFile *qemu_fopen_ops(QIOChannel *ioc, const QEMUFileOps *ops) +static QEMUFile *qemu_file_new_impl(QIOChannel *ioc, + const QEMUFileOps *ops, + bool is_writable) { QEMUFile *f; =20 @@ -119,10 +122,21 @@ QEMUFile *qemu_fopen_ops(QIOChannel *ioc, const QEMUF= ileOps *ops) =20 f->ioc =3D ioc; f->ops =3D ops; + f->is_writable =3D is_writable; =20 return f; } =20 +QEMUFile *qemu_file_new_output(QIOChannel *ioc, const QEMUFileOps *ops) +{ + return qemu_file_new_impl(ioc, ops, true); +} + +QEMUFile *qemu_file_new_input(QIOChannel *ioc, const QEMUFileOps *ops) +{ + return qemu_file_new_impl(ioc, ops, false); +} + =20 void qemu_file_set_hooks(QEMUFile *f, const QEMUFileHooks *hooks) { @@ -181,7 +195,7 @@ void qemu_file_set_error(QEMUFile *f, int ret) =20 bool qemu_file_is_writable(QEMUFile *f) { - return f->ops->writev_buffer; + return f->is_writable; } =20 static void qemu_iovec_release_ram(QEMUFile *f) diff --git a/migration/qemu-file.h b/migration/qemu-file.h index 3a1ecc0e34..3c93a27978 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -118,7 +118,8 @@ typedef struct QEMUFileHooks { QEMURamSaveFunc *save_page; } QEMUFileHooks; =20 -QEMUFile *qemu_fopen_ops(QIOChannel *ioc, const QEMUFileOps *ops); +QEMUFile *qemu_file_new_input(QIOChannel *ioc, const QEMUFileOps *ops); +QEMUFile *qemu_file_new_output(QIOChannel *ioc, const QEMUFileOps *ops); void qemu_file_set_hooks(QEMUFile *f, const QEMUFileHooks *hooks); int qemu_get_fd(QEMUFile *f); int qemu_fclose(QEMUFile *f); --=20 2.36.1 From nobody Tue May 21 14:34:03 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1655978050; cv=none; d=zohomail.com; s=zohoarc; b=bAP/IIycMCu7T0PlH15HZ42Mojkyb9a+yr9Ys1ReiCZZXUaDWVlMSHS75AwMmK+s31Ub4ZupTgwn1rJWBmKNrK3AqxyLn/OVre0Pzw8iJQY3GN0dgq161XKzbO2HB0j4f17WYE8I+WyKTreTsEwEIp29W2zSwN1knZwRYvo/klc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655978050; h=Content-Type: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=2kXETOHqNVN75aUkz1bPSP293e03Yqd4m5NMtIrkuf8=; b=Ek5+Hhh9LxyVA1lazlJom0UWUUBof52O8ASNpi0OblzazJsjdOTMczE6expsD0dzbm3prsz5fU/9GeFRzo8ro0cxqyi5LH8+3SuBHWuqB6CRgklwHn7fW1C0rVv2Lje6GxyyI/iDYIzQdJijIz8cRiCl/SC2lN5isHPBCj41eIk= 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 1655978050194205.97483616875581; Thu, 23 Jun 2022 02:54:10 -0700 (PDT) Received: from localhost ([::1]:47966 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o4JXN-0007Mt-5c for importer@patchew.org; Thu, 23 Jun 2022 05:54:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45334) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8k-0000T4-Ns for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:37575) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8h-0004ws-Ui for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:42 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-252-byuDsGv3PGO-830cOKgZ0w-1; Thu, 23 Jun 2022 05:28:38 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E78DC81D9EC; Thu, 23 Jun 2022 09:28:37 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.33.36.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id EC5FD40D282F; Thu, 23 Jun 2022 09:28:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655976519; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2kXETOHqNVN75aUkz1bPSP293e03Yqd4m5NMtIrkuf8=; b=WM+80fbapgnY1cheTYG2rWE1xMJgQ03KEuwSZe0gM/Qg887UbvgeePDJmF2wtNXLEZpDDA /gs7FEh2JkErxkmKdAh5k1iWykvsCJW0vGH+R03/l29fYiyWvdCLcHqzYkhF2UxmMwtkLZ HSK+W8d/goGpICCePowNO9SJNay0fJA= X-MC-Unique: byuDsGv3PGO-830cOKgZ0w-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, huangy81@chinatelecom.cn, quintela@redhat.com, leobras@redhat.com, peterx@redhat.com Cc: jdenemar@redhat.com Subject: [PULL 18/33] migration: remove unused QEMUFileGetFD typedef / qemu_get_fd method Date: Thu, 23 Jun 2022 10:27:55 +0100 Message-Id: <20220623092810.96234-19-dgilbert@redhat.com> In-Reply-To: <20220623092810.96234-1-dgilbert@redhat.com> References: <20220623092810.96234-1-dgilbert@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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=170.10.133.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1655978050631100003 From: Daniel P. Berrang=C3=A9 Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela Signed-off-by: Dr. David Alan Gilbert --- migration/qemu-file.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/migration/qemu-file.h b/migration/qemu-file.h index 3c93a27978..fe1b2d1c00 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -46,10 +46,6 @@ typedef ssize_t (QEMUFileGetBufferFunc)(void *opaque, ui= nt8_t *buf, */ typedef int (QEMUFileCloseFunc)(void *opaque, Error **errp); =20 -/* Called to return the OS file descriptor associated to the QEMUFile. - */ -typedef int (QEMUFileGetFD)(void *opaque); - /* Called to change the blocking mode of the file */ typedef int (QEMUFileSetBlocking)(void *opaque, bool enabled, Error **errp= ); @@ -121,7 +117,6 @@ typedef struct QEMUFileHooks { QEMUFile *qemu_file_new_input(QIOChannel *ioc, const QEMUFileOps *ops); QEMUFile *qemu_file_new_output(QIOChannel *ioc, const QEMUFileOps *ops); void qemu_file_set_hooks(QEMUFile *f, const QEMUFileHooks *hooks); -int qemu_get_fd(QEMUFile *f); int qemu_fclose(QEMUFile *f); =20 /* --=20 2.36.1 From nobody Tue May 21 14:34:03 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1655977987; cv=none; d=zohomail.com; s=zohoarc; b=UqCQiRsXhUqlWyQwYDwTr1T7S72eJ6Eiu3hPsu0EkWQtbEe67dj9wKoGaKMg5Yas1Ag663ijQVTNpM3azyf72UkugjR4luW1OJy1mVrbX1cIZJRMpNTXOwdXgvGijaWkFKSJd6H4Ci2X4xJQd8jD8VQuvv46Rz7aYD7gA1pVvmo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655977987; h=Content-Type: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=T1xN+11P1k1HT8e/kdMnxGNyNbGhYmDHd2rNAaVdSkY=; b=K5u6h4iBJ/JOEQI7hHy4+MzrHGk1RajenGF2I9w6/ZB7OD7nHe2CCTF4vi2GHI+29ZWhioDbiqSJCNK01hgfA+LwKkZfkZDEPcHKTh7LuRh1w/WYu4BgC3rwm3/d06F0kWP99zwRhuDKtLcFhAjmXOE8u2iBPf1WK8eKJJMlXGY= 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 1655977987659886.5343876698639; Thu, 23 Jun 2022 02:53:07 -0700 (PDT) Received: from localhost ([::1]:45216 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o4JWL-0005DO-5e for importer@patchew.org; Thu, 23 Jun 2022 05:53:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45340) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8l-0000Ue-7v for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:53511) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8j-0004xJ-C6 for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:42 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-245-KnMAECdLNc63aUTrsuuKRQ-1; Thu, 23 Jun 2022 05:28:39 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 24D96101E989; Thu, 23 Jun 2022 09:28:39 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.33.36.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id 27BBE40D2962; Thu, 23 Jun 2022 09:28:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655976520; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T1xN+11P1k1HT8e/kdMnxGNyNbGhYmDHd2rNAaVdSkY=; b=jKqMF1UQaPjjmm5eYZhxuf28MY8m6jG1Cf5EBmf7xKEK+CHbd3yprHBnqeSoIGcDgVQ+pr t3FcLh9THJ3OO056kxaBeT5G4QLcKSuu/BEdWz/vJe6mnX80hIq06BvySKNZb5d+8qC9ET SWq8ShDZVsz2LR59dmmPzUfu+flPB5s= X-MC-Unique: KnMAECdLNc63aUTrsuuKRQ-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, huangy81@chinatelecom.cn, quintela@redhat.com, leobras@redhat.com, peterx@redhat.com Cc: jdenemar@redhat.com Subject: [PULL 19/33] migration: remove the QEMUFileOps 'shut_down' callback Date: Thu, 23 Jun 2022 10:27:56 +0100 Message-Id: <20220623092810.96234-20-dgilbert@redhat.com> In-Reply-To: <20220623092810.96234-1-dgilbert@redhat.com> References: <20220623092810.96234-1-dgilbert@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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=170.10.129.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1655977990712100001 From: Daniel P. Berrang=C3=A9 This directly implements the shutdown logic using QIOChannel APIs. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela Signed-off-by: Dr. David Alan Gilbert --- migration/qemu-file-channel.c | 27 --------------------------- migration/qemu-file.c | 13 ++++++++++--- migration/qemu-file.h | 10 ---------- 3 files changed, 10 insertions(+), 40 deletions(-) diff --git a/migration/qemu-file-channel.c b/migration/qemu-file-channel.c index 5cb8ac93c0..80f05dc371 100644 --- a/migration/qemu-file-channel.c +++ b/migration/qemu-file-channel.c @@ -112,31 +112,6 @@ static int channel_close(void *opaque, Error **errp) } =20 =20 -static int channel_shutdown(void *opaque, - bool rd, - bool wr, - Error **errp) -{ - QIOChannel *ioc =3D QIO_CHANNEL(opaque); - - if (qio_channel_has_feature(ioc, - QIO_CHANNEL_FEATURE_SHUTDOWN)) { - QIOChannelShutdown mode; - if (rd && wr) { - mode =3D QIO_CHANNEL_SHUTDOWN_BOTH; - } else if (rd) { - mode =3D QIO_CHANNEL_SHUTDOWN_READ; - } else { - mode =3D QIO_CHANNEL_SHUTDOWN_WRITE; - } - if (qio_channel_shutdown(ioc, mode, errp) < 0) { - return -EIO; - } - } - return 0; -} - - static int channel_set_blocking(void *opaque, bool enabled, Error **errp) @@ -166,7 +141,6 @@ static QEMUFile *channel_get_output_return_path(void *o= paque) static const QEMUFileOps channel_input_ops =3D { .get_buffer =3D channel_get_buffer, .close =3D channel_close, - .shut_down =3D channel_shutdown, .set_blocking =3D channel_set_blocking, .get_return_path =3D channel_get_input_return_path, }; @@ -175,7 +149,6 @@ static const QEMUFileOps channel_input_ops =3D { static const QEMUFileOps channel_output_ops =3D { .writev_buffer =3D channel_writev_buffer, .close =3D channel_close, - .shut_down =3D channel_shutdown, .set_blocking =3D channel_set_blocking, .get_return_path =3D channel_get_output_return_path, }; diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 2d6ceb53af..d71bcb6c9c 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -71,16 +71,23 @@ struct QEMUFile { /* * Stop a file from being read/written - not all backing files can do this * typically only sockets can. + * + * TODO: convert to propagate Error objects instead of squashing + * to a fixed errno value */ int qemu_file_shutdown(QEMUFile *f) { - int ret; + int ret =3D 0; =20 f->shutdown =3D true; - if (!f->ops->shut_down) { + if (!qio_channel_has_feature(f->ioc, + QIO_CHANNEL_FEATURE_SHUTDOWN)) { return -ENOSYS; } - ret =3D f->ops->shut_down(f->ioc, true, true, NULL); + + if (qio_channel_shutdown(f->ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL) < 0)= { + ret =3D -EIO; + } =20 if (!f->last_error) { qemu_file_set_error(f, -EIO); diff --git a/migration/qemu-file.h b/migration/qemu-file.h index fe1b2d1c00..9fa92c1998 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -89,22 +89,12 @@ typedef size_t (QEMURamSaveFunc)(QEMUFile *f, */ typedef QEMUFile *(QEMURetPathFunc)(void *opaque); =20 -/* - * Stop any read or write (depending on flags) on the underlying - * transport on the QEMUFile. - * Existing blocking reads/writes must be woken - * Returns 0 on success, -err on error - */ -typedef int (QEMUFileShutdownFunc)(void *opaque, bool rd, bool wr, - Error **errp); - typedef struct QEMUFileOps { QEMUFileGetBufferFunc *get_buffer; QEMUFileCloseFunc *close; QEMUFileSetBlocking *set_blocking; QEMUFileWritevBufferFunc *writev_buffer; QEMURetPathFunc *get_return_path; - QEMUFileShutdownFunc *shut_down; } QEMUFileOps; =20 typedef struct QEMUFileHooks { --=20 2.36.1 From nobody Tue May 21 14:34:03 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1655978115; cv=none; d=zohomail.com; s=zohoarc; b=SPSEZJrBl9wKVFDrBWNtiOi9gMuVzQ7OjGRcOkN/9rfcTaEejjjPkldWurf6SlxPRarZnNZsn7blxYhdbAnmVKNVooCgsZ6CEgNa3PP1skDstxeihmRcElZaCdaaJ8Ox1GsmE81yBoF0nhuq8m2NK7JyHxMnEgVzJRdNtus5NFY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655978115; h=Content-Type: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=4axUKHaIIzvzWlrJsA5rLvfS1C75sXnDRQj3DDCmvRE=; b=OOH/PEjrM8wJITtkMLQOkAlfMRmzej9VKx9DyMzqAPOScqrxb4n9GkEwKJ1g3XtpaM0brIDCt8VxwwG31jFjY99NRsICfBncvlGgL+Cdk4hCw6pZOeIb4U53g9s35UaReLcXKAW4wCeoc9oTt2FGK769VDNJXKqhhTJkh8pGqyM= 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 1655978115055669.2242940620287; Thu, 23 Jun 2022 02:55:15 -0700 (PDT) Received: from localhost ([::1]:50106 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o4JYQ-0000Ou-1r for importer@patchew.org; Thu, 23 Jun 2022 05:55:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45410) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8p-0000d1-2z for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:52310) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8m-0004yS-Hn for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:46 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-314-NhCv1j5cMcCKJ4sAVa6R1Q-1; Thu, 23 Jun 2022 05:28:40 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 55F9C1C05199; Thu, 23 Jun 2022 09:28:40 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.33.36.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id 57068404E4DC; Thu, 23 Jun 2022 09:28:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655976524; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4axUKHaIIzvzWlrJsA5rLvfS1C75sXnDRQj3DDCmvRE=; b=ffrXaP2YAkgYoU6gu7MOr/e+q2cJJNg98H7HyNJjJjI4iTudOtjhMehZuIxr4lT+VAbLOs oV4NbKIJuV3bl3RvF9nfc4xRr8ZNQbT/g3s4/Yh5hekj0dFL65ZZez2jcy4NVKVluNh6D+ 0ViVvGSATG1nzkqB6n+4jEbFXZ+7yQo= X-MC-Unique: NhCv1j5cMcCKJ4sAVa6R1Q-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, huangy81@chinatelecom.cn, quintela@redhat.com, leobras@redhat.com, peterx@redhat.com Cc: jdenemar@redhat.com Subject: [PULL 20/33] migration: remove the QEMUFileOps 'set_blocking' callback Date: Thu, 23 Jun 2022 10:27:57 +0100 Message-Id: <20220623092810.96234-21-dgilbert@redhat.com> In-Reply-To: <20220623092810.96234-1-dgilbert@redhat.com> References: <20220623092810.96234-1-dgilbert@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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=170.10.133.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1655978116985100001 From: Daniel P. Berrang=C3=A9 This directly implements the set_blocking logic using QIOChannel APIs. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela Signed-off-by: Dr. David Alan Gilbert --- migration/qemu-file-channel.c | 14 -------------- migration/qemu-file.c | 4 +--- migration/qemu-file.h | 5 ----- 3 files changed, 1 insertion(+), 22 deletions(-) diff --git a/migration/qemu-file-channel.c b/migration/qemu-file-channel.c index 80f05dc371..0350d367ec 100644 --- a/migration/qemu-file-channel.c +++ b/migration/qemu-file-channel.c @@ -112,18 +112,6 @@ static int channel_close(void *opaque, Error **errp) } =20 =20 -static int channel_set_blocking(void *opaque, - bool enabled, - Error **errp) -{ - QIOChannel *ioc =3D QIO_CHANNEL(opaque); - - if (qio_channel_set_blocking(ioc, enabled, errp) < 0) { - return -1; - } - return 0; -} - static QEMUFile *channel_get_input_return_path(void *opaque) { QIOChannel *ioc =3D QIO_CHANNEL(opaque); @@ -141,7 +129,6 @@ static QEMUFile *channel_get_output_return_path(void *o= paque) static const QEMUFileOps channel_input_ops =3D { .get_buffer =3D channel_get_buffer, .close =3D channel_close, - .set_blocking =3D channel_set_blocking, .get_return_path =3D channel_get_input_return_path, }; =20 @@ -149,7 +136,6 @@ static const QEMUFileOps channel_input_ops =3D { static const QEMUFileOps channel_output_ops =3D { .writev_buffer =3D channel_writev_buffer, .close =3D channel_close, - .set_blocking =3D channel_set_blocking, .get_return_path =3D channel_get_output_return_path, }; =20 diff --git a/migration/qemu-file.c b/migration/qemu-file.c index d71bcb6c9c..95d5db9dd6 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -879,9 +879,7 @@ void qemu_put_counted_string(QEMUFile *f, const char *s= tr) */ void qemu_file_set_blocking(QEMUFile *f, bool block) { - if (f->ops->set_blocking) { - f->ops->set_blocking(f->ioc, block, NULL); - } + qio_channel_set_blocking(f->ioc, block, NULL); } =20 /* diff --git a/migration/qemu-file.h b/migration/qemu-file.h index 9fa92c1998..7793e765f2 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -46,10 +46,6 @@ typedef ssize_t (QEMUFileGetBufferFunc)(void *opaque, ui= nt8_t *buf, */ typedef int (QEMUFileCloseFunc)(void *opaque, Error **errp); =20 -/* Called to change the blocking mode of the file - */ -typedef int (QEMUFileSetBlocking)(void *opaque, bool enabled, Error **errp= ); - /* * This function writes an iovec to file. The handler must write all * of the data or return a negative errno value. @@ -92,7 +88,6 @@ typedef QEMUFile *(QEMURetPathFunc)(void *opaque); typedef struct QEMUFileOps { QEMUFileGetBufferFunc *get_buffer; QEMUFileCloseFunc *close; - QEMUFileSetBlocking *set_blocking; QEMUFileWritevBufferFunc *writev_buffer; QEMURetPathFunc *get_return_path; } QEMUFileOps; --=20 2.36.1 From nobody Tue May 21 14:34:03 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1655978272; cv=none; d=zohomail.com; s=zohoarc; b=aCSWZRBOZ2DppksQepb6azrNA6K+2oPFJH+dRMTM9upq2JbdTV+exuVDKUZ71tJrtfW4Eey0TC/uKw8cQH/IcAcbcRWEfX6BDz1KuaiffaMCC+FS53aq6vvoMZFffWHSNP3AFNKiByTZNRxVp4oeZ8KUJBtqp/3Rbk9voUw9CI0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655978272; h=Content-Type: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=kMPs2KvboerixWQ6VgPW6t5bFVTnKyfTuZpNQNy0GIU=; b=jGyVyQY52NhrE9dLdEL52/TFwNnwECR9KdW5NlUGq725XI90JtbUesENY8TSCnY6T3L1U3flvqQTkGe87gkVAKfPopOhvdl3rPlOWotZ6VZv5RbuqzAixHBhRO66fw5Em9R4pW0T7Vgst9xccTq7DTwSWjSIPKqpuisyJBsG0NE= 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 1655978272187694.0020473295608; Thu, 23 Jun 2022 02:57:52 -0700 (PDT) Received: from localhost ([::1]:56544 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o4Jax-0004mG-2Y for importer@patchew.org; Thu, 23 Jun 2022 05:57:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45376) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8n-0000aY-Gm for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:31347) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8l-0004yG-Qz for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:45 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-394-DgWMUJ7jNfmLd6WvTf7Vqw-1; Thu, 23 Jun 2022 05:28:41 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8ABAA81D9CC; Thu, 23 Jun 2022 09:28:41 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.33.36.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id 88D8D404E4DC; Thu, 23 Jun 2022 09:28:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655976523; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kMPs2KvboerixWQ6VgPW6t5bFVTnKyfTuZpNQNy0GIU=; b=JBtZrGhhigJ+QCmJkC92bOBgXKShqOEkeoHkrltqdi6b+zR29d0fbeXqoRODIy31UrK07p joECjFSgruvQ00cPyAzFlUYc2sQUq/mVjdEFsHFFCPSzwAZjYh0l10dMrnSqGMo1KQd71p aqZvaLIJh3qPFsPotUzlDGyhx8nXPg0= X-MC-Unique: DgWMUJ7jNfmLd6WvTf7Vqw-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, huangy81@chinatelecom.cn, quintela@redhat.com, leobras@redhat.com, peterx@redhat.com Cc: jdenemar@redhat.com Subject: [PULL 21/33] migration: remove the QEMUFileOps 'close' callback Date: Thu, 23 Jun 2022 10:27:58 +0100 Message-Id: <20220623092810.96234-22-dgilbert@redhat.com> In-Reply-To: <20220623092810.96234-1-dgilbert@redhat.com> References: <20220623092810.96234-1-dgilbert@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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=170.10.133.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1655978274062100001 From: Daniel P. Berrang=C3=A9 This directly implements the close logic using QIOChannel APIs. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela Signed-off-by: Dr. David Alan Gilbert --- migration/qemu-file-channel.c | 12 ------------ migration/qemu-file.c | 12 ++++++------ migration/qemu-file.h | 10 ---------- 3 files changed, 6 insertions(+), 28 deletions(-) diff --git a/migration/qemu-file-channel.c b/migration/qemu-file-channel.c index 0350d367ec..8ff58e81f9 100644 --- a/migration/qemu-file-channel.c +++ b/migration/qemu-file-channel.c @@ -102,16 +102,6 @@ static ssize_t channel_get_buffer(void *opaque, } =20 =20 -static int channel_close(void *opaque, Error **errp) -{ - int ret; - QIOChannel *ioc =3D QIO_CHANNEL(opaque); - ret =3D qio_channel_close(ioc, errp); - object_unref(OBJECT(ioc)); - return ret; -} - - static QEMUFile *channel_get_input_return_path(void *opaque) { QIOChannel *ioc =3D QIO_CHANNEL(opaque); @@ -128,14 +118,12 @@ static QEMUFile *channel_get_output_return_path(void = *opaque) =20 static const QEMUFileOps channel_input_ops =3D { .get_buffer =3D channel_get_buffer, - .close =3D channel_close, .get_return_path =3D channel_get_input_return_path, }; =20 =20 static const QEMUFileOps channel_output_ops =3D { .writev_buffer =3D channel_writev_buffer, - .close =3D channel_close, .get_return_path =3D channel_get_output_return_path, }; =20 diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 95d5db9dd6..74f919de67 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -408,16 +408,16 @@ void qemu_file_credit_transfer(QEMUFile *f, size_t si= ze) */ int qemu_fclose(QEMUFile *f) { - int ret; + int ret, ret2; qemu_fflush(f); ret =3D qemu_file_get_error(f); =20 - if (f->ops->close) { - int ret2 =3D f->ops->close(f->ioc, NULL); - if (ret >=3D 0) { - ret =3D ret2; - } + ret2 =3D qio_channel_close(f->ioc, NULL); + if (ret >=3D 0) { + ret =3D ret2; } + g_clear_pointer(&f->ioc, object_unref); + /* If any error was spotted before closing, we should report it * instead of the close() return value. */ diff --git a/migration/qemu-file.h b/migration/qemu-file.h index 7793e765f2..4a3beedb5b 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -37,15 +37,6 @@ typedef ssize_t (QEMUFileGetBufferFunc)(void *opaque, ui= nt8_t *buf, int64_t pos, size_t size, Error **errp); =20 -/* Close a file - * - * Return negative error number on error, 0 or positive value on success. - * - * The meaning of return value on success depends on the specific back-end= being - * used. - */ -typedef int (QEMUFileCloseFunc)(void *opaque, Error **errp); - /* * This function writes an iovec to file. The handler must write all * of the data or return a negative errno value. @@ -87,7 +78,6 @@ typedef QEMUFile *(QEMURetPathFunc)(void *opaque); =20 typedef struct QEMUFileOps { QEMUFileGetBufferFunc *get_buffer; - QEMUFileCloseFunc *close; QEMUFileWritevBufferFunc *writev_buffer; QEMURetPathFunc *get_return_path; } QEMUFileOps; --=20 2.36.1 From nobody Tue May 21 14:34:03 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1655978855; cv=none; d=zohomail.com; s=zohoarc; b=nxObR51pXClOZ/izE11keLVF8to+up0vQUT26RaPrfW9pb7MoFPZ4eJjB4nnyVkbZyycCwIoRM0CoxBWfke8fLrYzz0WPkrMq9R4wJ57GGH9ba1YHP5VS/1XnUsgDVSV+6tNPcCcGBgXD32QnSsczHwZSLro+rTesOCNP4WTPmM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655978855; h=Content-Type: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=SOgcSaxVmvP4VoCtgL+Iv1gxgUtAbjBB0e9DBiefTTo=; b=d3oNp+O2hLgwcDJwe3r2oSWwyOBQK8x2I1Sg356T01rUTEe8w6Pm9KgskDeDcGug1UVEcfmSasAIwqFTv5+PnD7ySwxM34eticialHCDKUwUM+nrFGEeaJwaUODC8w4mMKF67U2TlXmRcLDQBBdKEqA+BABbzOPHk7853/xbaY4= 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 16559788558871.7198808897427398; Thu, 23 Jun 2022 03:07:35 -0700 (PDT) Received: from localhost ([::1]:45374 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o4JkL-0008J2-62 for importer@patchew.org; Thu, 23 Jun 2022 06:07:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45454) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8s-0000iA-1J for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:35434) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8q-0004z2-E0 for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:49 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-352-_JkjMaVTOOGkuqgWmQYYag-1; Thu, 23 Jun 2022 05:28:43 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BC707294EDCF; Thu, 23 Jun 2022 09:28:42 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.33.36.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id BC9FA4050C43; Thu, 23 Jun 2022 09:28:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655976526; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SOgcSaxVmvP4VoCtgL+Iv1gxgUtAbjBB0e9DBiefTTo=; b=EOM0q0nsjr3QeTGaaJ3D+Pun/GacdRZ4+hnzRhxo1oy2GGeL8cnPbiV23Olb1V1u2/SeFk ZFyiWVye52ohjeQXgwuZ3O8rhn9ivknLhtt/IPDHNvcNWTT+ThHUnMQHeVD432wuv7vi1T LxKpdLuo/FayhLBq3H+GEKVh1ML+7ck= X-MC-Unique: _JkjMaVTOOGkuqgWmQYYag-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, huangy81@chinatelecom.cn, quintela@redhat.com, leobras@redhat.com, peterx@redhat.com Cc: jdenemar@redhat.com Subject: [PULL 22/33] migration: remove the QEMUFileOps 'get_buffer' callback Date: Thu, 23 Jun 2022 10:27:59 +0100 Message-Id: <20220623092810.96234-23-dgilbert@redhat.com> In-Reply-To: <20220623092810.96234-1-dgilbert@redhat.com> References: <20220623092810.96234-1-dgilbert@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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=170.10.133.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1655978857469100001 From: Daniel P. Berrang=C3=A9 This directly implements the get_buffer logic using QIOChannel APIs. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela Signed-off-by: Dr. David Alan Gilbert dgilbert: Fixup len =3D *-*EIO as spotted by Peter Xu --- migration/qemu-file-channel.c | 29 ----------------------------- migration/qemu-file.c | 18 ++++++++++++++++-- migration/qemu-file.h | 9 --------- 3 files changed, 16 insertions(+), 40 deletions(-) diff --git a/migration/qemu-file-channel.c b/migration/qemu-file-channel.c index 8ff58e81f9..7b32831752 100644 --- a/migration/qemu-file-channel.c +++ b/migration/qemu-file-channel.c @@ -74,34 +74,6 @@ static ssize_t channel_writev_buffer(void *opaque, } =20 =20 -static ssize_t channel_get_buffer(void *opaque, - uint8_t *buf, - int64_t pos, - size_t size, - Error **errp) -{ - QIOChannel *ioc =3D QIO_CHANNEL(opaque); - ssize_t ret; - - do { - ret =3D qio_channel_read(ioc, (char *)buf, size, errp); - if (ret < 0) { - if (ret =3D=3D QIO_CHANNEL_ERR_BLOCK) { - if (qemu_in_coroutine()) { - qio_channel_yield(ioc, G_IO_IN); - } else { - qio_channel_wait(ioc, G_IO_IN); - } - } else { - return -EIO; - } - } - } while (ret =3D=3D QIO_CHANNEL_ERR_BLOCK); - - return ret; -} - - static QEMUFile *channel_get_input_return_path(void *opaque) { QIOChannel *ioc =3D QIO_CHANNEL(opaque); @@ -117,7 +89,6 @@ static QEMUFile *channel_get_output_return_path(void *op= aque) } =20 static const QEMUFileOps channel_input_ops =3D { - .get_buffer =3D channel_get_buffer, .get_return_path =3D channel_get_input_return_path, }; =20 diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 74f919de67..2f46873efd 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -377,8 +377,22 @@ static ssize_t qemu_fill_buffer(QEMUFile *f) return 0; } =20 - len =3D f->ops->get_buffer(f->ioc, f->buf + pending, f->total_transfer= red, - IO_BUF_SIZE - pending, &local_error); + do { + len =3D qio_channel_read(f->ioc, + (char *)f->buf + pending, + IO_BUF_SIZE - pending, + &local_error); + if (len =3D=3D QIO_CHANNEL_ERR_BLOCK) { + if (qemu_in_coroutine()) { + qio_channel_yield(f->ioc, G_IO_IN); + } else { + qio_channel_wait(f->ioc, G_IO_IN); + } + } else if (len < 0) { + len =3D -EIO; + } + } while (len =3D=3D QIO_CHANNEL_ERR_BLOCK); + if (len > 0) { f->buf_size +=3D len; f->total_transferred +=3D len; diff --git a/migration/qemu-file.h b/migration/qemu-file.h index 4a3beedb5b..f7ed568894 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -29,14 +29,6 @@ #include "exec/cpu-common.h" #include "io/channel.h" =20 -/* Read a chunk of data from a file at the given position. The pos argume= nt - * can be ignored if the file is only be used for streaming. The number of - * bytes actually read should be returned. - */ -typedef ssize_t (QEMUFileGetBufferFunc)(void *opaque, uint8_t *buf, - int64_t pos, size_t size, - Error **errp); - /* * This function writes an iovec to file. The handler must write all * of the data or return a negative errno value. @@ -77,7 +69,6 @@ typedef size_t (QEMURamSaveFunc)(QEMUFile *f, typedef QEMUFile *(QEMURetPathFunc)(void *opaque); =20 typedef struct QEMUFileOps { - QEMUFileGetBufferFunc *get_buffer; QEMUFileWritevBufferFunc *writev_buffer; QEMURetPathFunc *get_return_path; } QEMUFileOps; --=20 2.36.1 From nobody Tue May 21 14:34:03 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1655978623; cv=none; d=zohomail.com; s=zohoarc; b=fNR9mzb48sHkGVTh++OrYBJgeyVJAlcKnhvzRPgVmwnJGEDM752bGuqk3/7sqHUQMy1MdTnIysVJKnF0WajOOmRQxprVH3PVUGmOItXFtvU40Vc4xg0VblmTMsR2Pf8C67sgCOuQPcUQ42t8ibS6SaumuuMK+MDrlHtqn126gs0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655978623; h=Content-Type: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=9elniG+RwDgy9oLvhR+cUtOMLa3XECE1vpoxurAcfaA=; b=QEyMcpkjpuBGuUZkka2TrniBLkxaUuHjT6/WJtpvnjOaL1JKZolStmLCCWjsRQ9xYWYOCxisVrZuLcH2cqzMgb1qGvTSJeA3umJD+FjfVwa9AxdYcSCkQWXoXy2VwvZ9gXyXfnlYNKQcX3We3p66Piob7eNjq7VhjiuUNUbKyAc= 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 1655978622997104.26653102276453; Thu, 23 Jun 2022 03:03:42 -0700 (PDT) Received: from localhost ([::1]:39236 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o4Jgb-0003yw-6x for importer@patchew.org; Thu, 23 Jun 2022 06:03:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45460) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8s-0000iC-GK for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:21557) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8q-0004zJ-Pj for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:50 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-49-cRs3ajhcMBWmiwtBZuNJoA-1; Thu, 23 Jun 2022 05:28:44 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EC9FB811E75; Thu, 23 Jun 2022 09:28:43 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.33.36.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id EFB394050C43; Thu, 23 Jun 2022 09:28:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655976528; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9elniG+RwDgy9oLvhR+cUtOMLa3XECE1vpoxurAcfaA=; b=Fpv4ArtpNrfb+D+m1CUT5KamK4CLJVcHc34pTPSVzZsC4XkxCYjFY3tLGmaGtnBFe7VTmX LmBU10Hzt/xvI7wXxMoI+HRzWhwHYFZ29TnFXuBPsVLMWoeTSf/ld1gZCooDBLewOCMv5e +SX7iaNTES08RVGqjuc1nZ5zcWfHTKI= X-MC-Unique: cRs3ajhcMBWmiwtBZuNJoA-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, huangy81@chinatelecom.cn, quintela@redhat.com, leobras@redhat.com, peterx@redhat.com Cc: jdenemar@redhat.com Subject: [PULL 23/33] migration: remove the QEMUFileOps 'writev_buffer' callback Date: Thu, 23 Jun 2022 10:28:00 +0100 Message-Id: <20220623092810.96234-24-dgilbert@redhat.com> In-Reply-To: <20220623092810.96234-1-dgilbert@redhat.com> References: <20220623092810.96234-1-dgilbert@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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=170.10.129.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1655978623515100001 From: Daniel P. Berrang=C3=A9 This directly implements the writev_buffer logic using QIOChannel APIs. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela Signed-off-by: Dr. David Alan Gilbert --- migration/qemu-file-channel.c | 43 ----------------------------------- migration/qemu-file.c | 24 +++++++------------ migration/qemu-file.h | 9 -------- 3 files changed, 8 insertions(+), 68 deletions(-) diff --git a/migration/qemu-file-channel.c b/migration/qemu-file-channel.c index 7b32831752..2e139f7bcd 100644 --- a/migration/qemu-file-channel.c +++ b/migration/qemu-file-channel.c @@ -32,48 +32,6 @@ #include "yank_functions.h" =20 =20 -static ssize_t channel_writev_buffer(void *opaque, - struct iovec *iov, - int iovcnt, - int64_t pos, - Error **errp) -{ - QIOChannel *ioc =3D QIO_CHANNEL(opaque); - ssize_t done =3D 0; - struct iovec *local_iov =3D g_new(struct iovec, iovcnt); - struct iovec *local_iov_head =3D local_iov; - unsigned int nlocal_iov =3D iovcnt; - - nlocal_iov =3D iov_copy(local_iov, nlocal_iov, - iov, iovcnt, - 0, iov_size(iov, iovcnt)); - - while (nlocal_iov > 0) { - ssize_t len; - len =3D qio_channel_writev(ioc, local_iov, nlocal_iov, errp); - if (len =3D=3D QIO_CHANNEL_ERR_BLOCK) { - if (qemu_in_coroutine()) { - qio_channel_yield(ioc, G_IO_OUT); - } else { - qio_channel_wait(ioc, G_IO_OUT); - } - continue; - } - if (len < 0) { - done =3D -EIO; - goto cleanup; - } - - iov_discard_front(&local_iov, &nlocal_iov, len); - done +=3D len; - } - - cleanup: - g_free(local_iov_head); - return done; -} - - static QEMUFile *channel_get_input_return_path(void *opaque) { QIOChannel *ioc =3D QIO_CHANNEL(opaque); @@ -94,7 +52,6 @@ static const QEMUFileOps channel_input_ops =3D { =20 =20 static const QEMUFileOps channel_output_ops =3D { - .writev_buffer =3D channel_writev_buffer, .get_return_path =3D channel_get_output_return_path, }; =20 diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 2f46873efd..355117fee0 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -248,10 +248,6 @@ static void qemu_iovec_release_ram(QEMUFile *f) */ void qemu_fflush(QEMUFile *f) { - ssize_t ret =3D 0; - ssize_t expect =3D 0; - Error *local_error =3D NULL; - if (!qemu_file_is_writable(f)) { return; } @@ -260,22 +256,18 @@ void qemu_fflush(QEMUFile *f) return; } if (f->iovcnt > 0) { - expect =3D iov_size(f->iov, f->iovcnt); - ret =3D f->ops->writev_buffer(f->ioc, f->iov, f->iovcnt, - f->total_transferred, &local_error); + Error *local_error =3D NULL; + if (qio_channel_writev_all(f->ioc, + f->iov, f->iovcnt, + &local_error) < 0) { + qemu_file_set_error_obj(f, -EIO, local_error); + } else { + f->total_transferred +=3D iov_size(f->iov, f->iovcnt); + } =20 qemu_iovec_release_ram(f); } =20 - if (ret >=3D 0) { - f->total_transferred +=3D ret; - } - /* We expect the QEMUFile write impl to send the full - * data set we requested, so sanity check that. - */ - if (ret !=3D expect) { - qemu_file_set_error_obj(f, ret < 0 ? ret : -EIO, local_error); - } f->buf_index =3D 0; f->iovcnt =3D 0; } diff --git a/migration/qemu-file.h b/migration/qemu-file.h index f7ed568894..de3f066014 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -29,14 +29,6 @@ #include "exec/cpu-common.h" #include "io/channel.h" =20 -/* - * This function writes an iovec to file. The handler must write all - * of the data or return a negative errno value. - */ -typedef ssize_t (QEMUFileWritevBufferFunc)(void *opaque, struct iovec *iov, - int iovcnt, int64_t pos, - Error **errp); - /* * This function provides hooks around different * stages of RAM migration. @@ -69,7 +61,6 @@ typedef size_t (QEMURamSaveFunc)(QEMUFile *f, typedef QEMUFile *(QEMURetPathFunc)(void *opaque); =20 typedef struct QEMUFileOps { - QEMUFileWritevBufferFunc *writev_buffer; QEMURetPathFunc *get_return_path; } QEMUFileOps; =20 --=20 2.36.1 From nobody Tue May 21 14:34:03 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1655979590; cv=none; d=zohomail.com; s=zohoarc; b=Ikwd/z6PXqCfIPpKTs6kxPWWqnJpolJtd5tXz09UuBKohWBRDHq6jDTxmVAg9uLHc5OrjQNZjO4k99odFSqHEOYFSPRdOwcLDO8f+KqgWAK3Pl5BaEmbrxXWFsxkvjQ7T6xMExlcJ3odpoUngzkGnSoawWE6tpmd+tIiuSSlPiQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655979590; h=Content-Type: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=GJCtJDwIAggQmNnMEx56N4hDOHtxOPWCHBoLwOBXQFI=; b=WJ65zs6YRgBSSj2Ths9EPLHW/MxYc6ytoXTzEFQeaOyIcLpb3Eel6qTVuXUSrgJoWuoZUuLCgAHt+P6rqBVBWphqsxHXWlPv1vZI5G3nNqQmRlmFrWc/D/NYFKWTTaOIqtBFs9hjttQcIOU6aOUpSV9GJa6B26+KVn+0uuZO0+A= 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 1655979589724167.5467388667123; Thu, 23 Jun 2022 03:19:49 -0700 (PDT) Received: from localhost ([::1]:33106 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o4JwC-0003JO-Eg for importer@patchew.org; Thu, 23 Jun 2022 06:19:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45478) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8t-0000iD-DY for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:32979) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8r-0004zR-EP for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:51 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-98-VdCU7oUVO5yV_ECK680sEg-1; Thu, 23 Jun 2022 05:28:45 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2A5F93AF42A8; Thu, 23 Jun 2022 09:28:45 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.33.36.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2B5264050C43; Thu, 23 Jun 2022 09:28:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655976528; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GJCtJDwIAggQmNnMEx56N4hDOHtxOPWCHBoLwOBXQFI=; b=Rg1Mnoo+LAJCqc6wrhz2Cgr8+Soh5mtWyXRQmLiUfZwrluyMlgf4Y9CCs9C+LFEACmGUkf OsAthjYS0392WYJFOip6R7ozS1//bux3PhbpIE/Rkq987VEqLoakdzCkkOCORhmmKBpSt1 4QqCebFHEYs3o1ML6pdZz/aLhCQz+Fk= X-MC-Unique: VdCU7oUVO5yV_ECK680sEg-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, huangy81@chinatelecom.cn, quintela@redhat.com, leobras@redhat.com, peterx@redhat.com Cc: jdenemar@redhat.com Subject: [PULL 24/33] migration: remove the QEMUFileOps 'get_return_path' callback Date: Thu, 23 Jun 2022 10:28:01 +0100 Message-Id: <20220623092810.96234-25-dgilbert@redhat.com> In-Reply-To: <20220623092810.96234-1-dgilbert@redhat.com> References: <20220623092810.96234-1-dgilbert@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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=170.10.133.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1655979591943100001 From: Daniel P. Berrang=C3=A9 This directly implements the get_return_path logic using QIOChannel APIs. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela Signed-off-by: Dr. David Alan Gilbert --- migration/qemu-file-channel.c | 16 ---------------- migration/qemu-file.c | 22 ++++++++++------------ migration/qemu-file.h | 6 ------ 3 files changed, 10 insertions(+), 34 deletions(-) diff --git a/migration/qemu-file-channel.c b/migration/qemu-file-channel.c index 2e139f7bcd..51717c1137 100644 --- a/migration/qemu-file-channel.c +++ b/migration/qemu-file-channel.c @@ -32,27 +32,11 @@ #include "yank_functions.h" =20 =20 -static QEMUFile *channel_get_input_return_path(void *opaque) -{ - QIOChannel *ioc =3D QIO_CHANNEL(opaque); - - return qemu_fopen_channel_output(ioc); -} - -static QEMUFile *channel_get_output_return_path(void *opaque) -{ - QIOChannel *ioc =3D QIO_CHANNEL(opaque); - - return qemu_fopen_channel_input(ioc); -} - static const QEMUFileOps channel_input_ops =3D { - .get_return_path =3D channel_get_input_return_path, }; =20 =20 static const QEMUFileOps channel_output_ops =3D { - .get_return_path =3D channel_get_output_return_path, }; =20 =20 diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 355117fee0..fad0e33164 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -95,18 +95,6 @@ int qemu_file_shutdown(QEMUFile *f) return ret; } =20 -/* - * Result: QEMUFile* for a 'return path' for comms in the opposite directi= on - * NULL if not available - */ -QEMUFile *qemu_file_get_return_path(QEMUFile *f) -{ - if (!f->ops->get_return_path) { - return NULL; - } - return f->ops->get_return_path(f->ioc); -} - bool qemu_file_mode_is_not_valid(const char *mode) { if (mode =3D=3D NULL || @@ -134,6 +122,16 @@ static QEMUFile *qemu_file_new_impl(QIOChannel *ioc, return f; } =20 +/* + * Result: QEMUFile* for a 'return path' for comms in the opposite directi= on + * NULL if not available + */ +QEMUFile *qemu_file_get_return_path(QEMUFile *f) +{ + object_ref(f->ioc); + return qemu_file_new_impl(f->ioc, f->ops, !f->is_writable); +} + QEMUFile *qemu_file_new_output(QIOChannel *ioc, const QEMUFileOps *ops) { return qemu_file_new_impl(ioc, ops, true); diff --git a/migration/qemu-file.h b/migration/qemu-file.h index de3f066014..fe8f9766d1 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -55,13 +55,7 @@ typedef size_t (QEMURamSaveFunc)(QEMUFile *f, size_t size, uint64_t *bytes_sent); =20 -/* - * Return a QEMUFile for comms in the opposite direction - */ -typedef QEMUFile *(QEMURetPathFunc)(void *opaque); - typedef struct QEMUFileOps { - QEMURetPathFunc *get_return_path; } QEMUFileOps; =20 typedef struct QEMUFileHooks { --=20 2.36.1 From nobody Tue May 21 14:34:03 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1655978351; cv=none; d=zohomail.com; s=zohoarc; b=HCAnv+WfgMfxc8TEOz6vfHsNRKLqtHD5X1tJPfM3zCh2/jAogApU8SewCp3VubSyLtuJkzbaBftHFtA30LszbpPSDbbOM8+lLLTNNh7/85/5mDtDCxCIQCXb/i1nlAPjk/sE98Uq7o5vMoJD2N7lNSrNB/Uk+ng2Ws/mBD89JQ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655978351; h=Content-Type: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=PY4fpvxGdjp1+fbi8zA9Qa+gNZHE10i6nQK1m8jqQU0=; b=HgciR8df3qf40c3AoL74igh1ac48GNfrHgqQt9hIuyFTMRpGfk/7XgY6QHKJda1o5oKMSR41BtqRy20rlabOupuKBprNV+bMjF2wB2Mt26ptTn1sSOyiNj9A+2isBiKAcf9e5jvda65YEkiaPQZlOBJzfXGB7eNzVw5OKHcZ/ZE= 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 16559783513190.7957650581838607; Thu, 23 Jun 2022 02:59:11 -0700 (PDT) Received: from localhost ([::1]:58696 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o4JcD-0006Kp-TT for importer@patchew.org; Thu, 23 Jun 2022 05:59:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45490) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8u-0000iH-V1 for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:37841) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8s-0004zj-Ka for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:52 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-196-V8L9GLgUPMKtutoqIz28eA-1; Thu, 23 Jun 2022 05:28:46 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 76F2E101E985; Thu, 23 Jun 2022 09:28:46 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.33.36.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5DA1940C1289; Thu, 23 Jun 2022 09:28:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655976530; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PY4fpvxGdjp1+fbi8zA9Qa+gNZHE10i6nQK1m8jqQU0=; b=cgv/UNI4W+wmI/J49rPFn2aHt3MInHKaoPGD2HMT8THatrdbAanVQ0N6nCNMfXYD1K0Hfg JG5cX1pFDNM/72NNtuUsPi+APEcu4/keid2yfAOegrF5+hMO5JhJ+JFRqQV0rQbc6xNToQ UTumzf9OTSr6Y/lGhYWF5j5bcaiQuGI= X-MC-Unique: V8L9GLgUPMKtutoqIz28eA-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, huangy81@chinatelecom.cn, quintela@redhat.com, leobras@redhat.com, peterx@redhat.com Cc: jdenemar@redhat.com Subject: [PULL 25/33] migration: remove the QEMUFileOps abstraction Date: Thu, 23 Jun 2022 10:28:02 +0100 Message-Id: <20220623092810.96234-26-dgilbert@redhat.com> In-Reply-To: <20220623092810.96234-1-dgilbert@redhat.com> References: <20220623092810.96234-1-dgilbert@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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=170.10.133.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1655978352755100001 From: Daniel P. Berrang=C3=A9 Now that all QEMUFile callbacks are removed, the entire concept can be deleted. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela Signed-off-by: Dr. David Alan Gilbert --- migration/channel.c | 4 +-- migration/colo.c | 5 ++-- migration/meson.build | 1 - migration/migration.c | 7 ++--- migration/qemu-file-channel.c | 53 ----------------------------------- migration/qemu-file-channel.h | 32 --------------------- migration/qemu-file.c | 20 ++++++------- migration/qemu-file.h | 7 ++--- migration/ram.c | 3 +- migration/rdma.c | 5 ++-- migration/savevm.c | 13 ++++----- tests/unit/test-vmstate.c | 5 ++-- 12 files changed, 27 insertions(+), 128 deletions(-) delete mode 100644 migration/qemu-file-channel.c delete mode 100644 migration/qemu-file-channel.h diff --git a/migration/channel.c b/migration/channel.c index a162d00fea..90087d8986 100644 --- a/migration/channel.c +++ b/migration/channel.c @@ -14,7 +14,7 @@ #include "channel.h" #include "tls.h" #include "migration.h" -#include "qemu-file-channel.h" +#include "qemu-file.h" #include "trace.h" #include "qapi/error.h" #include "io/channel-tls.h" @@ -85,7 +85,7 @@ void migration_channel_connect(MigrationState *s, return; } } else { - QEMUFile *f =3D qemu_fopen_channel_output(ioc); + QEMUFile *f =3D qemu_file_new_output(ioc); =20 migration_ioc_register_yank(ioc); =20 diff --git a/migration/colo.c b/migration/colo.c index 5f7071b3cd..2b71722fd6 100644 --- a/migration/colo.c +++ b/migration/colo.c @@ -14,7 +14,6 @@ #include "sysemu/sysemu.h" #include "qapi/error.h" #include "qapi/qapi-commands-migration.h" -#include "qemu-file-channel.h" #include "migration.h" #include "qemu-file.h" #include "savevm.h" @@ -559,7 +558,7 @@ static void colo_process_checkpoint(MigrationState *s) goto out; } bioc =3D qio_channel_buffer_new(COLO_BUFFER_BASE_SIZE); - fb =3D qemu_fopen_channel_output(QIO_CHANNEL(bioc)); + fb =3D qemu_file_new_output(QIO_CHANNEL(bioc)); object_unref(OBJECT(bioc)); =20 qemu_mutex_lock_iothread(); @@ -873,7 +872,7 @@ void *colo_process_incoming_thread(void *opaque) colo_incoming_start_dirty_log(); =20 bioc =3D qio_channel_buffer_new(COLO_BUFFER_BASE_SIZE); - fb =3D qemu_fopen_channel_input(QIO_CHANNEL(bioc)); + fb =3D qemu_file_new_input(QIO_CHANNEL(bioc)); object_unref(OBJECT(bioc)); =20 qemu_mutex_lock_iothread(); diff --git a/migration/meson.build b/migration/meson.build index 8d309f5849..690487cf1a 100644 --- a/migration/meson.build +++ b/migration/meson.build @@ -4,7 +4,6 @@ migration_files =3D files( 'xbzrle.c', 'vmstate-types.c', 'vmstate.c', - 'qemu-file-channel.c', 'qemu-file.c', 'yank_functions.c', ) diff --git a/migration/migration.c b/migration/migration.c index 6d56eb1617..78f5057373 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -30,7 +30,6 @@ #include "migration/misc.h" #include "migration.h" #include "savevm.h" -#include "qemu-file-channel.h" #include "qemu-file.h" #include "migration/vmstate.h" #include "block/block.h" @@ -723,7 +722,7 @@ void migration_ioc_process_incoming(QIOChannel *ioc, Er= ror **errp) =20 if (!mis->from_src_file) { /* The first connection (multifd may have multiple) */ - QEMUFile *f =3D qemu_fopen_channel_input(ioc); + QEMUFile *f =3D qemu_file_new_input(ioc); =20 if (!migration_incoming_setup(f, errp)) { return; @@ -3076,7 +3075,7 @@ static int postcopy_start(MigrationState *ms) */ bioc =3D qio_channel_buffer_new(4096); qio_channel_set_name(QIO_CHANNEL(bioc), "migration-postcopy-buffer"); - fb =3D qemu_fopen_channel_output(QIO_CHANNEL(bioc)); + fb =3D qemu_file_new_output(QIO_CHANNEL(bioc)); object_unref(OBJECT(bioc)); =20 /* @@ -3966,7 +3965,7 @@ static void *bg_migration_thread(void *opaque) */ s->bioc =3D qio_channel_buffer_new(512 * 1024); qio_channel_set_name(QIO_CHANNEL(s->bioc), "vmstate-buffer"); - fb =3D qemu_fopen_channel_output(QIO_CHANNEL(s->bioc)); + fb =3D qemu_file_new_output(QIO_CHANNEL(s->bioc)); object_unref(OBJECT(s->bioc)); =20 update_iteration_initial_status(s); diff --git a/migration/qemu-file-channel.c b/migration/qemu-file-channel.c deleted file mode 100644 index 51717c1137..0000000000 --- a/migration/qemu-file-channel.c +++ /dev/null @@ -1,53 +0,0 @@ -/* - * QEMUFile backend for QIOChannel objects - * - * Copyright (c) 2015-2016 Red Hat, Inc - * - * Permission is hereby granted, free of charge, to any person obtaining a= copy - * of this software and associated documentation files (the "Software"), t= o deal - * in the Software without restriction, including without limitation the r= ights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included= in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN - * THE SOFTWARE. - */ - -#include "qemu/osdep.h" -#include "qemu-file-channel.h" -#include "qemu-file.h" -#include "io/channel-socket.h" -#include "io/channel-tls.h" -#include "qemu/iov.h" -#include "qemu/yank.h" -#include "yank_functions.h" - - -static const QEMUFileOps channel_input_ops =3D { -}; - - -static const QEMUFileOps channel_output_ops =3D { -}; - - -QEMUFile *qemu_fopen_channel_input(QIOChannel *ioc) -{ - object_ref(OBJECT(ioc)); - return qemu_file_new_input(ioc, &channel_input_ops); -} - -QEMUFile *qemu_fopen_channel_output(QIOChannel *ioc) -{ - object_ref(OBJECT(ioc)); - return qemu_file_new_output(ioc, &channel_output_ops); -} diff --git a/migration/qemu-file-channel.h b/migration/qemu-file-channel.h deleted file mode 100644 index 0028a09eb6..0000000000 --- a/migration/qemu-file-channel.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * QEMUFile backend for QIOChannel objects - * - * Copyright (c) 2015-2016 Red Hat, Inc - * - * Permission is hereby granted, free of charge, to any person obtaining a= copy - * of this software and associated documentation files (the "Software"), t= o deal - * in the Software without restriction, including without limitation the r= ights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included= in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN - * THE SOFTWARE. - */ - -#ifndef QEMU_FILE_CHANNEL_H -#define QEMU_FILE_CHANNEL_H - -#include "io/channel.h" - -QEMUFile *qemu_fopen_channel_input(QIOChannel *ioc); -QEMUFile *qemu_fopen_channel_output(QIOChannel *ioc); -#endif diff --git a/migration/qemu-file.c b/migration/qemu-file.c index fad0e33164..1e80d496b7 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -35,7 +35,6 @@ #define MAX_IOV_SIZE MIN_CONST(IOV_MAX, 64) =20 struct QEMUFile { - const QEMUFileOps *ops; const QEMUFileHooks *hooks; QIOChannel *ioc; bool is_writable; @@ -107,16 +106,14 @@ bool qemu_file_mode_is_not_valid(const char *mode) return false; } =20 -static QEMUFile *qemu_file_new_impl(QIOChannel *ioc, - const QEMUFileOps *ops, - bool is_writable) +static QEMUFile *qemu_file_new_impl(QIOChannel *ioc, bool is_writable) { QEMUFile *f; =20 f =3D g_new0(QEMUFile, 1); =20 + object_ref(ioc); f->ioc =3D ioc; - f->ops =3D ops; f->is_writable =3D is_writable; =20 return f; @@ -128,21 +125,19 @@ static QEMUFile *qemu_file_new_impl(QIOChannel *ioc, */ QEMUFile *qemu_file_get_return_path(QEMUFile *f) { - object_ref(f->ioc); - return qemu_file_new_impl(f->ioc, f->ops, !f->is_writable); + return qemu_file_new_impl(f->ioc, !f->is_writable); } =20 -QEMUFile *qemu_file_new_output(QIOChannel *ioc, const QEMUFileOps *ops) +QEMUFile *qemu_file_new_output(QIOChannel *ioc) { - return qemu_file_new_impl(ioc, ops, true); + return qemu_file_new_impl(ioc, true); } =20 -QEMUFile *qemu_file_new_input(QIOChannel *ioc, const QEMUFileOps *ops) +QEMUFile *qemu_file_new_input(QIOChannel *ioc) { - return qemu_file_new_impl(ioc, ops, false); + return qemu_file_new_impl(ioc, false); } =20 - void qemu_file_set_hooks(QEMUFile *f, const QEMUFileHooks *hooks) { f->hooks =3D hooks; @@ -238,6 +233,7 @@ static void qemu_iovec_release_ram(QEMUFile *f) memset(f->may_free, 0, sizeof(f->may_free)); } =20 + /** * Flushes QEMUFile buffer * diff --git a/migration/qemu-file.h b/migration/qemu-file.h index fe8f9766d1..96e72d8bd8 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -55,9 +55,6 @@ typedef size_t (QEMURamSaveFunc)(QEMUFile *f, size_t size, uint64_t *bytes_sent); =20 -typedef struct QEMUFileOps { -} QEMUFileOps; - typedef struct QEMUFileHooks { QEMURamHookFunc *before_ram_iterate; QEMURamHookFunc *after_ram_iterate; @@ -65,8 +62,8 @@ typedef struct QEMUFileHooks { QEMURamSaveFunc *save_page; } QEMUFileHooks; =20 -QEMUFile *qemu_file_new_input(QIOChannel *ioc, const QEMUFileOps *ops); -QEMUFile *qemu_file_new_output(QIOChannel *ioc, const QEMUFileOps *ops); +QEMUFile *qemu_file_new_input(QIOChannel *ioc); +QEMUFile *qemu_file_new_output(QIOChannel *ioc); void qemu_file_set_hooks(QEMUFile *f, const QEMUFileHooks *hooks); int qemu_fclose(QEMUFile *f); =20 diff --git a/migration/ram.c b/migration/ram.c index bf321e1e72..01f9cc1d72 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -38,7 +38,6 @@ #include "migration.h" #include "migration/register.h" #include "migration/misc.h" -#include "migration/qemu-file-channel.h" #include "qemu-file.h" #include "postcopy-ram.h" #include "page_cache.h" @@ -569,7 +568,7 @@ static int compress_threads_save_setup(void) /* comp_param[i].file is just used as a dummy buffer to save data, * set its ops to empty. */ - comp_param[i].file =3D qemu_fopen_channel_output( + comp_param[i].file =3D qemu_file_new_output( QIO_CHANNEL(qio_channel_null_new())); comp_param[i].done =3D true; comp_param[i].quit =3D false; diff --git a/migration/rdma.c b/migration/rdma.c index 26a0cbbf40..94a55dd95b 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -21,7 +21,6 @@ #include "migration.h" #include "qemu-file.h" #include "ram.h" -#include "qemu-file-channel.h" #include "qemu/error-report.h" #include "qemu/main-loop.h" #include "qemu/module.h" @@ -4052,12 +4051,12 @@ static QEMUFile *qemu_fopen_rdma(RDMAContext *rdma,= const char *mode) rioc =3D QIO_CHANNEL_RDMA(object_new(TYPE_QIO_CHANNEL_RDMA)); =20 if (mode[0] =3D=3D 'w') { - rioc->file =3D qemu_fopen_channel_output(QIO_CHANNEL(rioc)); + rioc->file =3D qemu_file_new_output(QIO_CHANNEL(rioc)); rioc->rdmaout =3D rdma; rioc->rdmain =3D rdma->return_path; qemu_file_set_hooks(rioc->file, &rdma_write_hooks); } else { - rioc->file =3D qemu_fopen_channel_input(QIO_CHANNEL(rioc)); + rioc->file =3D qemu_file_new_input(QIO_CHANNEL(rioc)); rioc->rdmain =3D rdma; rioc->rdmaout =3D rdma->return_path; qemu_file_set_hooks(rioc->file, &rdma_read_hooks); diff --git a/migration/savevm.c b/migration/savevm.c index 3e9612121a..e8a1b96fcd 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -37,7 +37,6 @@ #include "migration/global_state.h" #include "migration/channel-block.h" #include "ram.h" -#include "qemu-file-channel.h" #include "qemu-file.h" #include "savevm.h" #include "postcopy-ram.h" @@ -134,11 +133,9 @@ static struct mig_cmd_args { static QEMUFile *qemu_fopen_bdrv(BlockDriverState *bs, int is_writable) { if (is_writable) { - return qemu_fopen_channel_output( - QIO_CHANNEL(qio_channel_block_new(bs))); + return qemu_file_new_output(QIO_CHANNEL(qio_channel_block_new(bs))= ); } else { - return qemu_fopen_channel_input( - QIO_CHANNEL(qio_channel_block_new(bs))); + return qemu_file_new_input(QIO_CHANNEL(qio_channel_block_new(bs))); } } =20 @@ -2161,7 +2158,7 @@ static int loadvm_handle_cmd_packaged(MigrationIncomi= ngState *mis) bioc->usage +=3D length; trace_loadvm_handle_cmd_packaged_received(ret); =20 - QEMUFile *packf =3D qemu_fopen_channel_input(QIO_CHANNEL(bioc)); + QEMUFile *packf =3D qemu_file_new_input(QIO_CHANNEL(bioc)); =20 ret =3D qemu_loadvm_state_main(packf, mis); trace_loadvm_handle_cmd_packaged_main(ret); @@ -2919,7 +2916,7 @@ void qmp_xen_save_devices_state(const char *filename,= bool has_live, bool live, goto the_end; } qio_channel_set_name(QIO_CHANNEL(ioc), "migration-xen-save-state"); - f =3D qemu_fopen_channel_output(QIO_CHANNEL(ioc)); + f =3D qemu_file_new_output(QIO_CHANNEL(ioc)); object_unref(OBJECT(ioc)); ret =3D qemu_save_device_state(f); if (ret < 0 || qemu_fclose(f) < 0) { @@ -2966,7 +2963,7 @@ void qmp_xen_load_devices_state(const char *filename,= Error **errp) return; } qio_channel_set_name(QIO_CHANNEL(ioc), "migration-xen-load-state"); - f =3D qemu_fopen_channel_input(QIO_CHANNEL(ioc)); + f =3D qemu_file_new_input(QIO_CHANNEL(ioc)); object_unref(OBJECT(ioc)); =20 ret =3D qemu_loadvm_state(f); diff --git a/tests/unit/test-vmstate.c b/tests/unit/test-vmstate.c index 6a417bb102..72077b5780 100644 --- a/tests/unit/test-vmstate.c +++ b/tests/unit/test-vmstate.c @@ -28,7 +28,6 @@ #include "migration/vmstate.h" #include "migration/qemu-file-types.h" #include "../migration/qemu-file.h" -#include "../migration/qemu-file-channel.h" #include "../migration/savevm.h" #include "qemu/coroutine.h" #include "qemu/module.h" @@ -52,9 +51,9 @@ static QEMUFile *open_test_file(bool write) } ioc =3D QIO_CHANNEL(qio_channel_file_new_fd(fd)); if (write) { - f =3D qemu_fopen_channel_output(ioc); + f =3D qemu_file_new_output(ioc); } else { - f =3D qemu_fopen_channel_input(ioc); + f =3D qemu_file_new_input(ioc); } object_unref(OBJECT(ioc)); return f; --=20 2.36.1 From nobody Tue May 21 14:34:03 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1655978524; cv=none; d=zohomail.com; s=zohoarc; b=eQgeAPQiMIbVQ7Nts4yWt1Wu+BwwtxVqLxAtERQRukInAjde75sgG8pR1ooyrPXhhcxJcl8SMAPmtqr4UDNuZtKQLUF8fycG3DbYNcElmh3IVAIdjaajuKy3jz8iDB2N7/y6bWBi6iamv2LkPs9RVxiaKw9xmFsk3n2ollrjISw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655978524; h=Content-Type: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=gVkCW/MbdgCVRNcQ8mL3o0ALPDubARCe+EyFeHqskQI=; b=mXAEXCIdx3BJ2VdD8tG0TjOgVSuywZn6dVIiSNKa2m4AlfOXgVY0Xm58tCeVaIXFMG0YYC3umDcd67G71VDGxzs31RA/tERHClyBJNOEqExPfRDP07ftIGxuXzR5+Rkyg+UW/HlM3m3pJEIn83QXkRtFktZyThnlsujOYC8vrXc= 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 1655978524937624.9645220701984; Thu, 23 Jun 2022 03:02:04 -0700 (PDT) Received: from localhost ([::1]:36758 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o4Jf1-0002Bl-MV for importer@patchew.org; Thu, 23 Jun 2022 06:02:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45480) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8t-0000iE-K5 for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:60270) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8r-0004zY-Rx for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:51 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-590-ImafhozSNCG6p65rUbPxrQ-1; Thu, 23 Jun 2022 05:28:48 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AE38F85A589; Thu, 23 Jun 2022 09:28:47 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.33.36.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id A8C0940D2962; Thu, 23 Jun 2022 09:28:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655976529; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gVkCW/MbdgCVRNcQ8mL3o0ALPDubARCe+EyFeHqskQI=; b=ewsdMUsDLH7HRmw9W+gCXB1Z39g+MzidVhzWyS5SRpY3KqLO5kHIWSWjabGKdqtkGt2bEn WReCLWsc2aeglSTx1zXEeCzsUN6gtb7XwNcu9hzYnCZtd5jZdGcCAfMYQDJofMU8HI21l1 lG+8BPDXzd4/lbMqMmBtTdIXHMekkqs= X-MC-Unique: ImafhozSNCG6p65rUbPxrQ-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, huangy81@chinatelecom.cn, quintela@redhat.com, leobras@redhat.com, peterx@redhat.com Cc: jdenemar@redhat.com Subject: [PULL 26/33] accel/kvm/kvm-all: Refactor per-vcpu dirty ring reaping Date: Thu, 23 Jun 2022 10:28:03 +0100 Message-Id: <20220623092810.96234-27-dgilbert@redhat.com> In-Reply-To: <20220623092810.96234-1-dgilbert@redhat.com> References: <20220623092810.96234-1-dgilbert@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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=170.10.133.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1655978526734100001 From: Hyman Huang(=E9=BB=84=E5=8B=87) Add a non-required argument 'CPUState' to kvm_dirty_ring_reap so that it can cover single vcpu dirty-ring-reaping scenario. Signed-off-by: Hyman Huang(=E9=BB=84=E5=8B=87) Reviewed-by: Peter Xu Message-Id: Signed-off-by: Dr. David Alan Gilbert --- accel/kvm/kvm-all.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index ba3210b1c1..672ed004ab 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -757,17 +757,20 @@ static uint32_t kvm_dirty_ring_reap_one(KVMState *s, = CPUState *cpu) } =20 /* Must be with slots_lock held */ -static uint64_t kvm_dirty_ring_reap_locked(KVMState *s) +static uint64_t kvm_dirty_ring_reap_locked(KVMState *s, CPUState* cpu) { int ret; - CPUState *cpu; uint64_t total =3D 0; int64_t stamp; =20 stamp =3D get_clock(); =20 - CPU_FOREACH(cpu) { - total +=3D kvm_dirty_ring_reap_one(s, cpu); + if (cpu) { + total =3D kvm_dirty_ring_reap_one(s, cpu); + } else { + CPU_FOREACH(cpu) { + total +=3D kvm_dirty_ring_reap_one(s, cpu); + } } =20 if (total) { @@ -788,7 +791,7 @@ static uint64_t kvm_dirty_ring_reap_locked(KVMState *s) * Currently for simplicity, we must hold BQL before calling this. We can * consider to drop the BQL if we're clear with all the race conditions. */ -static uint64_t kvm_dirty_ring_reap(KVMState *s) +static uint64_t kvm_dirty_ring_reap(KVMState *s, CPUState *cpu) { uint64_t total; =20 @@ -808,7 +811,7 @@ static uint64_t kvm_dirty_ring_reap(KVMState *s) * reset below. */ kvm_slots_lock(); - total =3D kvm_dirty_ring_reap_locked(s); + total =3D kvm_dirty_ring_reap_locked(s, cpu); kvm_slots_unlock(); =20 return total; @@ -855,7 +858,7 @@ static void kvm_dirty_ring_flush(void) * vcpus out in a synchronous way. */ kvm_cpu_synchronize_kick_all(); - kvm_dirty_ring_reap(kvm_state); + kvm_dirty_ring_reap(kvm_state, NULL); trace_kvm_dirty_ring_flush(1); } =20 @@ -1399,7 +1402,7 @@ static void kvm_set_phys_mem(KVMMemoryListener *kml, * Not easy. Let's cross the fingers until it's fixed. */ if (kvm_state->kvm_dirty_ring_size) { - kvm_dirty_ring_reap_locked(kvm_state); + kvm_dirty_ring_reap_locked(kvm_state, NULL); } else { kvm_slot_get_dirty_log(kvm_state, mem); } @@ -1471,7 +1474,7 @@ static void *kvm_dirty_ring_reaper_thread(void *data) r->reaper_state =3D KVM_DIRTY_RING_REAPER_REAPING; =20 qemu_mutex_lock_iothread(); - kvm_dirty_ring_reap(s); + kvm_dirty_ring_reap(s, NULL); qemu_mutex_unlock_iothread(); =20 r->reaper_iteration++; @@ -2967,7 +2970,7 @@ int kvm_cpu_exec(CPUState *cpu) */ trace_kvm_dirty_ring_full(cpu->cpu_index); qemu_mutex_lock_iothread(); - kvm_dirty_ring_reap(kvm_state); + kvm_dirty_ring_reap(kvm_state, NULL); qemu_mutex_unlock_iothread(); ret =3D 0; break; --=20 2.36.1 From nobody Tue May 21 14:34:03 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1655978545; cv=none; d=zohomail.com; s=zohoarc; b=RZ7jU0uL9IijkGG/7jgdueMJ2D7OCrThRriW9HvRXHsXPmGlu/4oFEAxJ4UD5G8wdZAPhdbSJVZU9q2F2nr1GsmN4sBopS56G5ImDTA+SZcdqTXcFsu+ai1IDa3PPZFlXEZVltJ4I/PW80ztUSZGDEYRtCAsZHkNIH4P+WF9qSw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655978545; h=Content-Type: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=s8DQU0i0lGKHWOmR2WyMVOo1Rb4B9cDG2PRWzNiPdnM=; b=n2h0Yc+zKZ/tw2JmexJG7hK6Hl0+rSWEgbbUCbinRBk4tw9D5cwQALlpFzT7oft8GoTeAaMo3AhjkE8ejgBbsSCtTxjTSRtkNi8zVXq9q5z7Zi+qeEuB4qfZLi9o+aaV5Nz9hxtW0HugAbbOB2dKRHiuTJGj0sO+Z594ys1sQq4= 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 16559785458017.440329563946307; Thu, 23 Jun 2022 03:02:25 -0700 (PDT) Received: from localhost ([::1]:37102 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o4JfM-0002Qt-PI for importer@patchew.org; Thu, 23 Jun 2022 06:02:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45636) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J94-0000wy-UN for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:29:05 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:26894) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J92-00051p-T1 for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:29:02 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-583-BXH6dHQCP1uWtJ6cg72DkA-1; Thu, 23 Jun 2022 05:28:49 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8AE4C1C05195; Thu, 23 Jun 2022 09:28:49 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.33.36.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id E07B74050C40; Thu, 23 Jun 2022 09:28:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655976540; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s8DQU0i0lGKHWOmR2WyMVOo1Rb4B9cDG2PRWzNiPdnM=; b=X9wSL5civzczkEgpcXbc1JCeb/v+OlZpePVBQ0KHhtLpb8aJXwhelMd1JLxY3I1swY/OUY A7T07w6thn1GSfb8W6cr49fKiLyEeyfJwTgwLqYwQ1jvJlVTuerk6UNCxcApfRAWICAtzb uuSMv7Ag9hGQiu+2Y8soYaE9c7mGCAQ= X-MC-Unique: BXH6dHQCP1uWtJ6cg72DkA-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, huangy81@chinatelecom.cn, quintela@redhat.com, leobras@redhat.com, peterx@redhat.com Cc: jdenemar@redhat.com Subject: [PULL 27/33] cpus: Introduce cpu_list_generation_id Date: Thu, 23 Jun 2022 10:28:04 +0100 Message-Id: <20220623092810.96234-28-dgilbert@redhat.com> In-Reply-To: <20220623092810.96234-1-dgilbert@redhat.com> References: <20220623092810.96234-1-dgilbert@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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=170.10.129.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1655978546950100001 From: Hyman Huang(=E9=BB=84=E5=8B=87) Introduce cpu_list_generation_id to track cpu list generation so that cpu hotplug/unplug can be detected during measurement of dirty page rate. cpu_list_generation_id could be used to detect changes of cpu list, which is prepared for dirty page rate measurement. Signed-off-by: Hyman Huang(=E9=BB=84=E5=8B=87) Reviewed-by: Peter Xu Message-Id: <4d7a5f2c86066839054282b1c224067d89d32fc1.1652931128.git.huangy= 81@chinatelecom.cn> Signed-off-by: Dr. David Alan Gilbert --- cpus-common.c | 8 ++++++++ include/exec/cpu-common.h | 1 + 2 files changed, 9 insertions(+) diff --git a/cpus-common.c b/cpus-common.c index db459b41ce..793364dc0e 100644 --- a/cpus-common.c +++ b/cpus-common.c @@ -73,6 +73,12 @@ static int cpu_get_free_index(void) } =20 CPUTailQ cpus =3D QTAILQ_HEAD_INITIALIZER(cpus); +static unsigned int cpu_list_generation_id; + +unsigned int cpu_list_generation_id_get(void) +{ + return cpu_list_generation_id; +} =20 void cpu_list_add(CPUState *cpu) { @@ -84,6 +90,7 @@ void cpu_list_add(CPUState *cpu) assert(!cpu_index_auto_assigned); } QTAILQ_INSERT_TAIL_RCU(&cpus, cpu, node); + cpu_list_generation_id++; } =20 void cpu_list_remove(CPUState *cpu) @@ -96,6 +103,7 @@ void cpu_list_remove(CPUState *cpu) =20 QTAILQ_REMOVE_RCU(&cpus, cpu, node); cpu->cpu_index =3D UNASSIGNED_CPU_INDEX; + cpu_list_generation_id++; } =20 CPUState *qemu_get_cpu(int index) diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index 5968551a05..2281be4e10 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -35,6 +35,7 @@ extern intptr_t qemu_host_page_mask; void qemu_init_cpu_list(void); void cpu_list_lock(void); void cpu_list_unlock(void); +unsigned int cpu_list_generation_id_get(void); =20 void tcg_flush_softmmu_tlb(CPUState *cs); =20 --=20 2.36.1 From nobody Tue May 21 14:34:03 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1655980171; cv=none; d=zohomail.com; s=zohoarc; b=eAIP1IMCcghiWLhUu7RQIqr2jZvhal46OTvoL7QlyCF5MfYDElyjcOJYnHbawO54m0uWEqeNvsDKfC8MVDKZteDFSPEOGHQLjjKHQ7XEwYBJDqQVwblZjsM9IuIW64gasVrde4k9ep8x31yxav86RRvTGQP6ECgtD+tgbYYtHA8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655980171; h=Content-Type: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=66v7PyoESFH4i8uDIErFBn9sj9Qf11DXUYqrmDqKFEE=; b=Y0NPEfSWJ9CKl35DVwLslOZcLTyMw/XcQBUVcLh8WrKUIIaqjKDLoM592rROQpvMHrZZtvFlLGD1x5CuwRc/lAvgJ8jZ44yecM1mAxBe4/Qgc8JDbIz0tSP1Y3GA47HajU+ZKXiwL3qPPRFtc3UnYZoqKdKqdoPLOHQBvWeCvJk= 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 1655980171147638.8692157914884; Thu, 23 Jun 2022 03:29:31 -0700 (PDT) Received: from localhost ([::1]:42216 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o4K5Z-0001ei-Lu for importer@patchew.org; Thu, 23 Jun 2022 06:29:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45534) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8z-0000qQ-D1 for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:24642) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8x-00050U-Am for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:57 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-587-kG3HHbb5PN6bmyxJ76y-Iw-1; Thu, 23 Jun 2022 05:28:51 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B94DD3AF42A8; Thu, 23 Jun 2022 09:28:50 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.33.36.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id BDD9D40C1289; Thu, 23 Jun 2022 09:28:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655976534; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=66v7PyoESFH4i8uDIErFBn9sj9Qf11DXUYqrmDqKFEE=; b=WOMe26vm8L7/kew3raw9nesoC/s5DQELshpByazSSBtvTMHdfzdxkgBotWZy88gcdfZitq zC4+ysIIcleoYYgvlyxIy5KTs6EqmHiqTw5YFrTjYiOKYLZK/GOG+Ame7oULdzwfgTif3p YDE6aDQ9lUqoz13mXwBUitUlIW57cdU= X-MC-Unique: kG3HHbb5PN6bmyxJ76y-Iw-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, huangy81@chinatelecom.cn, quintela@redhat.com, leobras@redhat.com, peterx@redhat.com Cc: jdenemar@redhat.com Subject: [PULL 28/33] migration/dirtyrate: Refactor dirty page rate calculation Date: Thu, 23 Jun 2022 10:28:05 +0100 Message-Id: <20220623092810.96234-29-dgilbert@redhat.com> In-Reply-To: <20220623092810.96234-1-dgilbert@redhat.com> References: <20220623092810.96234-1-dgilbert@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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=170.10.129.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1655980173340100001 From: Hyman Huang(=E9=BB=84=E5=8B=87) abstract out dirty log change logic into function global_dirty_log_change. abstract out dirty page rate calculation logic via dirty-ring into function vcpu_calculate_dirtyrate. abstract out mathematical dirty page rate calculation into do_calculate_dirtyrate, decouple it from DirtyStat. rename set_sample_page_period to dirty_stat_wait, which is well-understood and will be reused in dirtylimit. handle cpu hotplug/unplug scenario during measurement of dirty page rate. export util functions outside migration. Signed-off-by: Hyman Huang(=E9=BB=84=E5=8B=87) Reviewed-by: Peter Xu Message-Id: <1d65b53c19cfc7dca0114422129515055fa18fb8.1652931128.git.huangy= 81@chinatelecom.cn> Signed-off-by: Dr. David Alan Gilbert --- include/sysemu/dirtyrate.h | 28 +++++ migration/dirtyrate.c | 227 +++++++++++++++++++++++-------------- migration/dirtyrate.h | 7 +- 3 files changed, 174 insertions(+), 88 deletions(-) create mode 100644 include/sysemu/dirtyrate.h diff --git a/include/sysemu/dirtyrate.h b/include/sysemu/dirtyrate.h new file mode 100644 index 0000000000..4d3b9a4902 --- /dev/null +++ b/include/sysemu/dirtyrate.h @@ -0,0 +1,28 @@ +/* + * dirty page rate helper functions + * + * Copyright (c) 2022 CHINA TELECOM CO.,LTD. + * + * Authors: + * Hyman Huang(=E9=BB=84=E5=8B=87) + * + * 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_DIRTYRATE_H +#define QEMU_DIRTYRATE_H + +typedef struct VcpuStat { + int nvcpu; /* number of vcpu */ + DirtyRateVcpu *rates; /* array of dirty rate for each vcpu */ +} VcpuStat; + +int64_t vcpu_calculate_dirtyrate(int64_t calc_time_ms, + VcpuStat *stat, + unsigned int flag, + bool one_shot); + +void global_dirty_log_change(unsigned int flag, + bool start); +#endif diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index aace12a787..795fab5c37 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -46,7 +46,7 @@ static struct DirtyRateStat DirtyStat; static DirtyRateMeasureMode dirtyrate_mode =3D DIRTY_RATE_MEASURE_MODE_PAGE_SAMPLING; =20 -static int64_t set_sample_page_period(int64_t msec, int64_t initial_time) +static int64_t dirty_stat_wait(int64_t msec, int64_t initial_time) { int64_t current_time; =20 @@ -60,6 +60,132 @@ static int64_t set_sample_page_period(int64_t msec, int= 64_t initial_time) return msec; } =20 +static inline void record_dirtypages(DirtyPageRecord *dirty_pages, + CPUState *cpu, bool start) +{ + if (start) { + dirty_pages[cpu->cpu_index].start_pages =3D cpu->dirty_pages; + } else { + dirty_pages[cpu->cpu_index].end_pages =3D cpu->dirty_pages; + } +} + +static int64_t do_calculate_dirtyrate(DirtyPageRecord dirty_pages, + int64_t calc_time_ms) +{ + uint64_t memory_size_MB; + uint64_t increased_dirty_pages =3D + dirty_pages.end_pages - dirty_pages.start_pages; + + memory_size_MB =3D (increased_dirty_pages * TARGET_PAGE_SIZE) >> 20; + + return memory_size_MB * 1000 / calc_time_ms; +} + +void global_dirty_log_change(unsigned int flag, bool start) +{ + qemu_mutex_lock_iothread(); + if (start) { + memory_global_dirty_log_start(flag); + } else { + memory_global_dirty_log_stop(flag); + } + qemu_mutex_unlock_iothread(); +} + +/* + * global_dirty_log_sync + * 1. sync dirty log from kvm + * 2. stop dirty tracking if needed. + */ +static void global_dirty_log_sync(unsigned int flag, bool one_shot) +{ + qemu_mutex_lock_iothread(); + memory_global_dirty_log_sync(); + if (one_shot) { + memory_global_dirty_log_stop(flag); + } + qemu_mutex_unlock_iothread(); +} + +static DirtyPageRecord *vcpu_dirty_stat_alloc(VcpuStat *stat) +{ + CPUState *cpu; + DirtyPageRecord *records; + int nvcpu =3D 0; + + CPU_FOREACH(cpu) { + nvcpu++; + } + + stat->nvcpu =3D nvcpu; + stat->rates =3D g_malloc0(sizeof(DirtyRateVcpu) * nvcpu); + + records =3D g_malloc0(sizeof(DirtyPageRecord) * nvcpu); + + return records; +} + +static void vcpu_dirty_stat_collect(VcpuStat *stat, + DirtyPageRecord *records, + bool start) +{ + CPUState *cpu; + + CPU_FOREACH(cpu) { + record_dirtypages(records, cpu, start); + } +} + +int64_t vcpu_calculate_dirtyrate(int64_t calc_time_ms, + VcpuStat *stat, + unsigned int flag, + bool one_shot) +{ + DirtyPageRecord *records; + int64_t init_time_ms; + int64_t duration; + int64_t dirtyrate; + int i =3D 0; + unsigned int gen_id; + +retry: + init_time_ms =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME); + + cpu_list_lock(); + gen_id =3D cpu_list_generation_id_get(); + records =3D vcpu_dirty_stat_alloc(stat); + vcpu_dirty_stat_collect(stat, records, true); + cpu_list_unlock(); + + duration =3D dirty_stat_wait(calc_time_ms, init_time_ms); + + global_dirty_log_sync(flag, one_shot); + + cpu_list_lock(); + if (gen_id !=3D cpu_list_generation_id_get()) { + g_free(records); + g_free(stat->rates); + cpu_list_unlock(); + goto retry; + } + vcpu_dirty_stat_collect(stat, records, false); + cpu_list_unlock(); + + for (i =3D 0; i < stat->nvcpu; i++) { + dirtyrate =3D do_calculate_dirtyrate(records[i], duration); + + stat->rates[i].id =3D i; + stat->rates[i].dirty_rate =3D dirtyrate; + + trace_dirtyrate_do_calculate_vcpu(i, dirtyrate); + } + + g_free(records); + + return duration; +} + static bool is_sample_period_valid(int64_t sec) { if (sec < MIN_FETCH_DIRTYRATE_TIME_SEC || @@ -396,44 +522,6 @@ static bool compare_page_hash_info(struct RamblockDirt= yInfo *info, return true; } =20 -static inline void record_dirtypages(DirtyPageRecord *dirty_pages, - CPUState *cpu, bool start) -{ - if (start) { - dirty_pages[cpu->cpu_index].start_pages =3D cpu->dirty_pages; - } else { - dirty_pages[cpu->cpu_index].end_pages =3D cpu->dirty_pages; - } -} - -static void dirtyrate_global_dirty_log_start(void) -{ - qemu_mutex_lock_iothread(); - memory_global_dirty_log_start(GLOBAL_DIRTY_DIRTY_RATE); - qemu_mutex_unlock_iothread(); -} - -static void dirtyrate_global_dirty_log_stop(void) -{ - qemu_mutex_lock_iothread(); - memory_global_dirty_log_sync(); - memory_global_dirty_log_stop(GLOBAL_DIRTY_DIRTY_RATE); - qemu_mutex_unlock_iothread(); -} - -static int64_t do_calculate_dirtyrate_vcpu(DirtyPageRecord dirty_pages) -{ - uint64_t memory_size_MB; - int64_t time_s; - uint64_t increased_dirty_pages =3D - dirty_pages.end_pages - dirty_pages.start_pages; - - memory_size_MB =3D (increased_dirty_pages * TARGET_PAGE_SIZE) >> 20; - time_s =3D DirtyStat.calc_time; - - return memory_size_MB / time_s; -} - static inline void record_dirtypages_bitmap(DirtyPageRecord *dirty_pages, bool start) { @@ -444,11 +532,6 @@ static inline void record_dirtypages_bitmap(DirtyPageR= ecord *dirty_pages, } } =20 -static void do_calculate_dirtyrate_bitmap(DirtyPageRecord dirty_pages) -{ - DirtyStat.dirty_rate =3D do_calculate_dirtyrate_vcpu(dirty_pages); -} - static inline void dirtyrate_manual_reset_protect(void) { RAMBlock *block =3D NULL; @@ -492,71 +575,49 @@ static void calculate_dirtyrate_dirty_bitmap(struct D= irtyRateConfig config) DirtyStat.start_time =3D start_time / 1000; =20 msec =3D config.sample_period_seconds * 1000; - msec =3D set_sample_page_period(msec, start_time); + msec =3D dirty_stat_wait(msec, start_time); DirtyStat.calc_time =3D msec / 1000; =20 /* - * dirtyrate_global_dirty_log_stop do two things. + * do two things. * 1. fetch dirty bitmap from kvm * 2. stop dirty tracking */ - dirtyrate_global_dirty_log_stop(); + global_dirty_log_sync(GLOBAL_DIRTY_DIRTY_RATE, true); =20 record_dirtypages_bitmap(&dirty_pages, false); =20 - do_calculate_dirtyrate_bitmap(dirty_pages); + DirtyStat.dirty_rate =3D do_calculate_dirtyrate(dirty_pages, msec); } =20 static void calculate_dirtyrate_dirty_ring(struct DirtyRateConfig config) { - CPUState *cpu; - int64_t msec =3D 0; - int64_t start_time; + int64_t duration; uint64_t dirtyrate =3D 0; uint64_t dirtyrate_sum =3D 0; - DirtyPageRecord *dirty_pages; - int nvcpu =3D 0; int i =3D 0; =20 - CPU_FOREACH(cpu) { - nvcpu++; - } - - dirty_pages =3D malloc(sizeof(*dirty_pages) * nvcpu); - - DirtyStat.dirty_ring.nvcpu =3D nvcpu; - DirtyStat.dirty_ring.rates =3D malloc(sizeof(DirtyRateVcpu) * nvcpu); - - dirtyrate_global_dirty_log_start(); - - CPU_FOREACH(cpu) { - record_dirtypages(dirty_pages, cpu, true); - } - - start_time =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME); - DirtyStat.start_time =3D start_time / 1000; + /* start log sync */ + global_dirty_log_change(GLOBAL_DIRTY_DIRTY_RATE, true); =20 - msec =3D config.sample_period_seconds * 1000; - msec =3D set_sample_page_period(msec, start_time); - DirtyStat.calc_time =3D msec / 1000; + DirtyStat.start_time =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME) / 1000; =20 - dirtyrate_global_dirty_log_stop(); + /* calculate vcpu dirtyrate */ + duration =3D vcpu_calculate_dirtyrate(config.sample_period_seconds * 1= 000, + &DirtyStat.dirty_ring, + GLOBAL_DIRTY_DIRTY_RATE, + true); =20 - CPU_FOREACH(cpu) { - record_dirtypages(dirty_pages, cpu, false); - } + DirtyStat.calc_time =3D duration / 1000; =20 + /* calculate vm dirtyrate */ for (i =3D 0; i < DirtyStat.dirty_ring.nvcpu; i++) { - dirtyrate =3D do_calculate_dirtyrate_vcpu(dirty_pages[i]); - trace_dirtyrate_do_calculate_vcpu(i, dirtyrate); - - DirtyStat.dirty_ring.rates[i].id =3D i; + dirtyrate =3D DirtyStat.dirty_ring.rates[i].dirty_rate; DirtyStat.dirty_ring.rates[i].dirty_rate =3D dirtyrate; dirtyrate_sum +=3D dirtyrate; } =20 DirtyStat.dirty_rate =3D dirtyrate_sum; - free(dirty_pages); } =20 static void calculate_dirtyrate_sample_vm(struct DirtyRateConfig config) @@ -574,7 +635,7 @@ static void calculate_dirtyrate_sample_vm(struct DirtyR= ateConfig config) rcu_read_unlock(); =20 msec =3D config.sample_period_seconds * 1000; - msec =3D set_sample_page_period(msec, initial_time); + msec =3D dirty_stat_wait(msec, initial_time); DirtyStat.start_time =3D initial_time / 1000; DirtyStat.calc_time =3D msec / 1000; =20 diff --git a/migration/dirtyrate.h b/migration/dirtyrate.h index 69d4c5b865..594a5c0bb6 100644 --- a/migration/dirtyrate.h +++ b/migration/dirtyrate.h @@ -13,6 +13,8 @@ #ifndef QEMU_MIGRATION_DIRTYRATE_H #define QEMU_MIGRATION_DIRTYRATE_H =20 +#include "sysemu/dirtyrate.h" + /* * Sample 512 pages per GB as default. */ @@ -65,11 +67,6 @@ typedef struct SampleVMStat { uint64_t total_block_mem_MB; /* size of total sampled pages in MB */ } SampleVMStat; =20 -typedef struct VcpuStat { - int nvcpu; /* number of vcpu */ - DirtyRateVcpu *rates; /* array of dirty rate for each vcpu */ -} VcpuStat; - /* * Store calculation statistics for each measure. */ --=20 2.36.1 From nobody Tue May 21 14:34:03 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1655979158; cv=none; d=zohomail.com; s=zohoarc; b=DZ9yDqNSoo9jZ2lC9SlgPYHIKmmPuKjqoJNV4Sqrrk6A6SrEhxAh9TaVJ8x48hZUIZ8x9G3hMnM1JJR93LiZb/Slt0gXFD7PPBB/K2A+KhePeDsr0QqdXyP8MT78qtgZNXipRoGWHfHix+nvwksM55DeYFuBVb3tolu6UhZpTME= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655979158; h=Content-Type: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=+fD8EzKfyZsSjieIEW8N0I5mT8kDQQSXoBwgJL6zw9Y=; b=AxbcKjECCxqZctzpCEK9sDbkxfsGaHBNIVC5gy/nIjeX58MVl3sv7yEsbMyDSe0Dg21cPmwE8ynImtd5OQH2rpGv0WvTT8cv97bryQXksvgdInu5itlLOtD+4hU46dKbc6jH9HtNsyTxMWSMT852eITxGL+3lSMo1XHmVF1Uuqc= 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 1655979158807694.6629203595733; Thu, 23 Jun 2022 03:12:38 -0700 (PDT) Received: from localhost ([::1]:54204 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o4JpE-0006Jw-QL for importer@patchew.org; Thu, 23 Jun 2022 06:12:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45564) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J90-0000tW-Tx for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:25043) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8y-00050v-RS for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:58 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-516-L1FzNYXzOUG4DT0TsLO4ng-1; Thu, 23 Jun 2022 05:28:52 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E8F8C101E985; Thu, 23 Jun 2022 09:28:51 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.33.36.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id EADA540D2853; Thu, 23 Jun 2022 09:28:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655976536; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+fD8EzKfyZsSjieIEW8N0I5mT8kDQQSXoBwgJL6zw9Y=; b=NQ8Q3qycV7rEsFAOn5teM9Q/RaSrpqJQOD90N576V/6zsLbo2zUNGmO5JN7oQz5UVnNmWH sIAfOoZMFKRYAwtv7UbuJvP6zljIcxYuy097FJWtBE0eUzbzwiL5UILSBgKmdgcjj3Ai1U ubO0arGuBYHOsiHmaktLyBEZjIy3aL0= X-MC-Unique: L1FzNYXzOUG4DT0TsLO4ng-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, huangy81@chinatelecom.cn, quintela@redhat.com, leobras@redhat.com, peterx@redhat.com Cc: jdenemar@redhat.com Subject: [PULL 29/33] softmmu/dirtylimit: Implement vCPU dirtyrate calculation periodically Date: Thu, 23 Jun 2022 10:28:06 +0100 Message-Id: <20220623092810.96234-30-dgilbert@redhat.com> In-Reply-To: <20220623092810.96234-1-dgilbert@redhat.com> References: <20220623092810.96234-1-dgilbert@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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=170.10.133.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1655979160432100001 From: Hyman Huang(=E9=BB=84=E5=8B=87) Introduce the third method GLOBAL_DIRTY_LIMIT of dirty tracking for calculate dirtyrate periodly for dirty page rate limit. Add dirtylimit.c to implement dirtyrate calculation periodly, which will be used for dirty page rate limit. Add dirtylimit.h to export util functions for dirty page rate limit implementation. Signed-off-by: Hyman Huang(=E9=BB=84=E5=8B=87) Reviewed-by: Peter Xu Message-Id: <69a2287b9bf98a4a3d967e01091cb8f6bf80ead4.1652931128.git.huangy= 81@chinatelecom.cn> Signed-off-by: Dr. David Alan Gilbert --- include/exec/memory.h | 5 +- include/sysemu/dirtylimit.h | 22 +++++++ softmmu/dirtylimit.c | 116 ++++++++++++++++++++++++++++++++++++ softmmu/meson.build | 1 + 4 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 include/sysemu/dirtylimit.h create mode 100644 softmmu/dirtylimit.c diff --git a/include/exec/memory.h b/include/exec/memory.h index a6a0f4d8ad..bfb1de8eea 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -69,7 +69,10 @@ static inline void fuzz_dma_read_cb(size_t addr, /* Dirty tracking enabled because measuring dirty rate */ #define GLOBAL_DIRTY_DIRTY_RATE (1U << 1) =20 -#define GLOBAL_DIRTY_MASK (0x3) +/* Dirty tracking enabled because dirty limit */ +#define GLOBAL_DIRTY_LIMIT (1U << 2) + +#define GLOBAL_DIRTY_MASK (0x7) =20 extern unsigned int global_dirty_tracking; =20 diff --git a/include/sysemu/dirtylimit.h b/include/sysemu/dirtylimit.h new file mode 100644 index 0000000000..da459f03d6 --- /dev/null +++ b/include/sysemu/dirtylimit.h @@ -0,0 +1,22 @@ +/* + * Dirty page rate limit common functions + * + * Copyright (c) 2022 CHINA TELECOM CO.,LTD. + * + * Authors: + * Hyman Huang(=E9=BB=84=E5=8B=87) + * + * 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_DIRTYRLIMIT_H +#define QEMU_DIRTYRLIMIT_H + +#define DIRTYLIMIT_CALC_TIME_MS 1000 /* 1000ms */ + +int64_t vcpu_dirty_rate_get(int cpu_index); +void vcpu_dirty_rate_stat_start(void); +void vcpu_dirty_rate_stat_stop(void); +void vcpu_dirty_rate_stat_initialize(void); +void vcpu_dirty_rate_stat_finalize(void); +#endif diff --git a/softmmu/dirtylimit.c b/softmmu/dirtylimit.c new file mode 100644 index 0000000000..6102e8c76f --- /dev/null +++ b/softmmu/dirtylimit.c @@ -0,0 +1,116 @@ +/* + * Dirty page rate limit implementation code + * + * Copyright (c) 2022 CHINA TELECOM CO.,LTD. + * + * Authors: + * Hyman Huang(=E9=BB=84=E5=8B=87) + * + * 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 "qapi/error.h" +#include "qemu/main-loop.h" +#include "qapi/qapi-commands-migration.h" +#include "sysemu/dirtyrate.h" +#include "sysemu/dirtylimit.h" +#include "exec/memory.h" +#include "hw/boards.h" + +struct { + VcpuStat stat; + bool running; + QemuThread thread; +} *vcpu_dirty_rate_stat; + +static void vcpu_dirty_rate_stat_collect(void) +{ + VcpuStat stat; + int i =3D 0; + + /* calculate vcpu dirtyrate */ + vcpu_calculate_dirtyrate(DIRTYLIMIT_CALC_TIME_MS, + &stat, + GLOBAL_DIRTY_LIMIT, + false); + + for (i =3D 0; i < stat.nvcpu; i++) { + vcpu_dirty_rate_stat->stat.rates[i].id =3D i; + vcpu_dirty_rate_stat->stat.rates[i].dirty_rate =3D + stat.rates[i].dirty_rate; + } + + free(stat.rates); +} + +static void *vcpu_dirty_rate_stat_thread(void *opaque) +{ + rcu_register_thread(); + + /* start log sync */ + global_dirty_log_change(GLOBAL_DIRTY_LIMIT, true); + + while (qatomic_read(&vcpu_dirty_rate_stat->running)) { + vcpu_dirty_rate_stat_collect(); + } + + /* stop log sync */ + global_dirty_log_change(GLOBAL_DIRTY_LIMIT, false); + + rcu_unregister_thread(); + return NULL; +} + +int64_t vcpu_dirty_rate_get(int cpu_index) +{ + DirtyRateVcpu *rates =3D vcpu_dirty_rate_stat->stat.rates; + return qatomic_read(&rates[cpu_index].dirty_rate); +} + +void vcpu_dirty_rate_stat_start(void) +{ + if (qatomic_read(&vcpu_dirty_rate_stat->running)) { + return; + } + + qatomic_set(&vcpu_dirty_rate_stat->running, 1); + qemu_thread_create(&vcpu_dirty_rate_stat->thread, + "dirtyrate-stat", + vcpu_dirty_rate_stat_thread, + NULL, + QEMU_THREAD_JOINABLE); +} + +void vcpu_dirty_rate_stat_stop(void) +{ + qatomic_set(&vcpu_dirty_rate_stat->running, 0); + qemu_mutex_unlock_iothread(); + qemu_thread_join(&vcpu_dirty_rate_stat->thread); + qemu_mutex_lock_iothread(); +} + +void vcpu_dirty_rate_stat_initialize(void) +{ + MachineState *ms =3D MACHINE(qdev_get_machine()); + int max_cpus =3D ms->smp.max_cpus; + + vcpu_dirty_rate_stat =3D + g_malloc0(sizeof(*vcpu_dirty_rate_stat)); + + vcpu_dirty_rate_stat->stat.nvcpu =3D max_cpus; + vcpu_dirty_rate_stat->stat.rates =3D + g_malloc0(sizeof(DirtyRateVcpu) * max_cpus); + + vcpu_dirty_rate_stat->running =3D false; +} + +void vcpu_dirty_rate_stat_finalize(void) +{ + free(vcpu_dirty_rate_stat->stat.rates); + vcpu_dirty_rate_stat->stat.rates =3D NULL; + + free(vcpu_dirty_rate_stat); + vcpu_dirty_rate_stat =3D NULL; +} diff --git a/softmmu/meson.build b/softmmu/meson.build index 8138248661..3272af1f31 100644 --- a/softmmu/meson.build +++ b/softmmu/meson.build @@ -4,6 +4,7 @@ specific_ss.add(when: 'CONFIG_SOFTMMU', if_true: [files( 'memory.c', 'physmem.c', 'qtest.c', + 'dirtylimit.c', )]) =20 specific_ss.add(when: ['CONFIG_SOFTMMU', 'CONFIG_TCG'], if_true: [files( --=20 2.36.1 From nobody Tue May 21 14:34:03 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1655978966; cv=none; d=zohomail.com; s=zohoarc; b=JNvjE4qv6edO38T5rDYzwbKtxhNMrzY8kuhl0bdzEbilO4pZJQFkFOupk07XK2mWqGSu6Dr03aQ0T/eQFfJ2Un63opoHMaiImnIjerpDmc20WcMvdi7gvobKLaktsiPSO1E88ilCpZGSsIauhc+tEWf4FX27Kjt8aYcVYkNl5Uw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655978966; h=Content-Type: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=G5KkPhs3W9VvOQn89FxTsY+0TbY1HOXYtgWOM7Ij0ug=; b=AFjWO6VPHF0j6vuVONLcBDGWcSbTbwO0Hf6M/t4PnIxR3bzaKO3Z9CPqP1WChJlHayxJ0CjTJGf+R2lFMdT8M5yeYVqNyezCs/M1COpjNDC3p2YuGjuz1UnHAqIhYrMUIfT61YrtzPftWfHB4M2XlkFVkwmAazfxUH64EcQehz0= 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 1655978966798516.9146678654225; Thu, 23 Jun 2022 03:09:26 -0700 (PDT) Received: from localhost ([::1]:48060 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o4Jm9-0001lS-OS for importer@patchew.org; Thu, 23 Jun 2022 06:09:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45532) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8z-0000qO-7F for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:35101) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8x-00050Z-Ip for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:56 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-649-pkW_-Ek1M5C_s53zH2a-vA-1; Thu, 23 Jun 2022 05:28:53 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 240853C138AF; Thu, 23 Jun 2022 09:28:53 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.33.36.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id 27A9240D2962; Thu, 23 Jun 2022 09:28:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655976535; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=G5KkPhs3W9VvOQn89FxTsY+0TbY1HOXYtgWOM7Ij0ug=; b=bXaeuFUWQv56YXULOH+NIzliiNJG59OKjp3gMp5cLCv7oEgR5p36LDPO1ytCK2GeMT7LwL 3MUt/q/09WjPvjt3QeZgMc1JiB+ts9VQHylv6zcKULoma8s024Y/5C/3pIVKGcovLIlcpR S1LLc9XCzX0tglAvF2FnfXh1eZApGXk= X-MC-Unique: pkW_-Ek1M5C_s53zH2a-vA-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, huangy81@chinatelecom.cn, quintela@redhat.com, leobras@redhat.com, peterx@redhat.com Cc: jdenemar@redhat.com Subject: [PULL 30/33] accel/kvm/kvm-all: Introduce kvm_dirty_ring_size function Date: Thu, 23 Jun 2022 10:28:07 +0100 Message-Id: <20220623092810.96234-31-dgilbert@redhat.com> In-Reply-To: <20220623092810.96234-1-dgilbert@redhat.com> References: <20220623092810.96234-1-dgilbert@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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=170.10.129.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1655978968024100001 From: Hyman Huang(=E9=BB=84=E5=8B=87) Introduce kvm_dirty_ring_size util function to help calculate dirty ring ful time. Signed-off-by: Hyman Huang(=E9=BB=84=E5=8B=87) Acked-by: Peter Xu Message-Id: Signed-off-by: Dr. David Alan Gilbert dgilbert: Fixed up excess #endif --- accel/kvm/kvm-all.c | 5 +++++ accel/stubs/kvm-stub.c | 5 +++++ include/sysemu/kvm.h | 2 ++ 3 files changed, 12 insertions(+) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 672ed004ab..59b8ea1a05 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -2318,6 +2318,11 @@ static void query_stats_cb(StatsResultList **result,= StatsTarget target, strList *names, strList *targets, Error **errp); static void query_stats_schemas_cb(StatsSchemaList **result, Error **errp); =20 +uint32_t kvm_dirty_ring_size(void) +{ + return kvm_state->kvm_dirty_ring_size; +} + static int kvm_init(MachineState *ms) { MachineClass *mc =3D MACHINE_GET_CLASS(ms); diff --git a/accel/stubs/kvm-stub.c b/accel/stubs/kvm-stub.c index 3345882d85..2ac5f9c036 100644 --- a/accel/stubs/kvm-stub.c +++ b/accel/stubs/kvm-stub.c @@ -148,3 +148,8 @@ bool kvm_dirty_ring_enabled(void) { return false; } + +uint32_t kvm_dirty_ring_size(void) +{ + return 0; +} diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index a783c78868..efd6dee818 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -582,4 +582,6 @@ bool kvm_cpu_check_are_resettable(void); bool kvm_arch_cpu_check_are_resettable(void); =20 bool kvm_dirty_ring_enabled(void); + +uint32_t kvm_dirty_ring_size(void); #endif --=20 2.36.1 From nobody Tue May 21 14:34:03 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1655980524; cv=none; d=zohomail.com; s=zohoarc; b=m56mRsr+QrNGgpUzqevz5X2+ixZBW7zdDwpKiOjuQQh3FLkK8dZGclDYzs2/zVVJ7Ha+5emQNZmO7OKlvK2XtMUJZhio4rS3pn1t2CQzuQaD05UPTOrDo7EDN0uBW6dWhi7XPwav8pp4267kEEgZfXLrMTU+LKW7F2YWAyvznlA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655980524; h=Content-Type: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=4zaK4XjYkrgZyedXAOkQQiejEv8zKTgTVcrHGJYtipY=; b=K48DxYSMXy8Zr3srKYeKsVsyuvS571Iy+VSKq9VEGbfYSEL1M/LwRiOfQWvDJofZqs9z2LDV0C/TLocD28bVapzhfGYi9t24xyETdIkidvq5y5tJNC6Yw/XfzbmAr1eav+X3tCG8R5+NZlbLmAAk37B/y5zMZoiKN53f0zpey48= 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 1655980524029478.30314471307963; Thu, 23 Jun 2022 03:35:24 -0700 (PDT) Received: from localhost ([::1]:49040 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o4KBG-0006Tf-Ep for importer@patchew.org; Thu, 23 Jun 2022 06:35:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45592) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J92-0000vJ-FA for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:29:01 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:24901) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J90-00051I-6J for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:29:00 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-186-9bCKz8YNMn2uNHHa9bppag-1; Thu, 23 Jun 2022 05:28:54 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5402E101E986; Thu, 23 Jun 2022 09:28:54 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.33.36.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id 57C8740D2962; Thu, 23 Jun 2022 09:28:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655976537; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4zaK4XjYkrgZyedXAOkQQiejEv8zKTgTVcrHGJYtipY=; b=XJB2I4aUJUf7Vmrwh5l5HiVE57k69Vy+jbaHSuNmsY/yuR9FUNhFWB2yH4bT+I5Vxgq13x AvADK0gQYgCpVj/jMsz3pTAkHuC6Pq6Nh1NLPuPtd797tkd31YEElWtfNr5JvGUJVdSRNQ dWB1uYiD3ip8YPHWoTb0uIIkXP2HiCU= X-MC-Unique: 9bCKz8YNMn2uNHHa9bppag-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, huangy81@chinatelecom.cn, quintela@redhat.com, leobras@redhat.com, peterx@redhat.com Cc: jdenemar@redhat.com Subject: [PULL 31/33] softmmu/dirtylimit: Implement virtual CPU throttle Date: Thu, 23 Jun 2022 10:28:08 +0100 Message-Id: <20220623092810.96234-32-dgilbert@redhat.com> In-Reply-To: <20220623092810.96234-1-dgilbert@redhat.com> References: <20220623092810.96234-1-dgilbert@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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=170.10.133.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1655980525636100001 From: Hyman Huang(=E9=BB=84=E5=8B=87) Setup a negative feedback system when vCPU thread handling KVM_EXIT_DIRTY_RING_FULL exit by introducing throttle_us_per_full field in struct CPUState. Sleep throttle_us_per_full microseconds to throttle vCPU if dirtylimit is in service. Signed-off-by: Hyman Huang(=E9=BB=84=E5=8B=87) Reviewed-by: Peter Xu Message-Id: Signed-off-by: Dr. David Alan Gilbert --- accel/kvm/kvm-all.c | 20 ++- include/hw/core/cpu.h | 6 + include/sysemu/dirtylimit.h | 15 ++ softmmu/dirtylimit.c | 291 ++++++++++++++++++++++++++++++++++++ softmmu/trace-events | 7 + 5 files changed, 338 insertions(+), 1 deletion(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 59b8ea1a05..18e67af833 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -45,6 +45,7 @@ #include "qemu/guest-random.h" #include "sysemu/hw_accel.h" #include "kvm-cpus.h" +#include "sysemu/dirtylimit.h" =20 #include "hw/boards.h" #include "monitor/stats.h" @@ -477,6 +478,7 @@ int kvm_init_vcpu(CPUState *cpu, Error **errp) cpu->kvm_state =3D s; cpu->vcpu_dirty =3D true; cpu->dirty_pages =3D 0; + cpu->throttle_us_per_full =3D 0; =20 mmap_size =3D kvm_ioctl(s, KVM_GET_VCPU_MMAP_SIZE, 0); if (mmap_size < 0) { @@ -1470,6 +1472,11 @@ static void *kvm_dirty_ring_reaper_thread(void *data) */ sleep(1); =20 + /* keep sleeping so that dirtylimit not be interfered by reaper */ + if (dirtylimit_in_service()) { + continue; + } + trace_kvm_dirty_ring_reaper("wakeup"); r->reaper_state =3D KVM_DIRTY_RING_REAPER_REAPING; =20 @@ -2975,8 +2982,19 @@ int kvm_cpu_exec(CPUState *cpu) */ trace_kvm_dirty_ring_full(cpu->cpu_index); qemu_mutex_lock_iothread(); - kvm_dirty_ring_reap(kvm_state, NULL); + /* + * We throttle vCPU by making it sleep once it exit from kernel + * due to dirty ring full. In the dirtylimit scenario, reaping + * all vCPUs after a single vCPU dirty ring get full result in + * the miss of sleep, so just reap the ring-fulled vCPU. + */ + if (dirtylimit_in_service()) { + kvm_dirty_ring_reap(kvm_state, cpu); + } else { + kvm_dirty_ring_reap(kvm_state, NULL); + } qemu_mutex_unlock_iothread(); + dirtylimit_vcpu_execute(cpu); ret =3D 0; break; case KVM_EXIT_SYSTEM_EVENT: diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 996f94059f..500503da13 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -418,6 +418,12 @@ struct CPUState { */ bool throttle_thread_scheduled; =20 + /* + * Sleep throttle_us_per_full microseconds once dirty ring is full + * if dirty page rate limit is enabled. + */ + int64_t throttle_us_per_full; + bool ignore_memory_transaction_failures; =20 /* Used for user-only emulation of prctl(PR_SET_UNALIGN). */ diff --git a/include/sysemu/dirtylimit.h b/include/sysemu/dirtylimit.h index da459f03d6..8d2c1f3a6b 100644 --- a/include/sysemu/dirtylimit.h +++ b/include/sysemu/dirtylimit.h @@ -19,4 +19,19 @@ void vcpu_dirty_rate_stat_start(void); void vcpu_dirty_rate_stat_stop(void); void vcpu_dirty_rate_stat_initialize(void); void vcpu_dirty_rate_stat_finalize(void); + +void dirtylimit_state_lock(void); +void dirtylimit_state_unlock(void); +void dirtylimit_state_initialize(void); +void dirtylimit_state_finalize(void); +bool dirtylimit_in_service(void); +bool dirtylimit_vcpu_index_valid(int cpu_index); +void dirtylimit_process(void); +void dirtylimit_change(bool start); +void dirtylimit_set_vcpu(int cpu_index, + uint64_t quota, + bool enable); +void dirtylimit_set_all(uint64_t quota, + bool enable); +void dirtylimit_vcpu_execute(CPUState *cpu); #endif diff --git a/softmmu/dirtylimit.c b/softmmu/dirtylimit.c index 6102e8c76f..76d0b44e02 100644 --- a/softmmu/dirtylimit.c +++ b/softmmu/dirtylimit.c @@ -18,6 +18,26 @@ #include "sysemu/dirtylimit.h" #include "exec/memory.h" #include "hw/boards.h" +#include "sysemu/kvm.h" +#include "trace.h" + +/* + * Dirtylimit stop working if dirty page rate error + * value less than DIRTYLIMIT_TOLERANCE_RANGE + */ +#define DIRTYLIMIT_TOLERANCE_RANGE 25 /* MB/s */ +/* + * Plus or minus vcpu sleep time linearly if dirty + * page rate error value percentage over + * DIRTYLIMIT_LINEAR_ADJUSTMENT_PCT. + * Otherwise, plus or minus a fixed vcpu sleep time. + */ +#define DIRTYLIMIT_LINEAR_ADJUSTMENT_PCT 50 +/* + * Max vcpu sleep time percentage during a cycle + * composed of dirty ring full and sleep time. + */ +#define DIRTYLIMIT_THROTTLE_PCT_MAX 99 =20 struct { VcpuStat stat; @@ -25,6 +45,30 @@ struct { QemuThread thread; } *vcpu_dirty_rate_stat; =20 +typedef struct VcpuDirtyLimitState { + int cpu_index; + bool enabled; + /* + * Quota dirty page rate, unit is MB/s + * zero if not enabled. + */ + uint64_t quota; +} VcpuDirtyLimitState; + +struct { + VcpuDirtyLimitState *states; + /* Max cpus number configured by user */ + int max_cpus; + /* Number of vcpu under dirtylimit */ + int limited_nvcpu; +} *dirtylimit_state; + +/* protect dirtylimit_state */ +static QemuMutex dirtylimit_mutex; + +/* dirtylimit thread quit if dirtylimit_quit is true */ +static bool dirtylimit_quit; + static void vcpu_dirty_rate_stat_collect(void) { VcpuStat stat; @@ -54,6 +98,9 @@ static void *vcpu_dirty_rate_stat_thread(void *opaque) =20 while (qatomic_read(&vcpu_dirty_rate_stat->running)) { vcpu_dirty_rate_stat_collect(); + if (dirtylimit_in_service()) { + dirtylimit_process(); + } } =20 /* stop log sync */ @@ -86,9 +133,11 @@ void vcpu_dirty_rate_stat_start(void) void vcpu_dirty_rate_stat_stop(void) { qatomic_set(&vcpu_dirty_rate_stat->running, 0); + dirtylimit_state_unlock(); qemu_mutex_unlock_iothread(); qemu_thread_join(&vcpu_dirty_rate_stat->thread); qemu_mutex_lock_iothread(); + dirtylimit_state_lock(); } =20 void vcpu_dirty_rate_stat_initialize(void) @@ -114,3 +163,245 @@ void vcpu_dirty_rate_stat_finalize(void) free(vcpu_dirty_rate_stat); vcpu_dirty_rate_stat =3D NULL; } + +void dirtylimit_state_lock(void) +{ + qemu_mutex_lock(&dirtylimit_mutex); +} + +void dirtylimit_state_unlock(void) +{ + qemu_mutex_unlock(&dirtylimit_mutex); +} + +static void +__attribute__((__constructor__)) dirtylimit_mutex_init(void) +{ + qemu_mutex_init(&dirtylimit_mutex); +} + +static inline VcpuDirtyLimitState *dirtylimit_vcpu_get_state(int cpu_index) +{ + return &dirtylimit_state->states[cpu_index]; +} + +void dirtylimit_state_initialize(void) +{ + MachineState *ms =3D MACHINE(qdev_get_machine()); + int max_cpus =3D ms->smp.max_cpus; + int i; + + dirtylimit_state =3D g_malloc0(sizeof(*dirtylimit_state)); + + dirtylimit_state->states =3D + g_malloc0(sizeof(VcpuDirtyLimitState) * max_cpus); + + for (i =3D 0; i < max_cpus; i++) { + dirtylimit_state->states[i].cpu_index =3D i; + } + + dirtylimit_state->max_cpus =3D max_cpus; + trace_dirtylimit_state_initialize(max_cpus); +} + +void dirtylimit_state_finalize(void) +{ + free(dirtylimit_state->states); + dirtylimit_state->states =3D NULL; + + free(dirtylimit_state); + dirtylimit_state =3D NULL; + + trace_dirtylimit_state_finalize(); +} + +bool dirtylimit_in_service(void) +{ + return !!dirtylimit_state; +} + +bool dirtylimit_vcpu_index_valid(int cpu_index) +{ + MachineState *ms =3D MACHINE(qdev_get_machine()); + + return !(cpu_index < 0 || + cpu_index >=3D ms->smp.max_cpus); +} + +static inline int64_t dirtylimit_dirty_ring_full_time(uint64_t dirtyrate) +{ + static uint64_t max_dirtyrate; + uint32_t dirty_ring_size =3D kvm_dirty_ring_size(); + uint64_t dirty_ring_size_meory_MB =3D + dirty_ring_size * TARGET_PAGE_SIZE >> 20; + + if (max_dirtyrate < dirtyrate) { + max_dirtyrate =3D dirtyrate; + } + + return dirty_ring_size_meory_MB * 1000000 / max_dirtyrate; +} + +static inline bool dirtylimit_done(uint64_t quota, + uint64_t current) +{ + uint64_t min, max; + + min =3D MIN(quota, current); + max =3D MAX(quota, current); + + return ((max - min) <=3D DIRTYLIMIT_TOLERANCE_RANGE) ? true : false; +} + +static inline bool +dirtylimit_need_linear_adjustment(uint64_t quota, + uint64_t current) +{ + uint64_t min, max; + + min =3D MIN(quota, current); + max =3D MAX(quota, current); + + return ((max - min) * 100 / max) > DIRTYLIMIT_LINEAR_ADJUSTMENT_PCT; +} + +static void dirtylimit_set_throttle(CPUState *cpu, + uint64_t quota, + uint64_t current) +{ + int64_t ring_full_time_us =3D 0; + uint64_t sleep_pct =3D 0; + uint64_t throttle_us =3D 0; + + if (current =3D=3D 0) { + cpu->throttle_us_per_full =3D 0; + return; + } + + ring_full_time_us =3D dirtylimit_dirty_ring_full_time(current); + + if (dirtylimit_need_linear_adjustment(quota, current)) { + if (quota < current) { + sleep_pct =3D (current - quota) * 100 / current; + throttle_us =3D + ring_full_time_us * sleep_pct / (double)(100 - sleep_pct); + cpu->throttle_us_per_full +=3D throttle_us; + } else { + sleep_pct =3D (quota - current) * 100 / quota; + throttle_us =3D + ring_full_time_us * sleep_pct / (double)(100 - sleep_pct); + cpu->throttle_us_per_full -=3D throttle_us; + } + + trace_dirtylimit_throttle_pct(cpu->cpu_index, + sleep_pct, + throttle_us); + } else { + if (quota < current) { + cpu->throttle_us_per_full +=3D ring_full_time_us / 10; + } else { + cpu->throttle_us_per_full -=3D ring_full_time_us / 10; + } + } + + /* + * TODO: in the big kvm_dirty_ring_size case (eg: 65536, or other scen= ario), + * current dirty page rate may never reach the quota, we should = stop + * increasing sleep time? + */ + cpu->throttle_us_per_full =3D MIN(cpu->throttle_us_per_full, + ring_full_time_us * DIRTYLIMIT_THROTTLE_PCT_MAX); + + cpu->throttle_us_per_full =3D MAX(cpu->throttle_us_per_full, 0); +} + +static void dirtylimit_adjust_throttle(CPUState *cpu) +{ + uint64_t quota =3D 0; + uint64_t current =3D 0; + int cpu_index =3D cpu->cpu_index; + + quota =3D dirtylimit_vcpu_get_state(cpu_index)->quota; + current =3D vcpu_dirty_rate_get(cpu_index); + + if (!dirtylimit_done(quota, current)) { + dirtylimit_set_throttle(cpu, quota, current); + } + + return; +} + +void dirtylimit_process(void) +{ + CPUState *cpu; + + if (!qatomic_read(&dirtylimit_quit)) { + dirtylimit_state_lock(); + + if (!dirtylimit_in_service()) { + dirtylimit_state_unlock(); + return; + } + + CPU_FOREACH(cpu) { + if (!dirtylimit_vcpu_get_state(cpu->cpu_index)->enabled) { + continue; + } + dirtylimit_adjust_throttle(cpu); + } + dirtylimit_state_unlock(); + } +} + +void dirtylimit_change(bool start) +{ + if (start) { + qatomic_set(&dirtylimit_quit, 0); + } else { + qatomic_set(&dirtylimit_quit, 1); + } +} + +void dirtylimit_set_vcpu(int cpu_index, + uint64_t quota, + bool enable) +{ + trace_dirtylimit_set_vcpu(cpu_index, quota); + + if (enable) { + dirtylimit_state->states[cpu_index].quota =3D quota; + if (!dirtylimit_vcpu_get_state(cpu_index)->enabled) { + dirtylimit_state->limited_nvcpu++; + } + } else { + dirtylimit_state->states[cpu_index].quota =3D 0; + if (dirtylimit_state->states[cpu_index].enabled) { + dirtylimit_state->limited_nvcpu--; + } + } + + dirtylimit_state->states[cpu_index].enabled =3D enable; +} + +void dirtylimit_set_all(uint64_t quota, + bool enable) +{ + MachineState *ms =3D MACHINE(qdev_get_machine()); + int max_cpus =3D ms->smp.max_cpus; + int i; + + for (i =3D 0; i < max_cpus; i++) { + dirtylimit_set_vcpu(i, quota, enable); + } +} + +void dirtylimit_vcpu_execute(CPUState *cpu) +{ + if (dirtylimit_in_service() && + dirtylimit_vcpu_get_state(cpu->cpu_index)->enabled && + cpu->throttle_us_per_full) { + trace_dirtylimit_vcpu_execute(cpu->cpu_index, + cpu->throttle_us_per_full); + usleep(cpu->throttle_us_per_full); + } +} diff --git a/softmmu/trace-events b/softmmu/trace-events index 9c88887b3c..22606dc27b 100644 --- a/softmmu/trace-events +++ b/softmmu/trace-events @@ -31,3 +31,10 @@ runstate_set(int current_state, const char *current_stat= e_str, int new_state, co system_wakeup_request(int reason) "reason=3D%d" qemu_system_shutdown_request(int reason) "reason=3D%d" qemu_system_powerdown_request(void) "" + +#dirtylimit.c +dirtylimit_state_initialize(int max_cpus) "dirtylimit state initialize: ma= x cpus %d" +dirtylimit_state_finalize(void) +dirtylimit_throttle_pct(int cpu_index, uint64_t pct, int64_t time_us) "CPU= [%d] throttle percent: %" PRIu64 ", throttle adjust time %"PRIi64 " us" +dirtylimit_set_vcpu(int cpu_index, uint64_t quota) "CPU[%d] set dirty page= rate limit %"PRIu64 +dirtylimit_vcpu_execute(int cpu_index, int64_t sleep_time_us) "CPU[%d] sle= ep %"PRIi64 " us" --=20 2.36.1 From nobody Tue May 21 14:34:03 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1655978195; cv=none; d=zohomail.com; s=zohoarc; b=RfNJlztQNuj0W+5Swpr+GnIgDaKU65+q33AoOLhKPQ2koWp74bKhrrs1ejMaYBeQAlRpnymx6QJLhg37wyR/zEUR6DNNGWWBhxPj4q9kzDBb4U7/SZu+NupaCoSPPlTYPgxHXwKn7T7G/7m8sGYzhY2qSU/t7+6pSKSc/ZHLmh4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655978195; h=Content-Type: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=Pp4Me2eDe7bsV/UvhVVYE1AU87VI+nsWkt7eVDLn984=; b=Ic81OaObOv7UEDACMgpN91fe5DaJm96Vz7DxEmOWyJAHUM0QVxzTYnP4LzZRerBs/yhIzl/IkP4r9nfytzOzb2T70XNq+1BeUqukxdnIIC7t59L+P25jvRlZuud6TrvSCEYDKBibW6Ft+IAMge7/lq6ITHtbweustlg6hs670Tc= 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 1655978195090505.7134848576246; Thu, 23 Jun 2022 02:56:35 -0700 (PDT) Received: from localhost ([::1]:53864 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o4JZh-0002za-BA for importer@patchew.org; Thu, 23 Jun 2022 05:56:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45584) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J91-0000uo-Vq for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:29:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:27633) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J8z-00051E-Pj for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:28:59 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-568-y_fQ3jpbOxi5ELc3fslqnA-1; Thu, 23 Jun 2022 05:28:55 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 84B3380174C; Thu, 23 Jun 2022 09:28:55 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.33.36.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8967040D282F; Thu, 23 Jun 2022 09:28:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655976537; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Pp4Me2eDe7bsV/UvhVVYE1AU87VI+nsWkt7eVDLn984=; b=XDTe45yh4w0i5swxH2vUJkWoqGsvJo7OenAGOK4tHpQA8fEX6GU3EEfARdF2x1l7s1ViP3 Ud/Nx/OiBPGcDfRShzkwI85WaXyuX0Z9CFjuFVy9A2MARavvJY7V1nWQgSboSZrX/GxsrD O+uYmO1RKAIPjBEikMGfyZUPRNZTiow= X-MC-Unique: y_fQ3jpbOxi5ELc3fslqnA-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, huangy81@chinatelecom.cn, quintela@redhat.com, leobras@redhat.com, peterx@redhat.com Cc: jdenemar@redhat.com Subject: [PULL 32/33] softmmu/dirtylimit: Implement dirty page rate limit Date: Thu, 23 Jun 2022 10:28:09 +0100 Message-Id: <20220623092810.96234-33-dgilbert@redhat.com> In-Reply-To: <20220623092810.96234-1-dgilbert@redhat.com> References: <20220623092810.96234-1-dgilbert@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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=170.10.133.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1655978195763100001 From: Hyman Huang(=E9=BB=84=E5=8B=87) Implement dirtyrate calculation periodically basing on dirty-ring and throttle virtual CPU until it reachs the quota dirty page rate given by user. Introduce qmp commands "set-vcpu-dirty-limit", "cancel-vcpu-dirty-limit", "query-vcpu-dirty-limit" to enable, disable, query dirty page limit for virtual CPU. Meanwhile, introduce corresponding hmp commands "set_vcpu_dirty_limit", "cancel_vcpu_dirty_limit", "info vcpu_dirty_limit" so the feature can be more usable. "query-vcpu-dirty-limit" success depends on enabling dirty page rate limit, so just add it to the list of skipped command to ensure qmp-cmd-test run successfully. Signed-off-by: Hyman Huang(=E9=BB=84=E5=8B=87) Acked-by: Markus Armbruster Reviewed-by: Peter Xu Message-Id: <80195172e377e3d96394b5b94425098260380bfa.1652931128.git.huangy= 81@chinatelecom.cn> Signed-off-by: Dr. David Alan Gilbert --- hmp-commands-info.hx | 13 +++ hmp-commands.hx | 32 ++++++ include/monitor/hmp.h | 3 + qapi/migration.json | 80 +++++++++++++++ softmmu/dirtylimit.c | 194 +++++++++++++++++++++++++++++++++++++ tests/qtest/qmp-cmd-test.c | 2 + 6 files changed, 324 insertions(+) diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index 3ffa24bd67..188d9ece3b 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -865,6 +865,19 @@ SRST Display the vcpu dirty rate information. ERST =20 + { + .name =3D "vcpu_dirty_limit", + .args_type =3D "", + .params =3D "", + .help =3D "show dirty page limit information of all vCPU", + .cmd =3D hmp_info_vcpu_dirty_limit, + }, + +SRST + ``info vcpu_dirty_limit`` + Display the vcpu dirty page limit information. +ERST + #if defined(TARGET_I386) { .name =3D "sgx", diff --git a/hmp-commands.hx b/hmp-commands.hx index c9d465735a..182e639d14 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1768,3 +1768,35 @@ ERST "\n\t\t\t -b to specify dirty bitmap as method of ca= lculation)", .cmd =3D hmp_calc_dirty_rate, }, + +SRST +``set_vcpu_dirty_limit`` + Set dirty page rate limit on virtual CPU, the information about all the + virtual CPU dirty limit status can be observed with ``info vcpu_dirty_li= mit`` + command. +ERST + + { + .name =3D "set_vcpu_dirty_limit", + .args_type =3D "dirty_rate:l,cpu_index:l?", + .params =3D "dirty_rate [cpu_index]", + .help =3D "set dirty page rate limit, use cpu_index to set l= imit" + "\n\t\t\t\t\t on a specified virtual cpu", + .cmd =3D hmp_set_vcpu_dirty_limit, + }, + +SRST +``cancel_vcpu_dirty_limit`` + Cancel dirty page rate limit on virtual CPU, the information about all t= he + virtual CPU dirty limit status can be observed with ``info vcpu_dirty_li= mit`` + command. +ERST + + { + .name =3D "cancel_vcpu_dirty_limit", + .args_type =3D "cpu_index:l?", + .params =3D "[cpu_index]", + .help =3D "cancel dirty page rate limit, use cpu_index to ca= ncel" + "\n\t\t\t\t\t limit on a specified virtual cpu", + .cmd =3D hmp_cancel_vcpu_dirty_limit, + }, diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h index 2e89a97bd6..a618eb1e4e 100644 --- a/include/monitor/hmp.h +++ b/include/monitor/hmp.h @@ -131,6 +131,9 @@ void hmp_replay_delete_break(Monitor *mon, const QDict = *qdict); void hmp_replay_seek(Monitor *mon, const QDict *qdict); void hmp_info_dirty_rate(Monitor *mon, const QDict *qdict); void hmp_calc_dirty_rate(Monitor *mon, const QDict *qdict); +void hmp_set_vcpu_dirty_limit(Monitor *mon, const QDict *qdict); +void hmp_cancel_vcpu_dirty_limit(Monitor *mon, const QDict *qdict); +void hmp_info_vcpu_dirty_limit(Monitor *mon, const QDict *qdict); void hmp_human_readable_text_helper(Monitor *mon, HumanReadableText *(*qmp_handler)(Erro= r **)); void hmp_info_stats(Monitor *mon, const QDict *qdict); diff --git a/qapi/migration.json b/qapi/migration.json index 7102e474a6..e552ee4f43 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -1868,6 +1868,86 @@ ## { 'command': 'query-dirty-rate', 'returns': 'DirtyRateInfo' } =20 +## +# @DirtyLimitInfo: +# +# Dirty page rate limit information of a virtual CPU. +# +# @cpu-index: index of a virtual CPU. +# +# @limit-rate: upper limit of dirty page rate (MB/s) for a virtual +# CPU, 0 means unlimited. +# +# @current-rate: current dirty page rate (MB/s) for a virtual CPU. +# +# Since: 7.1 +# +## +{ 'struct': 'DirtyLimitInfo', + 'data': { 'cpu-index': 'int', + 'limit-rate': 'uint64', + 'current-rate': 'uint64' } } + +## +# @set-vcpu-dirty-limit: +# +# Set the upper limit of dirty page rate for virtual CPUs. +# +# Requires KVM with accelerator property "dirty-ring-size" set. +# A virtual CPU's dirty page rate is a measure of its memory load. +# To observe dirty page rates, use @calc-dirty-rate. +# +# @cpu-index: index of a virtual CPU, default is all. +# +# @dirty-rate: upper limit of dirty page rate (MB/s) for virtual CPUs. +# +# Since: 7.1 +# +# Example: +# {"execute": "set-vcpu-dirty-limit"} +# "arguments": { "dirty-rate": 200, +# "cpu-index": 1 } } +# +## +{ 'command': 'set-vcpu-dirty-limit', + 'data': { '*cpu-index': 'int', + 'dirty-rate': 'uint64' } } + +## +# @cancel-vcpu-dirty-limit: +# +# Cancel the upper limit of dirty page rate for virtual CPUs. +# +# Cancel the dirty page limit for the vCPU which has been set with +# set-vcpu-dirty-limit command. Note that this command requires +# support from dirty ring, same as the "set-vcpu-dirty-limit". +# +# @cpu-index: index of a virtual CPU, default is all. +# +# Since: 7.1 +# +# Example: +# {"execute": "cancel-vcpu-dirty-limit"} +# "arguments": { "cpu-index": 1 } } +# +## +{ 'command': 'cancel-vcpu-dirty-limit', + 'data': { '*cpu-index': 'int'} } + +## +# @query-vcpu-dirty-limit: +# +# Returns information about virtual CPU dirty page rate limits, if any. +# +# Since: 7.1 +# +# Example: +# {"execute": "query-vcpu-dirty-limit"} +# +## +{ 'command': 'query-vcpu-dirty-limit', + 'returns': [ 'DirtyLimitInfo' ] } + ## # @snapshot-save: # diff --git a/softmmu/dirtylimit.c b/softmmu/dirtylimit.c index 76d0b44e02..c5ea24120e 100644 --- a/softmmu/dirtylimit.c +++ b/softmmu/dirtylimit.c @@ -14,8 +14,12 @@ #include "qapi/error.h" #include "qemu/main-loop.h" #include "qapi/qapi-commands-migration.h" +#include "qapi/qmp/qdict.h" +#include "qapi/error.h" #include "sysemu/dirtyrate.h" #include "sysemu/dirtylimit.h" +#include "monitor/hmp.h" +#include "monitor/monitor.h" #include "exec/memory.h" #include "hw/boards.h" #include "sysemu/kvm.h" @@ -405,3 +409,193 @@ void dirtylimit_vcpu_execute(CPUState *cpu) usleep(cpu->throttle_us_per_full); } } + +static void dirtylimit_init(void) +{ + dirtylimit_state_initialize(); + dirtylimit_change(true); + vcpu_dirty_rate_stat_initialize(); + vcpu_dirty_rate_stat_start(); +} + +static void dirtylimit_cleanup(void) +{ + vcpu_dirty_rate_stat_stop(); + vcpu_dirty_rate_stat_finalize(); + dirtylimit_change(false); + dirtylimit_state_finalize(); +} + +void qmp_cancel_vcpu_dirty_limit(bool has_cpu_index, + int64_t cpu_index, + Error **errp) +{ + if (!kvm_enabled() || !kvm_dirty_ring_enabled()) { + return; + } + + if (has_cpu_index && !dirtylimit_vcpu_index_valid(cpu_index)) { + error_setg(errp, "incorrect cpu index specified"); + return; + } + + if (!dirtylimit_in_service()) { + return; + } + + dirtylimit_state_lock(); + + if (has_cpu_index) { + dirtylimit_set_vcpu(cpu_index, 0, false); + } else { + dirtylimit_set_all(0, false); + } + + if (!dirtylimit_state->limited_nvcpu) { + dirtylimit_cleanup(); + } + + dirtylimit_state_unlock(); +} + +void hmp_cancel_vcpu_dirty_limit(Monitor *mon, const QDict *qdict) +{ + int64_t cpu_index =3D qdict_get_try_int(qdict, "cpu_index", -1); + Error *err =3D NULL; + + qmp_cancel_vcpu_dirty_limit(!!(cpu_index !=3D -1), cpu_index, &err); + if (err) { + hmp_handle_error(mon, err); + return; + } + + monitor_printf(mon, "[Please use 'info vcpu_dirty_limit' to query " + "dirty limit for virtual CPU]\n"); +} + +void qmp_set_vcpu_dirty_limit(bool has_cpu_index, + int64_t cpu_index, + uint64_t dirty_rate, + Error **errp) +{ + if (!kvm_enabled() || !kvm_dirty_ring_enabled()) { + error_setg(errp, "dirty page limit feature requires KVM with" + " accelerator property 'dirty-ring-size' set'"); + return; + } + + if (has_cpu_index && !dirtylimit_vcpu_index_valid(cpu_index)) { + error_setg(errp, "incorrect cpu index specified"); + return; + } + + if (!dirty_rate) { + qmp_cancel_vcpu_dirty_limit(has_cpu_index, cpu_index, errp); + return; + } + + dirtylimit_state_lock(); + + if (!dirtylimit_in_service()) { + dirtylimit_init(); + } + + if (has_cpu_index) { + dirtylimit_set_vcpu(cpu_index, dirty_rate, true); + } else { + dirtylimit_set_all(dirty_rate, true); + } + + dirtylimit_state_unlock(); +} + +void hmp_set_vcpu_dirty_limit(Monitor *mon, const QDict *qdict) +{ + int64_t dirty_rate =3D qdict_get_int(qdict, "dirty_rate"); + int64_t cpu_index =3D qdict_get_try_int(qdict, "cpu_index", -1); + Error *err =3D NULL; + + qmp_set_vcpu_dirty_limit(!!(cpu_index !=3D -1), cpu_index, dirty_rate,= &err); + if (err) { + hmp_handle_error(mon, err); + return; + } + + monitor_printf(mon, "[Please use 'info vcpu_dirty_limit' to query " + "dirty limit for virtual CPU]\n"); +} + +static struct DirtyLimitInfo *dirtylimit_query_vcpu(int cpu_index) +{ + DirtyLimitInfo *info =3D NULL; + + info =3D g_malloc0(sizeof(*info)); + info->cpu_index =3D cpu_index; + info->limit_rate =3D dirtylimit_vcpu_get_state(cpu_index)->quota; + info->current_rate =3D vcpu_dirty_rate_get(cpu_index); + + return info; +} + +static struct DirtyLimitInfoList *dirtylimit_query_all(void) +{ + int i, index; + DirtyLimitInfo *info =3D NULL; + DirtyLimitInfoList *head =3D NULL, **tail =3D &head; + + dirtylimit_state_lock(); + + if (!dirtylimit_in_service()) { + dirtylimit_state_unlock(); + return NULL; + } + + for (i =3D 0; i < dirtylimit_state->max_cpus; i++) { + index =3D dirtylimit_state->states[i].cpu_index; + if (dirtylimit_vcpu_get_state(index)->enabled) { + info =3D dirtylimit_query_vcpu(index); + QAPI_LIST_APPEND(tail, info); + } + } + + dirtylimit_state_unlock(); + + return head; +} + +struct DirtyLimitInfoList *qmp_query_vcpu_dirty_limit(Error **errp) +{ + if (!dirtylimit_in_service()) { + return NULL; + } + + return dirtylimit_query_all(); +} + +void hmp_info_vcpu_dirty_limit(Monitor *mon, const QDict *qdict) +{ + DirtyLimitInfoList *limit, *head, *info =3D NULL; + Error *err =3D NULL; + + if (!dirtylimit_in_service()) { + monitor_printf(mon, "Dirty page limit not enabled!\n"); + return; + } + + info =3D qmp_query_vcpu_dirty_limit(&err); + if (err) { + hmp_handle_error(mon, err); + return; + } + + head =3D info; + for (limit =3D head; limit !=3D NULL; limit =3D limit->next) { + monitor_printf(mon, "vcpu[%"PRIi64"], limit rate %"PRIi64 " (MB/s)= ," + " current rate %"PRIi64 " (MB/s)\n", + limit->value->cpu_index, + limit->value->limit_rate, + limit->value->current_rate); + } + + g_free(info); +} diff --git a/tests/qtest/qmp-cmd-test.c b/tests/qtest/qmp-cmd-test.c index 056b40e67f..af00712458 100644 --- a/tests/qtest/qmp-cmd-test.c +++ b/tests/qtest/qmp-cmd-test.c @@ -110,6 +110,8 @@ static bool query_is_ignored(const char *cmd) "query-sev-capabilities", "query-sgx", "query-sgx-capabilities", + /* Success depends on enabling dirty page rate limit */ + "query-vcpu-dirty-limit", NULL }; int i; --=20 2.36.1 From nobody Tue May 21 14:34:03 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1655979666; cv=none; d=zohomail.com; s=zohoarc; b=hvUFIMkB9D+O+8YABiDseBMTt7QkI1GErytgsgWuV9B/mQ4Xu5t5rbBqcJ6Hcfn5FrHUFGwLuH/avzFrarHjGzuH4rnYFgFoJ5g5p54DQ9yUZcwqQNAY74a0xFTIOD7d6nDDA2OVTeyMLvIQArDTjdzPXmkPV+wztEdLt3xj2cc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1655979666; h=Content-Type: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=02bsooRW+muNZAOrkp1FfrnPEavTqzUd2wxFwS1LpsA=; b=J1JI6M0FCA8AtIFaFYMNn51jvu+YItR3DEjuP/HJJ65w/NpT2zuvaFQpMEhxP6kGfzJW9VsKZzXgG6HvQ46mBS099ugumxZqWajVzBnGfUhfhmPIMzCU7lU0Omai7maalgUc6jUtu4MWkOi+1W390f/N7X/Hpw66koliZ6ms0YU= 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 1655979666800354.5854279881805; Thu, 23 Jun 2022 03:21:06 -0700 (PDT) Received: from localhost ([::1]:34468 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o4JxR-0004Lg-Ki for importer@patchew.org; Thu, 23 Jun 2022 06:21:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45616) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J93-0000wV-DH for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:29:05 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:29917) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o4J91-00051W-B0 for qemu-devel@nongnu.org; Thu, 23 Jun 2022 05:29:01 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-249-d-utb_JGN_22ey5n84Y6Kg-1; Thu, 23 Jun 2022 05:28:57 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B8B4080174C; Thu, 23 Jun 2022 09:28:56 +0000 (UTC) Received: from dgilbert-t580.localhost (unknown [10.33.36.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id B813D40C1289; Thu, 23 Jun 2022 09:28:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655976538; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=02bsooRW+muNZAOrkp1FfrnPEavTqzUd2wxFwS1LpsA=; b=SRSgvBE6hIO+xOJmfslmBsgOZMnqHzBPJx16Dveh1uUjY+OsjdD9C5G7O59Ed0L3b9oJip i9BCfTww+aBXzFM5wXXCxn1YGIffDrJqAR6FVhrXJM6IJldNf1GB4OJWQvEEOxO8kR6CbH 6cmt3Wi61z2sRAKZt+Tv0FVukcWgAuM= X-MC-Unique: d-utb_JGN_22ey5n84Y6Kg-1 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, berrange@redhat.com, huangy81@chinatelecom.cn, quintela@redhat.com, leobras@redhat.com, peterx@redhat.com Cc: jdenemar@redhat.com Subject: [PULL 33/33] tests: Add dirty page rate limit test Date: Thu, 23 Jun 2022 10:28:10 +0100 Message-Id: <20220623092810.96234-34-dgilbert@redhat.com> In-Reply-To: <20220623092810.96234-1-dgilbert@redhat.com> References: <20220623092810.96234-1-dgilbert@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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=170.10.129.124; envelope-from=dgilbert@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1655979668294100003 From: Hyman Huang(=E9=BB=84=E5=8B=87) Add dirty page rate limit test if kernel support dirty ring. The following qmp commands are covered by this test case: "calc-dirty-rate", "query-dirty-rate", "set-vcpu-dirty-limit", "cancel-vcpu-dirty-limit" and "query-vcpu-dirty-limit". Signed-off-by: Hyman Huang(=E9=BB=84=E5=8B=87) Acked-by: Peter Xu Message-Id: <81ecb7b473d8ee2adf414a1f69ce8b7bd678c558.1652931128.git.huangy= 81@chinatelecom.cn> Signed-off-by: Dr. David Alan Gilbert --- tests/qtest/migration-helpers.c | 22 +++ tests/qtest/migration-helpers.h | 2 + tests/qtest/migration-test.c | 255 ++++++++++++++++++++++++++++++++ 3 files changed, 279 insertions(+) diff --git a/tests/qtest/migration-helpers.c b/tests/qtest/migration-helper= s.c index a6aa59e4e6..4849cba720 100644 --- a/tests/qtest/migration-helpers.c +++ b/tests/qtest/migration-helpers.c @@ -75,6 +75,28 @@ QDict *wait_command(QTestState *who, const char *command= , ...) return ret; } =20 +/* + * Execute the qmp command only + */ +QDict *qmp_command(QTestState *who, const char *command, ...) +{ + va_list ap; + QDict *resp, *ret; + + va_start(ap, command); + resp =3D qtest_vqmp(who, command, ap); + va_end(ap); + + g_assert(!qdict_haskey(resp, "error")); + g_assert(qdict_haskey(resp, "return")); + + ret =3D qdict_get_qdict(resp, "return"); + qobject_ref(ret); + qobject_unref(resp); + + return ret; +} + /* * Send QMP command "migrate". * Arguments are built from @fmt... (formatted like diff --git a/tests/qtest/migration-helpers.h b/tests/qtest/migration-helper= s.h index 78587c2b82..59561898d0 100644 --- a/tests/qtest/migration-helpers.h +++ b/tests/qtest/migration-helpers.h @@ -23,6 +23,8 @@ QDict *wait_command_fd(QTestState *who, int fd, const cha= r *command, ...); G_GNUC_PRINTF(2, 3) QDict *wait_command(QTestState *who, const char *command, ...); =20 +QDict *qmp_command(QTestState *who, const char *command, ...); + G_GNUC_PRINTF(3, 4) void migrate_qmp(QTestState *who, const char *uri, const char *fmt, ...); =20 diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index d33e8060f9..f59d31b2ef 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -24,6 +24,7 @@ #include "qapi/qobject-input-visitor.h" #include "qapi/qobject-output-visitor.h" #include "crypto/tlscredspsk.h" +#include "qapi/qmp/qlist.h" =20 #include "migration-helpers.h" #include "tests/migration/migration-test.h" @@ -58,6 +59,11 @@ static bool uffd_feature_thread_id; #include #include #include +/* + * Dirtylimit stop working if dirty page rate error + * value less than DIRTYLIMIT_TOLERANCE_RANGE + */ +#define DIRTYLIMIT_TOLERANCE_RANGE 25 /* MB/s */ =20 static bool ufd_version_check(void) { @@ -2070,6 +2076,253 @@ static void test_multifd_tcp_cancel(void) test_migrate_end(from, to2, true); } =20 +static void calc_dirty_rate(QTestState *who, uint64_t calc_time) +{ + qobject_unref(qmp_command(who, + "{ 'execute': 'calc-dirty-rate'," + "'arguments': { " + "'calc-time': %ld," + "'mode': 'dirty-ring' }}", + calc_time)); +} + +static QDict *query_dirty_rate(QTestState *who) +{ + return qmp_command(who, "{ 'execute': 'query-dirty-rate' }"); +} + +static void dirtylimit_set_all(QTestState *who, uint64_t dirtyrate) +{ + qobject_unref(qmp_command(who, + "{ 'execute': 'set-vcpu-dirty-limit'," + "'arguments': { " + "'dirty-rate': %ld } }", + dirtyrate)); +} + +static void cancel_vcpu_dirty_limit(QTestState *who) +{ + qobject_unref(qmp_command(who, + "{ 'execute': 'cancel-vcpu-dirty-limit' }")); +} + +static QDict *query_vcpu_dirty_limit(QTestState *who) +{ + QDict *rsp; + + rsp =3D qtest_qmp(who, "{ 'execute': 'query-vcpu-dirty-limit' }"); + g_assert(!qdict_haskey(rsp, "error")); + g_assert(qdict_haskey(rsp, "return")); + + return rsp; +} + +static bool calc_dirtyrate_ready(QTestState *who) +{ + QDict *rsp_return; + gchar *status; + + rsp_return =3D query_dirty_rate(who); + g_assert(rsp_return); + + status =3D g_strdup(qdict_get_str(rsp_return, "status")); + g_assert(status); + + return g_strcmp0(status, "measuring"); +} + +static void wait_for_calc_dirtyrate_complete(QTestState *who, + int64_t time_s) +{ + int max_try_count =3D 10000; + usleep(time_s * 1000000); + + while (!calc_dirtyrate_ready(who) && max_try_count--) { + usleep(1000); + } + + /* + * Set the timeout with 10 s(max_try_count * 1000us), + * if dirtyrate measurement not complete, fail test. + */ + g_assert_cmpint(max_try_count, !=3D, 0); +} + +static int64_t get_dirty_rate(QTestState *who) +{ + QDict *rsp_return; + gchar *status; + QList *rates; + const QListEntry *entry; + QDict *rate; + int64_t dirtyrate; + + rsp_return =3D query_dirty_rate(who); + g_assert(rsp_return); + + status =3D g_strdup(qdict_get_str(rsp_return, "status")); + g_assert(status); + g_assert_cmpstr(status, =3D=3D, "measured"); + + rates =3D qdict_get_qlist(rsp_return, "vcpu-dirty-rate"); + g_assert(rates && !qlist_empty(rates)); + + entry =3D qlist_first(rates); + g_assert(entry); + + rate =3D qobject_to(QDict, qlist_entry_obj(entry)); + g_assert(rate); + + dirtyrate =3D qdict_get_try_int(rate, "dirty-rate", -1); + + qobject_unref(rsp_return); + return dirtyrate; +} + +static int64_t get_limit_rate(QTestState *who) +{ + QDict *rsp_return; + QList *rates; + const QListEntry *entry; + QDict *rate; + int64_t dirtyrate; + + rsp_return =3D query_vcpu_dirty_limit(who); + g_assert(rsp_return); + + rates =3D qdict_get_qlist(rsp_return, "return"); + g_assert(rates && !qlist_empty(rates)); + + entry =3D qlist_first(rates); + g_assert(entry); + + rate =3D qobject_to(QDict, qlist_entry_obj(entry)); + g_assert(rate); + + dirtyrate =3D qdict_get_try_int(rate, "limit-rate", -1); + + qobject_unref(rsp_return); + return dirtyrate; +} + +static QTestState *dirtylimit_start_vm(void) +{ + QTestState *vm =3D NULL; + g_autofree gchar *cmd =3D NULL; + const char *arch =3D qtest_get_arch(); + g_autofree char *bootpath =3D NULL; + + assert((strcmp(arch, "x86_64") =3D=3D 0)); + bootpath =3D g_strdup_printf("%s/bootsect", tmpfs); + assert(sizeof(x86_bootsect) =3D=3D 512); + init_bootfile(bootpath, x86_bootsect, sizeof(x86_bootsect)); + + cmd =3D g_strdup_printf("-accel kvm,dirty-ring-size=3D4096 " + "-name dirtylimit-test,debug-threads=3Don " + "-m 150M -smp 1 " + "-serial file:%s/vm_serial " + "-drive file=3D%s,format=3Draw ", + tmpfs, bootpath); + + vm =3D qtest_init(cmd); + return vm; +} + +static void dirtylimit_stop_vm(QTestState *vm) +{ + qtest_quit(vm); + cleanup("bootsect"); + cleanup("vm_serial"); +} + +static void test_vcpu_dirty_limit(void) +{ + QTestState *vm; + int64_t origin_rate; + int64_t quota_rate; + int64_t rate ; + int max_try_count =3D 20; + int hit =3D 0; + + /* Start vm for vcpu dirtylimit test */ + vm =3D dirtylimit_start_vm(); + + /* Wait for the first serial output from the vm*/ + wait_for_serial("vm_serial"); + + /* Do dirtyrate measurement with calc time equals 1s */ + calc_dirty_rate(vm, 1); + + /* Sleep calc time and wait for calc dirtyrate complete */ + wait_for_calc_dirtyrate_complete(vm, 1); + + /* Query original dirty page rate */ + origin_rate =3D get_dirty_rate(vm); + + /* VM booted from bootsect should dirty memory steadily */ + assert(origin_rate !=3D 0); + + /* Setup quota dirty page rate at half of origin */ + quota_rate =3D origin_rate / 2; + + /* Set dirtylimit */ + dirtylimit_set_all(vm, quota_rate); + + /* + * Check if set-vcpu-dirty-limit and query-vcpu-dirty-limit + * works literally + */ + g_assert_cmpint(quota_rate, =3D=3D, get_limit_rate(vm)); + + /* Sleep a bit to check if it take effect */ + usleep(2000000); + + /* + * Check if dirtylimit take effect realistically, set the + * timeout with 20 s(max_try_count * 1s), if dirtylimit + * doesn't take effect, fail test. + */ + while (--max_try_count) { + calc_dirty_rate(vm, 1); + wait_for_calc_dirtyrate_complete(vm, 1); + rate =3D get_dirty_rate(vm); + + /* + * Assume hitting if current rate is less + * than quota rate (within accepting error) + */ + if (rate < (quota_rate + DIRTYLIMIT_TOLERANCE_RANGE)) { + hit =3D 1; + break; + } + } + + g_assert_cmpint(hit, =3D=3D, 1); + + hit =3D 0; + max_try_count =3D 20; + + /* Check if dirtylimit cancellation take effect */ + cancel_vcpu_dirty_limit(vm); + while (--max_try_count) { + calc_dirty_rate(vm, 1); + wait_for_calc_dirtyrate_complete(vm, 1); + rate =3D get_dirty_rate(vm); + + /* + * Assume dirtylimit be canceled if current rate is + * greater than quota rate (within accepting error) + */ + if (rate > (quota_rate + DIRTYLIMIT_TOLERANCE_RANGE)) { + hit =3D 1; + break; + } + } + + g_assert_cmpint(hit, =3D=3D, 1); + dirtylimit_stop_vm(vm); +} + static bool kvm_dirty_ring_supported(void) { #if defined(__linux__) && defined(HOST_X86_64) @@ -2215,6 +2468,8 @@ int main(int argc, char **argv) if (kvm_dirty_ring_supported()) { qtest_add_func("/migration/dirty_ring", test_precopy_unix_dirty_ring); + qtest_add_func("/migration/vcpu_dirty_limit", + test_vcpu_dirty_limit); } =20 ret =3D g_test_run(); --=20 2.36.1