mirror of
https://github.com/containers/podman.git
synced 2025-05-20 08:36:23 +08:00

We added the concept of image volumes in 2.2.0, to support inspecting an image from within a container. However, this is a strictly read-only mount, with no modification allowed. By contrast, the new `image` volume driver creates a c/storage container as its underlying storage, so we have a read/write layer. This, in and of itself, is not especially interesting, but what it will enable in the future is. If we add a new command to allow these image volumes to be committed, we can now distribute volumes - and changes to them - via a standard OCI image registry (which is rather new and quite exciting). Future work in this area: - Add support for `podman volume push` (commit volume changes and push resulting image to OCI registry). - Add support for `podman volume pull` (currently, we require that the image a volume is created from be already pulled; it would be simpler if we had a dedicated command that did the pull and made a volume from it) - Add support for scratch images (make an empty image on demand to use as the base of the volume) - Add UOR support to `podman volume push` and `podman volume pull` to enable both with non-image volume drivers Signed-off-by: Matthew Heon <matthew.heon@pm.me>
104 lines
2.5 KiB
Go
104 lines
2.5 KiB
Go
package libpod
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/containers/podman/v4/libpod/define"
|
|
)
|
|
|
|
// Creates a new volume
|
|
func newVolume(runtime *Runtime) *Volume {
|
|
volume := new(Volume)
|
|
volume.config = new(VolumeConfig)
|
|
volume.state = new(VolumeState)
|
|
volume.runtime = runtime
|
|
volume.config.Labels = make(map[string]string)
|
|
volume.config.Options = make(map[string]string)
|
|
volume.state.NeedsCopyUp = true
|
|
volume.state.NeedsChown = true
|
|
return volume
|
|
}
|
|
|
|
// teardownStorage deletes the volume from volumePath
|
|
func (v *Volume) teardownStorage() error {
|
|
if v.UsesVolumeDriver() {
|
|
return nil
|
|
}
|
|
|
|
// TODO: Should this be converted to use v.config.MountPoint?
|
|
return os.RemoveAll(filepath.Join(v.runtime.config.Engine.VolumePath, v.Name()))
|
|
}
|
|
|
|
// Volumes with options set, or a filesystem type, or a device to mount need to
|
|
// be mounted and unmounted.
|
|
func (v *Volume) needsMount() bool {
|
|
// Non-local driver always needs mount
|
|
if v.UsesVolumeDriver() {
|
|
return true
|
|
}
|
|
|
|
// Image driver always needs mount
|
|
if v.config.Driver == define.VolumeDriverImage {
|
|
return true
|
|
}
|
|
|
|
// Commit 28138dafcc added the UID and GID options to this map
|
|
// However we should only mount when options other than uid and gid are set.
|
|
// see https://github.com/containers/podman/issues/10620
|
|
index := 0
|
|
if _, ok := v.config.Options["UID"]; ok {
|
|
index++
|
|
}
|
|
if _, ok := v.config.Options["GID"]; ok {
|
|
index++
|
|
}
|
|
if _, ok := v.config.Options["SIZE"]; ok {
|
|
index++
|
|
}
|
|
if _, ok := v.config.Options["NOQUOTA"]; ok {
|
|
index++
|
|
}
|
|
if _, ok := v.config.Options["nocopy"]; ok {
|
|
index++
|
|
}
|
|
if _, ok := v.config.Options["copy"]; ok {
|
|
index++
|
|
}
|
|
// when uid or gid is set there is also the "o" option
|
|
// set so we have to ignore this one as well
|
|
if index > 0 {
|
|
index++
|
|
}
|
|
// Local driver with options other than uid,gid needs mount
|
|
return len(v.config.Options) > index
|
|
}
|
|
|
|
// update() updates the volume state from the DB.
|
|
func (v *Volume) update() error {
|
|
if err := v.runtime.state.UpdateVolume(v); err != nil {
|
|
return err
|
|
}
|
|
if !v.valid {
|
|
return define.ErrVolumeRemoved
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// save() saves the volume state to the DB
|
|
func (v *Volume) save() error {
|
|
return v.runtime.state.SaveVolume(v)
|
|
}
|
|
|
|
// Refresh volume state after a restart.
|
|
func (v *Volume) refresh() error {
|
|
lock, err := v.runtime.lockManager.AllocateAndRetrieveLock(v.config.LockID)
|
|
if err != nil {
|
|
return fmt.Errorf("acquiring lock %d for volume %s: %w", v.config.LockID, v.Name(), err)
|
|
}
|
|
v.lock = lock
|
|
|
|
return nil
|
|
}
|