File: pod_internal.go

package info (click to toggle)
podman 5.7.0%2Bds2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 23,824 kB
  • sloc: sh: 4,700; python: 2,798; perl: 1,885; ansic: 1,484; makefile: 977; ruby: 42; csh: 8
file content (78 lines) | stat: -rw-r--r-- 1,841 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//go:build !remote

package libpod

import (
	"fmt"
	"time"

	"github.com/containers/podman/v5/libpod/define"
	"go.podman.io/storage/pkg/stringid"
)

// Creates a new, empty pod
func newPod(runtime *Runtime) *Pod {
	pod := new(Pod)
	pod.config = new(PodConfig)
	pod.config.ID = stringid.GenerateRandomID()
	pod.config.Labels = make(map[string]string)
	pod.config.CreatedTime = time.Now()
	//	pod.config.InfraContainer = new(ContainerConfig)
	pod.state = new(podState)
	pod.runtime = runtime

	return pod
}

// Update pod state from database
func (p *Pod) updatePod() error {
	if err := p.runtime.state.UpdatePod(p); err != nil {
		return err
	}

	return nil
}

// Save pod state to database
func (p *Pod) save() error {
	if err := p.runtime.state.SavePod(p); err != nil {
		return fmt.Errorf("saving pod %s state: %w", p.ID(), err)
	}

	return nil
}

// Refresh a pod's state after restart
// This cannot lock any other pod, but may lock individual containers, as those
// will have refreshed by the time pod refresh runs.
func (p *Pod) refresh() error {
	// Need to do an update from the DB to pull potentially-missing state
	if err := p.runtime.state.UpdatePod(p); err != nil {
		return err
	}

	if !p.valid {
		return define.ErrPodRemoved
	}

	// Retrieve the pod's lock
	lock, err := p.runtime.lockManager.AllocateAndRetrieveLock(p.config.LockID)
	if err != nil {
		return fmt.Errorf("retrieving lock %d for pod %s: %w", p.config.LockID, p.ID(), err)
	}
	p.lock = lock

	if err := p.platformRefresh(); err != nil {
		return err
	}

	// Save changes
	return p.save()
}

// resetPodState resets state fields to default values.
// It is performed before a refresh and clears the state after a reboot.
// It does not save the results - assumes the database will do that for us.
func resetPodState(state *podState) {
	state.CgroupPath = ""
}