From a970249cc104f3a2f190ab5b7d94c0af7bd92c07 Mon Sep 17 00:00:00 2001 From: Qiu Jian Date: Sat, 30 Oct 2021 11:46:16 +0800 Subject: [PATCH] fix: delayed probing GPU on host init and add disable_gpu option --- pkg/hostman/hostinfo/hostinfo.go | 16 ++++++++++------ pkg/hostman/isolated_device/isolated_device.go | 13 +++++++++---- pkg/hostman/options/options.go | 4 +++- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/pkg/hostman/hostinfo/hostinfo.go b/pkg/hostman/hostinfo/hostinfo.go index 4253132bb0..acfd29f4ed 100644 --- a/pkg/hostman/hostinfo/hostinfo.go +++ b/pkg/hostman/hostinfo/hostinfo.go @@ -311,11 +311,7 @@ func (h *SHostInfo) parseConfig() error { h.MasterNic = nil } - if man, err := isolated_device.NewManager(h); err != nil { - return fmt.Errorf("NewIsolatedManager: %v", err) - } else { - h.IsolatedDeviceMan = man - } + h.IsolatedDeviceMan = isolated_device.NewManager(h) return nil } @@ -1473,7 +1469,15 @@ func (h *SHostInfo) uploadStorageInfo() { go storageman.StartSyncStorageSizeTask( time.Duration(options.HostOptions.SyncStorageInfoDurationSecond) * time.Second, ) - h.getIsolatedDevices() + var err error + if !options.HostOptions.DisableGPU { + err = h.IsolatedDeviceMan.ProbePCIDevices() + } + if err != nil { + h.onFail(errors.Wrap(err, "Probe PCI device failed")) + } else { + h.getIsolatedDevices() + } } func (h *SHostInfo) onSyncStorageInfoSucc(storage storageman.IStorage, storageInfo jsonutils.JSONObject) { diff --git a/pkg/hostman/isolated_device/isolated_device.go b/pkg/hostman/isolated_device/isolated_device.go index e912a496bb..270094fd31 100644 --- a/pkg/hostman/isolated_device/isolated_device.go +++ b/pkg/hostman/isolated_device/isolated_device.go @@ -96,17 +96,22 @@ type IsolatedDeviceManager struct { DetachedDevices []*CloudDeviceInfo } -func NewManager(host IHost) (*IsolatedDeviceManager, error) { +func NewManager(host IHost) *IsolatedDeviceManager { man := &IsolatedDeviceManager{ host: host, Devices: make([]IDevice, 0), DetachedDevices: make([]*CloudDeviceInfo, 0), } - err := man.fillPCIDevices() - return man, err + // Do probe laster - Qiu Jian + // err := man.fillPCIDevices() + return man } -func (man *IsolatedDeviceManager) fillPCIDevices() error { +func (man *IsolatedDeviceManager) ProbePCIDevices() error { + if len(man.Devices) > 0 { + // already probed, skip + return nil + } // only support gpu by now gpus, err := getPassthroughGPUS() if err != nil { diff --git a/pkg/hostman/options/options.go b/pkg/hostman/options/options.go index 5a870b4ee6..af4a892b06 100644 --- a/pkg/hostman/options/options.go +++ b/pkg/hostman/options/options.go @@ -143,7 +143,9 @@ type SHostOptions struct { DisableProbeKubelet bool `help:"Disable probe kubelet config" default:"false"` KubeletRunDirectory string `help:"Kubelet config file path" default:"/var/lib/kubelet"` - DisableKVM bool `help:"force disable KVM" default:"false"` + DisableKVM bool `help:"force disable KVM" default:"false" json:"disable_kvm"` + + DisableGPU bool `help:"force disable GPU" default:"false" json:"disable_gpu"` } var (