summaryrefslogtreecommitdiffstats
path: root/util.c
diff options
context:
space:
mode:
authorKinga Stefaniuk <kinga.stefaniuk@intel.com>2024-05-07 05:38:56 +0200
committerMariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>2024-05-14 11:08:06 +0200
commitaa1cc5815d2b14a8b47add18cfaa8264e19c10ce (patch)
tree19b8e321caa9d3107ca951b26c735e06372fea8c /util.c
parentutil.c: change devnm to const in mdmon functions (diff)
downloadmdadm-aa1cc5815d2b14a8b47add18cfaa8264e19c10ce.tar.xz
mdadm-aa1cc5815d2b14a8b47add18cfaa8264e19c10ce.zip
Wait for mdmon when it is stared via systemd
When mdmon is being started it may need few seconds to start. For now, we didn't wait for it. Introduce wait_for_mdmon() function, which waits up to 5 seconds for mdmon to start completely. Signed-off-by: Kinga Stefaniuk <kinga.stefaniuk@intel.com> Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Diffstat (limited to '')
-rw-r--r--util.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/util.c b/util.c
index e2b490e1..bf79742f 100644
--- a/util.c
+++ b/util.c
@@ -1932,6 +1932,35 @@ int mdmon_running(const char *devnm)
return 0;
}
+/*
+ * wait_for_mdmon() - Waits for mdmon within specified time.
+ * @devnm: Device for which mdmon should start.
+ *
+ * Function waits for mdmon to start. It may need few seconds
+ * to start, we set timeout to 5, it should be sufficient.
+ * Do not wait if mdmon has been started.
+ *
+ * Return: MDADM_STATUS_SUCCESS if mdmon is running, error code otherwise.
+ */
+mdadm_status_t wait_for_mdmon(const char *devnm)
+{
+ const time_t mdmon_timeout = 5;
+ time_t start_time = time(0);
+
+ if (mdmon_running(devnm))
+ return MDADM_STATUS_SUCCESS;
+
+ pr_info("Waiting for mdmon to start\n");
+ while (time(0) - start_time < mdmon_timeout) {
+ sleep_for(0, MSEC_TO_NSEC(200), true);
+ if (mdmon_running(devnm))
+ return MDADM_STATUS_SUCCESS;
+ };
+
+ pr_err("Timeout waiting for mdmon\n");
+ return MDADM_STATUS_ERROR;
+}
+
int start_mdmon(char *devnm)
{
int i;