[PATCH 4/5] tuna: Add intelligent path resolution for cpuset apply

John Kacur <[email protected]> Tue, 28 Jul 2026 13:06:06 -0400
Newsgroups org.kernel.vger.linux-rt-users
Message-ID <[email protected]>
When applying a cpuset profile, search for the file in standard
locations if the user provides just a filename (not a full path).

Search order for relative paths:
1. Current directory (./filename)
2. /etc/tuna/filename

Absolute paths are used as-is without searching.

This allows users to run 'tuna cpuset apply my-config.yaml' from
any directory and have it automatically find the file in /etc/tuna/
if it's not in the current directory.

Assisted-by: Claude:claude-sonnet-4-5
Signed-off-by: John Kacur <[email protected]>
---
 tuna-cmd.py | 35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)

diff --git a/tuna-cmd.py b/tuna-cmd.py
index cf33af13d5d3..25515d5ddd5a 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -118,6 +118,36 @@ def get_default_cpuset_profile():
     else:
         return '/etc/tuna/cpuset-profile.yaml'
 
+def resolve_cpuset_profile_path(filename):
+    """Resolve cpuset profile path by searching in standard locations.
+
+    Args:
+        filename: User-provided filename or path
+
+    Returns:
+        str: Resolved absolute path if file exists, otherwise original filename
+
+    Search order for relative paths:
+        1. Current directory (./filename)
+        2. /etc/tuna/filename
+    Absolute paths are returned as-is.
+    """
+    # If absolute path, use it directly
+    if os.path.isabs(filename):
+        return filename
+
+    # Try current directory first
+    if os.path.exists(filename):
+        return filename
+
+    # Try /etc/tuna/ as fallback
+    etc_path = os.path.join('/etc/tuna', filename)
+    if os.path.exists(etc_path):
+        return etc_path
+
+    # Return original filename (will produce meaningful error if not found)
+    return filename
+
 def gen_parser():
 
 
@@ -404,8 +434,11 @@ def apply_cpusets_cmd(filename, verbose=False):
         print("Error: cgroup v2 cpusets not supported on this system", file=sys.stderr)
         sys.exit(1)
 
+    # Resolve filename (search current dir, then /etc/tuna/)
+    resolved_path = resolve_cpuset_profile_path(filename)
+
     # Apply cpusets using profile module (passes cpuset module for code reuse)
-    num_applied, num_warnings, num_errors = profile.apply_cpusets(filename, cpuset, verbose)
+    num_applied, num_warnings, num_errors = profile.apply_cpusets(resolved_path, cpuset, verbose)
 
     # Print summary
     if num_applied > 0:
-- 
2.55.0