PostgreSQL Source Code git master
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#include "storage/smgr.h"
20
21
22/*
23 * Registry for entities that can be the target of AIO.
24 */
27 .name = "invalid",
28 },
30};
31
32
33
34/* --------------------------------------------------------------------------------
35 * Public target related functions operating on IO Handles
36 * --------------------------------------------------------------------------------
37 */
38
39bool
41{
42 return ioh->target != PGAIO_TID_INVALID;
43}
44
45/*
46 * Return the name for the target associated with the IO. Mostly useful for
47 * debugging/logging.
48 */
49const char *
51{
52 /* explicitly allow INVALID here, function used by debug messages */
54
55 return pgaio_target_info[ioh->target]->name;
56}
57
58/*
59 * Assign a target to the IO.
60 *
61 * This has to be called exactly once before pgaio_io_start_*() is called.
62 */
63void
65{
68
69 ioh->target = targetid;
70}
71
74{
75 return &ioh->target_data;
76}
77
78/*
79 * Return a stringified description of the IO's target.
80 *
81 * The string is localized and allocated in the current memory context.
82 */
83char *
85{
86 /* disallow INVALID, there wouldn't be a description */
88
90}
91
92
93
94/* --------------------------------------------------------------------------------
95 * Internal target related functions operating on IO Handles
96 * --------------------------------------------------------------------------------
97 */
98
99/*
100 * Internal: Check if pgaio_io_reopen() is available for the IO.
101 */
102bool
104{
106
107 return pgaio_target_info[ioh->target]->reopen != NULL;
108}
109
110/*
111 * Internal: Before executing an IO outside of the context of the process the
112 * IO has been staged in, the file descriptor has to be reopened - any FD
113 * referenced in the IO itself, won't be valid in the separate process.
114 */
115void
117{
119 Assert(ioh->op > PGAIO_OP_INVALID && ioh->op < PGAIO_OP_COUNT);
120
121 pgaio_target_info[ioh->target]->reopen(ioh);
122}
#define PGAIO_TID_COUNT
Definition: aio.h:123
#define PGAIO_OP_COUNT
Definition: aio.h:107
PgAioTargetID
Definition: aio.h:117
@ PGAIO_TID_SMGR
Definition: aio.h:120
@ PGAIO_TID_INVALID
Definition: aio.h:119
@ PGAIO_OP_INVALID
Definition: aio.h:90
@ PGAIO_HS_HANDED_OUT
Definition: aio_internal.h:53
PgAioTargetData * pgaio_io_get_target_data(PgAioHandle *ioh)
Definition: aio_target.c:73
static const PgAioTargetInfo * pgaio_target_info[]
Definition: aio_target.c:25
void pgaio_io_reopen(PgAioHandle *ioh)
Definition: aio_target.c:116
bool pgaio_io_can_reopen(PgAioHandle *ioh)
Definition: aio_target.c:103
bool pgaio_io_has_target(PgAioHandle *ioh)
Definition: aio_target.c:40
const char * pgaio_io_get_target_name(PgAioHandle *ioh)
Definition: aio_target.c:50
char * pgaio_io_get_target_description(PgAioHandle *ioh)
Definition: aio_target.c:84
void pgaio_io_set_target(PgAioHandle *ioh, PgAioTargetID targetid)
Definition: aio_target.c:64
struct PgAioTargetInfo PgAioTargetInfo
Definition: aio_types.h:24
Assert(PointerIsAligned(start, uint64))
const PgAioTargetInfo aio_smgr_target_info
Definition: smgr.c:172
PgAioTargetData target_data
Definition: aio_internal.h:181
PgAioOp op
Definition: aio_internal.h:105
PgAioHandleState state
Definition: aio_internal.h:99
PgAioTargetID target
Definition: aio_internal.h:102
void(* reopen)(PgAioHandle *ioh)
Definition: aio.h:164
char *(* describe_identity)(const PgAioTargetData *sd)
Definition: aio.h:167
const char * name
Definition: aio.h:170