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>
(cherry picked from commit 83f44d232d2c5d7ce7c5e10d2cd0f912d32c2ea5)
Signed-off-by: Brian Goff <cpuguy83@gmail.com>

Brian Goff authored on 2017/04/11 22:56:36
Showing 2 changed files
... ...
@@ -575,7 +575,7 @@ func (pm *Manager) Remove(name string, config *types.PluginRmConfig) error {
575 575
 func getMounts(root string) ([]string, error) {
576 576
 	infos, err := mount.GetMounts()
577 577
 	if err != nil {
578
-		return nil, errors.Wrap(err, "failed to read mount table while performing recursive unmount")
578
+		return nil, errors.Wrap(err, "failed to read mount table")
579 579
 	}
580 580
 
581 581
 	var mounts []string
... ...
@@ -171,9 +171,17 @@ func (pm *Manager) upgradePlugin(p *v2.Plugin, configDigest digest.Digest, blobs
171 171
 
172 172
 	pdir := filepath.Join(pm.config.Root, p.PluginObj.ID)
173 173
 	orig := filepath.Join(pdir, "rootfs")
174
+
175
+	// Make sure nothing is mounted
176
+	// This could happen if the plugin was disabled with `-f` with active mounts.
177
+	// If there is anything in `orig` is still mounted, this should error out.
178
+	if err := recursiveUnmount(orig); err != nil {
179
+		return err
180
+	}
181
+
174 182
 	backup := orig + "-old"
175 183
 	if err := os.Rename(orig, backup); err != nil {
176
-		return err
184
+		return errors.Wrap(err, "error backing up plugin data before upgrade")
177 185
 	}
178 186
 
179 187
 	defer func() {