From 82c069c857236edda446a901484b215fd82f2337 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 25 Jul 2025 20:30:31 +0200 Subject: [PATCH] api/types/system: move DiskUsage, DiskUsageOptions to api/types/backend These types were introduced in f07242f6d7091fe9000aa0bea0cc27b85baa945a, but while their description mentions it's the type used for the response, it actually isn't, and it's used by the backend, but ultimately marshaled to the "types.DiskUsage" struct; https://github.com/moby/moby/blob/7dc46c6e0c727a746ecfb8427c0c3cbd998059bc/daemon/server/router/system/system_routes.go#L254-L270 Signed-off-by: Sebastiaan van Stijn --- api/types/backend/disk_usage.go | 29 +++++++++++++++++++ api/types/system/disk_usage.go | 17 ----------- daemon/disk_usage.go | 7 ++--- daemon/server/router/system/backend.go | 15 ++-------- daemon/server/router/system/system_routes.go | 7 +++-- .../moby/moby/api/types/backend/disk_usage.go | 29 +++++++++++++++++++ .../moby/moby/api/types/system/disk_usage.go | 17 ----------- 7 files changed, 67 insertions(+), 54 deletions(-) create mode 100644 api/types/backend/disk_usage.go delete mode 100644 api/types/system/disk_usage.go create mode 100644 vendor/github.com/moby/moby/api/types/backend/disk_usage.go delete mode 100644 vendor/github.com/moby/moby/api/types/system/disk_usage.go diff --git a/api/types/backend/disk_usage.go b/api/types/backend/disk_usage.go new file mode 100644 index 0000000000..9e0c070035 --- /dev/null +++ b/api/types/backend/disk_usage.go @@ -0,0 +1,29 @@ +package backend + +import ( + "github.com/moby/moby/api/types/build" + "github.com/moby/moby/api/types/container" + "github.com/moby/moby/api/types/image" + "github.com/moby/moby/api/types/volume" +) + +// DiskUsageOptions holds parameters for system disk usage query. +type DiskUsageOptions struct { + // Containers controls whether container disk usage should be computed. + Containers bool + + // Images controls whether image disk usage should be computed. + Images bool + + // Volumes controls whether volume disk usage should be computed. + Volumes bool +} + +// DiskUsage contains the information returned by the backend for the +// GET "/system/df" endpoint. +type DiskUsage struct { + Images *image.DiskUsage + Containers *container.DiskUsage + Volumes *volume.DiskUsage + BuildCache *build.CacheDiskUsage +} diff --git a/api/types/system/disk_usage.go b/api/types/system/disk_usage.go deleted file mode 100644 index 333a7c7fc4..0000000000 --- a/api/types/system/disk_usage.go +++ /dev/null @@ -1,17 +0,0 @@ -package system - -import ( - "github.com/moby/moby/api/types/build" - "github.com/moby/moby/api/types/container" - "github.com/moby/moby/api/types/image" - "github.com/moby/moby/api/types/volume" -) - -// DiskUsage contains response of Engine API for API 1.49 and greater: -// GET "/system/df" -type DiskUsage struct { - Images *image.DiskUsage - Containers *container.DiskUsage - Volumes *volume.DiskUsage - BuildCache *build.CacheDiskUsage -} diff --git a/daemon/disk_usage.go b/daemon/disk_usage.go index b6e4a0daa3..b6ee2a9ba9 100644 --- a/daemon/disk_usage.go +++ b/daemon/disk_usage.go @@ -4,11 +4,10 @@ import ( "context" "fmt" - "github.com/docker/docker/daemon/server/router/system" + "github.com/moby/moby/api/types/backend" "github.com/moby/moby/api/types/container" "github.com/moby/moby/api/types/filters" "github.com/moby/moby/api/types/image" - systemtypes "github.com/moby/moby/api/types/system" "github.com/moby/moby/api/types/volume" "github.com/pkg/errors" "golang.org/x/sync/errgroup" @@ -103,10 +102,10 @@ func (daemon *Daemon) layerDiskUsage(ctx context.Context) (int64, error) { // SystemDiskUsage returns information about the daemon data disk usage. // Callers must not mutate contents of the returned fields. -func (daemon *Daemon) SystemDiskUsage(ctx context.Context, opts system.DiskUsageOptions) (*systemtypes.DiskUsage, error) { +func (daemon *Daemon) SystemDiskUsage(ctx context.Context, opts backend.DiskUsageOptions) (*backend.DiskUsage, error) { eg, ctx := errgroup.WithContext(ctx) - du := &systemtypes.DiskUsage{} + du := &backend.DiskUsage{} if opts.Containers { eg.Go(func() (err error) { du.Containers, err = daemon.containerDiskUsage(ctx) diff --git a/daemon/server/router/system/backend.go b/daemon/server/router/system/backend.go index 6da7825b54..84d8e28497 100644 --- a/daemon/server/router/system/backend.go +++ b/daemon/server/router/system/backend.go @@ -5,6 +5,7 @@ import ( "time" "github.com/moby/moby/api/types" + "github.com/moby/moby/api/types/backend" "github.com/moby/moby/api/types/build" "github.com/moby/moby/api/types/events" "github.com/moby/moby/api/types/filters" @@ -13,24 +14,12 @@ import ( "github.com/moby/moby/api/types/system" ) -// DiskUsageOptions holds parameters for system disk usage query. -type DiskUsageOptions struct { - // Containers controls whether container disk usage should be computed. - Containers bool - - // Images controls whether image disk usage should be computed. - Images bool - - // Volumes controls whether volume disk usage should be computed. - Volumes bool -} - // Backend is the methods that need to be implemented to provide // system specific functionality. type Backend interface { SystemInfo(context.Context) (*system.Info, error) SystemVersion(context.Context) (types.Version, error) - SystemDiskUsage(ctx context.Context, opts DiskUsageOptions) (*system.DiskUsage, error) + SystemDiskUsage(ctx context.Context, opts backend.DiskUsageOptions) (*backend.DiskUsage, error) SubscribeToEvents(since, until time.Time, ef filters.Args) ([]events.Message, chan interface{}) UnsubscribeFromEvents(chan interface{}) AuthenticateToRegistry(ctx context.Context, authConfig *registry.AuthConfig) (string, error) diff --git a/daemon/server/router/system/system_routes.go b/daemon/server/router/system/system_routes.go index afb1bbbdc8..ec5f817c6a 100644 --- a/daemon/server/router/system/system_routes.go +++ b/daemon/server/router/system/system_routes.go @@ -15,6 +15,7 @@ import ( "github.com/docker/docker/daemon/server/router/build" "github.com/docker/docker/pkg/ioutils" "github.com/moby/moby/api/types" + "github.com/moby/moby/api/types/backend" buildtypes "github.com/moby/moby/api/types/build" "github.com/moby/moby/api/types/events" "github.com/moby/moby/api/types/filters" @@ -183,11 +184,11 @@ func (s *systemRouter) getDiskUsage(ctx context.Context, w http.ResponseWriter, eg, ctx := errgroup.WithContext(ctx) - var systemDiskUsage *system.DiskUsage + var systemDiskUsage *backend.DiskUsage if getContainers || getImages || getVolumes { eg.Go(func() error { var err error - systemDiskUsage, err = s.backend.SystemDiskUsage(ctx, DiskUsageOptions{ + systemDiskUsage, err = s.backend.SystemDiskUsage(ctx, backend.DiskUsageOptions{ Containers: getContainers, Images: getImages, Volumes: getVolumes, @@ -238,7 +239,7 @@ func (s *systemRouter) getDiskUsage(ctx context.Context, w http.ResponseWriter, } } - du := system.DiskUsage{} + du := backend.DiskUsage{} if getBuildCache { du.BuildCache = &buildtypes.CacheDiskUsage{ TotalSize: builderSize, diff --git a/vendor/github.com/moby/moby/api/types/backend/disk_usage.go b/vendor/github.com/moby/moby/api/types/backend/disk_usage.go new file mode 100644 index 0000000000..9e0c070035 --- /dev/null +++ b/vendor/github.com/moby/moby/api/types/backend/disk_usage.go @@ -0,0 +1,29 @@ +package backend + +import ( + "github.com/moby/moby/api/types/build" + "github.com/moby/moby/api/types/container" + "github.com/moby/moby/api/types/image" + "github.com/moby/moby/api/types/volume" +) + +// DiskUsageOptions holds parameters for system disk usage query. +type DiskUsageOptions struct { + // Containers controls whether container disk usage should be computed. + Containers bool + + // Images controls whether image disk usage should be computed. + Images bool + + // Volumes controls whether volume disk usage should be computed. + Volumes bool +} + +// DiskUsage contains the information returned by the backend for the +// GET "/system/df" endpoint. +type DiskUsage struct { + Images *image.DiskUsage + Containers *container.DiskUsage + Volumes *volume.DiskUsage + BuildCache *build.CacheDiskUsage +} diff --git a/vendor/github.com/moby/moby/api/types/system/disk_usage.go b/vendor/github.com/moby/moby/api/types/system/disk_usage.go deleted file mode 100644 index 333a7c7fc4..0000000000 --- a/vendor/github.com/moby/moby/api/types/system/disk_usage.go +++ /dev/null @@ -1,17 +0,0 @@ -package system - -import ( - "github.com/moby/moby/api/types/build" - "github.com/moby/moby/api/types/container" - "github.com/moby/moby/api/types/image" - "github.com/moby/moby/api/types/volume" -) - -// DiskUsage contains response of Engine API for API 1.49 and greater: -// GET "/system/df" -type DiskUsage struct { - Images *image.DiskUsage - Containers *container.DiskUsage - Volumes *volume.DiskUsage - BuildCache *build.CacheDiskUsage -}