LCOV - code coverage report
Current view: top level - app/firedancer/commands - snapshot_create.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 52 0.0 %
Date: 2026-08-14 04:54:57 Functions: 0 4 0.0 %

          Line data    Source code
       1             : #include "../../shared/fd_config.h"
       2             : #include "../../shared/fd_action.h"
       3             : #include "../../shared/fd_bootinfo.h"
       4             : #include "../../../discof/admin/fd_adminctl.h"
       5             : 
       6             : static ulong
       7             : send_snapshot_create_cmd( fd_topo_t * topo,
       8           0 :                           ulong       target_slot ) {
       9           0 :   fd_topo_obj_t const * admin_ctl_obj = fd_topo_find_obj( topo, "adminctl", "admin", ULONG_MAX );
      10           0 :   if( FD_UNLIKELY( !admin_ctl_obj ) ) FD_LOG_ERR(( "admin tile command endpoint not found" ));
      11             : 
      12           0 :   fd_topo_wksp_t * admin_ctl_wksp = &topo->workspaces[ admin_ctl_obj->wksp_id ];
      13           0 :   fd_topo_join_workspace( topo, admin_ctl_wksp, FD_SHMEM_JOIN_MODE_READ_WRITE, FD_TOPO_CORE_DUMP_LEVEL_DISABLED );
      14           0 :   fd_topo_workspace_fill( topo, admin_ctl_wksp );
      15             : 
      16           0 :   fd_adminctl_t * adminctl = fd_adminctl_join( fd_topo_obj_laddr( topo, admin_ctl_obj->id ) );
      17           0 :   if( FD_UNLIKELY( !adminctl ) ) {
      18           0 :     FD_LOG_ERR(( "Failed to request snapshot creation as the command could not communicate with the "
      19           0 :                  "running Firedancer process. It is possible you are running the command from an "
      20           0 :                  "older or newer version of Firedancer that is no longer compatible." ));
      21           0 :   }
      22             : 
      23           0 :   void * payload     = NULL;
      24           0 :   ulong  payload_max = 0UL;
      25           0 :   ulong  slot_idx    = fd_adminctl_reserve( adminctl, &payload, &payload_max );
      26           0 :   if( FD_UNLIKELY( slot_idx==ULONG_MAX ) ) {
      27           0 :     FD_LOG_ERR(( "Failed to process `snapshot-create` command as there are other pending "
      28           0 :                  "commands that are being processed. Please wait for other commands to complete "
      29           0 :                  "or forcefully terminate the other processes and retry the command." ));
      30           0 :   }
      31           0 :   FD_TEST( payload_max>=sizeof(fd_adminctl_snap_create_t) );
      32             : 
      33           0 :   fd_adminctl_snap_create_t * req = payload;
      34           0 :   req->version = FD_ADMINCTL_SNAP_CREATE_PAYLOAD_VERSION;
      35           0 :   req->slot    = target_slot;
      36             : 
      37           0 :   fd_adminctl_publish( adminctl, slot_idx, FD_ADMINCTL_CMD_SNAP_CREATE, sizeof(fd_adminctl_snap_create_t) );
      38           0 :   return fd_adminctl_wait( adminctl, slot_idx );
      39           0 : }
      40             : 
      41             : static void
      42             : snapshot_create_cmd_args( int *    pargc,
      43             :                           char *** pargv,
      44           0 :                           args_t * args ) {
      45           0 :   args->snapshot_create.slot = fd_env_strip_cmdline_ulong( pargc, pargv, "--slot", NULL, 0UL );
      46           0 : }
      47             : 
      48             : static void
      49             : snapshot_create_cmd_fn( args_t *   args,
      50           0 :                         config_t * config ) {
      51           0 :   fd_bootinfo_adopt( config );
      52           0 :   fd_bootinfo_check_layout( config );
      53           0 :   fd_topo_t * topo = &config->topo;
      54             : 
      55             :   /* Send snapshot create command */
      56           0 :   ulong result = send_snapshot_create_cmd( topo, args->snapshot_create.slot );
      57           0 :   if( FD_UNLIKELY( result ) ) {
      58           0 :     if( FD_LIKELY( result==FD_SNAPSHOT_CREATE_RESULT_BUSY && !args->snapshot_create.slot ) ) {
      59           0 :       FD_LOG_NOTICE(( "snapshot creation already in progress, attaching ..." ));
      60           0 :     } else {
      61           0 :       FD_LOG_ERR(( "failed to request snapshot creation (%lu)", result ));
      62           0 :     }
      63           0 :   } else if( FD_UNLIKELY( args->snapshot_create.slot ) ) {
      64           0 :     FD_LOG_NOTICE(( "snapshot creation scheduled at slot %lu, waiting ...", args->snapshot_create.slot ));
      65           0 :   }
      66           0 : }
      67             : 
      68             : static void
      69           0 : snapshot_create_args_help( fd_action_help_t * help ) {
      70           0 :   fd_action_help_arg( help, "--slot", "<slot>",
      71           0 :       "Schedule snapshot creation at a slot in the future rather than\n"
      72           0 :       "creating one immediately.  Rooting stops at the first rooted slot at\n"
      73           0 :       "or after <slot> and a snapshot of it is created (default 0, which\n"
      74           0 :       "snapshots the current root immediately)" );
      75           0 : }
      76             : 
      77             : action_t fd_action_snapshot_create = {
      78             :   .name           = "snapshot-create",
      79             :   .args           = snapshot_create_cmd_args,
      80             :   .fn             = snapshot_create_cmd_fn,
      81             :   .description    = "Create a snapshot",
      82             :   .usage          = "snapshot-create [OPTIONS]",
      83             :   .args_help      = snapshot_create_args_help,
      84             : };

Generated by: LCOV version 1.14