Skip to content

Commit

Permalink
Merge pull request #1720 from rhatdan/cgroups
Browse files Browse the repository at this point in the history
UserConnection is used by non linux platforms
  • Loading branch information
openshift-ci[bot] authored Oct 31, 2023
2 parents 40d88ea + 48734f2 commit 116177b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
13 changes: 3 additions & 10 deletions pkg/cgroups/cgroups_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ func getAvailableControllers(exclude map[string]controllerHandler, cgroup2 bool)
return controllers, nil
}

// GetAvailableControllers get string:bool map of all the available controllers
func GetAvailableControllers(exclude map[string]controllerHandler, cgroup2 bool) ([]string, error) {
// AvailableControllers get string:bool map of all the available controllers
func AvailableControllers(exclude map[string]controllerHandler, cgroup2 bool) ([]string, error) {
availableControllers, err := getAvailableControllers(exclude, cgroup2)
if err != nil {
return nil, err
Expand Down Expand Up @@ -392,20 +392,13 @@ func (c *CgroupControl) CreateSystemdUnit(path string) error {
return systemdCreate(c.config.Resources, path, conn)
}

// GetUserConnection returns an user connection to D-BUS
func GetUserConnection(uid int) (*systemdDbus.Conn, error) {
return systemdDbus.NewConnection(func() (*dbus.Conn, error) {
return dbusAuthConnection(uid, dbus.SessionBusPrivateNoAutoStartup)
})
}

// CreateSystemdUserUnit creates the systemd cgroup for the specified user
func (c *CgroupControl) CreateSystemdUserUnit(path string, uid int) error {
if !c.systemd {
return fmt.Errorf("the cgroup controller is not using systemd")
}

conn, err := GetUserConnection(uid)
conn, err := UserConnection(uid)
if err != nil {
return err
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/cgroups/cgroups_supported.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"syscall"
"time"

systemdDbus "github.com/coreos/go-systemd/v22/dbus"
"github.com/godbus/dbus/v5"
"golang.org/x/sys/unix"
)

Expand All @@ -37,6 +39,13 @@ func IsCgroup2UnifiedMode() (bool, error) {
return isUnified, isUnifiedErr
}

// UserConnection returns an user connection to D-BUS
func UserConnection(uid int) (*systemdDbus.Conn, error) {
return systemdDbus.NewConnection(func() (*dbus.Conn, error) {
return dbusAuthConnection(uid, dbus.SessionBusPrivateNoAutoStartup)
})
}

// UserOwnsCurrentSystemdCgroup checks whether the current EUID owns the
// current cgroup.
func UserOwnsCurrentSystemdCgroup() (bool, error) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/cgroups/utils_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ func ReadFile(dir, file string) (string, error) {
return buf.String(), err
}

// GetBlkioFiles gets the proper files for blkio weights
func GetBlkioFiles(cgroupPath string) (wtFile, wtDevFile string) {
// BlkioFiles gets the proper files for blkio weights
func BlkioFiles(cgroupPath string) (wtFile, wtDevFile string) {
var weightFile string
var weightDeviceFile string
// in this important since runc keeps these variables private, they won't be set
Expand Down

0 comments on commit 116177b

Please sign in to comment.