linux/fs/bcachefs/extents.h

/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _BCACHEFS_EXTENTS_H
#define _BCACHEFS_EXTENTS_H

#include "bcachefs.h"
#include "bkey.h"
#include "extents_types.h"

struct bch_fs;
struct btree_trans;
enum bch_validate_flags;

/* extent entries: */

#define extent_entry_last(_e)

#define entry_to_ptr(_entry)

/* downcast, preserves const */
#define to_entry(_entry)

#define extent_entry_next(_entry)

#define extent_entry_next_safe(_entry, _end)

static inline unsigned
__extent_entry_type(const union bch_extent_entry *e)
{}

static inline enum bch_extent_entry_type
extent_entry_type(const union bch_extent_entry *e)
{}

static inline size_t extent_entry_bytes(const union bch_extent_entry *entry)
{}

static inline size_t extent_entry_u64s(const union bch_extent_entry *entry)
{}

static inline void __extent_entry_insert(struct bkey_i *k,
					 union bch_extent_entry *dst,
					 union bch_extent_entry *new)
{}

static inline void extent_entry_drop(struct bkey_s k, union bch_extent_entry *entry)
{}

static inline bool extent_entry_is_ptr(const union bch_extent_entry *e)
{}

static inline bool extent_entry_is_stripe_ptr(const union bch_extent_entry *e)
{}

static inline bool extent_entry_is_crc(const union bch_extent_entry *e)
{}

bch_extent_crc;

#define __entry_to_crc(_entry)

#define entry_to_crc(_entry)

static inline struct bch_extent_crc_unpacked
bch2_extent_crc_unpack(const struct bkey *k, const union bch_extent_crc *crc)
{}

static inline bool crc_is_compressed(struct bch_extent_crc_unpacked crc)
{}

static inline bool crc_is_encoded(struct bch_extent_crc_unpacked crc)
{}

void bch2_extent_crc_unpacked_to_text(struct printbuf *, struct bch_extent_crc_unpacked *);

/* bkey_ptrs: generically over any key type that has ptrs */

struct bkey_ptrs_c {};

struct bkey_ptrs {};

static inline struct bkey_ptrs_c bch2_bkey_ptrs_c(struct bkey_s_c k)
{}

static inline struct bkey_ptrs bch2_bkey_ptrs(struct bkey_s k)
{}

#define __bkey_extent_entry_for_each_from(_start, _end, _entry)

#define __bkey_ptr_next(_ptr, _end)

#define bkey_extent_entry_for_each_from(_p, _entry, _start)

#define bkey_extent_entry_for_each(_p, _entry)

#define __bkey_for_each_ptr(_start, _end, _ptr)

#define bkey_ptr_next(_p, _ptr)

#define bkey_for_each_ptr(_p, _ptr)

#define __bkey_ptr_next_decode(_k, _end, _ptr, _entry)

#define __bkey_for_each_ptr_decode(_k, _start, _end, _ptr, _entry)

#define bkey_for_each_ptr_decode(_k, _p, _ptr, _entry)

#define bkey_crc_next(_k, _start, _end, _crc, _iter)

#define __bkey_for_each_crc(_k, _start, _end, _crc, _iter)

#define bkey_for_each_crc(_k, _p, _crc, _iter)

/* Iterate over pointers in KEY_TYPE_extent: */

#define extent_for_each_entry_from(_e, _entry, _start)

#define extent_for_each_entry(_e, _entry)

#define extent_ptr_next(_e, _ptr)

#define extent_for_each_ptr(_e, _ptr)

#define extent_for_each_ptr_decode(_e, _ptr, _entry)

/* utility code common to all keys with pointers: */

struct bch_dev_io_failures *bch2_dev_io_failures(struct bch_io_failures *,
						 unsigned);
void bch2_mark_io_failure(struct bch_io_failures *,
			  struct extent_ptr_decoded *);
int bch2_bkey_pick_read_device(struct bch_fs *, struct bkey_s_c,
			       struct bch_io_failures *,
			       struct extent_ptr_decoded *);

/* KEY_TYPE_btree_ptr: */

int bch2_btree_ptr_invalid(struct bch_fs *, struct bkey_s_c,
			   enum bch_validate_flags, struct printbuf *);
void bch2_btree_ptr_to_text(struct printbuf *, struct bch_fs *,
			    struct bkey_s_c);

int bch2_btree_ptr_v2_invalid(struct bch_fs *, struct bkey_s_c,
			      enum bch_validate_flags, struct printbuf *);
void bch2_btree_ptr_v2_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
void bch2_btree_ptr_v2_compat(enum btree_id, unsigned, unsigned,
			      int, struct bkey_s);

#define bch2_bkey_ops_btree_ptr

#define bch2_bkey_ops_btree_ptr_v2

/* KEY_TYPE_extent: */

bool bch2_extent_merge(struct bch_fs *, struct bkey_s, struct bkey_s_c);

#define bch2_bkey_ops_extent

/* KEY_TYPE_reservation: */

int bch2_reservation_invalid(struct bch_fs *, struct bkey_s_c,
			     enum bch_validate_flags, struct printbuf *);
void bch2_reservation_to_text(struct printbuf *, struct bch_fs *, struct bkey_s_c);
bool bch2_reservation_merge(struct bch_fs *, struct bkey_s, struct bkey_s_c);

#define bch2_bkey_ops_reservation

/* Extent checksum entries: */

bool bch2_can_narrow_extent_crcs(struct bkey_s_c,
				 struct bch_extent_crc_unpacked);
