From nobody Sun Nov 24 11:43:34 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1722781492; cv=none; d=zohomail.com; s=zohoarc; b=c+Aufo3oL2FLbq13DsxJQqZQKeY+NTkAPmov/Zbq3Vfjyj2Revu6rqhk3/NvKh2sllq5tdIrMv5k2ctB05+fuTdqvEJUotSXVS0/p9EC89LU9BT5/3gSlWVTNHqqg3ZJGwtezMfOw/GBtfS2KL7IUdBJnBgJvBanO0uEb42c+nk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1722781492; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=x2R9ne5DfdGUUGMxzmrdwOWCGaoNP/K5T/DLLYSkhZU=; b=m5sP7h1Xkpd+2jNluNsE4X9C3hs9VYE3aud2AFz7UcU9oUuh9E7fgzwNY387PQlpoRw+cEWgp+oxMdumtEybW0XUnMmhOZe55byrS7XsCwm2sUYmhaffbZu2N78eY/Gt4sJBEo2AqIDgEKZxKlhMN68eJAknPSMqj2h6TkZRpiI= 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 1722781492754100.84547960349505; Sun, 4 Aug 2024 07:24:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sac9Y-00080K-Ja; Sun, 04 Aug 2024 10:24:08 -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 1sac9X-0007zh-DH for qemu-devel@nongnu.org; Sun, 04 Aug 2024 10:24:07 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sac9V-0005u0-NM for qemu-devel@nongnu.org; Sun, 04 Aug 2024 10:24:07 -0400 Received: by mail-pf1-x442.google.com with SMTP id d2e1a72fcca58-70d23caf8ddso8364881b3a.0 for ; Sun, 04 Aug 2024 07:24:05 -0700 (PDT) Received: from localhost.localdomain ([223.104.134.101]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ff592b5886sm49567305ad.299.2024.08.04.07.24.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Aug 2024 07:24:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722781444; x=1723386244; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=x2R9ne5DfdGUUGMxzmrdwOWCGaoNP/K5T/DLLYSkhZU=; b=hX74vD44EraAZWGmMdLzZOVC5eWvbYGIIg1zFT6kC+qD2Iyc5hGKVHfejwY3PgrBj+ dt33Xu+76hoVf6kD7koZvNM3UBC3bZnGlHgJ+/L68RN4vGedUMPQlPkHltFUShtdLGi8 1St7+fj4OGlmHsjLewPiFtDT56IRdAE7WOcZ/b34qDXDxUsa6MftqNbHk6H9B5Di1x2o gMxYFo/sJNuL+E+Uo1wt/7z4YDpnNeV8+EoKBvlBvcE7Zv7U418ghJCJ65F+FceZ7pXY tLwWoZb3Luf8wCJIffSPJTlqhbNiXwngCv5ZjW32fc7NQrJuxdXDvrVzx26IBrp6onma rf7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722781444; x=1723386244; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=x2R9ne5DfdGUUGMxzmrdwOWCGaoNP/K5T/DLLYSkhZU=; b=MyI3Ug+VxzdnZ2XXgiTwrN2987ELhgMPUe/U5sJ68jCgRDn8dWhwdYZ3X7R79PkJyT pH9dj/Qtmsu8cFvD75Y8HbTDScFsTQEF5U3/P51qnhItgE2twRRaDNERxmrLQyb9vHRf eRcI0fdg6ZJeAI9L1Wk3wf8n78G78aBFkhOlsYWyPm/rJDI5jnzR9f6TfUFUudp5vH8B 5Qm54xiNEdmwgkTDFadb1BIsF4ASSIkKukAjpwVAi9kG/PC7sNa2eekwoFst4rm6Li44 9vd8fhpE1eQi3/y9sspXBMzbfXZipHh2psQgOsHle2l5+rY2grJwjJ7AYmBN9ZY71zCM svNg== X-Gm-Message-State: AOJu0YxrRLbYE+rfa9I+33Ve4VF/z3O0UeI0jOE1R1/e0TANbs66dKeT jBvs1EMJPPpUiH2RjUSow5KAryBhpP4bCpf8+wiOFSJgyNg3kn7bgWFER8AOGUs= X-Google-Smtp-Source: AGHT+IHf2J8IEv8Mj9SEMAqIzErwANFBT57m75d8/84378qbF/Bt2dRsoVqcDaUUJXsMUEYAsOuefA== X-Received: by 2002:a17:903:1251:b0:1fb:98db:ad5f with SMTP id d9443c01a7336-1ff5722de68mr124981395ad.5.1722781443935; Sun, 04 Aug 2024 07:24:03 -0700 (PDT) From: luzhixing12345 To: qemu-devel@nongnu.org Cc: luzhixing12345 , "Michael S. Tsirkin" , Stefano Garzarella Subject: [PATCH] vhost-user: rewrite vu_dispatch with if-else Date: Sun, 4 Aug 2024 22:23:53 +0800 Message-Id: <20240804142353.25342-1-luzhixing12345@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::442; envelope-from=luzhixing12345@gmail.com; helo=mail-pf1-x442.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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 @gmail.com) X-ZM-MESSAGEID: 1722781493383116600 Content-Type: text/plain; charset="utf-8" rewrite with if-else instead of goto and I have a question, in two incorrent cases - need reply but no reply_requested - no need reply but has reply_requested should we call vu_panic or print warning message? --- subprojects/libvhost-user/libvhost-user.c | 39 +++++++++++++---------- subprojects/libvhost-user/libvhost-user.h | 6 ++-- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvho= st-user/libvhost-user.c index 9c630c2170..187e25f9bb 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -2158,32 +2158,39 @@ vu_dispatch(VuDev *dev) { VhostUserMsg vmsg =3D { 0, }; int reply_requested; - bool need_reply, success =3D false; + bool need_reply, success =3D true; =20 if (!dev->read_msg(dev, dev->sock, &vmsg)) { - goto end; + success =3D false; + free(vmsg.data); + return success; } =20 need_reply =3D vmsg.flags & VHOST_USER_NEED_REPLY_MASK; =20 reply_requested =3D vu_process_message(dev, &vmsg); - if (!reply_requested && need_reply) { - vmsg_set_reply_u64(&vmsg, 0); - reply_requested =3D 1; - } - - if (!reply_requested) { - success =3D true; - goto end; - } =20 - if (!vu_send_reply(dev, dev->sock, &vmsg)) { - goto end; + if (need_reply) { + if (reply_requested) { + if (!vu_send_reply(dev, dev->sock, &vmsg)) { + success =3D false; + } + } else { + // need reply but no reply requested, return 0(u64) + vmsg_set_reply_u64(&vmsg, 0); + if (!vu_send_reply(dev, dev->sock, &vmsg)) { + success =3D false; + } + } + } else { + // no need reply but reply requested, send a reply + if (reply_requested) { + if (!vu_send_reply(dev, dev->sock, &vmsg)) { + success =3D false; + } + } } =20 - success =3D true; - -end: free(vmsg.data); return success; } diff --git a/subprojects/libvhost-user/libvhost-user.h b/subprojects/libvho= st-user/libvhost-user.h index deb40e77b3..2daf8578f6 100644 --- a/subprojects/libvhost-user/libvhost-user.h +++ b/subprojects/libvhost-user/libvhost-user.h @@ -238,6 +238,8 @@ typedef struct VuDev VuDev; =20 typedef uint64_t (*vu_get_features_cb) (VuDev *dev); typedef void (*vu_set_features_cb) (VuDev *dev, uint64_t features); +typedef uint64_t (*vu_get_protocol_features_cb) (VuDev *dev); +typedef void (*vu_set_protocol_features_cb) (VuDev *dev, uint64_t features= ); typedef int (*vu_process_msg_cb) (VuDev *dev, VhostUserMsg *vmsg, int *do_reply); typedef bool (*vu_read_msg_cb) (VuDev *dev, int sock, VhostUserMsg *vmsg); @@ -256,9 +258,9 @@ typedef struct VuDevIface { vu_set_features_cb set_features; /* get the protocol feature bitmask from the underlying vhost * implementation */ - vu_get_features_cb get_protocol_features; + vu_get_protocol_features_cb get_protocol_features; /* enable protocol features in the underlying vhost implementation. */ - vu_set_features_cb set_protocol_features; + vu_set_protocol_features_cb set_protocol_features; /* process_msg is called for each vhost-user message received */ /* skip libvhost-user processing if return value !=3D 0 */ vu_process_msg_cb process_msg; --=20 2.34.1