From ae477f15f0bee3019f815ea29492e6bf7e1be57d Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Wed, 23 Oct 2024 15:10:09 -0700 Subject: [PATCH] libct/configs: move cgroup stuff to libct/cgroups We have quite a few external users of libcontainer/cgroups packages, and they all have to depend on libcontainer/configs as well. Let's move cgroup-related configuration to libcontainer/croups. Signed-off-by: Kir Kolyshkin --- libcontainer/cgroups/cgroups.go | 14 +++++----- .../config_blkio_device.go} | 2 +- .../config_hugepages.go} | 2 +- .../config_ifprio_map.go} | 2 +- .../config_linux.go} | 2 +- .../rdma.go => cgroups/config_rdma.go} | 2 +- .../config_unsupported.go} | 2 +- libcontainer/configs/cgroup_deprecated.go | 26 +++++++++++++++++++ 8 files changed, 38 insertions(+), 14 deletions(-) rename libcontainer/{configs/blkio_device.go => cgroups/config_blkio_device.go} (99%) rename libcontainer/{configs/hugepage_limit.go => cgroups/config_hugepages.go} (91%) rename libcontainer/{configs/interface_priority_map.go => cgroups/config_ifprio_map.go} (93%) rename libcontainer/{configs/cgroup_linux.go => cgroups/config_linux.go} (99%) rename libcontainer/{configs/rdma.go => cgroups/config_rdma.go} (95%) rename libcontainer/{configs/cgroup_unsupported.go => cgroups/config_unsupported.go} (92%) create mode 100644 libcontainer/configs/cgroup_deprecated.go diff --git a/libcontainer/cgroups/cgroups.go b/libcontainer/cgroups/cgroups.go index 53e194c74..719489c02 100644 --- a/libcontainer/cgroups/cgroups.go +++ b/libcontainer/cgroups/cgroups.go @@ -2,8 +2,6 @@ package cgroups import ( "errors" - - "github.com/opencontainers/runc/libcontainer/configs" ) var ( @@ -21,8 +19,8 @@ var ( // [github.com/opencontainers/runc/libcontainer/cgroups/devices] // package is imported, it is set to nil, so cgroup managers can't // manage devices. - DevicesSetV1 func(path string, r *configs.Resources) error - DevicesSetV2 func(path string, r *configs.Resources) error + DevicesSetV1 func(path string, r *Resources) error + DevicesSetV2 func(path string, r *Resources) error ) type Manager interface { @@ -42,7 +40,7 @@ type Manager interface { GetStats() (*Stats, error) // Freeze sets the freezer cgroup to the specified state. - Freeze(state configs.FreezerState) error + Freeze(state FreezerState) error // Destroy removes cgroup. Destroy() error @@ -54,7 +52,7 @@ type Manager interface { // Set sets cgroup resources parameters/limits. If the argument is nil, // the resources specified during Manager creation (or the previous call // to Set) are used. - Set(r *configs.Resources) error + Set(r *Resources) error // GetPaths returns cgroup path(s) to save in a state file in order to // restore later. @@ -67,10 +65,10 @@ type Manager interface { GetPaths() map[string]string // GetCgroups returns the cgroup data as configured. - GetCgroups() (*configs.Cgroup, error) + GetCgroups() (*Cgroup, error) // GetFreezerState retrieves the current FreezerState of the cgroup. - GetFreezerState() (configs.FreezerState, error) + GetFreezerState() (FreezerState, error) // Exists returns whether the cgroup path exists or not. Exists() bool diff --git a/libcontainer/configs/blkio_device.go b/libcontainer/cgroups/config_blkio_device.go similarity index 99% rename from libcontainer/configs/blkio_device.go rename to libcontainer/cgroups/config_blkio_device.go index 865344f99..9dc2a034c 100644 --- a/libcontainer/configs/blkio_device.go +++ b/libcontainer/cgroups/config_blkio_device.go @@ -1,4 +1,4 @@ -package configs +package cgroups import "fmt" diff --git a/libcontainer/configs/hugepage_limit.go b/libcontainer/cgroups/config_hugepages.go similarity index 91% rename from libcontainer/configs/hugepage_limit.go rename to libcontainer/cgroups/config_hugepages.go index d30216380..5357dd090 100644 --- a/libcontainer/configs/hugepage_limit.go +++ b/libcontainer/cgroups/config_hugepages.go @@ -1,4 +1,4 @@ -package configs +package cgroups type HugepageLimit struct { // which type of hugepage to limit. diff --git a/libcontainer/configs/interface_priority_map.go b/libcontainer/cgroups/config_ifprio_map.go similarity index 93% rename from libcontainer/configs/interface_priority_map.go rename to libcontainer/cgroups/config_ifprio_map.go index 9a0395eaf..d771603a7 100644 --- a/libcontainer/configs/interface_priority_map.go +++ b/libcontainer/cgroups/config_ifprio_map.go @@ -1,4 +1,4 @@ -package configs +package cgroups import ( "fmt" diff --git a/libcontainer/configs/cgroup_linux.go b/libcontainer/cgroups/config_linux.go similarity index 99% rename from libcontainer/configs/cgroup_linux.go rename to libcontainer/cgroups/config_linux.go index 4a34cf76f..f1e8a1578 100644 --- a/libcontainer/configs/cgroup_linux.go +++ b/libcontainer/cgroups/config_linux.go @@ -1,4 +1,4 @@ -package configs +package cgroups import ( systemdDbus "github.com/coreos/go-systemd/v22/dbus" diff --git a/libcontainer/configs/rdma.go b/libcontainer/cgroups/config_rdma.go similarity index 95% rename from libcontainer/configs/rdma.go rename to libcontainer/cgroups/config_rdma.go index c69f2c802..a0bd54f04 100644 --- a/libcontainer/configs/rdma.go +++ b/libcontainer/cgroups/config_rdma.go @@ -1,4 +1,4 @@ -package configs +package cgroups // LinuxRdma for Linux cgroup 'rdma' resource management (Linux 4.11) type LinuxRdma struct { diff --git a/libcontainer/configs/cgroup_unsupported.go b/libcontainer/cgroups/config_unsupported.go similarity index 92% rename from libcontainer/configs/cgroup_unsupported.go rename to libcontainer/cgroups/config_unsupported.go index 53f5ec5a0..db32ec483 100644 --- a/libcontainer/configs/cgroup_unsupported.go +++ b/libcontainer/cgroups/config_unsupported.go @@ -1,6 +1,6 @@ //go:build !linux -package configs +package cgroups // Cgroup holds properties of a cgroup on Linux // TODO Windows: This can ultimately be entirely factored out on Windows as diff --git a/libcontainer/configs/cgroup_deprecated.go b/libcontainer/configs/cgroup_deprecated.go new file mode 100644 index 000000000..2277d326e --- /dev/null +++ b/libcontainer/configs/cgroup_deprecated.go @@ -0,0 +1,26 @@ +package configs // Deprecated: use [github.com/opencontainers/runc/libcontainer/cgroups]. + +import "github.com/opencontainers/runc/libcontainer/cgroups" + +type ( + Cgroup = cgroups.Cgroup + Resources = cgroups.Resources + FreezerState = cgroups.FreezerState + LinuxRdma = cgroups.LinuxRdma + BlockIODevice = cgroups.BlockIODevice + WeightDevice = cgroups.WeightDevice + ThrottleDevice = cgroups.ThrottleDevice + HugepageLimit = cgroups.HugepageLimit + IfPrioMap = cgroups.IfPrioMap +) + +const ( + Undefined = cgroups.Undefined + Frozen = cgroups.Frozen + Thawed = cgroups.Thawed +) + +var ( + NewWeightDevice = cgroups.NewWeightDevice + NewThrottleDevice = cgroups.NewThrottleDevice +)