10
"github.com/containers/podman/v5/libpod/define"
13
// Creates a new volume
14
func newVolume(runtime *Runtime) *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
26
// teardownStorage deletes the volume from volumePath
27
func (v *Volume) teardownStorage() error {
28
if v.UsesVolumeDriver() {
32
// TODO: Should this be converted to use v.config.MountPoint?
33
return os.RemoveAll(filepath.Join(v.runtime.config.Engine.VolumePath, v.Name()))
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() {
44
// Image driver always needs mount
45
if v.config.Driver == define.VolumeDriverImage {
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
53
if _, ok := v.config.Options["UID"]; ok {
56
if _, ok := v.config.Options["GID"]; ok {
59
if _, ok := v.config.Options["SIZE"]; ok {
62
if _, ok := v.config.Options["NOQUOTA"]; ok {
65
if _, ok := v.config.Options["nocopy"]; ok {
68
if _, ok := v.config.Options["copy"]; ok {
71
// when uid or gid is set there is also the "o" option
72
// set so we have to ignore this one as well
76
// Local driver with options other than uid,gid needs mount
77
return len(v.config.Options) > index
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 {
86
return define.ErrVolumeRemoved
91
// save() saves the volume state to the DB
92
func (v *Volume) save() error {
93
return v.runtime.state.SaveVolume(v)
96
// Refresh volume state after a restart.
97
func (v *Volume) refresh() error {
98
lock, err := v.runtime.lockManager.AllocateAndRetrieveLock(v.config.LockID)
100
return fmt.Errorf("acquiring lock %d for volume %s: %w", v.config.LockID, v.Name(), err)
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) {
112
state.MountPoint = ""