func updateReadAhead()

in pkg/nfs/nodeserver.go [371:414]


func updateReadAhead(targetMountPath string, readAheadKB int64) error {
	cmd := exec.Command("mountpoint", "-d", targetMountPath)
	output, err := cmd.CombinedOutput()
	if err != nil {
		klog.Errorf("Error executing mountpoint command on target path %s", targetMountPath)
		if exitError, ok := err.(*exec.ExitError); ok {
			fmt.Printf("Exit code: %d\n", exitError.ExitCode())
		}
		return status.Error(codes.Internal, err.Error())
	}

	outputStr := strings.TrimSpace(string(output))
	klog.Infof("output of mountpoint for target mount path %s: %s", targetMountPath, output)

	// Update the target value
	sysClassEchoCmd := fmt.Sprintf("echo %d > /sys/class/bdi/%s/read_ahead_kb", readAheadKB, outputStr)
	klog.V(2).Infof("Executing command %s", sysClassEchoCmd)
	cmd = exec.Command("sh", "-c", sysClassEchoCmd)
	_, err = cmd.CombinedOutput()
	if err != nil {
		return status.Error(codes.Internal, err.Error())
	}

	// Verify updated value
	sysClassCatCmd := fmt.Sprintf("cat /sys/class/bdi/%s/read_ahead_kb", outputStr)
	klog.V(2).Infof("Executing command %s", sysClassCatCmd)
	cmd = exec.Command("sh", "-c", sysClassCatCmd)
	op, err := cmd.CombinedOutput()
	if err != nil {
		return status.Error(codes.Internal, err.Error())
	}
	klog.V(2).Infof("Output of %q : %s", sysClassCatCmd, op)

	opStr := strings.TrimSpace(string(op))
	updatedVal, err := strconv.ParseInt(opStr, 10, 0)
	if err != nil {
		return fmt.Errorf("invalid read_ahead_kb %v", err)
	}
	if updatedVal != readAheadKB {
		return fmt.Errorf("mismatch in read_ahead_kb, expected %d, got %d", readAheadKB, updatedVal)
	}

	return nil
}