From 3deac5dc85b6b0739c1d62716bb5edb13519d92e Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Thu, 8 Apr 2021 14:13:05 +0900 Subject: [PATCH] btrfs: annotate error with human-readable hint string Add hints for "Failed to destroy btrfs snapshot for : operation not permitted" on rootless Related to issue 41762 Signed-off-by: Akihiro Suda --- daemon/graphdriver/btrfs/btrfs.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/daemon/graphdriver/btrfs/btrfs.go b/daemon/graphdriver/btrfs/btrfs.go index 0720bb571f..87d26d4860 100644 --- a/daemon/graphdriver/btrfs/btrfs.go +++ b/daemon/graphdriver/btrfs/btrfs.go @@ -26,6 +26,7 @@ import ( "sync" "unsafe" + "github.com/containerd/containerd/pkg/userns" "github.com/docker/docker/daemon/graphdriver" "github.com/docker/docker/pkg/containerfs" "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 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 } // If quota is not enabled, fallback to rmdir syscall to delete subvolumes.