Skip to content

Commit eedfa90

Browse files
committed
Make AIO handle callbacks extensible
The pg_tde extension's custom storage manager needs to add its own AIO callback to decrypt pages before the buffer manager's callback is called but since the set of AIO callbacks is fixed we need to expose this API so that extensions can register their own types of callbacks. This new function for registering a callback is supposed to be called when intializing shared memory. We try to keep the number of callbacks low, setting it to 15, so that we have the 4 built-in callbacks and 11 slots that extensions can use.
1 parent d05cdb1 commit eedfa90

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/backend/storage/aio/aio_callback.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ static const PgAioHandleCallbacks aio_invalid_cb = {0};
2727

2828
typedef struct PgAioHandleCallbacksEntry
2929
{
30-
const PgAioHandleCallbacks *const cb;
31-
const char *const name;
30+
const PgAioHandleCallbacks *cb;
31+
const char *name;
3232
} PgAioHandleCallbacksEntry;
3333

3434
/*
3535
* Callback definition for the callbacks that can be registered on an IO
3636
* handle. See PgAioHandleCallbackID's definition for an explanation for why
3737
* callbacks are not identified by a pointer.
3838
*/
39-
static const PgAioHandleCallbacksEntry aio_handle_cbs[] = {
39+
static PgAioHandleCallbacksEntry aio_handle_cbs[PGAIO_HCB_MAX] = {
4040
#define CALLBACK_ENTRY(id, callback) [id] = {.cb = &callback, .name = #callback}
4141
CALLBACK_ENTRY(PGAIO_HCB_INVALID, aio_invalid_cb),
4242

@@ -48,7 +48,21 @@ static const PgAioHandleCallbacksEntry aio_handle_cbs[] = {
4848
#undef CALLBACK_ENTRY
4949
};
5050

51+
static PgAioHandleCallbackID aio_handle_max_cb_id = PGAIO_HCB_LOCAL_BUFFER_READV;
5152

53+
PgAioHandleCallbackID
54+
pgaio_io_register_callback_entry(const PgAioHandleCallbacks *callback, const char *name)
55+
{
56+
PgAioHandleCallbackID cb_id = ++aio_handle_max_cb_id;
57+
58+
if (cb_id > PGAIO_HCB_MAX)
59+
elog(FATAL, "There can be at most %d AIO callback entries", PGAIO_HCB_MAX);
60+
61+
aio_handle_cbs[cb_id].cb = callback;
62+
aio_handle_cbs[cb_id].name = name;
63+
64+
return cb_id;
65+
}
5266

5367
/* --------------------------------------------------------------------------------
5468
* Public callback related functions operating on IO Handles

src/include/storage/aio.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ typedef enum PgAioHandleCallbackID
200200
PGAIO_HCB_LOCAL_BUFFER_READV,
201201
} PgAioHandleCallbackID;
202202

203-
#define PGAIO_HCB_MAX PGAIO_HCB_LOCAL_BUFFER_READV
203+
#define PGAIO_HCB_MAX 15
204204
StaticAssertDecl(PGAIO_HCB_MAX < (1 << PGAIO_RESULT_ID_BITS),
205205
"PGAIO_HCB_MAX is too big for PGAIO_RESULT_ID_BITS");
206206

@@ -308,6 +308,7 @@ extern PgAioTargetData *pgaio_io_get_target_data(PgAioHandle *ioh);
308308
extern char *pgaio_io_get_target_description(PgAioHandle *ioh);
309309

310310
/* functions in aio_callback.c */
311+
extern PgAioHandleCallbackID pgaio_io_register_callback_entry(const PgAioHandleCallbacks *callback, const char *name);
311312
extern void pgaio_io_register_callbacks(PgAioHandle *ioh, PgAioHandleCallbackID cb_id,
312313
uint8 cb_data);
313314
extern void pgaio_io_set_handle_data_64(PgAioHandle *ioh, uint64 *data, uint8 len);

0 commit comments

Comments
 (0)