From 34e6efd39cc1add3bb722a176aa17dc921d983c7 Mon Sep 17 00:00:00 2001 From: Auke Kok Date: Wed, 10 May 2023 19:30:29 -0400 Subject: [PATCH] Adjust for new augmented rbtree compute callback function signature The new variant of the code that recomputes the augmented value is designed to handle non-scalar types and to facilitate that, it has new semantics for the _compute callback. It is now passed a boolean flag `exit` that indicates that if the value isn't changed, it should exit and halt propagation. The callback function now shall return whether that propagation should stop or not, and not the computed new value. The callback can now directly update the new computed value in the node. Signed-off-by: Auke Kok --- kmod/src/Makefile.kernelcompat | 10 ++++++++++ kmod/src/tseq.c | 20 +++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/kmod/src/Makefile.kernelcompat b/kmod/src/Makefile.kernelcompat index fab13456..896b7117 100644 --- a/kmod/src/Makefile.kernelcompat +++ b/kmod/src/Makefile.kernelcompat @@ -53,3 +53,13 @@ endif ifneq (,$(shell grep 'posix_acl_valid.*user_ns,' include/linux/posix_acl.h)) ccflags-y += -DKC_POSIX_ACL_VALID_USER_NS endif + +# +# v5.3-12296-g6d2052d188d9 +# +# The RBCOMPUTE function is now passed an extra flag, and should return a bool +# to indicate whether the propagated callback should stop or not. +# +ifneq (,$(shell grep 'static inline bool RBNAME.*_compute_max' include/linux/rbtree_augmented.h)) +ccflags-y += -DKC_RB_TREE_AUGMENTED_COMPUTE_MAX +endif diff --git a/kmod/src/tseq.c b/kmod/src/tseq.c index 781d00f3..b4b07f34 100644 --- a/kmod/src/tseq.c +++ b/kmod/src/tseq.c @@ -46,6 +46,23 @@ static struct scoutfs_tseq_entry *tseq_rb_next(struct scoutfs_tseq_entry *ent) return rb_entry(node, struct scoutfs_tseq_entry, node); } +#ifdef KC_RB_TREE_AUGMENTED_COMPUTE_MAX +static bool tseq_compute_total(struct scoutfs_tseq_entry *ent, bool exit) +{ + loff_t total = 1 + tseq_node_total(ent->node.rb_left) + + tseq_node_total(ent->node.rb_right); + + if (exit && ent->total == total) + return true; + + ent->total = total; + return false; +} + +RB_DECLARE_CALLBACKS(static, tseq_rb_callbacks, struct scoutfs_tseq_entry, + node, total, tseq_compute_total); +#else + static loff_t tseq_compute_total(struct scoutfs_tseq_entry *ent) { return 1 + tseq_node_total(ent->node.rb_left) + @@ -53,7 +70,8 @@ static loff_t tseq_compute_total(struct scoutfs_tseq_entry *ent) } RB_DECLARE_CALLBACKS(static, tseq_rb_callbacks, struct scoutfs_tseq_entry, - node, loff_t, total, tseq_compute_total) + node, loff_t, total, tseq_compute_total); +#endif void scoutfs_tseq_tree_init(struct scoutfs_tseq_tree *tree, scoutfs_tseq_show_t show)