mirror of
https://github.com/postgres/postgres.git
synced 2025-12-21 05:21:08 +03:00
This implements the following: 1) An smgr AIO target, for AIO on smgr files. This should be usable not just for md.c but also other SMGR implementation if we ever get them. 2) readv support in fd.c, which requires a small bit of infrastructure work in fd.c 3) smgr.c and md.c support for readv There still is nothing performing AIO, but as of this commit it would be possible. As part of this change FileGetRawDesc() actually ensures that the file is opened - previously it was basically not usable. It's used to reopen a file in IO workers. Reviewed-by: Noah Misch <noah@leadboat.com> Discussion: https://postgr.es/m/uvrtrknj4kdytuboidbhwclo4gxhswwcpgadptsjvjqcluzmah%40brqs62irg4dt Discussion: https://postgr.es/m/20210223100344.llw5an2aklengrmn@alap3.anarazel.de Discussion: https://postgr.es/m/stj36ea6yyhoxtqkhpieia2z4krnam7qyetc57rfezgk4zgapf@gcnactj4z56m
117 lines
2.8 KiB
C
117 lines
2.8 KiB
C
/*-------------------------------------------------------------------------
|
|
*
|
|
* aio_target.c
|
|
* AIO - Functionality related to executing IO for different targets
|
|
*
|
|
* Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
*
|
|
* IDENTIFICATION
|
|
* src/backend/storage/aio/aio_target.c
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
|
|
#include "postgres.h"
|
|
|
|
#include "storage/aio.h"
|
|
#include "storage/aio_internal.h"
|
|
#include "storage/smgr.h"
|
|
|
|
|
|
/*
|
|
* Registry for entities that can be the target of AIO.
|
|
*/
|
|
static const PgAioTargetInfo *pgaio_target_info[] = {
|
|
[PGAIO_TID_INVALID] = &(PgAioTargetInfo) {
|
|
.name = "invalid",
|
|
},
|
|
[PGAIO_TID_SMGR] = &aio_smgr_target_info,
|
|
};
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------
|
|
* Public target related functions operating on IO Handles
|
|
* --------------------------------------------------------------------------------
|
|
*/
|
|
|
|
bool
|
|
pgaio_io_has_target(PgAioHandle *ioh)
|
|
{
|
|
return ioh->target != PGAIO_TID_INVALID;
|
|
}
|
|
|
|
/*
|
|
* Return the name for the target associated with the IO. Mostly useful for
|
|
* debugging/logging.
|
|
*/
|
|
const char *
|
|
pgaio_io_get_target_name(PgAioHandle *ioh)
|
|
{
|
|
Assert(ioh->target >= 0 && ioh->target < PGAIO_TID_COUNT);
|
|
|
|
return pgaio_target_info[ioh->target]->name;
|
|
}
|
|
|
|
/*
|
|
* Assign a target to the IO.
|
|
*
|
|
* This has to be called exactly once before pgaio_io_start_*() is called.
|
|
*/
|
|
void
|
|
pgaio_io_set_target(PgAioHandle *ioh, PgAioTargetID targetid)
|
|
{
|
|
Assert(ioh->state == PGAIO_HS_HANDED_OUT);
|
|
Assert(ioh->target == PGAIO_TID_INVALID);
|
|
|
|
ioh->target = targetid;
|
|
}
|
|
|
|
PgAioTargetData *
|
|
pgaio_io_get_target_data(PgAioHandle *ioh)
|
|
{
|
|
return &ioh->target_data;
|
|
}
|
|
|
|
/*
|
|
* Return a stringified description of the IO's target.
|
|
*
|
|
* The string is localized and allocated in the current memory context.
|
|
*/
|
|
char *
|
|
pgaio_io_get_target_description(PgAioHandle *ioh)
|
|
{
|
|
return pgaio_target_info[ioh->target]->describe_identity(&ioh->target_data);
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------
|
|
* Internal target related functions operating on IO Handles
|
|
* --------------------------------------------------------------------------------
|
|
*/
|
|
|
|
/*
|
|
* Internal: Check if pgaio_io_reopen() is available for the IO.
|
|
*/
|
|
bool
|
|
pgaio_io_can_reopen(PgAioHandle *ioh)
|
|
{
|
|
return pgaio_target_info[ioh->target]->reopen != NULL;
|
|
}
|
|
|
|
/*
|
|
* Internal: Before executing an IO outside of the context of the process the
|
|
* IO has been staged in, the file descriptor has to be reopened - any FD
|
|
* referenced in the IO itself, won't be valid in the separate process.
|
|
*/
|
|
void
|
|
pgaio_io_reopen(PgAioHandle *ioh)
|
|
{
|
|
Assert(ioh->target >= 0 && ioh->target < PGAIO_TID_COUNT);
|
|
Assert(ioh->op >= 0 && ioh->op < PGAIO_OP_COUNT);
|
|
|
|
pgaio_target_info[ioh->target]->reopen(ioh);
|
|
}
|