]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selftests: net: retry when bind returns EBUSY in xdp_helper
authorBui Quang Minh <minhquangbui99@gmail.com>
Fri, 25 Apr 2025 07:10:17 +0000 (14:10 +0700)
committerJakub Kicinski <kuba@kernel.org>
Mon, 28 Apr 2025 22:49:10 +0000 (15:49 -0700)
When binding the XDP socket, we may get EBUSY because the deferred
destructor of XDP socket in previous test has not been executed yet. If
that is the case, just sleep and retry some times.

Signed-off-by: Bui Quang Minh <minhquangbui99@gmail.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Link: https://patch.msgid.link/20250425071018.36078-4-minhquangbui99@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/selftests/net/lib/xdp_helper.c

index 6327863cafa6d95ea84ae6dc94982d671ead3591..eb025a9f35b1802ff665c9f45c885ebabcf8fe9d 100644 (file)
@@ -38,6 +38,7 @@ int main(int argc, char **argv)
        struct sockaddr_xdp sxdp = { 0 };
        int num_desc = NUM_DESC;
        void *umem_area;
+       int retry = 0;
        int ifindex;
        int sock_fd;
        int queue;
@@ -102,11 +103,20 @@ int main(int argc, char **argv)
                }
        }
 
-       if (bind(sock_fd, (struct sockaddr *)&sxdp, sizeof(sxdp)) != 0) {
-               munmap(umem_area, UMEM_SZ);
-               perror("bind failed");
-               close(sock_fd);
-               return 1;
+       while (1) {
+               if (bind(sock_fd, (struct sockaddr *)&sxdp, sizeof(sxdp)) == 0)
+                       break;
+
+               if (errno == EBUSY && retry < 3) {
+                       retry++;
+                       sleep(1);
+                       continue;
+               } else {
+                       perror("bind failed");
+                       munmap(umem_area, UMEM_SZ);
+                       close(sock_fd);
+                       return 1;
+               }
        }
 
        ksft_ready();