podman

Форк
0
/
volume_internal.go 
113 строк · 2.8 Кб
1
//go:build !remote
2

3
package libpod
4

5
import (
6
	"fmt"
7
	"os"
8
	"path/filepath"
9

10
	"github.com/containers/podman/v5/libpod/define"
11
)
12

13
// Creates a new volume
14
func newVolume(runtime *Runtime) *Volume {
15
	volume := new(Volume)
16
	volume.config = new(VolumeConfig)
17
	volume.state = new(VolumeState)
18
	volume.runtime = runtime
19
	volume.config.Labels = make(map[string]string)
20
	volume.config.Options = make(map[string]string)
21
	volume.state.NeedsCopyUp = true
22
	volume.state.NeedsChown = true
23
	return volume
24
}
25

26
// teardownStorage deletes the volume from volumePath
27
func (v *Volume) teardownStorage() error {
28
	if v.UsesVolumeDriver() {
29
		return nil
30
	}
31

32
	// TODO: Should this be converted to use v.config.MountPoint?
33
	return os.RemoveAll(filepath.Join(v.runtime.config.Engine.VolumePath, v.Name()))
34
}
35

36
// Volumes with options set, or a filesystem type, or a device to mount need to
37
// be mounted and unmounted.
38
func (v *Volume) needsMount() bool {
39
	// Non-local driver always needs mount
40
	if v.UsesVolumeDriver() {
41
		return true
42
	}
43

44
	// Image driver always needs mount
45
	if v.config.Driver == define.VolumeDriverImage {
46
		return true
47
	}
48

49
	// Commit 28138dafcc added the UID and GID options to this map
50
	// However we should only mount when options other than uid and gid are set.
51
	// see https://github.com/containers/podman/issues/10620
52
	index := 0
53
	if _, ok := v.config.Options["UID"]; ok {
54
		index++
55
	}
56
	if _, ok := v.config.Options["GID"]; ok {
57
		index++
58
	}
59
	if _, ok := v.config.Options["SIZE"]; ok {
60
		index++
61
	}
62
	if _, ok := v.config.Options["NOQUOTA"]; ok {
63
		index++
64
	}
65
	if _, ok := v.config.Options["nocopy"]; ok {
66
		index++
67
	}
68
	if _, ok := v.config.Options["copy"]; ok {
69
		index++
70
	}
71
	// when uid or gid is set there is also the "o" option
72
	// set so we have to ignore this one as well
73
	if index > 0 {
74
		index++
75
	}
76
	// Local driver with options other than uid,gid needs mount
77
	return len(v.config.Options) > index
78
}
79

80
// update() updates the volume state from the DB.
81
func (v *Volume) update() error {
82
	if err := v.runtime.state.UpdateVolume(v); err != nil {
83
		return err
84
	}
85
	if !v.valid {
86
		return define.ErrVolumeRemoved
87
	}
88
	return nil
89
}
90

91
// save() saves the volume state to the DB
92
func (v *Volume) save() error {
93
	return v.runtime.state.SaveVolume(v)
94
}
95

96
// Refresh volume state after a restart.
97
func (v *Volume) refresh() error {
98
	lock, err := v.runtime.lockManager.AllocateAndRetrieveLock(v.config.LockID)
99
	if err != nil {
100
		return fmt.Errorf("acquiring lock %d for volume %s: %w", v.config.LockID, v.Name(), err)
101
	}
102
	v.lock = lock
103

104
	return nil
105
}
106

107
// resetVolumeState resets state fields to default values.
108
// It is performed before a refresh and clears the state after a reboot.
109
// It does not save the results - assumes the database will do that for us.
110
func resetVolumeState(state *VolumeState) {
111
	state.MountCount = 0
112
	state.MountPoint = ""
113
}
114

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.