]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
quota: Add error_r to get_resource() of quota_backend_vfuncs
authorMartti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
Tue, 17 Oct 2017 07:12:48 +0000 (10:12 +0300)
committerTimo Sirainen <tss@dovecot.fi>
Thu, 19 Oct 2017 13:43:44 +0000 (16:43 +0300)
src/plugins/quota/quota-count.c
src/plugins/quota/quota-dict.c
src/plugins/quota/quota-dirsize.c
src/plugins/quota/quota-fs.c
src/plugins/quota/quota-imapc.c
src/plugins/quota/quota-maildir.c
src/plugins/quota/quota-private.h
src/plugins/quota/quota.c

index 9501ae7a8d205e43ef384bb9b3d1349b07894c46..a034126910b9468dece6b4bbd479c20ac505f1ea 100644 (file)
@@ -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;
index 262c04a904767a6b00c0bd3aa671e666b06d8763..ece6ceea891cc8d3cd03c9b01e15ee505333c699 100644 (file)
@@ -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;
@@ -176,6 +177,8 @@ dict_quota_get_resource(struct quota_root *_root,
                                               value_r);
                }
        }
+       if (ret < 0)
+               *error_r = "quota-dict failed";
        return ret;
 }
 
index c2faf1eebf6b65c953fd32098e60b3c324a9379c..489420b8418140913ace17acfc33498d647bd3fb 100644 (file)
@@ -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;
 
@@ -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;
 }
 
index 7d46fd9dee599ad11808825f2865da02503bdbbd..3e4119c11c626f1992577d9a5a6d448ace89383d 100644 (file)
@@ -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;
@@ -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;
 
index 3799d5d9048fea76c3448174cc40e766ac1089c0..6e8deb858c648e393344149285450e4677a54b99 100644 (file)
@@ -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;
index c39a659953dd9585f337d84fba54483e0e2a8bac..d279222ee8d4c6e4cbc3bd847246160450d3bbc5 100644 (file)
@@ -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;
index 7274a49c8acee5888d253005fe446c1b91e157fe..2c14ce43533d567e94667be6d3a2e90fa3680f03 100644 (file)
@@ -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);
index a94189f23d4e5e69714a10e11a42c820ff70578e..c5df7f5384253c5f55d1c0078bdc18059fb7820c 100644 (file)
@@ -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(
@@ -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) {