LCOV - code coverage report
Current view: top level - app/fdctl/configure - hugetlbfs.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 302 0.0 %
Date: 2025-03-10 12:29:05 Functions: 0 7 0.0 %

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

Generated by: LCOV version 1.14