Commit dec223c9 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe

blk-cgroup: move struct blkcg to block/blk-cgroup.h

There is no real need to expose the blkcg structure to the whole kernel.
Move it to the private header an expose a helper to let the writeback
code access the cgwb_list member.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Acked-by: default avatarTejun Heo <tj@kernel.org>
Link: https://lore.kernel.org/r/20220420042723.1010598-8-hch@lst.deSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 397c9f46
...@@ -1005,6 +1005,13 @@ static struct cftype blkcg_legacy_files[] = { ...@@ -1005,6 +1005,13 @@ static struct cftype blkcg_legacy_files[] = {
{ } /* terminate */ { } /* terminate */
}; };
#ifdef CONFIG_CGROUP_WRITEBACK
struct list_head *blkcg_get_cgwb_list(struct cgroup_subsys_state *css)
{
return &css_to_blkcg(css)->cgwb_list;
}
#endif
/* /*
* blkcg destruction is a three-stage process. * blkcg destruction is a three-stage process.
* *
...@@ -1112,7 +1119,7 @@ void blkcg_unpin_online(struct cgroup_subsys_state *blkcg_css) ...@@ -1112,7 +1119,7 @@ void blkcg_unpin_online(struct cgroup_subsys_state *blkcg_css)
static void blkcg_css_offline(struct cgroup_subsys_state *css) static void blkcg_css_offline(struct cgroup_subsys_state *css)
{ {
/* this prevents anyone from attaching or migrating to this blkcg */ /* this prevents anyone from attaching or migrating to this blkcg */
wb_blkcg_offline(css_to_blkcg(css)); wb_blkcg_offline(css);
/* put the base online pin allowing step 2 to be triggered */ /* put the base online pin allowing step 2 to be triggered */
blkcg_unpin_online(css); blkcg_unpin_online(css);
......
...@@ -17,10 +17,38 @@ ...@@ -17,10 +17,38 @@
#include <linux/blk-cgroup.h> #include <linux/blk-cgroup.h>
#include <linux/blk-mq.h> #include <linux/blk-mq.h>
struct blkcg_gq;
struct blkg_policy_data;
/* percpu_counter batch for blkg_[rw]stats, per-cpu drift doesn't matter */ /* percpu_counter batch for blkg_[rw]stats, per-cpu drift doesn't matter */
#define BLKG_STAT_CPU_BATCH (INT_MAX / 2) #define BLKG_STAT_CPU_BATCH (INT_MAX / 2)
#ifdef CONFIG_BLK_CGROUP #ifdef CONFIG_BLK_CGROUP
struct blkcg {
struct cgroup_subsys_state css;
spinlock_t lock;
refcount_t online_pin;
struct radix_tree_root blkg_tree;
struct blkcg_gq __rcu *blkg_hint;
struct hlist_head blkg_list;
struct blkcg_policy_data *cpd[BLKCG_MAX_POLS];
struct list_head all_blkcgs_node;
#ifdef CONFIG_BLK_CGROUP_FC_APPID
char fc_app_id[FC_APPID_LEN];
#endif
#ifdef CONFIG_CGROUP_WRITEBACK
struct list_head cgwb_list;
#endif
};
static inline struct blkcg *css_to_blkcg(struct cgroup_subsys_state *css)
{
return css ? container_of(css, struct blkcg, css) : NULL;
}
/* /*
* A blkcg_gq (blkg) is association between a block cgroup (blkcg) and a * A blkcg_gq (blkg) is association between a block cgroup (blkcg) and a
......
...@@ -17,8 +17,6 @@ ...@@ -17,8 +17,6 @@
#include <linux/backing-dev-defs.h> #include <linux/backing-dev-defs.h>
#include <linux/slab.h> #include <linux/slab.h>
struct blkcg;
static inline struct backing_dev_info *bdi_get(struct backing_dev_info *bdi) static inline struct backing_dev_info *bdi_get(struct backing_dev_info *bdi)
{ {
kref_get(&bdi->refcnt); kref_get(&bdi->refcnt);
...@@ -154,7 +152,7 @@ struct bdi_writeback *wb_get_create(struct backing_dev_info *bdi, ...@@ -154,7 +152,7 @@ struct bdi_writeback *wb_get_create(struct backing_dev_info *bdi,
struct cgroup_subsys_state *memcg_css, struct cgroup_subsys_state *memcg_css,
gfp_t gfp); gfp_t gfp);
void wb_memcg_offline(struct mem_cgroup *memcg); void wb_memcg_offline(struct mem_cgroup *memcg);
void wb_blkcg_offline(struct blkcg *blkcg); void wb_blkcg_offline(struct cgroup_subsys_state *css);
/** /**
* inode_cgwb_enabled - test whether cgroup writeback is enabled on an inode * inode_cgwb_enabled - test whether cgroup writeback is enabled on an inode
...@@ -378,7 +376,7 @@ static inline void wb_memcg_offline(struct mem_cgroup *memcg) ...@@ -378,7 +376,7 @@ static inline void wb_memcg_offline(struct mem_cgroup *memcg)
{ {
} }
static inline void wb_blkcg_offline(struct blkcg *blkcg) static inline void wb_blkcg_offline(struct cgroup_subsys_state *css)
{ {
} }
......
...@@ -37,29 +37,6 @@ enum blkg_iostat_type { ...@@ -37,29 +37,6 @@ enum blkg_iostat_type {
BLKG_IOSTAT_NR, BLKG_IOSTAT_NR,
}; };
struct blkcg_gq;
struct blkg_policy_data;
struct blkcg {
struct cgroup_subsys_state css;
spinlock_t lock;
refcount_t online_pin;
struct radix_tree_root blkg_tree;
struct blkcg_gq __rcu *blkg_hint;
struct hlist_head blkg_list;
struct blkcg_policy_data *cpd[BLKCG_MAX_POLS];
struct list_head all_blkcgs_node;
#ifdef CONFIG_BLK_CGROUP_FC_APPID
char fc_app_id[FC_APPID_LEN];
#endif
#ifdef CONFIG_CGROUP_WRITEBACK
struct list_head cgwb_list;
#endif
};
struct blkg_iostat { struct blkg_iostat {
u64 bytes[BLKG_IOSTAT_NR]; u64 bytes[BLKG_IOSTAT_NR];
u64 ios[BLKG_IOSTAT_NR]; u64 ios[BLKG_IOSTAT_NR];
...@@ -114,11 +91,6 @@ extern struct cgroup_subsys_state * const blkcg_root_css; ...@@ -114,11 +91,6 @@ extern struct cgroup_subsys_state * const blkcg_root_css;
void blkcg_schedule_throttle(struct request_queue *q, bool use_memdelay); void blkcg_schedule_throttle(struct request_queue *q, bool use_memdelay);
void blkcg_maybe_throttle_current(void); void blkcg_maybe_throttle_current(void);
static inline struct blkcg *css_to_blkcg(struct cgroup_subsys_state *css)
{
return css ? container_of(css, struct blkcg, css) : NULL;
}
/** /**
* bio_blkcg - grab the blkcg associated with a bio * bio_blkcg - grab the blkcg associated with a bio
* @bio: target bio * @bio: target bio
...@@ -137,12 +109,10 @@ static inline struct blkcg *bio_blkcg(struct bio *bio) ...@@ -137,12 +109,10 @@ static inline struct blkcg *bio_blkcg(struct bio *bio)
bool blk_cgroup_congested(void); bool blk_cgroup_congested(void);
void blkcg_pin_online(struct cgroup_subsys_state *blkcg_css); void blkcg_pin_online(struct cgroup_subsys_state *blkcg_css);
void blkcg_unpin_online(struct cgroup_subsys_state *blkcg_css); void blkcg_unpin_online(struct cgroup_subsys_state *blkcg_css);
struct list_head *blkcg_get_cgwb_list(struct cgroup_subsys_state *css);
#else /* CONFIG_BLK_CGROUP */ #else /* CONFIG_BLK_CGROUP */
struct blkcg {
};
struct blkcg_gq { struct blkcg_gq {
}; };
......
...@@ -445,7 +445,6 @@ static int cgwb_create(struct backing_dev_info *bdi, ...@@ -445,7 +445,6 @@ static int cgwb_create(struct backing_dev_info *bdi,
{ {
struct mem_cgroup *memcg; struct mem_cgroup *memcg;
struct cgroup_subsys_state *blkcg_css; struct cgroup_subsys_state *blkcg_css;
struct blkcg *blkcg;
struct list_head *memcg_cgwb_list, *blkcg_cgwb_list; struct list_head *memcg_cgwb_list, *blkcg_cgwb_list;
struct bdi_writeback *wb; struct bdi_writeback *wb;
unsigned long flags; unsigned long flags;
...@@ -453,9 +452,8 @@ static int cgwb_create(struct backing_dev_info *bdi, ...@@ -453,9 +452,8 @@ static int cgwb_create(struct backing_dev_info *bdi,
memcg = mem_cgroup_from_css(memcg_css); memcg = mem_cgroup_from_css(memcg_css);
blkcg_css = cgroup_get_e_css(memcg_css->cgroup, &io_cgrp_subsys); blkcg_css = cgroup_get_e_css(memcg_css->cgroup, &io_cgrp_subsys);
blkcg = css_to_blkcg(blkcg_css);
memcg_cgwb_list = &memcg->cgwb_list; memcg_cgwb_list = &memcg->cgwb_list;
blkcg_cgwb_list = &blkcg->cgwb_list; blkcg_cgwb_list = blkcg_get_cgwb_list(blkcg_css);
/* look up again under lock and discard on blkcg mismatch */ /* look up again under lock and discard on blkcg mismatch */
spin_lock_irqsave(&cgwb_lock, flags); spin_lock_irqsave(&cgwb_lock, flags);
...@@ -723,18 +721,19 @@ void wb_memcg_offline(struct mem_cgroup *memcg) ...@@ -723,18 +721,19 @@ void wb_memcg_offline(struct mem_cgroup *memcg)
/** /**
* wb_blkcg_offline - kill all wb's associated with a blkcg being offlined * wb_blkcg_offline - kill all wb's associated with a blkcg being offlined
* @blkcg: blkcg being offlined * @css: blkcg being offlined
* *
* Also prevents creation of any new wb's associated with @blkcg. * Also prevents creation of any new wb's associated with @blkcg.
*/ */
void wb_blkcg_offline(struct blkcg *blkcg) void wb_blkcg_offline(struct cgroup_subsys_state *css)
{ {
struct bdi_writeback *wb, *next; struct bdi_writeback *wb, *next;
struct list_head *list = blkcg_get_cgwb_list(css);
spin_lock_irq(&cgwb_lock); spin_lock_irq(&cgwb_lock);
list_for_each_entry_safe(wb, next, &blkcg->cgwb_list, blkcg_node) list_for_each_entry_safe(wb, next, list, blkcg_node)
cgwb_kill(wb); cgwb_kill(wb);
blkcg->cgwb_list.next = NULL; /* prevent new wb's */ list->next = NULL; /* prevent new wb's */
spin_unlock_irq(&cgwb_lock); spin_unlock_irq(&cgwb_lock);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment