Skip to content

Commit

Permalink
quota: Add error_r to get_resource() of quota_backend_vfuncs
Browse files Browse the repository at this point in the history
  • Loading branch information
mrannanj authored and Timo Sirainen committed Oct 19, 2017
1 parent e83a11e commit a525be1
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 14 deletions.
7 changes: 5 additions & 2 deletions src/plugins/quota/quota-count.c
Expand Up @@ -228,13 +228,16 @@ count_quota_root_get_resources(struct quota_root *root ATTR_UNUSED)

static int
count_quota_get_resource(struct quota_root *_root,
const char *name, uint64_t *value_r)
const char *name, uint64_t *value_r,
const char **error_r)
{
struct count_quota_root *root = (struct count_quota_root *)_root;
uint64_t bytes, count;

if (quota_count_cached(root, &bytes, &count) < 0)
if (quota_count_cached(root, &bytes, &count) < 0) {
*error_r = "quota-count failed";
return -1;
}

if (strcmp(name, QUOTA_NAME_STORAGE_BYTES) == 0)
*value_r = bytes;
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/quota/quota-dict.c
Expand Up @@ -140,7 +140,8 @@ dict_quota_count(struct dict_quota_root *root,

static int
dict_quota_get_resource(struct quota_root *_root,
const char *name, uint64_t *value_r)
const char *name, uint64_t *value_r,
const char **error_r)
{
struct dict_quota_root *root = (struct dict_quota_root *)_root;
bool want_bytes;
Expand Down Expand Up @@ -176,6 +177,8 @@ dict_quota_get_resource(struct quota_root *_root,
value_r);
}
}
if (ret < 0)
*error_r = "quota-dict failed";
return ret;
}

Expand Down
5 changes: 4 additions & 1 deletion src/plugins/quota/quota-dirsize.c
Expand Up @@ -192,7 +192,7 @@ get_quota_root_usage(struct quota_root *root, uint64_t *value_r)

static int
dirsize_quota_get_resource(struct quota_root *_root, const char *name,
uint64_t *value_r)
uint64_t *value_r, const char **error_r)
{
int ret;

Expand All @@ -201,6 +201,9 @@ dirsize_quota_get_resource(struct quota_root *_root, const char *name,

ret = get_quota_root_usage(_root, value_r);

if (ret < 0)
*error_r = "quota-dirsize failed";

return ret < 0 ? -1 : 1;
}

Expand Down
4 changes: 3 additions & 1 deletion src/plugins/quota/quota-fs.c
Expand Up @@ -856,7 +856,7 @@ static bool fs_quota_match_box(struct quota_root *_root, struct mailbox *box)

static int
fs_quota_get_resource(struct quota_root *_root, const char *name,
uint64_t *value_r)
uint64_t *value_r, const char **error_r)
{
struct fs_quota_root *root = (struct fs_quota_root *)_root;
uint64_t bytes_value, count_value;
Expand Down Expand Up @@ -887,6 +887,8 @@ fs_quota_get_resource(struct quota_root *_root, const char *name,
&count_value, &count_limit);
}
}
if (ret < 0)
*error_r = "quota-fs failed";
if (ret <= 0)
return ret;

Expand Down
6 changes: 4 additions & 2 deletions src/plugins/quota/quota-imapc.c
Expand Up @@ -423,12 +423,14 @@ imapc_quota_root_get_resources(struct quota_root *root ATTR_UNUSED)

static int
imapc_quota_get_resource(struct quota_root *_root, const char *name,
uint64_t *value_r)
uint64_t *value_r, const char **error_r)
{
struct imapc_quota_root *root = (struct imapc_quota_root *)_root;

if (imapc_quota_refresh(root) < 0)
if (imapc_quota_refresh(root) < 0) {
*error_r = "quota-imapc failed";
return -1;
}

if (strcmp(name, QUOTA_NAME_STORAGE_BYTES) == 0)
*value_r = root->bytes_last;
Expand Down
6 changes: 4 additions & 2 deletions src/plugins/quota/quota-maildir.c
Expand Up @@ -836,13 +836,15 @@ maildir_quota_root_get_resources(struct quota_root *root ATTR_UNUSED)

static int
maildir_quota_get_resource(struct quota_root *_root, const char *name,
uint64_t *value_r)
uint64_t *value_r, const char **error_r)
{
struct maildir_quota_root *root = (struct maildir_quota_root *)_root;
bool recalculated;

if (maildirquota_refresh(root, &recalculated) < 0)
if (maildirquota_refresh(root, &recalculated) < 0) {
*error_r = "quota-maildir failed";
return -1;
}

if (strcmp(name, QUOTA_NAME_STORAGE_BYTES) == 0) {
*value_r = root->total_bytes;
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/quota/quota-private.h
Expand Up @@ -69,7 +69,8 @@ struct quota_backend_vfuncs {
/* Returns 1 if value was returned, 0 if resource name doesn't exist,
-1 if internal error. */
int (*get_resource)(struct quota_root *root,
const char *name, uint64_t *value_r);
const char *name, uint64_t *value_r,
const char **error_r);

int (*update)(struct quota_root *root,
struct quota_transaction_context *ctx);
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/quota/quota.c
Expand Up @@ -772,11 +772,12 @@ quota_get_resource(struct quota_root *root, const char *mailbox_name,

/* Get the value first. This call may also update quota limits if
they're defined externally. */
ret = root->backend.v.get_resource(root, name, value_r);
const char *error;
ret = root->backend.v.get_resource(root, name, value_r, &error);
if (ret < 0) {
*error_r = t_strdup_printf(
"Could not get %s from quota backend for mailbox %s",
name, mailbox_name);
"Could not get %s from quota backend for mailbox %s: %s",
name, mailbox_name, error);
return QUOTA_GET_RESULT_INTERNAL_ERROR;
} else if (ret == 0) {
*error_r = t_strdup_printf(
Expand All @@ -785,7 +786,6 @@ quota_get_resource(struct quota_root *root, const char *mailbox_name,
return QUOTA_GET_RESULT_UNKNOWN_RESOURCE;
}

const char *error;
if (quota_root_get_rule_limits(root, mailbox_name,
&bytes_limit, &count_limit,
&ignored, &error) < 0) {
Expand Down

0 comments on commit a525be1

Please sign in to comment.