aboutsummaryrefslogtreecommitdiffstats
path: root/block/blk-cgroup.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2012-04-16 16:57:26 -0400
committerJens Axboe <axboe@kernel.dk>2012-04-20 04:06:17 -0400
commitf95a04afa80c0f4ddd645ef6a84ed118b5d1ad46 (patch)
tree2428dacf9bab1eb643628c872aed3092704f7fb2 /block/blk-cgroup.c
parent3c798398e393e5f9502dbab2b51e6c25e2e8f2ac (diff)
blkcg: embed struct blkg_policy_data in policy specific data
Currently blkg_policy_data carries policy specific data as char flex array instead of being embedded in policy specific data. This was forced by oddities around blkg allocation which are all gone now. This patch makes blkg_policy_data embedded in policy specific data - throtl_grp and cfq_group so that it's more conventional and consistent with how io_cq is handled. * blkcg_policy->pdata_size is renamed to ->pd_size. * Functions which used to take void *pdata now takes struct blkg_policy_data *pd. * blkg_to_pdata/pdata_to_blkg() updated to blkg_to_pd/pd_to_blkg(). * Dummy struct blkg_policy_data definition added. Dummy pdata_to_blkg() definition was unused and inconsistent with the non-dummy version - correct dummy pd_to_blkg() added. * throtl and cfq updated accordingly. * As dummy blkg_to_pd/pd_to_blkg() are provided, blkg_to_cfqg/cfqg_to_blkg() don't need to be ifdef'd. Moved outside ifdef block. This patch doesn't introduce any functional change. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Vivek Goyal <vgoyal@redhat.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block/blk-cgroup.c')
-rw-r--r--block/blk-cgroup.c52
1 files changed, 26 insertions, 26 deletions
diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index 997570329517..3d495528a765 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -58,11 +58,6 @@ static bool blkcg_policy_enabled(struct request_queue *q,
58 return pol && test_bit(pol->plid, q->blkcg_pols); 58 return pol && test_bit(pol->plid, q->blkcg_pols);
59} 59}
60 60
61static size_t blkg_pd_size(const struct blkcg_policy *pol)
62{
63 return sizeof(struct blkg_policy_data) + pol->pdata_size;
64}
65
66/** 61/**
67 * blkg_free - free a blkg 62 * blkg_free - free a blkg
68 * @blkg: blkg to free 63 * @blkg: blkg to free
@@ -122,7 +117,7 @@ static struct blkcg_gq *blkg_alloc(struct blkcg *blkcg, struct request_queue *q)
122 continue; 117 continue;
123 118
124 /* alloc per-policy data and attach it to blkg */ 119 /* alloc per-policy data and attach it to blkg */
125 pd = kzalloc_node(blkg_pd_size(pol), GFP_ATOMIC, q->node); 120 pd = kzalloc_node(pol->pd_size, GFP_ATOMIC, q->node);
126 if (!pd) { 121 if (!pd) {
127 blkg_free(blkg); 122 blkg_free(blkg);
128 return NULL; 123 return NULL;
@@ -346,7 +341,8 @@ static const char *blkg_dev_name(struct blkcg_gq *blkg)
346 * cftype->read_seq_string method. 341 * cftype->read_seq_string method.
347 */ 342 */
348void blkcg_print_blkgs(struct seq_file *sf, struct blkcg *blkcg, 343void blkcg_print_blkgs(struct seq_file *sf, struct blkcg *blkcg,
349 u64 (*prfill)(struct seq_file *, void *, int), 344 u64 (*prfill)(struct seq_file *,
345 struct blkg_policy_data *, int),
350 const struct blkcg_policy *pol, int data, 346 const struct blkcg_policy *pol, int data,
351 bool show_total) 347 bool show_total)
352{ 348{
@@ -357,7 +353,7 @@ void blkcg_print_blkgs(struct seq_file *sf, struct blkcg *blkcg,
357 spin_lock_irq(&blkcg->lock); 353 spin_lock_irq(&blkcg->lock);
358 hlist_for_each_entry(blkg, n, &blkcg->blkg_list, blkcg_node) 354 hlist_for_each_entry(blkg, n, &blkcg->blkg_list, blkcg_node)
359 if (blkcg_policy_enabled(blkg->q, pol)) 355 if (blkcg_policy_enabled(blkg->q, pol))
360 total += prfill(sf, blkg->pd[pol->plid]->pdata, data); 356 total += prfill(sf, blkg->pd[pol->plid], data);
361 spin_unlock_irq(&blkcg->lock); 357 spin_unlock_irq(&blkcg->lock);
362 358
363 if (show_total) 359 if (show_total)
@@ -368,14 +364,14 @@ EXPORT_SYMBOL_GPL(blkcg_print_blkgs);
368/** 364/**
369 * __blkg_prfill_u64 - prfill helper for a single u64 value 365 * __blkg_prfill_u64 - prfill helper for a single u64 value
370 * @sf: seq_file to print to 366 * @sf: seq_file to print to
371 * @pdata: policy private data of interest 367 * @pd: policy private data of interest
372 * @v: value to print 368 * @v: value to print
373 * 369 *
374 * Print @v to @sf for the device assocaited with @pdata. 370 * Print @v to @sf for the device assocaited with @pd.
375 */ 371 */
376u64 __blkg_prfill_u64(struct seq_file *sf, void *pdata, u64 v) 372u64 __blkg_prfill_u64(struct seq_file *sf, struct blkg_policy_data *pd, u64 v)
377{ 373{
378 const char *dname = blkg_dev_name(pdata_to_blkg(pdata)); 374 const char *dname = blkg_dev_name(pd->blkg);
379 375
380 if (!dname) 376 if (!dname)
381 return 0; 377 return 0;
@@ -388,12 +384,12 @@ EXPORT_SYMBOL_GPL(__blkg_prfill_u64);
388/** 384/**
389 * __blkg_prfill_rwstat - prfill helper for a blkg_rwstat 385 * __blkg_prfill_rwstat - prfill helper for a blkg_rwstat
390 * @sf: seq_file to print to 386 * @sf: seq_file to print to
391 * @pdata: policy private data of interest 387 * @pd: policy private data of interest
392 * @rwstat: rwstat to print 388 * @rwstat: rwstat to print
393 * 389 *
394 * Print @rwstat to @sf for the device assocaited with @pdata. 390 * Print @rwstat to @sf for the device assocaited with @pd.
395 */ 391 */
396u64 __blkg_prfill_rwstat(struct seq_file *sf, void *pdata, 392u64 __blkg_prfill_rwstat(struct seq_file *sf, struct blkg_policy_data *pd,
397 const struct blkg_rwstat *rwstat) 393 const struct blkg_rwstat *rwstat)
398{ 394{
399 static const char *rwstr[] = { 395 static const char *rwstr[] = {
@@ -402,7 +398,7 @@ u64 __blkg_prfill_rwstat(struct seq_file *sf, void *pdata,
402 [BLKG_RWSTAT_SYNC] = "Sync", 398 [BLKG_RWSTAT_SYNC] = "Sync",
403 [BLKG_RWSTAT_ASYNC] = "Async", 399 [BLKG_RWSTAT_ASYNC] = "Async",
404 }; 400 };
405 const char *dname = blkg_dev_name(pdata_to_blkg(pdata)); 401 const char *dname = blkg_dev_name(pd->blkg);
406 u64 v; 402 u64 v;
407 int i; 403 int i;
408 404
@@ -421,30 +417,31 @@ u64 __blkg_prfill_rwstat(struct seq_file *sf, void *pdata,
421/** 417/**
422 * blkg_prfill_stat - prfill callback for blkg_stat 418 * blkg_prfill_stat - prfill callback for blkg_stat
423 * @sf: seq_file to print to 419 * @sf: seq_file to print to
424 * @pdata: policy private data of interest 420 * @pd: policy private data of interest
425 * @off: offset to the blkg_stat in @pdata 421 * @off: offset to the blkg_stat in @pd
426 * 422 *
427 * prfill callback for printing a blkg_stat. 423 * prfill callback for printing a blkg_stat.
428 */ 424 */
429u64 blkg_prfill_stat(struct seq_file *sf, void *pdata, int off) 425u64 blkg_prfill_stat(struct seq_file *sf, struct blkg_policy_data *pd, int off)
430{ 426{
431 return __blkg_prfill_u64(sf, pdata, blkg_stat_read(pdata + off)); 427 return __blkg_prfill_u64(sf, pd, blkg_stat_read((void *)pd + off));
432} 428}
433EXPORT_SYMBOL_GPL(blkg_prfill_stat); 429EXPORT_SYMBOL_GPL(blkg_prfill_stat);
434 430
435/** 431/**
436 * blkg_prfill_rwstat - prfill callback for blkg_rwstat 432 * blkg_prfill_rwstat - prfill callback for blkg_rwstat
437 * @sf: seq_file to print to 433 * @sf: seq_file to print to
438 * @pdata: policy private data of interest 434 * @pd: policy private data of interest
439 * @off: offset to the blkg_rwstat in @pdata 435 * @off: offset to the blkg_rwstat in @pd
440 * 436 *
441 * prfill callback for printing a blkg_rwstat. 437 * prfill callback for printing a blkg_rwstat.
442 */ 438 */
443u64 blkg_prfill_rwstat(struct seq_file *sf, void *pdata, int off) 439u64 blkg_prfill_rwstat(struct seq_file *sf, struct blkg_policy_data *pd,
440 int off)
444{ 441{
445 struct blkg_rwstat rwstat = blkg_rwstat_read(pdata + off); 442 struct blkg_rwstat rwstat = blkg_rwstat_read((void *)pd + off);
446 443
447 return __blkg_prfill_rwstat(sf, pdata, &rwstat); 444 return __blkg_prfill_rwstat(sf, pd, &rwstat);
448} 445}
449EXPORT_SYMBOL_GPL(blkg_prfill_rwstat); 446EXPORT_SYMBOL_GPL(blkg_prfill_rwstat);
450 447
@@ -733,7 +730,7 @@ int blkcg_activate_policy(struct request_queue *q,
733 730
734 /* allocate policy_data for all existing blkgs */ 731 /* allocate policy_data for all existing blkgs */
735 while (cnt--) { 732 while (cnt--) {
736 pd = kzalloc_node(blkg_pd_size(pol), GFP_KERNEL, q->node); 733 pd = kzalloc_node(pol->pd_size, GFP_KERNEL, q->node);
737 if (!pd) { 734 if (!pd) {
738 ret = -ENOMEM; 735 ret = -ENOMEM;
739 goto out_free; 736 goto out_free;
@@ -832,6 +829,9 @@ int blkcg_policy_register(struct blkcg_policy *pol)
832{ 829{
833 int i, ret; 830 int i, ret;
834 831
832 if (WARN_ON(pol->pd_size < sizeof(struct blkg_policy_data)))
833 return -EINVAL;
834
835 mutex_lock(&blkcg_pol_mutex); 835 mutex_lock(&blkcg_pol_mutex);
836 836
837 /* find an empty slot */ 837 /* find an empty slot */