Skip to content

Commit

Permalink
Merge pull request #922 from tydra-wang/fix-nas-sysctl
Browse files Browse the repository at this point in the history
fix(nas): set /proc/sys/sunrpc/tcp_slot_table_entries to 128
  • Loading branch information
k8s-ci-robot committed Dec 6, 2023
2 parents 15f6e0e + 8b0a90d commit fe4ce65
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 30 deletions.
6 changes: 3 additions & 3 deletions pkg/nas/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ const (

// newNodeServer create the csi node server
func newNodeServer(d *NAS) *nodeServer {
if err := checkSystemNasConfig(); err != nil {
log.Errorf("failed to config /proc/sys/sunrpc/tcp_slot_table_entries: %v", err)
}
return &nodeServer{
clientSet: GlobalConfigVar.KubeClient,
crdClient: GlobalConfigVar.DynamicClient,
Expand Down Expand Up @@ -387,9 +390,6 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
return &csi.NodePublishVolumeResponse{}, nil
}

// if system not set nas, config it.
checkSystemNasConfig()

//cpfs-nfs check valid
/*if opt.FSType == "cpfs" {
if !strings.HasPrefix(opt.Path, "/share") {
Expand Down
35 changes: 8 additions & 27 deletions pkg/nas/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ const (
Resize2fsFailedFixCmd = "%s fsck -a %s"

GiB = 1 << 30
// see https://help.aliyun.com/zh/nas/modify-the-maximum-number-of-concurrent-nfs-requests
TcpSlotTableEntries = "/proc/sys/sunrpc/tcp_slot_table_entries"
TcpSlotTableEntriesValue = "128\n"
)

var (
Expand Down Expand Up @@ -350,34 +353,12 @@ func setNasVolumeCapacityWithID(pvObj *v1.PersistentVolume, crdClient dynamic.In

// check system config,
// if tcp_slot_table_entries not set to 128, just config.
func checkSystemNasConfig() {
sunRPCFile := "/etc/modprobe.d/sunrpc.conf"
if utils.IsFileExisting(sunRPCFile) {
data, err := os.ReadFile(sunRPCFile)
if err != nil {
log.Warnf("Update Nas system config check error: %s", err.Error())
return
}
for _, line := range strings.Split(string(data), "\n") {
if strings.Contains(line, "tcp_slot_table_entries") && strings.Contains(line, "128") {
return
}
}
}

sunRpcConfig := "\"options sunrpc tcp_slot_table_entries=128\"\n\"options sunrpc tcp_max_slot_table_entries=128\""
// startRpcConfig := "sysctl -w sunrpc.tcp_slot_table_entries=128"
err := utils.WriteAndSyncFile(sunRPCFile, []byte(sunRpcConfig), 0755)
if err != nil {
log.Warnf("Write nas rpcconfig %s is failed, err: %s", sunRPCFile, err.Error())
return
}
err = exec.Command("sysctl", "-w", "sunrpc.tcp_slot_table_entries=128").Run()
if err != nil {
log.Warnf("Start nas rpcconfig is failed, err: %s", err.Error())
return
func checkSystemNasConfig() error {
data, err := os.ReadFile(TcpSlotTableEntries)
if err == nil && string(data) == TcpSlotTableEntriesValue {
return nil
}
log.Warnf("Update nas system config is successfully.")
return os.WriteFile(TcpSlotTableEntries, []byte(TcpSlotTableEntriesValue), os.ModePerm)
}

// ParseMountFlags parse mountOptions
Expand Down

0 comments on commit fe4ce65

Please sign in to comment.