Skip to content

Commit

Permalink
Merge pull request #18641 from wanyaoqi/automated-cherry-pick-of-#186…
Browse files Browse the repository at this point in the history
…39-upstream-master

Automated cherry pick of #18639: fix(region,host): sriov nic hotplug and metrics fix
  • Loading branch information
zexi authored Nov 13, 2023
2 parents 4116a06 + 0c98109 commit ee80ff4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 25 deletions.
2 changes: 2 additions & 0 deletions pkg/apis/compute/guestnetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,6 @@ type GuestnetworkJsonDesc struct {
type SNicTrafficRecord struct {
RxTraffic int64
TxTraffic int64

HasBeenSetDown bool
}
7 changes: 2 additions & 5 deletions pkg/compute/models/guest_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/hostman/guestman/guesttasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
39 changes: 25 additions & 14 deletions pkg/hostman/hostmetrics/hostmetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ee80ff4

Please sign in to comment.