From nobody Tue Oct 7 20:08:43 2025 Received: from out28-173.mail.aliyun.com (out28-173.mail.aliyun.com [115.124.28.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3831E1E48A; Tue, 8 Jul 2025 06:36:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.28.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751956617; cv=none; b=Bk4G/DIlhBFkvQGPvnQnEFqFSs4q3oxZi3oElxXbye46xpjT04+xJr6zvYoSHEIxZu0bcVzhfwz9HVfcH+8DGzQrX8sk3O7PXDSo3AMIp21lgJ9yDNc5aUv86yar8YVsA91ljf4KCTEEXriyInGZd6SzQ261T53BlcAvvJIMS7U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751956617; c=relaxed/simple; bh=e6+A6V/GIHjY2NtS85toohY3fDmWeS+De+ENSmkaW48=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iIAJDGlP2fFLOwiP1JjGOp0ykKSsA89EWYfxIIUEYISkXjhFF1J7JXv7nhYLfKf7hUPXLJcJo+wnhvMAhxsQ+x21oiQYxPJD22P3X0h8t9fg8mtSa5Mw0dRnh5WBjgYD0P4YHj9vXhYgnVBfhnbpBcXyonVrtrszKNne+UzAC1c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=antgroup.com; spf=pass smtp.mailfrom=antgroup.com; dkim=pass (1024-bit key) header.d=antgroup.com header.i=@antgroup.com header.b=Bygch159; arc=none smtp.client-ip=115.124.28.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=antgroup.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=antgroup.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=antgroup.com header.i=@antgroup.com header.b="Bygch159" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antgroup.com; s=default; t=1751956607; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To; bh=+Adkwaehj8WQlyxe1tcyATntmfd0OiZXAi1oQdyK2Hg=; b=Bygch159+jT2UvdH3IEyBuVtOG/tTZ+scNwiJRNh5pGfgQu/ZnvJsz692D2JBB8nv/svJ6482ufRaLWEbIs+09tVTNXQniGphK1tcJOQ4rjDDiSC7o3CpEHnmjVTs101O0LpMbUYloI5iWkoK7ZNVOsCUkIVOus1ZqPckw+1OW0= Received: from 127.0.0.1(mailfrom:niuxuewei.nxw@antgroup.com fp:SMTPD_---.dhGPAgC_1751956605 cluster:ay29) by smtp.aliyun-inc.com; Tue, 08 Jul 2025 14:36:46 +0800 From: Xuewei Niu Date: Tue, 08 Jul 2025 14:36:13 +0800 Subject: [PATCH net-next v6 3/4] test/vsock: Add retry mechanism to ioctl wrapper Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250708-siocinq-v6-3-3775f9a9e359@antgroup.com> References: <20250708-siocinq-v6-0-3775f9a9e359@antgroup.com> In-Reply-To: <20250708-siocinq-v6-0-3775f9a9e359@antgroup.com> To: "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman Cc: linux-hyperv@vger.kernel.org, virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Xuewei Niu , niuxuewei97@gmail.com X-Mailer: b4 0.14.2 Wrap the ioctl in `ioctl_int()`, which takes a pointer to the actual int value and an expected int value. The function will not return until either the ioctl returns the expected value or a timeout occurs, thus avoiding immediate failure. Signed-off-by: Xuewei Niu Reviewed-by: Luigi Leonardi Reviewed-by: Stefano Garzarella --- tools/testing/vsock/util.c | 30 +++++++++++++++++++++--------- tools/testing/vsock/util.h | 1 + 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/tools/testing/vsock/util.c b/tools/testing/vsock/util.c index 803f1e075b62228c25f9dffa1eff131b8072a06a..1e65c5abd85b8bcf5886272de15= 437d7be13eb89 100644 --- a/tools/testing/vsock/util.c +++ b/tools/testing/vsock/util.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include =20 @@ -101,28 +102,39 @@ void vsock_wait_remote_close(int fd) close(epollfd); } =20 -/* Wait until transport reports no data left to be sent. - * Return false if transport does not implement the unsent_bytes() callbac= k. +/* Wait until ioctl gives an expected int value. + * Return false if the op is not supported. */ -bool vsock_wait_sent(int fd) +bool vsock_ioctl_int(int fd, unsigned long op, int expected) { - int ret, sock_bytes_unsent; + int actual, ret; + char name[32]; + + snprintf(name, sizeof(name), "ioctl(%lu)", op); =20 timeout_begin(TIMEOUT); do { - ret =3D ioctl(fd, SIOCOUTQ, &sock_bytes_unsent); + ret =3D ioctl(fd, op, &actual); if (ret < 0) { if (errno =3D=3D EOPNOTSUPP) break; =20 - perror("ioctl(SIOCOUTQ)"); + perror(name); exit(EXIT_FAILURE); } - timeout_check("SIOCOUTQ"); - } while (sock_bytes_unsent !=3D 0); + timeout_check(name); + } while (actual !=3D expected); timeout_end(); =20 - return !ret; + return ret >=3D 0; +} + +/* Wait until transport reports no data left to be sent. + * Return false if transport does not implement the unsent_bytes() callbac= k. + */ +bool vsock_wait_sent(int fd) +{ + return vsock_ioctl_int(fd, SIOCOUTQ, 0); } =20 /* Create socket , bind to . diff --git a/tools/testing/vsock/util.h b/tools/testing/vsock/util.h index fdd4649fe2d49f57c93c4aa5dfbb37b710c65918..142c02a6834acb7117aca485b66= 1332b73754b63 100644 --- a/tools/testing/vsock/util.h +++ b/tools/testing/vsock/util.h @@ -87,6 +87,7 @@ int vsock_stream_listen(unsigned int cid, unsigned int po= rt); int vsock_seqpacket_accept(unsigned int cid, unsigned int port, struct sockaddr_vm *clientaddrp); void vsock_wait_remote_close(int fd); +bool vsock_ioctl_int(int fd, unsigned long op, int expected); bool vsock_wait_sent(int fd); void send_buf(int fd, const void *buf, size_t len, int flags, ssize_t expected_ret); --=20 2.34.1