PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
aio_target.c
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * aio_target.c
4 * AIO - Functionality related to executing IO for different targets
5 *
6 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
8 *
9 * IDENTIFICATION
10 * src/backend/storage/aio/aio_target.c
11 *
12 *-------------------------------------------------------------------------
13 */
14
15#include "postgres.h"
16
17#include "storage/aio.h"
19
20
21/*
22 * Registry for entities that can be the target of AIO.
23 */
26 .name = "invalid",
27 },
28};
29
30
31
32/* --------------------------------------------------------------------------------
33 * Public target related functions operating on IO Handles
34 * --------------------------------------------------------------------------------
35 */
36
37bool
39{
40 return ioh->target != PGAIO_TID_INVALID;
41}
42
43/*
44 * Return the name for the target associated with the IO. Mostly useful for
45 * debugging/logging.
46 */
47const char *
49{
50 Assert(ioh->target >= 0 && ioh->target < PGAIO_TID_COUNT);
51
52 return pgaio_target_info[ioh->target]->name;
53}
54
55/*
56 * Assign a target to the IO.
57 *
58 * This has to be called exactly once before pgaio_io_start_*() is called.
59 */
60void
62{
65
66 ioh->target = targetid;
67}
68
71{
72 return &ioh->target_data;
73}
74
75/*
76 * Return a stringified description of the IO's target.
77 *
78 * The string is localized and allocated in the current memory context.
79 */
80char *
82{
84}
85
86
87
88/* --------------------------------------------------------------------------------
89 * Internal target related functions operating on IO Handles
90 * --------------------------------------------------------------------------------
91 */
92
93/*
94 * Internal: Check if pgaio_io_reopen() is available for the IO.
95 */
96bool
98{
99 return pgaio_target_info[ioh->target]->reopen != NULL;
100}
101
102/*
103 * Internal: Before executing an IO outside of the context of the process the
104 * IO has been staged in, the file descriptor has to be reopened - any FD
105 * referenced in the IO itself, won't be valid in the separate process.
106 */
107void
109{
110 Assert(ioh->target >= 0 && ioh->target < PGAIO_TID_COUNT);
111 Assert(ioh->op >= 0 && ioh->op < PGAIO_OP_COUNT);
112
113 pgaio_target_info[ioh->target]->reopen(ioh);
114}
#define PGAIO_TID_COUNT
Definition: aio.h:122
#define PGAIO_OP_COUNT
Definition: aio.h:107
PgAioTargetID
Definition: aio.h:117
@ PGAIO_TID_INVALID
Definition: aio.h:119
@ PGAIO_HS_HANDED_OUT
Definition: aio_internal.h:48
PgAioTargetData * pgaio_io_get_target_data(PgAioHandle *ioh)
Definition: aio_target.c:70
static const PgAioTargetInfo * pgaio_target_info[]
Definition: aio_target.c:24
void pgaio_io_reopen(PgAioHandle *ioh)
Definition: aio_target.c:108
bool pgaio_io_can_reopen(PgAioHandle *ioh)
Definition: aio_target.c:97
bool pgaio_io_has_target(PgAioHandle *ioh)
Definition: aio_target.c:38
const char * pgaio_io_get_target_name(PgAioHandle *ioh)
Definition: aio_target.c:48
char * pgaio_io_get_target_description(PgAioHandle *ioh)
Definition: aio_target.c:81
void pgaio_io_set_target(PgAioHandle *ioh, PgAioTargetID targetid)
Definition: aio_target.c:61
struct PgAioTargetInfo PgAioTargetInfo
Definition: aio_types.h:24
Assert(PointerIsAligned(start, uint64))
PgAioTargetData target_data
Definition: aio_internal.h:176
PgAioOp op
Definition: aio_internal.h:100
PgAioHandleState state
Definition: aio_internal.h:94
PgAioTargetID target
Definition: aio_internal.h:97
void(* reopen)(PgAioHandle *ioh)
Definition: aio.h:163
char *(* describe_identity)(const PgAioTargetData *sd)
Definition: aio.h:166
const char * name
Definition: aio.h:169