#ifndef AIO_H
#define AIO_H
#include "storage/aio_types.h"
#include "storage/procnumber.h"
#if defined(USE_LIBURING) && !defined(EXEC_BACKEND)
#define IOMETHOD_IO_URING_ENABLED
#endif
typedef enum IoMethod
{
IOMETHOD_SYNC = 0,
IOMETHOD_WORKER,
#ifdef IOMETHOD_IO_URING_ENABLED
IOMETHOD_IO_URING,
#endif
} IoMethod;
#define DEFAULT_IO_METHOD IOMETHOD_WORKER
typedef enum PgAioHandleFlags
{
PGAIO_HF_REFERENCES_LOCAL = 1 << 1,
PGAIO_HF_SYNCHRONOUS = 1 << 0,
PGAIO_HF_BUFFERED = 1 << 2,
} PgAioHandleFlags;
typedef enum PgAioOp
{
PGAIO_OP_INVALID = 0,
PGAIO_OP_READV,
PGAIO_OP_WRITEV,
} PgAioOp;
#define PGAIO_OP_COUNT (PGAIO_OP_WRITEV + 1)
typedef enum PgAioTargetID
{
PGAIO_TID_INVALID = 0,
PGAIO_TID_SMGR,
} PgAioTargetID;
#define PGAIO_TID_COUNT (PGAIO_TID_SMGR + 1)
typedef union
{
struct
{
int fd;
uint16 iov_length;
uint64 offset;
} read;
struct
{
int fd;
uint16 iov_length;
uint64 offset;
} write;
} PgAioOpData;
struct PgAioTargetInfo
{
void (*reopen) (PgAioHandle *ioh);
char *(*describe_identity) (const PgAioTargetData *sd);
const char *name;
};
typedef enum PgAioHandleCallbackID
{
PGAIO_HCB_INVALID = 0,
PGAIO_HCB_MD_READV,
PGAIO_HCB_SHARED_BUFFER_READV,
PGAIO_HCB_LOCAL_BUFFER_READV,
} PgAioHandleCallbackID;
#define PGAIO_HCB_MAX PGAIO_HCB_LOCAL_BUFFER_READV
StaticAssertDecl(PGAIO_HCB_MAX < (1 << PGAIO_RESULT_ID_BITS),
"PGAIO_HCB_MAX is too big for PGAIO_RESULT_ID_BITS");
typedef void (*PgAioHandleCallbackStage) (PgAioHandle *ioh, uint8 cb_flags);
typedef PgAioResult (*PgAioHandleCallbackComplete) (PgAioHandle *ioh, PgAioResult prior_result, uint8 cb_flags);
typedef void (*PgAioHandleCallbackReport) (PgAioResult result, const PgAioTargetData *target_data, int elevel);
struct PgAioHandleCallbacks
{
PgAioHandleCallbackStage stage;
PgAioHandleCallbackComplete complete_shared;
PgAioHandleCallbackComplete complete_local;
PgAioHandleCallbackReport report;
};
#define PGAIO_HANDLE_MAX_CALLBACKS 4
struct ResourceOwnerData;
extern PgAioHandle *pgaio_io_acquire(struct ResourceOwnerData *resowner, PgAioReturn *ret);
extern PgAioHandle *pgaio_io_acquire_nb(struct ResourceOwnerData *resowner, PgAioReturn *ret);
extern void pgaio_io_release(PgAioHandle *ioh);
struct dlist_node;
extern void pgaio_io_release_resowner(struct dlist_node *ioh_node, bool on_error);
extern void pgaio_io_set_flag(PgAioHandle *ioh, PgAioHandleFlags flag);
extern int pgaio_io_get_id(PgAioHandle *ioh);
extern ProcNumber pgaio_io_get_owner(PgAioHandle *ioh);
extern void pgaio_io_get_wref(PgAioHandle *ioh, PgAioWaitRef *iow);
struct iovec;
extern int pgaio_io_get_iovec(PgAioHandle *ioh, struct iovec **iov);
extern PgAioOp pgaio_io_get_op(PgAioHandle *ioh);
extern PgAioOpData *pgaio_io_get_op_data(PgAioHandle *ioh);
extern void pgaio_io_start_readv(PgAioHandle *ioh,
int fd, int iovcnt, uint64 offset);
extern void pgaio_io_start_writev(PgAioHandle *ioh,
int fd, int iovcnt, uint64 offset);
extern void pgaio_io_set_target(PgAioHandle *ioh, PgAioTargetID targetid);
extern bool pgaio_io_has_target(PgAioHandle *ioh);
extern PgAioTargetData *pgaio_io_get_target_data(PgAioHandle *ioh);
extern char *pgaio_io_get_target_description(PgAioHandle *ioh);
extern void pgaio_io_register_callbacks(PgAioHandle *ioh, PgAioHandleCallbackID cb_id,
uint8 cb_data);
extern void pgaio_io_set_handle_data_64(PgAioHandle *ioh, uint64 *data, uint8 len);
extern void pgaio_io_set_handle_data_32(PgAioHandle *ioh, uint32 *data, uint8 len);
extern uint64 *pgaio_io_get_handle_data(PgAioHandle *ioh, uint8 *len);
extern void pgaio_wref_clear(PgAioWaitRef *iow);
extern bool pgaio_wref_valid(PgAioWaitRef *iow);
extern int pgaio_wref_get_id(PgAioWaitRef *iow);
extern void pgaio_wref_wait(PgAioWaitRef *iow);
extern bool pgaio_wref_check_done(PgAioWaitRef *iow);
extern void pgaio_result_report(PgAioResult result, const PgAioTargetData *target_data,
int elevel);
extern void pgaio_enter_batchmode(void);
extern void pgaio_exit_batchmode(void);
extern void pgaio_submit_staged(void);
extern bool pgaio_have_staged(void);
extern void pgaio_closing_fd(int fd);
extern PGDLLIMPORT int io_method;
extern PGDLLIMPORT int io_max_concurrency;
#endif