Line data Source code
1 : #include "configure.h"
2 :
3 : #include <stdio.h>
4 : #include <dirent.h>
5 : #include <sys/stat.h>
6 : #include <sys/mount.h>
7 : #include <linux/capability.h>
8 :
9 : static void
10 : init_perm( fd_caps_ctx_t * caps,
11 0 : config_t * const config ) {
12 0 : (void)config;
13 0 : fd_caps_check_root( caps, "hugetlbfs", "increase `/proc/sys/vm/nr_hugepages`" );
14 0 : fd_caps_check_capability( caps, "hugetlbfs", CAP_SYS_ADMIN, "mount hugetlbfs filesystems" );
15 0 : }
16 :
17 : static void
18 : fini_perm( fd_caps_ctx_t * caps,
19 0 : config_t * const config ) {
20 0 : (void)config;
21 0 : fd_caps_check_root( caps, "hugetlbfs", "remove directories from `/mnt`" );
22 0 : fd_caps_check_capability( caps, "hugetlbfs", CAP_SYS_ADMIN, "unmount hugetlbfs filesystems" );
23 0 : }
24 :
25 : static const char * ERR_MSG = "please confirm your host is configured for gigantic pages,";
26 :
27 : static char const * TOTAL_HUGE_PAGE_PATH[ 2 ] = {
28 : "/sys/devices/system/node/node%lu/hugepages/hugepages-2048kB/nr_hugepages",
29 : "/sys/devices/system/node/node%lu/hugepages/hugepages-1048576kB/nr_hugepages",
30 : };
31 :
32 : static char const * FREE_HUGE_PAGE_PATH[ 2 ] = {
33 : "/sys/devices/system/node/node%lu/hugepages/hugepages-2048kB/free_hugepages",
34 : "/sys/devices/system/node/node%lu/hugepages/hugepages-1048576kB/free_hugepages",
35 : };
36 :
37 : static ulong PAGE_SIZE[ 2 ] = {
38 : 2097152,
39 : 1073741824,
40 : };
41 :
42 : static char const * PAGE_NAMES[ 2 ] = {
43 : "huge",
44 : "gigantic"
45 : };
46 :
47 : static void
48 0 : init( config_t * const config ) {
49 0 : char const * mount_path[ 2 ] = {
50 0 : config->hugetlbfs.huge_page_mount_path,
51 0 : config->hugetlbfs.gigantic_page_mount_path,
52 0 : };
53 :
54 0 : ulong numa_node_cnt = fd_shmem_numa_cnt();
55 0 : for( ulong i=0UL; i<numa_node_cnt; i++ ) {
56 0 : ulong required_pages[ 2 ] = {
57 0 : fd_topo_huge_page_cnt( &config->topo, i, 0 ),
58 0 : fd_topo_gigantic_page_cnt( &config->topo, i ),
59 0 : };
60 :
61 0 : for( ulong j=0UL; j<2UL; j++ ) {
62 0 : char free_page_path[ PATH_MAX ];
63 0 : FD_TEST( fd_cstr_printf_check( free_page_path, PATH_MAX, NULL, FREE_HUGE_PAGE_PATH[ j ], i ) );
64 0 : ulong free_pages = read_uint_file( free_page_path, ERR_MSG );
65 :
66 : /* There is a TOCTOU race condition here, but it's not avoidable. There's
67 : no way to atomically increment the page count. */
68 0 : FD_TEST( required_pages[ j ]<=UINT_MAX );
69 0 : if( FD_UNLIKELY( free_pages<required_pages[ j ] ) ) {
70 0 : char total_page_path[ PATH_MAX ];
71 0 : FD_TEST( fd_cstr_printf_check( total_page_path, PATH_MAX, NULL, TOTAL_HUGE_PAGE_PATH[ j ], i ) );
72 0 : ulong total_pages = read_uint_file( total_page_path, ERR_MSG );
73 0 : ulong additional_pages_needed = required_pages[ j ]-free_pages;
74 :
75 0 : FD_LOG_NOTICE(( "RUN: `echo \"%u\" > %s`", (uint)(total_pages+additional_pages_needed), total_page_path ));
76 0 : write_uint_file( total_page_path, (uint)(total_pages+additional_pages_needed) );
77 0 : uint raised_free_pages = read_uint_file( free_page_path, ERR_MSG );
78 0 : if( FD_UNLIKELY( raised_free_pages<required_pages[ j ] ) ) {
79 : /* Well.. usually this is due to memory being fragmented,
80 : rather than not having enough memory. See something like
81 : https://tatref.github.io/blog/2023-visual-linux-memory-compact/
82 : for the sequence we do here. */
83 0 : FD_LOG_WARNING(( "ENOMEM-Out of memory when trying to reserve %s pages for Firedancer on NUMA node %lu. Compacting memory before trying again.",
84 0 : PAGE_NAMES[ j ],
85 0 : i ));
86 0 : FD_LOG_NOTICE(( "RUN: `echo \"1\" > /proc/sys/vm/compact_memory" ));
87 0 : write_uint_file( "/proc/sys/vm/compact_memory", 1 );
88 : /* Sleep a little to give the OS some time to perform the
89 : compaction. */
90 0 : nanosleep1( 0, 500000000 /* 500 millis */ );
91 0 : FD_LOG_NOTICE(( "RUN: `echo \"3\" > /proc/sys/vm/drop_caches" ));
92 0 : write_uint_file( "/proc/sys/vm/drop_caches", 3 );
93 0 : nanosleep1( 0, 500000000 /* 500 millis */ );
94 0 : FD_LOG_NOTICE(( "RUN: `echo \"1\" > /proc/sys/vm/compact_memory" ));
95 0 : write_uint_file( "/proc/sys/vm/compact_memory", 1 );
96 0 : nanosleep1( 0, 500000000 /* 500 millis */ );
97 0 : }
98 :
99 0 : FD_LOG_NOTICE(( "RUN: `echo \"%u\" > %s`", (uint)(total_pages+additional_pages_needed), total_page_path ));
100 0 : write_uint_file( total_page_path, (uint)(total_pages+additional_pages_needed) );
101 0 : raised_free_pages = read_uint_file( free_page_path, ERR_MSG );
102 0 : if( FD_UNLIKELY( raised_free_pages<required_pages[ j ] ) ) {
103 0 : FD_LOG_ERR(( "ENOMEM-Out of memory when trying to reserve %s pages for Firedancer on NUMA node %lu. Your Firedancer "
104 0 : "configuration requires %lu GiB of memory total consisting of %lu gigantic (1GiB) pages and %lu huge (2MiB) "
105 0 : "pages on this NUMA node but only %u %s pages were available according to `%s` (raised from %lu). If your "
106 0 : "system has the required amount of memory, this can be because it is not configured with %s page support, or "
107 0 : "Firedancer cannot increase the value of `%s` at runtime. You might need to enable huge pages in grub at boot "
108 0 : "time. This error can also happen because system uptime is high and memory is fragmented. You can fix this by "
109 0 : "rebooting the machine and running the `hugetlbfs` stage immediately on boot.",
110 0 : PAGE_NAMES[ j ],
111 0 : i,
112 0 : required_pages[ 1 ] + (required_pages[ 0 ] / 512),
113 0 : required_pages[ 1 ],
114 0 : required_pages[ 0 ],
115 0 : raised_free_pages,
116 0 : PAGE_NAMES[ j ],
117 0 : free_page_path,
118 0 : free_pages,
119 0 : PAGE_NAMES[ j ],
120 0 : total_page_path ));
121 0 : }
122 0 : }
123 0 : }
124 0 : }
125 :
126 : /* Do NOT include anonymous huge pages in the min_size count that
127 : we reserve here, because they do not come from the hugetlbfs.
128 : Counting them towards that reservation would prevent the
129 : anonymous mmap which maps them in from succeeding.
130 :
131 : The kernel min_size option for the hugetlbfs does not include an
132 : option to reserve pages from a specific NUMA node, so we simply
133 : take the sum here and hope they are distributed correctly. If
134 : they are not, creating files in the mount on a specific node may
135 : fail later with ENOMEM. */
136 :
137 0 : ulong min_size[ 2 ] = {0};
138 0 : for( ulong i=0UL; i<numa_node_cnt; i++ ) {
139 0 : min_size[ 0 ] += PAGE_SIZE[ 0 ] * fd_topo_huge_page_cnt( &config->topo, i, 0 );
140 0 : min_size[ 1 ] += PAGE_SIZE[ 1 ] * fd_topo_gigantic_page_cnt( &config->topo, i );
141 0 : }
142 :
143 0 : for( ulong i=0UL; i<2UL; i++ ) {
144 0 : FD_LOG_NOTICE(( "RUN: `mkdir -p %s`", mount_path[ i ] ));
145 0 : mkdir_all( mount_path[ i ], config->uid, config->gid );
146 0 : char options[ 256 ];
147 0 : FD_TEST( fd_cstr_printf_check( options, sizeof(options), NULL, "pagesize=%lu,min_size=%lu", PAGE_SIZE[ i ], min_size[ i ] ) );
148 0 : FD_LOG_NOTICE(( "RUN: `mount -t hugetlbfs none %s -o %s`", mount_path[ i ], options ));
149 0 : if( FD_UNLIKELY( mount( "none", mount_path[ i ], "hugetlbfs", 0, options) ) )
150 0 : FD_LOG_ERR(( "mount of hugetlbfs at `%s` failed (%i-%s)", mount_path[ i ], errno, fd_io_strerror( errno ) ));
151 0 : if( FD_UNLIKELY( chown( mount_path[ i ], config->uid, config->gid ) ) )
152 0 : FD_LOG_ERR(( "chown of hugetlbfs at `%s` failed (%i-%s)", mount_path[ i ], errno, fd_io_strerror( errno ) ));
153 0 : if( FD_UNLIKELY( chmod( mount_path[ i ], S_IRUSR | S_IWUSR | S_IXUSR ) ) )
154 0 : FD_LOG_ERR(( "chmod of hugetlbfs at `%s` failed (%i-%s)", mount_path[ i ], errno, fd_io_strerror( errno ) ));
155 0 : }
156 0 : }
157 :
158 : static void
159 : cmdline( char * buf,
160 0 : ulong buf_sz ) {
161 0 : FILE * fp = fopen( "/proc/self/cmdline", "r" );
162 0 : if( FD_UNLIKELY( !fp ) ) FD_LOG_ERR(( "error opening `/proc/self/cmdline` (%i-%s)", errno, fd_io_strerror( errno ) ));
163 :
164 0 : ulong read = fread( buf, 1UL, buf_sz - 1UL, fp );
165 0 : if( FD_UNLIKELY( ferror( fp ) ) ) FD_LOG_ERR(( "error reading `/proc/self/cmdline` (%i-%s)", errno, fd_io_strerror( errno ) ));
166 0 : if( FD_UNLIKELY( fclose( fp ) ) ) FD_LOG_ERR(( "error closing `/proc/self/cmdline` (%i-%s)", errno, fd_io_strerror( errno ) ));
167 :
168 0 : buf[ read ] = '\0';
169 0 : }
170 :
171 : static void
172 0 : warn_mount_users( char const * mount_path ) {
173 0 : DIR * dir = opendir( "/proc" );
174 0 : if( FD_UNLIKELY( !dir ) ) FD_LOG_ERR(( "error opening `/proc` (%i-%s)", errno, fd_io_strerror( errno ) ));
175 :
176 0 : struct dirent * entry;
177 0 : while(( FD_LIKELY( entry = readdir( dir ) ) )) {
178 0 : if( FD_UNLIKELY( !strcmp( entry->d_name, "." ) || !strcmp( entry->d_name, ".." ) ) ) continue;
179 0 : char * endptr;
180 0 : ulong pid = strtoul( entry->d_name, &endptr, 10 );
181 0 : if( FD_UNLIKELY( *endptr ) ) continue;
182 :
183 0 : char path[ PATH_MAX ];
184 0 : FD_TEST( fd_cstr_printf_check( path, PATH_MAX, NULL, "/proc/%lu/maps", pid ) );
185 0 : FILE * fp = fopen( path, "r" );
186 0 : if( FD_UNLIKELY( !fp && errno!=ENOENT ) ) FD_LOG_ERR(( "error opening `%s` (%i-%s)", path, errno, fd_io_strerror( errno ) ));
187 :
188 0 : char self_cmdline[ PATH_MAX ];
189 0 : cmdline( self_cmdline, PATH_MAX );
190 :
191 0 : char line[ 4096 ];
192 0 : while( FD_LIKELY( fgets( line, 4096, fp ) ) ) {
193 0 : if( FD_UNLIKELY( strlen( line )==4095 ) ) FD_LOG_ERR(( "line too long in `%s`", path ));
194 0 : if( FD_UNLIKELY( strstr( line, mount_path ) ) ) {
195 0 : FD_LOG_WARNING(( "process `%lu`:`%s` has a file descriptor open in `%s`", pid, self_cmdline, mount_path ));
196 0 : break;
197 0 : }
198 0 : }
199 0 : if( FD_UNLIKELY( ferror( fp ) ) )
200 0 : FD_LOG_ERR(( "error reading `%s` (%i-%s)", path, errno, fd_io_strerror( errno ) ));
201 0 : if( FD_LIKELY( fclose( fp ) ) )
202 0 : FD_LOG_ERR(( "error closing `%s` (%i-%s)", path, errno, fd_io_strerror( errno ) ));
203 0 : }
204 :
205 0 : if( FD_UNLIKELY( -1==closedir( dir ) ) ) FD_LOG_ERR(( "closedir (%i-%s)", errno, fd_io_strerror( errno ) ));
206 0 : }
207 :
208 : static void
209 : fini( config_t * const config,
210 0 : int pre_init ) {
211 0 : (void)pre_init;
212 :
213 : /* Not used by fdctl but might be created by other debugging tools
214 : on the system. */
215 :
216 0 : char normal_page_mount_path[ PATH_MAX ];
217 0 : FD_TEST( fd_cstr_printf_check( normal_page_mount_path, PATH_MAX, NULL, "%s/.normal", config->hugetlbfs.mount_path ) );
218 :
219 0 : const char * mount_path[ 3 ] = {
220 0 : config->hugetlbfs.huge_page_mount_path,
221 0 : config->hugetlbfs.gigantic_page_mount_path,
222 0 : normal_page_mount_path,
223 0 : };
224 :
225 0 : for( ulong i=0UL; i<3UL; i++ ) {
226 0 : FILE * fp = fopen( "/proc/self/mounts", "r" );
227 0 : if( FD_UNLIKELY( !fp ) ) FD_LOG_ERR(( "failed to open `/proc/self/mounts`" ));
228 :
229 0 : char line[ 4096 ];
230 0 : while( FD_LIKELY( fgets( line, 4096UL, fp ) ) ) {
231 0 : if( FD_UNLIKELY( strlen( line )==4095UL ) ) FD_LOG_ERR(( "line too long in `/proc/self/mounts`" ));
232 0 : if( FD_UNLIKELY( strstr( line, mount_path[ i ] ) ) ) {
233 0 : FD_LOG_NOTICE(( "RUN: `umount %s`", mount_path[ i ] ));
234 0 : if( FD_UNLIKELY( umount( mount_path[ i ] ) ) ) {
235 0 : if( FD_LIKELY( errno==EBUSY ) ) {
236 0 : warn_mount_users( mount_path[ i ] );
237 :
238 0 : FD_LOG_ERR(( "Unmount of hugetlbfs at `%s` failed because the mount is still in use. "
239 0 : "You can unmount it by killing all processes that are actively using files in "
240 0 : "the mount and running `fdctl configure fini hugetlbfs` again, or unmount "
241 0 : "manually with `umount %s`", mount_path[ i ], mount_path[ i ] ));
242 0 : } else {
243 0 : FD_LOG_ERR(( "umount of hugetlbfs at `%s` failed (%i-%s)", mount_path[ i ], errno, fd_io_strerror( errno ) ));
244 0 : }
245 0 : }
246 0 : }
247 0 : }
248 :
249 0 : if( FD_UNLIKELY( ferror( fp ) ) )
250 0 : FD_LOG_ERR(( "error reading `/proc/self/mounts` (%i-%s)", errno, fd_io_strerror( errno ) ));
251 0 : if( FD_LIKELY( fclose( fp ) ) )
252 0 : FD_LOG_ERR(( "error closing `/proc/self/mounts` (%i-%s)", errno, fd_io_strerror( errno ) ));
253 :
254 0 : FD_LOG_NOTICE(( "RUN: `rmdir %s`", mount_path[ i ] ));
255 0 : if( FD_UNLIKELY( rmdir( mount_path[ i ] ) && errno!=ENOENT ) )
256 0 : FD_LOG_ERR(( "error removing hugetlbfs mount at `%s` (%i-%s)", mount_path[ i ], errno, fd_io_strerror( errno ) ));
257 0 : }
258 :
259 0 : FD_LOG_NOTICE(( "RUN: `rmdir %s`", config->hugetlbfs.mount_path ));
260 0 : if( FD_UNLIKELY( rmdir( config->hugetlbfs.mount_path ) && errno!=ENOENT ) )
261 0 : FD_LOG_ERR(( "error removing hugetlbfs directory at `%s` (%i-%s)", config->hugetlbfs.mount_path, errno, fd_io_strerror( errno ) ));
262 0 : }
263 :
264 : static configure_result_t
265 0 : check( config_t * const config ) {
266 0 : char const * mount_path[ 2 ] = {
267 0 : config->hugetlbfs.huge_page_mount_path,
268 0 : config->hugetlbfs.gigantic_page_mount_path,
269 0 : };
270 :
271 0 : static char const * MOUNT_PAGE_SIZE[ 2 ] = {
272 0 : "pagesize=2M",
273 0 : "pagesize=1024M",
274 0 : };
275 :
276 0 : ulong numa_node_cnt = fd_shmem_numa_cnt();
277 0 : ulong required_min_size[ 2 ] = {0};
278 0 : for( ulong i=0UL; i<numa_node_cnt; i++ ) {
279 0 : required_min_size[ 0 ] += PAGE_SIZE[ 0 ] * fd_topo_huge_page_cnt( &config->topo, i, 0 );
280 0 : required_min_size[ 1 ] += PAGE_SIZE[ 1 ] * fd_topo_gigantic_page_cnt( &config->topo, i );
281 0 : }
282 :
283 0 : struct stat st;
284 0 : int result1 = stat( mount_path[ 0 ], &st );
285 0 : if( FD_UNLIKELY( result1 && errno!=ENOENT ) )
286 0 : PARTIALLY_CONFIGURED( "failed to stat `%s` (%i-%s)", mount_path[ 0 ], errno, fd_io_strerror( errno ) );
287 0 : int result2 = stat( mount_path[ 1 ], &st );
288 0 : if( FD_UNLIKELY( result2 && errno!=ENOENT ) )
289 0 : PARTIALLY_CONFIGURED( "failed to stat `%s` (%i-%s)", mount_path[ 1 ], errno, fd_io_strerror( errno ) );
290 :
291 0 : if( FD_UNLIKELY( result1 && result2 ) )
292 0 : NOT_CONFIGURED( "mounts `%s` and `%s` do not exist", mount_path[ 0 ], mount_path[ 1 ] );
293 0 : else if( FD_UNLIKELY( result1 ) )
294 0 : PARTIALLY_CONFIGURED( "mount `%s` does not exist", mount_path[ 0 ] );
295 0 : else if( FD_UNLIKELY( result2 ) )
296 0 : PARTIALLY_CONFIGURED( "mount `%s` does not exist", mount_path[ 1 ] );
297 :
298 0 : CHECK( check_dir( config->hugetlbfs.mount_path, config->uid, config->gid, S_IFDIR | S_IRUSR | S_IWUSR | S_IXUSR ) );
299 0 : for( ulong i=0UL; i<2UL; i++ ) {
300 0 : CHECK( check_dir( mount_path[ i ], config->uid, config->gid, S_IFDIR | S_IRUSR | S_IWUSR | S_IXUSR ) );
301 :
302 0 : FILE * fp = fopen( "/proc/self/mounts", "r" );
303 0 : if( FD_UNLIKELY( !fp ) ) FD_LOG_ERR(( "failed to open `/proc/self/mounts`" ));
304 :
305 0 : char line[ 4096 ];
306 0 : int found = 0;
307 0 : while( FD_LIKELY( fgets( line, 4096UL, fp ) ) ) {
308 0 : if( FD_UNLIKELY( strlen( line )==4095UL ) ) FD_LOG_ERR(( "line too long in `/proc/self/mounts`" ));
309 0 : if( FD_UNLIKELY( strstr( line, mount_path[ i ] ) ) ) {
310 0 : found = 1;
311 :
312 0 : char * saveptr;
313 0 : char * device = strtok_r( line, " ", &saveptr );
314 0 : if( FD_UNLIKELY( !device ) ) FD_LOG_ERR(( "error parsing `/proc/self/mounts`, line `%s`", line ));
315 0 : if( FD_UNLIKELY( strcmp( device, "none" ) ) ) {
316 0 : if( FD_UNLIKELY( fclose( fp ) ) )
317 0 : FD_LOG_ERR(( "error closing `/proc/self/mounts` (%i-%s)", errno, fd_io_strerror( errno ) ));
318 0 : PARTIALLY_CONFIGURED( "mount `%s` is on unrecognized device, expected `none`", mount_path[ i ] );
319 0 : }
320 :
321 0 : char * path1 = strtok_r( NULL, " ", &saveptr );
322 0 : if( FD_UNLIKELY( !path1 ) ) FD_LOG_ERR(( "error parsing `/proc/self/mounts`, line `%s`", line ));
323 0 : if( FD_UNLIKELY( strcmp( path1, mount_path[ i ] ) ) ) {
324 0 : if( FD_UNLIKELY( fclose( fp ) ) )
325 0 : FD_LOG_ERR(( "error closing `/proc/self/mounts` (%i-%s)", errno, fd_io_strerror( errno ) ));
326 0 : PARTIALLY_CONFIGURED( "mount `%s` is on unrecognized path, expected `%s`", path1, mount_path[ i ] );
327 0 : }
328 :
329 0 : char * type = strtok_r( NULL, " ", &saveptr );
330 0 : if( FD_UNLIKELY( !type ) ) FD_LOG_ERR(( "error parsing `/proc/self/mounts`, line `%s`", line ));
331 0 : if( FD_UNLIKELY( strcmp( type, "hugetlbfs" ) ) ) {
332 0 : if( FD_UNLIKELY( fclose( fp ) ) )
333 0 : FD_LOG_ERR(( "error closing `/proc/self/mounts` (%i-%s)", errno, fd_io_strerror( errno ) ));
334 0 : PARTIALLY_CONFIGURED( "mount `%s` has unrecognized type, expected `hugetlbfs`", mount_path[ i ] );
335 0 : }
336 :
337 0 : char * options = strtok_r( NULL, " ", &saveptr );
338 0 : if( FD_UNLIKELY( !options ) ) FD_LOG_ERR(( "error parsing `/proc/self/mounts`, line `%s`", line ));
339 :
340 0 : char * saveptr2;
341 0 : char * rw = strtok_r( options, ",", &saveptr2 );
342 0 : if( FD_UNLIKELY( !rw ) ) FD_LOG_ERR(( "error parsing `/proc/self/mounts`, line `%s`", line ));
343 0 : if( FD_UNLIKELY( strcmp( rw, "rw" ) ) ) {
344 0 : if( FD_UNLIKELY( fclose( fp ) ) )
345 0 : FD_LOG_ERR(( "error closing `/proc/self/mounts` (%i-%s)", errno, fd_io_strerror( errno ) ));
346 0 : PARTIALLY_CONFIGURED( "mount `%s` is not mounted read/write, expected `rw`", mount_path[ i ] );
347 0 : }
348 :
349 0 : char * seclabel = strtok_r( NULL, ",", &saveptr2 );
350 0 : if( FD_UNLIKELY( !seclabel ) ) FD_LOG_ERR(( "error parsing `/proc/self/mounts`, line `%s`", line ));
351 :
352 0 : char * relatime;
353 0 : if( FD_LIKELY( !strcmp( seclabel, "seclabel" ) ) ) {
354 0 : relatime = strtok_r( NULL, ",", &saveptr2 );
355 0 : if( FD_UNLIKELY( !relatime ) ) FD_LOG_ERR(( "error parsing `/proc/self/mounts`, line `%s`", line ));
356 0 : } else {
357 0 : relatime = seclabel;
358 0 : }
359 :
360 0 : if( FD_UNLIKELY( strcmp( relatime, "relatime" ) ) ) {
361 0 : if( FD_UNLIKELY( fclose( fp ) ) )
362 0 : FD_LOG_ERR(( "error closing `/proc/self/mounts` (%i-%s)", errno, fd_io_strerror( errno ) ));
363 0 : PARTIALLY_CONFIGURED( "mount `%s` is not mounted with `relatime`, expected `relatime`", mount_path[ i ] );
364 0 : }
365 :
366 0 : char * pagesize = strtok_r( NULL, ",", &saveptr2 );
367 0 : if( FD_UNLIKELY( !pagesize ) ) FD_LOG_ERR(( "error parsing `/proc/self/mounts`, line `%s`", line ));
368 0 : if( FD_UNLIKELY( strcmp( pagesize, MOUNT_PAGE_SIZE[ i ] ) ) ) {
369 0 : if( FD_UNLIKELY( fclose( fp ) ) )
370 0 : FD_LOG_ERR(( "error closing `/proc/self/mounts` (%i-%s)", errno, fd_io_strerror( errno ) ));
371 0 : PARTIALLY_CONFIGURED( "mount `%s` has unrecognized pagesize, expected `%s` %s", mount_path[ i ], MOUNT_PAGE_SIZE[ i ], pagesize );
372 0 : }
373 :
374 0 : char * _min_size = strtok_r( NULL, ",", &saveptr2 );
375 0 : if( FD_UNLIKELY( !_min_size ) ) FD_LOG_ERR(( "error parsing `/proc/self/mounts`, line `%s`", line ));
376 0 : if( FD_UNLIKELY( strncmp( "min_size=", _min_size, 9UL ) ) ) {
377 0 : if( FD_UNLIKELY( fclose( fp ) ) )
378 0 : FD_LOG_ERR(( "error closing `/proc/self/mounts` (%i-%s)", errno, fd_io_strerror( errno ) ));
379 0 : PARTIALLY_CONFIGURED( "mount `%s` has unrecognized min_size, expected at least `min_size=%lu`", mount_path[ i ], required_min_size[ i ] );
380 0 : }
381 :
382 0 : char * endptr;
383 0 : ulong min_size = strtoul( _min_size+9, &endptr, 10 );
384 0 : if( FD_UNLIKELY( *endptr ) ) {
385 0 : if( FD_UNLIKELY( fclose( fp ) ) )
386 0 : FD_LOG_ERR(( "error closing `/proc/self/mounts` (%i-%s)", errno, fd_io_strerror( errno ) ));
387 0 : PARTIALLY_CONFIGURED( "mount `%s` has malformed min_size, expected `min_size=%lu`", mount_path[ i ], required_min_size[ i ] );
388 0 : }
389 :
390 0 : if( FD_UNLIKELY( min_size<required_min_size[ i ] ) ) {
391 0 : if( FD_UNLIKELY( fclose( fp ) ) )
392 0 : FD_LOG_ERR(( "error closing `/proc/self/mounts` (%i-%s)", errno, fd_io_strerror( errno ) ));
393 0 : PARTIALLY_CONFIGURED( "mount `%s` has min_size `%lu`, expected at least `min_size=%lu`", mount_path[ i ], min_size, required_min_size[ i ] );
394 0 : }
395 :
396 0 : break;
397 0 : }
398 0 : }
399 :
400 0 : if( FD_UNLIKELY( ferror( fp ) ) )
401 0 : FD_LOG_ERR(( "error reading `/proc/self/mounts` (%i-%s)", errno, fd_io_strerror( errno ) ));
402 0 : if( FD_LIKELY( fclose( fp ) ) )
403 0 : FD_LOG_ERR(( "error closing `/proc/self/mounts` (%i-%s)", errno, fd_io_strerror( errno ) ));
404 :
405 0 : if( FD_UNLIKELY( !found ) )
406 0 : PARTIALLY_CONFIGURED( "mount `%s` not found in `/proc/self/mounts`", mount_path[ i ] );
407 0 : }
408 :
409 0 : CONFIGURE_OK();
410 0 : }
411 :
412 : configure_stage_t fd_cfg_stage_hugetlbfs = {
413 : .name = "hugetlbfs",
414 : .always_recreate = 0,
415 : .enabled = NULL,
416 : .init_perm = init_perm,
417 : .fini_perm = fini_perm,
418 : .init = init,
419 : .fini = fini,
420 : .check = check,
421 : };
|