Skip to content

Commit

Permalink
netinit: Add check mount path retry option for delayed mounts
Browse files Browse the repository at this point in the history
  • Loading branch information
PetervdPerk committed Feb 26, 2024
1 parent ea29af9 commit 26e91d5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
7 changes: 7 additions & 0 deletions netutils/netinit/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions netutils/netinit/netinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,23 @@ static void netinit_set_macaddr(void)
# define netinit_set_macaddr()
#endif

#if CONFIG_NETINIT_RETRY_MOUNTPATH > 0
static inline void netinit_checkpath(void){
int retries = CONFIG_NETINIT_RETRY_MOUNTPATH;
do {
DIR* dir = opendir(CONFIG_IPCFG_PATH);
if (dir) {
/* Directory exists. */
closedir(dir);
break;
} else {
usleep(100000);
}
retries--;
} while(retries > 0);
}
#endif

/****************************************************************************
* Name: netinit_set_ipv4addrs
*
Expand All @@ -355,6 +372,10 @@ static inline void netinit_set_ipv4addrs(void)
* file.
*/

#if 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)
Expand Down Expand Up @@ -512,6 +533,10 @@ static inline void netinit_set_ipv6addrs(void)
* file.
*/

#if 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))
{
Expand Down

0 comments on commit 26e91d5

Please sign in to comment.