Line data Source code
1 : #ifndef HEADER_fd_src_app_shared_commands_configure_configure_h 2 : #define HEADER_fd_src_app_shared_commands_configure_configure_h 3 : 4 : #include "../../../platform/fd_cap_chk.h" 5 : #include "../../fd_config.h" 6 : #include "../../fd_action.h" 7 : #include "../../../../disco/net/fd_net_tile.h" 8 : 9 : #include <stdarg.h> 10 : 11 0 : #define CONFIGURE_NR_OPEN_FILES (1024000U) 12 : 13 : enum { 14 : CONFIGURE_NOT_CONFIGURED, 15 : CONFIGURE_PARTIALLY_CONFIGURED, 16 : CONFIGURE_OK, 17 : }; 18 : 19 : typedef struct { 20 : int result; 21 : char message[ 256 ]; 22 : } configure_result_t; 23 : 24 0 : #define CHECK(x) do { \ 25 0 : configure_result_t result = (x); \ 26 0 : if( FD_UNLIKELY( result.result != CONFIGURE_OK ) ) { \ 27 0 : return result; \ 28 0 : } \ 29 0 : } while( 0 ) 30 : 31 0 : #define NOT_CONFIGURED(...) do { \ 32 0 : configure_result_t result; \ 33 0 : result.result = CONFIGURE_NOT_CONFIGURED; \ 34 0 : FD_TEST( fd_cstr_printf_check( result.message, \ 35 0 : sizeof( result.message ), \ 36 0 : NULL, \ 37 0 : __VA_ARGS__ ) ); \ 38 0 : return result; \ 39 0 : } while( 0 ) 40 : 41 0 : #define PARTIALLY_CONFIGURED(...) do { \ 42 0 : configure_result_t result; \ 43 0 : result.result = CONFIGURE_PARTIALLY_CONFIGURED; \ 44 0 : FD_TEST( fd_cstr_printf_check( result.message, \ 45 0 : sizeof( result.message ), \ 46 0 : NULL, \ 47 0 : __VA_ARGS__ ) ); \ 48 0 : return result; \ 49 0 : } while( 0 ) 50 : 51 0 : #define CONFIGURE_OK() do { \ 52 0 : configure_result_t result; \ 53 0 : result.result = CONFIGURE_OK; \ 54 0 : result.message[ 0 ] = '\0'; \ 55 0 : return result; \ 56 0 : } while( 0 ) 57 : 58 : #define FD_CONFIGURE_CHECK_TYPE_INIT_PERM (0) 59 0 : #define FD_CONFIGURE_CHECK_TYPE_FINI_PERM (1) 60 0 : #define FD_CONFIGURE_CHECK_TYPE_PRE_INIT (2) 61 0 : #define FD_CONFIGURE_CHECK_TYPE_UNDO_INIT (3) 62 0 : #define FD_CONFIGURE_CHECK_TYPE_POST_INIT (4) 63 0 : #define FD_CONFIGURE_CHECK_TYPE_CHECK (5) 64 0 : #define FD_CONFIGURE_CHECK_TYPE_PRE_FINI (6) 65 0 : #define FD_CONFIGURE_CHECK_TYPE_POST_FINI (7) 66 0 : #define FD_CONFIGURE_CHECK_TYPE_RUN (8) 67 : 68 : /* fini() returns whether or not it took any actions. */ 69 : 70 : typedef struct configure_stage { 71 : const char * name; 72 : int always_recreate; 73 : int (*enabled) ( config_t const * config ); 74 : void (*init_perm)( fd_cap_chk_t * chk, config_t const * config ); 75 : void (*fini_perm)( fd_cap_chk_t * chk, config_t const * config ); 76 : void (*init) ( config_t const * config ); 77 : int (*fini) ( config_t const * config, int pre_init ); 78 : configure_result_t (*check) ( config_t const * config, int check_type ); 79 : } configure_stage_t; 80 : 81 : extern configure_stage_t fd_cfg_stage_hugetlbfs; 82 : extern configure_stage_t fd_cfg_stage_iavf; 83 : extern configure_stage_t fd_cfg_stage_mlx5; 84 : extern configure_stage_t fd_cfg_stage_sysctl; 85 : extern configure_stage_t fd_cfg_stage_hyperthreads; 86 : extern configure_stage_t fd_cfg_stage_bonding; 87 : extern configure_stage_t fd_cfg_stage_ethtool_channels; 88 : extern configure_stage_t fd_cfg_stage_ethtool_offloads; 89 : extern configure_stage_t fd_cfg_stage_ethtool_loopback; 90 : extern configure_stage_t fd_cfg_stage_irq_affinity; 91 : extern configure_stage_t fd_cfg_stage_irq_balance; 92 : extern configure_stage_t fd_cfg_stage_sysfs_poll; 93 : extern configure_stage_t fd_cfg_stage_snapshots; 94 : extern configure_stage_t fd_cfg_stage_kworkers; 95 : extern configure_stage_t fd_cfg_stage_cpuset; 96 : extern configure_stage_t fd_cfg_stage_nohz_full; 97 : extern configure_stage_t fd_cfg_stage_rcu_nocbs; 98 : extern configure_stage_t fd_cfg_stage_console; 99 : 100 : extern configure_stage_t * STAGES[]; 101 : 102 : typedef enum { 103 : CONFIGURE_CMD_INIT, 104 : CONFIGURE_CMD_CHECK, 105 : CONFIGURE_CMD_FINI, 106 : } configure_cmd_t; 107 : 108 : typedef struct { 109 : configure_cmd_t command; 110 : configure_stage_t ** stages; 111 : } configure_args_t; 112 : 113 : /* Checks if a directory exists and is configured with the given uid, 114 : gid, and access mode. */ 115 : configure_result_t 116 : check_dir( const char * path, 117 : uint uid, 118 : uint gid, 119 : uint mode ); 120 : 121 : /* Checks if a file exists and is configured with the given uid, gid, 122 : and access mode. */ 123 : configure_result_t 124 : check_file( const char * path, 125 : uint uid, 126 : uint gid, 127 : uint mode ); 128 : 129 : int 130 : configure_stage( configure_stage_t * stage, 131 : configure_cmd_t command, 132 : config_t const * config ); 133 : 134 : /* configure_udp_ports lists the UDP listen ports */ 135 : uint 136 : configure_udp_ports( fd_config_t const * config, 137 : ushort ports[ FD_NET_RX_DEST_CNT ] ); 138 : 139 : void configure_cmd_args( int * pargc, char *** pargv, args_t * args ); 140 : void configure_cmd_perm( args_t * args, fd_cap_chk_t * chk, config_t const * config ); 141 : void configure_cmd_fn ( args_t * args, config_t * config ); 142 : 143 : extern action_t fd_action_configure; 144 : 145 : #endif /* HEADER_fd_src_app_shared_commands_configure_configure_h */