Mercurial > dovecot > original-hg > dovecot-1.2
changeset 4330:823648215520 HEAD
If size of the mail was known before saving started, we allocated
the quota twice for it.
author | Timo Sirainen <timo.sirainen@movial.fi> |
---|---|
date | Sun, 11 Jun 2006 20:39:04 +0300 |
parents | 72361670eaab |
children | b445c43d5472 |
files | src/plugins/quota/quota-dict.c src/plugins/quota/quota-dirsize.c src/plugins/quota/quota-fs.c src/plugins/quota/quota-maildir.c src/plugins/quota/quota-private.h src/plugins/quota/quota-storage.c src/plugins/quota/quota.c src/plugins/quota/quota.h |
diffstat | 8 files changed, 47 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/plugins/quota/quota-dict.c Sun Jun 11 20:38:06 2006 +0300 +++ b/src/plugins/quota/quota-dict.c Sun Jun 11 20:39:04 2006 +0300 @@ -223,6 +223,7 @@ quota_default_try_alloc, quota_default_try_alloc_bytes, + quota_default_test_alloc_bytes, quota_default_alloc, quota_default_free }
--- a/src/plugins/quota/quota-dirsize.c Sun Jun 11 20:38:06 2006 +0300 +++ b/src/plugins/quota/quota-dirsize.c Sun Jun 11 20:39:04 2006 +0300 @@ -313,6 +313,7 @@ quota_default_try_alloc, quota_default_try_alloc_bytes, + quota_default_test_alloc_bytes, quota_default_alloc, quota_default_free }
--- a/src/plugins/quota/quota-fs.c Sun Jun 11 20:38:06 2006 +0300 +++ b/src/plugins/quota/quota-fs.c Sun Jun 11 20:39:04 2006 +0300 @@ -268,6 +268,7 @@ quota_default_try_alloc, quota_default_try_alloc_bytes, + quota_default_test_alloc_bytes, quota_default_alloc, quota_default_free }
--- a/src/plugins/quota/quota-maildir.c Sun Jun 11 20:38:06 2006 +0300 +++ b/src/plugins/quota/quota-maildir.c Sun Jun 11 20:39:04 2006 +0300 @@ -687,6 +687,7 @@ quota_default_try_alloc, quota_default_try_alloc_bytes, + quota_default_test_alloc_bytes, quota_default_alloc, quota_default_free }
--- a/src/plugins/quota/quota-private.h Sun Jun 11 20:38:06 2006 +0300 +++ b/src/plugins/quota/quota-private.h Sun Jun 11 20:39:04 2006 +0300 @@ -51,6 +51,8 @@ struct mail *mail, bool *too_large_r); int (*try_alloc_bytes)(struct quota_root_transaction_context *ctx, uoff_t size, bool *too_large_r); + int (*test_alloc_bytes)(struct quota_root_transaction_context *ctx, + uoff_t size, bool *too_large_r); void (*alloc)(struct quota_root_transaction_context *ctx, struct mail *mail); void (*free)(struct quota_root_transaction_context *ctx, @@ -119,10 +121,12 @@ /* default simple implementations for bytes/count updating */ void quota_default_transaction_rollback(struct quota_root_transaction_context *ctx); +int quota_default_try_alloc(struct quota_root_transaction_context *ctx, + struct mail *mail, bool *too_large_r); int quota_default_try_alloc_bytes(struct quota_root_transaction_context *ctx, uoff_t size, bool *too_large_r); -int quota_default_try_alloc(struct quota_root_transaction_context *ctx, - struct mail *mail, bool *too_large_r); +int quota_default_test_alloc_bytes(struct quota_root_transaction_context *ctx, + uoff_t size, bool *too_large_r); void quota_default_alloc(struct quota_root_transaction_context *ctx, struct mail *mail); void quota_default_free(struct quota_root_transaction_context *ctx,
--- a/src/plugins/quota/quota-storage.c Sun Jun 11 20:38:06 2006 +0300 +++ b/src/plugins/quota/quota-storage.c Sun Jun 11 20:39:04 2006 +0300 @@ -186,7 +186,7 @@ full mail. */ bool too_large; - ret = quota_try_alloc_bytes(qt, st->st_size, &too_large); + ret = quota_test_alloc_bytes(qt, st->st_size, &too_large); if (ret == 0) { mail_storage_set_error(t->box->storage, "Quota exceeded");
--- a/src/plugins/quota/quota.c Sun Jun 11 20:38:06 2006 +0300 +++ b/src/plugins/quota/quota.c Sun Jun 11 20:39:04 2006 +0300 @@ -324,6 +324,25 @@ return ret; } +int quota_test_alloc_bytes(struct quota_transaction_context *ctx, + uoff_t size, bool *too_large_r) +{ + struct quota_root_transaction_context *const *root_transactions; + unsigned int i, count; + int ret = 1; + + root_transactions = array_get(&ctx->root_transactions, &count); + for (i = 0; i < count; i++) { + struct quota_root_transaction_context *t = + root_transactions[i]; + + ret = t->root->v.test_alloc_bytes(t, size, too_large_r); + if (ret <= 0) + break; + } + return ret; +} + void quota_alloc(struct quota_transaction_context *ctx, struct mail *mail) { struct quota_root_transaction_context *const *root_transactions; @@ -372,6 +391,20 @@ int quota_default_try_alloc_bytes(struct quota_root_transaction_context *ctx, uoff_t size, bool *too_large_r) { + int ret; + + ret = quota_default_test_alloc_bytes(ctx, size, too_large_r); + if (ret <= 0 || ctx->disabled) + return ret; + + ctx->count_diff++; + ctx->bytes_diff += size; + return 1; +} + +int quota_default_test_alloc_bytes(struct quota_root_transaction_context *ctx, + uoff_t size, bool *too_large_r) +{ if (ctx->disabled) { *too_large_r = FALSE; return 1; @@ -387,9 +420,6 @@ return 0; if (ctx->count_current + ctx->count_diff + 1 > ctx->count_limit) return 0; - - ctx->count_diff++; - ctx->bytes_diff += size; return 1; }
--- a/src/plugins/quota/quota.h Sun Jun 11 20:38:06 2006 +0300 +++ b/src/plugins/quota/quota.h Sun Jun 11 20:39:04 2006 +0300 @@ -65,6 +65,9 @@ struct mail *mail, bool *too_large_r); int quota_try_alloc_bytes(struct quota_transaction_context *ctx, uoff_t size, bool *too_large_r); +/* Like quota_try_alloc_bytes(), but don't actually update the quota. */ +int quota_test_alloc_bytes(struct quota_transaction_context *ctx, + uoff_t size, bool *too_large_r); /* Update quota by allocating/freeing space used by mail. */ void quota_alloc(struct quota_transaction_context *ctx, struct mail *mail); void quota_free(struct quota_transaction_context *ctx, struct mail *mail);