Skip to content

Commit 53548d6

Browse files
justxueweikuba-moo
authored andcommitted
test/vsock: Add retry mechanism to ioctl wrapper
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> Reviewed-by: Stefano Garzarella <sgarzare@redhat.com> Reviewed-by: Luigi Leonardi <leonardi@redhat.com> Link: https://patch.msgid.link/20250708-siocinq-v6-3-3775f9a9e359@antgroup.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent f7c7226 commit 53548d6

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

tools/testing/vsock/util.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <unistd.h>
1818
#include <assert.h>
1919
#include <sys/epoll.h>
20+
#include <sys/ioctl.h>
2021
#include <sys/mman.h>
2122
#include <linux/sockios.h>
2223

@@ -101,28 +102,39 @@ void vsock_wait_remote_close(int fd)
101102
close(epollfd);
102103
}
103104

104-
/* Wait until transport reports no data left to be sent.
105-
* Return false if transport does not implement the unsent_bytes() callback.
105+
/* Wait until ioctl gives an expected int value.
106+
* Return false if the op is not supported.
106107
*/
107-
bool vsock_wait_sent(int fd)
108+
bool vsock_ioctl_int(int fd, unsigned long op, int expected)
108109
{
109-
int ret, sock_bytes_unsent;
110+
int actual, ret;
111+
char name[32];
112+
113+
snprintf(name, sizeof(name), "ioctl(%lu)", op);
110114

111115
timeout_begin(TIMEOUT);
112116
do {
113-
ret = ioctl(fd, SIOCOUTQ, &sock_bytes_unsent);
117+
ret = ioctl(fd, op, &actual);
114118
if (ret < 0) {
115119
if (errno == EOPNOTSUPP)
116120
break;
117121

118-
perror("ioctl(SIOCOUTQ)");
122+
perror(name);
119123
exit(EXIT_FAILURE);
120124
}
121-
timeout_check("SIOCOUTQ");
122-
} while (sock_bytes_unsent != 0);
125+
timeout_check(name);
126+
} while (actual != expected);
123127
timeout_end();
124128

125-
return !ret;
129+
return ret >= 0;
130+
}
131+
132+
/* Wait until transport reports no data left to be sent.
133+
* Return false if transport does not implement the unsent_bytes() callback.
134+
*/
135+
bool vsock_wait_sent(int fd)
136+
{
137+
return vsock_ioctl_int(fd, SIOCOUTQ, 0);
126138
}
127139

128140
/* Create socket <type>, bind to <cid, port>.

tools/testing/vsock/util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ int vsock_stream_listen(unsigned int cid, unsigned int port);
8787
int vsock_seqpacket_accept(unsigned int cid, unsigned int port,
8888
struct sockaddr_vm *clientaddrp);
8989
void vsock_wait_remote_close(int fd);
90+
bool vsock_ioctl_int(int fd, unsigned long op, int expected);
9091
bool vsock_wait_sent(int fd);
9192
void send_buf(int fd, const void *buf, size_t len, int flags,
9293
ssize_t expected_ret);

0 commit comments

Comments
 (0)