aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md
diff options
context:
space:
mode:
authorKent Overstreet <koverstreet@google.com>2013-05-29 00:53:19 -0400
committerKent Overstreet <koverstreet@google.com>2013-06-26 20:06:33 -0400
commitbbc77aa7fb72e616edcb1b165c293e47c6d4d0cf (patch)
treed69a958a3bc87f556b75a7330d9699f329d39013 /drivers/md
parent5c694129c8db6d89c9be109049a16510b2f70f6d (diff)
bcache: fix a spurious gcc complaint, use scnprintf
An old version of gcc was complaining about using a const int as the size of a stack allocated array. Which should be fine - but using ARRAY_SIZE() is better, anyways. Also, refactor the code to use scnprintf(). Signed-off-by: Kent Overstreet <koverstreet@google.com>
Diffstat (limited to 'drivers/md')
-rw-r--r--drivers/md/bcache/sysfs.c43
1 files changed, 22 insertions, 21 deletions
diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c
index 4d9cca47e4c6..29228b8a6ffe 100644
--- a/drivers/md/bcache/sysfs.c
+++ b/drivers/md/bcache/sysfs.c
@@ -665,12 +665,10 @@ SHOW(__bch_cache)
665 int cmp(const void *l, const void *r) 665 int cmp(const void *l, const void *r)
666 { return *((uint16_t *) r) - *((uint16_t *) l); } 666 { return *((uint16_t *) r) - *((uint16_t *) l); }
667 667
668 /* Number of quantiles we compute */
669 const unsigned nq = 31;
670
671 size_t n = ca->sb.nbuckets, i, unused, btree; 668 size_t n = ca->sb.nbuckets, i, unused, btree;
672 uint64_t sum = 0; 669 uint64_t sum = 0;
673 uint16_t q[nq], *p, *cached; 670 /* Compute 31 quantiles */
671 uint16_t q[31], *p, *cached;
674 ssize_t ret; 672 ssize_t ret;
675 673
676 cached = p = vmalloc(ca->sb.nbuckets * sizeof(uint16_t)); 674 cached = p = vmalloc(ca->sb.nbuckets * sizeof(uint16_t));
@@ -703,26 +701,29 @@ SHOW(__bch_cache)
703 if (n) 701 if (n)
704 do_div(sum, n); 702 do_div(sum, n);
705 703
706 for (i = 0; i < nq; i++) 704 for (i = 0; i < ARRAY_SIZE(q); i++)
707 q[i] = INITIAL_PRIO - cached[n * (i + 1) / (nq + 1)]; 705 q[i] = INITIAL_PRIO - cached[n * (i + 1) /
706 (ARRAY_SIZE(q) + 1)];
708 707
709 vfree(p); 708 vfree(p);
710 709
711 ret = snprintf(buf, PAGE_SIZE, 710 ret = scnprintf(buf, PAGE_SIZE,
712 "Unused: %zu%%\n" 711 "Unused: %zu%%\n"
713 "Metadata: %zu%%\n" 712 "Metadata: %zu%%\n"
714 "Average: %llu\n" 713 "Average: %llu\n"
715 "Sectors per Q: %zu\n" 714 "Sectors per Q: %zu\n"
716 "Quantiles: [", 715 "Quantiles: [",
717 unused * 100 / (size_t) ca->sb.nbuckets, 716 unused * 100 / (size_t) ca->sb.nbuckets,
718 btree * 100 / (size_t) ca->sb.nbuckets, sum, 717 btree * 100 / (size_t) ca->sb.nbuckets, sum,
719 n * ca->sb.bucket_size / (nq + 1)); 718 n * ca->sb.bucket_size / (ARRAY_SIZE(q) + 1));
720 719
721 for (i = 0; i < nq && ret < (ssize_t) PAGE_SIZE; i++) 720 for (i = 0; i < ARRAY_SIZE(q); i++)
722 ret += snprintf(buf + ret, PAGE_SIZE - ret, 721 ret += scnprintf(buf + ret, PAGE_SIZE - ret,
723 i < nq - 1 ? "%u " : "%u]\n", q[i]); 722 "%u ", q[i]);
724 723 ret--;
725 buf[PAGE_SIZE - 1] = '\0'; 724
725 ret += scnprintf(buf + ret, PAGE_SIZE - ret, "]\n");
726
726 return ret; 727 return ret;
727 } 728 }
728 729