]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Use separate index alignment from memory alignment. We don't use pointers in
authorTimo Sirainen <tss@iki.fi>
Sun, 27 Apr 2003 00:59:43 +0000 (03:59 +0300)
committerTimo Sirainen <tss@iki.fi>
Sun, 27 Apr 2003 00:59:43 +0000 (03:59 +0300)
index file so required alignmentation comes pretty much from sizeof(off_t).

--HG--
branch : HEAD

configure.in
src/lib-index/mail-index-data.c
src/lib-index/mail-index-open.c
src/lib-index/mail-index-update.c
src/lib-index/mail-index.h

index ef91bd23b93402bc81d58bb24b841b54baead9dd..8fe2465844bf8a3595b53144d6d73cb59d447498 100644 (file)
@@ -49,10 +49,15 @@ AC_ARG_WITH(file-offset-size,
        preferred_off_t_bits=64)
 
 AC_ARG_WITH(mem-align,
-[  --with-mem-align=BYTES  Set the memory alignment (default: sizeof(off_t))],
+[  --with-mem-align=BYTES  Set the memory alignment (default: 8)],
        mem_align=$withval,
        mem_align=8)
 
+AC_ARG_WITH(index-align,
+[  --with-index-align=BYTES  Set the index file alignment (default: detect)],
+       index_align=$withval,
+       index_align=0)
+
 AC_ARG_WITH(passwd,
 [  --with-passwd           Build with /etc/passwd support (default)],
        if test x$withval = xno; then
@@ -226,9 +231,6 @@ AC_CHECK_FUNC(poll, [
        AC_DEFINE(IOLOOP_SELECT,, Implement I/O loop with select())
 ])
 
-dnl * memory alignment
-AC_DEFINE_UNQUOTED(MEM_ALIGN_SIZE, $mem_align, Required memory alignment)
-
 dnl * OS specific options
 case "$host_os" in
        hpux*)
@@ -391,11 +393,6 @@ AC_TRY_COMPILE([
   AC_DEFINE_UNQUOTED(OFF_T_MAX, $offt_max, Maximum value of off_t)
 ])
 
-dnl currently we break if off_t is smaller than mem_align
-if test $offt_bits = 32 -a $mem_align = 8; then
-  mem_align=4
-fi
-
 AC_DEFINE_UNQUOTED(PRIuUOFF_T, "$uofft_fmt", printf() format for uoff_t)
 
 dnl * make sure size_t isn't signed. we'd probably work fine with it, but
