dovecot: Use quota roots with mount path even if we never see a ...

dovecot at dovecot.org dovecot at dovecot.org
Tue Aug 7 01:59:47 EEST 2007


details:   http://hg.dovecot.org/dovecot/rev/8ab01c7b2927
changeset: 6204:8ab01c7b2927
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Aug 07 01:59:43 2007 +0300
description:
Use quota roots with mount path even if we never see a storage for them.
This is useful if e.g. INBOX is in different filesystem then other mails.

diffstat:

1 file changed, 53 insertions(+), 26 deletions(-)
src/plugins/quota/quota-fs.c |   79 ++++++++++++++++++++++++++++--------------

diffs (103 lines):

diff -r d93098194ed4 -r 8ab01c7b2927 src/plugins/quota/quota-fs.c
--- a/src/plugins/quota/quota-fs.c	Tue Aug 07 01:51:50 2007 +0300
+++ b/src/plugins/quota/quota-fs.c	Tue Aug 07 01:59:43 2007 +0300
@@ -182,14 +182,58 @@ fs_quota_root_find_mountpoint(struct quo
 	return empty;
 }
 
+static void fs_quota_mount_init(struct fs_quota_root *root,
+				struct fs_quota_mountpoint *mount)
+{
+	struct quota_root *const *roots;
+	unsigned int i, count;
+
+#ifdef FS_QUOTA_SOLARIS
+	if (mount->path == NULL) {
+		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);
+	}
+#endif
+	root->mount = mount;
+
+	/* if there are more unused quota roots, copy this mount to them */
+	roots = array_get(&root->root.quota->roots, &count);
+	for (i = 0; i < count; i++) {
+		struct fs_quota_root *root = (struct fs_quota_root *)roots[i];
+		if (QUOTA_ROOT_MATCH(root, mount) && root->mount == NULL) {
+			mount->refcount++;
+			root->mount = mount;
+		}
+	}
+}
+
+static void fs_quota_add_missing_mounts(struct quota *quota)
+{
+	struct fs_quota_mountpoint *mount;
+	struct quota_root *const *roots;
+	unsigned int i, count;
+
+	roots = array_get(&quota->roots, &count);
+	for (i = 0; i < count; i++) {
+		struct fs_quota_root *root = (struct fs_quota_root *)roots[i];
+
+		if (root->root.backend.name != quota_backend_fs.name ||
+		    root->storage_mount_path == NULL || root->mount != NULL)
+			continue;
+
+		mount = fs_quota_mountpoint_get(root->storage_mount_path);
+		fs_quota_mount_init(root, mount);
+	}
+}
+
 static void fs_quota_storage_added(struct quota *quota,
 				   struct mail_storage *storage)
 {
 	struct fs_quota_mountpoint *mount;
 	struct fs_quota_root *root;
-	struct quota_root *const *roots;
 	const char *dir;
-	unsigned int i, count;
 	bool is_file;
 
 	dir = mail_storage_get_mailbox_path(storage, "", &is_file);
@@ -201,31 +245,14 @@ static void fs_quota_storage_added(struc
 	}
 
 	root = fs_quota_root_find_mountpoint(quota, mount);
-	if (root == NULL || (root != NULL && root->mount != NULL)) {
-		/* already exists */
+	if (root != NULL && root->mount == NULL)
+		fs_quota_mount_init(root, mount);
+	else
 		fs_quota_mountpoint_free(mount);
-		return;
-	}
-
-#ifdef FS_QUOTA_SOLARIS
-	if (mount->path == NULL) {
-		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);
-	}
-#endif
-	root->mount = mount;
-
-	/* if there are more unused quota roots, copy this mount to them */
-	roots = array_get(&quota->roots, &count);
-	for (i = 0; i < count; i++) {
-		struct fs_quota_root *root = (struct fs_quota_root *)roots[i];
-		if (QUOTA_ROOT_MATCH(root, mount) && root->mount == NULL) {
-			mount->refcount++;
-			root->mount = mount;
-		}
-	}
+
+	/* we would actually want to do this only once after all quota roots
+	   are created, but there's no way to do this right now */
+	fs_quota_add_missing_mounts(quota);
 }
 
 static const char *const *


More information about the dovecot-cvs mailing list