Check if the layer is actually mounted.

There are cases where the storage database gets out of whack with
whether or not the storage is actually mounted.  We need to check
before returning the mount point.

1 A user could go in and umount the storage.
2 If the storage was mounted in a different mount namespace and then
the mount namespace goes away the counter will never get decremented
even though the mount point was removed.
3. If storage runtime is on non tmpfs storage a system reboot could be
done that will not clear the mount count.

This patch will fix the problem with the layer not being mounted, but
we still have a problem in that we can't figure out when to umount the
image. Not sure that is a solveable problem.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
Daniel J Walsh 2019-12-18 12:26:10 -05:00
parent d8c256832f
commit 522b6498e5
No known key found for this signature in database
GPG Key ID: A2DF901DABE2C028
1 changed files with 12 additions and 2 deletions

View File

@ -18,6 +18,7 @@ import (
"github.com/containers/storage/pkg/archive"
"github.com/containers/storage/pkg/idtools"
"github.com/containers/storage/pkg/ioutils"
"github.com/containers/storage/pkg/mount"
"github.com/containers/storage/pkg/stringid"
"github.com/containers/storage/pkg/system"
"github.com/containers/storage/pkg/tarlog"
@ -776,8 +777,17 @@ func (r *layerStore) Mount(id string, options drivers.MountOpts) (string, error)
return "", ErrLayerUnknown
}
if layer.MountCount > 0 {
layer.MountCount++
return layer.MountPoint, r.saveMounts()
mounted, err := mount.Mounted(layer.MountPoint)
if err != nil {
return "", err
}
// If the container is not mounted then we have a condition
// where the kernel umounted the mount point. This means
// that the mount count never got decremented.
if mounted {
layer.MountCount++
return layer.MountPoint, r.saveMounts()
}
}
if options.MountLabel == "" {
options.MountLabel = layer.MountLabel