LCOV - differential code coverage report
Current view: top level - src/backend/storage/aio - aio_target.c (source / functions) Coverage Total Hit UBC GBC CBC
Current: 0e5ff9b9b45a657aea12440478dc002e9b01f138 vs 0123ce131fca454009439dfa3b2266d1d40737d7 Lines: 100.0 % 23 23 3 20
Current Date: 2026-03-14 14:10:32 -0400 Functions: 100.0 % 7 7 1 6
Baseline: lcov-20260315-024220-baseline Branches: 50.0 % 22 11 11 2 9
Baseline Date: 2026-03-14 15:27:56 +0100 Line coverage date bins:
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
(30,360] days: 100.0 % 5 5 1 4
(360..) days: 100.0 % 18 18 2 16
Function coverage date bins:
(360..) days: 100.0 % 7 7 1 6
Branch coverage date bins:
(30,360] days: 50.0 % 18 9 9 2 7
(360..) days: 50.0 % 4 2 2 2

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : /*-------------------------------------------------------------------------
                                  2                 :                :  *
                                  3                 :                :  * aio_target.c
                                  4                 :                :  *    AIO - Functionality related to executing IO for different targets
                                  5                 :                :  *
                                  6                 :                :  * Portions Copyright (c) 1996-2026, 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"
                                 18                 :                : #include "storage/aio_internal.h"
                                 19                 :                : #include "storage/smgr.h"
                                 20                 :                : 
                                 21                 :                : 
                                 22                 :                : /*
                                 23                 :                :  * Registry for entities that can be the target of AIO.
                                 24                 :                :  */
                                 25                 :                : static const PgAioTargetInfo *pgaio_target_info[] = {
                                 26                 :                :     [PGAIO_TID_INVALID] = &(PgAioTargetInfo) {
                                 27                 :                :         .name = "invalid",
                                 28                 :                :     },
                                 29                 :                :     [PGAIO_TID_SMGR] = &aio_smgr_target_info,
                                 30                 :                : };
                                 31                 :                : 
                                 32                 :                : 
                                 33                 :                : 
                                 34                 :                : /* --------------------------------------------------------------------------------
                                 35                 :                :  * Public target related functions operating on IO Handles
                                 36                 :                :  * --------------------------------------------------------------------------------
                                 37                 :                :  */
                                 38                 :                : 
                                 39                 :                : bool
  363 andres@anarazel.de         40                 :CBC     2673318 : pgaio_io_has_target(PgAioHandle *ioh)
                                 41                 :                : {
                                 42                 :        2673318 :     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                 :                :  */
                                 49                 :                : const char *
                                 50                 :          11450 : pgaio_io_get_target_name(PgAioHandle *ioh)
                                 51                 :                : {
                                 52                 :                :     /* explicitly allow INVALID here, function used by debug messages */
  324                            53         [ -  + ]:          11450 :     Assert(ioh->target >= PGAIO_TID_INVALID && ioh->target < PGAIO_TID_COUNT);
                                 54                 :                : 
  363                            55                 :          11450 :     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                 :                :  */
                                 63                 :                : void
                                 64                 :        1336659 : pgaio_io_set_target(PgAioHandle *ioh, PgAioTargetID targetid)
                                 65                 :                : {
                                 66         [ -  + ]:        1336659 :     Assert(ioh->state == PGAIO_HS_HANDED_OUT);
                                 67         [ -  + ]:        1336659 :     Assert(ioh->target == PGAIO_TID_INVALID);
                                 68                 :                : 
                                 69                 :        1336659 :     ioh->target = targetid;
                                 70                 :        1336659 : }
                                 71                 :                : 
                                 72                 :                : PgAioTargetData *
                                 73                 :        4228962 : pgaio_io_get_target_data(PgAioHandle *ioh)
                                 74                 :                : {
                                 75                 :        4228962 :     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                 :                :  */
                                 83                 :                : char *
  363 andres@anarazel.de         84                 :GBC           1 : pgaio_io_get_target_description(PgAioHandle *ioh)
                                 85                 :                : {
                                 86                 :                :     /* disallow INVALID, there wouldn't be a description */
  324                            87   [ +  -  -  + ]:              1 :     Assert(ioh->target > PGAIO_TID_INVALID && ioh->target < PGAIO_TID_COUNT);
                                 88                 :                : 
  363                            89                 :              1 :     return pgaio_target_info[ioh->target]->describe_identity(&ioh->target_data);
                                 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                 :                :  */
                                102                 :                : bool
  363 andres@anarazel.de        103                 :CBC     1243509 : pgaio_io_can_reopen(PgAioHandle *ioh)
                                104                 :                : {
  324                           105   [ +  -  -  + ]:        1243509 :     Assert(ioh->target > PGAIO_TID_INVALID && ioh->target < PGAIO_TID_COUNT);
                                106                 :                : 
  363                           107                 :        1243509 :     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                 :                :  */
                                115                 :                : void
                                116                 :         487023 : pgaio_io_reopen(PgAioHandle *ioh)
                                117                 :                : {
  324                           118   [ +  -  -  + ]:         487023 :     Assert(ioh->target > PGAIO_TID_INVALID && ioh->target < PGAIO_TID_COUNT);
                                119   [ +  -  -  + ]:         487023 :     Assert(ioh->op > PGAIO_OP_INVALID && ioh->op < PGAIO_OP_COUNT);
                                120                 :                : 
  363                           121                 :         487023 :     pgaio_target_info[ioh->target]->reopen(ioh);
                                122                 :         487023 : }
        

Generated by: LCOV version 2.4-beta