Architecture documentation > 3. Virtual Devices
As Table 3.11 shows, sandbox storage uses two fixed roles rather than arbitrary disks.
Table 3.11. Sandbox block roles.
| Role | Access | Purpose |
|---|---|---|
distro |
Read-only | Curated base operating-system layer |
scratch |
Read-write | Private ext4 upper and work storage |
Roles are unique and appear in fixed order; an omitted distro role leaves
its slot empty. A disk-backed topology ends with scratch, except in the
RAM-backed overlay layout, which uses exactly one read-only distro block and
whose guest keeps the overlay's upper on a tmpfs in guest memory.
The role, not Linux enumeration order, defines identity.
Each attachment must use its role's access mode. The VMM opens the host storage through a generic disk interface and creates one single-queue virtio-blk device per role at the role's fixed slot, with no PCI enumeration. It adds one discovery token per block, which the machine profile owns, to the kernel command line. The guest kernel creates the device from that token, negotiates features within the role's fixed set, and places the split virtqueue in guest RAM. The guest agents identify each role by its MMIO address rather than by a device name.
Each role advertises an exact feature mask
(Table 2.8): virtio 1.0
split rings with indirect descriptors and event-index notification
suppression, a per-request segment limit, block-size and topology reporting,
and a write-back cache with explicit flush. The distro role's mask also has
the read-only feature. No other feature is offered: neither discard, packed
rings, nor platform access (VIRTIO_F_ACCESS_PLATFORM), since the machine has
no IOMMU. The device reports the backing store's capacity and its logical and
physical block sizes.
The MMIO window is a control plane for configuration and queue notifications; block data never crosses it. A request is a descriptor chain in guest RAM that holds a header with the operation and starting sector, any data buffers, and a status byte. The guest publishes the chain and, unless the device has suppressed notifications, notifies the queue, which wakes the device's I/O worker.
The worker reads requests directly from guest memory and services several concurrently. It translates each virtio sector address to the backing store's logical blocks and rejects a read or write that does not start on a logical-block boundary or whose length is not a whole number of logical blocks; the physical block size is only an alignment hint for the guest. Accepted reads and writes become asynchronous scatter-gather I/O. Individual writes are not forced to stable storage; a guest flush becomes a backend cache flush. On completion, the device stores a success, I/O-error, or unsupported status, publishes one used-ring entry, and, unless the guest suppressed the notification, signals the guest through the role's shared-status word and edge interrupt.
Because the device depends only on the generic disk interface, its guest-visible behavior is independent of the host storage type. The backend sees block offsets and buffers; filesystem semantics remain entirely in the guest. Read-only access is enforced at three layers: the guest is told that the device is read-only, the device rejects write and discard requests, and the VMM opens the host file without write access. Scratch is the only writable role.
A snapshot destination or a restore makes every block snapshot-capable. Each block must then be a nonempty, 512-byte-aligned raw regular file that uses cached I/O and is not reached through a final symbolic link, except the scratch that a platform restore declares absent, which has no file. The VMM retains that opened file for flushing and paired-scratch publication.
The snapshot contract records each block's role, read-only flag, logical length, logical and physical block sizes, and identity. A bound block's identity is the caller-authenticated immutable storage generation that every bound block shares, which capture records and each restore must state again: neither reads a block to identify it; see Snapshot Identity. Platform-tier layers are recorded as unbound, because image binding has not been consumed, so a restore may supply a different image with the captured block sizes and at most the captured length, past whose end reads return zeros. Writable scratch follows one of two policies:
- Paired. Capture publishes the exact scratch image with its length and identity. Restore rejects a caller-supplied scratch block and materializes the recorded artifact as a private copy, a reflink copy-on-write clone, or a single-use claimed continuation.
- Fresh. Capture happens before scratch is mounted and publishes no scratch artifact. Restore requires a new writable file with matching geometry, or, for a platform snapshot, may declare the scratch absent: the device keeps the captured geometry and stays writable, but its reads return zeros and its writes fail, for a guest that never writes it, such as one that keeps its upper in RAM.
nvx captures only the platform tier's configuration: an unbound placeholder
image and a fresh scratch, which it creates as sparse private files in the
caller's VM directory, at the geometries of the caller's capture
configuration, for a guest that captures before it mounts either. Before each
restore, Snapshot::accepts checks the caller's image against the
placeholder's length and block sizes, and its scratch against the dormant
scratch's geometry, and a restore whose upper is in RAM declares the scratch
absent.
Transport and queue progress are saved with the other device state. Stopping a queue prevents new descriptor intake and drains every accepted I/O to one used-ring completion. The drain has no deadline of its own: a backend that never completes an I/O stalls the capture until its caller ends the VMM; see Capture Transaction. The controller flushes and copies scratch only after that drain.