Skip to content

Commit

Permalink
volume ls: fix race that caused it to fail
Browse files Browse the repository at this point in the history
If volume ls was called while another volume was removed at the right
time it could have failed with "no such volume" as we did not ignore
such error during listing. As we list things and this no longer exists
the correct thing is to ignore the error and continue like we do with
containers, pods, etc...

I have a slight feeling that this might solve containers#23913 but I am not to
sure there so I am not adding a Fixes here.

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Luap99 committed Nov 6, 2024
1 parent c0e24c6 commit b1a49be
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 23 deletions.
3 changes: 3 additions & 0 deletions pkg/api/handlers/compat/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ func ListVolumes(w http.ResponseWriter, r *http.Request) {
for _, v := range vols {
mp, err := v.MountPoint()
if err != nil {
if errors.Is(err, define.ErrNoSuchVolume) {
continue
}
utils.InternalServerError(w, err)
return
}
Expand Down
26 changes: 3 additions & 23 deletions pkg/api/handlers/libpod/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,33 +121,13 @@ func ListVolumes(w http.ResponseWriter, r *http.Request) {
return
}

volumeFilters := []libpod.VolumeFilter{}
for filter, filterValues := range *filterMap {
filterFunc, err := filters.GenerateVolumeFilters(filter, filterValues, runtime)
if err != nil {
utils.InternalServerError(w, err)
return
}
volumeFilters = append(volumeFilters, filterFunc)
}

vols, err := runtime.Volumes(volumeFilters...)
ic := abi.ContainerEngine{Libpod: runtime}
volumeConfigs, err := ic.VolumeList(r.Context(), entities.VolumeListOptions{Filter: *filterMap})
if err != nil {
utils.InternalServerError(w, err)
return
}
volumeConfigs := make([]*entities.VolumeListReport, 0, len(vols))
for _, v := range vols {
inspectOut, err := v.Inspect()
if err != nil {
utils.InternalServerError(w, err)
return
}
config := entities.VolumeConfigResponse{
InspectVolumeData: *inspectOut,
}
volumeConfigs = append(volumeConfigs, &entities.VolumeListReport{VolumeConfigResponse: config})
}

utils.WriteResponse(w, http.StatusOK, volumeConfigs)
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/domain/infra/abi/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ func (ic *ContainerEngine) VolumeList(ctx context.Context, opts entities.VolumeL
for _, v := range vols {
inspectOut, err := v.Inspect()
if err != nil {
if errors.Is(err, define.ErrNoSuchVolume) {
continue
}
return nil, err
}
config := entities.VolumeConfigResponse{
Expand Down

0 comments on commit b1a49be

Please sign in to comment.