Skip to content

Commit

Permalink
Add a boolean return form unmount to indicate when the layer is reall…
Browse files Browse the repository at this point in the history
…y unmounted

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
  • Loading branch information
rhatdan committed Jul 13, 2018
1 parent 2d56a7f commit cc9ecef
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cmd/containers-storage/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func unmount(flags *mflag.FlagSet, action string, m storage.Store, args []string
mes := []mountPointError{}
errors := false
for _, arg := range args {
err := m.Unmount(arg, false)
_, err := m.Unmount(arg, false)
errText := ""
if err != nil {
errText = fmt.Sprintf("%v", err)
Expand Down
17 changes: 9 additions & 8 deletions layers.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ type LayerStore interface {
Mount(id, mountLabel string) (string, error)

// Unmount unmounts a layer when it is no longer in use.
Unmount(id string, force bool) error
Unmount(id string, force bool) (bool, error)

// Mounted returns whether or not the layer is mounted
Mounted(id string) (bool, error)
Expand Down Expand Up @@ -663,15 +663,15 @@ func (r *layerStore) Mount(id, mountLabel string) (string, error) {
return mountpoint, err
}

func (r *layerStore) Unmount(id string, force bool) error {
func (r *layerStore) Unmount(id string, force bool) (bool, error) {
if !r.IsReadWrite() {
return errors.Wrapf(ErrStoreIsReadOnly, "not allowed to update mount locations for layers at %q", r.mountspath())
return false, errors.Wrapf(ErrStoreIsReadOnly, "not allowed to update mount locations for layers at %q", r.mountspath())
}
layer, ok := r.lookup(id)
if !ok {
layerByMount, ok := r.bymount[filepath.Clean(id)]
if !ok {
return ErrLayerUnknown
return false, ErrLayerUnknown
}
layer = layerByMount
}
Expand All @@ -680,7 +680,7 @@ func (r *layerStore) Unmount(id string, force bool) error {
}
if layer.MountCount > 1 {
layer.MountCount--
return r.Save()
return true, r.Save()
}
err := r.driver.Put(id)
if err == nil || os.IsNotExist(err) {
Expand All @@ -691,7 +691,7 @@ func (r *layerStore) Unmount(id string, force bool) error {
layer.MountPoint = ""
err = r.Save()
}
return err
return false, err
}

func (r *layerStore) ParentOwners(id string) (uids, gids []int, err error) {
Expand Down Expand Up @@ -811,7 +811,7 @@ func (r *layerStore) Delete(id string) error {
return ErrLayerUnknown
}
id = layer.ID
if err := r.Unmount(id, true); err != nil {
if _, err := r.Unmount(id, true); err != nil {
return err
}
err := r.driver.Remove(id)
Expand Down Expand Up @@ -929,7 +929,8 @@ func (s *simpleGetCloser) Get(path string) (io.ReadCloser, error) {
}

func (s *simpleGetCloser) Close() error {
return s.r.Unmount(s.id, false)
_, err := s.r.Unmount(s.id, false)
return err
}

func (r *layerStore) newFileGetter(id string) (drivers.FileGetCloser, error) {
Expand Down
12 changes: 6 additions & 6 deletions store.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ type Store interface {
Mount(id, mountLabel string) (string, error)

// Unmount attempts to unmount a layer, image, or container, given an ID, a
// name, or a mount path.
Unmount(id string, force bool) error
// name, or a mount path. Returns whether or not the layer is still mounted
Unmount(id string, force bool) (bool, error)

// 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
Expand Down Expand Up @@ -2262,13 +2262,13 @@ func (s *store) Mounted(id string) (bool, error) {
return rlstore.Mounted(id)
}

func (s *store) Unmount(id string, force bool) error {
func (s *store) Unmount(id string, force bool) (bool, error) {
if layerID, err := s.ContainerLayerID(id); err == nil {
id = layerID
}
rlstore, err := s.LayerStore()
if err != nil {
return err
return false, err
}
rlstore.Lock()
defer rlstore.Unlock()
Expand All @@ -2278,7 +2278,7 @@ func (s *store) Unmount(id string, force bool) error {
if rlstore.Exists(id) {
return rlstore.Unmount(id, force)
}
return ErrLayerUnknown
return false, ErrLayerUnknown
}

func (s *store) Changes(from, to string) ([]archive.Change, error) {
Expand Down Expand Up @@ -2828,7 +2828,7 @@ func (s *store) Shutdown(force bool) ([]string, error) {
mounted = append(mounted, layer.ID)
if force {
for layer.MountCount > 0 {
err2 := rlstore.Unmount(layer.ID, force)
_, err2 := rlstore.Unmount(layer.ID, force)
if err2 != nil {
if err == nil {
err = err2
Expand Down

0 comments on commit cc9ecef

Please sign in to comment.