diff mbox series

[25/38] btrfs-progs: add kerncompat helpers for ctree.c sync

Message ID 3de4bf57a30d11793cfd46f59d27f03233ff2451.1692800904.git.josef@toxicpanda.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: sync ctree.c into btrfs-progs | expand

Commit Message

Josef Bacik Aug. 23, 2023, 2:32 p.m. UTC
Here are the helpers and stubbed out functions to be able to sync in
ctree.c into btrfs-progs.  These are various utilities the kernel
provides, 1 relocation and qgroup related function, and a trace point we
have in ctree.c.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 include/kerncompat.h | 76 ++++++++++++++++++++++++++++++++++++++++++++
 kernel-lib/trace.h   |  6 ++++
 2 files changed, 82 insertions(+)
diff mbox series

Patch

diff --git a/include/kerncompat.h b/include/kerncompat.h
index 0f73efcd..4ba6b3dc 100644
--- a/include/kerncompat.h
+++ b/include/kerncompat.h
@@ -201,6 +201,10 @@  typedef struct spinlock_struct {
 	unsigned long lock;
 } spinlock_t;
 
+struct rw_semaphore {
+	long lock;
+};
+
 #define mutex_init(m)						\
 do {								\
 	(m)->lock = 1;						\
@@ -243,6 +247,27 @@  static inline void spin_unlock_irqrestore(spinlock_t *lock, unsigned long flags)
 	spin_unlock(lock);
 }
 
+static inline void init_rwsem(struct rw_semaphore *sem)
+{
+	sem->lock = 0;
+}
+
+static inline bool down_read_trylock(struct rw_semaphore *sem)
+{
+	sem->lock++;
+	return true;
+}
+
+static inline void down_read(struct rw_semaphore *sem)
+{
+	sem->lock++;
+}
+
+static inline void up_read(struct rw_semaphore *sem)
+{
+	sem->lock--;
+}
+
 #define cond_resched()		do { } while (0)
 #define preempt_enable()	do { } while (0)
 #define preempt_disable()	do { } while (0)
@@ -400,6 +425,11 @@  static inline void *kmem_cache_alloc(struct kmem_cache *cache, gfp_t mask)
 	return malloc(cache->size);
 }
 
+static inline void *kmem_cache_zalloc(struct kmem_cache *cache, gfp_t mask)
+{
+	return calloc(1, cache->size);
+}
+
 static inline void kmem_cache_free(struct kmem_cache *cache, void *ptr)
 {
 	free(ptr);
@@ -704,6 +734,10 @@  static inline bool sb_rdonly(struct super_block *sb)
 
 #define unlikely(cond) (cond)
 
+#define rcu_dereference(c) (c)
+
+#define rcu_assign_pointer(p, v) do { (p) = (v); } while (0)
+
 static inline void atomic_set(atomic_t *a, int val)
 {
 	*a = val;
@@ -724,6 +758,15 @@  static inline void atomic_dec(atomic_t *a)
 	(*a)--;
 }
 
+static inline bool atomic_inc_not_zero(atomic_t *a)
+{
+	if (*a) {
+		atomic_inc(a);
+		return true;
+	}
+	return false;
+}
+
 static inline struct workqueue_struct *alloc_workqueue(const char *name,
 						       unsigned long flags,
 						       int max_active, ...)
@@ -766,6 +809,10 @@  static inline void lockdep_set_class(spinlock_t *lock, struct lock_class_key *lc
 {
 }
 
+static inline void lockdep_assert_held_read(struct rw_semaphore *sem)
+{
+}
+
 static inline bool cond_resched_lock(spinlock_t *lock)
 {
 	return false;
@@ -800,11 +847,26 @@  static inline void schedule(void)
 {
 }
 
+static inline void rcu_read_lock(void)
+{
+}
+
+static inline void rcu_read_unlock(void)
+{
+}
+
+static inline void synchronize_rcu(void)
+{
+}
+
 /*
  * Temporary definitions while syncing.
  */
 struct btrfs_inode;
 struct extent_state;
+struct extent_buffer;
+struct btrfs_root;
+struct btrfs_trans_handle;
 
 static inline void btrfs_merge_delalloc_extent(struct btrfs_inode *inode,
 					       struct extent_state *state,
@@ -830,4 +892,18 @@  static inline void btrfs_clear_delalloc_extent(struct btrfs_inode *inode,
 {
 }
 
+static inline int btrfs_reloc_cow_block(struct btrfs_trans_handle *trans,
+					struct btrfs_root *root,
+					struct extent_buffer *buf,
+					struct extent_buffer *cow)
+{
+	return 0;
+}
+
+static inline void btrfs_qgroup_trace_subtree_after_cow(struct btrfs_trans_handle *trans,
+							struct btrfs_root *root,
+							struct extent_buffer *buf)
+{
+}
+
 #endif
diff --git a/kernel-lib/trace.h b/kernel-lib/trace.h
index 588429e0..2542f9ea 100644
--- a/kernel-lib/trace.h
+++ b/kernel-lib/trace.h
@@ -57,4 +57,10 @@  static inline void trace_btrfs_convert_extent_bit(struct extent_io_tree *tree,
 {
 }
 
+static inline void trace_btrfs_cow_block(struct btrfs_root *root,
+					 struct extent_buffer *buf,
+					 struct extent_buffer *cow)
+{
+}
+
 #endif /* __PROGS_TRACE_H__ */