txg: generalise txg_wait_synced_sig() to txg_wait_synced_flags() (#17284)

txg_wait_synced_sig() is "wait for txg, unless a signal arrives". We
expect that future development will require similar "wait unless X"
behaviour.

This generalises the API as txg_wait_synced_flags(), where the provided
flags describe the events that should cause the call to return.

Instead of a boolean, the return is now an error code, which the caller
can use to know which event caused the call to return.

The existing call to txg_wait_synced_sig() is now
txg_wait_synced_flags(TXG_WAIT_SIGNAL).

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.

Signed-off-by: Rob Norris <robn@despairlabs.com>
Reviewed-by: Allan Jude <allan@klarasystems.com>
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
This commit is contained in:
Rob Norris
2025-05-03 08:29:50 +10:00
committed by GitHub
parent f85c96edf7
commit a7de203c86
4 changed files with 52 additions and 28 deletions
+20 -3
View File
@@ -66,6 +66,20 @@ typedef struct txg_list {
txg_node_t *tl_head[TXG_SIZE];
} txg_list_t;
/*
* Wait flags for txg_wait_synced_flags(). By default (TXG_WAIT_NONE), it will
* wait until the wanted txg is reached, or block forever. Additional flags
* indicate other conditions that the caller is interested in, that will cause
* the wait to break and return an error code describing the condition.
*/
typedef enum {
/* No special flags. Guaranteed to block forever or return 0 */
TXG_WAIT_NONE = 0,
/* If a signal arrives while waiting, abort and return EINTR */
TXG_WAIT_SIGNAL = (1 << 0),
} txg_wait_flag_t;
struct dsl_pool;
extern void txg_init(struct dsl_pool *dp, uint64_t txg);
@@ -86,13 +100,16 @@ extern void txg_kick(struct dsl_pool *dp, uint64_t txg);
* Try to make this happen as soon as possible (eg. kick off any
* necessary syncs immediately). If txg==0, wait for the currently open
* txg to finish syncing.
* See txg_wait_flag_t above for a description of how the flags affect the wait.
*/
extern void txg_wait_synced(struct dsl_pool *dp, uint64_t txg);
extern int txg_wait_synced_flags(struct dsl_pool *dp, uint64_t txg,
txg_wait_flag_t flags);
/*
* Wait as above. Returns true if the thread was signaled while waiting.
* Traditional form of txg_wait_synced_flags, waits forever.
* Shorthand for VERIFY0(txg_wait_synced_flags(dp, TXG_WAIT_NONE))
*/
extern boolean_t txg_wait_synced_sig(struct dsl_pool *dp, uint64_t txg);
extern void txg_wait_synced(struct dsl_pool *dp, uint64_t txg);
/*
* Wait until the given transaction group, or one after it, is