Skip to content

Commit

Permalink
koordlet: fix GeviceNumbers compatibility in mac (#2295)
Browse files Browse the repository at this point in the history
Signed-off-by: wangjianyu.wjy <[email protected]>
Co-authored-by: wangjianyu.wjy <[email protected]>
  • Loading branch information
ZiMengSheng and wangjianyu.wjy authored Dec 12, 2024
1 parent 1ffae87 commit 44b57d8
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 23 deletions.
27 changes: 4 additions & 23 deletions pkg/koordlet/runtimehooks/hooks/rdma/rdma.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import (
"fmt"
"os"
"path/filepath"
"syscall"

"k8s.io/klog/v2"

ext "github.com/koordinator-sh/koordinator/apis/extension"
schedulingv1alpha1 "github.com/koordinator-sh/koordinator/apis/scheduling/v1alpha1"
"github.com/koordinator-sh/koordinator/pkg/koordlet/runtimehooks/hooks"
"github.com/koordinator-sh/koordinator/pkg/koordlet/runtimehooks/protocol"
"github.com/koordinator-sh/koordinator/pkg/koordlet/util/system"
rmconfig "github.com/koordinator-sh/koordinator/pkg/runtimeproxy/config"
)

Expand Down Expand Up @@ -70,7 +70,7 @@ func (p *rdmaPlugin) InjectDevice(proto protocol.HooksProtocol) error {
return nil
}

deviceInfoCM, err := getDeviceNumbers(RdmaCmDir)
deviceInfoCM, err := system.GetDeviceNumbers(RdmaCmDir)
if err != nil {
klog.Errorf("InjectDevice: GetDeviceNumbers deviceinfoCM from %s error:%v", RdmaCmDir, err)
return err
Expand All @@ -96,7 +96,7 @@ func (p *rdmaPlugin) InjectDevice(proto protocol.HooksProtocol) error {
return err
}

deviceInfoVf, err := getDeviceNumbers(uverbsOfVF)
deviceInfoVf, err := system.GetDeviceNumbers(uverbsOfVF)
if err != nil {
klog.Errorf("InjectDevice: GetDeviceNumbers deviceinfoVf from %s error:%v", uverbsOfVF, err)
return err
Expand All @@ -118,7 +118,7 @@ func (p *rdmaPlugin) InjectDevice(proto protocol.HooksProtocol) error {
klog.Errorf("InjectDevice: getUVerbsViaPciAdd error:%v", err)
return err
}
deviceInfoPf, err := getDeviceNumbers(uverbs)
deviceInfoPf, err := system.GetDeviceNumbers(uverbs)
if err != nil {
klog.Errorf("InjectDevice: GetDeviceNumbers deviceinfoPf from %s error:%v", uverbs, err)
return err
Expand All @@ -144,22 +144,3 @@ func getUVerbsViaPciAdd(pciAddress string) (string, error) {
}
return filepath.Join(IBDevDir, files[0].Name()), nil
}

func major(dev uint64) int64 {
return int64((dev>>8)&0xff) | int64((dev>>12)&0xfff00)
}

func minor(dev uint64) int64 {
return int64(dev&0xff) | int64((dev>>12)&0xffffff00)
}

func getDeviceNumbers(devicePath string) ([]int64, error) {
fileInfo, err := os.Stat(devicePath)
if err != nil {
return nil, fmt.Errorf("failed to stat device file: %v", err)
}
deviceNumber := fileInfo.Sys().(*syscall.Stat_t).Rdev
major := major(deviceNumber)
minor := minor(deviceNumber)
return []int64{major, minor}, nil
}
42 changes: 42 additions & 0 deletions pkg/koordlet/util/system/device_numbers_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Copyright 2022 The Koordinator Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package system

import (
"fmt"
"os"
"syscall"
)

func major(dev uint64) int64 {
return int64((dev>>8)&0xff) | int64((dev>>12)&0xfff00)
}

func minor(dev uint64) int64 {
return int64(dev&0xff) | int64((dev>>12)&0xffffff00)
}

func GetDeviceNumbers(devicePath string) ([]int64, error) {
fileInfo, err := os.Stat(devicePath)
if err != nil {
return nil, fmt.Errorf("failed to stat device file: %v", err)
}
deviceNumber := fileInfo.Sys().(*syscall.Stat_t).Rdev
major := major(deviceNumber)
minor := minor(deviceNumber)
return []int64{major, minor}, nil
}
25 changes: 25 additions & 0 deletions pkg/koordlet/util/system/device_numbers_unsupported.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//go:build !linux
// +build !linux

/*
Copyright 2022 The Koordinator Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package system

func GetDeviceNumbers(devicePath string) ([]int64, error) {
// TODO implement it
return []int64{0, 0}, nil
}

0 comments on commit 44b57d8

Please sign in to comment.