]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
- Rotate the lease file when running in v6 mode.
authorShawn Routhier <sar@isc.org>
Tue, 15 May 2012 21:07:17 +0000 (21:07 +0000)
committerShawn Routhier <sar@isc.org>
Tue, 15 May 2012 21:07:17 +0000 (21:07 +0000)
  [ISC-Bugs #24887]

RELNOTES
includes/dhcpd.h
server/db.c
server/dhcpv6.c
server/mdb6.c

index b513813dd7fcb8673df7a15efc3724b274c6ff81..7e930b9469047376b05f1245c5f12f6cc07dfd15 100644 (file)
--- a/RELNOTES
+++ b/RELNOTES
@@ -147,6 +147,11 @@ work on other platforms. Please report any problems and suggested fixes to
   The use of a boolean test instead of a bitwise test in dst.
   [ISC-Bugs #28941]
 
+- Rotate the lease file when running in v6 mode.
+  Thanks to Christoph Moench-Tegeder at Astaro for the
+  report and the first version of the patch.
+  [ISC-Bugs #24887]
+
                        Changes since 4.2.2
 
 - Fix the code that checks for an existing DDNS transaction to cancel
index 6e7817c62dcca45a1c3da1c56da9d4b8e7e908e7..98ba07518eb6c88731e78e55ab2a9bbf7c706aa1 100644 (file)
@@ -2761,6 +2761,7 @@ int write_billing_class (struct class *);
 void commit_leases_timeout (void *);
 void commit_leases_readerdry(void *);
 int commit_leases (void);
+int commit_leases_timed (void);
 void db_startup (int);
 int new_lease_file (void);
 int group_writer (struct group_object *);
index 6cb84f7111048d7c364761676c3a613e533e895d..5be1684a8e6c8c4d11bfc6df291b34fdb3f5c786 100644 (file)
@@ -36,6 +36,8 @@
 #include <ctype.h>
 #include <errno.h>
 
+#define LEASE_REWRITE_PERIOD 3600
+
 static isc_result_t write_binding_scope(FILE *db_file, struct binding *bnd,
                                        char *prepend);
 
@@ -1002,7 +1004,7 @@ int commit_leases ()
        /* If we haven't rewritten the lease database in over an
           hour, rewrite it now.  (The length of time should probably
           be configurable. */
-       if (count && cur_time - write_time > 3600) {
+       if (count && cur_time - write_time > LEASE_REWRITE_PERIOD) {
                count = 0;
                write_time = cur_time;
                new_lease_file ();
@@ -1010,6 +1012,21 @@ int commit_leases ()
        return 1;
 }
 
+/*
+ * rewrite the lease file about once an hour
+ * This is meant as a quick patch for ticket 24887.  It allows
+ * us to rotate the v6 lease file without adding too many fsync()
+ * calls.  In the future wes should revisit this area and add
+ * something similar to the delayed ack code for v4.
+ */
+int commit_leases_timed()
+{
+       if ((count != 0) && (cur_time - write_time > LEASE_REWRITE_PERIOD)) {
+               return (commit_leases());
+       }
+       return (1);
+}
+
 void db_startup (testp)
        int testp;
 {
index e1f6e526311bdbd22cad43c53f14c42c35338747..9d5fa1d1aa5f5f262f909eab8e65c79f6e2287d8 100644 (file)
@@ -1207,6 +1207,10 @@ pick_v6_prefix(struct iasubopt **pref, int plen,
 }
 
 /*
+ *! \file server/dhcpv6.c
+ *
+ * \brief construct a reply containing information about a client's lease
+ *
  * lease_to_client() is called from several messages to construct a
  * reply that contains all that we know about the client's correct lease
  * (or projected lease).
@@ -1228,8 +1232,15 @@ pick_v6_prefix(struct iasubopt **pref, int plen,
  * validate and echo back any contents that can be.  If the client-supplied
  * data does not error out (on renew/rebind as above), but we did not send
  * any addresses, attempt to allocate one.
+ *
+ * At the end of the this function we call commit_leases_timed() to
+ * fsync and rotate the file as necessary.  commit_leases_timed() will
+ * check that we have written at least one lease to the file and that
+ * some time has passed before doing any fsync or file rewrite so we
+ * don't bother tracking if we did a write_ia during this function.
  */
 /* TODO: look at client hints for lease times */
+
 static void
 lease_to_client(struct data_string *reply_ret,
                struct packet *packet, 
@@ -1493,6 +1504,9 @@ lease_to_client(struct data_string *reply_ret,
        memcpy(reply_ret->buffer->data, reply.buf.data, reply.cursor);
        reply_ret->data = reply_ret->buffer->data;
 
+       /* If appropriate commit and rotate the lease file */
+       (void) commit_leases_timed();
+
       exit:
        /* Cleanup. */
        if (reply.shared != NULL)
index e6d0a1adecbfd958ce04ac5edb43a18b57ab4d50..f82e301d37e73c33778adf3f797e6ae34137450a 100644 (file)
@@ -1714,6 +1714,13 @@ lease_timeout_support(void *vpool) {
                iasubopt_dereference(&lease, MDL);
        }
 
+       /*
+        * If appropriate commit and rotate the lease file
+        * As commit_leases_timed() checks to see if we've done any writes
+        * we don't bother tracking if this function called write _ia
+        */
+       (void) commit_leases_timed();
+
        /*
         * Do some cleanup of our expired leases.
         */