Skip to content

Commit 83436a4

Browse files
committed
Update for review
1 parent 0866e0b commit 83436a4

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

clients/filesystem-fuse/src/filesystem.rs

+28-23
Original file line numberDiff line numberDiff line change
@@ -32,33 +32,33 @@ pub(crate) type Result<T> = std::result::Result<T, Errno>;
3232
#[async_trait]
3333
pub(crate) trait RawFileSystem: Send + Sync {
3434
/// Init the file system
35-
async fn init(&self);
35+
async fn init(&self) -> Result<()>;
3636

37-
/// Get the file path by file id
37+
/// Get the file path by file id, if the file id is valid, return the file path
3838
async fn get_file_path(&self, file_id: u64) -> String;
3939

40-
/// Validate the file id and file handle, if the file id or file handle is invalid, return error
40+
/// Validate the file id and file handle, if the file id and file handle is valid, return success
4141
async fn valid_file_id(&self, file_id: u64, fh: u64) -> Result<()>;
4242

43-
/// Get the file stat by file id
43+
/// Get the file stat by file id. if the file id is valid, return the file stat
4444
async fn stat(&self, file_id: u64) -> Result<FileStat>;
4545

46-
/// Get the file stat by parent file id and file name
46+
/// Lookup the file by parent file id and file name, if the file is exist, return the file stat
4747
async fn lookup(&self, parent_file_id: u64, name: &str) -> Result<FileStat>;
4848

49-
/// Read the directory by file id
49+
/// Read the directory by file id, if the file id is a valid directory, return the file stat list
5050
async fn read_dir(&self, dir_file_id: u64) -> Result<Vec<FileStat>>;
5151

52-
/// Open the file by file id and flags
52+
/// Open the file by file id and flags, if the file id is a valid file, return the file handle
5353
async fn open_file(&self, file_id: u64, flags: u32) -> Result<FileHandle>;
5454

55-
/// Open the directory by file id and flags
55+
/// Open the directory by file id and flags, if successful, return the file handle
5656
async fn open_dir(&self, file_id: u64, flags: u32) -> Result<FileHandle>;
5757

58-
/// Create the file by parent file id and file name and flags
58+
/// Create the file by parent file id and file name and flags, if successful, return the file handle
5959
async fn create_file(&self, parent_file_id: u64, name: &str, flags: u32) -> Result<FileHandle>;
6060

61-
/// Create the directory by parent file id and file name
61+
/// Create the directory by parent file id and file name, if successful, return the file id
6262
async fn create_dir(&self, parent_file_id: u64, name: &str) -> Result<u64>;
6363

6464
/// Set the file attribute by file id and file stat
@@ -70,13 +70,13 @@ pub(crate) trait RawFileSystem: Send + Sync {
7070
/// Remove the directory by parent file id and file name
7171
async fn remove_dir(&self, parent_file_id: u64, name: &str) -> Result<()>;
7272

73-
/// Close the file by file id and file handle
73+
/// Close the file by file id and file handle, if successful
7474
async fn close_file(&self, file_id: u64, fh: u64) -> Result<()>;
7575

76-
/// Read the file content by file id, file handle, offset and size
76+
/// Read the file content by file id, file handle, offset and size, if successful, return read result
7777
async fn read(&self, file_id: u64, fh: u64, offset: u64, size: u32) -> Result<Bytes>;
7878

79-
/// Write the file content by file id, file handle, offset and data
79+
/// Write the file content by file id, file handle, offset and data, if successful, return write size
8080
async fn write(&self, file_id: u64, fh: u64, offset: u64, data: &[u8]) -> Result<u32>;
8181
}
8282

@@ -85,32 +85,32 @@ pub(crate) trait RawFileSystem: Send + Sync {
8585
#[async_trait]
8686
pub(crate) trait PathFileSystem: Send + Sync {
8787
/// Init the file system
88-
async fn init(&self);
88+
async fn init(&self) -> Result<()>;
8989

90-
/// Get the file stat by file path
90+
/// Get the file stat by file path, if the file is exist, return the file stat
9191
async fn stat(&self, name: &str) -> Result<FileStat>;
9292

93-
/// Get the file stat by parent file path and file name
93+
/// Get the file stat by parent file path and file name, if the file is exist, return the file stat
9494
async fn lookup(&self, parent: &str, name: &str) -> Result<FileStat>;
9595

96-
/// Read the directory by file path
96+
/// Read the directory by file path, if the file is a valid directory, return the file stat list
9797
async fn read_dir(&self, name: &str) -> Result<Vec<FileStat>>;
9898

99-
/// Open the file by file path and flags
99+
/// Open the file by file path and flags, if the file is exist, return the opened file
100100
async fn open_file(&self, name: &str, flags: OpenFileFlags) -> Result<OpenedFile>;
101101

102-
/// Open the directory by file path and flags
102+
/// Open the directory by file path and flags, if the file is exist, return the opened file
103103
async fn open_dir(&self, name: &str, flags: OpenFileFlags) -> Result<OpenedFile>;
104104

105-
/// Create the file by parent file path and file name and flags
105+
/// Create the file by parent file path and file name and flags, if successful, return the opened file
106106
async fn create_file(
107107
&self,
108108
parent: &str,
109109
name: &str,
110110
flags: OpenFileFlags,
111111
) -> Result<OpenedFile>;
112112

113-
/// Create the directory by parent file path and file name
113+
/// Create the directory by parent file path and file name, if successful, return the file stat
114114
async fn create_dir(&self, parent: &str, name: &str) -> Result<FileStat>;
115115

116116
/// Set the file attribute by file path and file stat
@@ -123,6 +123,7 @@ pub(crate) trait PathFileSystem: Send + Sync {
123123
async fn remove_dir(&self, parent: &str, name: &str) -> Result<()>;
124124
}
125125

126+
// FileSystemContext is the system environment for the fuse file system.
126127
pub(crate) struct FileSystemContext {
127128
// system user id
128129
pub(crate) uid: u32,
@@ -140,7 +141,6 @@ pub(crate) struct FileSystemContext {
140141
pub(crate) block_size: u32,
141142
}
142143

143-
// FileSystemContext is the file system context for the file system implementation.
144144
impl FileSystemContext {
145145
pub(crate) fn new(uid: u32, gid: u32) -> Self {
146146
FileSystemContext {
@@ -153,7 +153,7 @@ impl FileSystemContext {
153153
}
154154
}
155155

156-
// FileStat is the file stat for the file system.
156+
// FileStat is the file metadata of the file
157157
#[derive(Clone, Debug)]
158158
pub struct FileStat {
159159
// file id for the file system.
@@ -214,8 +214,10 @@ pub struct OpenFileFlags(u32);
214214
/// File reader interface for read file content
215215
#[async_trait]
216216
pub(crate) trait FileReader: Sync + Send {
217+
/// read the file content by offset and size, if successful, return the read result
217218
async fn read(&mut self, offset: u64, size: u32) -> Result<Bytes>;
218219

220+
/// close the file
219221
async fn close(&mut self) -> Result<()> {
220222
Ok(())
221223
}
@@ -224,12 +226,15 @@ pub(crate) trait FileReader: Sync + Send {
224226
/// File writer interface for write file content
225227
#[async_trait]
226228
pub trait FileWriter: Sync + Send {
229+
/// write the file content by offset and data, if successful, return the write size
227230
async fn write(&mut self, offset: u64, data: &[u8]) -> Result<u32>;
228231

232+
/// close the file
229233
async fn close(&mut self) -> Result<()> {
230234
Ok(())
231235
}
232236

237+
/// flush the file
233238
async fn flush(&mut self) -> Result<()> {
234239
Ok(())
235240
}

clients/filesystem-fuse/src/fuse_api_handle.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl<T: RawFileSystem> Filesystem for FuseApiHandle<T> {
115115
fh: Option<u64>,
116116
_flags: u32,
117117
) -> fuse3::Result<ReplyAttr> {
118-
// check the opened file file_id is the same as the inode
118+
// check the fh is associated with the file_id
119119
if let Some(fh) = fh {
120120
self.fs.valid_file_id(inode, fh).await?;
121121
}
@@ -134,7 +134,7 @@ impl<T: RawFileSystem> Filesystem for FuseApiHandle<T> {
134134
fh: Option<u64>,
135135
set_attr: SetAttr,
136136
) -> fuse3::Result<ReplyAttr> {
137-
// check the opened file file_id is the same as the inode
137+
// check the fh is associated with the file_id
138138
if let Some(fh) = fh {
139139
self.fs.valid_file_id(inode, fh).await?;
140140
}

0 commit comments

Comments
 (0)