Linux RAID subsystem development
 help / color / mirror / Atom feed
From: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
To: jes@trained-monkey.org
Cc: linux-raid@vger.kernel.org
Subject: [PATCH] Monitor: make libudev dependency optional
Date: Thu, 18 Mar 2021 17:12:35 +0100	[thread overview]
Message-ID: <20210318161235.23168-1-mariusz.tkaczyk@linux.intel.com> (raw)

Make -ludev configurable, enabled by default.
To disable it, -DNO_LIBUDEV has to be set explicitly in CXFALGS.

This patch restores commit cab9c67d461c ("mdmonitor: set small delay
once") for configuration without libudev to bring minimal support in
such case.

Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
---
 Makefile  |  7 ++++++-
 Monitor.c | 28 +++++++++++++++++++++++-----
 2 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/Makefile b/Makefile
index 1e6e1e12..2a51d813 100644
--- a/Makefile
+++ b/Makefile
@@ -119,7 +119,12 @@ endif
 # If you want a static binary, you might uncomment these
 # LDFLAGS = -static
 # STRIP = -s
-LDLIBS=-ldl -ludev
+LDLIBS = -ldl
+
+# To explicitly disable libudev, set -DNO_LIBUDEV in CXFLAGS
+ifeq (, $(findstring -DNO_LIBUDEV,  $(CXFLAGS)))
+	LDLIBS += -ludev
+endif
 
 INSTALL = /usr/bin/install
 DESTDIR =
diff --git a/Monitor.c b/Monitor.c
index 4c39145b..d68c3b42 100644
--- a/Monitor.c
+++ b/Monitor.c
@@ -29,7 +29,9 @@
 #include	<signal.h>
 #include	<limits.h>
 #include	<syslog.h>
+#ifndef NO_LIBUDEV
 #include	<libudev.h>
+#endif
 
 struct state {
 	char *devname;
@@ -73,7 +75,9 @@ static int add_new_arrays(struct mdstat_ent *mdstat, struct state **statelist,
 			  int test, struct alert_info *info);
 static void try_spare_migration(struct state *statelist, struct alert_info *info);
 static void link_containers_with_subarrays(struct state *list);
+#ifndef NO_LIBUDEV
 static int check_udev_activity(void);
+#endif
 
 int Monitor(struct mddev_dev *devlist,
 	    char *mailaddr, char *alert_cmd,
@@ -131,6 +135,7 @@ int Monitor(struct mddev_dev *devlist,
 	char *mailfrom;
 	struct alert_info info;
 	struct mddev_ident *mdlist;
+	int delay_for_event = c->delay;
 
 	if (!mailaddr) {
 		mailaddr = conf_get_mailaddr();
@@ -256,13 +261,25 @@ int Monitor(struct mddev_dev *devlist,
 				break;
 			}
 			else {
+#ifndef NO_LIBUDEV
 				/*
-				 * If mdmonitor is awaken by event, check for udev activity
-				 * to wait for udev to finish new devices processing.
+				 * Wait for udevd to finish new devices
+				 * processing.
 				 */
-				if (mdstat_wait(c->delay) && check_udev_activity())
+				if (mdstat_wait(delay_for_event) &&
+				    check_udev_activity())
 					pr_err("Error while waiting for UDEV to complete new devices processing\n");
-
+#else
+				int wait_result = mdstat_wait(delay_for_event);
+				/*
+				 * Give chance to process new device
+				 */
+				if (wait_result != 0) {
+					if (c->delay > 5)
+						delay_for_event = 5;
+				} else
+					delay_for_event = c->delay;
+#endif
 				mdstat_close();
 			}
 		}
@@ -1033,7 +1050,7 @@ static void link_containers_with_subarrays(struct state *list)
 				}
 }
 
-
+#ifndef NO_LIBUDEV
 /* function: check_udev_activity
  * Description: Function waits for udev to finish
  * events processing.
@@ -1087,6 +1104,7 @@ out:
 		udev_unref(udev);
 	return rc;
 }
+#endif
 
 /* Not really Monitor but ... */
 int Wait(char *dev)
-- 
2.26.2


             reply	other threads:[~2021-03-18 16:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-18 16:12 Mariusz Tkaczyk [this message]
2021-03-19 12:31 ` [PATCH] Monitor: make libudev dependency optional Jes Sorensen

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=20210318161235.23168-1-mariusz.tkaczyk@linux.intel.com \
    --to=mariusz.tkaczyk@linux.intel.com \
    --cc=jes@trained-monkey.org \
    --cc=linux-raid@vger.kernel.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