mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #18641 from wanyaoqi/automated-cherry-pick-of-#18639-upstream-master
Automated cherry pick of #18639: fix(region,host): sriov nic hotplug and metrics fix
This commit is contained in:
@@ -141,4 +141,6 @@ type GuestnetworkJsonDesc struct {
|
||||
type SNicTrafficRecord struct {
|
||||
RxTraffic int64
|
||||
TxTraffic int64
|
||||
|
||||
HasBeenSetDown bool
|
||||
}
|
||||
|
||||
@@ -2571,14 +2571,11 @@ func (self *SGuest) PerformAttachnetwork(ctx context.Context, userCred mcclient.
|
||||
quotas.CancelPendingUsage(ctx, userCred, pendingUsage, pendingUsage, false)
|
||||
return nil, httperrors.NewBadRequestError("%v", err)
|
||||
}
|
||||
net := gns[0].GetNetwork()
|
||||
if input.Nets[i].SriovDevice != nil {
|
||||
input.Nets[i].SriovDevice.NetworkIndex = &gns[0].Index
|
||||
input.Nets[i].SriovDevice.WireId = net.WireId
|
||||
err = self.createIsolatedDeviceOnHost(ctx, userCred, host, input.Nets[i].SriovDevice, pendingUsageHost)
|
||||
err = self.allocSriovNicDevice(ctx, userCred, host, &gns[0], input.Nets[i], pendingUsageHost)
|
||||
if err != nil {
|
||||
quotas.CancelPendingUsage(ctx, userCred, pendingUsageHost, pendingUsageHost, false)
|
||||
return nil, errors.Wrap(err, "self.createIsolatedDeviceOnHost")
|
||||
return nil, errors.Wrap(err, "self.allocSriovNicDevice")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -712,18 +712,18 @@ func (n *SGuestNetworkSyncTask) delNicDevice(nic *desc.SGuestNetwork) {
|
||||
}
|
||||
|
||||
func (n *SGuestNetworkSyncTask) addNic(nic *desc.SGuestNetwork) {
|
||||
if nic.Driver == "vfio-pci" {
|
||||
// vfio device will add on isolated devices sync task
|
||||
n.onDeviceAdd(nic)
|
||||
return
|
||||
}
|
||||
|
||||
if err := n.guest.generateNicScripts(nic); err != nil {
|
||||
log.Errorln(err)
|
||||
n.errors = append(n.errors, err)
|
||||
n.syncNetworkConf()
|
||||
return
|
||||
}
|
||||
|
||||
if nic.Driver == "vfio-pci" {
|
||||
// vfio device will add on isolated devices sync task
|
||||
n.onDeviceAdd(nic)
|
||||
return
|
||||
}
|
||||
var (
|
||||
netType = "tap"
|
||||
upscript = n.guest.getNicUpScriptPath(nic)
|
||||
|
||||
@@ -255,20 +255,18 @@ func (s *SGuestMonitorCollector) saveNicTraffics(reportData map[string]*GuestMet
|
||||
log.Warningf("failed found report data for nic %s", gm.Nics[i].Ifname)
|
||||
continue
|
||||
}
|
||||
nicHasBeenSetDown := false
|
||||
nicTraffic := compute.SNicTrafficRecord{}
|
||||
for index, record := range guestTrafficRecord {
|
||||
if index == strconv.Itoa(nicIo.Meta.Index) {
|
||||
nicTraffic.RxTraffic += record.RxTraffic
|
||||
nicTraffic.TxTraffic += record.TxTraffic
|
||||
nicHasBeenSetDown = record.HasBeenSetDown
|
||||
}
|
||||
}
|
||||
|
||||
if gm.Nics[i].RxTrafficLimit > 0 || gm.Nics[i].TxTrafficLimit > 0 {
|
||||
var nicDown, nicHasBeenSetDown = false, false
|
||||
if nicTraffic.RxTraffic >= gm.Nics[i].RxTrafficLimit || nicTraffic.RxTraffic >= gm.Nics[i].TxTrafficLimit {
|
||||
// record traffic excced, nic must has been set down
|
||||
nicHasBeenSetDown = true
|
||||
}
|
||||
var nicDown = false
|
||||
if gm.Nics[i].RxTrafficLimit > 0 {
|
||||
nicTraffic.RxTraffic += int64(nicIo.TimeDiff * nicIo.BPSRecv / 8)
|
||||
if nicTraffic.RxTraffic >= gm.Nics[i].RxTrafficLimit {
|
||||
@@ -283,11 +281,12 @@ func (s *SGuestMonitorCollector) saveNicTraffics(reportData map[string]*GuestMet
|
||||
nicDown = true
|
||||
}
|
||||
}
|
||||
guestTraffics[strconv.Itoa(nicIo.Meta.Index)] = nicTraffic
|
||||
if !nicHasBeenSetDown && nicDown {
|
||||
log.Infof("guest %s nic %d traffic exceed, set nic down", gm.Id, nicIo.Meta.Index)
|
||||
gm.SetNicDown(nicIo.Meta.Index)
|
||||
nicTraffic.HasBeenSetDown = true
|
||||
}
|
||||
guestTraffics[strconv.Itoa(nicIo.Meta.Index)] = nicTraffic
|
||||
}
|
||||
}
|
||||
if len(guestTraffics) == 0 {
|
||||
@@ -621,14 +620,26 @@ func (m *SGuestMonitor) Netio() []*NetIOMetric {
|
||||
data.Meta.NetId = nic.NetId
|
||||
data.Meta.Uptime, _ = host.Uptime()
|
||||
|
||||
data.BytesSent = nicStat.BytesRecv
|
||||
data.BytesRecv = nicStat.BytesSent
|
||||
data.PacketsRecv = nicStat.PacketsSent
|
||||
data.PacketsSent = nicStat.PacketsRecv
|
||||
data.ErrIn = nicStat.Errout
|
||||
data.ErrOut = nicStat.Errin
|
||||
data.DropIn = nicStat.Dropout
|
||||
data.DropOut = nicStat.Dropin
|
||||
if nic.Driver == "vfio-pci" {
|
||||
data.BytesSent = nicStat.BytesSent
|
||||
data.BytesRecv = nicStat.BytesRecv
|
||||
data.PacketsRecv = nicStat.PacketsRecv
|
||||
data.PacketsSent = nicStat.PacketsSent
|
||||
data.ErrIn = nicStat.Errin
|
||||
data.ErrOut = nicStat.Errout
|
||||
data.DropIn = nicStat.Dropin
|
||||
data.DropOut = nicStat.Dropout
|
||||
} else {
|
||||
data.BytesSent = nicStat.BytesRecv
|
||||
data.BytesRecv = nicStat.BytesSent
|
||||
data.PacketsRecv = nicStat.PacketsSent
|
||||
data.PacketsSent = nicStat.PacketsRecv
|
||||
data.ErrIn = nicStat.Errout
|
||||
data.ErrOut = nicStat.Errin
|
||||
data.DropIn = nicStat.Dropout
|
||||
data.DropOut = nicStat.Dropin
|
||||
}
|
||||
|
||||
res = append(res, data)
|
||||
}
|
||||
return res
|
||||
|
||||
Reference in New Issue
Block a user