summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2018-07-24 13:33:07 -0400
committerKent Overstreet <kent.overstreet@gmail.com>2018-08-01 14:35:33 -0400
commit478637ce4bfc36c9406650da4d1a1377d2ec76e4 (patch)
treeb3b6d9239a0dc719f6e038c2c2856908f9529a9a
parent1c3ebe8e0b64aad66268c39165fa3c911bcd981a (diff)
bcachefs: kill s_alloc, use bch_data_type
-rw-r--r--fs/bcachefs/btree_update_interior.c2
-rw-r--r--fs/bcachefs/buckets.c30
-rw-r--r--fs/bcachefs/buckets.h12
-rw-r--r--fs/bcachefs/buckets_types.h10
-rw-r--r--fs/bcachefs/chardev.c5
-rw-r--r--fs/bcachefs/sysfs.c55
6 files changed, 44 insertions, 70 deletions
diff --git a/fs/bcachefs/btree_update_interior.c b/fs/bcachefs/btree_update_interior.c
index eae0c0c53b50..74f603fa4eb4 100644
--- a/fs/bcachefs/btree_update_interior.c
+++ b/fs/bcachefs/btree_update_interior.c
@@ -183,7 +183,7 @@ found:
*/
replicas = bch2_extent_nr_dirty_ptrs(k);
if (replicas)
- stats->s[replicas - 1].data[S_META] -= c->opts.btree_node_size;
+ stats->s[replicas - 1].data[BCH_DATA_BTREE] -= c->opts.btree_node_size;
/*
* We're dropping @k from the btree, but it's still live until the
diff --git a/fs/bcachefs/buckets.c b/fs/bcachefs/buckets.c
index 059a5ce9937f..519498b00d01 100644
--- a/fs/bcachefs/buckets.c
+++ b/fs/bcachefs/buckets.c
@@ -81,16 +81,14 @@ static void bch2_fs_stats_verify(struct bch_fs *c)
{
struct bch_fs_usage stats =
__bch2_fs_usage_read(c);
- unsigned i;
+ unsigned i, j;
for (i = 0; i < ARRAY_SIZE(stats.s); i++) {
- if ((s64) stats.s[i].data[S_META] < 0)
- panic("replicas %u meta underflow: %lli\n",
- i + 1, stats.s[i].data[S_META]);
-
- if ((s64) stats.s[i].data[S_DIRTY] < 0)
- panic("replicas %u dirty underflow: %lli\n",
- i + 1, stats.s[i].data[S_DIRTY]);
+ for (j = 0; j < ARRAY_SIZE(stats.s[i].data); j++)
+ if ((s64) stats.s[i].data[j] < 0)
+ panic("replicas %u %s underflow: %lli\n",
+ i + 1, bch_data_types[j],
+ stats.s[i].data[j]);
if ((s64) stats.s[i].persistent_reserved < 0)
panic("replicas %u reserved underflow: %lli\n",
@@ -246,12 +244,16 @@ struct fs_usage_sum {
static inline struct fs_usage_sum __fs_usage_sum(struct bch_fs_usage stats)
{
struct fs_usage_sum sum = { 0 };
- unsigned i;
+ unsigned i, j;
for (i = 0; i < ARRAY_SIZE(stats.s); i++) {
- sum.data += (stats.s[i].data[S_META] +
- stats.s[i].data[S_DIRTY]) * (i + 1);
- sum.reserved += stats.s[i].persistent_reserved * (i + 1);
+ u64 a = 0;
+
+ for (j = 0; j < ARRAY_SIZE(stats.s[i].data); j++)
+ a += stats.s[i].data[j];
+
+ sum.data += a * (i + 1);
+ sum.reserved += stats.s[i].persistent_reserved * (i + 1);
}
sum.reserved += stats.online_reserved;
@@ -637,8 +639,6 @@ void bch2_mark_key(struct bch_fs *c, struct bkey_s_c k,
struct bkey_s_c_extent e = bkey_s_c_to_extent(k);
const struct bch_extent_ptr *ptr;
struct bch_extent_crc_unpacked crc;
- enum s_alloc type = data_type == BCH_DATA_USER
- ? S_DIRTY : S_META;
unsigned replicas = 0;
BUG_ON(!sectors);
@@ -651,7 +651,7 @@ void bch2_mark_key(struct bch_fs *c, struct bkey_s_c k,
if (replicas) {
BUG_ON(replicas - 1 > ARRAY_SIZE(stats->s));
- stats->s[replicas - 1].data[type] += sectors;
+ stats->s[replicas - 1].data[data_type] += sectors;
}
break;
}
diff --git a/fs/bcachefs/buckets.h b/fs/bcachefs/buckets.h
index 27eb19de2736..4116cd5f9e26 100644
--- a/fs/bcachefs/buckets.h
+++ b/fs/bcachefs/buckets.h
@@ -167,18 +167,6 @@ static inline u64 dev_buckets_free(struct bch_fs *c, struct bch_dev *ca)
/* Filesystem usage: */
-static inline enum bch_data_type s_alloc_to_data_type(enum s_alloc s)
-{
- switch (s) {
- case S_META:
- return BCH_DATA_BTREE;
- case S_DIRTY:
- return BCH_DATA_USER;
- default:
- BUG();
- }
-}
-
struct bch_fs_usage __bch2_fs_usage_read(struct bch_fs *);
struct bch_fs_usage bch2_fs_usage_read(struct bch_fs *);
void bch2_fs_usage_apply(struct bch_fs *, struct bch_fs_usage *,
diff --git a/fs/bcachefs/buckets_types.h b/fs/bcachefs/buckets_types.h
index a0b7ef3841a0..2f23d02b9e22 100644
--- a/fs/bcachefs/buckets_types.h
+++ b/fs/bcachefs/buckets_types.h
@@ -1,6 +1,7 @@
#ifndef _BUCKETS_TYPES_H
#define _BUCKETS_TYPES_H
+#include "bcachefs_format.h"
#include "util.h"
#define BUCKET_JOURNAL_SEQ_BITS 16
@@ -58,13 +59,6 @@ struct bch_dev_usage {
u64 sectors_fragmented;
};
-/* kill, switch to bch_data_type? */
-enum s_alloc {
- S_META,
- S_DIRTY,
- S_ALLOC_NR,
-};
-
struct bch_fs_usage {
/* all fields are in units of 512 byte sectors: */
/* _uncompressed_ sectors: */
@@ -72,7 +66,7 @@ struct bch_fs_usage {
u64 available_cache;
struct {
- u64 data[S_ALLOC_NR];
+ u64 data[BCH_DATA_NR];
u64 persistent_reserved;
} s[BCH_REPLICAS_MAX];
};
diff --git a/fs/bcachefs/chardev.c b/fs/bcachefs/chardev.c
index 5593b9a1de27..2182ae15f01f 100644
--- a/fs/bcachefs/chardev.c
+++ b/fs/bcachefs/chardev.c
@@ -405,9 +405,8 @@ static long bch2_ioctl_usage(struct bch_fs *c,
dst.persistent_reserved[i] =
src.s[i].persistent_reserved;
- for (j = 0; j < S_ALLOC_NR; j++)
- dst.sectors[s_alloc_to_data_type(j)][i] =
- src.s[i].data[j];
+ for (j = 0; j < BCH_DATA_NR; j++)
+ dst.sectors[j][i] = src.s[i].data[j];
}
ret = copy_to_user(&user_arg->fs, &dst, sizeof(dst));
diff --git a/fs/bcachefs/sysfs.c b/fs/bcachefs/sysfs.c
index 4987ee76a08c..85e885638a71 100644
--- a/fs/bcachefs/sysfs.c
+++ b/fs/bcachefs/sysfs.c
@@ -229,41 +229,34 @@ static size_t bch2_btree_cache_size(struct bch_fs *c)
static ssize_t show_fs_alloc_debug(struct bch_fs *c, char *buf)
{
+ char *out = buf, *end = buf + PAGE_SIZE;
struct bch_fs_usage stats = bch2_fs_usage_read(c);
+ unsigned replicas, type;
+
+ out += scnprintf(out, end - out,
+ "capacity:\t\t%llu\n",
+ c->capacity);
+
+ for (replicas = 0; replicas < ARRAY_SIZE(stats.s); replicas++) {
+ out += scnprintf(out, end - out,
+ "%u replicas:\n",
+ replicas + 1);
+
+ for (type = BCH_DATA_SB; type < BCH_DATA_NR; type++)
+ out += scnprintf(out, end - out,
+ "\t%s:\t\t%llu\n",
+ bch2_data_types[type],
+ stats.s[replicas].data[type]);
+ out += scnprintf(out, end - out,
+ "\treserved:\t%llu\n",
+ stats.s[replicas].persistent_reserved);
+ }
- return scnprintf(buf, PAGE_SIZE,
- "capacity:\t\t%llu\n"
- "1 replicas:\n"
- "\tmeta:\t\t%llu\n"
- "\tdirty:\t\t%llu\n"
- "\treserved:\t%llu\n"
- "2 replicas:\n"
- "\tmeta:\t\t%llu\n"
- "\tdirty:\t\t%llu\n"
- "\treserved:\t%llu\n"
- "3 replicas:\n"
- "\tmeta:\t\t%llu\n"
- "\tdirty:\t\t%llu\n"
- "\treserved:\t%llu\n"
- "4 replicas:\n"
- "\tmeta:\t\t%llu\n"
- "\tdirty:\t\t%llu\n"
- "\treserved:\t%llu\n"
+ out += scnprintf(out, end - out,
"online reserved:\t%llu\n",
- c->capacity,
- stats.s[0].data[S_META],
- stats.s[0].data[S_DIRTY],
- stats.s[0].persistent_reserved,
- stats.s[1].data[S_META],
- stats.s[1].data[S_DIRTY],
- stats.s[1].persistent_reserved,
- stats.s[2].data[S_META],
- stats.s[2].data[S_DIRTY],
- stats.s[2].persistent_reserved,
- stats.s[3].data[S_META],
- stats.s[3].data[S_DIRTY],
- stats.s[3].persistent_reserved,
stats.online_reserved);
+
+ return out - buf;
}
static ssize_t bch2_compression_stats(struct bch_fs *c, char *buf)