Ensure read and write on the socket
Currently we don't panic when reading and writing on the socket is not up to the desired value. Need to use write_all
and read_exact
variants as @alkimake suggests.
src/util.rs
:
diff --git a/src/util.rs b/src/util.rs
index 596e981..a5cf763 100644
--- a/src/util.rs
+++ b/src/util.rs
#![macro_use]
#![allow(dead_code)]
@@ -43,7 +42,7 @@ macro_rules! read_x_bytes {
($ty:ty, $size:expr, $socket:expr) => {{
assert_eq!($size, ::core::mem::size_of::<$ty>());
let mut data = [0 as u8; $size];
- $socket.read(&mut data).expect("Error on reading client.");
+ $socket.read_exact(&mut data).expect("Error on reading client.");
<$ty>::from_be_bytes(data)
}};
}
@@ -67,13 +66,13 @@ macro_rules! write_x_bytes {
::core::mem::size_of::<$ty>()
);
let data = <$ty>::to_be_bytes($num);
- $socket.write(&data).expect("Error writing to client.");
+ $socket.write_all(&data).expect("Error writing to client.");
}};
}
macro_rules! write {
($buf:expr, $socket:expr) => {{
- $socket.write($buf).expect("Error on writing data")
+ $socket.write_all($buf).expect("Error on writing data")
However, doing mkfs.ext4
causes panic in read_exact
call. It is might me a bug in nbd
or nbd-client
.
Unfortunately we won't be able to do this fix until we understand this problem since nbd-rs
must support mkfs.ext4
.