~ubuntu-branches/ubuntu/utopic/dovecot/utopic-proposed

« back to all changes in this revision

Viewing changes to src/lib-index/mail-index-sync-update.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-01-08 09:35:49 UTC
  • mfrom: (4.1.35 sid)
  • Revision ID: package-import@ubuntu.com-20140108093549-i72o93pux8p0dlaf
Tags: 1:2.2.9-1ubuntu1
* Merge from Debian unstable, remaining changes:
  + Add mail-stack-delivery package:
    - Update d/rules
    - d/control: convert existing dovecot-postfix package to a dummy
      package and add new mail-stack-delivery package.
    - Update maintainer scripts.
    - Rename d/dovecot-postfix.* to debian/mail-stack-delivery.*
    - d/mail-stack-delivery.preinst: Move previously installed backups and
      config files to a new package namespace.
    - d/mail-stack-delivery.prerm: Added to handle downgrades.
  + Use Snakeoil SSL certificates by default:
    - d/control: Depend on ssl-cert.
    - d/dovecot-core.postinst: Relax grep for SSL_* a bit.
  + Add autopkgtest to debian/tests/*.
  + Add ufw integration:
    - d/dovecot-core.ufw.profile: new ufw profile.
    - d/rules: install profile in dovecot-core.
    - d/control: dovecot-core - suggest ufw.
  + d/dovecot-core.dirs: Added usr/share/doc/dovecot-core
  + Add apport hook:
    - d/rules, d/source_dovecot.py
  + Add upstart job:
    - d/rules, d/dovecot-core.dovecot.upstart, d/control,
      d/dovecot-core.dirs, dovecot-imapd.{postrm, postinst, prerm},
      d/dovecot-pop3d.{postinst, postrm, prerm}.
      d/mail-stack-deliver.postinst: Convert init script to upstart.
  + Use the autotools-dev dh addon to update config.guess/config.sub for
    arm64.
* Dropped changes, included in Debian:
  - Update Dovecot name to reflect distribution in login greeting.
  - Update Drac plugin for >= 2.0.0 support.
* d/control: Drop dovecot-postfix package as its no longer required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2004-2012 Dovecot authors, see the included COPYING file */
 
1
/* Copyright (c) 2004-2013 Dovecot authors, see the included COPYING file */
2
2
 
