~james-page/ubuntu/raring/dovecot/autopkgtest

« back to all changes in this revision

Viewing changes to src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2012-06-11 11:11:54 UTC
  • mfrom: (1.15.2) (4.1.27 sid)
  • Revision ID: package-import@ubuntu.com-20120611111154-678cwbdj6ktgsv1h
Tags: 1:2.1.7-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/{control,rules}: enable PIE hardening.
  + 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.
  + d/control: Added Pre-Depends: dpkg (>= 1.15.6) to dovecot-dbg to support
    xz compression in Ubuntu.
  + d/control: Demote dovecot-common Recommends: to Suggests: to prevent
    install of extra packages on upgrade.
  + d/patches/dovecot-drac.patch: Updated with version for dovecot >= 2.0.0.
  + d/control: Drop B-D on systemd.
* Dropped changes:
  + d/patches/fix-racey-restart.patch: part of 2.1.x, no longer required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2009-2011 Dovecot authors, see the included COPYING file */
 
1
/* Copyright (c) 2009-2012 Dovecot authors, see the included COPYING file */
2
2
 
3
3
#include "lib.h"
4
4
#include "array.h"
21
21
#include <unistd.h>
22
22
 
23
23
struct mdbox_rebuild_msg {
24
 
        uint8_t guid_128[MAIL_GUID_128_SIZE];
 
24
        guid_128_t guid_128;
25
25
        uint32_t file_id;
26
26
        uint32_t offset;
27
27
        uint32_t size;
50
50
        ARRAY_TYPE(seq_range) seen_file_ids;
51
51
 
52
52
        uint32_t rebuild_count;
53
 
        uint32_t highest_seen_map_uid;
54
53
        uint32_t highest_file_id;
55
54
 
56
55
        struct mailbox_list *default_list;
58
57
        struct rebuild_msg_mailbox prev_msg;
59
58
};
60
59
 
61
 
static unsigned int guid_hash(const void *p)
62
 
{
63
 
        const uint8_t *s = p;
64
 
        unsigned int i, g, h = 0;
65
 
 
66
 
        for (i = 0; i < MAIL_GUID_128_SIZE; i++) {
67
 
                h = (h << 4) + s[i];
68
 
                if ((g = h & 0xf0000000UL)) {
69
 
                        h = h ^ (g >> 24);
70
 
                        h = h ^ g;
71
 
                }
72
 
        }
73
 
        return h;
74
 
}
75
 
 
76
 
static int guid_cmp(const void *p1, const void *p2)
77
 
{
78
 
        return memcmp(p1, p2, MAIL_GUID_128_SIZE);
79
 
}
80
 
 
81
60
static struct mdbox_storage_rebuild_context *
82
61
mdbox_storage_rebuild_init(struct mdbox_storage *storage,
83
62
                           struct mdbox_map_atomic_context *atomic)
91
70
        ctx->atomic = atomic;
92
71
        ctx->pool = pool_alloconly_create("dbox map rebuild", 1024*256);
93
72
        ctx->guid_hash = hash_table_create(default_pool, ctx->pool, 0,
94
 
                                           guid_hash, guid_cmp);
 
73
                                           guid_128_hash, guid_128_cmp);
95
74
        i_array_init(&ctx->msgs, 512);
96
75
        i_array_init(&ctx->seen_file_ids, 128);
97
76
 
198
177
                rec->offset = offset;
199
178
                rec->size = file->input->v_offset - offset;
200
179
                mail_generate_guid_128_hash(guid, rec->guid_128);
201
 
                i_assert(!mail_guid_128_is_empty(rec->guid_128));
 
180
                i_assert(!guid_128_is_empty(rec->guid_128));
202
181
                array_append(&ctx->msgs, &rec, 1);
203
182
 
204
183
                old_rec = hash_table_lookup(ctx->guid_hash, rec->guid_128);
477
456
        }
478
457
 
479
458
        /* make sure we have valid mailbox guid */
