fix: handle NBD_OPT_INFO in handshake for macOS 26.3 compatibility

This commit is contained in:
harshdoesdev
2026-04-07 18:12:20 +05:30
parent ee052a99ce
commit e84df11cda
3 changed files with 25 additions and 18 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "shuru-cli"
version = "0.5.5"
version = "0.5.6"
edition = "2021"
[[bin]]
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "shuru-store"
version = "0.1.1"
version = "0.1.2"
edition = "2021"
description = "NBD-backed storage layer for shuru microVMs"
license = "Apache-2.0"
+23 -16
View File
@@ -44,6 +44,7 @@ const NBD_FLAG_SEND_FLUSH: u16 = 1 << 2;
// Option types
const NBD_OPT_EXPORT_NAME: u32 = 1;
const NBD_OPT_ABORT: u32 = 2;
const NBD_OPT_INFO: u32 = 6;
const NBD_OPT_GO: u32 = 7;
// Option reply types
@@ -126,22 +127,13 @@ fn handshake(
debug!("NBD handshake complete (EXPORT_NAME), size={}", backend.size());
return Ok(());
}
NBD_OPT_GO => {
// Modern negotiation: send NBD_REP_INFO then NBD_REP_ACK
let trans_flags = NBD_FLAG_HAS_FLAGS | NBD_FLAG_SEND_FLUSH;
// Send NBD_INFO_EXPORT
let mut info = Vec::with_capacity(12);
info.extend_from_slice(&NBD_INFO_EXPORT.to_be_bytes());
info.extend_from_slice(&backend.size().to_be_bytes());
info.extend_from_slice(&trans_flags.to_be_bytes());
send_option_reply(stream, option, NBD_REP_INFO, &info)?;
// Send ACK
send_option_reply(stream, option, NBD_REP_ACK, &[])?;
stream.flush()?;
debug!("NBD handshake complete (GO), size={}", backend.size());
return Ok(());
NBD_OPT_INFO | NBD_OPT_GO => {
send_export_info(stream, option, backend)?;
if option == NBD_OPT_GO {
debug!("NBD handshake complete (GO), size={}", backend.size());
return Ok(());
}
debug!("NBD INFO reply sent, size={}", backend.size());
}
NBD_OPT_ABORT => {
send_option_reply(stream, option, NBD_REP_ACK, &[])?;
@@ -157,6 +149,21 @@ fn handshake(
}
}
fn send_export_info(
stream: &mut std::os::unix::net::UnixStream,
option: u32,
backend: &dyn NbdBackend,
) -> std::io::Result<()> {
let trans_flags = NBD_FLAG_HAS_FLAGS | NBD_FLAG_SEND_FLUSH;
let mut info = [0u8; 12];
info[0..2].copy_from_slice(&NBD_INFO_EXPORT.to_be_bytes());
info[2..10].copy_from_slice(&backend.size().to_be_bytes());
info[10..12].copy_from_slice(&trans_flags.to_be_bytes());
send_option_reply(stream, option, NBD_REP_INFO, &info)?;
send_option_reply(stream, option, NBD_REP_ACK, &[])?;
stream.flush()
}
fn send_option_reply(
stream: &mut std::os::unix::net::UnixStream,
option: u32,