3
3
#include "lib.h"
4
4
#include "ioloop.h"
75
75
{
76
76
        struct mail_index_map *map = ctx->view->map;
77
77
 
78
 
        i_assert(MAIL_INDEX_MAP_IS_IN_MEMORY(map) ||
79
 
                 map->rec_map->lock_id != 0);
80
 
 
81
78
        if (map->refcount > 1) {
82
79
                map = mail_index_map_clone(map);
83
80
                mail_index_sync_replace_map(ctx, map);
92
89
struct mail_index_map *
93
90
mail_index_sync_get_atomic_map(struct mail_index_sync_map_ctx *ctx)
94
91
{
95
 
        mail_index_sync_move_to_private_memory(ctx);
 
92
        (void)mail_index_sync_move_to_private_memory(ctx);
96
93
        mail_index_record_map_move_to_private(ctx->view->map);
97
94
        mail_index_modseq_sync_map_replaced(ctx->modseq_ctx);
98
 
        ctx->view->map->write_atomic = TRUE;
99
95
        return ctx->view->map;
100
96
}
101
97
 
176
172
        if (all) {
177
173
                mail_index_sync_header_update_counts_all(ctx, uid, old_flags,
178
174
                                                         new_flags);
 
175
        } else if (uid >= ctx->view->map->hdr.next_uid) {
 
176
                mail_index_sync_set_corrupted(ctx, "uid %u >= next_uid %u",
 
177
                                              uid, ctx->view->map->hdr.next_uid);
179
178
        } else {
180
 
                i_assert(uid < ctx->view->map->hdr.next_uid);
181
179
                if (mail_index_header_update_counts(&ctx->view->map->hdr,
182
180
                                                    old_flags, new_flags,
183
181
                                                    &error) < 0)
324
322
                else if (!mail_index_lookup_seq(view, u->uid, &seq))
325
323
                        continue;
326
324
 
327
 
                min_modseq = ((uint64_t)u->modseq_high32 >> 32) |
 
325
                min_modseq = ((uint64_t)u->modseq_high32 << 32) |
328
326
                        u->modseq_low32;
329
327
                if (highest_modseq < min_modseq)
330
328
                        highest_modseq = min_modseq;
344
342
        return 1;
345
343
}
346
344
 
347
 
void mail_index_sync_write_seq_update(struct mail_index_sync_map_ctx *ctx,
348
 
                                      uint32_t seq1, uint32_t seq2)
349
 
{
350
 
        struct mail_index_map *map = ctx->view->map;
351
 
 
352
 
        if (map->rec_map->write_seq_first == 0 ||
353
 
            map->rec_map->write_seq_first > seq1)
354
 
                map->rec_map->write_seq_first = seq1;
355
 
        if (map->rec_map->write_seq_last < seq2)
356
 
                map->rec_map->write_seq_last = seq2;
357
 
}
358
 
 
359
345
static int sync_append(const struct mail_index_record *rec,
360
346
                       struct mail_index_sync_map_ctx *ctx)
361
347
{
396
382
                map->rec_map->last_appended_uid = rec->uid;
397
383
                new_flags = rec->flags;
398
384
 
399
 
                mail_index_sync_write_seq_update(ctx,
400
 
                                                 map->rec_map->records_count,
401
 
                                                 map->rec_map->records_count);
402
385
                mail_index_modseq_append(ctx->modseq_ctx,
403
386
                                         map->rec_map->records_count);
404
387
        }
426
409
        if (!mail_index_lookup_seq_range(view, u->uid1, u->uid2, &seq1, &seq2))
427
410
                return 1;
428
411
 
429
 
        mail_index_sync_write_seq_update(ctx, seq1, seq2);
430
412
        if (!MAIL_TRANSACTION_FLAG_UPDATE_IS_INTERNAL(u)) {
431
413
                mail_index_modseq_update_flags(ctx->modseq_ctx,
432
414
                                               u->add_flags | u->remove_flags,
471
453
        struct mail_index_map *map = ctx->view->map;
472
454
        uint32_t orig_log_file_tail_offset = map->hdr.log_file_tail_offset;
473
455
        uint32_t orig_next_uid = map->hdr.next_uid;
474
 
        uint32_t orig_uid_validity = map->hdr.uid_validity;
475
456
 
476
457
        if (u->offset >= map->hdr.base_header_size ||
477
458
            u->offset + u->size > map->hdr.base_header_size) {
483
464
 
484
465
        buffer_write(map->hdr_copy_buf, u->offset, u + 1, u->size);
485
466
        map->hdr_base = map->hdr_copy_buf->data;
486
 
        map->write_base_header = TRUE;
487
467
 
488
468
        /* @UNSAFE */
489
469
        if ((uint32_t)(u->offset + u->size) <= sizeof(map->hdr)) {
494
474
                       u + 1, sizeof(map->hdr) - u->offset);
495
475
        }
496
476
 
497
 
        /* UIDVALIDITY can be changed only by resetting the index */
498
 
        if (orig_uid_validity != 0 &&
499
 
            MAIL_INDEX_HEADER_UPDATE_FIELD_IN_RANGE(u, uid_validity)) {
500
 
                mail_index_sync_set_corrupted(ctx,
501
 
                        "uid_validity updated unexpectedly: %u -> %u",
502
 
                        orig_uid_validity, map->hdr.uid_validity);
503
 
                /* let it through anyway, although this could give wrong
504
 
                   "next_uid shrank" errors if the value actually changed.. */
505
 
        }
506
477
        if (map->hdr.next_uid < orig_next_uid) {
507
 
                mail_index_sync_set_corrupted(ctx,
508
 
                        "next_uid shrank ignored: %u -> %u",
509
 
                        orig_next_uid, map->hdr.next_uid);
 
478
                /* next_uid update tried to shrink its value. this can happen
 
479
                   in some race conditions with e.g. with dsync, so just
 
480
                   silently ignore it. */
510
481
                map->hdr.next_uid = orig_next_uid;
511
 
                return -1;
512
482
        }
513
483
 
514
484
        /* the tail offset updates are intended for internal transaction
523
493
                            const struct mail_transaction_header *hdr,
524
494
                            const void *data)
525
495
{
 
496
        uint64_t modseq;
526
497
        int ret = 0;
527
498
 
528
499
        switch (hdr->type & MAIL_TRANSACTION_TYPE_MASK) {
564
535
                t_array_init(&uids, 64);
565
536
                end = CONST_PTR_OFFSET(data, hdr->size);
566
537
                for (; rec != end; rec++) {
567
 
                        if (rec->uid == 0) {
568
 
                                mail_index_sync_set_corrupted(ctx,
569
 
                                        "Expunge-guid for invalid uid=%u",
570
 
                                        rec->uid);
571
 
                                break;
572
 
                        }
573
 
                        seq_range_array_add(&uids, 0, rec->uid);
 
538
                        i_assert(rec->uid != 0);
 
539
                        seq_range_array_add(&uids, rec->uid);
574
540
                }
575
541
 
576
542
                /* do this in reverse so the memmove()s are smaller */
626
592
                        }
627
593
 
628
594
                        rec = CONST_PTR_OFFSET(data, i);
629
 
                        if (i + sizeof(*rec) + rec->name_size > hdr->size) {
630
 
                                mail_index_sync_set_corrupted(ctx,
631
 
                                        "ext intro: name_size too large");
632
 
                                ret = -1;
633
 
                                break;
634
 
                        }
 
595
                        /* name_size checked by _log_view_next() */
 
596
                        i_assert(i + sizeof(*rec) + rec->name_size <= hdr->size);
635
597
 
636
598
                        ret = mail_index_sync_ext_intro(ctx, rec);
637
599
                        if (ret <= 0)
804
766
                break;
805
767
        case MAIL_TRANSACTION_BOUNDARY:
806
768
                break;
 
769
        case MAIL_TRANSACTION_ATTRIBUTE_UPDATE:
 
770
                modseq = mail_transaction_log_view_get_prev_modseq(ctx->view->log_view);
 
771
                mail_index_modseq_update_highest(ctx->modseq_ctx, modseq);
 
772
                break;
807
773
        default:
808
774
                mail_index_sync_set_corrupted(ctx,
809
775
                        "Unknown transaction record type 0x%x",
977
943
        map->refcount--;
978
944
 
979
945
        had_dirty = (map->hdr.flags & MAIL_INDEX_HDR_FLAG_HAVE_DIRTY) != 0;
980
 
        if (had_dirty) {
 
946
        if (had_dirty)
981
947
                map->hdr.flags &= ~MAIL_INDEX_HDR_FLAG_HAVE_DIRTY;
982
 
                map->write_base_header = TRUE;
983
 
        }
984
948
 
985
949
        if (map->hdr_base != map->hdr_copy_buf->data) {
986
950
                /* if syncing updates the header, it updates hdr_copy_buf