diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2023-09-26 23:49:34 +0200 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-22 23:10:16 +0200 |
commit | 4637429e3946d083eedde1668c17a4fadaf3c0b1 (patch) | |
tree | e963537ab982b1a82fa0aa33afab53713ce33fa7 /fs/bcachefs | |
parent | bcachefs: KEY_TYPE_error now counts towards i_sectors (diff) | |
download | linux-4637429e3946d083eedde1668c17a4fadaf3c0b1.tar.xz linux-4637429e3946d083eedde1668c17a4fadaf3c0b1.zip |
bcachefs: bch2_sb_field_get() refactoring
Instead of using token pasting to generate methods for each superblock
section, just make the type a parameter to bch2_sb_field_get().
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs')
-rw-r--r-- | fs/bcachefs/checksum.c | 9 | ||||
-rw-r--r-- | fs/bcachefs/counters.c | 6 | ||||
-rw-r--r-- | fs/bcachefs/disk_groups.c | 12 | ||||
-rw-r--r-- | fs/bcachefs/journal.c | 4 | ||||
-rw-r--r-- | fs/bcachefs/journal_sb.c | 2 | ||||
-rw-r--r-- | fs/bcachefs/journal_seq_blacklist.c | 16 | ||||
-rw-r--r-- | fs/bcachefs/quota.c | 6 | ||||
-rw-r--r-- | fs/bcachefs/replicas.c | 16 | ||||
-rw-r--r-- | fs/bcachefs/sb-clean.c | 4 | ||||
-rw-r--r-- | fs/bcachefs/sb-members.c | 24 | ||||
-rw-r--r-- | fs/bcachefs/super-io.c | 18 | ||||
-rw-r--r-- | fs/bcachefs/super-io.h | 30 | ||||
-rw-r--r-- | fs/bcachefs/super.c | 6 |
13 files changed, 71 insertions, 82 deletions
diff --git a/fs/bcachefs/checksum.c b/fs/bcachefs/checksum.c index 839f00dce50f..3c761ad6b1c8 100644 --- a/fs/bcachefs/checksum.c +++ b/fs/bcachefs/checksum.c @@ -678,7 +678,7 @@ int bch2_disable_encryption(struct bch_fs *c) mutex_lock(&c->sb_lock); - crypt = bch2_sb_get_crypt(c->disk_sb.sb); + crypt = bch2_sb_field_get(c->disk_sb.sb, crypt); if (!crypt) goto out; @@ -712,7 +712,7 @@ int bch2_enable_encryption(struct bch_fs *c, bool keyed) mutex_lock(&c->sb_lock); /* Do we already have an encryption key? */ - if (bch2_sb_get_crypt(c->disk_sb.sb)) + if (bch2_sb_field_get(c->disk_sb.sb, crypt)) goto err; ret = bch2_alloc_ciphers(c); @@ -740,7 +740,8 @@ int bch2_enable_encryption(struct bch_fs *c, bool keyed) if (ret) goto err; - crypt = bch2_sb_resize_crypt(&c->disk_sb, sizeof(*crypt) / sizeof(u64)); + crypt = bch2_sb_field_resize(&c->disk_sb, crypt, + sizeof(*crypt) / sizeof(u64)); if (!crypt) { ret = -BCH_ERR_ENOSPC_sb_crypt; goto err; @@ -781,7 +782,7 @@ int bch2_fs_encryption_init(struct bch_fs *c) goto out; } - crypt = bch2_sb_get_crypt(c->disk_sb.sb); + crypt = bch2_sb_field_get(c->disk_sb.sb, crypt); if (!crypt) goto out; diff --git a/fs/bcachefs/counters.c b/fs/bcachefs/counters.c index 26eb3d82b1cb..02a996e06a64 100644 --- a/fs/bcachefs/counters.c +++ b/fs/bcachefs/counters.c @@ -48,7 +48,7 @@ static void bch2_sb_counters_to_text(struct printbuf *out, struct bch_sb *sb, int bch2_sb_counters_to_cpu(struct bch_fs *c) { - struct bch_sb_field_counters *ctrs = bch2_sb_get_counters(c->disk_sb.sb); + struct bch_sb_field_counters *ctrs = bch2_sb_field_get(c->disk_sb.sb, counters); unsigned int i; unsigned int nr = bch2_sb_counter_nr_entries(ctrs); u64 val = 0; @@ -66,13 +66,13 @@ int bch2_sb_counters_to_cpu(struct bch_fs *c) int bch2_sb_counters_from_cpu(struct bch_fs *c) { - struct bch_sb_field_counters *ctrs = bch2_sb_get_counters(c->disk_sb.sb); + struct bch_sb_field_counters *ctrs = bch2_sb_field_get(c->disk_sb.sb, counters); struct bch_sb_field_counters *ret; unsigned int i; unsigned int nr = bch2_sb_counter_nr_entries(ctrs); if (nr < BCH_COUNTER_NR) { - ret = bch2_sb_resize_counters(&c->disk_sb, + ret = bch2_sb_field_resize(&c->disk_sb, counters, sizeof(*ctrs) / sizeof(u64) + BCH_COUNTER_NR); if (ret) { diff --git a/fs/bcachefs/disk_groups.c b/fs/bcachefs/disk_groups.c index 3c8aa69b67ea..e00133b6ea51 100644 --- a/fs/bcachefs/disk_groups.c +++ b/fs/bcachefs/disk_groups.c @@ -157,7 +157,7 @@ int bch2_sb_disk_groups_to_cpu(struct bch_fs *c) lockdep_assert_held(&c->sb_lock); - groups = bch2_sb_get_disk_groups(c->disk_sb.sb); + groups = bch2_sb_field_get(c->disk_sb.sb, disk_groups); nr_groups = disk_groups_nr(groups); if (!groups) @@ -295,7 +295,7 @@ static int __bch2_disk_group_add(struct bch_sb_handle *sb, unsigned parent, const char *name, unsigned namelen) { struct bch_sb_field_disk_groups *groups = - bch2_sb_get_disk_groups(sb->sb); + bch2_sb_field_get(sb->sb, disk_groups); unsigned i, nr_groups = disk_groups_nr(groups); struct bch_disk_group *g; @@ -313,7 +313,7 @@ static int __bch2_disk_group_add(struct bch_sb_handle *sb, unsigned parent, sizeof(struct bch_disk_group) * (nr_groups + 1)) / sizeof(u64); - groups = bch2_sb_resize_disk_groups(sb, u64s); + groups = bch2_sb_field_resize(sb, disk_groups, u64s); if (!groups) return -BCH_ERR_ENOSPC_disk_label_add; @@ -337,7 +337,7 @@ static int __bch2_disk_group_add(struct bch_sb_handle *sb, unsigned parent, int bch2_disk_path_find(struct bch_sb_handle *sb, const char *name) { struct bch_sb_field_disk_groups *groups = - bch2_sb_get_disk_groups(sb->sb); + bch2_sb_field_get(sb->sb, disk_groups); int v = -1; do { @@ -367,7 +367,7 @@ int bch2_disk_path_find_or_create(struct bch_sb_handle *sb, const char *name) if (*next == '.') next++; - groups = bch2_sb_get_disk_groups(sb->sb); + groups = bch2_sb_field_get(sb->sb, disk_groups); v = __bch2_disk_group_find(groups, parent, name, len); if (v < 0) @@ -385,7 +385,7 @@ int bch2_disk_path_find_or_create(struct bch_sb_handle *sb, const char *name) void bch2_disk_path_to_text(struct printbuf *out, struct bch_sb *sb, unsigned v) { struct bch_sb_field_disk_groups *groups = - bch2_sb_get_disk_groups(sb); + bch2_sb_field_get(sb, disk_groups); struct bch_disk_group *g; unsigned nr = 0; u16 path[32]; diff --git a/fs/bcachefs/journal.c b/fs/bcachefs/journal.c index fc3dd5bef386..0e7a9ffa3671 100644 --- a/fs/bcachefs/journal.c +++ b/fs/bcachefs/journal.c @@ -1170,9 +1170,9 @@ int bch2_dev_journal_init(struct bch_dev *ca, struct bch_sb *sb) { struct journal_device *ja = &ca->journal; struct bch_sb_field_journal *journal_buckets = - bch2_sb_get_journal(sb); + bch2_sb_field_get(sb, journal); struct bch_sb_field_journal_v2 *journal_buckets_v2 = - bch2_sb_get_journal_v2(sb); + bch2_sb_field_get(sb, journal_v2); unsigned i, nr_bvecs; ja->nr = 0; diff --git a/fs/bcachefs/journal_sb.c b/fs/bcachefs/journal_sb.c index 3c5a95e29463..ae4fb8c3a2bc 100644 --- a/fs/bcachefs/journal_sb.c +++ b/fs/bcachefs/journal_sb.c @@ -194,7 +194,7 @@ int bch2_journal_buckets_to_sb(struct bch_fs *c, struct bch_dev *ca, if (buckets[i] + 1 != buckets[i + 1]) nr_compacted++; - j = bch2_sb_resize_journal_v2(&ca->disk_sb, + j = bch2_sb_field_resize(&ca->disk_sb, journal_v2, (sizeof(*j) + sizeof(j->d[0]) * nr_compacted) / sizeof(u64)); if (!j) return -BCH_ERR_ENOSPC_sb_journal; diff --git a/fs/bcachefs/journal_seq_blacklist.c b/fs/bcachefs/journal_seq_blacklist.c index 1e1a79405693..f9d9aa95bf3a 100644 --- a/fs/bcachefs/journal_seq_blacklist.c +++ b/fs/bcachefs/journal_seq_blacklist.c @@ -58,8 +58,8 @@ blacklist_entry_try_merge(struct bch_fs *c, &bl->start[i + 1], sizeof(bl->start[0]) * (nr - i)); - bl = bch2_sb_resize_journal_seq_blacklist(&c->disk_sb, - sb_blacklist_u64s(nr)); + bl = bch2_sb_field_resize(&c->disk_sb, journal_seq_blacklist, + sb_blacklist_u64s(nr)); BUG_ON(!bl); } @@ -79,7 +79,7 @@ int bch2_journal_seq_blacklist_add(struct bch_fs *c, u64 start, u64 end) int ret = 0; mutex_lock(&c->sb_lock); - bl = bch2_sb_get_journal_seq_blacklist(c->disk_sb.sb); + bl = bch2_sb_field_get(c->disk_sb.sb, journal_seq_blacklist); nr = blacklist_nr_entries(bl); for (i = 0; i < nr; i++) { @@ -100,8 +100,8 @@ int bch2_journal_seq_blacklist_add(struct bch_fs *c, u64 start, u64 end) } } - bl = bch2_sb_resize_journal_seq_blacklist(&c->disk_sb, - sb_blacklist_u64s(nr + 1)); + bl = bch2_sb_field_resize(&c->disk_sb, journal_seq_blacklist, + sb_blacklist_u64s(nr + 1)); if (!bl) { ret = -BCH_ERR_ENOSPC_sb_journal_seq_blacklist; goto out; @@ -158,7 +158,7 @@ bool bch2_journal_seq_is_blacklisted(struct bch_fs *c, u64 seq, int bch2_blacklist_table_initialize(struct bch_fs *c) { struct bch_sb_field_journal_seq_blacklist *bl = - bch2_sb_get_journal_seq_blacklist(c->disk_sb.sb); + bch2_sb_field_get(c->disk_sb.sb, journal_seq_blacklist); struct journal_seq_blacklist_table *t; unsigned i, nr = blacklist_nr_entries(bl); @@ -281,7 +281,7 @@ retry: return; mutex_lock(&c->sb_lock); - bl = bch2_sb_get_journal_seq_blacklist(c->disk_sb.sb); + bl = bch2_sb_field_get(c->disk_sb.sb, journal_seq_blacklist); if (!bl) goto out; @@ -306,7 +306,7 @@ retry: bch_info(c, "nr blacklist entries was %u, now %u", nr, new_nr); if (new_nr != nr) { - bl = bch2_sb_resize_journal_seq_blacklist(&c->disk_sb, + bl = bch2_sb_field_resize(&c->disk_sb, journal_seq_blacklist, new_nr ? sb_blacklist_u64s(new_nr) : 0); BUG_ON(new_nr && !bl); diff --git a/fs/bcachefs/quota.c b/fs/bcachefs/quota.c index 36de2f071d80..cb68ae44d597 100644 --- a/fs/bcachefs/quota.c +++ b/fs/bcachefs/quota.c @@ -513,12 +513,12 @@ void bch2_fs_quota_init(struct bch_fs *c) static struct bch_sb_field_quota *bch2_sb_get_or_create_quota(struct bch_sb_handle *sb) { - struct bch_sb_field_quota *sb_quota = bch2_sb_get_quota(sb->sb); + struct bch_sb_field_quota *sb_quota = bch2_sb_field_get(sb->sb, quota); if (sb_quota) return sb_quota; - sb_quota = bch2_sb_resize_quota(sb, sizeof(*sb_quota) / sizeof(u64)); + sb_quota = bch2_sb_field_resize(sb, quota, sizeof(*sb_quota) / sizeof(u64)); if (sb_quota) { unsigned qtype, qc; @@ -536,7 +536,7 @@ static void bch2_sb_quota_read(struct bch_fs *c) struct bch_sb_field_quota *sb_quota; unsigned i, j; - sb_quota = bch2_sb_get_quota(c->disk_sb.sb); + sb_quota = bch2_sb_field_get(c->disk_sb.sb, quota); if (!sb_quota) return; diff --git a/fs/bcachefs/replicas.c b/fs/bcachefs/replicas.c index a9a694fb0b18..cef2a0447b86 100644 --- a/fs/bcachefs/replicas.c +++ b/fs/bcachefs/replicas.c @@ -700,9 +700,9 @@ int bch2_sb_replicas_to_cpu_replicas(struct bch_fs *c) struct bch_replicas_cpu new_r = { 0, 0, NULL }; int ret = 0; - if ((sb_v1 = bch2_sb_get_replicas(c->disk_sb.sb))) + if ((sb_v1 = bch2_sb_field_get(c->disk_sb.sb, replicas))) ret = __bch2_sb_replicas_to_cpu_replicas(sb_v1, &new_r); - else if ((sb_v0 = bch2_sb_get_replicas_v0(c->disk_sb.sb))) + else if ((sb_v0 = bch2_sb_field_get(c->disk_sb.sb, replicas_v0))) ret = __bch2_sb_replicas_v0_to_cpu_replicas(sb_v0, &new_r); if (ret) return ret; @@ -732,13 +732,13 @@ static int bch2_cpu_replicas_to_sb_replicas_v0(struct bch_fs *c, for_each_cpu_replicas_entry(r, src) bytes += replicas_entry_bytes(src) - 1; - sb_r = bch2_sb_resize_replicas_v0(&c->disk_sb, + sb_r = bch2_sb_field_resize(&c->disk_sb, replicas_v0, DIV_ROUND_UP(bytes, sizeof(u64))); if (!sb_r) return -BCH_ERR_ENOSPC_sb_replicas; bch2_sb_field_delete(&c->disk_sb, BCH_SB_FIELD_replicas); - sb_r = bch2_sb_get_replicas_v0(c->disk_sb.sb); + sb_r = bch2_sb_field_get(c->disk_sb.sb, replicas_v0); memset(&sb_r->entries, 0, vstruct_end(&sb_r->field) - @@ -777,13 +777,13 @@ static int bch2_cpu_replicas_to_sb_replicas(struct bch_fs *c, if (!need_v1) return bch2_cpu_replicas_to_sb_replicas_v0(c, r); - sb_r = bch2_sb_resize_replicas(&c->disk_sb, + sb_r = bch2_sb_field_resize(&c->disk_sb, replicas, DIV_ROUND_UP(bytes, sizeof(u64))); if (!sb_r) return -BCH_ERR_ENOSPC_sb_replicas; bch2_sb_field_delete(&c->disk_sb, BCH_SB_FIELD_replicas_v0); - sb_r = bch2_sb_get_replicas(c->disk_sb.sb); + sb_r = bch2_sb_field_get(c->disk_sb.sb, replicas); memset(&sb_r->entries, 0, vstruct_end(&sb_r->field) - @@ -998,8 +998,8 @@ unsigned bch2_sb_dev_has_data(struct bch_sb *sb, unsigned dev) struct bch_sb_field_replicas_v0 *replicas_v0; unsigned i, data_has = 0; - replicas = bch2_sb_get_replicas(sb); - replicas_v0 = bch2_sb_get_replicas_v0(sb); + replicas = bch2_sb_field_get(sb, replicas); + replicas_v0 = bch2_sb_field_get(sb, replicas_v0); if (replicas) { struct bch_replicas_entry *r; diff --git a/fs/bcachefs/sb-clean.c b/fs/bcachefs/sb-clean.c index a3695e56a155..61203d7c8d36 100644 --- a/fs/bcachefs/sb-clean.c +++ b/fs/bcachefs/sb-clean.c @@ -137,7 +137,7 @@ struct bch_sb_field_clean *bch2_read_superblock_clean(struct bch_fs *c) int ret; mutex_lock(&c->sb_lock); - sb_clean = bch2_sb_get_clean(c->disk_sb.sb); + sb_clean = bch2_sb_field_get(c->disk_sb.sb, clean); if (fsck_err_on(!sb_clean, c, "superblock marked clean but clean section not present")) { @@ -359,7 +359,7 @@ void bch2_fs_mark_clean(struct bch_fs *c) u64s = sizeof(*sb_clean) / sizeof(u64) + c->journal.entry_u64s_reserved; - sb_clean = bch2_sb_resize_clean(&c->disk_sb, u64s); + sb_clean = bch2_sb_field_resize(&c->disk_sb, clean, u64s); if (!sb_clean) { bch_err(c, "error resizing superblock while setting filesystem clean"); goto out; diff --git a/fs/bcachefs/sb-members.c b/fs/bcachefs/sb-members.c index 04bde1aaff9f..6dd85bb996fe 100644 --- a/fs/bcachefs/sb-members.c +++ b/fs/bcachefs/sb-members.c @@ -16,7 +16,7 @@ static struct bch_member *members_v2_get_mut(struct bch_sb_field_members_v2 *mi, struct bch_member *bch2_members_v2_get_mut(struct bch_sb *sb, int i) { - return members_v2_get_mut(bch2_sb_get_members_v2(sb), i); + return members_v2_get_mut(bch2_sb_field_get(sb, members_v2), i); } static struct bch_member members_v2_get(struct bch_sb_field_members_v2 *mi, int i) @@ -41,22 +41,22 @@ static struct bch_member members_v1_get(struct bch_sb_field_members_v1 *mi, int struct bch_member bch2_sb_member_get(struct bch_sb *sb, int i) { - struct bch_sb_field_members_v2 *mi2 = bch2_sb_get_members_v2(sb); + struct bch_sb_field_members_v2 *mi2 = bch2_sb_field_get(sb, members_v2); if (mi2) return members_v2_get(mi2, i); - struct bch_sb_field_members_v1 *mi1 = bch2_sb_get_members_v1(sb); + struct bch_sb_field_members_v1 *mi1 = bch2_sb_field_get(sb, members_v1); return members_v1_get(mi1, i); } static int sb_members_v2_resize_entries(struct bch_fs *c) { - struct bch_sb_field_members_v2 *mi = bch2_sb_get_members_v2(c->disk_sb.sb); + struct bch_sb_field_members_v2 *mi = bch2_sb_field_get(c->disk_sb.sb, members_v2); if (le16_to_cpu(mi->member_bytes) < sizeof(struct bch_member)) { unsigned u64s = DIV_ROUND_UP((sizeof(*mi) + sizeof(mi->_members[0]) * c->disk_sb.sb->nr_devices), 8); - mi = bch2_sb_resize_members_v2(&c->disk_sb, u64s); + mi = bch2_sb_field_resize(&c->disk_sb, members_v2, u64s); if (!mi) return -BCH_ERR_ENOSPC_sb_members_v2; @@ -76,12 +76,12 @@ int bch2_members_v2_init(struct bch_fs *c) struct bch_sb_field_members_v1 *mi1; struct bch_sb_field_members_v2 *mi2; - if (!bch2_sb_get_members_v2(c->disk_sb.sb)) { - mi2 = bch2_sb_resize_members_v2(&c->disk_sb, + if (!bch2_sb_field_get(c->disk_sb.sb, members_v2)) { + mi2 = bch2_sb_field_resize(&c->disk_sb, members_v2, DIV_ROUND_UP(sizeof(*mi2) + sizeof(struct bch_member) * c->sb.nr_devices, sizeof(u64))); - mi1 = bch2_sb_get_members_v1(c->disk_sb.sb); + mi1 = bch2_sb_field_get(c->disk_sb.sb, members_v1); memcpy(&mi2->_members[0], &mi1->_members[0], BCH_MEMBER_V1_BYTES * c->sb.nr_devices); memset(&mi2->pad[0], 0, sizeof(mi2->pad)); @@ -96,13 +96,13 @@ int bch_members_cpy_v2_v1(struct bch_sb_handle *disk_sb) struct bch_sb_field_members_v1 *mi1; struct bch_sb_field_members_v2 *mi2; - mi1 = bch2_sb_resize_members_v1(disk_sb, + mi1 = bch2_sb_field_resize(disk_sb, members_v1, DIV_ROUND_UP(sizeof(*mi1) + BCH_MEMBER_V1_BYTES * disk_sb->sb->nr_devices, sizeof(u64))); if (!mi1) return -BCH_ERR_ENOSPC_sb_members; - mi2 = bch2_sb_get_members_v2(disk_sb->sb); + mi2 = bch2_sb_field_get(disk_sb->sb, members_v2); for (unsigned i = 0; i < disk_sb->sb->nr_devices; i++) memcpy(members_v1_get_mut(mi1, i), members_v2_get_mut(mi2, i), BCH_MEMBER_V1_BYTES); @@ -283,7 +283,7 @@ static void bch2_sb_members_v1_to_text(struct printbuf *out, struct bch_sb *sb, struct bch_sb_field *f) { struct bch_sb_field_members_v1 *mi = field_to_type(f, members_v1); - struct bch_sb_field_disk_groups *gi = bch2_sb_get_disk_groups(sb); + struct bch_sb_field_disk_groups *gi = bch2_sb_field_get(sb, disk_groups); unsigned i; for (i = 0; i < sb->nr_devices; i++) { @@ -301,7 +301,7 @@ static void bch2_sb_members_v2_to_text(struct printbuf *out, struct bch_sb *sb, struct bch_sb_field *f) { struct bch_sb_field_members_v2 *mi = field_to_type(f, members_v2); - struct bch_sb_field_disk_groups *gi = bch2_sb_get_disk_groups(sb); + struct bch_sb_field_disk_groups *gi = bch2_sb_field_get(sb, disk_groups); unsigned i; for (i = 0; i < sb->nr_devices; i++) { diff --git a/fs/bcachefs/super-io.c b/fs/bcachefs/super-io.c index 4498e24dabdb..332d41e1c0a3 100644 --- a/fs/bcachefs/super-io.c +++ b/fs/bcachefs/super-io.c @@ -96,7 +96,7 @@ const char * const bch2_sb_fields[] = { static int bch2_sb_field_validate(struct bch_sb *, struct bch_sb_field *, struct printbuf *); -struct bch_sb_field *bch2_sb_field_get(struct bch_sb *sb, +struct bch_sb_field *bch2_sb_field_get_id(struct bch_sb *sb, enum bch_sb_field_type type) { struct bch_sb_field *f; @@ -151,7 +151,7 @@ static struct bch_sb_field *__bch2_sb_field_resize(struct bch_sb_handle *sb, void bch2_sb_field_delete(struct bch_sb_handle *sb, enum bch_sb_field_type type) { - struct bch_sb_field *f = bch2_sb_field_get(sb->sb, type); + struct bch_sb_field *f = bch2_sb_field_get_id(sb->sb, type); if (f) __bch2_sb_field_resize(sb, f, 0); @@ -225,11 +225,11 @@ int bch2_sb_realloc(struct bch_sb_handle *sb, unsigned u64s) return 0; } -struct bch_sb_field *bch2_sb_field_resize(struct bch_sb_handle *sb, +struct bch_sb_field *bch2_sb_field_resize_id(struct bch_sb_handle *sb, enum bch_sb_field_type type, unsigned u64s) { - struct bch_sb_field *f = bch2_sb_field_get(sb->sb, type); + struct bch_sb_field *f = bch2_sb_field_get_id(sb->sb, type); ssize_t old_u64s = f ? le32_to_cpu(f->u64s) : 0; ssize_t d = -old_u64s + u64s; @@ -255,7 +255,7 @@ struct bch_sb_field *bch2_sb_field_resize(struct bch_sb_handle *sb, } } - f = bch2_sb_field_get(sb->sb, type); + f = bch2_sb_field_get_id(sb->sb, type); f = __bch2_sb_field_resize(sb, f, u64s); if (f) f->type = cpu_to_le32(type); @@ -458,7 +458,7 @@ static int bch2_sb_validate(struct bch_sb_handle *disk_sb, struct printbuf *out, } /* members must be validated first: */ - mi = bch2_sb_get_members_v1(sb); + mi = bch2_sb_field_get(sb, members_v1); if (!mi) { prt_printf(out, "Invalid superblock: member info area missing"); return -BCH_ERR_invalid_sb_members_missing; @@ -546,8 +546,8 @@ static int __copy_super(struct bch_sb_handle *dst_handle, struct bch_sb *src) if ((1U << i) & BCH_SINGLE_DEVICE_SB_FIELDS) continue; - src_f = bch2_sb_field_get(src, i); - dst_f = bch2_sb_field_get(dst, i); + src_f = bch2_sb_field_get_id(src, i); + dst_f = bch2_sb_field_get_id(dst, i); d = (src_f ? le32_to_cpu(src_f->u64s) : 0) - (dst_f ? le32_to_cpu(dst_f->u64s) : 0); @@ -559,7 +559,7 @@ static int __copy_super(struct bch_sb_handle *dst_handle, struct bch_sb *src) return ret; dst = dst_handle->sb; - dst_f = bch2_sb_field_get(dst, i); + dst_f = bch2_sb_field_get_id(dst, i); } dst_f = __bch2_sb_field_resize(dst_handle, dst_f, diff --git a/fs/bcachefs/super-io.h b/fs/bcachefs/super-io.h index f7e9099931a7..b0d8584f475f 100644 --- a/fs/bcachefs/super-io.h +++ b/fs/bcachefs/super-io.h @@ -23,31 +23,19 @@ u64 bch2_upgrade_recovery_passes(struct bch_fs *c, unsigned, unsigned); -struct bch_sb_field *bch2_sb_field_get(struct bch_sb *, enum bch_sb_field_type); -struct bch_sb_field *bch2_sb_field_resize(struct bch_sb_handle *, - enum bch_sb_field_type, unsigned); -void bch2_sb_field_delete(struct bch_sb_handle *, enum bch_sb_field_type); - #define field_to_type(_f, _name) \ container_of_or_null(_f, struct bch_sb_field_##_name, field) -#define x(_name, _nr) \ -static inline struct bch_sb_field_##_name * \ -bch2_sb_get_##_name(struct bch_sb *sb) \ -{ \ - return field_to_type(bch2_sb_field_get(sb, \ - BCH_SB_FIELD_##_name), _name); \ -} \ - \ -static inline struct bch_sb_field_##_name * \ -bch2_sb_resize_##_name(struct bch_sb_handle *sb, unsigned u64s) \ -{ \ - return field_to_type(bch2_sb_field_resize(sb, \ - BCH_SB_FIELD_##_name, u64s), _name); \ -} +struct bch_sb_field *bch2_sb_field_get_id(struct bch_sb *, enum bch_sb_field_type); +#define bch2_sb_field_get(_sb, _name) \ + field_to_type(bch2_sb_field_get_id(_sb, BCH_SB_FIELD_##_name), _name) -BCH_SB_FIELDS() -#undef x +struct bch_sb_field *bch2_sb_field_resize_id(struct bch_sb_handle *, + enum bch_sb_field_type, unsigned); +#define bch2_sb_field_resize(_sb, _name, _u64s) \ + field_to_type(bch2_sb_field_resize_id(_sb, BCH_SB_FIELD_##_name, _u64s), _name) + +void bch2_sb_field_delete(struct bch_sb_handle *, enum bch_sb_field_type); extern const char * const bch2_sb_fields[]; diff --git a/fs/bcachefs/super.c b/fs/bcachefs/super.c index 2014f7816f66..1c775695336d 100644 --- a/fs/bcachefs/super.c +++ b/fs/bcachefs/super.c @@ -1630,9 +1630,9 @@ int bch2_dev_add(struct bch_fs *c, const char *path) goto err_unlock; } - mi = bch2_sb_get_members_v2(ca->disk_sb.sb); + mi = bch2_sb_field_get(ca->disk_sb.sb, members_v2); - if (!bch2_sb_resize_members_v2(&ca->disk_sb, + if (!bch2_sb_field_resize(&ca->disk_sb, members_v2, le32_to_cpu(mi->field.u64s) + sizeof(dev_mi) / sizeof(u64))) { ret = -BCH_ERR_ENOSPC_sb_members; @@ -1656,7 +1656,7 @@ have_slot: u64s = DIV_ROUND_UP(sizeof(struct bch_sb_field_members_v2) + le16_to_cpu(mi->member_bytes) * nr_devices, sizeof(u64)); - mi = bch2_sb_resize_members_v2(&c->disk_sb, u64s); + mi = bch2_sb_field_resize(&c->disk_sb, members_v2, u64s); if (!mi) { ret = -BCH_ERR_ENOSPC_sb_members; bch_err_msg(c, ret, "setting up new superblock"); |