changeset 10683:9c68c8d42ff2 HEAD

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.
author Timo Sirainen <tss@iki.fi>
date Tue, 09 Feb 2010 18:54:34 +0200
parents 9f0c4800cb13
children e202b2b86702
files src/lib-storage/index/dbox-common/dbox-file.c src/lib-storage/index/dbox-multi/mdbox-file.c src/lib-storage/index/dbox-multi/mdbox-map.c
diffstat 3 files changed, 15 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- 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 @@
 
 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);
--- 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_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 *
--- 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 @@
 			      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 @@
 	/* 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];
+		    dbox_file_get_append_stream(append, output_r) > 0)
+			return append;
 
-		/* can't append to this file anymore. we could close it
-		   otherwise, except that would also lose our lock too early. */
+		/* 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;