From nobody Thu Nov 14 16:44:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1696278880; cv=none; d=zohomail.com; s=zohoarc; b=dyNwYC7ZMDivPA5DPg+ulgWb3w+uGnLO/PClkDZDkN/xLtYIyVcSCYkw0qpsoJ7Rtzxpm0aUQetJwcFcrB9XYCTdXtpY+jEr+DJ9yhtoAKFEN9n1FlNq+69nrbYJLbvy6iHpwAHPCYjl62LODmF7UEBGgAMj2NSkTwZjy7JuuS4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696278880; 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=FNxOG/drRlkY3d6uhvoOfPq4VgCa4J4atWRHGxUXUNo=; b=enoR4lBsTHLkV4k5JKZ+8dnqmdKa7eR55SBynSo2cZqsHYfx2avIb+ge0yrTmhsly13r+DIhP6Jcy4V0rz8Vnysj53k0YrSb7P6EHO6AkbTQ8kbDilsEUfTzJUpTIcTP+sH//sEUCgDt21vvRI7y0fly63EDWX22FtA08Y5UL4k= 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 1696278880412980.4043428009587; Mon, 2 Oct 2023 13:34:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnPat-0003SQ-Ai; Mon, 02 Oct 2023 16:32:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnPar-0003Rw-Rz for qemu-devel@nongnu.org; Mon, 02 Oct 2023 16:32:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnPaq-0001Tv-3Z for qemu-devel@nongnu.org; Mon, 02 Oct 2023 16:32: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-18-4C9K9IekOE-sXpyArf8PyQ-1; Mon, 02 Oct 2023 16:32: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 ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A1810858F1B; Mon, 2 Oct 2023 20:32:37 +0000 (UTC) Received: from lacos-laptop-9.usersys.redhat.com (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8F76840C6EBF; Mon, 2 Oct 2023 20:32:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696278759; 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=FNxOG/drRlkY3d6uhvoOfPq4VgCa4J4atWRHGxUXUNo=; b=gYu+RcGdaa0+e+n4eKIw0QIhluGHlMjcFk5Fhlut5I32PseVYph94bhiY5iYFUaJSKlAp5 d8tmYyHKvmkBDIVDrsCn/GQ5WdHVq8Ymt0M/6Vs3uIISvA20pGA5ovm9EKanyGOidZ873D sevWmlFhUbOFySKdslEAxwXV/KYF5fI= X-MC-Unique: 4C9K9IekOE-sXpyArf8PyQ-1 From: Laszlo Ersek To: qemu-devel@nongnu.org, lersek@redhat.com Cc: "Michael S. Tsirkin" , Eugenio Perez Martin , German Maglione , Liu Jiang , Sergio Lopez Pascual , Stefano Garzarella Subject: [PATCH v3 3/7] vhost-user: factor out "vhost_user_write_sync" Date: Mon, 2 Oct 2023 22:32:17 +0200 Message-Id: <20231002203221.17241-4-lersek@redhat.com> In-Reply-To: <20231002203221.17241-1-lersek@redhat.com> References: <20231002203221.17241-1-lersek@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 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=lersek@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1696278882551100003 Content-Type: text/plain; charset="utf-8" The tails of the "vhost_user_set_vring_addr" and "vhost_user_set_u64" functions are now byte-for-byte identical. Factor the common tail out to a new function called "vhost_user_write_sync". This is purely refactoring -- no observable change. Cc: "Michael S. Tsirkin" (supporter:vhost) Cc: Eugenio Perez Martin Cc: German Maglione Cc: Liu Jiang Cc: Sergio Lopez Pascual Cc: Stefano Garzarella Signed-off-by: Laszlo Ersek Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefano Garzarella Tested-by: Albert Esteve Reviewed-by: Eugenio P=C3=A9rez --- Notes: v3: =20 - pick up R-b from Eugenio, T-b from Albert =20 v2: =20 - pick up R-b's from Phil and Stefano =20 - rename "vhost_user_write_msg" to "vhost_user_write_sync" (in code and commit message) [Stefano] hw/virtio/vhost-user.c | 66 +++++++++----------- 1 file changed, 28 insertions(+), 38 deletions(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 64eac317bfb2..1476b36f0a6e 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1320,10 +1320,35 @@ static int enforce_reply(struct vhost_dev *dev, return vhost_user_get_features(dev, &dummy); } =20 +/* Note: "msg->hdr.flags" may be modified. */ +static int vhost_user_write_sync(struct vhost_dev *dev, VhostUserMsg *msg, + bool wait_for_reply) +{ + int ret; + + if (wait_for_reply) { + bool reply_supported =3D virtio_has_feature(dev->protocol_features, + VHOST_USER_PROTOCOL_F_REPLY_ACK); + if (reply_supported) { + msg->hdr.flags |=3D VHOST_USER_NEED_REPLY_MASK; + } + } + + ret =3D vhost_user_write(dev, msg, NULL, 0); + if (ret < 0) { + return ret; + } + + if (wait_for_reply) { + return enforce_reply(dev, msg); + } + + return 0; +} + static int vhost_user_set_vring_addr(struct vhost_dev *dev, struct vhost_vring_addr *addr) { - int ret; VhostUserMsg msg =3D { .hdr.request =3D VHOST_USER_SET_VRING_ADDR, .hdr.flags =3D VHOST_USER_VERSION, @@ -1337,24 +1362,7 @@ static int vhost_user_set_vring_addr(struct vhost_de= v *dev, */ bool wait_for_reply =3D addr->flags & (1 << VHOST_VRING_F_LOG); =20 - if (wait_for_reply) { - bool reply_supported =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_REPLY_ACK); - if (reply_supported) { - msg.hdr.flags |=3D VHOST_USER_NEED_REPLY_MASK; - } - } - - ret =3D vhost_user_write(dev, &msg, NULL, 0); - if (ret < 0) { - return ret; - } - - if (wait_for_reply) { - return enforce_reply(dev, &msg); - } - - return 0; + return vhost_user_write_sync(dev, &msg, wait_for_reply); } =20 static int vhost_user_set_u64(struct vhost_dev *dev, int request, uint64_t= u64, @@ -1366,26 +1374,8 @@ static int vhost_user_set_u64(struct vhost_dev *dev,= int request, uint64_t u64, .payload.u64 =3D u64, .hdr.size =3D sizeof(msg.payload.u64), }; - int ret; =20 - if (wait_for_reply) { - bool reply_supported =3D virtio_has_feature(dev->protocol_features, - VHOST_USER_PROTOCOL_F_REPLY_ACK); - if (reply_supported) { - msg.hdr.flags |=3D VHOST_USER_NEED_REPLY_MASK; - } - } - - ret =3D vhost_user_write(dev, &msg, NULL, 0); - if (ret < 0) { - return ret; - } - - if (wait_for_reply) { - return enforce_reply(dev, &msg); - } - - return 0; + return vhost_user_write_sync(dev, &msg, wait_for_reply); } =20 static int vhost_user_set_status(struct vhost_dev *dev, uint8_t status)