Skip to content

SR: Phase 4: Full restore with incremental container adoption - #550

Merged
Roaa Sakr (romoh) merged 5 commits into
msft-mainfrom
cameronbaird/msft-main/phase4-rs-snapshot-restore-feature
Sep 18, 2026
Merged

Roaa Sakr (romoh) merged 5 commits into
msft-mainfrom
cameronbaird/msft-main/phase4-rs-snapshot-restore-feature

Conversation

@Camelron

Copy link
Copy Markdown

Consume live and completed container accounting during the snapshot phase.
This tells us which containers were naturally completed
(init or ephemeral containers) and which are currently running
(workload, pause).

For live containers only, the restore path adopts the guest processes,
storing mappings for the new containerd-provided ctr ids to the
snapshotted instance's guest ids held by the agent. We then
refresh the mounts and resume the cgroup, which was paused during
snapshot.

For incoming CreateContainers for completed containers,
handle this synthetically. Respond with normal TaskStart and
then TaskExit events.

Copilot AI balanced review requested due to automatic review settings August 27, 2026 23:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds full snapshot restoration with live-container adoption, synthetic completion handling, identity mapping, and recursive snapshot support.

Changes:

  • Records live/completed container identities and persists restore state.
  • Adopts restored guest processes and refreshes node-local mounts.
  • Adds restored rootfs/device lifecycle and agent mount-preparation APIs.

Reviewed changes

Copilot reviewed 31 out of 32 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/runtime-rs/crates/runtimes/virt_container/src/sandbox.rs Builds and restores expanded snapshot manifests.
src/runtime-rs/crates/runtimes/virt_container/src/sandbox_persist.rs Persists restore state.
src/runtime-rs/crates/runtimes/virt_container/src/restore.rs Implements adoption, identity hashing, and completion tracking.
src/runtime-rs/crates/runtimes/virt_container/src/container_manager/process.rs Separates host/guest process identities.
src/runtime-rs/crates/runtimes/virt_container/src/container_manager/manager.rs Handles adopted and synthetic containers.
src/runtime-rs/crates/runtimes/virt_container/src/container_manager/container.rs Routes operations through guest IDs.
src/runtime-rs/crates/runtimes/virt_container/src/container_manager/container_inner.rs Applies guest IDs to agent RPCs.
src/runtime-rs/crates/runtimes/virt_container/Cargo.toml Adds SHA-256 support.
src/runtime-rs/crates/runtimes/src/manager.rs Persists lifecycle transitions and emits events.
src/runtime-rs/crates/runtimes/common/src/types/mod.rs Defines snapshot inventory types.
src/runtime-rs/crates/runtimes/common/src/sandbox.rs Adds runtime-state persistence API.
src/runtime-rs/crates/runtimes/common/src/container_manager.rs Adds synthetic completion API.
src/runtime-rs/crates/resource/src/volume/share_fs_volume.rs Refreshes copied guest mounts.
src/runtime-rs/crates/resource/src/volume/mod.rs Exposes snapshot mount metadata.
src/runtime-rs/crates/resource/src/rootfs/snapshot.rs Rewrites recursive snapshot disk configuration.
src/runtime-rs/crates/resource/src/rootfs/restored_rootfs.rs Implements restored rootfs lifecycle.
src/runtime-rs/crates/resource/src/rootfs/mod.rs Registers and manages restored rootfs objects.
src/runtime-rs/crates/resource/src/manager.rs Exposes restore resource operations.
src/runtime-rs/crates/resource/src/manager_inner.rs Performs guest mount refreshes.
src/runtime-rs/crates/hypervisor/src/lib.rs Adds restored-device removal API.
src/runtime-rs/crates/hypervisor/src/device/device_manager.rs Delegates restored-device removal.
src/runtime-rs/crates/hypervisor/src/ch/mod.rs Implements removal for Cloud Hypervisor.
src/runtime-rs/crates/hypervisor/src/ch/inner_hypervisor.rs Documents paused restore/network behavior.
src/runtime-rs/crates/hypervisor/src/ch/inner_device.rs Removes restored CLH devices by ID.
src/runtime-rs/crates/agent/src/types.rs Defines guest-mount preparation request.
src/runtime-rs/crates/agent/src/lib.rs Extends the agent interface.
src/runtime-rs/crates/agent/src/kata/trans.rs Converts the new request type.
src/runtime-rs/crates/agent/src/kata/agent.rs Registers the agent RPC.
src/libs/protocols/protos/agent.proto Defines PrepareGuestMount.
src/agent/src/rpc.rs Implements guest mount clearing.
src/agent/src/netlink.rs Clarifies restored interface replacement.
Cargo.lock Locks the SHA-256 dependency.
Suppressed comments (2)

