From nobody Wed Nov 27 16:50:47 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=1697740236; cv=none; d=zohomail.com; s=zohoarc; b=N5GaB5KzV2yRBFVdlpOnQ8qBOXUGMIN1LhS6Zc8NBiQEq0WmKbD3fbh/c+uy5lZdr1kiFvzPixbnSXiz7HGoktZGXjLGVUhi5DfZ428bSAsjsHBo6HwvLDG4caA45UYM2C3wR4x4T5Q5AI45hB2gr272F1bm+GJxQgZtqWue9xE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697740236; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=BFZkemHVKMpqq9uyVp58jnRD/h5a0Rr9UNCxOcsmGpE=; b=gTH99sEHYKLwUx3l0g1ot3pAYQ6QX/6qfxgmg/8iZIDEw04yyc3fnAEC8mIeF5xwroUenb1ayna6LcqJthLwuoE+cHRL+G4rmnPu/tWdLkbsTJ0l+1pt02u7TcHI5n+Jrgv0G5JOTQmppCOs+Uy8ZJDNLw83ZBeUAZeFbm0JZxo= 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 1697740236389244.59812291575054; Thu, 19 Oct 2023 11:30:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qtXhH-0000J9-7f; Thu, 19 Oct 2023 14:24:39 -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 1qtXfD-0006Ol-2F for qemu-devel@nongnu.org; Thu, 19 Oct 2023 14:22:32 -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 1qtXfA-0000lB-1i for qemu-devel@nongnu.org; Thu, 19 Oct 2023 14:22:30 -0400 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-286-7Bqu0No4PTOf0E223IdTIw-1; Thu, 19 Oct 2023 14:22:24 -0400 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-32d83fd3765so4899147f8f.3 for ; Thu, 19 Oct 2023 11:22:24 -0700 (PDT) Received: from redhat.com ([2a06:c701:73d2:bf00:e379:826:5137:6b23]) by smtp.gmail.com with ESMTPSA id y15-20020a5d614f000000b003142e438e8csm4986748wrt.26.2023.10.19.11.22.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 11:22:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697739745; 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=BFZkemHVKMpqq9uyVp58jnRD/h5a0Rr9UNCxOcsmGpE=; b=JQC7bAnfRwWQSEkMvFeEL0qGTVETn2WF9D+VhYsZGrN+h2Az70RHb8+zEHi6adWBoAjre+ HteSQPDEwp1SDyVKY0isrPAp/u4GkiGWJtWKQjnrRINkFqAlbGkJpCCBHfsA1Iyn6M0aWg HNHDhHpWLkhQ5MD1dIpadgZUNqIPfl4= X-MC-Unique: 7Bqu0No4PTOf0E223IdTIw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697739743; x=1698344543; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=BFZkemHVKMpqq9uyVp58jnRD/h5a0Rr9UNCxOcsmGpE=; b=FmikO6thDzeYfYv3hu5QzJ+zoDSOf2t5RLuWckc0IS86qPF1tY+5U92tIYdlQfMaYm JJ0a59IjXaM/Q1QqbyeW8peqNNgq39eAiAlupUJCdk1fhpKgOfIk9PKq7+X4A32+2IlF /RLd5I4KiHQORQ3AgJ9rqVvVfjsY1SdgWbF3t/0XLCNyc2o9srd4jYQ4uKg13f9wLNyp UlC6iaZq5G9oePcg0UcFMKq+QRPd/puLlsS1wcD3JilYokf/1OOn32ijiilrLshEVi6y Qwp0PXA28+3K0zNt+WLl6ZDNY2v+c63WvIlLQfETM1BuMKQHlC6+6SJpbSuRuiLc6hP0 Xz7Q== X-Gm-Message-State: AOJu0YwtQbi9sUbZkfWbvj9e4P0K5ZXqu038u/nxI6i9Ig1ZpoLVm7u7 U9ZlS7gvjma+u9SAS9KXudUtWfLA2AuDHmypxOuwzoMLd3+HKtEu1J4lgehQaL5YXAy70eYQCU2 TfdKX34tPUCM99/kgDpJMB2UPn/fyBsccFYkT/CVJ4hc63mLfRDaQnFUocSfhZtxxg6Ku X-Received: by 2002:adf:f2c6:0:b0:32d:ccde:73a0 with SMTP id d6-20020adff2c6000000b0032dccde73a0mr2102919wrp.33.1697739742864; Thu, 19 Oct 2023 11:22:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGZI+mq0ZKtX0zYOF388GOcD9VpjKIrKCcGNiHRBMALhajjnkgJlG3C3pJFVTcgo061P0JpnA== X-Received: by 2002:adf:f2c6:0:b0:32d:ccde:73a0 with SMTP id d6-20020adff2c6000000b0032dccde73a0mr2102901wrp.33.1697739742541; Thu, 19 Oct 2023 11:22:22 -0700 (PDT) Date: Thu, 19 Oct 2023 14:22:20 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Laszlo Ersek , Eugenio Perez Martin , German Maglione , Liu Jiang , Sergio Lopez Pascual , Stefano Garzarella , Philippe =?utf-8?Q?Mathieu-Daud=C3=A9?= , Albert Esteve Subject: [PULL v2 26/78] vhost-user: factor out "vhost_user_write_sync" Message-ID: <7c8be448c483f01c32021ccee4ba09ef0a69ff3e.1697739629.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent 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=mst@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: 1697740238519100003 From: Laszlo Ersek 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 Message-Id: <20231002203221.17241-4-lersek@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- 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 6c7b4cc75c..95dbf9880c 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1310,10 +1310,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, @@ -1327,24 +1352,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, @@ -1356,26 +1364,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) --=20 MST