Make sure plugin rootfs is unmounted on upgraded
In some cases, if a user specifies `-f` when disabling a plugin mounts
can still exist on the plugin rootfs.
This can cause problems during upgrade where the rootfs is removed and
may cause data loss.
To resolve this, ensure the rootfs is unmounted
before performing an upgrade.
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
(cherry picked from commit 83f44d232d
)
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
parent
9e241de40b
commit
3600abb7aa
2 changed files with 10 additions and 2 deletions
|
@ -575,7 +575,7 @@ func (pm *Manager) Remove(name string, config *types.PluginRmConfig) error {
|
||||||
func getMounts(root string) ([]string, error) {
|
func getMounts(root string) ([]string, error) {
|
||||||
infos, err := mount.GetMounts()
|
infos, err := mount.GetMounts()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to read mount table while performing recursive unmount")
|
return nil, errors.Wrap(err, "failed to read mount table")
|
||||||
}
|
}
|
||||||
|
|
||||||
var mounts []string
|
var mounts []string
|
||||||
|
|
|
@ -171,9 +171,17 @@ func (pm *Manager) upgradePlugin(p *v2.Plugin, configDigest digest.Digest, blobs
|
||||||
|
|
||||||
pdir := filepath.Join(pm.config.Root, p.PluginObj.ID)
|
pdir := filepath.Join(pm.config.Root, p.PluginObj.ID)
|
||||||
orig := filepath.Join(pdir, "rootfs")
|
orig := filepath.Join(pdir, "rootfs")
|
||||||
|
|
||||||
|
// Make sure nothing is mounted
|
||||||
|
// This could happen if the plugin was disabled with `-f` with active mounts.
|
||||||
|
// If there is anything in `orig` is still mounted, this should error out.
|
||||||
|
if err := recursiveUnmount(orig); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
backup := orig + "-old"
|
backup := orig + "-old"
|
||||||
if err := os.Rename(orig, backup); err != nil {
|
if err := os.Rename(orig, backup); err != nil {
|
||||||
return err
|
return errors.Wrap(err, "error backing up plugin data before upgrade")
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
|
|
Loading…
Reference in a new issue