File ppc64_cpu-Clean-up-sysfs-smt-control-error-handling.patch of Package powerpc-utils.37742

From 8d613e0e81561ce0b1d6ea834b07c73f5f9251a1 Mon Sep 17 00:00:00 2001
From: Michal Suchanek <msuchanek@suse.de>
Date: Fri, 9 Feb 2024 13:12:33 +0100
Subject: [PATCH] ppc64_cpu: Clean up sysfs smt/control error handling

When the kernel does not support the sysfs intercface do not report an
arror, fall back to the old method silently.

Suggested-by: Nathan Lynch<nathanl@linux.ibm.com>
Signed-off-by: Michal Suchanek <msuchanek@suse.de>
---
v3: retry is needed on ENODEV to support powernv
---
 src/ppc64_cpu.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/src/ppc64_cpu.c b/src/ppc64_cpu.c
index c318928..688152b 100644
--- a/src/ppc64_cpu.c
+++ b/src/ppc64_cpu.c
@@ -364,14 +364,28 @@ static int is_dscr_capable(void)
 
 /*
  * Depends on kernel's CONFIG_HOTPLUG_CPU
+ * Return -1 for fatal error, -2 to retry.
  */
 static int set_smt_control(int smt_state)
 {
 	if (set_attribute(SYS_SMT_CONTROL, "%d", smt_state)) {
-		/* Silently ignore kernel not supporting this feature */
-		if (errno != ENODEV)
-			perror(SYS_SMT_CONTROL);
-		return -1;
+		switch (errno) {
+			case ENOENT:
+			/*
+			 * The kernel does not have the interface.
+			 * Try the old method.
+			 */
+				return -2;
+			case ENODEV:
+			/*
+			 * Setting SMT state not supported by this interface.
+			 * eg. powernv
+			 */
+				return -2;
+			default:
+				perror(SYS_SMT_CONTROL);
+				return -1;
+		}
 	}
 	return 0;
 }
@@ -405,7 +419,7 @@ static int do_smt(char *state, bool numeric)
 		}
 
 		/* Try using smt/control if failing, fall back to the legacy way */
-		if (set_smt_control(smt_state))
+		if ((rc = set_smt_control(smt_state)) == -2)
 			rc = set_smt_state(smt_state);
 	}
 
-- 
2.44.0

openSUSE Build Service is sponsored by