PostgreSQL Source Code git master
Loading...
Searching...
No Matches
aio_io.c File Reference
#include "postgres.h"
#include "miscadmin.h"
#include "storage/aio.h"
#include "storage/aio_internal.h"
#include "storage/fd.h"
#include "utils/wait_event.h"
Include dependency graph for aio_io.c:

Go to the source code of this file.

Functions

static void pgaio_io_before_start (PgAioHandle *ioh)
 
int pgaio_io_get_iovec (PgAioHandle *ioh, struct iovec **iov)
 
PgAioOp pgaio_io_get_op (PgAioHandle *ioh)
 
PgAioOpDatapgaio_io_get_op_data (PgAioHandle *ioh)
 
void pgaio_io_start_readv (PgAioHandle *ioh, int fd, int iovcnt, uint64 offset)
 
void pgaio_io_start_writev (PgAioHandle *ioh, int fd, int iovcnt, uint64 offset)
 
void pgaio_io_perform_synchronously (PgAioHandle *ioh)
 
const charpgaio_io_get_op_name (PgAioHandle *ioh)
 
bool pgaio_io_uses_fd (PgAioHandle *ioh, int fd)
 
int pgaio_io_get_iovec_length (PgAioHandle *ioh, struct iovec **iov)
 

Function Documentation

◆ pgaio_io_before_start()

static void pgaio_io_before_start ( PgAioHandle ioh)
static

Definition at line 161 of file aio_io.c.

162{
163 Assert(ioh->state == PGAIO_HS_HANDED_OUT);
167
168 /*
169 * Otherwise the FDs referenced by the IO could be closed due to interrupt
170 * processing.
171 */
173}
PgAioBackend * pgaio_my_backend
Definition aio.c:81
@ PGAIO_OP_INVALID
Definition aio.h:90
@ PGAIO_HS_HANDED_OUT
bool pgaio_io_has_target(PgAioHandle *ioh)
Definition aio_target.c:40
#define Assert(condition)
Definition c.h:1002
#define INTERRUPTS_CAN_BE_PROCESSED()
Definition miscadmin.h:132
static int fb(int x)
PgAioHandle * handed_out_io

References Assert, fb(), PgAioBackend::handed_out_io, INTERRUPTS_CAN_BE_PROCESSED, PGAIO_HS_HANDED_OUT, pgaio_io_has_target(), pgaio_my_backend, and PGAIO_OP_INVALID.

Referenced by pgaio_io_start_readv(), and pgaio_io_start_writev().

◆ pgaio_io_get_iovec()

int pgaio_io_get_iovec ( PgAioHandle ioh,
struct iovec **  iov 
)

Definition at line 42 of file aio_io.c.

43{
45
46 *iov = &pgaio_ctl->iovecs[ioh->iovec_off];
47
48 return PG_IOV_MAX;
49}
PgAioCtl * pgaio_ctl
Definition aio.c:78
#define PG_IOV_MAX
Definition pg_iovec.h:47
struct iovec * iovecs

References Assert, fb(), PgAioCtl::iovecs, PG_IOV_MAX, pgaio_ctl, and PGAIO_HS_HANDED_OUT.

Referenced by mdstartreadv().

◆ pgaio_io_get_iovec_length()

int pgaio_io_get_iovec_length ( PgAioHandle ioh,
struct iovec **  iov 
)

Definition at line 224 of file aio_io.c.

225{
226 Assert(ioh->state >= PGAIO_HS_DEFINED);
227
228 *iov = &pgaio_ctl->iovecs[ioh->iovec_off];
229
230 switch ((PgAioOp) ioh->op)
231 {
232 case PGAIO_OP_READV:
233 return ioh->op_data.read.iov_length;
234 case PGAIO_OP_WRITEV:
235 return ioh->op_data.write.iov_length;
236 default:
238 return 0;
239 }
240}
PgAioOp
Definition aio.h:88
@ PGAIO_OP_WRITEV
Definition aio.h:93
@ PGAIO_OP_READV
Definition aio.h:92
@ PGAIO_HS_DEFINED
#define pg_unreachable()
Definition c.h:426

References Assert, fb(), PgAioCtl::iovecs, pg_unreachable, pgaio_ctl, PGAIO_HS_DEFINED, PGAIO_OP_READV, and PGAIO_OP_WRITEV.

Referenced by IoWorkerMain().

◆ pgaio_io_get_op()

PgAioOp pgaio_io_get_op ( PgAioHandle ioh)

Definition at line 52 of file aio_io.c.

53{
54 return ioh->op;
55}

References fb().

Referenced by smgr_aio_reopen().

◆ pgaio_io_get_op_data()

PgAioOpData * pgaio_io_get_op_data ( PgAioHandle ioh)

Definition at line 58 of file aio_io.c.

59{
60 return &ioh->op_data;
61}

References fb().

Referenced by smgr_aio_reopen().

◆ pgaio_io_get_op_name()

const char * pgaio_io_get_op_name ( PgAioHandle ioh)

Definition at line 180 of file aio_io.c.

