PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
aio_types.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * aio_types.h
4 * AIO related types that are useful to include separately, to reduce the
5 * "include burden".
6 *
7 *
8 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
9 * Portions Copyright (c) 1994, Regents of the University of California
10 *
11 * src/include/storage/aio_types.h
12 *
13 *-------------------------------------------------------------------------
14 */
15#ifndef AIO_TYPES_H
16#define AIO_TYPES_H
17
18#include "storage/block.h"
20
21
22typedef struct PgAioHandle PgAioHandle;
25
26/*
27 * A reference to an IO that can be used to wait for the IO (using
28 * pgaio_wref_wait()) to complete.
29 *
30 * These can be passed across process boundaries.
31 */
32typedef struct PgAioWaitRef
33{
34 /* internal ID identifying the specific PgAioHandle */
36
37 /*
38 * IO handles are reused. To detect if a handle was reused, and thereby
39 * avoid unnecessarily waiting for a newer IO, each time the handle is
40 * reused a generation number is increased.
41 *
42 * To avoid requiring alignment sufficient for an int64, split the
43 * generation into two.
44 */
48
49
50/*
51 * Information identifying what the IO is being performed on.
52 *
53 * This needs sufficient information to
54 *
55 * a) Reopen the file for the IO if the IO is executed in a context that
56 * cannot use the FD provided initially (e.g. because the IO is executed in
57 * a worker process).
58 *
59 * b) Describe the object the IO is performed on in log / error messages.
60 */
61typedef union PgAioTargetData
62{
63 struct
64 {
65 RelFileLocator rlocator; /* physical relation identifier */
66 BlockNumber blockNum; /* blknum relative to begin of reln */
68 ForkNumber forkNum:8; /* don't waste 4 byte for four values */
69 bool is_temp:1; /* proc can be inferred by owning AIO */
70 bool skip_fsync:1;
73
74
75/*
76 * The status of an AIO operation.
77 */
79{
80 PGAIO_RS_UNKNOWN, /* not yet completed / uninitialized */
82 PGAIO_RS_PARTIAL, /* did not fully succeed, no warning/error */
83 PGAIO_RS_WARNING, /* [partially] succeeded, with a warning */
84 PGAIO_RS_ERROR, /* failed entirely */
86
87
88/*
89 * Result of IO operation, visible only to the initiator of IO.
90 *
91 * We need to be careful about the size of PgAioResult, as it is embedded in
92 * every PgAioHandle, as well as every PgAioReturn. Currently we assume we can
93 * fit it into one 8 byte value, restricting the space for per-callback error
94 * data to PGAIO_RESULT_ERROR_BITS.
95 */
96#define PGAIO_RESULT_ID_BITS 6
97#define PGAIO_RESULT_STATUS_BITS 3
98#define PGAIO_RESULT_ERROR_BITS 23
99typedef struct PgAioResult
100{
101 /*
102 * This is of type PgAioHandleCallbackID, but can't use a bitfield of an
103 * enum, because some compilers treat enums as signed.
104 */
106
107 /* of type PgAioResultStatus, see above */
109
110 /* meaning defined by callback->error */
112
115
116
120 "PgAioResult bits divided up incorrectly");
122 "PgAioResult has unexpected size");
123
124/*
125 * Combination of PgAioResult with minimal metadata about the IO.
126 *
127 * Contains sufficient information to be able, in case the IO [partially]
128 * fails, to log/raise an error under control of the IO issuing code.
129 */
130typedef struct PgAioReturn
131{
135
136
137#endif /* AIO_TYPES_H */
#define PGAIO_RESULT_ID_BITS
Definition: aio_types.h:96
StaticAssertDecl(PGAIO_RESULT_ID_BITS+PGAIO_RESULT_STATUS_BITS+PGAIO_RESULT_ERROR_BITS==32, "PgAioResult bits divided up incorrectly")
union PgAioTargetData PgAioTargetData
struct PgAioResult PgAioResult
#define PGAIO_RESULT_STATUS_BITS
Definition: aio_types.h:97
#define PGAIO_RESULT_ERROR_BITS
Definition: aio_types.h:98
PgAioResultStatus
Definition: aio_types.h:79
@ PGAIO_RS_OK
Definition: aio_types.h:81
@ PGAIO_RS_UNKNOWN
Definition: aio_types.h:80
@ PGAIO_RS_PARTIAL
Definition: aio_types.h:82
@ PGAIO_RS_ERROR
Definition: aio_types.h:84
@ PGAIO_RS_WARNING
Definition: aio_types.h:83
struct PgAioWaitRef PgAioWaitRef
struct PgAioReturn PgAioReturn
uint32 BlockNumber
Definition: block.h:31
int32_t int32
Definition: c.h:498
uint32_t uint32
Definition: c.h:502
ForkNumber
Definition: relpath.h:56
uint32 status
Definition: aio_types.h:108
uint32 error_data
Definition: aio_types.h:111
int32 result
Definition: aio_types.h:113
uint32 id
Definition: aio_types.h:105
PgAioResult result
Definition: aio_types.h:132
PgAioTargetData target_data
Definition: aio_types.h:133
uint32 generation_upper
Definition: aio_types.h:45
uint32 aio_index
Definition: aio_types.h:35
uint32 generation_lower
Definition: aio_types.h:46
BlockNumber blockNum
Definition: aio_types.h:66
RelFileLocator rlocator
Definition: aio_types.h:65
BlockNumber nblocks
Definition: aio_types.h:67
struct PgAioTargetData::@124 smgr
ForkNumber forkNum
Definition: aio_types.h:68