Commit 2436cb9f authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Use x-macros for more enums

This patch standardizes all the enums that have associated string tables
(probably more enums should have string tables).
Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 41f8b09e
...@@ -720,13 +720,13 @@ static size_t find_reclaimable_buckets(struct bch_fs *c, struct bch_dev *ca) ...@@ -720,13 +720,13 @@ static size_t find_reclaimable_buckets(struct bch_fs *c, struct bch_dev *ca)
ca->inc_gen_needs_gc = 0; ca->inc_gen_needs_gc = 0;
switch (ca->mi.replacement) { switch (ca->mi.replacement) {
case CACHE_REPLACEMENT_LRU: case BCH_CACHE_REPLACEMENT_lru:
find_reclaimable_buckets_lru(c, ca); find_reclaimable_buckets_lru(c, ca);
break; break;
case CACHE_REPLACEMENT_FIFO: case BCH_CACHE_REPLACEMENT_fifo:
find_reclaimable_buckets_fifo(c, ca); find_reclaimable_buckets_fifo(c, ca);
break; break;
case CACHE_REPLACEMENT_RANDOM: case BCH_CACHE_REPLACEMENT_random:
find_reclaimable_buckets_random(c, ca); find_reclaimable_buckets_random(c, ca);
break; break;
} }
...@@ -1037,7 +1037,7 @@ static int discard_invalidated_buckets(struct bch_fs *c, struct bch_dev *ca) ...@@ -1037,7 +1037,7 @@ static int discard_invalidated_buckets(struct bch_fs *c, struct bch_dev *ca)
static inline bool allocator_thread_running(struct bch_dev *ca) static inline bool allocator_thread_running(struct bch_dev *ca)
{ {
return ca->mi.state == BCH_MEMBER_STATE_RW && return ca->mi.state == BCH_MEMBER_STATE_rw &&
test_bit(BCH_FS_ALLOCATOR_RUNNING, &ca->fs->flags); test_bit(BCH_FS_ALLOCATOR_RUNNING, &ca->fs->flags);
} }
......
...@@ -991,19 +991,29 @@ LE64_BITMASK(BCH_MEMBER_NR_READ_ERRORS, struct bch_member, flags[1], 0, 20); ...@@ -991,19 +991,29 @@ LE64_BITMASK(BCH_MEMBER_NR_READ_ERRORS, struct bch_member, flags[1], 0, 20);
LE64_BITMASK(BCH_MEMBER_NR_WRITE_ERRORS,struct bch_member, flags[1], 20, 40); LE64_BITMASK(BCH_MEMBER_NR_WRITE_ERRORS,struct bch_member, flags[1], 20, 40);
#endif #endif
#define BCH_MEMBER_STATES() \
x(rw, 0) \
x(ro, 1) \
x(failed, 2) \
x(spare, 3)
enum bch_member_state { enum bch_member_state {
BCH_MEMBER_STATE_RW = 0, #define x(t, n) BCH_MEMBER_STATE_##t = n,
BCH_MEMBER_STATE_RO = 1, BCH_MEMBER_STATES()
BCH_MEMBER_STATE_FAILED = 2, #undef x
BCH_MEMBER_STATE_SPARE = 3, BCH_MEMBER_STATE_NR
BCH_MEMBER_STATE_NR = 4,
}; };
enum cache_replacement { #define BCH_CACHE_REPLACEMENT_POLICIES() \
CACHE_REPLACEMENT_LRU = 0, x(lru, 0) \
CACHE_REPLACEMENT_FIFO = 1, x(fifo, 1) \
CACHE_REPLACEMENT_RANDOM = 2, x(random, 2)
CACHE_REPLACEMENT_NR = 3,
enum bch_cache_replacement_policies {
#define x(t, n) BCH_CACHE_REPLACEMENT_##t = n,
BCH_CACHE_REPLACEMENT_POLICIES()
#undef x
BCH_CACHE_REPLACEMENT_NR
}; };
struct bch_sb_field_members { struct bch_sb_field_members {
...@@ -1405,11 +1415,16 @@ enum bch_sb_compat { ...@@ -1405,11 +1415,16 @@ enum bch_sb_compat {
#define BCH_BKEY_PTRS_MAX 16U #define BCH_BKEY_PTRS_MAX 16U
#define BCH_ERROR_ACTIONS() \
x(continue, 0) \
x(ro, 1) \
x(panic, 2)
enum bch_error_actions { enum bch_error_actions {
BCH_ON_ERROR_CONTINUE = 0, #define x(t, n) BCH_ON_ERROR_##t = n,
BCH_ON_ERROR_RO = 1, BCH_ERROR_ACTIONS()
BCH_ON_ERROR_PANIC = 2, #undef x
BCH_NR_ERROR_ACTIONS = 3, BCH_ON_ERROR_NR
}; };
enum bch_str_hash_type { enum bch_str_hash_type {
...@@ -1420,11 +1435,16 @@ enum bch_str_hash_type { ...@@ -1420,11 +1435,16 @@ enum bch_str_hash_type {
BCH_STR_HASH_NR = 4, BCH_STR_HASH_NR = 4,
}; };
#define BCH_STR_HASH_OPTS() \
x(crc32c, 0) \
x(crc64, 1) \
x(siphash, 2)
enum bch_str_hash_opts { enum bch_str_hash_opts {
BCH_STR_HASH_OPT_CRC32C = 0, #define x(t, n) BCH_STR_HASH_OPT_##t = n,
BCH_STR_HASH_OPT_CRC64 = 1, BCH_STR_HASH_OPTS()
BCH_STR_HASH_OPT_SIPHASH = 2, #undef x
BCH_STR_HASH_OPT_NR = 3, BCH_STR_HASH_OPT_NR
}; };
enum bch_csum_type { enum bch_csum_type {
...@@ -1459,11 +1479,16 @@ static inline _Bool bch2_csum_type_is_encryption(enum bch_csum_type type) ...@@ -1459,11 +1479,16 @@ static inline _Bool bch2_csum_type_is_encryption(enum bch_csum_type type)
} }
} }
#define BCH_CSUM_OPTS() \
x(none, 0) \
x(crc32c, 1) \
x(crc64, 2)
enum bch_csum_opts { enum bch_csum_opts {
BCH_CSUM_OPT_NONE = 0, #define x(t, n) BCH_CSUM_OPT_##t = n,
BCH_CSUM_OPT_CRC32C = 1, BCH_CSUM_OPTS()
BCH_CSUM_OPT_CRC64 = 2, #undef x
BCH_CSUM_OPT_NR = 3, BCH_CSUM_OPT_NR
}; };
#define BCH_COMPRESSION_TYPES() \ #define BCH_COMPRESSION_TYPES() \
...@@ -1475,7 +1500,7 @@ enum bch_csum_opts { ...@@ -1475,7 +1500,7 @@ enum bch_csum_opts {
x(incompressible, 5) x(incompressible, 5)
enum bch_compression_type { enum bch_compression_type {
#define x(t, n) BCH_COMPRESSION_TYPE_##t, #define x(t, n) BCH_COMPRESSION_TYPE_##t = n,
BCH_COMPRESSION_TYPES() BCH_COMPRESSION_TYPES()
#undef x #undef x
BCH_COMPRESSION_TYPE_NR BCH_COMPRESSION_TYPE_NR
...@@ -1488,7 +1513,7 @@ enum bch_compression_type { ...@@ -1488,7 +1513,7 @@ enum bch_compression_type {
x(zstd, 3) x(zstd, 3)
enum bch_compression_opts { enum bch_compression_opts {
#define x(t, n) BCH_COMPRESSION_OPT_##t, #define x(t, n) BCH_COMPRESSION_OPT_##t = n,
BCH_COMPRESSION_OPTS() BCH_COMPRESSION_OPTS()
#undef x #undef x
BCH_COMPRESSION_OPT_NR BCH_COMPRESSION_OPT_NR
......
...@@ -954,7 +954,7 @@ int bch2_btree_node_read_done(struct bch_fs *c, struct bch_dev *ca, ...@@ -954,7 +954,7 @@ int bch2_btree_node_read_done(struct bch_fs *c, struct bch_dev *ca,
bkey_for_each_ptr(bch2_bkey_ptrs(bkey_i_to_s(&b->key)), ptr) { bkey_for_each_ptr(bch2_bkey_ptrs(bkey_i_to_s(&b->key)), ptr) {
struct bch_dev *ca = bch_dev_bkey_exists(c, ptr->dev); struct bch_dev *ca = bch_dev_bkey_exists(c, ptr->dev);
if (ca->mi.state != BCH_MEMBER_STATE_RW) if (ca->mi.state != BCH_MEMBER_STATE_rw)
set_btree_node_need_rewrite(b); set_btree_node_need_rewrite(b);
} }
out: out:
......
...@@ -77,11 +77,11 @@ static inline enum bch_csum_type bch2_csum_opt_to_type(enum bch_csum_opts type, ...@@ -77,11 +77,11 @@ static inline enum bch_csum_type bch2_csum_opt_to_type(enum bch_csum_opts type,
bool data) bool data)
{ {
switch (type) { switch (type) {
case BCH_CSUM_OPT_NONE: case BCH_CSUM_OPT_none:
return BCH_CSUM_NONE; return BCH_CSUM_NONE;
case BCH_CSUM_OPT_CRC32C: case BCH_CSUM_OPT_crc32c:
return data ? BCH_CSUM_CRC32C : BCH_CSUM_CRC32C_NONZERO; return data ? BCH_CSUM_CRC32C : BCH_CSUM_CRC32C_NONZERO;
case BCH_CSUM_OPT_CRC64: case BCH_CSUM_OPT_crc64:
return data ? BCH_CSUM_CRC64 : BCH_CSUM_CRC64_NONZERO; return data ? BCH_CSUM_CRC64 : BCH_CSUM_CRC64_NONZERO;
default: default:
BUG(); BUG();
......
...@@ -11,13 +11,13 @@ bool bch2_inconsistent_error(struct bch_fs *c) ...@@ -11,13 +11,13 @@ bool bch2_inconsistent_error(struct bch_fs *c)
set_bit(BCH_FS_ERROR, &c->flags); set_bit(BCH_FS_ERROR, &c->flags);
switch (c->opts.errors) { switch (c->opts.errors) {
case BCH_ON_ERROR_CONTINUE: case BCH_ON_ERROR_continue:
return false; return false;
case BCH_ON_ERROR_RO: case BCH_ON_ERROR_ro:
if (bch2_fs_emergency_read_only(c)) if (bch2_fs_emergency_read_only(c))
bch_err(c, "emergency read only"); bch_err(c, "emergency read only");
return true; return true;
case BCH_ON_ERROR_PANIC: case BCH_ON_ERROR_panic:
panic(bch2_fmt(c, "panic after error")); panic(bch2_fmt(c, "panic after error"));
return true; return true;
default: default:
...@@ -38,10 +38,10 @@ void bch2_io_error_work(struct work_struct *work) ...@@ -38,10 +38,10 @@ void bch2_io_error_work(struct work_struct *work)
bool dev; bool dev;
down_write(&c->state_lock); down_write(&c->state_lock);
dev = bch2_dev_state_allowed(c, ca, BCH_MEMBER_STATE_RO, dev = bch2_dev_state_allowed(c, ca, BCH_MEMBER_STATE_ro,
BCH_FORCE_IF_DEGRADED); BCH_FORCE_IF_DEGRADED);
if (dev if (dev
? __bch2_dev_set_state(c, ca, BCH_MEMBER_STATE_RO, ? __bch2_dev_set_state(c, ca, BCH_MEMBER_STATE_ro,
BCH_FORCE_IF_DEGRADED) BCH_FORCE_IF_DEGRADED)
: bch2_fs_emergency_read_only(c)) : bch2_fs_emergency_read_only(c))
bch_err(ca, bch_err(ca,
......
...@@ -724,7 +724,7 @@ static unsigned bch2_extent_ptr_durability(struct bch_fs *c, ...@@ -724,7 +724,7 @@ static unsigned bch2_extent_ptr_durability(struct bch_fs *c,
ca = bch_dev_bkey_exists(c, p.ptr.dev); ca = bch_dev_bkey_exists(c, p.ptr.dev);
if (ca->mi.state != BCH_MEMBER_STATE_FAILED) if (ca->mi.state != BCH_MEMBER_STATE_failed)
durability = max_t(unsigned, durability, ca->mi.durability); durability = max_t(unsigned, durability, ca->mi.durability);
if (p.has_ec) if (p.has_ec)
......
...@@ -870,8 +870,8 @@ int bch2_journal_read(struct bch_fs *c, struct list_head *list, ...@@ -870,8 +870,8 @@ int bch2_journal_read(struct bch_fs *c, struct list_head *list,
!(bch2_dev_has_data(c, ca) & (1 << BCH_DATA_journal))) !(bch2_dev_has_data(c, ca) & (1 << BCH_DATA_journal)))
continue; continue;
if ((ca->mi.state == BCH_MEMBER_STATE_RW || if ((ca->mi.state == BCH_MEMBER_STATE_rw ||
ca->mi.state == BCH_MEMBER_STATE_RO) && ca->mi.state == BCH_MEMBER_STATE_ro) &&
percpu_ref_tryget(&ca->io_ref)) percpu_ref_tryget(&ca->io_ref))
closure_call(&ca->journal.read, closure_call(&ca->journal.read,
bch2_journal_read_device, bch2_journal_read_device,
...@@ -1064,7 +1064,7 @@ static void __journal_write_alloc(struct journal *j, ...@@ -1064,7 +1064,7 @@ static void __journal_write_alloc(struct journal *j,
* it: * it:
*/ */
if (!ca->mi.durability || if (!ca->mi.durability ||
ca->mi.state != BCH_MEMBER_STATE_RW || ca->mi.state != BCH_MEMBER_STATE_rw ||
!ja->nr || !ja->nr ||
bch2_bkey_has_device(bkey_i_to_s_c(&w->key), bch2_bkey_has_device(bkey_i_to_s_c(&w->key),
ca->dev_idx) || ca->dev_idx) ||
......
...@@ -9,86 +9,59 @@ ...@@ -9,86 +9,59 @@
#include "super-io.h" #include "super-io.h"
#include "util.h" #include "util.h"
#define x(t, n) #t,
const char * const bch2_error_actions[] = { const char * const bch2_error_actions[] = {
"continue", BCH_ERROR_ACTIONS()
"remount-ro",
"panic",
NULL NULL
}; };
const char * const bch2_sb_features[] = { const char * const bch2_sb_features[] = {
#define x(f, n) #f,
BCH_SB_FEATURES() BCH_SB_FEATURES()
#undef x
NULL NULL
}; };
const char * const bch2_sb_compat[] = { const char * const bch2_sb_compat[] = {
#define x(f, n) #f,
BCH_SB_COMPAT() BCH_SB_COMPAT()
#undef x
NULL NULL
}; };
const char * const bch2_btree_ids[] = { const char * const bch2_btree_ids[] = {
#define x(name, ...) #name,
BCH_BTREE_IDS() BCH_BTREE_IDS()
#undef x
NULL NULL
}; };
const char * const bch2_csum_opts[] = { const char * const bch2_csum_opts[] = {
"none", BCH_CSUM_OPTS()
"crc32c",
"crc64",
NULL NULL
}; };
const char * const bch2_compression_opts[] = { const char * const bch2_compression_opts[] = {
#define x(t, n) #t,
BCH_COMPRESSION_OPTS() BCH_COMPRESSION_OPTS()
#undef x
NULL NULL
}; };
const char * const bch2_str_hash_types[] = { const char * const bch2_str_hash_types[] = {
"crc32c", BCH_STR_HASH_OPTS()
"crc64",
"siphash",
NULL NULL
}; };
const char * const bch2_data_types[] = { const char * const bch2_data_types[] = {
#define x(t, n) #t,
BCH_DATA_TYPES() BCH_DATA_TYPES()
#undef x
NULL NULL
}; };
const char * const bch2_cache_replacement_policies[] = { const char * const bch2_cache_replacement_policies[] = {
"lru", BCH_CACHE_REPLACEMENT_POLICIES()
"fifo",
"random",
NULL NULL
}; };
/* Default is -1; we skip past it for struct cached_dev's cache mode */ const char * const bch2_member_states[] = {
const char * const bch2_cache_modes[] = { BCH_MEMBER_STATES()
"default",
"writethrough",
"writeback",
"writearound",
"none",
NULL NULL
}; };
const char * const bch2_dev_state[] = { #undef x
"readwrite",
"readonly",
"failed",
"spare",
NULL
};
void bch2_opts_apply(struct bch_opts *dst, struct bch_opts src) void bch2_opts_apply(struct bch_opts *dst, struct bch_opts src)
{ {
......
...@@ -17,8 +17,7 @@ extern const char * const bch2_compression_opts[]; ...@@ -17,8 +17,7 @@ extern const char * const bch2_compression_opts[];
extern const char * const bch2_str_hash_types[]; extern const char * const bch2_str_hash_types[];
extern const char * const bch2_data_types[]; extern const char * const bch2_data_types[];
extern const char * const bch2_cache_replacement_policies[]; extern const char * const bch2_cache_replacement_policies[];
extern const char * const bch2_cache_modes[]; extern const char * const bch2_member_states[];
extern const char * const bch2_dev_state[];
/* /*
* Mount options; we also store defaults in the superblock. * Mount options; we also store defaults in the superblock.
...@@ -91,7 +90,7 @@ enum opt_type { ...@@ -91,7 +90,7 @@ enum opt_type {
x(errors, u8, \ x(errors, u8, \
OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \ OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
OPT_STR(bch2_error_actions), \ OPT_STR(bch2_error_actions), \
BCH_SB_ERROR_ACTION, BCH_ON_ERROR_RO, \ BCH_SB_ERROR_ACTION, BCH_ON_ERROR_ro, \
NULL, "Action to take on filesystem error") \ NULL, "Action to take on filesystem error") \
x(metadata_replicas, u8, \ x(metadata_replicas, u8, \
OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \ OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
...@@ -116,12 +115,12 @@ enum opt_type { ...@@ -116,12 +115,12 @@ enum opt_type {
x(metadata_checksum, u8, \ x(metadata_checksum, u8, \
OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \ OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
OPT_STR(bch2_csum_opts), \ OPT_STR(bch2_csum_opts), \
BCH_SB_META_CSUM_TYPE, BCH_CSUM_OPT_CRC32C, \ BCH_SB_META_CSUM_TYPE, BCH_CSUM_OPT_crc32c, \
NULL, NULL) \ NULL, NULL) \
x(data_checksum, u8, \ x(data_checksum, u8, \
OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \ OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
OPT_STR(bch2_csum_opts), \ OPT_STR(bch2_csum_opts), \
BCH_SB_DATA_CSUM_TYPE, BCH_CSUM_OPT_CRC32C, \ BCH_SB_DATA_CSUM_TYPE, BCH_CSUM_OPT_crc32c, \
NULL, NULL) \ NULL, NULL) \
x(compression, u8, \ x(compression, u8, \
OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \ OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
...@@ -136,7 +135,7 @@ enum opt_type { ...@@ -136,7 +135,7 @@ enum opt_type {
x(str_hash, u8, \ x(str_hash, u8, \
OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \ OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
OPT_STR(bch2_str_hash_types), \ OPT_STR(bch2_str_hash_types), \
BCH_SB_STR_HASH_TYPE, BCH_STR_HASH_OPT_SIPHASH, \ BCH_SB_STR_HASH_TYPE, BCH_STR_HASH_OPT_siphash, \
NULL, "Hash function for directory entries and xattrs")\ NULL, "Hash function for directory entries and xattrs")\
x(metadata_target, u16, \ x(metadata_target, u16, \
OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \ OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
......
...@@ -982,7 +982,7 @@ bool bch2_have_enough_devs(struct bch_fs *c, struct bch_devs_mask devs, ...@@ -982,7 +982,7 @@ bool bch2_have_enough_devs(struct bch_fs *c, struct bch_devs_mask devs,
struct bch_dev *ca = bch_dev_bkey_exists(c, e->devs[i]); struct bch_dev *ca = bch_dev_bkey_exists(c, e->devs[i]);
nr_online += test_bit(e->devs[i], devs.d); nr_online += test_bit(e->devs[i], devs.d);
nr_failed += ca->mi.state == BCH_MEMBER_STATE_FAILED; nr_failed += ca->mi.state == BCH_MEMBER_STATE_failed;
} }
if (nr_failed == e->nr_devs) if (nr_failed == e->nr_devs)
......
...@@ -18,11 +18,11 @@ static inline enum bch_str_hash_type ...@@ -18,11 +18,11 @@ static inline enum bch_str_hash_type
bch2_str_hash_opt_to_type(struct bch_fs *c, enum bch_str_hash_opts opt) bch2_str_hash_opt_to_type(struct bch_fs *c, enum bch_str_hash_opts opt)
{ {
switch (opt) { switch (opt) {
case BCH_STR_HASH_OPT_CRC32C: case BCH_STR_HASH_OPT_crc32c:
return BCH_STR_HASH_CRC32C; return BCH_STR_HASH_CRC32C;
case BCH_STR_HASH_OPT_CRC64: case BCH_STR_HASH_OPT_crc64:
return BCH_STR_HASH_CRC64; return BCH_STR_HASH_CRC64;
case BCH_STR_HASH_OPT_SIPHASH: case BCH_STR_HASH_OPT_siphash:
return c->sb.features & (1ULL << BCH_FEATURE_new_siphash) return c->sb.features & (1ULL << BCH_FEATURE_new_siphash)
? BCH_STR_HASH_SIPHASH ? BCH_STR_HASH_SIPHASH
: BCH_STR_HASH_SIPHASH_OLD; : BCH_STR_HASH_SIPHASH_OLD;
......
...@@ -1171,7 +1171,7 @@ static int bch2_dev_alloc(struct bch_fs *c, unsigned dev_idx) ...@@ -1171,7 +1171,7 @@ static int bch2_dev_alloc(struct bch_fs *c, unsigned dev_idx)
ca->fs = c; ca->fs = c;
if (ca->mi.state == BCH_MEMBER_STATE_RW && if (ca->mi.state == BCH_MEMBER_STATE_rw &&
bch2_dev_allocator_start(ca)) { bch2_dev_allocator_start(ca)) {
bch2_dev_free(ca); bch2_dev_free(ca);
goto err; goto err;
...@@ -1276,16 +1276,16 @@ bool bch2_dev_state_allowed(struct bch_fs *c, struct bch_dev *ca, ...@@ -1276,16 +1276,16 @@ bool bch2_dev_state_allowed(struct bch_fs *c, struct bch_dev *ca,
lockdep_assert_held(&c->state_lock); lockdep_assert_held(&c->state_lock);
switch (new_state) { switch (new_state) {
case BCH_MEMBER_STATE_RW: case BCH_MEMBER_STATE_rw:
return true; return true;
case BCH_MEMBER_STATE_RO: case BCH_MEMBER_STATE_ro:
if (ca->mi.state != BCH_MEMBER_STATE_RW) if (ca->mi.state != BCH_MEMBER_STATE_rw)
return true; return true;
/* do we have enough devices to write to? */ /* do we have enough devices to write to? */
for_each_member_device(ca2, c, i) for_each_member_device(ca2, c, i)
if (ca2 != ca) if (ca2 != ca)
nr_rw += ca2->mi.state == BCH_MEMBER_STATE_RW; nr_rw += ca2->mi.state == BCH_MEMBER_STATE_rw;
required = max(!(flags & BCH_FORCE_IF_METADATA_DEGRADED) required = max(!(flags & BCH_FORCE_IF_METADATA_DEGRADED)
? c->opts.metadata_replicas ? c->opts.metadata_replicas
...@@ -1295,10 +1295,10 @@ bool bch2_dev_state_allowed(struct bch_fs *c, struct bch_dev *ca, ...@@ -1295,10 +1295,10 @@ bool bch2_dev_state_allowed(struct bch_fs *c, struct bch_dev *ca,
: c->opts.data_replicas_required); : c->opts.data_replicas_required);
return nr_rw >= required; return nr_rw >= required;
case BCH_MEMBER_STATE_FAILED: case BCH_MEMBER_STATE_failed:
case BCH_MEMBER_STATE_SPARE: case BCH_MEMBER_STATE_spare:
if (ca->mi.state != BCH_MEMBER_STATE_RW && if (ca->mi.state != BCH_MEMBER_STATE_rw &&
ca->mi.state != BCH_MEMBER_STATE_RO) ca->mi.state != BCH_MEMBER_STATE_ro)
return true; return true;
/* do we have enough devices to read from? */ /* do we have enough devices to read from? */
...@@ -1335,8 +1335,8 @@ static bool bch2_fs_may_start(struct bch_fs *c) ...@@ -1335,8 +1335,8 @@ static bool bch2_fs_may_start(struct bch_fs *c)
ca = bch_dev_locked(c, i); ca = bch_dev_locked(c, i);
if (!bch2_dev_is_online(ca) && if (!bch2_dev_is_online(ca) &&
(ca->mi.state == BCH_MEMBER_STATE_RW || (ca->mi.state == BCH_MEMBER_STATE_rw ||
ca->mi.state == BCH_MEMBER_STATE_RO)) { ca->mi.state == BCH_MEMBER_STATE_ro)) {
mutex_unlock(&c->sb_lock); mutex_unlock(&c->sb_lock);
return false; return false;
} }
...@@ -1369,7 +1369,7 @@ static const char *__bch2_dev_read_write(struct bch_fs *c, struct bch_dev *ca) ...@@ -1369,7 +1369,7 @@ static const char *__bch2_dev_read_write(struct bch_fs *c, struct bch_dev *ca)
{ {
lockdep_assert_held(&c->state_lock); lockdep_assert_held(&c->state_lock);
BUG_ON(ca->mi.state != BCH_MEMBER_STATE_RW); BUG_ON(ca->mi.state != BCH_MEMBER_STATE_rw);
bch2_dev_allocator_add(c, ca); bch2_dev_allocator_add(c, ca);
bch2_recalc_capacity(c); bch2_recalc_capacity(c);
...@@ -1392,10 +1392,10 @@ int __bch2_dev_set_state(struct bch_fs *c, struct bch_dev *ca, ...@@ -1392,10 +1392,10 @@ int __bch2_dev_set_state(struct bch_fs *c, struct bch_dev *ca,
if (!bch2_dev_state_allowed(c, ca, new_state, flags)) if (!bch2_dev_state_allowed(c, ca, new_state, flags))
return -EINVAL; return -EINVAL;
if (new_state != BCH_MEMBER_STATE_RW) if (new_state != BCH_MEMBER_STATE_rw)
__bch2_dev_read_only(c, ca); __bch2_dev_read_only(c, ca);
bch_notice(ca, "%s", bch2_dev_state[new_state]); bch_notice(ca, "%s", bch2_member_states[new_state]);
mutex_lock(&c->sb_lock); mutex_lock(&c->sb_lock);
mi = bch2_sb_get_members(c->disk_sb.sb); mi = bch2_sb_get_members(c->disk_sb.sb);
...@@ -1403,7 +1403,7 @@ int __bch2_dev_set_state(struct bch_fs *c, struct bch_dev *ca, ...@@ -1403,7 +1403,7 @@ int __bch2_dev_set_state(struct bch_fs *c, struct bch_dev *ca,
bch2_write_super(c); bch2_write_super(c);
mutex_unlock(&c->sb_lock); mutex_unlock(&c->sb_lock);
if (new_state == BCH_MEMBER_STATE_RW && if (new_state == BCH_MEMBER_STATE_rw &&
__bch2_dev_read_write(c, ca)) __bch2_dev_read_write(c, ca))
ret = -ENOMEM; ret = -ENOMEM;
...@@ -1465,7 +1465,7 @@ int bch2_dev_remove(struct bch_fs *c, struct bch_dev *ca, int flags) ...@@ -1465,7 +1465,7 @@ int bch2_dev_remove(struct bch_fs *c, struct bch_dev *ca, int flags)
*/ */
percpu_ref_put(&ca->ref); percpu_ref_put(&ca->ref);
if (!bch2_dev_state_allowed(c, ca, BCH_MEMBER_STATE_FAILED, flags)) { if (!bch2_dev_state_allowed(c, ca, BCH_MEMBER_STATE_failed, flags)) {
bch_err(ca, "Cannot remove without losing data"); bch_err(ca, "Cannot remove without losing data");
goto err; goto err;
} }
...@@ -1549,7 +1549,7 @@ int bch2_dev_remove(struct bch_fs *c, struct bch_dev *ca, int flags) ...@@ -1549,7 +1549,7 @@ int bch2_dev_remove(struct bch_fs *c, struct bch_dev *ca, int flags)
bch2_dev_usage_journal_reserve(c); bch2_dev_usage_journal_reserve(c);
return 0; return 0;
err: err:
if (ca->mi.state == BCH_MEMBER_STATE_RW && if (ca->mi.state == BCH_MEMBER_STATE_rw &&
!percpu_ref_is_zero(&ca->io_ref)) !percpu_ref_is_zero(&ca->io_ref))
__bch2_dev_read_write(c, ca); __bch2_dev_read_write(c, ca);
up_write(&c->state_lock); up_write(&c->state_lock);
...@@ -1673,7 +1673,7 @@ int bch2_dev_add(struct bch_fs *c, const char *path) ...@@ -1673,7 +1673,7 @@ int bch2_dev_add(struct bch_fs *c, const char *path)
if (ret) if (ret)
goto err_late; goto err_late;
if (ca->mi.state == BCH_MEMBER_STATE_RW) { if (ca->mi.state == BCH_MEMBER_STATE_rw) {
err = __bch2_dev_read_write(c, ca); err = __bch2_dev_read_write(c, ca);
if (err) if (err)
goto err_late; goto err_late;
...@@ -1734,7 +1734,7 @@ int bch2_dev_online(struct bch_fs *c, const char *path) ...@@ -1734,7 +1734,7 @@ int bch2_dev_online(struct bch_fs *c, const char *path)
goto err; goto err;
} }
if (ca->mi.state == BCH_MEMBER_STATE_RW) { if (ca->mi.state == BCH_MEMBER_STATE_rw) {
err = __bch2_dev_read_write(c, ca); err = __bch2_dev_read_write(c, ca);
if (err) if (err)
goto err; goto err;
...@@ -1768,7 +1768,7 @@ int bch2_dev_offline(struct bch_fs *c, struct bch_dev *ca, int flags) ...@@ -1768,7 +1768,7 @@ int bch2_dev_offline(struct bch_fs *c, struct bch_dev *ca, int flags)
return 0; return 0;
} }
if (!bch2_dev_state_allowed(c, ca, BCH_MEMBER_STATE_FAILED, flags)) { if (!bch2_dev_state_allowed(c, ca, BCH_MEMBER_STATE_failed, flags)) {
bch_err(ca, "Cannot offline required disk"); bch_err(ca, "Cannot offline required disk");
up_write(&c->state_lock); up_write(&c->state_lock);
return -EINVAL; return -EINVAL;
......
...@@ -34,7 +34,7 @@ static inline bool bch2_dev_is_online(struct bch_dev *ca) ...@@ -34,7 +34,7 @@ static inline bool bch2_dev_is_online(struct bch_dev *ca)
static inline bool bch2_dev_is_readable(struct bch_dev *ca) static inline bool bch2_dev_is_readable(struct bch_dev *ca)
{ {
return bch2_dev_is_online(ca) && return bch2_dev_is_online(ca) &&
ca->mi.state != BCH_MEMBER_STATE_FAILED; ca->mi.state != BCH_MEMBER_STATE_failed;
} }
static inline bool bch2_dev_get_ioref(struct bch_dev *ca, int rw) static inline bool bch2_dev_get_ioref(struct bch_dev *ca, int rw)
...@@ -42,8 +42,8 @@ static inline bool bch2_dev_get_ioref(struct bch_dev *ca, int rw) ...@@ -42,8 +42,8 @@ static inline bool bch2_dev_get_ioref(struct bch_dev *ca, int rw)
if (!percpu_ref_tryget(&ca->io_ref)) if (!percpu_ref_tryget(&ca->io_ref))
return false; return false;
if (ca->mi.state == BCH_MEMBER_STATE_RW || if (ca->mi.state == BCH_MEMBER_STATE_rw ||
(ca->mi.state == BCH_MEMBER_STATE_RO && rw == READ)) (ca->mi.state == BCH_MEMBER_STATE_ro && rw == READ))
return true; return true;
percpu_ref_put(&ca->io_ref); percpu_ref_put(&ca->io_ref);
...@@ -158,11 +158,11 @@ static inline struct bch_dev *bch2_get_next_online_dev(struct bch_fs *c, ...@@ -158,11 +158,11 @@ static inline struct bch_dev *bch2_get_next_online_dev(struct bch_fs *c,
__for_each_online_member(ca, c, iter, ~0) __for_each_online_member(ca, c, iter, ~0)
#define for_each_rw_member(ca, c, iter) \ #define for_each_rw_member(ca, c, iter) \
__for_each_online_member(ca, c, iter, 1 << BCH_MEMBER_STATE_RW) __for_each_online_member(ca, c, iter, 1 << BCH_MEMBER_STATE_rw)
#define for_each_readable_member(ca, c, iter) \ #define for_each_readable_member(ca, c, iter) \
__for_each_online_member(ca, c, iter, \ __for_each_online_member(ca, c, iter, \
(1 << BCH_MEMBER_STATE_RW)|(1 << BCH_MEMBER_STATE_RO)) (1 << BCH_MEMBER_STATE_rw)|(1 << BCH_MEMBER_STATE_ro))
/* /*
* If a key exists that references a device, the device won't be going away and * If a key exists that references a device, the device won't be going away and
......
...@@ -886,7 +886,7 @@ SHOW(bch2_dev) ...@@ -886,7 +886,7 @@ SHOW(bch2_dev)
} }
if (attr == &sysfs_state_rw) { if (attr == &sysfs_state_rw) {
bch2_string_opt_to_text(&out, bch2_dev_state, bch2_string_opt_to_text(&out, bch2_member_states,
ca->mi.state); ca->mi.state);
pr_buf(&out, "\n"); pr_buf(&out, "\n");
return out.pos - buf; return out.pos - buf;
......
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