LCOV - code coverage report
Current view: top level - disco/archiver - fd_archiver_feeder.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 75 0.0 %
Date: 2025-12-06 04:45:29 Functions: 0 7 0.0 %

          Line data    Source code
       1             : #include "../tiles.h"
       2             : 
       3             : #include "fd_archiver.h"
       4             : #include <unistd.h>
       5             : #include <sys/socket.h>
       6             : #include "generated/archiver_feeder_seccomp.h"
       7             : 
       8             : /* The archiver feeder tiles forward fragments that we want to capture from a subset of
       9             : the input links to the single archiver writer tile.
      10             : 
      11             : There can (should) be many archiver feeder tiles, and a single archiver writer tile.
      12             : 
      13             : This can be used to set up a variety of flexible topologies for capturing, such as round-robin
      14             : or 1-1. */
      15             : 
      16             : #define FD_ARCHIVER_FEEDER_MAX_INPUT_LINKS (32UL)
      17             : 
      18             : typedef struct {
      19             :   fd_wksp_t * mem;
      20             :   ulong       chunk0;
      21             :   ulong       wmark;
      22             : } fd_archiver_feeder_in_ctx_t;
      23             : 
      24             : struct fd_archiver_feeder_tile_ctx {
      25             :   fd_wksp_t * out_mem;
      26             :   ulong       out_chunk0;
      27             :   ulong       out_wmark;
      28             :   ulong       out_chunk;
      29             : 
      30             :   ulong count;
      31             : 
      32             :   ulong round_robin_idx;
      33             :   ulong round_robin_cnt;
      34             : 
      35             :   /* Input links */
      36             :   fd_archiver_feeder_in_ctx_t in[ FD_ARCHIVER_FEEDER_MAX_INPUT_LINKS ];
      37             : };
      38             : typedef struct fd_archiver_feeder_tile_ctx fd_archiver_feeder_tile_ctx_t;
      39             : 
      40             : FD_FN_CONST static inline ulong
      41           0 : scratch_align( void ) {
      42           0 :   return 4096UL;
      43           0 : }
      44             : 
      45             : static ulong
      46             : populate_allowed_seccomp( fd_topo_t const *      topo,
      47             :                           fd_topo_tile_t const * tile,
      48             :                           ulong                  out_cnt,
      49           0 :                           struct sock_filter *   out ) {
      50           0 :   (void)topo;
      51           0 :   (void)tile;
      52             : 
      53           0 :   populate_sock_filter_policy_archiver_feeder( out_cnt, out, (uint)fd_log_private_logfile_fd() );
      54           0 :   return sock_filter_policy_archiver_feeder_instr_cnt;
      55           0 : }
      56             : 
      57             : static ulong
      58             : populate_allowed_fds( fd_topo_t const *      topo,
      59             :                       fd_topo_tile_t const * tile,
      60             :                       ulong                  out_fds_cnt,
      61           0 :                       int *                  out_fds ) {
      62           0 :   (void)topo;
      63           0 :   (void)tile;
      64           0 :   (void)out_fds_cnt;
      65             : 
      66           0 :   ulong out_cnt = 0UL;
      67             : 
      68           0 :   out_fds[ out_cnt++ ] = 2; /* stderr */
      69           0 :   if( FD_LIKELY( -1!=fd_log_private_logfile_fd() ) )
      70           0 :     out_fds[ out_cnt++ ] = fd_log_private_logfile_fd(); /* logfile */
      71             : 
      72           0 :   return out_cnt;
      73           0 : }
      74             : 
      75             : FD_FN_PURE static inline ulong
      76           0 : scratch_footprint( fd_topo_tile_t const * tile ) {
      77           0 :   (void)tile;
      78           0 :   ulong l = FD_LAYOUT_INIT;
      79           0 :   l = FD_LAYOUT_APPEND( l, alignof(fd_archiver_feeder_tile_ctx_t), sizeof(fd_archiver_feeder_tile_ctx_t) );
      80           0 :   return FD_LAYOUT_FINI( l, scratch_align() );
      81           0 : }
      82             : 
      83             : static void
      84             : unprivileged_init( fd_topo_t *      topo,
      85           0 :                    fd_topo_tile_t * tile ) {
      86           0 :   void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
      87             : 
      88           0 :   FD_SCRATCH_ALLOC_INIT( l, scratch );
      89           0 :   fd_archiver_feeder_tile_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof(fd_archiver_feeder_tile_ctx_t), sizeof(fd_archiver_feeder_tile_ctx_t) );
      90           0 :   memset( ctx, 0, sizeof(fd_archiver_feeder_tile_ctx_t) );
      91             : 
      92           0 :   ctx->round_robin_cnt = fd_topo_tile_name_cnt( topo, tile->name );
      93           0 :   ctx->round_robin_idx = tile->kind_id;
      94             : 
      95           0 :   for( ulong i=0; i<tile->in_cnt; i++ ) {
      96           0 :     fd_topo_link_t * link = &topo->links[ tile->in_link_id[ i ] ];
      97           0 :     fd_topo_wksp_t * link_wksp = &topo->workspaces[ topo->objs[ link->dcache_obj_id ].wksp_id ];
      98             : 
      99           0 :     ctx->in[ i ].mem    = link_wksp->wksp;
     100           0 :     ctx->in[ i ].chunk0 = fd_dcache_compact_chunk0( ctx->in[ i ].mem, link->dcache );
     101           0 :     ctx->in[ i ].wmark  = fd_dcache_compact_wmark ( ctx->in[ i ].mem, link->dcache, link->mtu );
     102           0 :   }
     103             : 
     104           0 :   ctx->out_mem    = topo->workspaces[ topo->objs[ topo->links[ tile->out_link_id[ 0 ] ].dcache_obj_id ].wksp_id ].wksp;
     105           0 :   ctx->out_chunk0 = fd_dcache_compact_chunk0( ctx->out_mem, topo->links[ tile->out_link_id[ 0 ] ].dcache );
     106           0 :   ctx->out_wmark  = fd_dcache_compact_wmark ( ctx->out_mem, topo->links[ tile->out_link_id[ 0 ] ].dcache, topo->links[ tile->out_link_id[ 0 ] ].mtu );
     107           0 :   ctx->out_chunk  = ctx->out_chunk0;
     108             : 
     109           0 :   ulong scratch_top = FD_SCRATCH_ALLOC_FINI( l, scratch_align() );
     110           0 :   if( FD_UNLIKELY( scratch_top > (ulong)scratch + scratch_footprint( tile ) ) ) {
     111           0 :     FD_LOG_ERR(( "scratch overflow %lu %lu %lu", scratch_top - (ulong)scratch - scratch_footprint( tile ), scratch_top, (ulong)scratch + scratch_footprint( tile ) ));
     112           0 :   }
     113           0 : }
     114             : 
     115             : // TODO: if you wanted, you could round-robin using before_frag
     116             : 
     117             : static inline void
     118             : during_frag( fd_archiver_feeder_tile_ctx_t * ctx,
     119             :              ulong                           in_idx,
     120             :              ulong                           seq,
     121             :              ulong                           sig,
     122             :              ulong                           chunk,
     123             :              ulong                           sz,
     124           0 :              ulong                           ctl FD_PARAM_UNUSED ) {
     125             :   /* TODO: filter by signature in before_credit */
     126           0 :   if( FD_UNLIKELY( chunk<ctx->in[ in_idx ].chunk0 || chunk>ctx->in[ in_idx ].wmark ) ) {
     127           0 :     FD_LOG_ERR(( "chunk %lu %lu corrupt, not in range [%lu,%lu]", chunk, sz, ctx->in[ in_idx ].chunk0, ctx->in[ in_idx ].wmark ));
     128           0 :   }
     129             : 
     130           0 :   uchar * src = (uchar *)fd_chunk_to_laddr( ctx->in[in_idx].mem, chunk );
     131           0 :   uchar * dst = (uchar *)fd_chunk_to_laddr( ctx->out_mem, ctx->out_chunk );
     132             : 
     133           0 :   if( FD_LIKELY( sz ) ) {
     134             :     /* Write the header to the dst */
     135           0 :     fd_archiver_frag_header_t * header = fd_type_pun( dst );
     136           0 :     header->magic                      = FD_ARCHIVER_HEADER_MAGIC;
     137           0 :     header->version                    = FD_ARCHIVER_HEADER_VERSION;
     138           0 :     header->tile_id                    = FD_ARCHIVER_SIG_TILE_ID(sig);
     139             :     /* header->ns_since_prev_fragment is set in the single writer tile, so that we have a total order */
     140           0 :     header->sz                         = sz;
     141           0 :     header->sig                        = FD_ARCHIVER_SIG_CLEAR(sig);
     142           0 :     header->seq                        = seq;
     143             : 
     144             :     /* Write the frag to the dst */
     145           0 :     fd_memcpy( dst + FD_ARCHIVER_FRAG_HEADER_FOOTPRINT, src, sz );
     146           0 :   }
     147           0 : }
     148             : 
     149             : static inline void
     150             : after_frag( fd_archiver_feeder_tile_ctx_t * ctx,
     151             :             ulong                           in_idx FD_PARAM_UNUSED,
     152             :             ulong                           seq    FD_PARAM_UNUSED,
     153             :             ulong                           sig    FD_PARAM_UNUSED,
     154             :             ulong                           sz,
     155             :             ulong                           tsorig,
     156             :             ulong                           tspub  FD_PARAM_UNUSED,
     157           0 :             fd_stem_context_t *             stem ) {
     158             :   /* Publish the message to the queue */
     159           0 :   ulong full_sz = sz + FD_ARCHIVER_FRAG_HEADER_FOOTPRINT;
     160           0 :   fd_stem_publish( stem, 0UL, 0UL, ctx->out_chunk, full_sz, 0UL, tsorig, 0UL);
     161           0 :   ctx->out_chunk = fd_dcache_compact_next( ctx->out_chunk, full_sz, ctx->out_chunk0, ctx->out_wmark );
     162           0 : }
     163             : 
     164           0 : #define STEM_BURST (1UL)
     165             : 
     166           0 : #define STEM_CALLBACK_CONTEXT_TYPE  fd_archiver_feeder_tile_ctx_t
     167           0 : #define STEM_CALLBACK_CONTEXT_ALIGN alignof(fd_archiver_feeder_tile_ctx_t)
     168             : 
     169           0 : #define STEM_CALLBACK_DURING_FRAG         during_frag
     170           0 : #define STEM_CALLBACK_AFTER_FRAG          after_frag
     171             : 
     172             : #include "../stem/fd_stem.c"
     173             : 
     174             : fd_topo_run_tile_t fd_tile_archiver_feeder = {
     175             :   .name                     = "arch_f",
     176             :   .populate_allowed_seccomp = populate_allowed_seccomp,
     177             :   .populate_allowed_fds     = populate_allowed_fds,
     178             :   .scratch_align            = scratch_align,
     179             :   .scratch_footprint        = scratch_footprint,
     180             :   .unprivileged_init        = unprivileged_init,
     181             :   .run                      = stem_run,
     182             : };

Generated by: LCOV version 1.14