LCOV - code coverage report
Current view: top level - src/include/storage - smgr.h (source / functions) Coverage Total Hit
Test: PostgreSQL 19devel Lines: 100.0 % 6 6
Test Date: 2026-03-04 15:14:37 Functions: 100.0 % 2 2
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /*-------------------------------------------------------------------------
       2              :  *
       3              :  * smgr.h
       4              :  *    storage manager switch public interface declarations.
       5              :  *
       6              :  *
       7              :  * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
       8              :  * Portions Copyright (c) 1994, Regents of the University of California
       9              :  *
      10              :  * src/include/storage/smgr.h
      11              :  *
      12              :  *-------------------------------------------------------------------------
      13              :  */
      14              : #ifndef SMGR_H
      15              : #define SMGR_H
      16              : 
      17              : #include "lib/ilist.h"
      18              : #include "storage/aio_types.h"
      19              : #include "storage/block.h"
      20              : #include "storage/relfilelocator.h"
      21              : 
      22              : /*
      23              :  * smgr.c maintains a table of SMgrRelation objects, which are essentially
      24              :  * cached file handles.  An SMgrRelation is created (if not already present)
      25              :  * by smgropen(), and destroyed by smgrdestroy().  Note that neither of these
      26              :  * operations imply I/O, they just create or destroy a hashtable entry.  (But
      27              :  * smgrdestroy() may release associated resources, such as OS-level file
      28              :  * descriptors.)
      29              :  *
      30              :  * An SMgrRelation may be "pinned", to prevent it from being destroyed while
      31              :  * it's in use.  We use this to prevent pointers in relcache to smgr from being
      32              :  * invalidated.  SMgrRelations that are not pinned are deleted at end of
      33              :  * transaction.
      34              :  */
      35              : typedef struct SMgrRelationData
      36              : {
      37              :     /* rlocator is the hashtable lookup key, so it must be first! */
      38              :     RelFileLocatorBackend smgr_rlocator;    /* relation physical identifier */
      39              : 
      40              :     /*
      41              :      * The following fields are reset to InvalidBlockNumber upon a cache flush
      42              :      * event, and hold the last known size for each fork.  This information is
      43              :      * currently only reliable during recovery, since there is no cache
      44              :      * invalidation for fork extension.
      45              :      */
      46              :     BlockNumber smgr_targblock; /* current insertion target block */
      47              :     BlockNumber smgr_cached_nblocks[MAX_FORKNUM + 1];   /* last known size */
      48              : 
      49              :     /* additional public fields may someday exist here */
      50              : 
      51              :     /*
      52              :      * Fields below here are intended to be private to smgr.c and its
      53              :      * submodules.  Do not touch them from elsewhere.
      54              :      */
      55              :     int         smgr_which;     /* storage manager selector */
      56              : 
      57              :     /*
      58              :      * for md.c; per-fork arrays of the number of open segments
      59              :      * (md_num_open_segs) and the segments themselves (md_seg_fds).
      60              :      */
      61              :     int         md_num_open_segs[MAX_FORKNUM + 1];
      62              :     struct _MdfdVec *md_seg_fds[MAX_FORKNUM + 1];
      63              : 
      64              :     /*
      65              :      * Pinning support.  If unpinned (ie. pincount == 0), 'node' is a list
      66              :      * link in list of all unpinned SMgrRelations.
      67              :      */
      68              :     int         pincount;
      69              :     dlist_node  node;
      70              : } SMgrRelationData;
      71              : 
      72              : typedef SMgrRelationData *SMgrRelation;
      73              : 
      74              : #define SmgrIsTemp(smgr) \
      75              :     RelFileLocatorBackendIsTemp((smgr)->smgr_rlocator)
      76              : 
      77              : extern PGDLLIMPORT const PgAioTargetInfo aio_smgr_target_info;
      78              : 
      79              : extern void smgrinit(void);
      80              : extern SMgrRelation smgropen(RelFileLocator rlocator, ProcNumber backend);
      81              : extern bool smgrexists(SMgrRelation reln, ForkNumber forknum);
      82              : extern void smgrpin(SMgrRelation reln);
      83              : extern void smgrunpin(SMgrRelation reln);
      84              : extern void smgrclose(SMgrRelation reln);
      85              : extern void smgrdestroyall(void);
      86              : extern void smgrrelease(SMgrRelation reln);
      87              : extern void smgrreleaseall(void);
      88              : extern void smgrreleaserellocator(RelFileLocatorBackend rlocator);
      89              : extern void smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo);
      90              : extern void smgrdosyncall(SMgrRelation *rels, int nrels);
      91              : extern void smgrdounlinkall(SMgrRelation *rels, int nrels, bool isRedo);
      92              : extern void smgrextend(SMgrRelation reln, ForkNumber forknum,
      93              :                        BlockNumber blocknum, const void *buffer, bool skipFsync);
      94              : extern void smgrzeroextend(SMgrRelation reln, ForkNumber forknum,
      95              :                            BlockNumber blocknum, int nblocks, bool skipFsync);
      96              : extern bool smgrprefetch(SMgrRelation reln, ForkNumber forknum,
      97              :                          BlockNumber blocknum, int nblocks);
      98              : extern uint32 smgrmaxcombine(SMgrRelation reln, ForkNumber forknum,
      99              :                              BlockNumber blocknum);
     100              : extern void smgrreadv(SMgrRelation reln, ForkNumber forknum,
     101              :                       BlockNumber blocknum,
     102              :                       void **buffers, BlockNumber nblocks);
     103              : extern void smgrstartreadv(PgAioHandle *ioh,
     104              :                            SMgrRelation reln, ForkNumber forknum,
     105              :                            BlockNumber blocknum,
     106              :                            void **buffers, BlockNumber nblocks);
     107              : extern void smgrwritev(SMgrRelation reln, ForkNumber forknum,
     108              :                        BlockNumber blocknum,
     109              :                        const void **buffers, BlockNumber nblocks,
     110              :                        bool skipFsync);
     111              : extern void smgrwriteback(SMgrRelation reln, ForkNumber forknum,
     112              :                           BlockNumber blocknum, BlockNumber nblocks);
     113              : extern BlockNumber smgrnblocks(SMgrRelation reln, ForkNumber forknum);
     114              : extern BlockNumber smgrnblocks_cached(SMgrRelation reln, ForkNumber forknum);
     115              : extern void smgrtruncate(SMgrRelation reln, ForkNumber *forknum, int nforks,
     116              :                          BlockNumber *old_nblocks,
     117              :                          BlockNumber *nblocks);
     118              : extern void smgrimmedsync(SMgrRelation reln, ForkNumber forknum);
     119              : extern void smgrregistersync(SMgrRelation reln, ForkNumber forknum);
     120              : extern void AtEOXact_SMgr(void);
     121              : extern bool ProcessBarrierSmgrRelease(void);
     122              : 
     123              : static inline void
     124          598 : smgrread(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
     125              :          void *buffer)
     126              : {
     127          598 :     smgrreadv(reln, forknum, blocknum, &buffer, 1);
     128          598 : }
     129              : 
     130              : static inline void
     131       578770 : smgrwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
     132              :           const void *buffer, bool skipFsync)
     133              : {
     134       578770 :     smgrwritev(reln, forknum, blocknum, &buffer, 1, skipFsync);
     135       578770 : }
     136              : 
     137              : extern void pgaio_io_set_target_smgr(PgAioHandle *ioh,
     138              :                                      SMgrRelationData *smgr,
     139              :                                      ForkNumber forknum,
     140              :                                      BlockNumber blocknum,
     141              :                                      int nblocks,
     142              :                                      bool skip_fsync);
     143              : 
     144              : #endif                          /* SMGR_H */
        

Generated by: LCOV version 2.0-1