mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00
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>
This commit is contained in:
parent
f7c7226592
commit
53548d6bff
2 changed files with 30 additions and 17 deletions
|
@ -17,6 +17,7 @@
|
|||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <linux/sockios.h>
|
||||
|
||||
|
@ -101,28 +102,39 @@ void vsock_wait_remote_close(int fd)
|
|||
close(epollfd);
|
||||
}
|
||||
|
||||
/* Wait until ioctl gives an expected int value.
|
||||
* Return false if the op is not supported.
|
||||
*/
|
||||
bool vsock_ioctl_int(int fd, unsigned long op, int expected)
|
||||
{
|
||||
int actual, ret;
|
||||
char name[32];
|
||||
|
||||
snprintf(name, sizeof(name), "ioctl(%lu)", op);
|
||||
|
||||
timeout_begin(TIMEOUT);
|
||||
do {
|
||||
ret = ioctl(fd, op, &actual);
|
||||
if (ret < 0) {
|
||||
if (errno == EOPNOTSUPP)
|
||||
break;
|
||||
|
||||
perror(name);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
timeout_check(name);
|
||||
} while (actual != expected);
|
||||
timeout_end();
|
||||
|
||||
return ret >= 0;
|
||||
}
|
||||
|
||||
/* 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 ret, sock_bytes_unsent;
|
||||
|
||||
timeout_begin(TIMEOUT);
|
||||
do {
|
||||
ret = ioctl(fd, SIOCOUTQ, &sock_bytes_unsent);
|
||||
if (ret < 0) {
|
||||
if (errno == EOPNOTSUPP)
|
||||
break;
|
||||
|
||||
perror("ioctl(SIOCOUTQ)");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
timeout_check("SIOCOUTQ");
|
||||
} while (sock_bytes_unsent != 0);
|
||||
timeout_end();
|
||||
|
||||
return !ret;
|
||||
return vsock_ioctl_int(fd, SIOCOUTQ, 0);
|
||||
}
|
||||
|
||||
/* Create socket <type>, bind to <cid, port>.
|
||||
|
|
|
@ -87,6 +87,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);
|
||||
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);
|
||||
|
|
Loading…
Add table
Reference in a new issue