feat: add rdma_reject, rdma_get_devices and address getters#116
feat: add rdma_reject, rdma_get_devices and address getters#116dragonJACson wants to merge 2 commits into
Conversation
91c5661 to
a35f549
Compare
There was a problem hiding this comment.
Code Review
This pull request adds support for rejecting connections, querying RDMA devices, and retrieving local and remote ports and socket addresses from an Identifier. The review feedback highlights several critical compilation issues, including calls to an undefined helper function port_from_raw_addr in tests, and incorrect pointer usage (self.cm_id.as_ref() instead of self.cm_id.as_ptr()) when calling FFI functions. Additionally, the get_devices function needs to be updated to correctly handle cases where no RDMA devices are present on the system without returning an error.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| pub fn get_devices() -> Result<Vec<Arc<DeviceContext>>, GetDevicesError> { | ||
| let mut num_devices = 0; | ||
| let devices = unsafe { rdma_get_devices(&mut num_devices) }; | ||
| let devices = NonNull::new(devices).ok_or_else(|| GetDevicesErrorKind::Rdmacm(io::Error::last_os_error()))?; | ||
| let devices = RdmaDeviceList { devices }; | ||
| let num_devices = usize::try_from(num_devices).map_err(|_| GetDevicesErrorKind::InvalidDeviceCount(num_devices))?; | ||
|
|
||
| let contexts = unsafe { std::slice::from_raw_parts(devices.devices.as_ptr(), num_devices) }; | ||
| contexts | ||
| .iter() | ||
| .enumerate() | ||
| .map(|(index, &context)| { | ||
| NonNull::new(context) | ||
| .map(cached_device_context) | ||
| .ok_or_else(|| GetDevicesErrorKind::NullDeviceContext(index).into()) | ||
| }) | ||
| .collect() | ||
| } |
There was a problem hiding this comment.
If there are no RDMA devices on the system, rdma_get_devices returns NULL and sets num_devices to 0. Currently, this function treats any NULL return as an error, which will cause a false positive error when no devices are present. Instead, check if num_devices is 0 when devices is NULL and return an empty Vec in that case.
pub fn get_devices() -> Result<Vec<Arc<DeviceContext>>, GetDevicesError> {
let mut num_devices = 0;
let devices = unsafe { rdma_get_devices(&mut num_devices) };
if devices.is_null() {
if num_devices == 0 {
return Ok(Vec::new());
}
return Err(GetDevicesErrorKind::Rdmacm(io::Error::last_os_error()).into());
}
let devices = RdmaDeviceList { devices: unsafe { NonNull::new_unchecked(devices) } };
let num_devices = usize::try_from(num_devices).map_err(|_| GetDevicesErrorKind::InvalidDeviceCount(num_devices))?;
let contexts = unsafe { std::slice::from_raw_parts(devices.devices.as_ptr(), num_devices) };
contexts
.iter()
.enumerate()
.map(|(index, &context)| {
NonNull::new(context)
.map(cached_device_context)
.ok_or_else(|| GetDevicesErrorKind::NullDeviceContext(index).into())
})
.collect()
}
Codecov Report❌ Patch coverage is
🚀 New features to boost your workflow:
|
a35f549 to
06816da
Compare
06816da to
36de44f
Compare
36de44f to
d10e5f0
Compare
There was a problem hiding this comment.
Pull request overview
This PR expands the RDMA CM wrapper API by adding connection rejection support, device enumeration via RDMA CM, and convenient accessors for local/peer addresses and ports, while reusing the existing global DeviceContext cache.
Changes:
- Add
Identifier::reject()wrappingrdma_reject, with a dedicatedRejectError. - Add
get_devices()wrappingrdma_get_devicesand integrating results with the globalDeviceContextcache. - Add
Identifiergetters for local/peerSocketAddrand for src/dst ports; update/add tests to cover new helpers and improve robustness.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let num_devices = usize::try_from(num_devices).map_err(|_| GetDevicesErrorKind::InvalidDeviceCount(num_devices))?; | ||
| let contexts = unsafe { std::slice::from_raw_parts(devices.devices.as_ptr(), num_devices) }; | ||
| contexts | ||
| .iter() | ||
| .enumerate() | ||
| .map(|(index, &context)| { | ||
| NonNull::new(context) | ||
| .map(cached_device_context) | ||
| .ok_or_else(|| GetDevicesErrorKind::NullDeviceContext(index).into()) | ||
| }) | ||
| .collect() |
No description provided.