Skip to content

Commit 7fef0b6

Browse files
committed
daemon/volume: don't print warnings for non-volume directories
When restoring volumes at startup, the local volume driver's constructor ([daemon/volume/local.New]) iterates over all directories found inside the volume storage path (`/var/lib/docker/volumes`). It does not (currently) check for presence of other indicators that the directory is an actual volume, such as the `_data` directory being present, or a `opts.json`. In situations where `/var/lib/docker/volumes` contains directories that were not created by docker, this can result in errors when calculating the size of volumes (`docker system df`); Before (re)starting the daemon, create some directories; mkdir /var/lib/docker/volumes/notavolume echo "some file" > /var/lib/docker/volumes/notavolume/some-file mkdir /var/lib/docker/volumes/notavolume2 Then, start the daemon, and run `docker system df`. The daemon logs will now contain warnings about the path not being found: WARN[2026-02-09T11:27:31.940713593Z] Failed to determine size of volume error="lstat /var/lib/docker/volumes/notavolume/_data: no such file or directory" volume=notavolume WARN[2026-02-09T11:27:31.940765468Z] Failed to determine size of volume error="lstat /var/lib/docker/volumes/notavolume2/_data: no such file or directory" volume=notavolume2 The [calcSize] function used to calculate the size of a volume already ignores files _within_ the volume's storage that are not / no longer found, but does not ignore errors if the base directory (`_data`) itself doesn't exist. This patch: - makes the logs ignore "not found" errors - adds a TODO to look into ignoring these directories during daemon startup (when instantiating the driver and restoring volumes). [daemon/volume/local.New]: https://github.com/moby/moby/blob/6c5233e1098dc689b2e665087780695ac8864e95/daemon/volume/local/local.go#L51-L85 [calcSize]: https://github.com/moby/moby/blob/daeaac0d3cf147cc7450a3ab9a869327c71bad45/daemon/internal/directory/directory_unix.go#L13-L24 Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent d94c62f commit 7fef0b6

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

daemon/volume/local/local.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ func New(scope string, rootIdentity idtools.Identity) (*Root, error) {
7373
}
7474

7575
for _, d := range dirs {
76+
// TODO(thaJeztah): this should probably skip non-volume directories (directories without a "_data" directory and no "opts.json" file).
7677
if !d.IsDir() {
7778
continue
7879
}

daemon/volume/service/convert.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package service
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
7+
"os"
68
"strconv"
79
"time"
810

@@ -69,7 +71,12 @@ func (s *VolumesService) volumesToAPI(ctx context.Context, volumes []volume.Volu
6971
}
7072
sz, err := directory.Size(ctx, p)
7173
if err != nil {
72-
log.G(ctx).WithError(err).WithField("volume", v.Name()).Warnf("Failed to determine size of volume")
74+
if !errors.Is(err, os.ErrNotExist) {
75+
log.G(ctx).WithFields(log.Fields{
76+
"error": err,
77+
"volume": v.Name(),
78+
}).Warn("Failed to determine size of volume")
79+
}
7380
sz = -1
7481
}
7582
apiV.UsageData = &volumetypes.UsageData{Size: sz, RefCount: int64(s.vs.CountReferences(v))}

0 commit comments

Comments
 (0)