Merge pull request #23512 from rhatdan/mount

Remove another race condition when mounting containers or images
This commit is contained in:
openshift-merge-bot[bot]
2024-08-06 11:41:10 +00:00
committed by GitHub
2 changed files with 17 additions and 0 deletions

View File

@ -34,6 +34,7 @@ import (
"github.com/containers/podman/v5/pkg/specgenutil"
"github.com/containers/podman/v5/pkg/util"
"github.com/containers/storage"
"github.com/containers/storage/types"
"github.com/sirupsen/logrus"
)
@ -1367,6 +1368,11 @@ func (ic *ContainerEngine) ContainerMount(ctx context.Context, nameOrIDs []strin
for _, ctr := range containers {
report := entities.ContainerMountReport{Id: ctr.ID()}
report.Path, report.Err = ctr.Mount()
if options.All &&
(errors.Is(report.Err, define.ErrNoSuchCtr) ||
errors.Is(report.Err, define.ErrCtrRemoved)) {
continue
}
reports = append(reports, &report)
}
if len(reports) > 0 {
@ -1381,6 +1387,9 @@ func (ic *ContainerEngine) ContainerMount(ctx context.Context, nameOrIDs []strin
for _, sctr := range storageCtrs {
mounted, path, err := ic.Libpod.IsStorageContainerMounted(sctr.ID)
if err != nil {
if errors.Is(err, types.ErrContainerUnknown) {
continue
}
return nil, err
}
@ -1405,6 +1414,10 @@ func (ic *ContainerEngine) ContainerMount(ctx context.Context, nameOrIDs []strin
for _, ctr := range containers {
mounted, path, err := ctr.Mounted()
if err != nil {
if errors.Is(err, define.ErrNoSuchCtr) ||
errors.Is(err, define.ErrCtrRemoved) {
continue
}
return nil, err
}

View File

@ -35,6 +35,7 @@ import (
"github.com/containers/podman/v5/pkg/errorhandling"
"github.com/containers/podman/v5/pkg/rootless"
"github.com/containers/storage"
"github.com/containers/storage/types"
"github.com/opencontainers/go-digest"
imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/sirupsen/logrus"
@ -181,6 +182,9 @@ func (ir *ImageEngine) Mount(ctx context.Context, nameOrIDs []string, opts entit
// We're only looking for mounted images.
mountPoint, err = i.Mountpoint()
if err != nil {
if errors.Is(err, types.ErrImageUnknown) {
continue
}
return nil, err
}
// Not mounted, so skip.