linux/fs/bcachefs/util.h

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

#include <linux/bio.h>
#include <linux/blkdev.h>
#include <linux/closure.h>
#include <linux/errno.h>
#include <linux/freezer.h>
#include <linux/kernel.h>
#include <linux/min_heap.h>
#include <linux/sched/clock.h>
#include <linux/llist.h>
#include <linux/log2.h>
#include <linux/percpu.h>
#include <linux/preempt.h>
#include <linux/ratelimit.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>
#include <linux/workqueue.h>

#include "mean_and_variance.h"

#include "darray.h"
#include "time_stats.h"

struct closure;

#ifdef CONFIG_BCACHEFS_DEBUG
#define EBUG_ON(cond)
#else
#define EBUG_ON
#endif

#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define CPU_BIG_ENDIAN
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
#define CPU_BIG_ENDIAN
#endif

/* type hackery */

#define type_is_exact(_val, _type)

#define type_is(_val, _type)

/* Userspace doesn't align allocations as nicely as the kernel allocators: */
static inline size_t buf_pages(void *p, size_t len)
{}

#define init_heap(heap, _size, gfp)

#define free_heap(heap)

#define ANYSINT_MAX(t)

#include "printbuf.h"

#define prt_vprintf(_out, ...)
#define prt_printf(_out, ...)
#define printbuf_str(_buf)
#define printbuf_exit(_buf)

#define printbuf_tabstops_reset(_buf)
#define printbuf_tabstop_pop(_buf)
#define printbuf_tabstop_push(_buf, _n)

#define printbuf_indent_add(_out, _n)
#define printbuf_indent_sub(_out, _n)

#define prt_newline(_out)
#define prt_tab(_out)
#define prt_tab_rjust(_out)

#define prt_bytes_indented(...)
#define prt_u64(_out, _v)
#define prt_human_readable_u64(...)
#define prt_human_readable_s64(...)
#define prt_units_u64(...)
#define prt_units_s64(...)
#define prt_string_option(...)
#define prt_bitflags(...)
#define prt_bitflags_vector(...)

void bch2_pr_time_units(struct printbuf *, u64);
void bch2_prt_datetime(struct printbuf *, time64_t);

#ifdef __KERNEL__
static inline void uuid_unparse_lower(u8 *uuid, char *out)
{}
#else
#include <uuid/uuid.h>
#endif

static inline void pr_uuid(struct printbuf *out, u8 *uuid)
{}

int bch2_strtoint_h(const char *, int *);
int bch2_strtouint_h(const char *, unsigned int *);
int bch2_strtoll_h(const char *, long long *);
int bch2_strtoull_h(const char *, unsigned long long *);
int bch2_strtou64_h(const char *, u64 *);

static inline int bch2_strtol_h(const char *cp, long *res)
{}

static inline int bch2_strtoul_h(const char *cp, long *res)
{}

#define strtoi_h(cp, res)

#define strtoul_safe(cp, var)

#define strtoul_safe_clamp(cp, var, min, max)

#define strtoul_safe_restrict(cp, var, min, max)

#define snprint(out, var)

bool bch2_is_zero(const void *, size_t);

u64 bch2_read_flag_list(char *, const char * const[]);

void bch2_prt_u64_base2_nbits(struct printbuf *, u64, unsigned);
void bch2_prt_u64_base2(struct printbuf *, u64);

void bch2_print_string_as_lines(const char *prefix, const char *lines);
void bch2_print_string_as_lines_nonblocking(const char *prefix, const char *lines);

bch_stacktrace;
int bch2_save_backtrace(bch_stacktrace *stack, struct task_struct *, unsigned, gfp_t);
void bch2_prt_backtrace(struct printbuf *, bch_stacktrace *);
int bch2_prt_task_backtrace(struct printbuf *, struct task_struct *, unsigned, gfp_t);

static inline void prt_bdevname(struct printbuf *out, struct block_device *bdev)
{}

void bch2_time_stats_to_text(struct printbuf *, struct bch2_time_stats *);

#define ewma_add(ewma, val, weight)

struct bch_ratelimit {};

static inline void bch2_ratelimit_reset(struct bch_ratelimit *d)
{}

u64 bch2_ratelimit_delay(struct bch_ratelimit *);
void bch2_ratelimit_increment(struct bch_ratelimit *, u64);

struct bch_pd_controller {};

void bch2_pd_controller_update(struct bch_pd_controller *, s64, s64, int);
void bch2_pd_controller_init(struct bch_pd_controller *);
void bch2_pd_controller_debug_to_text(struct printbuf *, struct bch_pd_controller *);

