Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion doc/docs/technical-documentation/drvfs.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,32 @@ mount -t drvfs C: /tmp/my-mount-point

Internally, this is handled by `/usr/sbin/mount.drvfs`, which is a symlink to `/init`. When `/init` starts, it looks at `argv[0]` to determine which entrypoint to run. If `argv[0]` is `mount.drvfs`, then `/init` runs the `mount.drvfs` entrypoint (see `MountDrvfsEntry()` in `src/linux/init/drvfs.cpp`).

Depending on the distribution configuration, `mount.drvfs` will either mount the drive as `drvfs` (WSL1), or `plan9`, `virtio-plan9` or `virtiofs` (WSL), depending on [.wslconfig](https://learn.microsoft.com/windows/wsl/wsl-config).
Depending on the distribution configuration, `mount.drvfs` will either mount the drive as `drvfs` (WSL1), or `plan9`, `virtio-plan9` or `virtiofs` (WSL), depending on [.wslconfig](https://learn.microsoft.com/windows/wsl/wsl-config).

## Mounting with an explicit transport

`mount.drvfs` accepts a `transport=` mount option that overrides the default transport selected by `.wslconfig`:

```bash
sudo mount -t drvfs C: /mnt/c_plan9 -o transport=plan9
sudo mount -t drvfs C: /mnt/c_virtio9p -o transport=virtio9p
sudo mount -t drvfs C: /mnt/c_virtiofs -o transport=virtiofs
```

Accepted values are `plan9`, `virtio9p`, and `virtiofs`. Unknown or empty values cause the mount to fail with an error.

The requested transport must be available in the VM. By default the host only stands up the transport selected by `wsl2.virtio9p` / `wsl2.virtiofs`, so mounting with a `transport=` value whose backend is not running fails at mount time. To make all three transports available simultaneously in a single VM (useful for development and benchmarking), enable the experimental setting below.

## Testing all three transports in a single VM (experimental)

To exercise the three DrvFs transports concurrently in a single VM, enable:

```ini
# .wslconfig
[experimental]
drvFsTransports = true
```

When this setting is enabled, the host stands up all three transport backends (plan9-over-hvsocket server, virtio9p server, and virtiofs worker) regardless of `wsl2.virtio9p` / `wsl2.virtiofs`. Combined with the `transport=` mount option above, this lets the same drive be mounted under each transport in the same VM without restarting.

This setting is intended for diagnostics and is off by default; it has a small steady-state cost (extra plan9 server and virtiofs worker thread) when enabled.
32 changes: 30 additions & 2 deletions src/linux/init/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2404,13 +2404,41 @@ try
volumesToMount[driveIndex.value()] = false;
}

//
// Detect the transport used by the existing mount from its
// super options. virtio9p mounts have `trans=virtio`; hvsocket
// plan9 mounts have `trans=fd`. This is required because the
// global default (WSL_USE_VIRTIO_9P) may not match the actual
// transport when the experimental DrvFsTransports option lets
// mounts use different transports concurrently.
//

DrvFsTransport ExistingTransport = WSL_USE_VIRTIO_9P() ? DrvFsTransport::Virtio9p : DrvFsTransport::Plan9;
{
std::string_view SuperOptions = MountEntry.SuperOptions;
while (!SuperOptions.empty())
{
auto Option = UtilStringNextToken(SuperOptions, ",");
if (Option == "trans=virtio")
{
ExistingTransport = DrvFsTransport::Virtio9p;
break;
}
else if (Option == "trans=fd")
{
ExistingTransport = DrvFsTransport::Plan9;
break;
}
}
}

//
// Construct new Plan9 mount options based on the existing mount.
//

NewMountOptions = MountEntry.MountOptions;
NewMountOptions += ',';
if (WSL_USE_VIRTIO_9P())
if (ExistingTransport == DrvFsTransport::Virtio9p)
{
//
// Check if the existing mount is a drvfs mount that needs to be remounted.
Expand Down Expand Up @@ -2443,7 +2471,7 @@ try
NewMountOptions += ',';
}

MountPlan9Share(NewSource, MountEntry.MountPoint, NewMountOptions.c_str(), Message->Admin);
MountPlan9Share(NewSource, MountEntry.MountPoint, NewMountOptions.c_str(), Message->Admin, ExistingTransport);
}
else if (strcmp(MountEntry.FileSystemType, VIRTIO_FS_TYPE) == 0)
{
Expand Down
Loading
Loading