Line data Source code
1 : #ifndef HEADER_fd_src_app_fdctl_configure_configure_h 2 : #define HEADER_fd_src_app_fdctl_configure_configure_h 3 : 4 : #include "../fdctl.h" 5 : 6 : #include <stdarg.h> 7 : 8 0 : #define CONFIGURE_NR_OPEN_FILES (1024000U) 9 : 10 : enum { 11 : CONFIGURE_NOT_CONFIGURED, 12 : CONFIGURE_PARTIALLY_CONFIGURED, 13 : CONFIGURE_OK, 14 : }; 15 : 16 : typedef struct { 17 : int result; 18 : char message[ 256 ]; 19 : } configure_result_t; 20 : 21 0 : #define CHECK(x) do { \ 22 0 : configure_result_t result = (x); \ 23 0 : if( FD_UNLIKELY( result.result != CONFIGURE_OK ) ) { \ 24 0 : return result; \ 25 0 : } \ 26 0 : } while( 0 ) 27 : 28 0 : #define NOT_CONFIGURED(...) do { \ 29 0 : configure_result_t result; \ 30 0 : result.result = CONFIGURE_NOT_CONFIGURED; \ 31 0 : FD_TEST( fd_cstr_printf_check( result.message, \ 32 0 : sizeof( result.message ), \ 33 0 : NULL, \ 34 0 : __VA_ARGS__ ) ); \ 35 0 : return result; \ 36 0 : } while( 0 ) 37 : 38 0 : #define PARTIALLY_CONFIGURED(...) do { \ 39 0 : configure_result_t result; \ 40 0 : result.result = CONFIGURE_PARTIALLY_CONFIGURED; \ 41 0 : FD_TEST( fd_cstr_printf_check( result.message, \ 42 0 : sizeof( result.message ), \ 43 0 : NULL, \ 44 0 : __VA_ARGS__ ) ); \ 45 0 : return result; \ 46 0 : } while( 0 ) 47 : 48 0 : #define CONFIGURE_OK() do { \ 49 0 : configure_result_t result; \ 50 0 : result.result = CONFIGURE_OK; \ 51 0 : result.message[ 0 ] = '\0'; \ 52 0 : return result; \ 53 0 : } while( 0 ) 54 : 55 : typedef struct configure_stage { 56 : const char * name; 57 : int always_recreate; 58 : int (*enabled) ( config_t * const config ); 59 : void (*init_perm)( fd_caps_ctx_t * caps, config_t * const config ); 60 : void (*fini_perm)( fd_caps_ctx_t * caps, config_t * const config ); 61 : void (*init) ( config_t * const config ); 62 : void (*fini) ( config_t * const config, int pre_init ); 63 : configure_result_t (*check) ( config_t * const config ); 64 : } configure_stage_t; 65 : 66 : extern configure_stage_t hugetlbfs; 67 : extern configure_stage_t sysctl; 68 : extern configure_stage_t ethtool_channels; 69 : extern configure_stage_t ethtool_gro; 70 : extern configure_stage_t workspace; 71 : 72 : extern configure_stage_t * STAGES[]; 73 : 74 : typedef enum { 75 : CONFIGURE_CMD_INIT, 76 : CONFIGURE_CMD_CHECK, 77 : CONFIGURE_CMD_FINI, 78 : } configure_cmd_t; 79 : 80 : typedef struct { 81 : configure_cmd_t command; 82 : configure_stage_t ** stages; 83 : } configure_args_t; 84 : 85 : /* try_defragment_memory() tells the operating system to defragment 86 : memory allocations, it it is hint, and can be useful to call before 87 : trying to request large contiguous memory to be mapped. */ 88 : void try_defragment_memory( void ); 89 : 90 : /* Enter the network namespace given in the configuration in this 91 : process. If this call succeeds the process is now inside the 92 : namespace. */ 93 : void enter_network_namespace( const char * interface ); 94 : 95 : void leave_network_namespace( void ); 96 : 97 : void close_network_namespace_original_fd( void ); 98 : 99 : /* Checks if a directory exists and is configured with the given uid, 100 : gid, and access mode. */ 101 : configure_result_t 102 : check_dir( const char * path, 103 : uint uid, 104 : uint gid, 105 : uint mode ); 106 : 107 : /* Checks if a file exists and is configured with the given uid, gid, 108 : and access mode. */ 109 : configure_result_t 110 : check_file( const char * path, 111 : uint uid, 112 : uint gid, 113 : uint mode ); 114 : 115 : #endif /* HEADER_fd_src_app_fdctl_configure_configure_h */