Skip to content

Commit

Permalink
Add force to umount to force the umount of a container image
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel J Walsh <[email protected]>
  • Loading branch information
rhatdan committed Jul 13, 2018
1 parent 90d0a58 commit cf6a5b5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions cmd/containers-storage/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func copyContent(flags *mflag.FlagSet, action string, m storage.Store, args []st
return 1
}
target = filepath.Join(targetMount, targetParts[1])
defer m.Unmount(targetLayer.ID)
defer m.Unmount(targetLayer.ID, false)
}
args = args[:len(args)-1]
for _, srcSpec := range args {
Expand All @@ -83,7 +83,7 @@ func copyContent(flags *mflag.FlagSet, action string, m storage.Store, args []st
return 1
}
source = filepath.Join(sourceMount, sourceParts[1])
defer m.Unmount(sourceLayer.ID)
defer m.Unmount(sourceLayer.ID, false)
}
archiver := chrootarchive.NewArchiverWithChown(tarIDMappings, chownOpts, untarIDMappings)
if err := archiver.CopyWithTar(source, target); err != nil {
Expand Down
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)
err := m.Unmount(arg, false)
errText := ""
if err != nil {
errText = fmt.Sprintf("%v", err)
Expand Down
15 changes: 8 additions & 7 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) error
Unmount(id string, force bool) error

// 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.
Expand Down Expand Up @@ -652,7 +652,7 @@ func (r *layerStore) Mount(id, mountLabel string) (string, error) {
return mountpoint, err
}

func (r *layerStore) Unmount(id string) error {
func (r *layerStore) Unmount(id string, force bool) error {
if !r.IsReadWrite() {
return errors.Wrapf(ErrStoreIsReadOnly, "not allowed to update mount locations for layers at %q", r.mountspath())
}
Expand All @@ -664,6 +664,9 @@ func (r *layerStore) Unmount(id string) error {
}
layer = layerByMount
}
if force {
layer.MountCount = 1
}
if layer.MountCount > 1 {
layer.MountCount--
return r.Save()
Expand Down Expand Up @@ -797,10 +800,8 @@ func (r *layerStore) Delete(id string) error {
return ErrLayerUnknown
}
id = layer.ID
for layer.MountCount > 0 {
if err := r.Unmount(id); err != nil {
return err
}
if err := r.Unmount(id, true); err != nil {
return err
}
err := r.driver.Remove(id)
if err == nil {
Expand Down Expand Up @@ -917,7 +918,7 @@ func (s *simpleGetCloser) Get(path string) (io.ReadCloser, error) {
}

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

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

// Unmount attempts to unmount a layer, image, or container, given an ID, a
// name, or a mount path.
Unmount(id string) error
Unmount(id string, force 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 @@ -2245,7 +2245,7 @@ func (s *store) Mount(id, mountLabel string) (string, error) {
return "", ErrLayerUnknown
}

func (s *store) Unmount(id string) error {
func (s *store) Unmount(id string, force bool) error {
if layerID, err := s.ContainerLayerID(id); err == nil {
id = layerID
}
Expand All @@ -2259,7 +2259,7 @@ func (s *store) Unmount(id string) error {
rlstore.Load()
}
if rlstore.Exists(id) {
return rlstore.Unmount(id)
return rlstore.Unmount(id, force)
}
return ErrLayerUnknown
}
Expand Down Expand Up @@ -2811,7 +2811,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)
err2 := rlstore.Unmount(layer.ID, force)
if err2 != nil {
if err == nil {
err = err2
Expand Down

0 comments on commit cf6a5b5

Please sign in to comment.