Skip to content

Commit 353b0ee

Browse files
xujihui1985imeoer
authored andcommitted
feat: support fuse notify resend
1 parent 839f5db commit 353b0ee

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

src/abi/fuse_abi_linux.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ const INIT_EXT: u64 = 0x4000_0000;
197197
// This flag indicates whether the guest kernel enable per-file dax
198198
const PERFILE_DAX: u64 = 0x2_0000_0000;
199199

200+
// this flag indicates whether the guest kernel enable resend
201+
const HAS_RESEND: u64 = 1_u64 << 39;
202+
200203
// This flag indicates whether to enable fd-passthrough. It was defined in the
201204
// Anolis kernel but not in the upstream kernel. To avoid collision, we'll set
202205
// it to the most significant bit.
@@ -458,6 +461,9 @@ bitflags! {
458461
/// If this feature is enabled, filesystem will notify guest kernel whether file
459462
/// enable DAX by EntryOut.Attr.flags of inode when lookup
460463
const PERFILE_DAX = PERFILE_DAX;
464+
465+
/// indicates whether the kernel support resend inflight request
466+
const HAS_RESEND = HAS_RESEND;
461467
}
462468
}
463469

@@ -755,7 +761,8 @@ pub enum NotifyOpcode {
755761
Store = 4,
756762
Retrieve = 5,
757763
Delete = 6,
758-
CodeMax = 7,
764+
Resend = 7,
765+
CodeMax = 8,
759766
}
760767

761768
#[repr(C)]

src/api/server/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pub const MAX_REQ_PAGES: u16 = 256; // 1MB
5151
pub struct Server<F: FileSystem + Sync> {
5252
fs: F,
5353
vers: ArcSwap<ServerVersion>,
54+
enabled: Option<FsOptions>,
5455
}
5556

5657
impl<F: FileSystem + Sync> Server<F> {
@@ -62,6 +63,7 @@ impl<F: FileSystem + Sync> Server<F> {
6263
major: KERNEL_VERSION,
6364
minor: KERNEL_MINOR_VERSION,
6465
})),
66+
enabled: None,
6567
}
6668
}
6769
}

src/api/server/sync_io.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,27 @@ impl<F: FileSystem + Sync> Server<F> {
5757
.map_err(Error::FailedToWrite)?;
5858
buffer_writer.commit(None).map_err(Error::InvalidMessage)
5959
}
60+
61+
#[cfg(feature = "fusedev")]
62+
pub fn notify_resend<S: BitmapSlice>(
63+
&self,
64+
mut w: FuseDevWriter<'_, S>,
65+
) -> Result<()> {
66+
if !self.enabled.map_or(false,|enabled| {
67+
enabled.contains(FsOptions::HAS_RESEND)
68+
}) {
69+
return Ok(0)
70+
}
71+
let mut buffer_writer = w.split_at(0).map_err(Error::FailedToSplitWriter)?;
72+
let mut header = OutHeader::default();
73+
header.unique = 0;
74+
header.error = NotifyOpcode::Resend as i32;
75+
buffer_writer
76+
.write_obj(header)
77+
.map_err(Error::FailedToWrite)?;
78+
buffer_writer.commit(None).map_err(Error::InvalidMessage)
79+
}
80+
6081
/// Main entrance to handle requests from the transport layer.
6182
///
6283
/// It receives Fuse requests from transport layers, parses the request according to Fuse ABI,
@@ -744,6 +765,7 @@ impl<F: FileSystem + Sync> Server<F> {
744765
}
745766
let vers = ServerVersion { major, minor };
746767
self.vers.store(Arc::new(vers));
768+
self.enabled = Some(enabled);
747769
if minor < KERNEL_MINOR_VERSION_INIT_OUT_SIZE {
748770
ctx.reply_ok(
749771
Some(

0 commit comments

Comments
 (0)