From 718dbd3cb8ae856c5fdfeb4b5c9cc7fe74ebc89b Mon Sep 17 00:00:00 2001 From: Qiu Jian Date: Fri, 19 Nov 2021 03:11:19 +0800 Subject: [PATCH] fix: add host option for ethtool_enable_gso --- pkg/hostman/hostinfo/hostbridge/hostbridge.go | 2 +- pkg/hostman/options/options.go | 5 ++++- pkg/util/netutils2/netutils.go | 16 ++++++++++++---- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/pkg/hostman/hostinfo/hostbridge/hostbridge.go b/pkg/hostman/hostinfo/hostbridge/hostbridge.go index 48bf3a120c..4bd72110ef 100644 --- a/pkg/hostman/hostinfo/hostbridge/hostbridge.go +++ b/pkg/hostman/hostinfo/hostbridge/hostbridge.go @@ -78,7 +78,7 @@ func NewBaseBridgeDriver(bridge, inter, ip string) (*SBaseBridgeDriver, error) { return nil, fmt.Errorf("%s not exists", inter) } bd.ip = ip - bd.inter.DisableGso() + bd.inter.SetupGso(options.HostOptions.EthtoolEnableGso) } else if len(ip) > 0 { return nil, fmt.Errorf("A bridge without interface must have no IP") } diff --git a/pkg/hostman/options/options.go b/pkg/hostman/options/options.go index 18f2f3ab97..40e84e2553 100644 --- a/pkg/hostman/options/options.go +++ b/pkg/hostman/options/options.go @@ -18,6 +18,7 @@ import ( "os" common_options "yunion.io/x/onecloud/pkg/cloudcommon/options" + "yunion.io/x/onecloud/pkg/util/fileutils2" ) type SHostOptions struct { @@ -147,6 +148,8 @@ type SHostOptions struct { DisableKVM bool `help:"force disable KVM" default:"false" json:"disable_kvm"` DisableGPU bool `help:"force disable GPU" default:"false" json:"disable_gpu"` + + EthtoolEnableGso bool `help:"use ethtool to turn on or off GSO(generic segment offloading)" default:"false" json:"ethtool_enable_gso"` } var ( @@ -155,7 +158,7 @@ var ( func Parse() (hostOpts SHostOptions) { common_options.ParseOptions(&hostOpts, os.Args, "host.conf", "host") - if len(hostOpts.CommonConfigFile) > 0 { + if len(hostOpts.CommonConfigFile) > 0 && fileutils2.Exists(hostOpts.CommonConfigFile) { commonCfg := &common_options.HostCommonOptions{} commonCfg.Config = hostOpts.CommonConfigFile common_options.ParseOptions(commonCfg, []string{os.Args[0]}, "common.conf", "host") diff --git a/pkg/util/netutils2/netutils.go b/pkg/util/netutils2/netutils.go index 7c1c519bda..cc244124b6 100644 --- a/pkg/util/netutils2/netutils.go +++ b/pkg/util/netutils2/netutils.go @@ -346,12 +346,20 @@ func (n *SNetInterface) fetchConfig(expectIp string) { } -func (n *SNetInterface) DisableGso() { +// https://kris.io/2015/10/01/kvm-network-performance-tso-and-gso-turn-it-off/ +// General speaking, it is recommended to turn of GSO +// however, this will degrade host network performance +func (n *SNetInterface) SetupGso(on bool) { + onoff := "off" + if on { + onoff = "on" + } procutils.NewCommand( "ethtool", "-K", n.name, - "tso", "off", "gso", "off", - "gro", "off", "tx", "off", - "rx", "off", "sg", "off").Run() + "tso", onoff, "gso", onoff, + "ufo", onoff, "lro", onoff, + "gro", onoff, "tx", onoff, + "rx", onoff, "sg", onoff).Run() } func (n *SNetInterface) IsSecretInterface() bool {