summaryrefslogtreecommitdiff
path: root/libpod/boltdb_state.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2022-09-23 14:41:55 +0200
committerGitHub <noreply@github.com>2022-09-23 14:41:55 +0200
commita80c406f833190070636c5982f5b0aff58f9b23d (patch)
treeb694fa3e2fe8e5d134b83ca64b4f6867987e2456 /libpod/boltdb_state.go
parent0d65c2481973a956bb90e393814a18ceb6389450 (diff)
parentfc6dcd12b3430f2d1ee495ef19d184a088f3bb34 (diff)
downloadpodman-a80c406f833190070636c5982f5b0aff58f9b23d.tar.gz
podman-a80c406f833190070636c5982f5b0aff58f9b23d.tar.bz2
podman-a80c406f833190070636c5982f5b0aff58f9b23d.zip
Merge pull request #15841 from mheon/image_driver
Add support for 'image' volume driver
Diffstat (limited to 'libpod/boltdb_state.go')
-rw-r--r--libpod/boltdb_state.go53
1 files changed, 53 insertions, 0 deletions
diff --git a/libpod/boltdb_state.go b/libpod/boltdb_state.go
index 4fd95a3cf..77c234892 100644
--- a/libpod/boltdb_state.go
+++ b/libpod/boltdb_state.go
@@ -109,6 +109,7 @@ func NewBoltState(path string, runtime *Runtime) (State, error) {
runtimeConfigBkt,
exitCodeBkt,
exitCodeTimeStampBkt,
+ volCtrsBkt,
}
// Does the DB need an update?
@@ -2551,6 +2552,11 @@ func (s *BoltState) AddVolume(volume *Volume) error {
return err
}
+ volCtrsBkt, err := getVolumeContainersBucket(tx)
+ if err != nil {
+ return err
+ }
+
// Check if we already have a volume with the given name
volExists := allVolsBkt.Get(volName)
if volExists != nil {
@@ -2580,6 +2586,12 @@ func (s *BoltState) AddVolume(volume *Volume) error {
}
}
+ if volume.config.StorageID != "" {
+ if err := volCtrsBkt.Put([]byte(volume.config.StorageID), volName); err != nil {
+ return fmt.Errorf("storing volume %s container ID in DB: %w", volume.Name(), err)
+ }
+ }
+
if err := allVolsBkt.Put(volName, volName); err != nil {
return fmt.Errorf("storing volume %s in all volumes bucket in DB: %w", volume.Name(), err)
}
@@ -2619,6 +2631,11 @@ func (s *BoltState) RemoveVolume(volume *Volume) error {
return err
}
+ volCtrIDBkt, err := getVolumeContainersBucket(tx)
+ if err != nil {
+ return err
+ }
+
// Check if the volume exists
volDB := volBkt.Bucket(volName)
if volDB == nil {
@@ -2665,6 +2682,11 @@ func (s *BoltState) RemoveVolume(volume *Volume) error {
if err := volBkt.DeleteBucket(volName); err != nil {
return fmt.Errorf("removing volume %s from DB: %w", volume.Name(), err)
}
+ if volume.config.StorageID != "" {
+ if err := volCtrIDBkt.Delete([]byte(volume.config.StorageID)); err != nil {
+ return fmt.Errorf("removing volume %s container ID from DB: %w", volume.Name(), err)
+ }
+ }
return nil
})
@@ -3618,3 +3640,34 @@ func (s *BoltState) AllPods() ([]*Pod, error) {
return pods, nil
}
+
+// ContainerIDIsVolume checks if the given c/storage container ID is used as
+// backing storage for a volume.
+func (s *BoltState) ContainerIDIsVolume(id string) (bool, error) {
+ if !s.valid {
+ return false, define.ErrDBClosed
+ }
+
+ isVol := false
+
+ db, err := s.getDBCon()
+ if err != nil {
+ return false, err
+ }
+ defer s.deferredCloseDBCon(db)
+
+ err = db.View(func(tx *bolt.Tx) error {
+ volCtrsBkt, err := getVolumeContainersBucket(tx)
+ if err != nil {
+ return err
+ }
+
+ volName := volCtrsBkt.Get([]byte(id))
+ if volName != nil {
+ isVol = true
+ }
+
+ return nil
+ })
+ return isVol, err
+}