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