Skip to content

Commit bd104b9

Browse files
committed
fix formatting
1 parent b63cbcc commit bd104b9

File tree

10 files changed

+456
-265
lines changed

10 files changed

+456
-265
lines changed

src/bindings/rust/build.rs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16+
use os_info;
1617
use std::env;
1718
use std::path::PathBuf;
18-
use os_info;
1919

2020
fn get_lib_path(nixl_root_path: &str, arch: &str) -> String {
2121
let os_info = os_info::get();
@@ -77,9 +77,25 @@ fn get_nixl_libs() -> Option<Vec<pkg_config::Library>> {
7777
pkg_config::probe_library("etcd-cpp-api"),
7878
pkg_config::probe_library("ucx"),
7979
) {
80-
(Ok(nixl), Ok(nixl_build), Ok(nixl_common), Ok(stream), Ok(serdes), Ok(ucx_utils), Ok(etcd), Ok(ucx)) => {
81-
Some(vec![nixl, nixl_build, nixl_common, stream, serdes, ucx_utils, etcd, ucx])
82-
}
80+
(
81+
Ok(nixl),
82+
Ok(nixl_build),
83+
Ok(nixl_common),
84+
Ok(stream),
85+
Ok(serdes),
86+
Ok(ucx_utils),
87+
Ok(etcd),
88+
Ok(ucx),
89+
) => Some(vec![
90+
nixl,
91+
nixl_build,
92+
nixl_common,
93+
stream,
94+
serdes,
95+
ucx_utils,
96+
etcd,
97+
ucx,
98+
]),
8399
_ => None,
84100
}
85101
}
@@ -111,7 +127,10 @@ fn build_nixl(cc_builder: &mut cc::Build) {
111127
println!("cargo:rustc-link-search=native={}", nixl_root_path);
112128
println!("cargo:rustc-link-search=native={}/lib", nixl_root_path);
113129
println!("cargo:rustc-link-search=native={}/lib64", nixl_root_path);
114-
println!("cargo:rustc-link-search=native={}/lib/x86_64-linux-gnu", nixl_root_path);
130+
println!(
131+
"cargo:rustc-link-search=native={}/lib/x86_64-linux-gnu",
132+
nixl_root_path
133+
);
115134

116135
// Try to use pkg-config if available
117136
if let Some(libs) = get_nixl_libs() {
@@ -125,10 +144,7 @@ fn build_nixl(cc_builder: &mut cc::Build) {
125144
println!("cargo:warning=pkg-config not available, using manual library paths");
126145
}
127146

128-
cc_builder
129-
.file("wrapper.cpp")
130-
.includes(nixl_include_paths);
131-
147+
cc_builder.file("wrapper.cpp").includes(nixl_include_paths);
132148

133149
println!("cargo:rustc-link-search={}", nixl_lib_path);
134150

src/bindings/rust/src/agent.rs

Lines changed: 61 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,23 @@
1414
// limitations under the License.
1515

1616
use super::*;
17-
use crate::descriptors::{QueryResponseList, RegDescList};
1817
use crate::bindings::{
19-
nixl_capi_agent_config_s as nixl_capi_agent_config_t,
20-
nixl_capi_thread_sync_t, nixl_capi_create_configured_agent};
18+
nixl_capi_agent_config_s as nixl_capi_agent_config_t, nixl_capi_create_configured_agent,
19+
nixl_capi_thread_sync_t,
20+
};
21+
use crate::descriptors::{QueryResponseList, RegDescList};
2122

2223
impl From<ThreadSync> for nixl_capi_thread_sync_t {
2324
fn from(value: ThreadSync) -> Self {
2425
match value {
2526
ThreadSync::None => crate::bindings::nixl_capi_thread_sync_t_NIXL_CAPI_THREAD_SYNC_NONE,
26-
ThreadSync::Strict => crate::bindings::nixl_capi_thread_sync_t_NIXL_CAPI_THREAD_SYNC_STRICT,
27+
ThreadSync::Strict => {
28+
crate::bindings::nixl_capi_thread_sync_t_NIXL_CAPI_THREAD_SYNC_STRICT
29+
}
2730
ThreadSync::Rw => crate::bindings::nixl_capi_thread_sync_t_NIXL_CAPI_THREAD_SYNC_RW,
28-
ThreadSync::Default => crate::bindings::nixl_capi_thread_sync_t_NIXL_CAPI_THREAD_SYNC_DEFAULT,
31+
ThreadSync::Default => {
32+
crate::bindings::nixl_capi_thread_sync_t_NIXL_CAPI_THREAD_SYNC_DEFAULT
33+
}
2934
}
3035
}
3136
}
@@ -94,9 +99,8 @@ impl Agent {
9499
};
95100

96101
let mut agent = ptr::null_mut();
97-
let status = unsafe {
98-
nixl_capi_create_configured_agent(c_name.as_ptr(), &mut c_cfg, &mut agent)
99-
};
102+
let status =
103+
unsafe { nixl_capi_create_configured_agent(c_name.as_ptr(), &mut c_cfg, &mut agent) };
100104

101105
match status {
102106
NIXL_CAPI_SUCCESS => {
@@ -402,7 +406,11 @@ impl Agent {
402406
/// # Returns
403407
/// A byte array containing the local partial metadata
404408
///
405-
pub fn get_local_partial_md(&self, descs: &RegDescList, opt_args: Option<&OptArgs>) -> Result<Vec<u8>, NixlError> {
409+
pub fn get_local_partial_md(
410+
&self,
411+
descs: &RegDescList,
412+
opt_args: Option<&OptArgs>,
413+
) -> Result<Vec<u8>, NixlError> {
406414
tracing::trace!("Getting local partial metadata");
407415
let mut data = std::ptr::null_mut();
408416
let mut len: usize = 0;
@@ -425,15 +433,24 @@ impl Agent {
425433
libc::free(data as *mut libc::c_void);
426434
vec
427435
};
428-
tracing::trace!(metadata.size = len, "Successfully retrieved local partial metadata");
436+
tracing::trace!(
437+
metadata.size = len,
438+
"Successfully retrieved local partial metadata"
439+
);
429440
Ok(bytes)
430441
}
431442
NIXL_CAPI_ERROR_INVALID_PARAM => {
432-
tracing::error!(error = "invalid_param", "Failed to get local partial metadata");
443+
tracing::error!(
444+
error = "invalid_param",
445+
"Failed to get local partial metadata"
446+
);
433447
Err(NixlError::InvalidParam)
434448
}
435449
_ => {
436-
tracing::error!(error = "backend_error", "Failed to get local partial metadata");
450+
tracing::error!(
451+
error = "backend_error",
452+
"Failed to get local partial metadata"
453+
);
437454
Err(NixlError::BackendError)
438455
}
439456
}
@@ -476,7 +493,11 @@ impl Agent {
476493
}
477494
}
478495

479-
pub fn make_connection(&self, remote_agent: &str, opt_args: Option<&OptArgs>) -> Result<(), NixlError> {
496+
pub fn make_connection(
497+
&self,
498+
remote_agent: &str,
499+
opt_args: Option<&OptArgs>,
500+
) -> Result<(), NixlError> {
480501
let remote_agent = CString::new(remote_agent)?;
481502
let inner_guard = self.inner.write().unwrap();
482503

@@ -521,10 +542,15 @@ impl Agent {
521542
}
522543
}
523544

524-
pub fn make_xfer_req(&self, operation: XferOp,
525-
local_descs: &XferDlistHandle, local_indices: &[i32],
526-
remote_descs: &XferDlistHandle, remote_indices: &[i32],
527-
opt_args: Option<&OptArgs>) -> Result<XferRequest, NixlError> {
545+
pub fn make_xfer_req(
546+
&self,
547+
operation: XferOp,
548+
local_descs: &XferDlistHandle,
549+
local_indices: &[i32],
550+
remote_descs: &XferDlistHandle,
551+
remote_indices: &[i32],
552+
opt_args: Option<&OptArgs>,
553+
) -> Result<XferRequest, NixlError> {
528554
let mut req = std::ptr::null_mut();
529555
let inner_guard = self.inner.read().unwrap();
530556

@@ -539,13 +565,13 @@ impl Agent {
539565
remote_indices.as_ptr(),
540566
remote_indices.len() as usize,
541567
&mut req,
542-
opt_args.map_or(std::ptr::null_mut(), |args| args.inner.as_ptr())
568+
opt_args.map_or(std::ptr::null_mut(), |args| args.inner.as_ptr()),
543569
)
544570
};
545571

546572
match status {
547-
NIXL_CAPI_SUCCESS => Ok(XferRequest::new(NonNull::new(req)
548-
.ok_or(NixlError::FailedToCreateXferRequest)?,
573+
NIXL_CAPI_SUCCESS => Ok(XferRequest::new(
574+
NonNull::new(req).ok_or(NixlError::FailedToCreateXferRequest)?,
549575
self.inner.clone(),
550576
)),
551577
NIXL_CAPI_ERROR_INVALID_PARAM => Err(NixlError::InvalidParam),
@@ -657,7 +683,11 @@ impl Agent {
657683
/// # Arguments
658684
/// * `descs` - Registration descriptor list to send
659685
/// * `opt_args` - Optional arguments for sending metadata
660-
pub fn send_local_partial_md(&self, descs: &RegDescList, opt_args: Option<&OptArgs>) -> Result<(), NixlError> {
686+
pub fn send_local_partial_md(
687+
&self,
688+
descs: &RegDescList,
689+
opt_args: Option<&OptArgs>,
690+
) -> Result<(), NixlError> {
661691
tracing::trace!("Sending local partial metadata to etcd");
662692
let inner_guard = self.inner.write().unwrap();
663693
let status = unsafe {
@@ -673,14 +703,16 @@ impl Agent {
673703
Ok(())
674704
}
675705
NIXL_CAPI_ERROR_INVALID_PARAM => {
676-
tracing::error!(error = "invalid_param", "Failed to send local partial metadata to etcd");
706+
tracing::error!(
707+
error = "invalid_param",
708+
"Failed to send local partial metadata to etcd"
709+
);
677710
Err(NixlError::InvalidParam)
678711
}
679-
_ => Err(NixlError::BackendError)
712+
_ => Err(NixlError::BackendError),
680713
}
681714
}
682715

683-
684716
/// Fetch a remote agent's metadata from etcd
685717
///
686718
/// Once fetched, the metadata will be loaded and cached locally, enabling
@@ -975,7 +1007,7 @@ impl Agent {
9751007

9761008
match status {
9771009
NIXL_CAPI_SUCCESS => Ok(XferStatus::Success), // Transfer completed
978-
NIXL_CAPI_IN_PROG => Ok(XferStatus::InProgress), // Transfer in progress
1010+
NIXL_CAPI_IN_PROG => Ok(XferStatus::InProgress), // Transfer in progress
9791011
NIXL_CAPI_ERROR_INVALID_PARAM => Err(NixlError::InvalidParam),
9801012
_ => Err(NixlError::BackendError),
9811013
}
@@ -995,22 +1027,17 @@ impl Agent {
9951027
let mut backend = std::ptr::null_mut();
9961028
let inner_guard = self.inner.write().unwrap();
9971029
let status = unsafe {
998-
nixl_capi_query_xfer_backend(
999-
inner_guard.handle.as_ptr(),
1000-
req.handle(),
1001-
&mut backend
1002-
)
1030+
nixl_capi_query_xfer_backend(inner_guard.handle.as_ptr(), req.handle(), &mut backend)
10031031
};
10041032
match status {
1005-
NIXL_CAPI_SUCCESS => {
1006-
Ok(Backend{ inner: NonNull::new(backend).ok_or(NixlError::FailedToCreateBackend)? })
1007-
}
1033+
NIXL_CAPI_SUCCESS => Ok(Backend {
1034+
inner: NonNull::new(backend).ok_or(NixlError::FailedToCreateBackend)?,
1035+
}),
10081036
NIXL_CAPI_ERROR_INVALID_PARAM => Err(NixlError::InvalidParam),
10091037
_ => Err(NixlError::BackendError),
10101038
}
10111039
}
10121040

1013-
10141041
/// Gets notifications from other agents
10151042
///
10161043
/// # Arguments

src/bindings/rust/src/descriptors/reg.rs

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
use super::*;
1716
use super::sync_manager::{BackendSyncable, SyncManager};
17+
use super::*;
1818

1919
/// Public registration descriptor used for indexing and comparisons
2020
#[derive(Debug, Clone, PartialEq)]
@@ -78,9 +78,8 @@ impl<'a> RegDescList<'a> {
7878
/// Creates a new registration descriptor list for the given memory type
7979
pub fn new(mem_type: MemType) -> Result<Self, NixlError> {
8080
let mut dlist = ptr::null_mut();
81-
let status = unsafe {
82-
nixl_capi_create_reg_dlist(mem_type as nixl_capi_mem_type_t, &mut dlist)
83-
};
81+
let status =
82+
unsafe { nixl_capi_create_reg_dlist(mem_type as nixl_capi_mem_type_t, &mut dlist) };
8483

8584
match status {
8685
NIXL_CAPI_SUCCESS => {
@@ -105,7 +104,9 @@ impl<'a> RegDescList<'a> {
105104
}
106105
}
107106

108-
pub fn get_type(&self) -> Result<MemType, NixlError> { Ok(self.mem_type) }
107+
pub fn get_type(&self) -> Result<MemType, NixlError> {
108+
Ok(self.mem_type)
109+
}
109110

110111
/// Adds a descriptor to the list
111112
pub fn add_desc(&mut self, addr: usize, len: usize, dev_id: u64) -> Result<(), NixlError> {
@@ -137,10 +138,14 @@ impl<'a> RegDescList<'a> {
137138
}
138139

139140
/// Returns the number of descriptors in the list
140-
pub fn desc_count(&self) -> Result<usize, NixlError> { Ok(self.sync_mgr.data().descriptors.len()) }
141+
pub fn desc_count(&self) -> Result<usize, NixlError> {
142+
Ok(self.sync_mgr.data().descriptors.len())
143+
}
141144

142145
/// Returns the number of descriptors in the list
143-
pub fn len(&self) -> Result<usize, NixlError> { Ok(self.sync_mgr.data().descriptors.len()) }
146+
pub fn len(&self) -> Result<usize, NixlError> {
147+
Ok(self.sync_mgr.data().descriptors.len())
148+
}
144149

145150
/// Trims the list to the given size
146151
pub fn trim(&mut self) -> Result<(), NixlError> {
@@ -152,11 +157,15 @@ impl<'a> RegDescList<'a> {
152157

153158
/// Removes the descriptor at the given index
154159
pub fn rem_desc(&mut self, index: i32) -> Result<(), NixlError> {
155-
if index < 0 { return Err(NixlError::InvalidParam); }
160+
if index < 0 {
161+
return Err(NixlError::InvalidParam);
162+
}
156163
let idx = index as usize;
157164

158165
self.sync_mgr.modify(|data| {
159-
if idx >= data.descriptors.len() { return Err(NixlError::InvalidParam); }
166+
if idx >= data.descriptors.len() {
167+
return Err(NixlError::InvalidParam);
168+
}
160169
data.descriptors.remove(idx);
161170
Ok(())
162171
})
@@ -185,12 +194,15 @@ impl<'a> RegDescList<'a> {
185194
/// Resizes the list to the given size
186195
pub fn resize(&mut self, new_size: usize) -> Result<(), NixlError> {
187196
self.sync_mgr.modify(|data| {
188-
data.descriptors.resize(new_size, RegDescriptor {
189-
addr: 0,
190-
len: 0,
191-
dev_id: 0,
192-
metadata: Vec::new(),
193-
});
197+
data.descriptors.resize(
198+
new_size,
199+
RegDescriptor {
200+
addr: 0,
201+
len: 0,
202+
dev_id: 0,
203+
metadata: Vec::new(),
204+
},
205+
);
194206
});
195207
Ok(())
196208
}
@@ -224,7 +236,10 @@ impl<'a> RegDescList<'a> {
224236
}
225237

226238
pub(crate) fn handle(&self) -> *mut bindings::nixl_capi_reg_dlist_s {
227-
self.sync_mgr.backend().map(|b| b.as_ptr()).unwrap_or(ptr::null_mut())
239+
self.sync_mgr
240+
.backend()
241+
.map(|b| b.as_ptr())
242+
.unwrap_or(ptr::null_mut())
228243
}
229244
}
230245

src/bindings/rust/src/descriptors/sync_manager.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,3 @@ impl<T: BackendSyncable> SyncManager<T> {
6666
Ok(())
6767
}
6868
}
69-

0 commit comments

Comments
 (0)