blk-cgroup: refactor blkcg_print_stat
Factor out a helper to deal with a single blkcg_gq to make the code a little bit easier to follow. Signed-off-by: Christoph Hellwig <hch@lst.de> Acked-by: Tejun Heo <tj@kernel.org> Link: https://lore.kernel.org/r/20210810152623.1796144-1-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
committed by
Jens Axboe
parent
3973e15fa5
commit
49cb5168a7
@@ -870,36 +870,23 @@ static void blkcg_fill_root_iostats(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int blkcg_print_stat(struct seq_file *sf, void *v)
|
static void blkcg_print_one_stat(struct blkcg_gq *blkg, struct seq_file *s)
|
||||||
{
|
{
|
||||||
struct blkcg *blkcg = css_to_blkcg(seq_css(sf));
|
|
||||||
struct blkcg_gq *blkg;
|
|
||||||
|
|
||||||
if (!seq_css(sf)->parent)
|
|
||||||
blkcg_fill_root_iostats();
|
|
||||||
else
|
|
||||||
cgroup_rstat_flush(blkcg->css.cgroup);
|
|
||||||
|
|
||||||
rcu_read_lock();
|
|
||||||
|
|
||||||
hlist_for_each_entry_rcu(blkg, &blkcg->blkg_list, blkcg_node) {
|
|
||||||
struct blkg_iostat_set *bis = &blkg->iostat;
|
struct blkg_iostat_set *bis = &blkg->iostat;
|
||||||
const char *dname;
|
|
||||||
char *buf;
|
|
||||||
u64 rbytes, wbytes, rios, wios, dbytes, dios;
|
u64 rbytes, wbytes, rios, wios, dbytes, dios;
|
||||||
size_t size = seq_get_buf(sf, &buf), off = 0;
|
|
||||||
int i;
|
|
||||||
bool has_stats = false;
|
bool has_stats = false;
|
||||||
|
const char *dname;
|
||||||
unsigned seq;
|
unsigned seq;
|
||||||
|
char *buf;
|
||||||
spin_lock_irq(&blkg->q->queue_lock);
|
size_t size = seq_get_buf(s, &buf), off = 0;
|
||||||
|
int i;
|
||||||
|
|
||||||
if (!blkg->online)
|
if (!blkg->online)
|
||||||
goto skip;
|
return;
|
||||||
|
|
||||||
dname = blkg_dev_name(blkg);
|
dname = blkg_dev_name(blkg);
|
||||||
if (!dname)
|
if (!dname)
|
||||||
goto skip;
|
return;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Hooray string manipulation, count is the size written NOT
|
* Hooray string manipulation, count is the size written NOT
|
||||||
@@ -930,10 +917,9 @@ static int blkcg_print_stat(struct seq_file *sf, void *v)
|
|||||||
|
|
||||||
if (blkcg_debug_stats && atomic_read(&blkg->use_delay)) {
|
if (blkcg_debug_stats && atomic_read(&blkg->use_delay)) {
|
||||||
has_stats = true;
|
has_stats = true;
|
||||||
off += scnprintf(buf+off, size-off,
|
off += scnprintf(buf+off, size-off, " use_delay=%d delay_nsec=%llu",
|
||||||
" use_delay=%d delay_nsec=%llu",
|
|
||||||
atomic_read(&blkg->use_delay),
|
atomic_read(&blkg->use_delay),
|
||||||
(unsigned long long)atomic64_read(&blkg->delay_nsec));
|
atomic64_read(&blkg->delay_nsec));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < BLKCG_MAX_POLS; i++) {
|
for (i = 0; i < BLKCG_MAX_POLS; i++) {
|
||||||
@@ -952,15 +938,29 @@ static int blkcg_print_stat(struct seq_file *sf, void *v)
|
|||||||
if (has_stats) {
|
if (has_stats) {
|
||||||
if (off < size - 1) {
|
if (off < size - 1) {
|
||||||
off += scnprintf(buf+off, size-off, "\n");
|
off += scnprintf(buf+off, size-off, "\n");
|
||||||
seq_commit(sf, off);
|
seq_commit(s, off);
|
||||||
} else {
|
} else {
|
||||||
seq_commit(sf, -1);
|
seq_commit(s, -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
skip:
|
|
||||||
spin_unlock_irq(&blkg->q->queue_lock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int blkcg_print_stat(struct seq_file *sf, void *v)
|
||||||
|
{
|
||||||
|
struct blkcg *blkcg = css_to_blkcg(seq_css(sf));
|
||||||
|
struct blkcg_gq *blkg;
|
||||||
|
|
||||||
|
if (!seq_css(sf)->parent)
|
||||||
|
blkcg_fill_root_iostats();
|
||||||
|
else
|
||||||
|
cgroup_rstat_flush(blkcg->css.cgroup);
|
||||||
|
|
||||||
|
rcu_read_lock();
|
||||||
|
hlist_for_each_entry_rcu(blkg, &blkcg->blkg_list, blkcg_node) {
|
||||||
|
spin_lock_irq(&blkg->q->queue_lock);
|
||||||
|
blkcg_print_one_stat(blkg, sf);
|
||||||
|
spin_unlock_irq(&blkg->q->queue_lock);
|
||||||
|
}
|
||||||
rcu_read_unlock();
|
rcu_read_unlock();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user