Skip to content

Commit

Permalink
blk-cgroup: Simplify policy files registration
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Michal Koutný authored and Tejun Heo committed Mar 11, 2025
1 parent 76f9409 commit 4a893bd
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 19 deletions.
7 changes: 5 additions & 2 deletions block/blk-cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
23 changes: 7 additions & 16 deletions block/blk-ioprio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions include/linux/cgroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion kernel/cgroup/cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 4a893bd

Please sign in to comment.