# HG changeset patch # User Timo Sirainen # Date 1301948341 -10800 # Node ID 230458801916e1f8589d1bca4ccc20de81899658 # Parent 618f610c7c67ac317e800593410637ae98fbd6c2 quota: Code cleanup. diff -r 618f610c7c67 -r 230458801916 src/plugins/quota/quota-private.h --- a/src/plugins/quota/quota-private.h Mon Apr 04 23:18:31 2011 +0300 +++ b/src/plugins/quota/quota-private.h Mon Apr 04 23:19:01 2011 +0300 @@ -130,7 +130,9 @@ struct mailbox *box; int64_t bytes_used, count_used; - uint64_t bytes_left, count_left; + /* how many bytes/mails can be saved until limit is reached. + (set once, not updated by bytes_used/count_used) */ + uint64_t bytes_ceil, count_ceil; struct mail *tmp_mail; diff -r 618f610c7c67 -r 230458801916 src/plugins/quota/quota.c --- a/src/plugins/quota/quota.c Mon Apr 04 23:18:31 2011 +0300 +++ b/src/plugins/quota/quota.c Mon Apr 04 23:19:01 2011 +0300 @@ -924,8 +924,8 @@ i_assert(ctx->quota != NULL); ctx->box = box; - ctx->bytes_left = (uint64_t)-1; - ctx->count_left = (uint64_t)-1; + ctx->bytes_ceil = (uint64_t)-1; + ctx->count_ceil = (uint64_t)-1; return ctx; } @@ -934,7 +934,7 @@ struct quota_root *const *roots; const char *mailbox_name; unsigned int i, count; - uint64_t bytes_limit, count_limit, current, limit, left; + uint64_t bytes_limit, count_limit, current, limit, ceil; int ret; ctx->limits_set = TRUE; @@ -958,9 +958,9 @@ QUOTA_NAME_STORAGE_BYTES, ¤t, &limit); if (ret > 0) { - left = limit < current ? 0 : limit - current; - if (ctx->bytes_left > left) - ctx->bytes_left = left; + ceil = limit < current ? 0 : limit - current; + if (ctx->bytes_ceil > ceil) + ctx->bytes_ceil = ceil; } else if (ret < 0) { ctx->failed = TRUE; return -1; @@ -972,9 +972,9 @@ QUOTA_NAME_MESSAGES, ¤t, &limit); if (ret > 0) { - left = limit < current ? 0 : limit - current; - if (ctx->count_left > left) - ctx->count_left = left; + ceil = limit < current ? 0 : limit - current; + if (ctx->count_ceil > ceil) + ctx->count_ceil = ceil; } else if (ret < 0) { ctx->failed = TRUE; return -1; @@ -1170,10 +1170,11 @@ *too_large_r = FALSE; - if ((int64_t)ctx->count_left >= ctx->count_used + 1 && - (int64_t)ctx->bytes_left >= ctx->bytes_used + (off_t)size) + if (ctx->count_used + 1 <= (int64_t)ctx->count_ceil && + ctx->bytes_used + (off_t)size <= (int64_t)ctx->bytes_ceil) return 1; + /* limit reached. only thing left to do now is to set too_large_r. */ roots = array_get(&ctx->quota->roots, &count); for (i = 0; i < count; i++) { uint64_t bytes_limit, count_limit;