Skip to content

Commit 4a893bd

Browse files
Werkovhtejun
authored andcommitted
blk-cgroup: Simplify policy files registration
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ý <[email protected]> Acked-by: Jens Axboe <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent 76f9409 commit 4a893bd

File tree

4 files changed

+14
-19
lines changed

4 files changed

+14
-19
lines changed

block/blk-cgroup.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,12 +1768,15 @@ int blkcg_policy_register(struct blkcg_policy *pol)
17681768
mutex_unlock(&blkcg_pol_mutex);
17691769

17701770
/* everything is in place, add intf files for the new policy */
1771-
if (pol->dfl_cftypes)
1771+
if (pol->dfl_cftypes == pol->legacy_cftypes) {
1772+
WARN_ON(cgroup_add_cftypes(&io_cgrp_subsys,
1773+
pol->dfl_cftypes));
1774+
} else {
17721775
WARN_ON(cgroup_add_dfl_cftypes(&io_cgrp_subsys,
17731776
pol->dfl_cftypes));
1774-
if (pol->legacy_cftypes)
17751777
WARN_ON(cgroup_add_legacy_cftypes(&io_cgrp_subsys,
17761778
pol->legacy_cftypes));
1779+
}
17771780
mutex_unlock(&blkcg_pol_register_mutex);
17781781
return 0;
17791782

block/blk-ioprio.c

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -113,27 +113,18 @@ static void ioprio_free_cpd(struct blkcg_policy_data *cpd)
113113
kfree(blkcg);
114114
}
115115

116-
#define IOPRIO_ATTRS \
117-
{ \
118-
.name = "prio.class", \
119-
.seq_show = ioprio_show_prio_policy, \
120-
.write = ioprio_set_prio_policy, \
121-
}, \
122-
{ } /* sentinel */
123-
124-
/* cgroup v2 attributes */
125116
static struct cftype ioprio_files[] = {
126-
IOPRIO_ATTRS
127-
};
128-
129-
/* cgroup v1 attributes */
130-
static struct cftype ioprio_legacy_files[] = {
131-
IOPRIO_ATTRS
117+
{
118+
.name = "prio.class",
119+
.seq_show = ioprio_show_prio_policy,
120+
.write = ioprio_set_prio_policy,
121+
},
122+
{ } /* sentinel */
132123
};
133124

134125
static struct blkcg_policy ioprio_policy = {
135126
.dfl_cftypes = ioprio_files,
136-
.legacy_cftypes = ioprio_legacy_files,
127+
.legacy_cftypes = ioprio_files,
137128

138129
.cpd_alloc_fn = ioprio_alloc_cpd,
139130
.cpd_free_fn = ioprio_free_cpd,

include/linux/cgroup.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ int cgroup_transfer_tasks(struct cgroup *to, struct cgroup *from);
113113

114114
int cgroup_add_dfl_cftypes(struct cgroup_subsys *ss, struct cftype *cfts);
115115
int cgroup_add_legacy_cftypes(struct cgroup_subsys *ss, struct cftype *cfts);
116+
int cgroup_add_cftypes(struct cgroup_subsys *ss, struct cftype *cfts);
116117
int cgroup_rm_cftypes(struct cftype *cfts);
117118
void cgroup_file_notify(struct cgroup_file *cfile);
118119
void cgroup_file_show(struct cgroup_file *cfile, bool show);

kernel/cgroup/cgroup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4451,7 +4451,7 @@ int cgroup_rm_cftypes(struct cftype *cfts)
44514451
* function currently returns 0 as long as @cfts registration is successful
44524452
* even if some file creation attempts on existing cgroups fail.
44534453
*/
4454-
static int cgroup_add_cftypes(struct cgroup_subsys *ss, struct cftype *cfts)
4454+
int cgroup_add_cftypes(struct cgroup_subsys *ss, struct cftype *cfts)
44554455
{
44564456
int ret;
44574457

0 commit comments

Comments
 (0)