Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: send mr and support latest rustc #9

Merged
merged 3 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion KRdmaKit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![allow(non_snake_case)]
#![feature(
get_mut_unchecked,
new_uninit,
new_zeroed_alloc,
allocator_api,
trusted_random_access,
stmt_expr_attributes,
Expand Down
28 changes: 28 additions & 0 deletions KRdmaKit/src/queue_pairs/handshake_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,34 @@ impl QueuePair {
Ok(data)
}

pub fn send_mr_info(&self, mr_infos: MRInfos) -> Result<MRInfos, ControlpathError> {
let addr = match self.comm {
None => {
return Err(ControlpathError::CreationError(
"None value on `comm`",
Error::from_kernel_errno(0),
))
}
Some(comm) => comm.addr,
};
let mut stream = std::net::TcpStream::connect(addr).map_err(|_| {
ControlpathError::CreationError("Failed to connect server", Error::from_kernel_errno(0))
})?;

let serialized = serde_json::to_string(&mr_infos).unwrap();

let req = CMMessage {
message_type: CMMessageType::SendMRReq,
serialized,
};

let _ = then_send_sync(&mut stream, req).map_err(|_| {
ControlpathError::CreationError("Failed to send message", Error::from_kernel_errno(0))
})?;

Ok(mr_infos)
}

#[inline]
pub fn comm_struct(&self) -> Option<CommStruct> {
self.comm
Expand Down
22 changes: 22 additions & 0 deletions KRdmaKit/src/services_user/cm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ impl Into<ib_gid> for ibv_gid_wrapper {
pub struct DefaultConnectionManagerHandler {
pub registered_rc: Arc<Mutex<HashMap<u64, Arc<QueuePair>>>>,
pub registered_mr: MRWrapper,
pub remote_mr: Arc<Mutex<MRInfos>>,
pub port_num: u8,
pub ctx: Arc<Context>,
}
Expand All @@ -86,6 +87,7 @@ impl DefaultConnectionManagerHandler {
Self {
registered_rc: Arc::new(Default::default()),
registered_mr: Default::default(),
remote_mr: Arc::new(Default::default()),
port_num,
ctx: ctx.clone(),
}
Expand All @@ -111,6 +113,11 @@ impl DefaultConnectionManagerHandler {
self.registered_mr.inner.iter().map(|(_, mr)| mr).collect()
}

#[inline]
pub fn exp_get_remote_mrs(&self) -> Arc<Mutex<MRInfos>> {
Arc::clone(&self.remote_mr)
}

#[inline]
pub fn ctx(&self) -> &Arc<Context> {
&self.ctx
Expand Down Expand Up @@ -188,6 +195,16 @@ impl ConnectionManagerHandler for DefaultConnectionManagerHandler {
})
}

fn handle_send_mr_req(&self, raw: String) -> Result<CMMessage, CMError> {
let mrs: MRInfos = serde_json::from_str(raw.as_str())
.map_err(|_| CMError::InvalidArg("Failed to do deserialization", "".to_string()))?;
self.remote_mr.lock().unwrap().set_inner(mrs.inner);
Ok(CMMessage {
message_type: CMMessageType::NeverSend,
serialized: Default::default(),
})
}

fn handle_error(&self, _raw: String) -> Result<CMMessage, CMError> {
return Ok(CMMessage {
message_type: CMMessageType::NeverSend,
Expand Down Expand Up @@ -216,6 +233,11 @@ impl MRInfos {
pub fn inner(&self) -> &HashMap<String, MRInfo> {
&self.inner
}

#[inline]
pub fn set_inner(&mut self, inner: HashMap<String, MRInfo>) {
self.inner = inner;
}
}

#[derive(Default)]
Expand Down
11 changes: 11 additions & 0 deletions KRdmaKit/src/services_user/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ pub trait ConnectionManagerHandler: Send + Sync {
fn handle_query_mr_req(&self, raw: String) -> Result<CMMessage, CMError> {
unimplemented!()
}
fn handle_send_mr_req(&self, raw: String) -> Result<CMMessage, CMError> {
unimplemented!()
}
fn handle_error(&self, raw: String) -> Result<CMMessage, CMError> {
unimplemented!()
}
Expand Down Expand Up @@ -71,6 +74,8 @@ pub enum CMMessageType {
RegRCRes,
QueryMRRes,

SendMRReq,

Error,
NeverSend, // Never send back this type of message

Expand Down Expand Up @@ -247,6 +252,7 @@ impl<T: ConnectionManagerHandler + 'static> ConnectionManagerServer<T> {
CMMessageType::RegRCReq => handler.handle_reg_rc_req(raw),
CMMessageType::DeregRCReq => handler.handle_dereg_rc_req(raw),
CMMessageType::QueryMRReq => handler.handle_query_mr_req(raw),
CMMessageType::SendMRReq => handler.handle_send_mr_req(raw),
CMMessageType::UserSlotA => handler.handle_user_slot_a(raw),
CMMessageType::UserSlotB => handler.handle_user_slot_b(raw),
CMMessageType::UserSlotC => handler.handle_user_slot_c(raw),
Expand All @@ -263,6 +269,11 @@ impl<T: ConnectionManagerHandler + 'static> ConnectionManagerServer<T> {
pub fn handler(&self) -> &T {
&self.handler
}

#[inline]
pub fn into_handler(self) -> T {
self.handler
}
}

#[inline]
Expand Down
2 changes: 1 addition & 1 deletion rust-user-rdma/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ no-std-net = {path = "../rust-kernel-rdma/deps/no-std-net"}
[build-dependencies]
bindgen = "0.59.1" ## FIXME: update
cc = "1.0"
shlex = "0.1"
shlex ="1"

[features]
OFED_5_4 = []
Expand Down