Change Mounted to return the number of times mounted

podman unmount wants to know if the image is only mounted 1 time
and refuse to unmount if the container state expects it to be mounted.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
Daniel J Walsh 2018-07-17 16:27:25 -04:00
parent 46a8a1cddb
commit 1538971882
No known key found for this signature in database
GPG Key ID: A2DF901DABE2C028
4 changed files with 11 additions and 11 deletions

View File

@ -88,7 +88,7 @@ func mounted(flags *mflag.FlagSet, action string, m storage.Store, args []string
errText = fmt.Sprintf("%v", err) errText = fmt.Sprintf("%v", err)
errors = true errors = true
} else { } else {
if mounted { if mounted > 0 {
fmt.Printf("%s mounted\n", arg) fmt.Printf("%s mounted\n", arg)
} }
} }

View File

@ -213,8 +213,8 @@ type LayerStore interface {
// Unmount unmounts a layer when it is no longer in use. // Unmount unmounts a layer when it is no longer in use.
Unmount(id string, force bool) (bool, error) Unmount(id string, force bool) (bool, error)
// Mounted returns whether or not the layer is mounted. // Mounted returns number of times the layer has been mounted.
Mounted(id string) (bool, error) Mounted(id string) (int, error)
// ParentOwners returns the UIDs and GIDs of parents of the layer's mountpoint // ParentOwners returns the UIDs and GIDs of parents of the layer's mountpoint
// for which the layer's UID and GID maps don't contain corresponding entries. // for which the layer's UID and GID maps don't contain corresponding entries.
@ -627,12 +627,12 @@ func (r *layerStore) Create(id string, parent *Layer, names []string, mountLabel
return r.CreateWithFlags(id, parent, names, mountLabel, options, moreOptions, writeable, nil) return r.CreateWithFlags(id, parent, names, mountLabel, options, moreOptions, writeable, nil)
} }
func (r *layerStore) Mounted(id string) (bool, error) { func (r *layerStore) Mounted(id string) (int, error) {
layer, ok := r.lookup(id) layer, ok := r.lookup(id)
if !ok { if !ok {
return false, ErrLayerUnknown return 0, ErrLayerUnknown
} }
return layer.MountCount > 0, nil return layer.MountCount, nil
} }
func (r *layerStore) Mount(id, mountLabel string) (string, error) { func (r *layerStore) Mount(id, mountLabel string) (string, error) {

View File

@ -1,5 +1,5 @@
// Code generated by ffjson <https://github.com/pquerna/ffjson>. DO NOT EDIT. // Code generated by ffjson <https://github.com/pquerna/ffjson>. DO NOT EDIT.
// source: ./layers.go // source: layers.go
package storage package storage

View File

@ -265,8 +265,8 @@ type Store interface {
// name, or a mount path. Returns whether or not the layer is still mounted. // name, or a mount path. Returns whether or not the layer is still mounted.
Unmount(id string, force bool) (bool, error) Unmount(id string, force bool) (bool, error)
// Unmount attempts to discover whether the specified id is mounted. // Mounted returns number of times the layer has been mounted.
Mounted(id string) (bool, error) Mounted(id string) (int, error)
// Changes returns a summary of the changes which would need to be made // Changes returns a summary of the changes which would need to be made
// to one layer to make its contents the same as a second layer. If // to one layer to make its contents the same as a second layer. If
@ -2248,13 +2248,13 @@ func (s *store) Mount(id, mountLabel string) (string, error) {
return "", ErrLayerUnknown return "", ErrLayerUnknown
} }
func (s *store) Mounted(id string) (bool, error) { func (s *store) Mounted(id string) (int, error) {
if layerID, err := s.ContainerLayerID(id); err == nil { if layerID, err := s.ContainerLayerID(id); err == nil {
id = layerID id = layerID
} }
rlstore, err := s.LayerStore() rlstore, err := s.LayerStore()
if err != nil { if err != nil {
return false, err return 0, err
} }
rlstore.Lock() rlstore.Lock()
defer rlstore.Unlock() defer rlstore.Unlock()