*error_r = "quota count backend requires quota_vsizes=yes";
return -1;
}
+ event_set_append_log_prefix(root->backend.event, "quota-count: ");
+
root->auto_updating = TRUE;
return quota_root_default_init(root, args, error_r);
}
struct dict_settings set;
const char *username, *p, *error;
+ event_set_append_log_prefix(_root->backend.event, "quota-dict: ");
+
const struct quota_param_parser dict_params[] = {
{.param_name = "no-unset", .param_handler = handle_nounset_param},
quota_param_hidden, quota_param_ignoreunlimited, quota_param_noenforcing, quota_param_ns,
if (*username == '\0')
username = _root->quota->user->username;
- e_debug(_root->quota->event,
- "dict quota: user=%s, uri=%s, noenforcing=%d",
+ e_debug(_root->backend.event, "user=%s, uri=%s, noenforcing=%d",
username, args, _root->no_enforcing ? 1 : 0);
/* FIXME: we should use 64bit integer as datatype instead but before
dict_set(dt, DICT_QUOTA_CURRENT_BYTES_PATH, dec2str(bytes));
dict_set(dt, DICT_QUOTA_CURRENT_COUNT_PATH, dec2str(count));
- e_debug(root->root.quota->event, "dict quota: Quota recalculated: "
+ e_debug(root->root.backend.event, "Quota recalculated: "
"count=%"PRIu64" bytes=%"PRIu64, count, bytes);
dict_transaction_commit_async(&dt, NULL, NULL);
timeout_remove(&root->to_update);
if (dict_quota_count(root, TRUE, &value, &error)
<= QUOTA_GET_RESULT_INTERNAL_ERROR)
- e_error(root->root.quota->event,
- "quota-dict: Recalculation failed: %s", error);
+ e_error(root->root.backend.event,
+ "Recalculation failed: %s", error);
}
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) {
- e_error(root->root.quota->event,
- "dict quota: Quota update failed: %s "
+ e_error(root->root.backend.event,
+ "Quota update failed: %s "
"- Quota is now desynced", result->error);
}
}
const char **error_r)
{
root->auto_updating = TRUE;
+ event_set_append_log_prefix(root->backend.event, "quota-dirsize: ");
return quota_root_default_init(root, args, error_r);
}
{.param_name = NULL}
};
+ event_set_append_log_prefix(_root->backend.event, "quota-fs: ");
+
if (quota_parse_parameters(_root, &args, error_r, fs_params, TRUE) < 0)
return -1;
_root->auto_updating = TRUE;
i_free(root);
}
-static struct fs_quota_mountpoint *
-fs_quota_mountpoint_get(struct quota *quota, const char *dir)
+static struct fs_quota_mountpoint *fs_quota_mountpoint_get(const char *dir)
{
struct fs_quota_mountpoint *mount;
struct mountpoint point;
if (mount_type_is_nfs(mount)) {
if (strchr(mount->device_path, ':') == NULL) {
- e_error(quota->event,
- "quota-fs: %s is not a valid NFS device path",
+ e_error(quota_backend_fs.event,
+ "%s is not a valid NFS device path",
mount->device_path);
fs_quota_mountpoint_free(mount);
return NULL;
mount->path = i_strconcat(mount->mount_path, "/quotas", NULL);
mount->fd = open(mount->path, O_RDONLY);
if (mount->fd == -1 && errno != ENOENT)
- e_error(root->root.quota->event,
+ e_error(root->root.backend.event,
"open(%s) failed: %m", mount->path);
}
#endif
root->mount = mount;
- 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);
+ e_debug(root->root.backend.event, "fs quota add mailbox dir = %s", dir);
+ e_debug(root->root.backend.event, "fs quota block device = %s", mount->device_path);
+ e_debug(root->root.backend.event, "fs quota mount point = %s", mount->mount_path);
+ e_debug(root->root.backend.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);
root->storage_mount_path == NULL || root->mount != NULL)
continue;
- mount = fs_quota_mountpoint_get(quota, root->storage_mount_path);
+ mount = fs_quota_mountpoint_get(root->storage_mount_path);
if (mount != NULL) {
fs_quota_mount_init(root, mount,
root->storage_mount_path);
&dir))
mount = NULL;
else
- mount = fs_quota_mountpoint_get(quota, dir);
+ mount = fs_quota_mountpoint_get(dir);
if (mount != NULL) {
root = fs_quota_root_find_mountpoint(quota, mount);
if (root != NULL && root->mount == NULL)
path++;
}
- e_debug(root->root.quota->event, "quota-fs: host=%s, path=%s, uid=%s",
+ e_debug(root->root.backend.event, "host=%s, path=%s, uid=%s",
host, path, dec2str(root->uid));
/* clnt_create() polls for a while to establish a connection */
rquota_get_result(&result.getquota_rslt_u.gqr_rquota,
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" "
+ e_debug(root->root.backend.event, "uid=%s, bytes=%"PRIu64"/%"PRIu64" "
"files=%"PRIu64"/%"PRIu64,
dec2str(root->uid),
*bytes_value_r, *bytes_limit_r,
return 1;
}
case Q_NOQUOTA:
- e_debug(root->root.quota->event, "quota-fs: uid=%s, limit=unlimited",
+ e_debug(root->root.backend.event, "uid=%s, limit=unlimited",
dec2str(root->uid));
fs_quota_root_disable(root, FALSE);
return 0;
host = t_strdup_until(mount->device_path, path);
path++;
- e_debug(root->root.quota->event, "quota-fs: host=%s, path=%s, gid=%s",
+ e_debug(root->root.backend.event, "host=%s, path=%s, gid=%s",
host, path, dec2str(root->gid));
/* clnt_create() polls for a while to establish a connection */
rquota_get_result(&result.getquota_rslt_u.gqr_rquota,
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" "
+ e_debug(root->root.backend.event, "gid=%s, bytes=%"PRIu64"/%"PRIu64" "
"files=%"PRIu64"/%"PRIu64,
dec2str(root->gid),
*bytes_value_r, *bytes_limit_r,
return 1;
}
case Q_NOQUOTA:
- e_debug(root->root.quota->event, "quota-fs: gid=%s, limit=unlimited",
+ e_debug(root->root.backend.event, "gid=%s, limit=unlimited",
dec2str(root->gid));
fs_quota_root_disable(root, TRUE);
return 0;
return FALSE;
if (stat(mailbox_path, &mst) < 0) {
if (errno != ENOENT)
- e_error(_root->quota->event,
+ e_error(_root->backend.event,
"stat(%s) failed: %m", mailbox_path);
return FALSE;
}
if (stat(root->storage_mount_path, &rst) < 0) {
- e_debug(_root->quota->event, "stat(%s) failed: %m",
+ e_debug(_root->backend.event, "stat(%s) failed: %m",
root->storage_mount_path);
return FALSE;
}
match = CMP_DEV_T(mst.st_dev, rst.st_dev);
- e_debug(_root->quota->event, "box=%s mount=%s match=%s", mailbox_path,
+ e_debug(_root->backend.event, "box=%s mount=%s match=%s", mailbox_path,
root->storage_mount_path, match ? "yes" : "no");
return match;
}
};
_root->auto_updating = TRUE;
+ event_set_append_log_prefix(root->root.backend.event, "quota-imapc: ");
if (quota_parse_parameters(_root, &args, error_r, imapc_params, TRUE) < 0)
return -1;
/* non-imapc namespace, skip */
if ((storage->class_flags &
MAIL_STORAGE_CLASS_FLAG_NOQUOTA) == 0) {
- e_warning(root->root.quota->event,
- "quota: Namespace '%s' is not imapc, "
+ e_warning(root->root.backend.event,
+ "Namespace '%s' is not imapc, "
"skipping for imapc quota",
root->imapc_ns->prefix);
}
const struct imapc_quota_refresh_root *refresh_root;
if (array_count(&refresh->roots) == 0) {
- e_error(quota->event,
- "quota: imapc didn't return any QUOTA results");
+ e_error(quota_backend_imapc.event,
+ "imapc didn't return any QUOTA results");
return;
}
/* use the first quota root for everything */
}
if ((capa & IMAPC_CAPABILITY_QUOTA) == 0) {
/* no QUOTA capability - disable quota */
- e_warning(root->root.quota->event,
- "quota: Remote IMAP server doesn't support QUOTA - disabling");
+ e_warning(root->root.backend.event,
+ "Remote IMAP server doesn't support QUOTA - disabling");
root->client = NULL;
return 0;
}
/* 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) {
- e_error(ctx->root->root.quota->event,
+ e_error(ctx->root->root.backend.event,
"stat(%s) failed: %m", str_c(ctx->path));
ctx->state = 0;
}
perm.file_create_gid,
perm.file_create_gid_origin) < 0 &&
errno != EEXIST) {
- e_error(root->root.quota->event,
+ e_error(root->root.backend.event,
"mkdir_parents(%s) failed: %m", dir);
return -1;
}
perm.file_create_gid_origin);
}
if (fd == -1) {
- e_error(root->root.quota->event,
+ e_error(root->root.backend.event,
"safe_mkstemp(%s) failed: %m", path);
return -1;
}
str_printfa(str, "\n%"PRIu64" %"PRIu64"\n",
root->total_bytes, root->total_count);
if (write_full(fd, str_data(str), str_len(str)) < 0) {
- e_error(_root->quota->event,
+ e_error(root->root.backend.event,
"write_full(%s) failed: %m", str_c(temp_path));
i_close_fd(&fd);
i_unlink(str_c(temp_path));
i_close_fd(&fd);
if (rename(str_c(temp_path), path) < 0) {
- e_error(_root->quota->event,
+ e_error(root->root.backend.event,
"rename(%s, %s) failed: %m", str_c(temp_path), path);
i_unlink_if_exists(str_c(temp_path));
return -1;
if (unlink(root->maildirsize_path) < 0 &&
errno != ENOENT && errno != ESTALE)
- e_error(root->root.quota->event,
+ e_error(root->root.backend.event,
"unlink(%s) failed: %m", root->maildirsize_path);
}
/* non-maildir namespace, skip */
if ((storage->class_flags &
MAIL_STORAGE_CLASS_FLAG_NOQUOTA) == 0) {
- e_warning(root->root.quota->event,
+ e_warning(root->root.backend.event,
"Namespace '%s' is not Maildir, "
"skipping for Maildir++ quota",
root->maildirsize_ns->prefix);
if (errno == ESTALE) {
/* deleted/replaced already, ignore */
} else {
- e_error(root->root.quota->event,
+ e_error(root->root.backend.event,
"write_full(%s) failed: %m",
root->maildirsize_path);
}
if (close(root->fd) < 0) {
ret = -1;
if (errno != ESTALE)
- e_error(root->root.quota->event,
+ e_error(root->root.backend.event,
"close(%s) failed: %m", root->maildirsize_path);
}
root->fd = -1;
static int maildir_quota_init(struct quota_root *_root, const char *args,
const char **error_r)
{
+ event_set_append_log_prefix(_root->backend.event, "quota-maildir: ");
return quota_root_default_init(_root, args, error_r);
}
it doesn't exist. */
if (maildirquota_refresh(root, &recalculated, &error) < 0) {
*error_r = t_strdup_printf(
- "quota-maildir: Could not update storage usage data: %s",
+ "Could not update storage usage data: %s",
error);
return -1;
}
we wanted to do. */
} else if (root->fd == -1) {
if (maildirsize_recalculate(root, &error) < 0)
- e_error(_root->quota->event,
- "quota-maildir: %s", error);
+ e_error(root->root.backend.event, "%s", error);
} else if (ctx->recalculate != QUOTA_RECALCULATE_DONT) {
i_close_fd(&root->fd);
if (maildirsize_recalculate(root, &error) < 0)
- e_error(_root->quota->event,
- "quota-maildir: %s", error);
+ e_error(root->root.backend.event, "%s", error);
} else if (maildirsize_update(root, ctx->count_used, ctx->bytes_used) < 0) {
i_close_fd(&root->fd);
maildirsize_rebuild_later(root);
struct quota_backend {
/* quota backends equal if backend1.name == backend2.name */
const char *name;
+ struct event *event;
struct quota_backend_vfuncs v;
};
if (root->limit_set_dict != NULL)
dict_deinit(&root->limit_set_dict);
+ event_unref(&root->backend.event);
root->backend.v.deinit(root);
pool_unref(&pool);
}
sizeof(void *), 10);
if (root->backend.v.init != NULL) {
+ root->backend.event = event_create(quota->event);
+ event_set_forced_debug(root->backend.event, root->quota->set->debug);
+
if (root->backend.v.init(root, root_set->args, error_r) < 0) {
*error_r = t_strdup_printf("%s quota init failed: %s",
root->backend.name, *error_r);
+
+ event_unref(&root->backend.event);
return -1;
}
} else {