From 5c3019e0288830e77ac19ad330ab77a2277be4ae Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Fri, 27 Sep 2024 14:46:59 +0200 Subject: [PATCH 1/2] podman mount: ignore ErrLayerUnknown When we check for a storage container mount we normally expect a ErrContainerUnknown when it does not exists. However during we check if it is actually mounted we also can get ErrLayerUnknown when the contianer was removed between the Container and Mount checks as they do not happen under the same lock. Fixes #23671 Signed-off-by: Paul Holzinger --- pkg/domain/infra/abi/containers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/domain/infra/abi/containers.go b/pkg/domain/infra/abi/containers.go index 6c9a820996..d2f99a26f7 100644 --- a/pkg/domain/infra/abi/containers.go +++ b/pkg/domain/infra/abi/containers.go @@ -1418,7 +1418,7 @@ func (ic *ContainerEngine) ContainerMount(ctx context.Context, nameOrIDs []strin // This can only happen in a narrow race because we first create the storage // container and then the libpod container so the StorageContainers() call // above would need to happen in that interval. - if errors.Is(err, types.ErrContainerUnknown) || errors.Is(err, define.ErrCtrExists) { + if errors.Is(err, types.ErrContainerUnknown) || errors.Is(err, types.ErrLayerUnknown) || errors.Is(err, define.ErrCtrExists) { continue } return nil, err From 1950555b2646fc5a49d5ce66b4b375b386ec063b Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Fri, 27 Sep 2024 14:55:15 +0200 Subject: [PATCH 2/2] podman mount: some better error wrapping As shown in #23671 these functions can return the raw error without any useful context to the user which makes it hard to understand where things went wrong. Simply add some context to some error paths here. Signed-off-by: Paul Holzinger --- libpod/runtime_ctr.go | 4 ++-- pkg/domain/infra/abi/containers.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go index 3551613a1f..87d8484783 100644 --- a/libpod/runtime_ctr.go +++ b/libpod/runtime_ctr.go @@ -1412,13 +1412,13 @@ func (r *Runtime) IsStorageContainerMounted(id string) (bool, string, error) { mountCnt, err := r.storageService.MountedContainerImage(id) if err != nil { - return false, "", err + return false, "", fmt.Errorf("get mount count of container: %w", err) } mounted := mountCnt > 0 if mounted { path, err = r.storageService.GetMountpoint(id) if err != nil { - return false, "", err + return false, "", fmt.Errorf("get container mount point: %w", err) } } return mounted, path, nil diff --git a/pkg/domain/infra/abi/containers.go b/pkg/domain/infra/abi/containers.go index d2f99a26f7..b6a7baa04d 100644 --- a/pkg/domain/infra/abi/containers.go +++ b/pkg/domain/infra/abi/containers.go @@ -1421,7 +1421,7 @@ func (ic *ContainerEngine) ContainerMount(ctx context.Context, nameOrIDs []strin if errors.Is(err, types.ErrContainerUnknown) || errors.Is(err, types.ErrLayerUnknown) || errors.Is(err, define.ErrCtrExists) { continue } - return nil, err + return nil, fmt.Errorf("check if storage container is mounted: %w", err) } var name string @@ -1449,7 +1449,7 @@ func (ic *ContainerEngine) ContainerMount(ctx context.Context, nameOrIDs []strin errors.Is(err, define.ErrCtrRemoved) { continue } - return nil, err + return nil, fmt.Errorf("check if container is mounted: %w", err) } if mounted {