# Virtiofsd - High-Performance File Sharing

Share directories between host and guest VMs with near-local performance using virtio-fs.

## Prerequisites

virtiofsd must be installed on your system:

**Ubuntu/Debian:**
```bash
sudo apt update && sudo apt install qemu-system-x86
sudo cp /usr/lib/qemu/virtiofsd /usr/local/bin/
```

**Fedora/CentOS/RHEL:**
```bash
sudo dnf install qemu-kvm
```

**Arch Linux:**
```bash
sudo pacman -S qemu
```

**From Source:**
```bash
git clone https://gitlab.com/virtio-fs/virtiofsd
cd virtiofsd && cargo build --release
sudo cp target/release/virtiofsd /usr/local/bin/
```

## Functions

| Function | Description |
|----------|-------------|
| `virtiofsd_available()` | Check if virtiofsd is installed |
| `virtiofsd_version()` | Get virtiofsd version |
| `virtiofsd_config()` | Create a new configuration builder |
| `start_virtiofsd_daemon(config)` | Start a virtiofsd daemon |
| `share_directory(host_dir, socket_path)` | Quick share directory |
| `share_directory_readonly(host_dir, socket_path)` | Share directory read-only |
| `share_directory_with_mount(host_dir, guest_dir, socket_path)` | Share with guest mount point |
| `create_temp_share(socket_path)` | Create temporary shared directory |

## Configuration Builder Methods

| Method | Description |
|--------|-------------|
| `.socket_path(path)` | Set Unix socket path |
| `.shared_dir(dir)` | Set directory to share |
| `.shared_dir_with_mount(host_dir, guest_dir)` | Set both host and guest directories |
| `.readonly(bool)` | Set read-only mode |
| `.sandbox(bool)` | Enable/disable sandbox |
| `.thread_pool_size(size)` | Set worker thread count |
| `.cache(bool)` | Enable/disable caching |
| `.extra_args(array)` | Add extra arguments |
| `.build()` | Build and validate configuration |

## Daemon Methods

| Method | Description |
|--------|-------------|
| `.pid()` | Get process ID |
| `.socket_path()` | Get socket path |
| `.shared_dir()` | Get shared directory |
| `.is_running()` | Check if daemon is running |
| `.stop()` | Stop the daemon |
| `.to_map()` | Convert to map representation |

## Example Files

- `01_config_demo.rhai` - Configuration options and examples
- `02_basic_operations.rhai` - Basic daemon lifecycle management
- `03_advanced_management.rhai` - Multi-daemon scenarios with performance tuning
- `04_vm_integration.rhai` - VM integration with QEMU configuration examples

## Performance Tips

1. **Disable sandbox** for maximum performance (reduces security)
2. **Increase thread pool size** for concurrent access
3. **Enable cache** for better read performance
4. **Use tmpfs** for socket location to reduce disk I/O
5. **Mount with appropriate options** in the guest VM

## Security Considerations

- Keep sandbox enabled for untrusted guests
- Use read-only mode when possible
- Validate shared directory permissions
- Monitor daemon processes regularly
