[dovecot-cvs] dovecot/src/plugins/quota quota-dict.c, 1.16, 1.17 quota-dirsize.c, 1.15, 1.16 quota-fs.c, 1.25, 1.26 quota-maildir.c, 1.16, 1.17 quota.c, 1.15, 1.16 quota.h, 1.7, 1.8

tss at dovecot.org tss at dovecot.org
Wed Nov 22 17:23:12 UTC 2006


Update of /var/lib/cvs/dovecot/src/plugins/quota
In directory talvi:/tmp/cvs-serv5631

Modified Files:
	quota-dict.c quota-dirsize.c quota-fs.c quota-maildir.c 
	quota.c quota.h 
Log Message:
Bytes and kilobytes were somewhat mixed up everywhere. Also fixes a
compiling problem.



Index: quota-dict.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/quota/quota-dict.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- quota-dict.c	30 Jul 2006 18:49:39 -0000	1.16
+++ quota-dict.c	22 Nov 2006 17:23:09 -0000	1.17
@@ -65,7 +65,7 @@
 dict_quota_root_get_resources(struct quota_root *root __attr_unused__)
 {
 	static const char *resources[] = {
-		QUOTA_NAME_STORAGE, QUOTA_NAME_MESSAGES, NULL
+		QUOTA_NAME_STORAGE_KILOBYTES, QUOTA_NAME_MESSAGES, NULL
 	};
 
 	return resources;
@@ -79,11 +79,11 @@
 	const char *value;
 	int ret;
 
-	if (strcmp(name, QUOTA_NAME_STORAGE) == 0) {
+	if (strcmp(name, QUOTA_NAME_STORAGE_BYTES) == 0) {
 		t_push();
 		ret = dict_lookup(root->dict, unsafe_data_stack_pool,
 				  DICT_QUOTA_CURRENT_BYTES_PATH, &value);
-		*value_r = ret <= 0 ? 0 : strtoull(value, NULL, 10) / 1024;
+		*value_r = ret <= 0 ? 0 : strtoull(value, NULL, 10);
 		t_pop();
 	} else if (strcmp(name, QUOTA_NAME_MESSAGES) == 0) {
 		t_push();

Index: quota-dirsize.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/quota/quota-dirsize.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- quota-dirsize.c	10 Sep 2006 12:48:35 -0000	1.15
+++ quota-dirsize.c	22 Nov 2006 17:23:09 -0000	1.16
@@ -34,7 +34,7 @@
 static const char *const *
 dirsize_quota_root_get_resources(struct quota_root *root __attr_unused__)
 {
-	static const char *resources[] = { QUOTA_NAME_STORAGE, NULL };
+	static const char *resources[] = { QUOTA_NAME_STORAGE_KILOBYTES, NULL };
 
 	return resources;
 }
@@ -166,6 +166,7 @@
 	}
 
 	/* now sum up the found paths */
+	*value_r = 0;
 	count_paths = array_get(&paths, &count);
 	for (i = 0; i < count; i++) {
 		if (get_usage(count_paths[i].path, count_paths[i].is_file,
@@ -183,13 +184,12 @@
 dirsize_quota_get_resource(struct quota_root *_root, const char *name,
 			   uint64_t *value_r, uint64_t *limit __attr_unused__)
 {
-	if (strcasecmp(name, QUOTA_NAME_STORAGE) != 0)
+	if (strcasecmp(name, QUOTA_NAME_STORAGE_BYTES) != 0)
 		return 0;
 
 	if (get_quota_root_usage(_root, value_r) < 0)
 		return -1;
 
-	*value_r /= 1024;
 	return 1;
 }
 

Index: quota-fs.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/quota/quota-fs.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- quota-fs.c	17 Sep 2006 18:10:32 -0000	1.25
+++ quota-fs.c	22 Nov 2006 17:23:09 -0000	1.26
@@ -184,7 +184,7 @@
 static const char *const *
 fs_quota_root_get_resources(struct quota_root *root __attr_unused__)
 {
-	static const char *resources[] = { QUOTA_NAME_STORAGE, NULL };
+	static const char *resources[] = { QUOTA_NAME_STORAGE_KILOBYTES, NULL };
 
 	return resources;
 }
@@ -202,7 +202,8 @@
 	*value_r = 0;
 	*limit_r = 0;
 
-	if (strcasecmp(name, QUOTA_NAME_STORAGE) != 0 || root->mount == NULL)
+	if (strcasecmp(name, QUOTA_NAME_STORAGE_BYTES) != 0 ||
+	    root->mount == NULL)
 		return 0;
 
 #if defined (HAVE_QUOTACTL) && defined(HAVE_SYS_QUOTA_H)
@@ -221,8 +222,8 @@
 		}
 
 		/* values always returned in 512 byte blocks */
-		*value_r = xdqblk.d_bcount >> 1;
-		*limit_r = xdqblk.d_blk_softlimit >> 1;
+		*value_r = xdqblk.d_bcount * 512;
+		*limit_r = xdqblk.d_blk_softlimit * 512;
 	} else
 #endif
 	{
@@ -241,8 +242,8 @@
 			return -1;
 		}
 
-		*value_r = dqblk.dqb_curblocks / 1024;
-		*limit_r = dqblk.dqb_bsoftlimit;
+		*value_r = dqblk.dqb_curblocks;
+		*limit_r = dqblk.dqb_bsoftlimit * 1024;
 	}
 #elif defined(HAVE_QUOTACTL)
 	/* BSD, AIX */
@@ -252,8 +253,8 @@
 			root->mount->mount_path);
 		return -1;
 	}
