Commit 037a2d9f authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: simplify bch_devs_list

Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent defd9e39
......@@ -970,8 +970,8 @@ static int __open_bucket_add_buckets(struct btree_trans *trans,
devs = target_rw_devs(c, wp->data_type, target);
/* Don't allocate from devices we already have pointers to: */
for (i = 0; i < devs_have->nr; i++)
__clear_bit(devs_have->devs[i], devs.d);
darray_for_each(*devs_have, i)
__clear_bit(*i, devs.d);
open_bucket_for_each(c, ptrs, ob, i)
__clear_bit(ob->dev, devs.d);
......
......@@ -568,7 +568,7 @@ static inline struct bch_devs_list bch2_bkey_devs(struct bkey_s_c k)
const struct bch_extent_ptr *ptr;
bkey_for_each_ptr(p, ptr)
ret.devs[ret.nr++] = ptr->dev;
ret.data[ret.nr++] = ptr->dev;
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)
if (!ptr->cached)
ret.devs[ret.nr++] = ptr->dev;
ret.data[ret.nr++] = ptr->dev;
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)
if (ptr->cached)
ret.devs[ret.nr++] = ptr->dev;
ret.data[ret.nr++] = ptr->dev;
return ret;
}
......
......@@ -173,8 +173,6 @@ void bch2_devlist_to_replicas(struct bch_replicas_entry_v1 *e,
enum bch_data_type data_type,
struct bch_devs_list devs)
{
unsigned i;
BUG_ON(!data_type ||
data_type == BCH_DATA_sb ||
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_required = 1;
for (i = 0; i < devs.nr; i++)
e->devs[e->nr_devs++] = devs.devs[i];
darray_for_each(devs, i)
e->devs[e->nr_devs++] = *i;
bch2_replicas_entry_sort(e);
}
......
......@@ -2,6 +2,8 @@
#ifndef _BCACHEFS_SB_MEMBERS_H
#define _BCACHEFS_SB_MEMBERS_H
#include "darray.h"
extern char * const bch2_member_error_strs[];
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,
unsigned dev)
{
unsigned i;
for (i = 0; i < devs.nr; i++)
if (devs.devs[i] == dev)
darray_for_each(devs, i)
if (*i == dev)
return true;
return false;
}
static inline void bch2_dev_list_drop_dev(struct bch_devs_list *devs,
unsigned dev)
{
unsigned i;
for (i = 0; i < devs->nr; i++)
if (devs->devs[i] == dev) {
array_remove_item(devs->devs, devs->nr, i);
darray_for_each(*devs, i)
if (*i == dev) {
darray_remove_item(devs, i);
return;
}
}
......@@ -72,14 +69,14 @@ static inline void bch2_dev_list_add_dev(struct bch_devs_list *devs,
unsigned dev)
{
if (!bch2_dev_list_has_dev(*devs, dev)) {
BUG_ON(devs->nr >= ARRAY_SIZE(devs->devs));
devs->devs[devs->nr++] = dev;
BUG_ON(devs->nr >= ARRAY_SIZE(devs->data));
devs->data[devs->nr++] = 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,
......
......@@ -22,7 +22,7 @@ struct bch_devs_mask {
struct bch_devs_list {
u8 nr;
u8 devs[BCH_BKEY_PTRS_MAX];
u8 data[BCH_BKEY_PTRS_MAX];
};
struct bch_member_cpu {
......
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