Skip to content

When fd_type is fd_normal, pollfd needs to be replaced with the actual fd instead of the index#1730

Open
kaolamall wants to merge 1 commit into
linux-rdma:masterfrom
kaolamall:master
Open

When fd_type is fd_normal, pollfd needs to be replaced with the actual fd instead of the index#1730
kaolamall wants to merge 1 commit into
linux-rdma:masterfrom
kaolamall:master

Conversation

@kaolamall
Copy link
Copy Markdown

In the socket function, when in fork_support mode, a normal socket is created, and the return value is the index, not the socket fd. When polling, the fd passed in the pollfd parameter must be the index, not the actual socket fd. Before calling real.poll, the fd in pollfd is not replaced with the actual socket fd, so real.poll cannot poll for the correct event.

In the socket function:
if (fork_support && (domain == PF_INET || domain == PF_INET6) &&
(type == SOCK_STREAM) && (!protocol || protocol == IPPROTO_TCP)) {
ret = real.socket(domain, type, protocol);
if (ret < 0)
return ret;
fd_store(index, ret, fd_normal, fd_fork);
return index; //Here return the index, not real socket fd.
}

In the poll function:
for (i = 0; i < nfds; i++) {
if (fd_gett(fds[i].fd) == fd_rsocket) // If only fd_normal is present in fds, real.poll will be called, and the fd in fds is not a real socket fd
goto use_rpoll;
}
return real.poll(fds, nfds, timeout);

@kaolamall kaolamall closed this Apr 22, 2026
@kaolamall kaolamall reopened this Apr 22, 2026
@kaolamall kaolamall closed this Apr 22, 2026
@kaolamall kaolamall reopened this Apr 22, 2026
@kaolamall kaolamall force-pushed the master branch 2 times, most recently from 9786441 to 85e37d7 Compare April 23, 2026 07:26
@rleon
Copy link
Copy Markdown
Member

rleon commented May 4, 2026

This PR should include only commits which you should merge, so please rebase your PR to the latest master branch and force push result to this pull request.

Thanks

When using rdma-core's preload library, the poll function needs to
correctly distinguish between rsocket-managed fds and normal fds.
This change ensures that pollfd structures are properly prepared and
the call is routed to either the native poll or rpoll based on the
actual fd type.

Signed-off-by: zhangwenge <zhangwengege@126.com>
Comment thread librdmacm/preload.c

ret = rpoll(rfds, nfds, timeout);
if (!has_rsocket)
ret = real.poll(rfds, nfds, timeout);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing code does check for a normal fd and calls real.poll() if there are no rsocket fd's. The commit message does not indicate what the error is in the current flow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants