summaryrefslogtreecommitdiffstats
path: root/fs/bcachefs/bkey_methods.h
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2023-12-27 23:54:52 -0500
committerKent Overstreet <kent.overstreet@linux.dev>2024-01-05 23:24:19 -0500
commitc95e9ec48682425267e682e5489ee9dc42313335 (patch)
tree5577df31b5a83da2633214b061bd6c45462dd8d9 /fs/bcachefs/bkey_methods.h
parent089e311347ebe347a79545ca117a02811623c91e (diff)
downloadlinux-stable-c95e9ec48682425267e682e5489ee9dc42313335.tar.gz
linux-stable-c95e9ec48682425267e682e5489ee9dc42313335.tar.bz2
linux-stable-c95e9ec48682425267e682e5489ee9dc42313335.zip
bcachefs: BTREE_TRIGGER_TRANSACTIONAL
New flag so that triggers can distinguish whether we're running transactional or atomic triggers (or gc) - unifying the callbacks. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/bkey_methods.h')
-rw-r--r--fs/bcachefs/bkey_methods.h26
1 files changed, 22 insertions, 4 deletions
diff --git a/fs/bcachefs/bkey_methods.h b/fs/bcachefs/bkey_methods.h
index 896020055097..d8f42ba1cd0f 100644
--- a/fs/bcachefs/bkey_methods.h
+++ b/fs/bcachefs/bkey_methods.h
@@ -95,11 +95,10 @@ enum btree_update_flags {
__BTREE_UPDATE_NOJOURNAL,
__BTREE_UPDATE_KEY_CACHE_RECLAIM,
- __BTREE_TRIGGER_NORUN, /* Don't run triggers at all */
-
+ __BTREE_TRIGGER_NORUN,
+ __BTREE_TRIGGER_TRANSACTIONAL,
__BTREE_TRIGGER_INSERT,
__BTREE_TRIGGER_OVERWRITE,
-
__BTREE_TRIGGER_GC,
__BTREE_TRIGGER_BUCKET_INVALIDATE,
};
@@ -108,12 +107,31 @@ enum btree_update_flags {
#define BTREE_UPDATE_NOJOURNAL (1U << __BTREE_UPDATE_NOJOURNAL)
#define BTREE_UPDATE_KEY_CACHE_RECLAIM (1U << __BTREE_UPDATE_KEY_CACHE_RECLAIM)
+/* Don't run triggers at all */
#define BTREE_TRIGGER_NORUN (1U << __BTREE_TRIGGER_NORUN)
+/*
+ * If set, we're running transactional triggers as part of a transaction commit:
+ * triggers may generate new updates
+ *
+ * If cleared, and either BTREE_TRIGGER_INSERT|BTREE_TRIGGER_OVERWRITE are set,
+ * we're running atomic triggers during a transaction commit: we have our
+ * journal reservation, we're holding btree node write locks, and we know the
+ * transaction is going to commit (returning an error here is a fatal error,
+ * causing us to go emergency read-only)
+ */
+#define BTREE_TRIGGER_TRANSACTIONAL (1U << __BTREE_TRIGGER_TRANSACTIONAL)
+
+/* @new is entering the btree */
#define BTREE_TRIGGER_INSERT (1U << __BTREE_TRIGGER_INSERT)
+
+/* @old is leaving the btree */
#define BTREE_TRIGGER_OVERWRITE (1U << __BTREE_TRIGGER_OVERWRITE)
+/* We're in gc/fsck: running triggers to recalculate e.g. disk usage */
#define BTREE_TRIGGER_GC (1U << __BTREE_TRIGGER_GC)
+
+/* signal from bucket invalidate path to alloc trigger */
#define BTREE_TRIGGER_BUCKET_INVALIDATE (1U << __BTREE_TRIGGER_BUCKET_INVALIDATE)
static inline int bch2_trans_mark_key(struct btree_trans *trans,
@@ -124,7 +142,7 @@ static inline int bch2_trans_mark_key(struct btree_trans *trans,
const struct bkey_ops *ops = bch2_bkey_type_ops(old.k->type ?: new.k->type);
return ops->trans_trigger
- ? ops->trans_trigger(trans, btree_id, level, old, new, flags)
+ ? ops->trans_trigger(trans, btree_id, level, old, new, flags|BTREE_TRIGGER_TRANSACTIONAL)
: 0;
}