bool bch2_bkey_narrow_crcs(struct bkey_i *, struct bch_extent_crc_unpacked);
void bch2_extent_crc_append(struct bkey_i *,
			    struct bch_extent_crc_unpacked);

/* Generic code for keys with pointers: */

static inline bool bkey_is_btree_ptr(const struct bkey *k)
{}

static inline bool bkey_extent_is_direct_data(const struct bkey *k)
{}

static inline bool bkey_extent_is_inline_data(const struct bkey *k)
{}

static inline unsigned bkey_inline_data_offset(const struct bkey *k)
{}

static inline unsigned bkey_inline_data_bytes(const struct bkey *k)
{}

#define bkey_inline_data_p(_k)

static inline bool bkey_extent_is_data(const struct bkey *k)
{}

/*
 * Should extent be counted under inode->i_sectors?
 */
static inline bool bkey_extent_is_allocation(const struct bkey *k)
{}

static inline bool bkey_extent_is_unwritten(struct bkey_s_c k)
{}

static inline bool bkey_extent_is_reservation(struct bkey_s_c k)
{}

static inline struct bch_devs_list bch2_bkey_devs(struct bkey_s_c k)
{}

static inline struct bch_devs_list bch2_bkey_dirty_devs(struct bkey_s_c k)
{}

static inline struct bch_devs_list bch2_bkey_cached_devs(struct bkey_s_c k)
{}

unsigned bch2_bkey_nr_ptrs(struct bkey_s_c);
unsigned bch2_bkey_nr_ptrs_allocated(struct bkey_s_c);
unsigned bch2_bkey_nr_ptrs_fully_allocated(struct bkey_s_c);
bool bch2_bkey_is_incompressible(struct bkey_s_c);
unsigned bch2_bkey_sectors_compressed(struct bkey_s_c);

unsigned bch2_bkey_replicas(struct bch_fs *, struct bkey_s_c);
unsigned bch2_extent_ptr_desired_durability(struct bch_fs *, struct extent_ptr_decoded *);
unsigned bch2_extent_ptr_durability(struct bch_fs *, struct extent_ptr_decoded *);
unsigned bch2_bkey_durability(struct bch_fs *, struct bkey_s_c);

void bch2_bkey_drop_device(struct bkey_s, unsigned);
void bch2_bkey_drop_device_noerror(struct bkey_s, unsigned);

const struct bch_extent_ptr *bch2_bkey_has_device_c(struct bkey_s_c, unsigned);

static inline struct bch_extent_ptr *bch2_bkey_has_device(struct bkey_s k, unsigned dev)
{}

bool bch2_bkey_has_target(struct bch_fs *, struct bkey_s_c, unsigned);

void bch2_bkey_extent_entry_drop(struct bkey_i *, union bch_extent_entry *);

static inline void bch2_bkey_append_ptr(struct bkey_i *k, struct bch_extent_ptr ptr)
{}

void bch2_extent_ptr_decoded_append(struct bkey_i *,
				    struct extent_ptr_decoded *);
union bch_extent_entry *bch2_bkey_drop_ptr_noerror(struct bkey_s,
						   struct bch_extent_ptr *);
union bch_extent_entry *bch2_bkey_drop_ptr(struct bkey_s,
					   struct bch_extent_ptr *);

#define bch2_bkey_drop_ptrs(_k, _ptr, _cond)

bool bch2_bkey_matches_ptr(struct bch_fs *, struct bkey_s_c,
			   struct bch_extent_ptr, u64);
bool bch2_extents_match(struct bkey_s_c, struct bkey_s_c);
struct bch_extent_ptr *
bch2_extent_has_ptr(struct bkey_s_c, struct extent_ptr_decoded, struct bkey_s);

void bch2_extent_ptr_set_cached(struct bkey_s, struct bch_extent_ptr *);

bool bch2_extent_normalize(struct bch_fs *, struct bkey_s);
void bch2_extent_ptr_to_text(struct printbuf *out, struct bch_fs *, const struct bch_extent_ptr *);
void bch2_bkey_ptrs_to_text(struct printbuf *, struct bch_fs *,
			    struct bkey_s_c);
int bch2_bkey_ptrs_invalid(struct bch_fs *, struct bkey_s_c,
			   enum bch_validate_flags, struct printbuf *);

void bch2_ptr_swab(struct bkey_s);

const struct bch_extent_rebalance *bch2_bkey_rebalance_opts(struct bkey_s_c);
unsigned bch2_bkey_ptrs_need_rebalance(struct bch_fs *, struct bkey_s_c,
				       unsigned, unsigned);
bool bch2_bkey_needs_rebalance(struct bch_fs *, struct bkey_s_c);

int bch2_bkey_set_needs_rebalance(struct bch_fs *, struct bkey_i *,
				  struct bch_io_opts *);

/* Generic extent code: */

enum bch_extent_overlap {};

/* Returns how k overlaps with m */
static inline enum bch_extent_overlap bch2_extent_overlap(const struct bkey *k,
							  const struct bkey *m)
{}

int bch2_cut_front_s(struct bpos, struct bkey_s);
int bch2_cut_back_s(struct bpos, struct bkey_s);

static inline void bch2_cut_front(struct bpos where, struct bkey_i *k)
{}

static inline void bch2_cut_back(struct bpos where, struct bkey_i *k)
{}

/**
 * bch_key_resize - adjust size of @k
 *
 * bkey_start_offset(k) will be preserved, modifies where the extent ends
 */
static inline void bch2_key_resize(struct bkey *k, unsigned new_size)
{}

#endif /* _BCACHEFS_EXTENTS_H */