瀏覽代碼

Merge pull request #32525 from cpuguy83/ensure_unmount_plugin

Make sure plugin rootfs is unmounted on upgrade
Vincent Demeester 8 年之前
父節點
當前提交
aa92df71b2
共有 2 個文件被更改,包括 10 次插入2 次删除
  1. 1 1
      plugin/backend_linux.go
  2. 9 1
      plugin/manager_linux.go

+ 1 - 1
plugin/backend_linux.go

@@ -648,7 +648,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

+ 9 - 1
plugin/manager_linux.go

@@ -199,9 +199,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() {