feat(region,host): sriov nic support (#15342)

Support sriov nic passthrough to kvm guest.

Signed-off-by: wanyaoqi <d3lx.yq@gmail.com>

Signed-off-by: wanyaoqi <d3lx.yq@gmail.com>
This commit is contained in:
wanyaoqi
2022-11-13 18:17:30 +08:00
committed by GitHub
parent beb2951523
commit 70755a9a1b
29 changed files with 814 additions and 157 deletions
@@ -18,6 +18,7 @@ import (
"context"
"fmt"
"yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/scheduler/core"
)
@@ -46,6 +47,15 @@ func (f *IsolatedDevicePredicate) PreExecute(ctx context.Context, u *core.Unit,
func (f *IsolatedDevicePredicate) Execute(ctx context.Context, u *core.Unit, c core.Candidater) (bool, []core.PredicateFailureReason, error) {
h := NewPredicateHelper(f, u, c)
reqIsoDevs := u.SchedData().IsolatedDevices
if reqIsoDevs == nil {
reqIsoDevs = []*compute.IsolatedDeviceConfig{}
}
networks := u.SchedData().Networks
for i := 0; i < len(networks); i++ {
if networks[i].SriovDevice != nil {
reqIsoDevs = append(reqIsoDevs, networks[i].SriovDevice)
}
}
getter := c.Getter()
minCapacity := int64(0xFFFFFFFF)
@@ -151,6 +151,24 @@ func IsNetworksAvailable(ctx context.Context, c core.Candidater, data *api.Sched
return freeCnt, nil
}
func checkSriovNic(
c core.Candidater, netWireId string, dev *computeapi.IsolatedDeviceConfig,
) error {
if dev.WireId != "" {
if dev.WireId != netWireId {
return fmt.Errorf("Network wire not matched sriov nic wire %s != %s", netWireId, dev.WireId)
} else {
return nil
}
}
getter := c.Getter()
devs := getter.UnusedIsolatedDevicesByModelAndWire(dev.Model, netWireId)
if len(devs) == 0 {
return fmt.Errorf("Network wire no sriov nic available")
}
return nil
}
func IsNetworkAvailable(
ctx context.Context,
c core.Candidater, data *api.SchedInfo,
@@ -197,6 +215,16 @@ func IsNetworkAvailable(
}
}
if req.SriovDevice != nil {
err := checkSriovNic(c, n.WireId, req.SriovDevice)
if err != nil {
return FailReason{
Reason: err.Error(),
Type: NetworkWire,
}
}
}
if n.IsPublic && n.PublicScope == string(rbacutils.ScopeSystem) {
// system-wide share
} else if n.IsPublic && n.PublicScope == string(rbacutils.ScopeDomain) && (n.DomainId == data.Domain || utils.IsInStringArray(data.Domain, n.GetSharedDomains())) {