pub struct SnapshotCatalog { /* private fields */ }Expand description
Manages the on-disk snapshot catalog for all VMs.
Layout:
{data_dir}/snapshots/{vm_id}/{snapshot_id}/
vmstate
mem (full only)
meta.json
{data_dir}/snapshots/{vm_id}/.{snapshot_id}.partial/ (being written)Every catalogued directory carries a readable meta.json, because a
snapshot is written into a .partial staging directory and renamed in as a
whole (see PendingSnapshot). Readers therefore treat a missing or
unparseable record as corruption rather than as a normal lifecycle state.
Implementations§
Source§impl SnapshotCatalog
impl SnapshotCatalog
Sourcepub fn new(data_dir: &str) -> SnapshotCatalog
pub fn new(data_dir: &str) -> SnapshotCatalog
Create a new catalog rooted at {data_dir}/snapshots.
Sourcepub fn begin(&self, vm_id: &str) -> Result<PendingSnapshot<'_>, SnapshotError>
pub fn begin(&self, vm_id: &str) -> Result<PendingSnapshot<'_>, SnapshotError>
Start a new snapshot for vm_id.
Creates the staging directory; the snapshot enters the catalog only on
PendingSnapshot::commit.
Sourcepub fn list(&self, vm_id: &str) -> Result<Vec<SnapshotInfo>, SnapshotError>
pub fn list(&self, vm_id: &str) -> Result<Vec<SnapshotInfo>, SnapshotError>
List all snapshots for a VM, sorted by creation time (oldest first).
Sourcepub fn get(
&self,
vm_id: &str,
snapshot_id: &str,
) -> Result<SnapshotMeta, SnapshotError>
pub fn get( &self, vm_id: &str, snapshot_id: &str, ) -> Result<SnapshotMeta, SnapshotError>
Look up a single snapshot by ID.
Sourcepub fn delete(
&self,
vm_id: &str,
snapshot_id: &str,
) -> Result<(), SnapshotError>
pub fn delete( &self, vm_id: &str, snapshot_id: &str, ) -> Result<(), SnapshotError>
Delete a snapshot directory from disk.
Sourcepub fn sweep_incomplete(&self)
pub fn sweep_incomplete(&self)
Remove staging directories left behind by a crash mid-checkpoint.
A committed snapshot is renamed into place atomically, so anything still staged when the process died is unfinished by definition — and can be holding a full memory dump.
Sourcepub fn find_by_id(
&self,
snapshot_id: &str,
) -> Result<SnapshotMeta, SnapshotError>
pub fn find_by_id( &self, snapshot_id: &str, ) -> Result<SnapshotMeta, SnapshotError>
Find a snapshot by ID alone, searching across all owner directories.
Sourcepub fn list_all(&self) -> Result<Vec<SnapshotInfo>, SnapshotError>
pub fn list_all(&self) -> Result<Vec<SnapshotInfo>, SnapshotError>
List all snapshots across every owner directory, sorted by creation time.
Sourcepub fn referenced_rootfs_paths(
&self,
) -> Result<BTreeSet<PathBuf>, SnapshotError>
pub fn referenced_rootfs_paths( &self, ) -> Result<BTreeSet<PathBuf>, SnapshotError>
Rootfs images that catalogued snapshots depend on.
Restore rebuilds the dm-snapshot origin from
SnapshotMeta::rootfs_path, and the guest memory in the snapshot was
captured against those exact bytes — re-converting the same image with a
different vm-agent produces a different file and is not a substitute.
Anything that garbage-collects rootfs images must treat these as pinned.
Sourcepub fn delete_by_id(&self, snapshot_id: &str) -> Result<(), SnapshotError>
pub fn delete_by_id(&self, snapshot_id: &str) -> Result<(), SnapshotError>
Delete a snapshot knowing only its ID (searches across all owner directories).