|
| 1 | +# Virtiofs Windows Implementation Plan |
| 2 | + |
| 3 | +## Executive Summary |
| 4 | + |
| 5 | +Implementing virtiofs on Windows is a **2-4 week project** requiring: |
| 6 | +1. Windows file system API adaptation |
| 7 | +2. FUSE protocol implementation |
| 8 | +3. Inode/handle management |
| 9 | +4. Permission and security mapping |
| 10 | + |
| 11 | +## Phase 1: Foundation (Days 1-3) ✅ START HERE |
| 12 | + |
| 13 | +### Goal: Basic read-only filesystem with minimal operations |
| 14 | + |
| 15 | +### Tasks: |
| 16 | +1. ✅ Implement core data structures |
| 17 | + - InodeData: Track file handles and metadata |
| 18 | + - HandleData: Track open file handles |
| 19 | + - Inode/Handle maps |
| 20 | + |
| 21 | +2. ✅ Implement basic operations: |
| 22 | + - `init()`: Initialize filesystem |
| 23 | + - `lookup()`: Look up file/directory by name |
| 24 | + - `getattr()`: Get file attributes |
| 25 | + - `opendir()`: Open directory |
| 26 | + - `readdir()`: Read directory entries |
| 27 | + - `releasedir()`: Close directory |
| 28 | + |
| 29 | +3. ✅ Windows API mapping: |
| 30 | + - Use `std::fs` for basic operations |
| 31 | + - Map Windows file attributes to POSIX stat |
| 32 | + - Handle path conversion (Windows → POSIX) |
| 33 | + |
| 34 | +### Success Criteria: |
| 35 | +- Can mount virtiofs in guest |
| 36 | +- Can list root directory |
| 37 | +- Can read file metadata |
| 38 | + |
| 39 | +## Phase 2: File Operations (Days 4-7) |
| 40 | + |
| 41 | +### Goal: Read-only file access |
| 42 | + |
| 43 | +### Tasks: |
| 44 | +1. Implement file operations: |
| 45 | + - `open()`: Open file for reading |
| 46 | + - `read()`: Read file data |
| 47 | + - `release()`: Close file |
| 48 | + - `statfs()`: Get filesystem statistics |
| 49 | + |
| 50 | +2. Implement zero-copy I/O: |
| 51 | + - `ZeroCopyReader` for efficient data transfer |
| 52 | + - Buffer management |
| 53 | + |
| 54 | +### Success Criteria: |
| 55 | +- Can read files from guest |
| 56 | +- Performance is acceptable (>100 MB/s) |
| 57 | + |
| 58 | +## Phase 3: Write Operations (Days 8-12) |
| 59 | + |
| 60 | +### Goal: Full read-write filesystem |
| 61 | + |
| 62 | +### Tasks: |
| 63 | +1. Implement write operations: |
| 64 | + - `create()`: Create new file |
| 65 | + - `write()`: Write file data |
| 66 | + - `unlink()`: Delete file |
| 67 | + - `mkdir()`: Create directory |
| 68 | + - `rmdir()`: Remove directory |
| 69 | + - `rename()`: Rename file/directory |
| 70 | + |
| 71 | +2. Implement attribute operations: |
| 72 | + - `setattr()`: Set file attributes |
| 73 | + - `chmod()`: Change permissions (map to Windows ACLs) |
| 74 | + - `chown()`: Change ownership (limited on Windows) |
| 75 | + |
| 76 | +### Success Criteria: |
| 77 | +- Can create/modify/delete files |
| 78 | +- Can create/delete directories |
| 79 | +- Basic permission handling works |
| 80 | + |
| 81 | +## Phase 4: Advanced Features (Days 13-20) |
| 82 | + |
| 83 | +### Goal: Production-ready filesystem |
| 84 | + |
| 85 | +### Tasks: |
| 86 | +1. Implement advanced operations: |
| 87 | + - `link()`: Hard links (if supported) |
| 88 | + - `symlink()`: Symbolic links |
| 89 | + - `readlink()`: Read symlink target |
| 90 | + - `fsync()`: Sync file data |
| 91 | + - `flush()`: Flush file data |
| 92 | + |
| 93 | +2. Implement extended attributes (if needed): |
| 94 | + - `getxattr()`: Get extended attribute |
| 95 | + - `setxattr()`: Set extended attribute |
| 96 | + - `listxattr()`: List extended attributes |
| 97 | + - `removexattr()`: Remove extended attribute |
| 98 | + |
| 99 | +3. Performance optimization: |
| 100 | + - Caching strategy |
| 101 | + - Batch operations |
| 102 | + - Async I/O |
| 103 | + |
| 104 | +4. Error handling: |
| 105 | + - Proper error mapping (Windows → POSIX errno) |
| 106 | + - Recovery from failures |
| 107 | + - Logging and diagnostics |
| 108 | + |
| 109 | +### Success Criteria: |
| 110 | +- All common file operations work |
| 111 | +- Performance is good (>500 MB/s for large files) |
| 112 | +- Stable under stress testing |
| 113 | + |
| 114 | +## Technical Challenges |
| 115 | + |
| 116 | +### 1. Path Handling |
| 117 | +**Challenge**: Windows uses backslashes, POSIX uses forward slashes |
| 118 | +**Solution**: Convert paths at the boundary, use `PathBuf` internally |
| 119 | + |
| 120 | +### 2. Permissions |
| 121 | +**Challenge**: Windows ACLs vs POSIX permissions |
| 122 | +**Solution**: |
| 123 | +- Map basic permissions (read/write/execute) |
| 124 | +- Ignore complex ACLs for now |
| 125 | +- Use default permissions for new files |
| 126 | + |
| 127 | +### 3. Inode Numbers |
| 128 | +**Challenge**: Windows doesn't have stable inode numbers |
| 129 | +**Solution**: |
| 130 | +- Generate synthetic inodes |
| 131 | +- Use file ID (GetFileInformationByHandle) as basis |
| 132 | +- Maintain inode → path mapping |
| 133 | + |
| 134 | +### 4. File Locking |
| 135 | +**Challenge**: Different locking semantics |
| 136 | +**Solution**: |
| 137 | +- Use Windows file locking APIs |
| 138 | +- Map POSIX lock types to Windows equivalents |
| 139 | + |
| 140 | +### 5. Case Sensitivity |
| 141 | +**Challenge**: Windows is case-insensitive by default |
| 142 | +**Solution**: |
| 143 | +- Preserve case in filenames |
| 144 | +- Handle case-insensitive lookups |
| 145 | +- Document limitations |
| 146 | + |
| 147 | +## Implementation Strategy |
| 148 | + |
| 149 | +### Minimal Viable Product (MVP) |
| 150 | +Focus on Phase 1-2 first (read-only filesystem): |
| 151 | +- Sufficient for many use cases (config files, read-only data) |
| 152 | +- Faster to implement (1 week) |
| 153 | +- Lower risk |
| 154 | + |
| 155 | +### Full Implementation |
| 156 | +Complete all phases for production use: |
| 157 | +- Required for container workloads |
| 158 | +- Needed for a3s box |
| 159 | +- 2-4 weeks total |
| 160 | + |
| 161 | +## Decision Point |
| 162 | + |
| 163 | +**Question for user**: Which approach do you prefer? |
| 164 | + |
| 165 | +**Option A: MVP First (1 week)** |
| 166 | +- Implement read-only filesystem |
| 167 | +- Test with real workloads |
| 168 | +- Decide if write support is needed |
| 169 | + |
| 170 | +**Option B: Full Implementation (2-4 weeks)** |
| 171 | +- Implement complete filesystem |
| 172 | +- Production-ready from start |
| 173 | +- Higher upfront investment |
| 174 | + |
| 175 | +**Recommendation**: Start with Option A (MVP), then evaluate based on a3s box requirements. |
| 176 | + |
| 177 | +## Next Steps |
| 178 | + |
| 179 | +If approved, I will: |
| 180 | +1. Create task list for Phase 1 |
| 181 | +2. Implement core data structures |
| 182 | +3. Implement basic operations (lookup, getattr, readdir) |
| 183 | +4. Add smoke tests |
| 184 | +5. Iterate based on feedback |
| 185 | + |
| 186 | +--- |
| 187 | + |
| 188 | +*Created: 2026-03-05* |
| 189 | +*Estimated effort: 2-4 weeks* |
0 commit comments