From: Timo Sirainen Date: Thu, 31 Oct 2019 17:27:15 +0000 (+0200) Subject: quota: Use event based logging X-Git-Tag: 2.3.13~252 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d9f9d0862441111a471a1f526f725590a295bec2;p=thirdparty%2Fdovecot%2Fcore.git quota: Use event based logging --- diff --git a/src/plugins/quota/quota-dict.c b/src/plugins/quota/quota-dict.c index 9aa527e712..690dc76881 100644 --- a/src/plugins/quota/quota-dict.c +++ b/src/plugins/quota/quota-dict.c @@ -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); } } diff --git a/src/plugins/quota/quota-fs.c b/src/plugins/quota/quota-fs.c index c2c7221ca0..e519b4fbaf 100644 --- a/src/plugins/quota/quota-fs.c +++ b/src/plugins/quota/quota-fs.c @@ -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; } diff --git a/src/plugins/quota/quota-imapc.c b/src/plugins/quota/quota-imapc.c index 6abdfdc698..870e1b6044 100644 --- a/src/plugins/quota/quota-imapc.c +++ b/src/plugins/quota/quota-imapc.c @@ -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; } diff --git a/src/plugins/quota/quota-maildir.c b/src/plugins/quota/quota-maildir.c index 015bab841e..b3391e5a80 100644 --- a/src/plugins/quota/quota-maildir.c +++ b/src/plugins/quota/quota-maildir.c @@ -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); diff --git a/src/plugins/quota/quota-storage.c b/src/plugins/quota/quota-storage.c index 7afb5fa3b7..7eb4557482 100644 --- a/src/plugins/quota/quota-storage.c +++ b/src/plugins/quota/quota-storage.c @@ -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); } } diff --git a/src/plugins/quota/quota-util.c b/src/plugins/quota/quota-util.c index 224916d5a0..95ce369cf7 100644 --- a/src/plugins/quota/quota-util.c +++ b/src/plugins/quota/quota-util.c @@ -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; } diff --git a/src/plugins/quota/quota.c b/src/plugins/quota/quota.c index 084849d053..81cb3334a9 100644 --- a/src/plugins/quota/quota.c +++ b/src/plugins/quota/quota.c @@ -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");