DPDK patches and discussions
 help / color / mirror / Atom feed
From: Bruce Richardson <bruce.richardson@intel.com>
To: Stephen Hemminger <stephen@networkplumber.org>
Cc: <dev@dpdk.org>
Subject: Re: [RFC] eal: use C library to parse filesystem table
Date: Mon, 24 Nov 2025 13:53:28 +0000	[thread overview]
Message-ID: <aSRjWHmqAl7B8YGq@bricha3-mobl1.ger.corp.intel.com> (raw)
In-Reply-To: <20251122194921.158921-1-stephen@networkplumber.org>

On Sat, Nov 22, 2025 at 11:49:21AM -0800, Stephen Hemminger wrote:
> Rather than doing parsing of /proc/mounts with open coded string
> handling, use the standard C library routines.
> These exist in BSD and Linux.
> 
> It also avoids any possible issues with escaped strings etc
> which the library handles. See getmntent(3) man page.
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
Acked-by: Bruce Richardson <bruce.richardson@intel.com>


>  lib/eal/linux/eal_hugepage_info.c | 45 ++++++++++---------------------
>  1 file changed, 14 insertions(+), 31 deletions(-)
> 

<snip>  

> -		pagesz_str = strstr(splitstr[OPTIONS], pagesize_opt);
> +		pagesz_str = strstr(entry.mnt_opts, pagesize_opt);
>  
>  		/* if no explicit page size, the default page size is compared */
>  		if (pagesz_str == NULL) {
>  			if (hugepage_sz != default_size)
>  				continue;
> -		}
> -		/* there is an explicit page size, so check it */
> -		else {
> +		} else {
> +			/* there is an explicit page size, so check it */
>  			uint64_t pagesz = rte_str_to_size(&pagesz_str[pagesize_opt_len]);
>  			if (pagesz != hugepage_sz)
>  				continue;

Since you are already changing this part, this if-else block can be
shortened down to avoid duplicating the continue check:

diff --git a/lib/eal/linux/eal_hugepage_info.c b/lib/eal/linux/eal_hugepage_info.c
index ecc0374204..0e54b35ce1 100644
--- a/lib/eal/linux/eal_hugepage_info.c
+++ b/lib/eal/linux/eal_hugepage_info.c
@@ -227,22 +227,16 @@ get_hugepage_dir(uint64_t hugepage_sz, char *hugedir, int len)
        while (getmntent_r(mounts, &entry, buf, sizeof(buf))) {
                const char *pagesz_str;
                size_t mountpt_len = 0;
+               uint64_t pagesz;
 
                if (strcmp(entry.mnt_type, "hugetlbfs") != 0)
                        continue;
 
                pagesz_str = strstr(entry.mnt_opts, pagesize_opt);
-
-               /* if no explicit page size, the default page size is compared */
-               if (pagesz_str == NULL) {
-                       if (hugepage_sz != default_size)
-                               continue;
-               } else {
-                       /* there is an explicit page size, so check it */
-                       uint64_t pagesz = rte_str_to_size(&pagesz_str[pagesize_opt_len]);
-                       if (pagesz != hugepage_sz)
-                               continue;
-               }
+               pagesz = (pagesz_str == NULL) ? default_size :
+                               rte_str_to_size(&pagesz_str[pagesize_opt_len]);
+               if (pagesz != hugepage_sz)
+                       continue;
 
                /*
                 * If no --huge-dir option has been given, we're done.


      reply	other threads:[~2025-11-24 13:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-22 19:49 Stephen Hemminger
2025-11-24 13:53 ` Bruce Richardson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aSRjWHmqAl7B8YGq@bricha3-mobl1.ger.corp.intel.com \
    --to=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).