Commit fb8e5b4c authored by Kent Overstreet's avatar Kent Overstreet
Browse files

bcachefs: sb-members.c



Split out a new file for bch_sb_field_members - we'll likely want to
move more code here in the future.

Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 8079aab0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ bcachefs-y := \
	recovery.o		\
	reflink.o		\
	replicas.o		\
	sb-members.o		\
	siphash.o		\
	six.o			\
	subvolume.o		\
+1 −1
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@
#include "bcachefs.h"
#include "alloc_types.h"
#include "extents.h"
#include "super.h"
#include "sb-members.h"

#include <linux/hash.h>

+46 −1
Original line number Diff line number Diff line
@@ -10,7 +10,31 @@

#include "buckets_types.h"
#include "extents.h"
#include "super.h"
#include "sb-members.h"

static inline size_t sector_to_bucket(const struct bch_dev *ca, sector_t s)
{
	return div_u64(s, ca->mi.bucket_size);
}

static inline sector_t bucket_to_sector(const struct bch_dev *ca, size_t b)
{
	return ((sector_t) b) * ca->mi.bucket_size;
}

static inline sector_t bucket_remainder(const struct bch_dev *ca, sector_t s)
{
	u32 remainder;

	div_u64_rem(s, ca->mi.bucket_size, &remainder);
	return remainder;
}

static inline size_t sector_to_bucket_and_offset(const struct bch_dev *ca, sector_t s,
						 u32 *offset)
{
	return div_u64_rem(s, ca->mi.bucket_size, offset);
}

#define for_each_bucket(_b, _buckets)				\
	for (_b = (_buckets)->b + (_buckets)->first_bucket;	\
@@ -292,6 +316,27 @@ int bch2_trans_mark_metadata_bucket(struct btree_trans *, struct bch_dev *,
				    size_t, enum bch_data_type, unsigned);
int bch2_trans_mark_dev_sb(struct bch_fs *, struct bch_dev *);

static inline bool is_superblock_bucket(struct bch_dev *ca, u64 b)
{
	struct bch_sb_layout *layout = &ca->disk_sb.sb->layout;
	u64 b_offset	= bucket_to_sector(ca, b);
	u64 b_end	= bucket_to_sector(ca, b + 1);
	unsigned i;

	if (!b)
		return true;

	for (i = 0; i < layout->nr_superblocks; i++) {
		u64 offset = le64_to_cpu(layout->sb_offset[i]);
		u64 end = offset + (1 << layout->sb_max_size_bits);

		if (!(offset >= b_end || end <= b_offset))
			return true;
	}

	return false;
}

/* disk reservations: */

static inline void bch2_disk_reservation_put(struct bch_fs *c,
+1 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0
#include "bcachefs.h"
#include "disk_groups.h"
#include "sb-members.h"
#include "super-io.h"

#include <linux/sort.h>
+2 −1
Original line number Diff line number Diff line
@@ -3,13 +3,14 @@
#include "bcachefs.h"
#include "btree_key_cache.h"
#include "btree_update.h"
#include "buckets.h"
#include "errcode.h"
#include "error.h"
#include "journal.h"
#include "journal_io.h"
#include "journal_reclaim.h"
#include "replicas.h"
#include "super.h"
#include "sb-members.h"
#include "trace.h"

#include <linux/kthread.h>
Loading