181{
182 Assert(ioh->op >= 0 && ioh->op < PGAIO_OP_COUNT);
183
184 switch ((PgAioOp) ioh->op)
185 {
186 case PGAIO_OP_INVALID:
187 return "invalid";
188 case PGAIO_OP_READV:
189 return "readv";
190 case PGAIO_OP_WRITEV:
191 return "writev";
192 }
193
194 return NULL; /* silence compiler */
195}
#define PGAIO_OP_COUNT
Definition aio.h:107

References Assert, fb(), PGAIO_OP_COUNT, PGAIO_OP_INVALID, PGAIO_OP_READV, and PGAIO_OP_WRITEV.

Referenced by IoWorkerMain(), and pg_get_aios().

◆ pgaio_io_perform_synchronously()

void pgaio_io_perform_synchronously ( PgAioHandle ioh)

Definition at line 116 of file aio_io.c.

117{
118 ssize_t result = 0;
119 struct iovec *iov = &pgaio_ctl->iovecs[ioh->iovec_off];
120
122
123 /* Perform IO. */
124 switch ((PgAioOp) ioh->op)
125 {
126 case PGAIO_OP_READV:
128 result = pg_preadv(ioh->op_data.read.fd, iov,
129 ioh->op_data.read.iov_length,
130 ioh->op_data.read.offset);
132 break;
133 case PGAIO_OP_WRITEV:
135 result = pg_pwritev(ioh->op_data.write.fd, iov,
136 ioh->op_data.write.iov_length,
137 ioh->op_data.write.offset);
139 break;
140 case PGAIO_OP_INVALID:
141 elog(ERROR, "trying to execute invalid IO operation");
142 }
143
144 /*
145 * ssize_t to int conversion should be ok because result should be no more
146 * than PG_IOV_MAX times BLCKSZ.
147 */
149 ioh->result = result < 0 ? -errno : result;
150
152
154}
void pgaio_io_process_completion(PgAioHandle *ioh, int result)
Definition aio.c:528
uint32 result
#define ERROR
Definition elog.h:40
#define elog(elevel,...)
Definition elog.h:228
#define START_CRIT_SECTION()
Definition miscadmin.h:152
#define END_CRIT_SECTION()
Definition miscadmin.h:154
static ssize_t pg_preadv(int fd, const struct iovec *iov, int iovcnt, pgoff_t offset)
Definition pg_iovec.h:54
static ssize_t pg_pwritev(int fd, const struct iovec *iov, int iovcnt, pgoff_t offset)
Definition pg_iovec.h:93
static void pgstat_report_wait_start(uint32 wait_event_info)
Definition wait_event.h:67
static void pgstat_report_wait_end(void)
Definition wait_event.h:83

References Assert, elog, END_CRIT_SECTION, ERROR, fb(), PgAioCtl::iovecs, pg_preadv(), pg_pwritev(), pgaio_ctl, pgaio_io_process_completion(), PGAIO_OP_INVALID, PGAIO_OP_READV, PGAIO_OP_WRITEV, pgstat_report_wait_end(), pgstat_report_wait_start(), result, and START_CRIT_SECTION.

Referenced by IoWorkerMain(), pgaio_io_stage(), and pgaio_worker_submit().

◆ pgaio_io_start_readv()

void pgaio_io_start_readv ( PgAioHandle ioh,
int  fd,
int  iovcnt,
uint64  offset 
)

Definition at line 78 of file aio_io.c.

80{
82
83 ioh->op_data.read.fd = fd;
84 ioh->op_data.read.offset = offset;
85 ioh->op_data.read.iov_length = iovcnt;
86
88}
void pgaio_io_stage(PgAioHandle *ioh, PgAioOp op)
Definition aio.c:424
static void pgaio_io_before_start(PgAioHandle *ioh)
Definition aio_io.c:161
static int fd(const char *x, int i)

References fb(), fd(), pgaio_io_before_start(), pgaio_io_stage(), and PGAIO_OP_READV.

Referenced by FileStartReadV().

◆ pgaio_io_start_writev()

void pgaio_io_start_writev ( PgAioHandle ioh,
int  fd,
int  iovcnt,
uint64  offset 
)

Definition at line 91 of file aio_io.c.

93{
95
96 ioh->op_data.write.fd = fd;
97 ioh->op_data.write.offset = offset;
98 ioh->op_data.write.iov_length = iovcnt;
99
101}

References fb(), fd(), pgaio_io_before_start(), pgaio_io_stage(), and PGAIO_OP_WRITEV.

◆ pgaio_io_uses_fd()

bool pgaio_io_uses_fd ( PgAioHandle ioh,
int  fd 
)

Definition at line 202 of file aio_io.c.

203{
204 Assert(ioh->state >= PGAIO_HS_DEFINED);
205
206 switch ((PgAioOp) ioh->op)
207 {
208 case PGAIO_OP_READV:
209 return ioh->op_data.read.fd == fd;
210 case PGAIO_OP_WRITEV:
211 return ioh->op_data.write.fd == fd;
212 case PGAIO_OP_INVALID:
213 return false;
214 }
215
216 return false; /* silence compiler */
217}

References Assert, fb(), fd(), PGAIO_HS_DEFINED, PGAIO_OP_INVALID, PGAIO_OP_READV, and PGAIO_OP_WRITEV.

Referenced by pgaio_closing_fd().