bcachefs: simplify bch_devs_list

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2023-12-23 21:02:45 -05:00
parent defd9e39b5
commit 037a2d9f48
5 changed files with 18 additions and 23 deletions

View File

@ -970,8 +970,8 @@ static int __open_bucket_add_buckets(struct btree_trans *trans,
devs = target_rw_devs(c, wp->data_type, target); devs = target_rw_devs(c, wp->data_type, target);
/* Don't allocate from devices we already have pointers to: */ /* Don't allocate from devices we already have pointers to: */
for (i = 0; i < devs_have->nr; i++) darray_for_each(*devs_have, i)
__clear_bit(devs_have->devs[i], devs.d); __clear_bit(*i, devs.d);
open_bucket_for_each(c, ptrs, ob, i) open_bucket_for_each(c, ptrs, ob, i)
__clear_bit(ob->dev, devs.d); __clear_bit(ob->dev, devs.d);

View File

@ -568,7 +568,7 @@ static inline struct bch_devs_list bch2_bkey_devs(struct bkey_s_c k)
const struct bch_extent_ptr *ptr; const struct bch_extent_ptr *ptr;
bkey_for_each_ptr(p, ptr) bkey_for_each_ptr(p, ptr)
ret.devs[ret.nr++] = ptr->dev; ret.data[ret.nr++] = ptr->dev;
return ret; return ret;
} }
@ -581,7 +581,7 @@ static inline struct bch_devs_list bch2_bkey_dirty_devs(struct bkey_s_c k)
bkey_for_each_ptr(p, ptr) bkey_for_each_ptr(p, ptr)
if (!ptr->cached) if (!ptr->cached)
ret.devs[ret.nr++] = ptr->dev; ret.data[ret.nr++] = ptr->dev;
return ret; return ret;
} }
@ -594,7 +594,7 @@ static inline struct bch_devs_list bch2_bkey_cached_devs(struct bkey_s_c k)
bkey_for_each_ptr(p, ptr) bkey_for_each_ptr(p, ptr)
if (ptr->cached) if (ptr->cached)
ret.devs[ret.nr++] = ptr->dev; ret.data[ret.nr++] = ptr->dev;
return ret; return ret;
} }

View File

@ -173,8 +173,6 @@ void bch2_devlist_to_replicas(struct bch_replicas_entry_v1 *e,
enum bch_data_type data_type, enum bch_data_type data_type,
struct bch_devs_list devs) struct bch_devs_list devs)
{ {
unsigned i;
BUG_ON(!data_type || BUG_ON(!data_type ||
data_type == BCH_DATA_sb || data_type == BCH_DATA_sb ||
data_type >= BCH_DATA_NR); data_type >= BCH_DATA_NR);
@ -183,8 +181,8 @@ void bch2_devlist_to_replicas(struct bch_replicas_entry_v1 *e,
e->nr_devs = 0; e->nr_devs = 0;
e->nr_required = 1; e->nr_required = 1;
for (i = 0; i < devs.nr; i++) darray_for_each(devs, i)
e->devs[e->nr_devs++] = devs.devs[i]; e->devs[e->nr_devs++] = *i;
bch2_replicas_entry_sort(e); bch2_replicas_entry_sort(e);
} }

View File

@ -2,6 +2,8 @@
#ifndef _BCACHEFS_SB_MEMBERS_H #ifndef _BCACHEFS_SB_MEMBERS_H
#define _BCACHEFS_SB_MEMBERS_H #define _BCACHEFS_SB_MEMBERS_H
#include "darray.h"
extern char * const bch2_member_error_strs[]; extern char * const bch2_member_error_strs[];
static inline struct bch_member * static inline struct bch_member *
@ -47,23 +49,18 @@ static inline unsigned dev_mask_nr(const struct bch_devs_mask *devs)
static inline bool bch2_dev_list_has_dev(struct bch_devs_list devs, static inline bool bch2_dev_list_has_dev(struct bch_devs_list devs,
unsigned dev) unsigned dev)
{ {
unsigned i; darray_for_each(devs, i)
if (*i == dev)
for (i = 0; i < devs.nr; i++)
if (devs.devs[i] == dev)
return true; return true;
return false; return false;
} }
static inline void bch2_dev_list_drop_dev(struct bch_devs_list *devs, static inline void bch2_dev_list_drop_dev(struct bch_devs_list *devs,
unsigned dev) unsigned dev)
{ {
unsigned i; darray_for_each(*devs, i)
if (*i == dev) {
for (i = 0; i < devs->nr; i++) darray_remove_item(devs, i);
if (devs->devs[i] == dev) {
array_remove_item(devs->devs, devs->nr, i);
return; return;
} }
} }
@ -72,14 +69,14 @@ static inline void bch2_dev_list_add_dev(struct bch_devs_list *devs,
unsigned dev) unsigned dev)
{ {
if (!bch2_dev_list_has_dev(*devs, dev)) { if (!bch2_dev_list_has_dev(*devs, dev)) {
BUG_ON(devs->nr >= ARRAY_SIZE(devs->devs)); BUG_ON(devs->nr >= ARRAY_SIZE(devs->data));
devs->devs[devs->nr++] = dev; devs->data[devs->nr++] = dev;
} }
} }
static inline struct bch_devs_list bch2_dev_list_single(unsigned dev) static inline struct bch_devs_list bch2_dev_list_single(unsigned dev)
{ {
return (struct bch_devs_list) { .nr = 1, .devs[0] = dev }; return (struct bch_devs_list) { .nr = 1, .data[0] = dev };
} }
static inline struct bch_dev *__bch2_next_dev(struct bch_fs *c, unsigned *iter, static inline struct bch_dev *__bch2_next_dev(struct bch_fs *c, unsigned *iter,

View File

@ -22,7 +22,7 @@ struct bch_devs_mask {
struct bch_devs_list { struct bch_devs_list {
u8 nr; u8 nr;
u8 devs[BCH_BKEY_PTRS_MAX]; u8 data[BCH_BKEY_PTRS_MAX];
}; };
struct bch_member_cpu { struct bch_member_cpu {