From: tang.junhui <[email protected]>

Move uev_discard() form uevent processing thread to uevent listening
thread to discard unnecessary uevents as soon as possible.

Change-Id: Iaac159ffe3930e53c3325d1069c3ed497e440c0c
Signed-off-by: tang.wenjun <[email protected]>
---
 libmultipath/uevent.c | 28 ++++++++++++++++++++++++++++
 multipathd/main.c     | 25 -------------------------
 2 files changed, 28 insertions(+), 25 deletions(-)

diff --git a/libmultipath/uevent.c b/libmultipath/uevent.c
index 181b3b8..ac49cac 100644
--- a/libmultipath/uevent.c
+++ b/libmultipath/uevent.c
@@ -24,6 +24,7 @@
 
 #include <unistd.h>
 #include <stdio.h>
+#include <stdbool.h>
 #include <errno.h>
 #include <stdlib.h>
 #include <stddef.h>
@@ -80,6 +81,28 @@ struct uevent * alloc_uevent (void)
        return uev;
 }
 
+bool
+uevent_can_discard(char *devpath)
+{
+       char *tmp;
+       char a[11], b[11];
+
+       /*
+        * keep only block devices, discard partitions
+        */
+       tmp = strstr(devpath, "/block/");
+       if (tmp == NULL){
+               condlog(4, "no /block/ in '%s'", devpath);
+               return true;
+       }
+       if (sscanf(tmp, "/block/%10s", a) != 1 ||
+           sscanf(tmp, "/block/%10[^/]/%10s", a, b) == 2) {
+               condlog(4, "discard event on %s", devpath);
+               return true;
+       }
+       return false;
+}
+
 void
 service_uevq(struct list_head *tmpq)
 {
@@ -527,6 +550,11 @@ int uevent_listen(struct udev *udev)
                        uev = uevent_from_udev_device(dev);
                        if (!uev)
                                continue;
+                       if (uevent_can_discard(uev->devpath)) {
+                                udev_device_unref(uev->udev);
+                                FREE(uev);
+                                continue;
+                       }
                        list_add_tail(&uev->node, &uevlisten_tmp);
                        events++;
                        continue;
diff --git a/multipathd/main.c b/multipathd/main.c
index 68c8e17..51f7b60 100644
--- a/multipathd/main.c
+++ b/multipathd/main.c
@@ -1087,28 +1087,6 @@ uxsock_trigger (char * str, char ** reply, int * len, 
void * trigger_data)
        return r;
 }
 
-static int
-uev_discard(char * devpath)
-{
-       char *tmp;
-       char a[11], b[11];
-
-       /*
-        * keep only block devices, discard partitions
-        */
-       tmp = strstr(devpath, "/block/");
-       if (tmp == NULL){
-               condlog(4, "no /block/ in '%s'", devpath);
-               return 1;
-       }
-       if (sscanf(tmp, "/block/%10s", a) != 1 ||
-           sscanf(tmp, "/block/%10[^/]/%10s", a, b) == 2) {
-               condlog(4, "discard event on %s", devpath);
-               return 1;
-       }
-       return 0;
-}
-
 int
 uev_trigger (struct uevent * uev, void * trigger_data)
 {
@@ -1118,9 +1096,6 @@ uev_trigger (struct uevent * uev, void * trigger_data)
 
        vecs = (struct vectors *)trigger_data;
 
-       if (uev_discard(uev->devpath))
-               return 0;
-
        pthread_cleanup_push(config_cleanup, NULL);
        pthread_mutex_lock(&config_lock);
        if (running_state != DAEMON_IDLE &&
-- 
2.8.1.windows.1


--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel

Reply via email to