This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git


The following commit(s) were added to refs/heads/master by this push:
     new 2d6f5f230 netinit: Add check mount path retry option for delayed mounts
2d6f5f230 is described below

commit 2d6f5f230eea9d47bd1b9282e92e24626f3d1072
Author: Peter van der Perk <peter.vanderp...@nxp.com>
AuthorDate: Mon Feb 26 22:44:36 2024 +0100

    netinit: Add check mount path retry option for delayed mounts
---
 netutils/netinit/Kconfig   |  7 +++++++
 netutils/netinit/netinit.c | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+)

diff --git a/netutils/netinit/Kconfig b/netutils/netinit/Kconfig
index 747e6bc1d..6af444e6a 100644
--- a/netutils/netinit/Kconfig
+++ b/netutils/netinit/Kconfig
@@ -118,6 +118,13 @@ config NETINIT_THREAD_PRIORITY
                PHY polling is CPU intensive and can interfere with the 
usability of
                of threads competing for CPU bandwidth.
 
+config NETINIT_RETRY_MOUNTPATH
+       int "Network initialization retry mount path count"
+       default 0
+       ---help---
+               This should be set if the filesystem get mounted after netinit 
got started.
+               The netinit thread will check for the mount path before 
continuing.
+
 endif # NETINIT_THREAD
 
 config NETINIT_DEBUG
diff --git a/netutils/netinit/netinit.c b/netutils/netinit/netinit.c
index 80bdcbb30..8e9f14792 100644
--- a/netutils/netinit/netinit.c
+++ b/netutils/netinit/netinit.c
@@ -334,6 +334,30 @@ static void netinit_set_macaddr(void)
 #  define netinit_set_macaddr()
 #endif
 
+#if defined(CONFIG_NETINIT_THREAD) && CONFIG_NETINIT_RETRY_MOUNTPATH > 0
+static inline void netinit_checkpath(void)
+{
+  int retries = CONFIG_NETINIT_RETRY_MOUNTPATH;
+  while (retries > 0)
+    {
+      DIR * dir = opendir(CONFIG_IPCFG_PATH);
+      if (dir)
+        {
+          /* Directory exists. */
+
+          closedir(dir);
+          break;
+        }
+      else
+        {
+        usleep(100000);
+        }
+
+      retries--;
+    }
+}
+#endif
+
 /****************************************************************************
  * Name: netinit_set_ipv4addrs
  *
@@ -355,6 +379,10 @@ static inline void netinit_set_ipv4addrs(void)
    * file.
    */
 
+#if defined(CONFIG_NETINIT_THREAD) && CONFIG_NETINIT_RETRY_MOUNTPATH > 0
+  netinit_checkpath();
+#endif
+
   ret = ipcfg_read(NET_DEVNAME, (FAR struct ipcfg_s *)&ipv4cfg, AF_INET);
 #ifdef CONFIG_NETUTILS_DHCPC
   if (ret >= 0 && ipv4cfg.proto != IPv4PROTO_NONE)
@@ -512,6 +540,10 @@ static inline void netinit_set_ipv6addrs(void)
    * file.
    */
 
+#if defined(CONFIG_NETINIT_THREAD) && CONFIG_NETINIT_RETRY_MOUNTPATH > 0
+  netinit_checkpath();
+#endif
+
   ret = ipcfg_read(NET_DEVNAME, (FAR struct ipcfg_s *)&ipv6cfg, AF_INET6);
   if (ret >= 0 && IPCFG_HAVE_STATIC(ipv6cfg.proto))
     {

Reply via email to