Move the code that actually loops through the paths and checks them into
a separate function, to stop it from being so heavily indented. This
will be more imporant when a future patch makes paths checked by mpp.

No functional changes.

Signed-off-by: Benjamin Marzinski <[email protected]>
---
 multipathd/main.c | 65 +++++++++++++++++++++++++----------------------
 1 file changed, 35 insertions(+), 30 deletions(-)

diff --git a/multipathd/main.c b/multipathd/main.c
index 42ccb92f..27e18a0c 100644
--- a/multipathd/main.c
+++ b/multipathd/main.c
@@ -2782,6 +2782,38 @@ enum checker_state {
        CHECKER_FINISHED,
 };
 
+static enum checker_state
+check_paths(struct vectors *vecs, unsigned int ticks, int *num_paths_p)
+{
+       unsigned int paths_checked = 0;
+       struct timespec diff_time, start_time, end_time;
+       struct path *pp;
+       int i, rc;
+
+       get_monotonic_time(&start_time);
+       vector_foreach_slot(vecs->pathvec, pp, i) {
+               if (pp->is_checked)
+                       continue;
+               pp->is_checked = true;
+               if (pp->mpp)
+                       rc = check_path(vecs, pp, ticks, start_time.tv_sec);
+               else
+                       rc = handle_uninitialized_path(vecs, pp, ticks);
+               if (rc < 0)
+                       i--;
+               else
+                       *num_paths_p += rc;
+               if (++paths_checked % 128 == 0 &&
+                   (lock_has_waiters(&vecs->lock) || waiting_clients())) {
+                       get_monotonic_time(&end_time);
+                       timespecsub(&end_time, &start_time, &diff_time);
+                       if (diff_time.tv_sec > 0)
+                               return CHECKER_RUNNING;
+               }
+       }
+       return CHECKER_FINISHED;
+}
+
 static void *
 checkerloop (void *ap)
 {
@@ -2813,7 +2845,7 @@ checkerloop (void *ap)
 
        while (1) {
                struct timespec diff_time, start_time, end_time;
-               int num_paths = 0, strict_timing, rc = 0;
+               int num_paths = 0, strict_timing;
                unsigned int ticks = 0;
                enum checker_state checker_state = CHECKER_STARTING;
 
@@ -2832,16 +2864,14 @@ checkerloop (void *ap)
                        sd_notify(0, "WATCHDOG=1");
 #endif
                while (checker_state != CHECKER_FINISHED) {
-                       unsigned int paths_checked = 0, i;
-                       struct timespec chk_start_time;
                        struct multipath *mpp;
+                       int i;
 
                        pthread_cleanup_push(cleanup_lock, &vecs->lock);
                        lock(&vecs->lock);
                        pthread_testcancel();
                        vector_foreach_slot(vecs->mpvec, mpp, i)
                                mpp->is_checked = false;
-                       get_monotonic_time(&chk_start_time);
                        if (checker_state == CHECKER_STARTING) {
                                vector_foreach_slot(vecs->mpvec, mpp, i)
                                        check_mpp(vecs, mpp, ticks);
@@ -2849,32 +2879,7 @@ checkerloop (void *ap)
                                        pp->is_checked = false;
                                checker_state = CHECKER_RUNNING;
                        }
-                       vector_foreach_slot(vecs->pathvec, pp, i) {
-                               if (pp->is_checked)
-                                       continue;
-                               pp->is_checked = true;
-                               if (pp->mpp)
-                                       rc = check_path(vecs, pp, ticks,
-                                                       chk_start_time.tv_sec);
-                               else
-                                       rc = handle_uninitialized_path(vecs, pp,
-                                                                      ticks);
-                               if (rc < 0)
-                                       i--;
-                               else
-                                       num_paths += rc;
-                               if (++paths_checked % 128 == 0 &&
-                                   (lock_has_waiters(&vecs->lock) ||
-                                    waiting_clients())) {
-                                       get_monotonic_time(&end_time);
-                                       timespecsub(&end_time, &chk_start_time,
-                                                   &diff_time);
-                                       if (diff_time.tv_sec > 0)
-                                               goto unlock;
-                               }
-                       }
-                       checker_state = CHECKER_FINISHED;
-unlock:
+                       checker_state = check_paths(vecs, ticks, &num_paths);
                        lock_cleanup_pop(vecs->lock);
                        if (checker_state != CHECKER_FINISHED) {
                                /* Yield to waiters */
-- 
2.45.0


Reply via email to