@@ -479,6 +476,18 @@ if test $i_cv_type_socklen_t = yes; then
   AC_DEFINE(HAVE_SOCKLEN_T,, Define to 'int' if you don't have socklen_t)
 fi
 
+dnl * memory alignment
+if test "$index_align" = "0"; then
+  if test $offt_bits = 64; then
+    index_align=8
+  else
+    index_align=4
+  fi
+fi
+
+AC_DEFINE_UNQUOTED(MEM_ALIGN_SIZE, $mem_align, Required memory alignment)
+AC_DEFINE_UNQUOTED(INDEX_ALIGN_SIZE, $index_align, Required index alignment)
+
 dnl * find random source
 AC_MSG_CHECKING([for /dev/urandom])
 if test -c /dev/urandom; then
index c5f3885cf51ec03c94bcd2455b812de92cd06099..b25bb39abd0d84ec42fc6ec49faf03843b854840 100644 (file)
@@ -449,7 +449,7 @@ uoff_t mail_index_data_append(struct mail_index_data *data, const void *buffer,
 {
        uoff_t offset;
 
-       i_assert((size & (MEM_ALIGN_SIZE-1)) == 0);
+       i_assert((size & (INDEX_ALIGN_SIZE-1)) == 0);
        i_assert(data->index->lock_type == MAIL_LOCK_EXCLUSIVE);
 
        if (!mmap_update(data, 0, sizeof(struct mail_index_data_header)))
@@ -550,7 +550,7 @@ mail_index_data_lookup_header(struct mail_index_data *data,
                return NULL;
        }
 
-       if ((pos % MEM_ALIGN_SIZE) != 0) {
+       if ((pos % INDEX_ALIGN_SIZE) != 0) {
                index_data_set_corrupted(data, "Data position (%"PRIuUOFF_T") "
                                         "is not memory aligned for record %u",
                                         pos, index_rec->uid);
@@ -612,7 +612,7 @@ mail_index_data_lookup(struct mail_index_data *data,
                        break;
                }
 
-               if ((rec->full_field_size % MEM_ALIGN_SIZE) != 0) {
+               if ((rec->full_field_size % INDEX_ALIGN_SIZE) != 0) {
                        index_data_set_corrupted(data, "Field %d size %u "
                                "is not memory aligned for record %u",
                                (int)field, rec->full_field_size,
index 2f21afdafad671721e1e904b0bdd6b422606f376..438a0cc4e1afbe0b29592a29182547b4783a6b0e 100644 (file)
@@ -199,7 +199,7 @@ static int mail_index_is_compatible(const struct mail_index_header *hdr)
                hdr->compat_data[2] == sizeof(unsigned int) &&
                hdr->compat_data[3] == sizeof(time_t) &&
                hdr->compat_data[4] == sizeof(uoff_t) &&
-               hdr->compat_data[5] == MEM_ALIGN_SIZE;
+               hdr->compat_data[5] == INDEX_ALIGN_SIZE;
 }
 
 static int mail_index_init_file(struct mail_index *index,
@@ -235,7 +235,7 @@ void mail_index_init_header(struct mail_index *index,
        hdr->compat_data[2] = sizeof(unsigned int);
        hdr->compat_data[3] = sizeof(time_t);
        hdr->compat_data[4] = sizeof(uoff_t);
-       hdr->compat_data[5] = MEM_ALIGN_SIZE;
+       hdr->compat_data[5] = INDEX_ALIGN_SIZE;
        hdr->indexid = ioloop_time;
 
        /* mark the index requiring rebuild - rebuild() removes this flag
index 11a30e1ac6f1b4c25c572998672c2fbff0ee610f..5fd4af2f2d02a376cf940eefa19ebcf8bfbc271b 100644 (file)
@@ -81,11 +81,11 @@ static void get_data_block_sizes(struct mail_index_update *update,
 
                if (update->fields[i] != NULL) {
                        /* value was modified - use it */
-                       field_min_size = MEM_ALIGN(update->field_sizes[i]);
+                       field_min_size = INDEX_ALIGN(update->field_sizes[i]);
                        *min_size += SIZEOF_MAIL_INDEX_DATA + field_min_size;
                        *max_size += SIZEOF_MAIL_INDEX_DATA +
-                               MEM_ALIGN(update->field_sizes[i] +
-                                         update->field_extra_sizes[i]);
+                               INDEX_ALIGN(update->field_sizes[i] +
+                                           update->field_extra_sizes[i]);
 
                        if (!field_exists ||
                            rec->full_field_size < field_min_size)
@@ -109,15 +109,15 @@ static size_t get_max_align_size(size_t base, size_t extra, size_t *max_extra)
 {
        size_t size;
 
-       size = MEM_ALIGN(base);
+       size = INDEX_ALIGN(base);
        extra -= size - base;
-       if (*max_extra < MEM_ALIGN_SIZE || extra == 0)
+       if (*max_extra < INDEX_ALIGN_SIZE || extra == 0)
                return size; /* no extra / extra went into alignment */
 
-       extra = MEM_ALIGN(extra);
+       extra = INDEX_ALIGN(extra);
        if (extra > *max_extra) {
                /* partial */
-               extra = *max_extra & ~(size_t)(MEM_ALIGN_SIZE-1);
+               extra = *max_extra & ~(size_t)(INDEX_ALIGN_SIZE-1);
                i_assert(extra <= *max_extra);
        }
 
@@ -168,7 +168,7 @@ static void *create_data_block(struct mail_index_update *update,
                        /* the field doesn't exist, jump to next */
                        continue;
                }
-               i_assert((full_field_size % MEM_ALIGN_SIZE) == 0);
+               i_assert((full_field_size % INDEX_ALIGN_SIZE) == 0);
 
                destrec = buffer_append_space(buf, SIZEOF_MAIL_INDEX_DATA +
                                              full_field_size);
index 9ee3131b5630ba8c8df65ee3f1482fa0db935410..21cb3b7df0ebb0f825e55e95aa6317d78b046ddc 100644 (file)
@@ -118,7 +118,7 @@ struct mail_index_header {
           2 = sizeof(unsigned int),
           3 = sizeof(time_t),
           4 = sizeof(uoff_t),
-          5 = MEM_ALIGN_SIZE */
+          5 = INDEX_ALIGN_SIZE */
 
        unsigned int indexid;
        unsigned int sync_id; /* re-mmap() when changed, required only
@@ -176,11 +176,11 @@ struct mail_index_data_record_header {
 struct mail_index_data_record {
        unsigned int field; /* enum mail_data_field */
        unsigned int full_field_size;
-       char data[MEM_ALIGN_SIZE]; /* variable size */
+       char data[INDEX_ALIGN_SIZE]; /* variable size */
 };
 
 #define SIZEOF_MAIL_INDEX_DATA \
-       (sizeof(struct mail_index_data_record) - MEM_ALIGN_SIZE)
+       (sizeof(struct mail_index_data_record) - INDEX_ALIGN_SIZE)
 
 #define DATA_RECORD_SIZE(rec) \
         (SIZEOF_MAIL_INDEX_DATA + (rec)->full_field_size)
@@ -348,7 +348,7 @@ struct mail_index {
        void (*update_field)(struct mail_index_update *update,
                             enum mail_data_field field,
                             const char *value, size_t extra_space);
-       /* Just remember that full_field_size will be MEM_ALIGNed, so
+       /* Just remember that full_field_size will be INDEX_ALIGNed, so
           it may differer from the given size parameter. */
        void (*update_field_raw)(struct mail_index_update *update,
                                 enum mail_data_field field,
@@ -591,4 +591,8 @@ int mail_index_truncate(struct mail_index *index);
 #define INDEX_IS_IN_MEMORY(index) \
        ((index)->anon_mmap)
 
+/* Returns alignmentation for given size */
+#define INDEX_ALIGN(size) \
+       (((size) + INDEX_ALIGN_SIZE-1) & ~((unsigned int) INDEX_ALIGN_SIZE-1))
+
 #endif