winbindd: shorten client list scan
authorUri Simchoni <urisimchoni@gmail.com>
Mon, 13 Jul 2015 18:42:57 +0000 (21:42 +0300)
committerJeremy Allison <jra@samba.org>
Wed, 15 Jul 2015 23:45:19 +0000 (01:45 +0200)
Counting on the client list being sorted by last access time,
the list scan for removing timed-out clients is shortened - once
the list is scanned oldest to newest, and once a non-timed-out
client is found, the scan can stop.

Also, finding the oldest idle client for removing an idle client
is simplified - oldest idle client is last idle client.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=11397

Signed-off-by: Uri Simchoni <urisimchoni@gmail.com>
Reviewed-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Thu Jul 16 01:45:20 CEST 2015 on sn-devel-104

source3/winbindd/winbindd.c

index 620fd3fb8b6caf449326d9b190950b687c09b27d..c878ce2e220ff93708af21104ea59d09249b5384 100644 (file)
@@ -1086,16 +1086,13 @@ static bool client_is_idle(struct winbindd_cli_state *state) {
 static bool remove_idle_client(void)
 {
        struct winbindd_cli_state *state, *remove_state = NULL;
-       time_t last_access = 0;
        int nidle = 0;
 
        for (state = winbindd_client_list(); state; state = state->next) {
                if (client_is_idle(state)) {
                        nidle++;
-                       if (!last_access || state->last_access < last_access) {
-                               last_access = state->last_access;
-                               remove_state = state;
-                       }
+                       /* list is sorted by access time */
+                       remove_state = state;
                }
        }
 
@@ -1117,14 +1114,14 @@ static bool remove_idle_client(void)
 
 static void remove_timed_out_clients(void)
 {
-       struct winbindd_cli_state *state, *next = NULL;
+       struct winbindd_cli_state *state, *prev = NULL;
        time_t curr_time = time(NULL);
        int timeout_val = lp_winbind_request_timeout();
 
-       for (state = winbindd_client_list(); state; state = next) {
+       for (state = winbindd_client_list_tail(); state; state = prev) {
                time_t expiry_time;
 
-               next = state->next;
+               prev = winbindd_client_list_prev(state);
                expiry_time = state->last_access + timeout_val;
 
                if (curr_time > expiry_time) {
@@ -1140,6 +1137,10 @@ static void remove_timed_out_clients(void)
                                        (unsigned int)state->pid));
                        }
                        remove_client(state);
+               } else {
+                       /* list is sorted, previous clients in
+                          list are newer */
+                       break;
                }
        }
 }