#define sysfs_pd_controller_attribute(name)

#define sysfs_pd_controller_files(name)

#define sysfs_pd_controller_show(name, var)

#define sysfs_pd_controller_store(name, var)

#define container_of_or_null(ptr, type, member)

/* Does linear interpolation between powers of two */
static inline unsigned fract_exp_two(unsigned x, unsigned fract_bits)
{}

void bch2_bio_map(struct bio *bio, void *base, size_t);
int bch2_bio_alloc_pages(struct bio *, size_t, gfp_t);

#define closure_bio_submit(bio, cl)

#define kthread_wait(cond)

#define kthread_wait_freezable(cond)

size_t bch2_rand_range(size_t);

void memcpy_to_bio(struct bio *, struct bvec_iter, const void *);
void memcpy_from_bio(void *, struct bio *, struct bvec_iter);

static inline void memcpy_u64s_small(void *dst, const void *src,
				     unsigned u64s)
{}

static inline void __memcpy_u64s(void *dst, const void *src,
				 unsigned u64s)
{}

static inline void memcpy_u64s(void *dst, const void *src,
			       unsigned u64s)
{}

static inline void __memmove_u64s_down(void *dst, const void *src,
				       unsigned u64s)
{}

static inline void memmove_u64s_down(void *dst, const void *src,
				     unsigned u64s)
{}

static inline void __memmove_u64s_down_small(void *dst, const void *src,
				       unsigned u64s)
{}

static inline void memmove_u64s_down_small(void *dst, const void *src,
				     unsigned u64s)
{}

static inline void __memmove_u64s_up_small(void *_dst, const void *_src,
					   unsigned u64s)
{}

static inline void memmove_u64s_up_small(void *dst, const void *src,
					 unsigned u64s)
{}

static inline void __memmove_u64s_up(void *_dst, const void *_src,
				     unsigned u64s)
{}

static inline void memmove_u64s_up(void *dst, const void *src,
				   unsigned u64s)
{}

static inline void memmove_u64s(void *dst, const void *src,
				unsigned u64s)
{}

/* Set the last few bytes up to a u64 boundary given an offset into a buffer. */
static inline void memset_u64s_tail(void *s, int c, unsigned bytes)
{}

/* just the memmove, doesn't update @_nr */
#define __array_insert_item(_array, _nr, _pos)

#define array_insert_item(_array, _nr, _pos, _new_item)

#define array_remove_items(_array, _nr, _pos, _nr_to_remove)

#define array_remove_item(_array, _nr, _pos)

static inline void __move_gap(void *array, size_t element_size,
			      size_t nr, size_t size,
			      size_t old_gap, size_t new_gap)
{}

/* Move the gap in a gap buffer: */
#define move_gap(_d, _new_gap)

#define bubble_sort(_base, _nr, _cmp)

#define per_cpu_sum(_p)

static inline u64 percpu_u64_get(u64 __percpu *src)
{}

static inline void percpu_u64_set(u64 __percpu *dst, u64 src)
{}

static inline void acc_u64s(u64 *acc, const u64 *src, unsigned nr)
{}

static inline void acc_u64s_percpu(u64 *acc, const u64 __percpu *src,
				   unsigned nr)
{}

static inline void percpu_memset(void __percpu *p, int c, size_t bytes)
{}

u64 *bch2_acc_percpu_u64s(u64 __percpu *, unsigned);

#define cmp_int(l, r)

static inline int u8_cmp(u8 l, u8 r)
{}

static inline int cmp_le32(__le32 l, __le32 r)
{}

#include <linux/uuid.h>

#define QSTR(n)

static inline bool qstr_eq(const struct qstr l, const struct qstr r)
{}

void bch2_darray_str_exit(darray_str *);
int bch2_split_devs(const char *, darray_str *);

#ifdef __KERNEL__

__must_check
static inline int copy_to_user_errcode(void __user *to, const void *from, unsigned long n)
{}

__must_check
static inline int copy_from_user_errcode(void *to, const void __user *from, unsigned long n)
{}

#endif

static inline void mod_bit(long nr, volatile unsigned long *addr, bool v)
{}

static inline void __set_bit_le64(size_t bit, __le64 *addr)
{}

static inline void __clear_bit_le64(size_t bit, __le64 *addr)
{}

static inline bool test_bit_le64(size_t bit, __le64 *addr)
{}

#endif /* _BCACHEFS_UTIL_H */