]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
blk-cgroup: Simplify policy files registration
authorMichal Koutný <mkoutny@suse.com>
Tue, 11 Mar 2025 12:36:28 +0000 (13:36 +0100)
committerTejun Heo <tj@kernel.org>
Tue, 11 Mar 2025 19:22:55 +0000 (09:22 -1000)
Use one set of files when there is no difference between default and
legacy files, similar to regular subsys files registration. No
functional change.

Signed-off-by: Michal Koutný <mkoutny@suse.com>
Acked-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Tejun Heo <tj@kernel.org>
block/blk-cgroup.c
block/blk-ioprio.c
include/linux/cgroup.h
kernel/cgroup/cgroup.c

index b3e5184b10d5ff741feaef2f90f0281872be48de..fa26b33b540e253d635378f353d9d8d7340719ad 100644 (file)
@@ -1768,12 +1768,15 @@ int blkcg_policy_register(struct blkcg_policy *pol)
        mutex_unlock(&blkcg_pol_mutex);
 
        /* everything is in place, add intf files for the new policy */
-       if (pol->dfl_cftypes)
+       if (pol->dfl_cftypes == pol->legacy_cftypes) {
+               WARN_ON(cgroup_add_cftypes(&io_cgrp_subsys,
+                                          pol->dfl_cftypes));
+       } else {
                WARN_ON(cgroup_add_dfl_cftypes(&io_cgrp_subsys,
                                               pol->dfl_cftypes));
-       if (pol->legacy_cftypes)
                WARN_ON(cgroup_add_legacy_cftypes(&io_cgrp_subsys,
                                                  pol->legacy_cftypes));
+       }
        mutex_unlock(&blkcg_pol_register_mutex);
        return 0;
 
index 8fff7ccc0ac7353ee72d4e15105f6b2fa68fbfed..13659dc15c3fffaef93eb934d1a68a2c3c00f280 100644 (file)
@@ -113,27 +113,18 @@ static void ioprio_free_cpd(struct blkcg_policy_data *cpd)
        kfree(blkcg);
 }
 
-#define IOPRIO_ATTRS                                           \
-       {                                                       \
-               .name           = "prio.class",                 \
-               .seq_show       = ioprio_show_prio_policy,      \
-               .write          = ioprio_set_prio_policy,       \
-       },                                                      \
-       { } /* sentinel */
-
-/* cgroup v2 attributes */
 static struct cftype ioprio_files[] = {
-       IOPRIO_ATTRS
-};
-
-/* cgroup v1 attributes */
-static struct cftype ioprio_legacy_files[] = {
-       IOPRIO_ATTRS
+       {
+               .name           = "prio.class",
+               .seq_show       = ioprio_show_prio_policy,
+               .write          = ioprio_set_prio_policy,
+       },
+       { } /* sentinel */
 };
 
 static struct blkcg_policy ioprio_policy = {
        .dfl_cftypes    = ioprio_files,
-       .legacy_cftypes = ioprio_legacy_files,
+       .legacy_cftypes = ioprio_files,
 
        .cpd_alloc_fn   = ioprio_alloc_cpd,
        .cpd_free_fn    = ioprio_free_cpd,
index f8ef47f8a634df490a8aea2344183f6b1c08aa9f..8e7415c64ed1d5d6240fcacc3b8ab54f539e3a01 100644 (file)
@@ -113,6 +113,7 @@ int cgroup_transfer_tasks(struct cgroup *to, struct cgroup *from);
 
 int cgroup_add_dfl_cftypes(struct cgroup_subsys *ss, struct cftype *cfts);
 int cgroup_add_legacy_cftypes(struct cgroup_subsys *ss, struct cftype *cfts);
+int cgroup_add_cftypes(struct cgroup_subsys *ss, struct cftype *cfts);
 int cgroup_rm_cftypes(struct cftype *cfts);
 void cgroup_file_notify(struct cgroup_file *cfile);
 void cgroup_file_show(struct cgroup_file *cfile, bool show);
index a810952d75c843698d03ecdbd95d325acaae0782..66f79f798c2554376c291375d3907d2a008ec609 100644 (file)
@@ -4451,7 +4451,7 @@ int cgroup_rm_cftypes(struct cftype *cfts)
  * function currently returns 0 as long as @cfts registration is successful
  * even if some file creation attempts on existing cgroups fail.
  */
-static int cgroup_add_cftypes(struct cgroup_subsys *ss, struct cftype *cfts)
+int cgroup_add_cftypes(struct cgroup_subsys *ss, struct cftype *cfts)
 {
        int ret;