|
| 1 | +## High level architecture |
| 2 | + |
| 3 | +```mermaid |
| 4 | +graph TD |
| 5 | + subgraph User Space |
| 6 | + A[Application] -- Mounts FS --> B(libfuse-fs) |
| 7 | + subgraph libfuse-fs |
| 8 | + C(Server) -- Dispatches Requests --> D{Filesystem Trait} |
| 9 | + D -- Implemented by --> E[PassthroughFS] |
| 10 | + D -- Implemented by --> F[OverlayFS] |
| 11 | + F -- Accesses --> E |
| 12 | + end |
| 13 | + E -- Accesses --> G[Underlying Filesystem] |
| 14 | + B -- Uses --> H[rfuse3] |
| 15 | + end |
| 16 | +
|
| 17 | + subgraph Kernel Space |
| 18 | + I[VFS] -- File Operations --> J[FUSE Kernel Driver] |
| 19 | + end |
| 20 | +
|
| 21 | + H -- Communicates via /dev/fuse --> J |
| 22 | +
|
| 23 | + style B fill:#f9f,stroke:#333,stroke-width:2px |
| 24 | + style C fill:#ccf,stroke:#333,stroke-width:2px |
| 25 | + style D fill:#ccf,stroke:#333,stroke-width:2px |
| 26 | + style E fill:#cfc,stroke:#333,stroke-width:2px |
| 27 | + style F fill:#cfc,stroke:#333,stroke-width:2px |
| 28 | +``` |
| 29 | + |
| 30 | +## Key data structures |
| 31 | + |
| 32 | +```mermaid |
| 33 | +classDiagram |
| 34 | + direction TB |
| 35 | +
|
| 36 | + class OverlayFs { |
| 37 | + <<Struct>> |
| 38 | + - config: Config |
| 39 | + - upper_layer: PassthroughFs |
| 40 | + - lower_layers: Vec<PassthroughFs> |
| 41 | + - inode_store: InodeStore |
| 42 | + - handles: Map<u64, HandleData> |
| 43 | + + new(config, upper, lowers) |
| 44 | + + lookup() |
| 45 | + + read() |
| 46 | + + write() |
| 47 | + } |
| 48 | +
|
| 49 | + class InodeStore { |
| 50 | + <<Struct>> |
| 51 | + - inodes: Map<u64, OverlayInode> |
| 52 | + - next_ino: u64 |
| 53 | + + get_inode(inode) OverlayInode |
| 54 | + + add_inode(inode) u64 |
| 55 | + } |
| 56 | +
|
| 57 | + class OverlayInode { |
| 58 | + <<Struct>> |
| 59 | + + inode: u64 |
| 60 | + + real_inodes: Vec<RealInode> |
| 61 | + + children: Map<String, OverlayInode> |
| 62 | + + parent: OverlayInode |
| 63 | + } |
| 64 | +
|
| 65 | + class RealInode { |
| 66 | + <<Struct>> |
| 67 | + + layer: PassthroughFs |
| 68 | + + in_upper_layer: bool |
| 69 | + + whiteout: bool |
| 70 | + + opaque: bool |
| 71 | + # Represents one inode object in specific layer |
| 72 | + } |
| 73 | +
|
| 74 | + class HandleData { |
| 75 | + <<Struct>> |
| 76 | + + node: OverlayInode |
| 77 | + + real_handle: Option<RealHandle> |
| 78 | + # Data for an opened file |
| 79 | + } |
| 80 | +
|
| 81 | + class RealHandle { |
| 82 | + <<Struct>> |
| 83 | + + layer: PassthroughFs |
| 84 | + + in_upper_layer: bool |
| 85 | + + inode: u64 |
| 86 | + + handle: AtomicU64 |
| 87 | + # A wrapper of one inode in specific layer |
| 88 | + } |
| 89 | + |
| 90 | + class Config { |
| 91 | + <<Struct>> |
| 92 | + + mountpoint: PathBuf |
| 93 | + + do_import: bool |
| 94 | + + writeback: bool |
| 95 | + + no_open: bool |
| 96 | + + cache_policy: CachePolicy |
| 97 | + # Configuration for OverlayFs |
| 98 | + } |
| 99 | + |
| 100 | + namespace passthrough { |
| 101 | + class PassthroughFs { |
| 102 | + <<Struct>> |
| 103 | + + inode_map: passthrough.InodeStore |
| 104 | + + handle_map: HandleMap |
| 105 | + + cfg: passthrough::Config |
| 106 | + + writeback: bool |
| 107 | + + no_open: bool |
| 108 | + # A file system that simply "passes through" all requests it receives to the underlying file system |
| 109 | + } |
| 110 | + |
| 111 | + class passthrough.InodeStore { |
| 112 | + <<Struct>> |
| 113 | + - data: Map<u64, InodeData> |
| 114 | + - by_id: Map<u64, u64> |
| 115 | + - by_handle: Map<FileHandle, u64> |
| 116 | + # Data structures to manage accessed inodes |
| 117 | + } |
| 118 | +
|
| 119 | + class InodeData { |
| 120 | + <<Struct>> |
| 121 | + + inode: u64 |
| 122 | + + handle: InodeHandle |
| 123 | + + id: InodeId |
| 124 | + + refcount: AtomicU64 |
| 125 | + # Represents an inode in PassthroughFs |
| 126 | + } |
| 127 | +
|
| 128 | + class HandleMap { |
| 129 | + <<Struct>> |
| 130 | + - map: Map<u64, HandleData> |
| 131 | + } |
| 132 | + |
| 133 | + class passthrough.HandleData { |
| 134 | + <<struct>> |
| 135 | + - inode: u64 |
| 136 | + - file: std::fs::File |
| 137 | + - open_flags: u32 |
| 138 | + } |
| 139 | +
|
| 140 | + class FileHandle { |
| 141 | + <<Struct>> |
| 142 | + + mnt_id: u64 |
| 143 | + + handle: CFileHandle |
| 144 | + # Struct to maintain information for a file handle |
| 145 | + } |
| 146 | + } |
| 147 | +
|
| 148 | + Relationships |
| 149 | + OverlayFs "1" *-- "1" Config : contains |
| 150 | + OverlayFs "1" *-- "1" PassthroughFs : has upper layer |
| 151 | + OverlayFs "1" *-- "n" PassthroughFs : has lower layers |
| 152 | + OverlayFs "1" *-- "1" InodeStore : manages |
| 153 | + OverlayFs "1" *-- "n" HandleData : manages handles |
| 154 | +
|
| 155 | + InodeStore "1" *-- "*" OverlayInode : stores |
| 156 | +
|
| 157 | + OverlayInode "1" *-- "n" RealInode : aggregates |
| 158 | +
|
| 159 | + HandleData "1" *-- "1" RealHandle : contains |
| 160 | + HandleData ..> OverlayInode : references |
| 161 | +
|
| 162 | + RealInode ..> PassthroughFs : associated with |
| 163 | + RealHandle ..> PassthroughFs : associated with |
| 164 | + |
| 165 | + PassthroughFs "1" *-- "1" passthrough.InodeStore : manages |
| 166 | + PassthroughFs "1" *-- "1" HandleMap : manages |
| 167 | +
|
| 168 | + passthrough.InodeStore "1" *-- "*" InodeData : stores |
| 169 | + HandleMap "1" *-- "*" passthrough.HandleData : stores |
| 170 | +
|
| 171 | + InodeData ..> FileHandle : (via InodeHandle) references |
| 172 | +``` |
| 173 | + |
| 174 | +## File read flow |
| 175 | + |
1 | 176 | ```mermaid |
2 | | -graph LR |
3 | | - classDef process fill:#E5F6FF,stroke:#73A6FF,stroke-width:2px |
4 | | -
|
5 | | - OverlayFs([OverlayFs]):::process |
6 | | - OverlayInode([OverlayInode]):::process |
7 | | - RealInode([RealInode]):::process |
8 | | - RealHandle([RealHandle]):::process |
9 | | - HandleData([HandleData]):::process |
10 | | - InodeStore([InodeStore]):::process |
11 | | - Config([Config]):::process |
12 | | - PassthroughFs([PassthroughFs]):::process |
13 | | -
|
14 | | - OverlayFs -->|including| Config |
15 | | - OverlayFs -->|includes multiple| lower_layers(PassthroughFs) |
16 | | - OverlayFs -->|includes one| upper_layer(PassthroughFs) |
17 | | - OverlayFs -->|manages| InodeStore |
18 | | - OverlayFs -->|manages| handles(HandleData) |
19 | | -
|
20 | | - OverlayInode -->|includes multiple| RealInode |
21 | | - OverlayInode -->|parent| OverlayInode |
22 | | - OverlayInode -->|child| OverlayInode |
23 | | -
|
24 | | - RealInode -->|associated with| PassthroughFs |
25 | | - RealHandle -->|associated with| PassthroughFs |
26 | | - HandleData -->|includes| OverlayInode |
27 | | - HandleData -->|includes| RealHandle |
28 | | -
|
29 | | - OverlayFs -->|operations involve| OverlayInode |
30 | | - InodeStore -->|stores| OverlayInode |
| 177 | +sequenceDiagram |
| 178 | + actor User |
| 179 | + participant Kernel |
| 180 | + participant rfuse3 as rfuse3::Session |
| 181 | + participant Server as OverlayFs |
| 182 | + participant PassthroughFS |
| 183 | + participant UnderlyingFS as Underlying Filesystem |
| 184 | +
|
| 185 | + %% -- Initialization (Conceptual) -- |
| 186 | + %% Server->>rfuse3: Create Session(mountpoint, PassthroughFS) |
| 187 | + %% Server->>rfuse3: session.run() |
| 188 | +
|
| 189 | + %% -- Read Operation Flow -- |
| 190 | + User->>Kernel: cat a_file.txt (read operation) |
| 191 | + Kernel->>rfuse3: FUSE_READ Request (raw bytes via /dev/fuse) |
| 192 | + activate rfuse3 |
| 193 | +
|
| 194 | + rfuse3->>rfuse3: loop: read_request() & dispatch(bytes) |
| 195 | + note right of rfuse3: 1. Reads raw bytes from kernel.<br>2. `dispatch` decodes header,<br>identifies FUSE_READ op. |
| 196 | +
|
| 197 | + %% This call is conceptual. In reality, rfuse3 calls the trait method directly. |
| 198 | + %% The 'Server' role here represents the application logic layer that rfuse3 serves. |
| 199 | + rfuse3->>Server: Calls Filesystem trait method |
| 200 | + activate Server |
| 201 | + note left of Server: rfuse3 invokes the registered<br>Filesystem implementation. |
| 202 | +
|
| 203 | + Server->>PassthroughFS: read(req, ino, fh, offset, size, reply) |
| 204 | + activate PassthroughFS |
| 205 | + note over PassthroughFS: Your business logic is executed. |
| 206 | +
|
| 207 | + PassthroughFS->>PassthroughFS: Get FileHandle from fh |
| 208 | + PassthroughFS->>UnderlyingFS: pread(file_descriptor, buffer, offset) |
| 209 | + activate UnderlyingFS |
| 210 | +
|
| 211 | + UnderlyingFS-->>PassthroughFS: Returns data |
| 212 | + deactivate UnderlyingFS |
| 213 | +
|
| 214 | + PassthroughFS-->>Server: reply.data(data) |
| 215 | + deactivate PassthroughFS |
| 216 | + note over Server, PassthroughFS: The reply object is used to<br>pass the result back up the chain. |
| 217 | +
|
| 218 | + Server-->>rfuse3: (via reply object) Response is ready |
| 219 | + deactivate Server |
| 220 | +
|
| 221 | + rfuse3->>Kernel: FUSE_READ Response (formatted bytes) |
| 222 | + deactivate rfuse3 |
31 | 223 |
|
| 224 | + Kernel-->>User: Displays content of a_file.txt |
32 | 225 | ``` |
0 commit comments