From: Xuewei Niu <niuxuewei97@gmail.com>
To: sgarzare@redhat.com, mst@redhat.com, pabeni@redhat.com,
jasowang@redhat.com, xuanzhuo@linux.alibaba.com,
davem@davemloft.net, netdev@vger.kernel.org, stefanha@redhat.com,
leonardi@redhat.com
Cc: virtualization@lists.linux.dev, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org, fupan.lfp@antgroup.com,
Xuewei Niu <niuxuewei.nxw@antgroup.com>
Subject: [PATCH net-next v3 2/3] test/vsock: Add retry mechanism to ioctl wrapper
Date: Tue, 17 Jun 2025 12:53:45 +0800 [thread overview]
Message-ID: <20250617045347.1233128-3-niuxuewei.nxw@antgroup.com> (raw)
In-Reply-To: <20250617045347.1233128-1-niuxuewei.nxw@antgroup.com>
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 <niuxuewei.nxw@antgroup.com>
---
tools/testing/vsock/util.c | 37 ++++++++++++++++++++++++++++---------
tools/testing/vsock/util.h | 1 +
2 files changed, 29 insertions(+), 9 deletions(-)
diff --git a/tools/testing/vsock/util.c b/tools/testing/vsock/util.c
index 0c7e9cbcbc85..ecfbe52efca2 100644
--- a/tools/testing/vsock/util.c
+++ b/tools/testing/vsock/util.c
@@ -16,6 +16,7 @@
#include <unistd.h>
#include <assert.h>
#include <sys/epoll.h>
+#include <sys/ioctl.h>
#include <sys/mman.h>
#include <linux/sockios.h>
@@ -97,28 +98,46 @@ void vsock_wait_remote_close(int fd)
close(epollfd);
}
-/* Wait until transport reports no data left to be sent.
- * Return false if transport does not implement the unsent_bytes() callback.
+/* Wait until ioctl gives an expected int value.
+ * Return a negative value if the op is not supported.
*/
-bool vsock_wait_sent(int fd)
+int ioctl_int(int fd, unsigned long op, int *actual, int expected)
{
- int ret, sock_bytes_unsent;
+ int ret;
+ char name[32];
+
+ if (!actual) {
+ fprintf(stderr, "%s requires a non-null pointer\n", __func__);
+ exit(EXIT_FAILURE);
+ }
+
+ snprintf(name, sizeof(name), "ioctl(%lu)", op);
timeout_begin(TIMEOUT);
do {
- ret = ioctl(fd, SIOCOUTQ, &sock_bytes_unsent);
+ ret = ioctl(fd, op, actual);
if (ret < 0) {
if (errno == EOPNOTSUPP)
break;
- perror("ioctl(SIOCOUTQ)");
+ perror(name);
exit(EXIT_FAILURE);
}
- timeout_check("SIOCOUTQ");
- } while (sock_bytes_unsent != 0);
+ timeout_check(name);
+ } while (*actual != expected);
timeout_end();
- return !ret;
+ return ret;
+}
+
+/* Wait until transport reports no data left to be sent.
+ * Return false if transport does not implement the unsent_bytes() callback.
+ */
+bool vsock_wait_sent(int fd)
+{
+ int sock_bytes_unsent;
+
+ return !(ioctl_int(fd, SIOCOUTQ, &sock_bytes_unsent, 0));
}
/* Create socket <type>, bind to <cid, port> and return the file descriptor. */
diff --git a/tools/testing/vsock/util.h b/tools/testing/vsock/util.h
index 5e2db67072d5..f3fe725cdeab 100644
--- a/tools/testing/vsock/util.h
+++ b/tools/testing/vsock/util.h
@@ -54,6 +54,7 @@ int vsock_stream_listen(unsigned int cid, unsigned int port);
int vsock_seqpacket_accept(unsigned int cid, unsigned int port,
struct sockaddr_vm *clientaddrp);
void vsock_wait_remote_close(int fd);
+int ioctl_int(int fd, unsigned long op, int *actual, 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);
--
2.34.1
next prev parent reply other threads:[~2025-06-17 4:54 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-17 4:53 [PATCH net-next v3 0/3] vsock: Introduce SIOCINQ ioctl support Xuewei Niu
2025-06-17 4:53 ` [PATCH net-next v3 1/3] vsock: Add support for SIOCINQ ioctl Xuewei Niu
2025-06-17 14:39 ` Stefano Garzarella
2025-06-22 13:59 ` Xuewei Niu
2025-06-23 17:01 ` Stefano Garzarella
2025-06-25 8:03 ` [EXTERNAL] " Dexuan Cui
2025-06-25 13:32 ` Stefano Garzarella
2025-06-25 16:41 ` Dexuan Cui
2025-06-26 5:02 ` Xuewei Niu
2025-06-27 8:50 ` [EXTERNAL] " Dexuan Cui
2025-06-27 11:01 ` Stefano Garzarella
2025-06-27 11:42 ` Xuewei Niu
2025-06-17 4:53 ` Xuewei Niu [this message]
2025-06-17 15:10 ` [PATCH net-next v3 2/3] test/vsock: Add retry mechanism to ioctl wrapper Stefano Garzarella
2025-06-17 15:23 ` Xuewei Niu
2025-06-17 4:53 ` [PATCH net-next v3 3/3] test/vsock: Add ioctl SIOCINQ tests Xuewei Niu
2025-06-17 15:21 ` Stefano Garzarella
2025-06-17 15:31 ` Xuewei Niu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250617045347.1233128-3-niuxuewei.nxw@antgroup.com \
--to=niuxuewei97@gmail.com \
--cc=davem@davemloft.net \
--cc=fupan.lfp@antgroup.com \
--cc=jasowang@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=leonardi@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=niuxuewei.nxw@antgroup.com \
--cc=pabeni@redhat.com \
--cc=sgarzare@redhat.com \
--cc=stefanha@redhat.com \
--cc=virtualization@lists.linux.dev \
--cc=xuanzhuo@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).