Sfoglia il codice sorgente

btrfs: annotate error with human-readable hint string

Add hints for "Failed to destroy btrfs snapshot <DIR> for <ID>: operation not permitted" on rootless

Related to issue 41762

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
Akihiro Suda 4 anni fa
parent
commit
3deac5dc85
1 ha cambiato i file con 5 aggiunte e 0 eliminazioni
  1. 5 0
      daemon/graphdriver/btrfs/btrfs.go

+ 5 - 0
daemon/graphdriver/btrfs/btrfs.go

@@ -26,6 +26,7 @@ import (
 	"sync"
 	"sync"
 	"unsafe"
 	"unsafe"
 
 
+	"github.com/containerd/containerd/pkg/userns"
 	"github.com/docker/docker/daemon/graphdriver"
 	"github.com/docker/docker/daemon/graphdriver"
 	"github.com/docker/docker/pkg/containerfs"
 	"github.com/docker/docker/pkg/containerfs"
 	"github.com/docker/docker/pkg/idtools"
 	"github.com/docker/docker/pkg/idtools"
@@ -600,6 +601,10 @@ func (d *Driver) Remove(id string) error {
 
 
 	if err := subvolDelete(d.subvolumesDir(), id, d.quotaEnabled); err != nil {
 	if err := subvolDelete(d.subvolumesDir(), id, d.quotaEnabled); err != nil {
 		if d.quotaEnabled {
 		if d.quotaEnabled {
+			// use strings.Contains() rather than errors.Is(), because subvolDelete() does not use %w yet
+			if userns.RunningInUserNS() && strings.Contains(err.Error(), "operation not permitted") {
+				err = errors.Wrap(err, `failed to delete subvolume without root (hint: remount btrfs on "user_subvol_rm_allowed" option, or update the kernel to >= 4.18, or change the storage driver to "fuse-overlayfs")`)
+			}
 			return err
 			return err
 		}
 		}
 		// If quota is not enabled, fallback to rmdir syscall to delete subvolumes.
 		// If quota is not enabled, fallback to rmdir syscall to delete subvolumes.