]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
quota: Use event based logging
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 31 Oct 2019 17:27:15 +0000 (19:27 +0200)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Tue, 8 Sep 2020 18:42:41 +0000 (18:42 +0000)
src/plugins/quota/quota-dict.c
src/plugins/quota/quota-fs.c
src/plugins/quota/quota-imapc.c
src/plugins/quota/quota-maildir.c
src/plugins/quota/quota-storage.c
src/plugins/quota/quota-util.c
src/plugins/quota/quota.c

index 9aa527e7129d575c91fb54670f86b9f28400f80b..690dc76881f3ef873db81b488038fc46b54a73b8 100644 (file)
@@ -63,10 +63,9 @@ static int dict_quota_init(struct quota_root *_root, const char *args,
        if (*username == '\0')
                username = _root->quota->user->username;
 
-       if (_root->quota->set->debug) {
-               i_debug("dict quota: user=%s, uri=%s, noenforcing=%d",
-                       username, args, _root->no_enforcing ? 1 : 0);
-       }
+       e_debug(_root->quota->event,
+               "dict quota: user=%s, uri=%s, noenforcing=%d",
+               username, args, _root->no_enforcing ? 1 : 0);
 
        /* FIXME: we should use 64bit integer as datatype instead but before
           it can actually be used don't bother */
@@ -130,10 +129,8 @@ dict_quota_count(struct dict_quota_root *root,
        dict_set(dt, DICT_QUOTA_CURRENT_BYTES_PATH, dec2str(bytes));
        dict_set(dt, DICT_QUOTA_CURRENT_COUNT_PATH, dec2str(count));
 
-       if (root->root.quota->set->debug) {
-               i_debug("dict quota: Quota recalculated: "
-                       "count=%"PRIu64" bytes=%"PRIu64, count, bytes);
-       }
+       e_debug(root->root.quota->event, "dict quota: Quota recalculated: "
+               "count=%"PRIu64" bytes=%"PRIu64, count, bytes);
 
        dict_transaction_commit_async(&dt, NULL, NULL);
        *value_r = want_bytes ? bytes : count;
@@ -189,7 +186,8 @@ static void dict_quota_recalc_timeout(struct dict_quota_root *root)
        timeout_remove(&root->to_update);
        if (dict_quota_count(root, TRUE, &value, &error)
            <= QUOTA_GET_RESULT_INTERNAL_ERROR)
-               i_error("quota-dict: Recalculation failed: %s", error);
+               e_error(root->root.quota->event,
+                       "quota-dict: Recalculation failed: %s", error);
 }
 
 static void dict_quota_update_callback(const struct dict_commit_result *result,
@@ -202,7 +200,8 @@ static void dict_quota_update_callback(const struct dict_commit_result *result,
                if (root->to_update == NULL)
                        root->to_update = timeout_add_short(0, dict_quota_recalc_timeout, root);
        } else if (result->ret < 0) {
-               i_error("dict quota: Quota update failed: %s "
+               e_error(root->root.quota->event,
+                       "dict quota: Quota update failed: %s "
                        "- Quota is now desynced", result->error);
        }
 }
index c2c7221ca084eed6f054c5b51f7242fb42c7cecf..e519b4fbafcc1cb93246e0e39a62e5541a1eeb41 100644 (file)
@@ -163,7 +163,8 @@ static void fs_quota_deinit(struct quota_root *_root)
        i_free(root);
 }
 
-static struct fs_quota_mountpoint *fs_quota_mountpoint_get(const char *dir)
+static struct fs_quota_mountpoint *
+fs_quota_mountpoint_get(struct quota *quota, const char *dir)
 {
        struct fs_quota_mountpoint *mount;
        struct mountpoint point;
@@ -185,7 +186,8 @@ static struct fs_quota_mountpoint *fs_quota_mountpoint_get(const char *dir)
 
        if (mount_type_is_nfs(mount)) {
                if (strchr(mount->device_path, ':') == NULL) {
-                       i_error("quota-fs: %s is not a valid NFS device path",
+                       e_error(quota->event,
+                               "quota-fs: %s is not a valid NFS device path",
                                mount->device_path);
                        fs_quota_mountpoint_free(mount);
                        return NULL;
@@ -238,17 +240,16 @@ fs_quota_mount_init(struct fs_quota_root *root,
                mount->path = i_strconcat(mount->mount_path, "/quotas", NULL);
                mount->fd = open(mount->path, O_RDONLY);
                if (mount->fd == -1 && errno != ENOENT)
-                       i_error("open(%s) failed: %m", mount->path);
+                       e_error(root->root.quota->event,
+                               "open(%s) failed: %m", mount->path);
        }
 #endif
        root->mount = mount;
 
-       if (root->root.quota->set->debug) {
-               i_debug("fs quota add mailbox dir = %s", dir);
-               i_debug("fs quota block device = %s", mount->device_path);
-               i_debug("fs quota mount point = %s", mount->mount_path);
-               i_debug("fs quota mount type = %s", mount->type);
-       }
+       e_debug(root->root.quota->event, "fs quota add mailbox dir = %s", dir);
+       e_debug(root->root.quota->event, "fs quota block device = %s", mount->device_path);
+       e_debug(root->root.quota->event, "fs quota mount point = %s", mount->mount_path);
+       e_debug(root->root.quota->event, "fs quota mount type = %s", mount->type);
 
        /* if there are more unused quota roots, copy this mount to them */
        roots = array_get(&root->root.quota->roots, &count);
@@ -275,7 +276,7 @@ static void fs_quota_add_missing_mounts(struct quota *quota)
                    root->storage_mount_path == NULL || root->mount != NULL)
                        continue;
 
-               mount = fs_quota_mountpoint_get(root->storage_mount_path);
+               mount = fs_quota_mountpoint_get(quota, root->storage_mount_path);
                if (mount != NULL) {
                        fs_quota_mount_init(root, mount,
                                            root->storage_mount_path);
@@ -294,7 +295,7 @@ static void fs_quota_namespace_added(struct quota *quota,
                                        &dir))
                mount = NULL;
        else
-               mount = fs_quota_mountpoint_get(dir);
+               mount = fs_quota_mountpoint_get(quota, dir);
        if (mount != NULL) {
                root = fs_quota_root_find_mountpoint(quota, mount);
                if (root != NULL && root->mount == NULL)
@@ -391,10 +392,8 @@ do_rquota_user(struct fs_quota_root *root,
                        path++;
        }
 
-       if (root->root.quota->set->debug) {
-               i_debug("quota-fs: host=%s, path=%s, uid=%s",
-                       host, path, dec2str(root->uid));
-       }
+       e_debug(root->root.quota->event, "quota-fs: host=%s, path=%s, uid=%s",
+               host, path, dec2str(root->uid));
 
        /* clnt_create() polls for a while to establish a connection */
        cl = clnt_create(host, RQUOTAPROG, RQUOTAVERS, "udp");
@@ -437,20 +436,16 @@ do_rquota_user(struct fs_quota_root *root,
                rquota_get_result(&result.getquota_rslt_u.gqr_rquota,
                                  bytes_value_r, bytes_limit_r,
                                  count_value_r, count_limit_r);
-               if (root->root.quota->set->debug) {
-                       i_debug("quota-fs: uid=%s, bytes=%"PRIu64"/%"PRIu64" "
-                               "files=%"PRIu64"/%"PRIu64,
-                               dec2str(root->uid),
-                               *bytes_value_r, *bytes_limit_r,
-                               *count_value_r, *count_limit_r);
-               }
+               e_debug(root->root.quota->event, "quota-fs: uid=%s, bytes=%"PRIu64"/%"PRIu64" "
+                       "files=%"PRIu64"/%"PRIu64,
+                       dec2str(root->uid),
+                       *bytes_value_r, *bytes_limit_r,
+                       *count_value_r, *count_limit_r);
                return 1;
        }
        case Q_NOQUOTA:
-               if (root->root.quota->set->debug) {
-                       i_debug("quota-fs: uid=%s, limit=unlimited",
-                               dec2str(root->uid));
-               }
+               e_debug(root->root.quota->event, "quota-fs: uid=%s, limit=unlimited",
+                       dec2str(root->uid));
                fs_quota_root_disable(root, FALSE);
                return 0;
        case Q_EPERM:
@@ -488,10 +483,8 @@ do_rquota_group(struct fs_quota_root *root ATTR_UNUSED,
        host = t_strdup_until(mount->device_path, path);
        path++;
 
-       if (root->root.quota->set->debug) {
-               i_debug("quota-fs: host=%s, path=%s, gid=%s",
-                       host, path, dec2str(root->gid));
-       }
+       e_debug(root->root.quota->event, "quota-fs: host=%s, path=%s, gid=%s",
+               host, path, dec2str(root->gid));
 
        /* clnt_create() polls for a while to establish a connection */
        cl = clnt_create(host, RQUOTAPROG, EXT_RQUOTAVERS, "udp");
@@ -534,20 +527,16 @@ do_rquota_group(struct fs_quota_root *root ATTR_UNUSED,
                rquota_get_result(&result.getquota_rslt_u.gqr_rquota,
                                  bytes_value_r, bytes_limit_r,
                                  count_value_r, count_limit_r);
-               if (root->root.quota->set->debug) {
-                       i_debug("quota-fs: gid=%s, bytes=%"PRIu64"/%"PRIu64" "
-                               "files=%"PRIu64"/%"PRIu64,
-                               dec2str(root->gid),
-                               *bytes_value_r, *bytes_limit_r,
-                               *count_value_r, *count_limit_r);
-               }
+               e_debug(root->root.quota->event, "quota-fs: gid=%s, bytes=%"PRIu64"/%"PRIu64" "
+                       "files=%"PRIu64"/%"PRIu64,
+                       dec2str(root->gid),
+                       *bytes_value_r, *bytes_limit_r,
+                       *count_value_r, *count_limit_r);
                return 1;
        }
        case Q_NOQUOTA:
-               if (root->root.quota->set->debug) {
-                       i_debug("quota-fs: gid=%s, limit=unlimited",
-                               dec2str(root->gid));
-               }
+               e_debug(root->root.quota->event, "quota-fs: gid=%s, limit=unlimited",
+                       dec2str(root->gid));
                fs_quota_root_disable(root, TRUE);
                return 0;
        case Q_EPERM:
@@ -866,21 +855,18 @@ static bool fs_quota_match_box(struct quota_root *_root, struct mailbox *box)
                return FALSE;
        if (stat(mailbox_path, &mst) < 0) {
                if (errno != ENOENT)
-                       i_error("stat(%s) failed: %m", mailbox_path);
+                       e_error(_root->quota->event,
+                               "stat(%s) failed: %m", mailbox_path);
                return FALSE;
        }
        if (stat(root->storage_mount_path, &rst) < 0) {
-               if (_root->quota->set->debug) {
-                       i_debug("stat(%s) failed: %m",
-                               root->storage_mount_path);
-               }
+               e_debug(_root->quota->event, "stat(%s) failed: %m",
+                       root->storage_mount_path);
                return FALSE;
        }
        match = CMP_DEV_T(mst.st_dev, rst.st_dev);
-       if (_root->quota->set->debug) {
-               i_debug("box=%s mount=%s match=%s", mailbox_path,
-                       root->storage_mount_path, match ? "yes" : "no");
-       }
+       e_debug(_root->quota->event, "box=%s mount=%s match=%s", mailbox_path,
+               root->storage_mount_path, match ? "yes" : "no");
        return match;
 }
 
index 6abdfdc6980457083b1b0b3a8eaa6b70d8ce557e..870e1b604476765369b342801a472db4ab05d75e 100644 (file)
@@ -222,7 +222,8 @@ static bool imapc_quota_client_init(struct imapc_quota_root *root)
                /* non-imapc namespace, skip */
                if ((storage->class_flags &
                     MAIL_STORAGE_CLASS_FLAG_NOQUOTA) == 0) {
-                       i_warning("quota: Namespace '%s' is not imapc, "
+                       e_warning(root->root.quota->event,
+                                 "quota: Namespace '%s' is not imapc, "
                                  "skipping for imapc quota",
                                  root->imapc_ns->prefix);
                }
@@ -253,7 +254,8 @@ imapc_quota_refresh_update(struct quota *quota,
        const struct imapc_quota_refresh_root *refresh_root;
 
        if (array_count(&refresh->roots) == 0) {
-               i_error("quota: imapc didn't return any QUOTA results");
+               e_error(quota->event,
+                       "quota: imapc didn't return any QUOTA results");
                return;
        }
        /* use the first quota root for everything */
@@ -386,7 +388,8 @@ static int imapc_quota_refresh(struct imapc_quota_root *root,
        }
        if ((capa & IMAPC_CAPABILITY_QUOTA) == 0) {
                /* no QUOTA capability - disable quota */
-               i_warning("quota: Remote IMAP server doesn't support QUOTA - disabling");
+               e_warning(root->root.quota->event,
+                         "quota: Remote IMAP server doesn't support QUOTA - disabling");
                root->client = NULL;
                return 0;
        }
index 015bab841e46b5c79987630e089269ac47221c31..b3391e5a806a46efa1bd751fdd1dd763b8be6f27 100644 (file)
@@ -188,7 +188,8 @@ maildir_list_next(struct maildir_list_context *ctx, time_t *mtime_r)
                /* ignore if the directory got lost, stale or if it was
                   actually a file and not a directory */
                if (errno != ENOENT && errno != ESTALE && errno != ENOTDIR) {
-                       i_error("stat(%s) failed: %m", str_c(ctx->path));
+                       e_error(ctx->root->root.quota->event,
+                               "stat(%s) failed: %m", str_c(ctx->path));
                        ctx->state = 0;
                }
        }
@@ -278,7 +279,8 @@ static int maildirsize_write(struct maildir_quota_root *root, const char *path)
                                        perm.file_create_gid,
                                        perm.file_create_gid_origin) < 0 &&
                    errno != EEXIST) {
-                       i_error("mkdir_parents(%s) failed: %m", dir);
+                       e_error(root->root.quota->event,
+                               "mkdir_parents(%s) failed: %m", dir);
                        return -1;
                }
                fd = safe_mkstemp_hostpid_group(temp_path,
@@ -287,7 +289,8 @@ static int maildirsize_write(struct maildir_quota_root *root, const char *path)
                                                perm.file_create_gid_origin);
        }
        if (fd == -1) {
-               i_error("safe_mkstemp(%s) failed: %m", path);
+               e_error(root->root.quota->event,
+                       "safe_mkstemp(%s) failed: %m", path);
                return -1;
        }
 
@@ -304,7 +307,8 @@ static int maildirsize_write(struct maildir_quota_root *root, const char *path)
        str_printfa(str, "\n%"PRIu64" %"PRIu64"\n",
                    root->total_bytes, root->total_count);
        if (write_full(fd, str_data(str), str_len(str)) < 0) {
-               i_error("write_full(%s) failed: %m", str_c(temp_path));
+               e_error(_root->quota->event,
+                       "write_full(%s) failed: %m", str_c(temp_path));
                i_close_fd(&fd);
                i_unlink(str_c(temp_path));
                return -1;
@@ -312,7 +316,8 @@ static int maildirsize_write(struct maildir_quota_root *root, const char *path)
        i_close_fd(&fd);
 
        if (rename(str_c(temp_path), path) < 0) {
-               i_error("rename(%s, %s) failed: %m", str_c(temp_path), path);
+               e_error(_root->quota->event,
+                       "rename(%s, %s) failed: %m", str_c(temp_path), path);
                i_unlink_if_exists(str_c(temp_path));
                return -1;
        }
@@ -358,7 +363,8 @@ static void maildirsize_rebuild_later(struct maildir_quota_root *root)
 
        if (unlink(root->maildirsize_path) < 0 &&
            errno != ENOENT && errno != ESTALE)
-               i_error("unlink(%s) failed: %m", root->maildirsize_path);
+               e_error(root->root.quota->event,
+                       "unlink(%s) failed: %m", root->maildirsize_path);
 }
 
 static int maildirsize_recalculate_finish(struct maildir_quota_root *root,
@@ -657,7 +663,8 @@ static bool maildirquota_limits_init(struct maildir_quota_root *root)
                /* non-maildir namespace, skip */
                if ((storage->class_flags &
                     MAIL_STORAGE_CLASS_FLAG_NOQUOTA) == 0) {
-                       i_warning("quota: Namespace '%s' is not Maildir, "
+                       e_warning(root->root.quota->event,
+                                 "Namespace '%s' is not Maildir, "
                                  "skipping for Maildir++ quota",
                                  root->maildirsize_ns->prefix);
                }
@@ -743,7 +750,8 @@ static int maildirsize_update(struct maildir_quota_root *root,
                if (errno == ESTALE) {
                        /* deleted/replaced already, ignore */
                } else {
-                       i_error("write_full(%s) failed: %m",
+                       e_error(root->root.quota->event,
+                               "write_full(%s) failed: %m",
                                root->maildirsize_path);
                }
        } else {
@@ -751,7 +759,8 @@ static int maildirsize_update(struct maildir_quota_root *root,
                if (close(root->fd) < 0) {
                        ret = -1;
                        if (errno != ESTALE)
-                               i_error("close(%s) failed: %m", root->maildirsize_path);
+                               e_error(root->root.quota->event,
+                                       "close(%s) failed: %m", root->maildirsize_path);
                }
                root->fd = -1;
        }
@@ -909,11 +918,13 @@ maildir_quota_update(struct quota_root *_root,
                   we wanted to do. */
        } else if (root->fd == -1) {
                if (maildirsize_recalculate(root, &error) < 0)
-                       i_error("quota-maildir: %s", error);
+                       e_error(_root->quota->event,
+                               "quota-maildir: %s", error);
        } else if (ctx->recalculate != QUOTA_RECALCULATE_DONT) {
                i_close_fd(&root->fd);
                if (maildirsize_recalculate(root, &error) < 0)
-                       i_error("quota-maildir: %s", error);
+                       e_error(_root->quota->event,
+                               "quota-maildir: %s", error);
        } else if (maildirsize_update(root, ctx->count_used, ctx->bytes_used) < 0) {
                i_close_fd(&root->fd);
                maildirsize_rebuild_later(root);
index 7afb5fa3b7fe3c06cb0ec8a072fe67b76d41366d..7eb455748215d4ed7527fe5d28bf7bb8e6aaab2a 100644 (file)
@@ -265,12 +265,16 @@ static int quota_check(struct mail_save_context *ctx, struct mailbox *src_box)
                return 0;
        case QUOTA_ALLOC_RESULT_TEMPFAIL:
                /* Log the error, but allow saving anyway. */
-               i_error("quota: Failed to check if user is under quota: %s - saving mail anyway", error);
+               e_error(qt->quota->event,
+                       "quota: Failed to check if user is under quota: %s - "
+                       "saving mail anyway", error);
                return 0;
        case QUOTA_ALLOC_RESULT_BACKGROUND_CALC:
                /* Could not determine if there is enough space due to ongoing
                   background quota calculation, allow saving anyway. */
-               i_warning("quota: Failed to check if user is under quota: %s - saving mail anyway", error);
+               e_warning(qt->quota->event,
+                         "quota: Failed to check if user is under quota: %s - "
+                         "saving mail anyway", error);
                return 0;
        default:
                quota_set_storage_error(qt, t->box, ret, error);
@@ -293,10 +297,13 @@ quota_copy(struct mail_save_context *ctx, struct mail *mail)
        enum quota_get_result error_res;
        const char *error;
        if (quota_transaction_set_limits(qt, &error_res, &error) < 0) {
-               if (error_res == QUOTA_GET_RESULT_BACKGROUND_CALC)
-                       i_warning("quota: %s - copying mail anyway", error);
-               else
-                       i_error("quota: %s - copying mail anyway", error);
+               if (error_res == QUOTA_GET_RESULT_BACKGROUND_CALC) {
+                       e_warning(qt->quota->event,
+                                 "quota: %s - copying mail anyway", error);
+               } else {
+                       e_error(qt->quota->event,
+                               "quota: %s - copying mail anyway", error);
+               }
        }
 
        if (qbox->module_ctx.super.copy(ctx, mail) < 0)
@@ -338,13 +345,17 @@ quota_save_begin(struct mail_save_context *ctx, struct istream *input)
                        break;
                case QUOTA_ALLOC_RESULT_TEMPFAIL:
                        /* Log the error, but allow saving anyway. */
-                       i_error("quota: Failed to check if user is under quota: %s - saving mail anyway", error);
+                       e_error(qt->quota->event,
+                               "quota: Failed to check if user is under quota: %s - "
+                               "saving mail anyway", error);
                        break;
                case QUOTA_ALLOC_RESULT_BACKGROUND_CALC:
                        /* Could not determine if there is enough space due to
                         * ongoing background quota calculation, allow saving
                         * anyway. */
-                       i_warning("quota: Failed to check if user is under quota: %s - saving mail anyway", error);
+                       e_warning(qt->quota->event,
+                                 "quota: Failed to check if user is under quota: %s - "
+                                 "saving mail anyway", error);
                        break;
                default:
                        quota_set_storage_error(qt, t->box, qret, error);
@@ -360,9 +371,11 @@ quota_save_begin(struct mail_save_context *ctx, struct istream *input)
        enum quota_get_result error_res;
        if (quota_transaction_set_limits(qt, &error_res, &error) < 0) {
                if (error_res == QUOTA_GET_RESULT_BACKGROUND_CALC)
-                       i_warning("quota: %s - saving mail anyway", error);
+                       e_warning(qt->quota->event,
+                                 "quota: %s - saving mail anyway", error);
                else
-                       i_error("quota: %s - saving mail anyway", error);
+                       e_error(qt->quota->event,
+                               "quota: %s - saving mail anyway", error);
        }
 
        return qbox->module_ctx.super.save_begin(ctx, input);
@@ -734,7 +747,8 @@ static void quota_root_set_namespace(struct quota_root *root,
                root->ns = mail_namespace_find_prefix(namespaces,
                                                      root->ns_prefix);
                if (root->ns == NULL && !silent_errors) {
-                       i_error("quota: Unknown namespace: %s",
+                       e_error(root->quota->event,
+                               "quota: Unknown namespace: %s",
                                root->ns_prefix);
                }
        }
@@ -744,7 +758,8 @@ static void quota_root_set_namespace(struct quota_root *root,
                ns = mail_namespace_find(namespaces, name);
                if ((ns->flags & NAMESPACE_FLAG_UNUSABLE) != 0 &&
                    !silent_errors)
-                       i_error("quota: Unknown namespace: %s", name);
+                       e_error(root->quota->event,
+                               "quota: Unknown namespace: %s", name);
        }
 }
 
index 224916d5a0aa87bb0f84f3d8bdca6c8f1306b260..95ce369cf75f27554a783015218fbf25dc6d1103 100644 (file)
@@ -130,8 +130,9 @@ void quota_root_recalculate_relative_rules(struct quota_root_settings *root_set,
                                              bytes_limit, 0);
        root_set->last_mail_max_extra_bytes = root_set->grace_rule.bytes_limit;
 
-       if (root_set->set->debug && root_set->set->initialized) {
-               i_debug("Quota root %s: Recalculated relative rules with "
+       if (root_set->set->initialized) {
+               e_debug(root_set->set->event,
+                       "Quota root %s: Recalculated relative rules with "
                        "bytes=%lld count=%lld. Now grace=%"PRIu64, root_set->name,
                        (long long)bytes_limit, (long long)count_limit,
                        root_set->last_mail_max_extra_bytes);
@@ -167,7 +168,7 @@ quota_rule_parse_limits(struct quota_root_settings *root_set,
                        }
                        value++;
                } else if (*value != '-' && relative_rule) {
-                       i_warning("quota root %s rule %s: "
+                       e_warning(root_set->set->event, "quota root %s rule %s: "
                                  "obsolete configuration for rule '%s' "
                                  "should be changed to '%s=+%s'",
                                  root_set->name, full_rule_def,
@@ -255,10 +256,9 @@ int quota_root_add_rule(struct quota_root_settings *root_set,
 
        if (strcmp(p, "ignore") == 0) {
                rule->ignore = TRUE;
-               if (root_set->set->debug) {
-                       i_debug("Quota rule: root=%s mailbox=%s ignored",
-                               root_set->name, mailbox_mask);
-               }
+               e_debug(root_set->set->event,
+                       "Quota rule: root=%s mailbox=%s ignored",
+                       root_set->name, mailbox_mask);
                return 0;
        }
 
@@ -280,22 +280,20 @@ int quota_root_add_rule(struct quota_root_settings *root_set,
        quota_root_recalculate_relative_rules(root_set,
                                              root_set->default_rule.bytes_limit,
                                              root_set->default_rule.count_limit);
-       if (root_set->set->debug) {
-               const char *rule_plus =
-                       rule == &root_set->default_rule ? "" : "+";
-
-               i_debug("Quota rule: root=%s mailbox=%s "
-                       "bytes=%s%lld%s messages=%s%lld%s",
-                       root_set->name, mailbox_mask,
-                       rule->bytes_limit > 0 ? rule_plus : "",
-                       (long long)rule->bytes_limit,
-                       rule->bytes_percent == 0 ? "" :
-                       t_strdup_printf(" (%u%%)", rule->bytes_percent),
-                       rule->count_limit > 0 ? rule_plus : "",
-                       (long long)rule->count_limit,
-                       rule->count_percent == 0 ? "" :
-                       t_strdup_printf(" (%u%%)", rule->count_percent));
-       }
+       const char *rule_plus =
+               rule == &root_set->default_rule ? "" : "+";
+
+       e_debug(root_set->set->event, "Quota rule: root=%s mailbox=%s "
+               "bytes=%s%lld%s messages=%s%lld%s",
+               root_set->name, mailbox_mask,
+               rule->bytes_limit > 0 ? rule_plus : "",
+               (long long)rule->bytes_limit,
+               rule->bytes_percent == 0 ? "" :
+               t_strdup_printf(" (%u%%)", rule->bytes_percent),
+               rule->count_limit > 0 ? rule_plus : "",
+               (long long)rule->count_limit,
+               rule->count_percent == 0 ? "" :
+               t_strdup_printf(" (%u%%)", rule->count_percent));
        return ret;
 }
 
@@ -342,18 +340,16 @@ int quota_root_add_warning_rule(struct quota_root_settings *root_set,
        quota_root_recalculate_relative_rules(root_set,
                                              root_set->default_rule.bytes_limit,
                                              root_set->default_rule.count_limit);
-       if (root_set->set->debug) {
-               i_debug("Quota warning: bytes=%"PRId64"%s "
-                       "messages=%"PRId64"%s reverse=%s command=%s",
-                       warning->rule.bytes_limit,
-                       warning->rule.bytes_percent == 0 ? "" :
-                       t_strdup_printf(" (%u%%)", warning->rule.bytes_percent),
-                       warning->rule.count_limit,
-                       warning->rule.count_percent == 0 ? "" :
-                       t_strdup_printf(" (%u%%)", warning->rule.count_percent),
-                       warning->reverse ? "yes" : "no",
-                       warning->command);
-       }
+       e_debug(root_set->set->event, "Quota warning: bytes=%"PRId64"%s "
+               "messages=%"PRId64"%s reverse=%s command=%s",
+               warning->rule.bytes_limit,
+               warning->rule.bytes_percent == 0 ? "" :
+               t_strdup_printf(" (%u%%)", warning->rule.bytes_percent),
+               warning->rule.count_limit,
+               warning->rule.count_percent == 0 ? "" :
+               t_strdup_printf(" (%u%%)", warning->rule.count_percent),
+               warning->reverse ? "yes" : "no",
+               warning->command);
        return 0;
 }
 
@@ -375,12 +371,10 @@ int quota_root_parse_grace(struct quota_root_settings *root_set,
        quota_rule_recalculate_relative_rules(&root_set->grace_rule,
                root_set->default_rule.bytes_limit, 0);
        root_set->last_mail_max_extra_bytes = root_set->grace_rule.bytes_limit;
-       if (root_set->set->debug) {
-               i_debug("Quota grace: root=%s bytes=%lld%s",
-                       root_set->name, (long long)root_set->grace_rule.bytes_limit,
-                       root_set->grace_rule.bytes_percent == 0 ? "" :
-                       t_strdup_printf(" (%u%%)", root_set->grace_rule.bytes_percent));
-       }
+       e_debug(root_set->set->event, "Quota grace: root=%s bytes=%lld%s",
+               root_set->name, (long long)root_set->grace_rule.bytes_limit,
+               root_set->grace_rule.bytes_percent == 0 ? "" :
+               t_strdup_printf(" (%u%%)", root_set->grace_rule.bytes_percent));
        return 0;
 }
 
index 084849d053d1b1dd878e31f87e599c250fd973f0..81cb3334a9c601f0b1cbd99763b33c18869a9747 100644 (file)
@@ -238,10 +238,8 @@ quota_root_settings_init(struct quota_settings *quota_set, const char *root_def,
        }
        root_set->args = p_strdup(quota_set->pool, args);
 
-       if (quota_set->debug) {
-               i_debug("Quota root: name=%s backend=%s args=%s",
-                       root_set->name, backend_name, args == NULL ? "" : args);
-       }
+       e_debug(quota_set->event, "Quota root: name=%s backend=%s args=%s",
+               root_set->name, backend_name, args == NULL ? "" : args);
 
        p_array_init(&root_set->rules, quota_set->pool, 4);
        p_array_init(&root_set->warning_rules, quota_set->pool, 4);
@@ -854,7 +852,8 @@ int quota_set_resource(struct quota_root *root, const char *name,
                        set.home_dir = NULL;
                if (dict_init(root->set->limit_set, &set,
                              &root->limit_set_dict, &error) < 0) {
-                       i_error("dict_init() failed: %s", error);
+                       e_error(root->quota->event,
+                               "dict_init() failed: %s", error);
                        *client_error_r = "Internal quota limit update error";
                        return -1;
                }
@@ -864,7 +863,8 @@ int quota_set_resource(struct quota_root *root, const char *name,
        key = t_strdup_printf(QUOTA_LIMIT_SET_PATH"%s", key);
        dict_set(trans, key, dec2str(value));
        if (dict_transaction_commit(&trans, &error) < 0) {
-               i_error("dict_transaction_commit() failed: %s", error);
+               e_error(root->quota->event,
+                       "dict_transaction_commit() failed: %s", error);
                *client_error_r = "Internal quota limit update error";
                return -1;
        }
@@ -1039,8 +1039,7 @@ static void quota_warning_execute(struct quota_root *root, const char *cmd,
 
        restrict_access_init(&set.restrict_set);
 
-       if (root->quota->set->debug)
-               i_debug("quota: Executing warning: %s (because %s)", cmd, reason);
+       e_debug(root->quota->event, "quota: Executing warning: %s (because %s)", cmd, reason);
 
        args = t_strsplit_spaces(cmd, " ");
        if (last_arg != NULL) {
@@ -1072,7 +1071,8 @@ static void quota_warning_execute(struct quota_root *root, const char *cmd,
 
        if (program_client_create(socket_path, args, &set, TRUE,
                                  &pc, &error) < 0) {
-               i_error("program_client_create(%s) failed: %s", socket_path,
+               e_error(root->quota->event,
+                       "program_client_create(%s) failed: %s", socket_path,
                        error);
                return;
        }
@@ -1097,13 +1097,15 @@ static void quota_warnings_execute(struct quota_transaction_context *ctx,
 
        if (quota_get_resource(root, "", QUOTA_NAME_STORAGE_BYTES,
                               &bytes_current, &bytes_limit, &error) == QUOTA_GET_RESULT_INTERNAL_ERROR) {
-               i_error("Failed to get quota resource "QUOTA_NAME_STORAGE_BYTES
+               e_error(root->quota->event,
+                       "Failed to get quota resource "QUOTA_NAME_STORAGE_BYTES
                        ": %s", error);
                return;
        }
        if (quota_get_resource(root, "", QUOTA_NAME_MESSAGES,
                               &count_current, &count_limit, &error) == QUOTA_GET_RESULT_INTERNAL_ERROR) {
-               i_error("Failed to get quota resource "QUOTA_NAME_MESSAGES
+               e_error(root->quota->event,
+                       "Failed to get quota resource "QUOTA_NAME_MESSAGES
                        ": %s", error);
                return;
        }
@@ -1165,7 +1167,8 @@ int quota_transaction_commit(struct quota_transaction_context **_ctx)
 
                        const char *error;
                        if (roots[i]->backend.v.update(roots[i], ctx, &error) < 0) {
-                               i_error("Failed to update quota for %s: %s",
+                               e_error(ctx->quota->event,
+                                       "Failed to update quota for %s: %s",
                                        mailbox_name, error);
                                ret = -1;
                        }
@@ -1199,10 +1202,8 @@ static bool quota_over_flag_init_root(struct quota_root *root,
        name = t_strconcat(root->set->set_name, "_over_script", NULL);
        *quota_over_script_r = mail_user_plugin_getenv(root->quota->user, name);
        if (*quota_over_script_r == NULL) {
-               if (root->quota->set->debug) {
-                       i_debug("quota: quota_over_flag check: "
-                               "%s unset - skipping", name);
-               }
+               e_debug(root->quota->event, "quota: quota_over_flag check: "
+                       "%s unset - skipping", name);
                return FALSE;
        }
 
@@ -1210,10 +1211,8 @@ static bool quota_over_flag_init_root(struct quota_root *root,
        name = t_strconcat(root->set->set_name, "_over_flag_value", NULL);
        flag_mask = mail_user_plugin_getenv(root->quota->user, name);
        if (flag_mask == NULL) {
-               if (root->quota->set->debug) {
-                       i_debug("quota: quota_over_flag check: "
-                               "%s unset - skipping", name);
-               }
+               e_debug(root->quota->event, "quota: quota_over_flag check: "
+                       "%s unset - skipping", name);
                return FALSE;
        }
 
@@ -1241,20 +1240,16 @@ static void quota_over_flag_check_root(struct quota_root *root)
        if (root->quota->user->session_create_time +
            QUOTA_OVER_FLAG_MAX_DELAY_SECS < ioloop_time) {
                /* userdb's quota_over_flag lookup is too old. */
-               if (root->quota->set->debug) {
-                       i_debug("quota: quota_over_flag check: "
-                               "Flag lookup time is too old - skipping");
-               }
+               e_debug(root->quota->event, "quota: quota_over_flag check: "
+                       "Flag lookup time is too old - skipping");
                return;
        }
        if (root->quota->user->session_restored) {
                /* we don't know whether the quota_over_script was executed
                   before hibernation. just assume that it was, so we don't
                   unnecessarily call it too often. */
-               if (root->quota->set->debug) {
-                       i_debug("quota: quota_over_flag check: "
-                               "Session was already hibernated - skipping");
-               }
+               e_debug(root->quota->event, "quota: quota_over_flag check: "
+                       "Session was already hibernated - skipping");
                return;
        }
        root->quota_over_flag_checked = TRUE;
@@ -1268,23 +1263,20 @@ static void quota_over_flag_check_root(struct quota_root *root)
                                         &limit, &error);
                if (ret == QUOTA_GET_RESULT_INTERNAL_ERROR) {
                        /* can't reliably verify this */
-                       i_error("quota: Quota %s lookup failed - can't verify quota_over_flag: %s",
+                       e_error(root->quota->event,
+                               "quota: Quota %s lookup failed - can't verify quota_over_flag: %s",
                                resources[i], error);
                        return;
                }
-               if (root->quota->set->debug) {
-                       i_debug("quota: quota_over_flag check: %s ret=%d value=%"PRIu64" limit=%"PRIu64,
-                               resources[i], ret, value, limit);
-               }
+               e_debug(root->quota->event, "quota: quota_over_flag check: %s ret=%d value=%"PRIu64" limit=%"PRIu64,
+                       resources[i], ret, value, limit);
                if (ret == QUOTA_GET_RESULT_LIMITED && value >= limit)
                        cur_overquota = TRUE;
        }
-       if (root->quota->set->debug) {
-               i_debug("quota: quota_over_flag=%d(%s) vs currently overquota=%d",
-                       quota_over_status ? 1 : 0,
-                       quota_over_flag == NULL ? "(null)" : quota_over_flag,
-                       cur_overquota ? 1 : 0);
-       }
+       e_debug(root->quota->event, "quota: quota_over_flag=%d(%s) vs currently overquota=%d",
+               quota_over_status ? 1 : 0,
+               quota_over_flag == NULL ? "(null)" : quota_over_flag,
+               cur_overquota ? 1 : 0);
        if (cur_overquota != quota_over_status) {
                quota_warning_execute(root, quota_over_script, quota_over_flag,
                                      "quota_over_flag mismatch");