-	*value_r = (uint64_t)dqblk.dqb_curblocks * 1024 / DEV_BSIZE;
-	*limit_r = (uint64_t)dqblk.dqb_bsoftlimit * 1024 / DEV_BSIZE;
+	*value_r = (uint64_t)dqblk.dqb_curblocks * DEV_BSIZE;
+	*limit_r = (uint64_t)dqblk.dqb_bsoftlimit * DEV_BSIZE;
 #else
 	/* Solaris */
 	if (root->mount->fd == -1)
@@ -266,8 +267,8 @@
 		i_error("ioctl(%s, Q_QUOTACTL) failed: %m", root->mount->path);
 		return -1;
 	}
-	*value_r = (uint64_t)dqblk.dqb_curblocks * 1024 / DEV_BSIZE;
-	*limit_r = (uint64_t)dqblk.dqb_bsoftlimit * 1024 / DEV_BSIZE;
+	*value_r = (uint64_t)dqblk.dqb_curblocks * DEV_BSIZE;
+	*limit_r = (uint64_t)dqblk.dqb_bsoftlimit * DEV_BSIZE;
 #endif
 	return 1;
 }

Index: quota-maildir.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/quota/quota-maildir.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- quota-maildir.c	16 Nov 2006 00:17:18 -0000	1.16
+++ quota-maildir.c	22 Nov 2006 17:23:09 -0000	1.17
@@ -134,8 +134,7 @@
 	ctx = i_new(struct maildir_list_context, 1);
 	ctx->storage = storage;
 	ctx->path = str_new(default_pool, 512);
-	ctx->iter = mailbox_list_iter_init(mail_storage_get_list(storage),
-					   "", "*",
+	ctx->iter = mailbox_list_iter_init(mail_storage_get_list(storage), "*",
 					   MAILBOX_LIST_ITER_FAST_FLAGS);
 	return ctx;
 }
@@ -591,7 +590,7 @@
 maildir_quota_root_get_resources(struct quota_root *root __attr_unused__)
 {
 	static const char *resources_both[] = {
-		QUOTA_NAME_STORAGE,
+		QUOTA_NAME_STORAGE_KILOBYTES,
 		QUOTA_NAME_MESSAGES,
 		NULL
 	};
@@ -608,8 +607,8 @@
 	if (maildirquota_refresh(root) < 0)
 		return -1;
 
-	if (strcmp(name, QUOTA_NAME_STORAGE) == 0)
-		*value_r = root->total_bytes / 1024;
+	if (strcmp(name, QUOTA_NAME_STORAGE_BYTES) == 0)
+		*value_r = root->total_bytes;
 	else if (strcmp(name, QUOTA_NAME_MESSAGES) == 0)
 		*value_r = root->total_count;
 	else

Index: quota.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/quota/quota.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- quota.c	10 Sep 2006 12:48:35 -0000	1.15
+++ quota.c	22 Nov 2006 17:23:09 -0000	1.16
@@ -300,7 +300,8 @@
 
 	for (; iter->i < count; iter->i++) {
 		ret = quota_get_resource(roots[iter->i], "",
-					 QUOTA_NAME_STORAGE, &value, &limit);
+					 QUOTA_NAME_STORAGE_KILOBYTES,
+					 &value, &limit);
 		if (ret == 0) {
 			ret = quota_get_resource(roots[iter->i], "",
 						 QUOTA_NAME_MESSAGES,
@@ -348,11 +349,17 @@
 		       const char *name, uint64_t *value_r, uint64_t *limit_r)
 {
 	uint64_t bytes_limit, count_limit;
+	bool kilobytes = FALSE;
 	int ret;
 
+	if (strcmp(name, QUOTA_NAME_STORAGE_KILOBYTES) == 0) {
+		name = QUOTA_NAME_STORAGE_BYTES;
+		kilobytes = TRUE;
+	}
+
 	(void)quota_root_get_rule_limits(root, mailbox_name,
 					 &bytes_limit, &count_limit);
-	if (strcmp(name, QUOTA_NAME_STORAGE) == 0)
+	if (strcmp(name, QUOTA_NAME_STORAGE_BYTES) == 0)
 		*limit_r = bytes_limit;
 	else if (strcmp(name, QUOTA_NAME_MESSAGES) == 0)
 		*limit_r = count_limit;
@@ -360,6 +367,10 @@
 		*limit_r = 0;
 
 	ret = root->backend.v.get_resource(root, name, value_r, limit_r);
+	if (kilobytes && ret > 0) {
+		*value_r /= 1024;
+		*limit_r /= 1024;
+	}
 	return ret <= 0 ? ret :
 		(*limit_r == 0 ? 0 : 1);
 }
@@ -397,7 +408,8 @@
 	roots = array_get(&quota->roots, &count);
 	for (i = 0; i < count; i++) {
 		ret = quota_get_resource(roots[i], mailbox_name,
-					 QUOTA_NAME_STORAGE, &current, &limit);
+					 QUOTA_NAME_STORAGE_BYTES,
+					 &current, &limit);
 		if (ret > 0) {
 			left = limit < current ? 0 : limit - current;
 			if (ctx->bytes_left > left)

Index: quota.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/quota/quota.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- quota.h	30 Jul 2006 18:32:07 -0000	1.7
+++ quota.h	22 Nov 2006 17:23:09 -0000	1.8
@@ -5,7 +5,9 @@
 struct mailbox;
 
 /* Message storage size kilobytes. */
-#define QUOTA_NAME_STORAGE "STORAGE"
+#define QUOTA_NAME_STORAGE_KILOBYTES "STORAGE"
+/* Message storage size bytes. This is used only internally. */
+#define QUOTA_NAME_STORAGE_BYTES "STORAGE_BYTES"
 /* Number of messages. */
 #define QUOTA_NAME_MESSAGES "MESSAGES"
 



More information about the dovecot-cvs mailing list