src/runtime-rs/crates/runtimes/src/manager.rs:723

  • delete_process has already removed and cleaned the task before this save runs. If persistence fails, Delete returns an error and suppresses TaskDelete, but a retry sees ContainerNotFound, leaving containerd unable to complete deletion. The durable state update and externally visible delete result need failure semantics that do not report a reversible failure after the irreversible mutation.
                sandbox
                    .persist_runtime_state()
                    .await
                    .context("persist process deletion")?;

src/runtime-rs/crates/runtimes/src/manager.rs:830

  • This save can fail after the process was resumed (or synthetically completed) and after TaskStart was published. Returning a Start error then contradicts the already-observed event and may cause containerd to retry a running task. Persist before publishing success where possible, or treat a post-commit save failure as a fatal recovery condition rather than a failed Start RPC.
                    sandbox
                        .persist_runtime_state()
                        .await
                        .context("persist container start")?;

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/runtime-rs/crates/runtimes/virt_container/src/sandbox.rs
Comment thread src/runtime-rs/crates/runtimes/virt_container/src/restore.rs Outdated
Comment thread src/runtime-rs/crates/runtimes/virt_container/src/restore.rs
Comment thread src/runtime-rs/crates/runtimes/src/manager.rs
Comment on lines +339 to +343
self.resource_manager
.cleanup_restored_rootfs(container_id)
.await
.context("detach deleted restored rootfs")?;
self.restore_context.retire_live(container_id).await;
Comment thread src/agent/src/rpc.rs
Comment thread src/runtime-rs/crates/resource/src/rootfs/snapshot.rs
@Camelron
Cameron E Baird (Camelron) force-pushed the cameronbaird/msft-main/phase4-rs-snapshot-restore-feature branch from 06d013b to 4508c9a Compare August 31, 2026 21:45
@Camelron
Cameron E Baird (Camelron) force-pushed the cameronbaird/msft-main/phase4-rs-snapshot-restore-feature branch from c9338f4 to 2afc1b3 Compare September 1, 2026 22:57
@Camelron
Cameron E Baird (Camelron) force-pushed the cameronbaird/msft-main/phase4-rs-snapshot-restore-feature branch 2 times, most recently from 4a0ec93 to 82f7cb9 Compare September 4, 2026 23:17
@Camelron
Cameron E Baird (Camelron) force-pushed the cameronbaird/msft-main/phase4-rs-snapshot-restore-feature branch from 82f7cb9 to 7d5c452 Compare September 9, 2026 18:51
@Camelron
Cameron E Baird (Camelron) force-pushed the cameronbaird/msft-main/phase4-rs-snapshot-restore-feature branch 2 times, most recently from 9e4a695 to defed5a Compare September 9, 2026 23:39
@Camelron
Cameron E Baird (Camelron) force-pushed the cameronbaird/msft-main/phase4-rs-snapshot-restore-feature branch from defed5a to 134eb88 Compare September 10, 2026 18:45
@Camelron
Cameron E Baird (Camelron) force-pushed the cameronbaird/msft-main/phase4-rs-snapshot-restore-feature branch from 134eb88 to f657dc7 Compare September 10, 2026 18:51
@Camelron
Cameron E Baird (Camelron) force-pushed the cameronbaird/msft-main/phase4-rs-snapshot-restore-feature branch from f657dc7 to 0ce75d1 Compare September 11, 2026 19:03
@Camelron
Cameron E Baird (Camelron) force-pushed the cameronbaird/msft-main/phase4-rs-snapshot-restore-feature branch from 0ce75d1 to 089ecd3 Compare September 15, 2026 20:50
@Camelron
Cameron E Baird (Camelron) force-pushed the cameronbaird/msft-main/phase4-rs-snapshot-restore-feature branch from 089ecd3 to 3daac79 Compare September 15, 2026 23:01
@Camelron
Cameron E Baird (Camelron) force-pushed the cameronbaird/msft-main/phase4-rs-snapshot-restore-feature branch from 3daac79 to 34b9009 Compare September 15, 2026 23:32
@Camelron
Cameron E Baird (Camelron) force-pushed the cameronbaird/msft-main/phase4-rs-snapshot-restore-feature branch from 34b9009 to 367a9b7 Compare September 16, 2026 17:57
@Camelron
Cameron E Baird (Camelron) force-pushed the cameronbaird/msft-main/phase4-rs-snapshot-restore-feature branch from 367a9b7 to 35041e8 Compare September 16, 2026 19:14
@Camelron
Cameron E Baird (Camelron) force-pushed the cameronbaird/msft-main/phase4-rs-snapshot-restore-feature branch from 35041e8 to af5a321 Compare September 16, 2026 20:33
@Camelron
Cameron E Baird (Camelron) force-pushed the cameronbaird/msft-main/phase4-rs-snapshot-restore-feature branch 2 times, most recently from 50dda97 to 851be9e Compare September 16, 2026 23:15
@Camelron
Cameron E Baird (Camelron) force-pushed the cameronbaird/msft-main/phase4-rs-snapshot-restore-feature branch 5 times, most recently from 56716cd to 69df05a Compare September 17, 2026 00:18
@Camelron
Cameron E Baird (Camelron) force-pushed the cameronbaird/msft-main/phase4-rs-snapshot-restore-feature branch from 69df05a to 1a4da9a Compare September 17, 2026 16:35
Base automatically changed from cameronbaird/msft-main/phase3-rs-snapshot-restore-feature to msft-main September 17, 2026 21:54
Add live and completed container accounting during the snapshot phase.
This tells us which containers were naturally completed
(init or ephemeral containers) and which are currently running
(workload, pause).

