Browse code

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>

Brian Goff authored on 2017/04/11 22:56:36
Showing 2 changed files
... ...
@@ -648,7 +648,7 @@ func (pm *Manager) Remove(name string, config *types.PluginRmConfig) error {
648 648
 func getMounts(root string) ([]string, error) {
649 649
 	infos, err := mount.GetMounts()
650 650
 	if err != nil {
651
-		return nil, errors.Wrap(err, "failed to read mount table while performing recursive unmount")
651
+		return nil, errors.Wrap(err, "failed to read mount table")
652 652
 	}
653 653
 
654 654
 	var mounts []string
... ...
@@ -199,9 +199,17 @@ func (pm *Manager) upgradePlugin(p *v2.Plugin, configDigest digest.Digest, blobs
199 199
 
200 200
 	pdir := filepath.Join(pm.config.Root, p.PluginObj.ID)
201 201
 	orig := filepath.Join(pdir, "rootfs")
202
+
203
+	// Make sure nothing is mounted
204
+	// This could happen if the plugin was disabled with `-f` with active mounts.
205
+	// If there is anything in `orig` is still mounted, this should error out.
206
+	if err := recursiveUnmount(orig); err != nil {
207
+		return err
208
+	}
209
+
202 210
 	backup := orig + "-old"
203 211
 	if err := os.Rename(orig, backup); err != nil {
204
-		return err
212
+		return errors.Wrap(err, "error backing up plugin data before upgrade")
205 213
 	}
206 214
 
207 215
 	defer func() {