]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev/iocost: call get_known_solutions() in apply_solution_for_path()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 26 Apr 2023 02:56:23 +0000 (11:56 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 26 Apr 2023 05:50:09 +0000 (14:50 +0900)
Then, the solution name can be logged.

src/udev/iocost/iocost.c

index 801751a398440131a796bbdf63b6890b20abf64f..9737cf6af706542732a6e5530c2ffecddab033be 100644 (file)
@@ -141,23 +141,14 @@ static int query_named_solution(
                 const char **ret_model,
                 const char **ret_qos) {
 
-        _cleanup_strv_free_ char **solutions = NULL;
         _cleanup_free_ char *upper_name = NULL, *qos_key = NULL, *model_key = NULL;
         const char *qos, *model;
         int r;
 
+        assert(name);
         assert(ret_qos);
         assert(ret_model);
 
-        /* If NULL is passed we query the default solution, which is the first one listed
-         * in the IOCOST_SOLUTIONS key or the one specified by the TargetSolution setting.
-         */
-        if (!name) {
-                r = get_known_solutions(device, LOG_DEBUG, &solutions, &name);
-                if (r < 0)
-                        return r;
-        }
-
         upper_name = strdup(name);
         if (!upper_name)
                 return log_oom();
@@ -193,6 +184,7 @@ static int query_named_solution(
 
 static int apply_solution_for_path(const char *path, const char *name) {
         _cleanup_(sd_device_unrefp) sd_device *device = NULL;
+        _cleanup_strv_free_ char **solutions = NULL;
         _cleanup_free_ char *qos = NULL, *model = NULL;
         const char *qos_params, *model_params;
         dev_t devnum;
@@ -202,16 +194,24 @@ static int apply_solution_for_path(const char *path, const char *name) {
         if (r < 0)
                 return log_error_errno(r, "Error looking up device: %m");
 
+        r = sd_device_get_devnum(device, &devnum);
+        if (r < 0)
+                return log_device_error_errno(device, r, "Error getting devnum: %m");
+
+        if (!name) {
+                r = get_known_solutions(device, LOG_DEBUG, &solutions, &name);
+                if (r == -ENOENT)
+                        return 0;
+                if (r < 0)
+                        return r;
+        }
+
         r = query_named_solution(device, name, &model_params, &qos_params);
         if (r == -ENOENT)
                 return 0;
         if (r < 0)
                 return r;
 
-        r = sd_device_get_devnum(device, &devnum);
-        if (r < 0)
-                return log_device_error_errno(device, r, "Error getting devnum: %m");
-
         if (asprintf(&qos, DEVNUM_FORMAT_STR " enable=1 ctrl=user %s", DEVNUM_FORMAT_VAL(devnum), qos_params) < 0)
                 return log_oom();
 
@@ -219,8 +219,9 @@ static int apply_solution_for_path(const char *path, const char *name) {
                 return log_oom();
 
         log_debug("Applying iocost parameters to %s using solution '%s'\n"
-                        "\tio.cost.qos: %s\n"
-                        "\tio.cost.model: %s\n", path, name ?: "default", qos, model);
+                  "\tio.cost.qos: %s\n"
+                  "\tio.cost.model: %s\n",
+                  path, name, qos, model);
 
         r = cg_set_attribute("io", NULL, "io.cost.qos", qos);
         if (r < 0) {