For live containers only, the restore path adopts the guest processes,
storing mappings for the new containerd-provided ctr ids to the
snapshotted instance's guest ids held by the agent. We then
refresh the mounts and resume the cgroup, which was paused during
snapshot.

For incoming CreateContainers for completed containers,
handle this synthetically. Respond with normal TaskStart and
then TaskExit events.

Signed-off-by: Cameron Baird <cameronbaird@microsoft.com>
Assisted-by: Sol 5.6
If a new container arrives after all live and completed contianters
are accounted for from the snapshot manifest, allow them to proceed as
new cold-started containers.

This allows us to support ephemeral containers such as from
kubectl debug --target=app...

Signed-off-by: Cameron Baird <cameronbaird@microsoft.com>
Assisted-by: Sol:5.6
Containers in a pod may be deployed with restartPolicy: Always or
similar.

In this case, we delete the old restored container and cold-start
a replacement. However, this transaction didn't update the
RestoreContext
didn't recieve these updates, causing subsequent snapshot/restores
to fail.

Now at the point a container delete request lands in runtime-rs,
we update the RestoreContext and hypervisor such that the old VMDK/disks
are removed, and unplugged. When the restarting container cold-starts
(a full Create-StartContainer), it becomes a Running and therefore
a target of the snapshot path if one later occurs.

Signed-off-by: Cameron Baird <cameronbaird@microsoft.com>
Assisted-by: Sol 5.6
For a given Pod with multiple instances of the same container
image (e.g. 3 busybox containers inside one pod),
kata deduplicates the number of disks attached to the VM,
attaching only one disk for the three containers who
reference it. We must account for this
in the snapshot, deduplicating layers/disks.

Signed-off-by: Cameron Baird <cameronbaird@microsoft.com>
Assisted-by: Sol 5.6
Skip runtime-state persistence after sandbox teardown has started and
prevent cleanup from removing the persistence directory during a save.

Bound best-effort Nydus unmount requests to five seconds and apply the
deadline to the complete HTTP response. This prevents Nydus cleanup from
blocking process-exit publication past the CRI StopPodSandbox timeout.

Signed-off-by: Cameron Baird <cameronbaird@microsoft.com>
Assisted-by: Sol:5.6
@Camelron
Cameron E Baird (Camelron) force-pushed the cameronbaird/msft-main/phase4-rs-snapshot-restore-feature branch from b0a1422 to 48f4fd8 Compare September 17, 2026 21:54
#[async_trait]
impl Rootfs for RestoredRootfs {
async fn get_guest_rootfs_path(&self) -> Result<String> {
Ok("/run/kata-containers/shared/containers/restored/rootfs".to_string())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Use known global to construct this path.

@romoh
Roaa Sakr (romoh) merged commit efc44c9 into msft-main Sep 18, 2026
229 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants