dovecot-2.0: mdbox: Saving now closes newly created files if the...

dovecot at dovecot.org dovecot at dovecot.org
Tue Feb 9 18:55:09 EET 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/9c68c8d42ff2
changeset: 10683:9c68c8d42ff2
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Feb 09 18:54:34 2010 +0200
description:
mdbox: Saving now closes newly created files if they become full.
Newly created files also aren't locked anymore, they're not visible to
others anyway until map index is updated.

diffstat:

3 files changed, 16 insertions(+), 22 deletions(-)
src/lib-storage/index/dbox-common/dbox-file.c |    2 +-
src/lib-storage/index/dbox-multi/mdbox-file.c |   15 +--------------
src/lib-storage/index/dbox-multi/mdbox-map.c  |   21 ++++++++++++++-------

diffs (80 lines):

diff -r 9f0c4800cb13 -r 9c68c8d42ff2 src/lib-storage/index/dbox-common/dbox-file.c
--- a/src/lib-storage/index/dbox-common/dbox-file.c	Tue Feb 09 18:34:33 2010 +0200
+++ b/src/lib-storage/index/dbox-common/dbox-file.c	Tue Feb 09 18:54:34 2010 +0200
@@ -264,7 +264,7 @@ int dbox_file_try_lock(struct dbox_file 
 
 void dbox_file_unlock(struct dbox_file *file)
 {
-	i_assert(!file->appending);
+	i_assert(!file->appending || file->lock == NULL);
 
 	if (file->lock != NULL)
 		file_unlock(&file->lock);
diff -r 9f0c4800cb13 -r 9c68c8d42ff2 src/lib-storage/index/dbox-multi/mdbox-file.c
--- a/src/lib-storage/index/dbox-multi/mdbox-file.c	Tue Feb 09 18:34:33 2010 +0200
+++ b/src/lib-storage/index/dbox-multi/mdbox-file.c	Tue Feb 09 18:54:34 2010 +0200
@@ -104,24 +104,11 @@ static int mdbox_file_create(struct dbox
 static int mdbox_file_create(struct dbox_file *file)
 {
 	bool create_parents;
-	int ret;
 
 	create_parents = dbox_file_is_in_alt(file);
 	file->fd = file->storage->v.
 		file_create_fd(file, file->cur_path, create_parents);
-
-	/* even though we don't need it locked while writing to it, by the
-	   time we rename() it it needs to be locked. so we might as well do
-	   it here. */
-	if ((ret = dbox_file_try_lock(file)) <= 0) {
-		if (ret < 0)
-			return -1;
-		mail_storage_set_critical(&file->storage->storage,
-			"dbox: Couldn't lock created file: %s",
-			file->cur_path);
-		return -1;
-	}
-	return 0;
+	return file->fd == -1 ? -1 : 0;
 }
 
 static struct dbox_file *
diff -r 9f0c4800cb13 -r 9c68c8d42ff2 src/lib-storage/index/dbox-multi/mdbox-map.c
--- a/src/lib-storage/index/dbox-multi/mdbox-map.c	Tue Feb 09 18:34:33 2010 +0200
+++ b/src/lib-storage/index/dbox-multi/mdbox-map.c	Tue Feb 09 18:54:34 2010 +0200
@@ -638,7 +638,8 @@ dbox_map_find_existing_append(struct dbo
 			      uoff_t mail_size, struct ostream **output_r)
 {
 	struct dbox_map *map = ctx->map;
-	struct dbox_file_append_context *const *file_appends;
+	struct dbox_file_append_context *const *file_appends, *append;
+	struct mdbox_file *mfile;
 	unsigned int i, count;
 	uoff_t append_offset;
 
@@ -648,13 +649,19 @@ dbox_map_find_existing_append(struct dbo
 	/* first try to use files already used in this append */
 	file_appends = array_get(&ctx->file_appends, &count);
 	for (i = count; i > ctx->files_nonappendable_count; i--) {
-		append_offset = file_appends[i-1]->output->offset;
+		append = file_appends[i-1];
+
+		append_offset = append->output->offset;
 		if (append_offset + mail_size <= map->set->mdbox_rotate_size &&
-		    dbox_file_get_append_stream(file_appends[i-1], output_r) > 0)
-			return file_appends[i-1];
-
-		/* can't append to this file anymore. we could close it
-		   otherwise, except that would also lose our lock too early. */
+		    dbox_file_get_append_stream(append, output_r) > 0)
+			return append;
+
+		/* can't append to this file anymore. if we created this file,
+		   close it so we don't waste fds. if we didn't, we can't close
+		   it without also losing our lock too early. */
+		mfile = (struct mdbox_file *)append->file;
+		if (mfile->file_id == 0 && dbox_file_append_flush(append) == 0)
+			dbox_file_close(append->file);
 	}
 	ctx->files_nonappendable_count = count;
 	return NULL;


More information about the dovecot-cvs mailing list