480
 
        if (mail_guid_128_is_empty(hdr.mailbox_guid)) {
481
 
                if (!mail_guid_128_is_empty(backup_hdr.mailbox_guid)) {
 
459
        if (guid_128_is_empty(hdr.mailbox_guid)) {
 
460
                if (!guid_128_is_empty(backup_hdr.mailbox_guid)) {
482
461
                        memcpy(hdr.mailbox_guid, backup_hdr.mailbox_guid,
483
462
                               sizeof(hdr.mailbox_guid));
484
463
                } else {
485
 
                        mail_generate_guid_128(hdr.mailbox_guid);
 
464
                        guid_128_generate(hdr.mailbox_guid);
486
465
                }
487
466
        }
488
467
 
505
484
        struct mail_index_transaction *trans;
506
485
        struct dbox_sync_rebuild_context *rebuild_ctx;
507
486
        enum mail_error error;
508
 
        const char *name;
509
487
        int ret;
510
488
 
511
 
        name = mail_namespace_get_storage_name(ns, vname);
512
 
        if (!mailbox_list_is_valid_existing_name(ns->list, name)) {
513
 
                i_warning("Invalid mailbox name: %s", name);
514
 
                return 0;
515
 
        }
516
 
 
517
 
        box = mailbox_alloc(ns->list, name, MAILBOX_FLAG_READONLY |
518
 
                            MAILBOX_FLAG_KEEP_RECENT |
 
489
        box = mailbox_alloc(ns->list, vname, MAILBOX_FLAG_READONLY |
519
490
                            MAILBOX_FLAG_IGNORE_ACLS);
520
491
        i_assert(box->storage == &ctx->storage->storage.storage);
521
 
        if (dbox_mailbox_open(box) < 0) {
522
 
                (void)mail_storage_get_last_error(box->storage, &error);
 
492
        if (mailbox_open(box) < 0) {
 
493
                error = mailbox_get_last_mail_error(box);
 
494
                i_error("Couldn't open mailbox '%s': %s",
 
495
                        vname, mailbox_get_last_error(box, NULL));
523
496
                mailbox_free(&box);
524
497
                if (error == MAIL_ERROR_TEMP)
525
498
                        return -1;
537
510
                return -1;
538
511
        }
539
512
 
540
 
        /* reset cache, just in case it contains invalid data */
541
 
        mail_cache_reset(box->cache);
542
 
 
543
513
        rebuild_ctx = dbox_sync_index_rebuild_init(&mbox->box, view, trans);
544
514
        mdbox_header_update(rebuild_ctx, mbox);
545
515
        rebuild_mailbox_multi(ctx, rebuild_ctx, mbox, view, trans);
635
605
        if (ret > 0 && !deleted && dbox_file_metadata_read(file) > 0) {
636
606
                mailbox = dbox_file_metadata_get(file,
637
607
                                                 DBOX_METADATA_ORIG_MAILBOX);
 
608
                mailbox = mailbox_list_get_vname(ctx->default_list, mailbox);
638
609
                mailbox = t_strdup(mailbox);
639
610
        }
640
611
        dbox_file_unref(&file);
653
624
           there. */
654
625
        created = FALSE;
655
626
        box = ctx->prev_msg.box != NULL &&
656
 
                strcmp(mailbox, ctx->prev_msg.box->name) == 0 ?
 
627
                strcmp(mailbox, ctx->prev_msg.box->vname) == 0 ?
657
628
                ctx->prev_msg.box : NULL;
658
629
        while (box == NULL) {
659
630
                box = mailbox_alloc(ctx->default_list, mailbox,
660
631
                                    MAILBOX_FLAG_READONLY |
661
 
                                    MAILBOX_FLAG_KEEP_RECENT |
662
632
                                    MAILBOX_FLAG_IGNORE_ACLS);
663
633
                i_assert(box->storage == storage);
664
 
                if (dbox_mailbox_open(box) == 0)
 
634
                if (mailbox_open(box) == 0)
665
635
                        break;
666
636
 
667
 
                (void)mail_storage_get_last_error(box->storage, &error);
 
637
                error = mailbox_get_last_mail_error(box);
668
638
                if (error == MAIL_ERROR_NOTFOUND && !created) {
669
639
                        /* mailbox doesn't exist currently? see if creating
670
640
                           it helps. */