"fern/pages/kubernetes/quickstart.md" did not exist on "3057af00b6ceb41e8179c177d5446917a102bdba"
mounts.go 1.21 KB
Newer Older
1
2
3
4
5
6
7
8
package restore

import (
	"fmt"

	criurpc "github.com/checkpoint-restore/go-criu/v7/rpc"
	"google.golang.org/protobuf/proto"

9
	"github.com/ai-dynamo/dynamo/deploy/chrek/pkg/checkpoint"
10
11
12
)

// GenerateExtMountMaps generates external mount mappings for CRIU restore.
13
14
15
16
17
18
19
20
// It reuses the exact dump-time ext-mount plan persisted in checkpoint manifest.
func GenerateExtMountMaps(data *checkpoint.CheckpointManifest) ([]*criurpc.ExtMountMap, error) {
	if data == nil {
		return nil, fmt.Errorf("checkpoint manifest is required")
	}
	if len(data.CRIUDump.ExtMnt) == 0 {
		return nil, fmt.Errorf("checkpoint manifest is missing criuDump.extMnt")
	}
21

22
	maps := []*criurpc.ExtMountMap{{
23
24
		Key: proto.String("/"),
		Val: proto.String("."),
25
26
	}}
	addedMounts := map[string]struct{}{"/": {}}
27

28
29
30
31
	// Replay dump-time ext-mount plan exactly, with restore-specific root remap.
	for _, mount := range data.CRIUDump.ExtMnt {
		key := mount.Key
		if key == "" || key == "/" {
32
33
			continue
		}
34
		if _, exists := addedMounts[key]; exists {
35
36
			continue
		}
37
38
39
40
		val := mount.Val
		if val == "" {
			val = key
		}
41
		maps = append(maps, &criurpc.ExtMountMap{
42
43
			Key: proto.String(key),
			Val: proto.String(val),
44
		})
45
		addedMounts[key] = struct{}{}
46
47
48
49
	}

	return maps, nil
}