1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
use crate::{
completion_queue::WorkRequestId,
memory_region::{LocalMemoryRegion, RemoteMemoryRegion},
};
use clippy_utilities::Cast;
use rdma_sys::{ibv_recv_wr, ibv_send_flags, ibv_send_wr, ibv_sge, ibv_wr_opcode};
#[repr(C)]
pub(crate) struct SendWr {
inner: ibv_send_wr,
sges: Vec<ibv_sge>,
}
impl SendWr {
fn new(lms: &[&LocalMemoryRegion], wr_id: WorkRequestId) -> Self {
assert!(!lms.is_empty());
let mut sges: Vec<ibv_sge> = lms.iter().map(|lm| (*lm).into()).collect();
let mut inner = unsafe { std::mem::zeroed::<ibv_send_wr>() };
inner.next = std::ptr::null_mut();
inner.wr_id = wr_id.into();
inner.sg_list = sges.as_mut_ptr();
inner.num_sge = sges.len().cast();
Self { inner, sges }
}
pub(crate) fn new_send(lms: &[&LocalMemoryRegion], wr_id: WorkRequestId) -> Self {
let mut sr = Self::new(lms, wr_id);
sr.inner.opcode = ibv_wr_opcode::IBV_WR_SEND;
sr.inner.send_flags = ibv_send_flags::IBV_SEND_SIGNALED.0;
sr
}
#[allow(clippy::as_conversions)]
pub(crate) fn new_read(
lms: &[&LocalMemoryRegion],
wr_id: WorkRequestId,
rm: &RemoteMemoryRegion,
) -> Self {
let mut sr = Self::new(lms, wr_id);
sr.inner.opcode = ibv_wr_opcode::IBV_WR_RDMA_READ;
sr.inner.send_flags = ibv_send_flags::IBV_SEND_SIGNALED.0;
sr.inner.wr.rdma.remote_addr = (rm.as_ptr() as usize).cast();
sr.inner.wr.rdma.rkey = rm.rkey();
sr
}
#[allow(clippy::as_conversions)]
pub(crate) fn new_write(
lms: &[&LocalMemoryRegion],
wr_id: WorkRequestId,
rm: &RemoteMemoryRegion,
) -> Self {
let mut sr = Self::new(lms, wr_id);
sr.inner.opcode = ibv_wr_opcode::IBV_WR_RDMA_WRITE;
sr.inner.send_flags = ibv_send_flags::IBV_SEND_SIGNALED.0;
sr.inner.wr.rdma.remote_addr = (rm.as_ptr() as usize).cast();
sr.inner.wr.rdma.rkey = rm.rkey();
sr
}
}
impl AsRef<ibv_send_wr> for SendWr {
fn as_ref(&self) -> &ibv_send_wr {
&self.inner
}
}
impl<'lm> AsMut<ibv_send_wr> for SendWr {
fn as_mut(&mut self) -> &mut ibv_send_wr {
&mut self.inner
}
}
#[repr(C)]
pub(crate) struct RecvWr {
inner: ibv_recv_wr,
sges: Vec<ibv_sge>,
}
impl RecvWr {
fn new(lms: &[&LocalMemoryRegion], wr_id: WorkRequestId) -> Self {
assert!(!lms.is_empty());
let mut sges: Vec<ibv_sge> = lms.iter().map(|lm| (*lm).into()).collect();
let mut inner = unsafe { std::mem::zeroed::<ibv_recv_wr>() };
inner.next = std::ptr::null_mut();
inner.wr_id = wr_id.into();
inner.sg_list = sges.as_mut_ptr();
inner.num_sge = sges.len().cast();
Self { inner, sges }
}
pub(crate) fn new_recv(lms: &[&LocalMemoryRegion], wr_id: WorkRequestId) -> Self {
Self::new(lms, wr_id)
}
}
impl AsRef<ibv_recv_wr> for RecvWr {
fn as_ref(&self) -> &ibv_recv_wr {
&self.inner
}
}
impl AsMut<ibv_recv_wr> for RecvWr {
fn as_mut(&mut self) -> &mut ibv_recv_wr {
&mut self.inner
}
}
impl From<&LocalMemoryRegion> for ibv_sge {
#[inline]
#[allow(clippy::as_conversions)]
fn from(lmr: &LocalMemoryRegion) -> Self {
Self {
addr: (lmr.as_ptr() as usize).cast(),
length: lmr.length().cast(),
lkey: lmr.lkey(),
}
}
}