From 486aa4e5c81eac992f19d1aa833fa6b4195aaecf Mon Sep 17 00:00:00 2001 From: Shawn Routhier Date: Fri, 12 Mar 2010 01:29:34 +0000 Subject: [PATCH] Update the fsync batch code to work with the isc libraries - 21044 --- RELNOTES | 5 ++++ includes/dhcpd.h | 4 +++ server/dhcp.c | 63 ++++++++++++++++++++++++++++++------------------ server/dhcpd.c | 2 -- 4 files changed, 48 insertions(+), 26 deletions(-) diff --git a/RELNOTES b/RELNOTES index 1502c6221..4c9512dd7 100644 --- a/RELNOTES +++ b/RELNOTES @@ -40,6 +40,11 @@ work on other platforms. Please report any problems and suggested fixes to . + Changes since 4.2.0a2 + +- Update the fsync code to work with the changes to the DDNS code. It now + uses a timer instead of noticing if there are no more packets to process. + Changes since 4.2.0a1 - When using 'ignore client-updates;', the FQDN returned to the client diff --git a/includes/dhcpd.h b/includes/dhcpd.h index 786210726..4ceb22bae 100644 --- a/includes/dhcpd.h +++ b/includes/dhcpd.h @@ -667,6 +667,10 @@ struct lease_state { # define DEFAULT_ACK_DELAY_USECS 250000 /* 1/4 of a second */ #endif +#if !defined (DEFAULT_MIN_ACK_DELAY_USECS) +# define DEFAULT_MIN_ACK_DELAY_USECS 10000 /* 1/100 second */ +#endif + #if !defined (DEFAULT_DEFAULT_LEASE_TIME) # define DEFAULT_DEFAULT_LEASE_TIME 43200 #endif diff --git a/server/dhcp.c b/server/dhcp.c index 26f664c9f..7a01c3c9b 100644 --- a/server/dhcp.c +++ b/server/dhcp.c @@ -45,11 +45,13 @@ int outstanding_pings; struct leasequeue *ackqueue_head, *ackqueue_tail; static struct leasequeue *free_ackqueue; -static struct timeval next_fsync; +static struct timeval max_fsync; + int outstanding_acks; int max_outstanding_acks = DEFAULT_DELAYED_ACK; int max_ack_delay_secs = DEFAULT_ACK_DELAY_SECS; int max_ack_delay_usecs = DEFAULT_ACK_DELAY_USECS; +int min_ack_delay_usecs = DEFAULT_MIN_ACK_DELAY_USECS; static char dhcp_message [256]; static int site_code_min; @@ -2836,11 +2838,13 @@ void ack_lease (packet, lease, offer, when, msg, ms_nulltp, hp) } } -/* CC: queue single ACK: - - write the lease (but do not fsync it yet) - - add to double linked list - - commit if more than xx ACKs pending - - Not yet: schedule a fsync at the next interval (1 second?) +/* + * CC: queue single ACK: + * - write the lease (but do not fsync it yet) + * - add to double linked list + * - commit if more than xx ACKs pending + * - if necessary set the max timer and bump the next timer + * but only up to the max timer value. */ void @@ -2870,43 +2874,54 @@ delayed_ack_enqueue(struct lease *lease) q->next->prev = q; outstanding_acks++; - if (outstanding_acks > max_outstanding_acks) + if (outstanding_acks > max_outstanding_acks) { commit_leases(); - /* If next_fsync is not set, schedule an fsync. */ - if (next_fsync.tv_sec == 0 && next_fsync.tv_usec == 0) { - next_fsync.tv_sec = cur_tv.tv_sec + max_ack_delay_secs; - next_fsync.tv_usec = cur_tv.tv_usec + max_ack_delay_usecs; + /* Reset max_fsync and cancel any pending timeout. */ + memset(&max_fsync, 0, sizeof(max_fsync)); + cancel_timeout(commit_leases_ackout, NULL); + } else { + struct timeval next_fsync; + + if (max_fsync.tv_sec == 0 && max_fsync.tv_usec == 0) { + /* set the maximum time we'll wait */ + max_fsync.tv_sec = cur_tv.tv_sec + max_ack_delay_secs; + max_fsync.tv_usec = cur_tv.tv_usec + + max_ack_delay_usecs; + if (max_fsync.tv_usec >= 1000000) { + max_fsync.tv_sec++; + max_fsync.tv_usec -= 1000000; + } + } + + /* Set the timeout */ + next_fsync.tv_sec = cur_tv.tv_sec; + next_fsync.tv_usec = cur_tv.tv_usec + min_ack_delay_usecs; if (next_fsync.tv_usec >= 1000000) { next_fsync.tv_sec++; next_fsync.tv_usec -= 1000000; } + /* but not more than the max */ + if ((next_fsync.tv_sec > max_fsync.tv_sec) || + ((next_fsync.tv_sec == max_fsync.tv_sec) && + (next_fsync.tv_usec > max_fsync.tv_usec))) { + next_fsync.tv_sec = max_fsync.tv_sec; + next_fsync.tv_usec = max_fsync.tv_usec; + } add_timeout(&next_fsync, commit_leases_ackout, NULL, (tvref_t) NULL, (tvunref_t) NULL); } } -void -commit_leases_readerdry(void *foo) -{ - if (outstanding_acks) { - commit_leases(); - - /* Reset next_fsync and cancel any pending timeout. */ - memset(&next_fsync, 0, sizeof(next_fsync)); - cancel_timeout(commit_leases_ackout, NULL); - } -} - static void commit_leases_ackout(void *foo) { if (outstanding_acks) { commit_leases(); - memset(&next_fsync, 0, sizeof(next_fsync)); + memset(&max_fsync, 0, sizeof(max_fsync)); } } diff --git a/server/dhcpd.c b/server/dhcpd.c index 0678c73ef..092ee33c7 100644 --- a/server/dhcpd.c +++ b/server/dhcpd.c @@ -836,8 +836,6 @@ main(int argc, char **argv) { omapi_set_int_value ((omapi_object_t *)dhcp_control_object, (omapi_object_t *)0, "state", server_running); - register_eventhandler(&rw_queue_empty,commit_leases_readerdry); - /* Receive packets and dispatch them... */ dispatch (); -- 2.47.3