[dovecot-cvs] dovecot/src/lib-index mail-index-dummy-view.c, 1.2, 1.3 mail-index-private.h, 1.71, 1.72 mail-index-transaction-private.h, 1.30, 1.31 mail-index-transaction-view.c, 1.18, 1.19 mail-index-transaction.c, 1.77, 1.78 mail-index-view-private.h, 1.24, 1.25 mail-index-view.c, 1.46, 1.47 mail-index.c, 1.236, 1.237 mail-index.h, 1.159, 1.160

tss-movial at dovecot.org tss-movial at dovecot.org
Wed Jun 28 19:31:08 EEST 2006


Update of /var/lib/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv1042/lib-index

Modified Files:
	mail-index-dummy-view.c mail-index-private.h 
	mail-index-transaction-private.h mail-index-transaction-view.c 
	mail-index-transaction.c mail-index-view-private.h 
	mail-index-view.c mail-index.c mail-index.h 
Log Message:
Beginnings of joining mail-storage API more closely to mail-index, so that
mail-index could be directly used if needed. Currently only transactions
are joined.



Index: mail-index-dummy-view.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-dummy-view.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- mail-index-dummy-view.c	5 Feb 2005 18:05:24 -0000	1.2
+++ mail-index-dummy-view.c	28 Jun 2006 16:31:05 -0000	1.3
@@ -17,7 +17,7 @@
 	return (uint32_t)-3;
 }
 
-static struct mail_index_view_methods dummy_view_methods = {
+static struct mail_index_view_vfuncs dummy_view_vfuncs = {
 	_dummy_view_close,
 	_dummy_view_get_message_count,
 	NULL,
@@ -35,7 +35,7 @@
 
 	view = i_new(struct mail_index_view, 1);
 	view->refcount = 1;
-	view->methods = dummy_view_methods;
+	view->v = dummy_view_vfuncs;
 	view->index = index;
 	return view;
 }

Index: mail-index-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-private.h,v
retrieving revision 1.71
retrieving revision 1.72
diff -u -d -r1.71 -r1.72
--- mail-index-private.h	28 Jun 2006 13:10:38 -0000	1.71
+++ mail-index-private.h	28 Jun 2006 16:31:05 -0000	1.72
@@ -6,6 +6,8 @@
 #include <fcntl.h>
 
 #include "mail-index.h"
+#include "mail-index-view-private.h"
+#include "mail-index-transaction-private.h"
 
 struct mail_transaction_header;
 struct mail_transaction_log_view;
@@ -168,7 +170,7 @@
 	unsigned int last_grow_count;
 
 	/* Module-specific contexts. See mail_index_module_id. */
-	ARRAY_DEFINE(module_contexts, void);
+	ARRAY_DEFINE(mail_index_module_contexts, void);
 
 	char *error;
 	unsigned int nodiskspace:1;

Index: mail-index-transaction-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-transaction-private.h,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- mail-index-transaction-private.h	28 Jun 2006 13:10:38 -0000	1.30
+++ mail-index-transaction-private.h	28 Jun 2006 16:31:05 -0000	1.31
@@ -9,8 +9,16 @@
 	ARRAY_TYPE(seq_range) remove_seq;
 };
 
+struct mail_index_transaction_vfuncs {
+	int (*commit)(struct mail_index_transaction *t,
+		      uint32_t *log_file_seq_r, uoff_t *log_file_offset_r);
+	void (*rollback)(struct mail_index_transaction *t);
+};
+
 struct mail_index_transaction {
 	int refcount;
+
+	struct mail_index_transaction_vfuncs v;
 	struct mail_index_view *view;
 
         ARRAY_DEFINE(appends, struct mail_index_record);
@@ -35,6 +43,9 @@
 
         struct mail_cache_transaction_ctx *cache_trans_ctx;
 
+	/* Module-specific contexts. See mail_index_module_id. */
+	ARRAY_DEFINE(mail_index_transaction_module_contexts, void);
+
 	unsigned int hide_transaction:1;
 	unsigned int no_appends:1;
 	unsigned int appends_nonsorted:1;
@@ -44,6 +55,9 @@
 	unsigned int log_updates:1;
 };
 
+extern void (*hook_mail_index_transaction_created)
+		(struct mail_index_transaction *t);
+
 struct mail_index_record *
 mail_index_transaction_lookup(struct mail_index_transaction *t, uint32_t seq);
 

Index: mail-index-transaction-view.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-transaction-view.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- mail-index-transaction-view.c	28 Jun 2006 13:10:38 -0000	1.18
+++ mail-index-transaction-view.c	28 Jun 2006 16:31:05 -0000	1.19
@@ -10,7 +10,7 @@
 
 struct mail_index_view_transaction {
 	struct mail_index_view view;
-	struct mail_index_view_methods *parent;
+	struct mail_index_view_vfuncs *super;
 	struct mail_index_transaction *t;
 };
 
@@ -18,9 +18,10 @@
 {
 	struct mail_index_view_transaction *tview =
 		(struct mail_index_view_transaction *)view;
+	struct mail_index_transaction *t = tview->t;
 
-	mail_index_transaction_unref(&tview->t);
-	tview->parent->close(view);
+	tview->super->close(view);
+	mail_index_transaction_unref(&t);
 }
 
 static uint32_t _tview_get_message_count(struct mail_index_view *view)
@@ -40,7 +41,7 @@
                 (struct mail_index_view_transaction *)view;
 
 	/* FIXME: header counters may not be correct */
-	return tview->parent->get_header(view);
+	return tview->super->get_header(view);
 }
 
 static int _tview_lookup_full(struct mail_index_view *view, uint32_t seq,
@@ -59,7 +60,7 @@
 		return 1;
 	}
 
-	ret = tview->parent->lookup_full(view, seq, map_r, rec_r);
+	ret = tview->super->lookup_full(view, seq, map_r, rec_r);
 	if (ret <= 0)
 		return ret;
 
@@ -79,7 +80,7 @@
 		*uid_r = mail_index_transaction_lookup(tview->t, seq)->uid;
 		return 0;
 	} else {
-		return tview->parent->lookup_uid(view, seq, uid_r);
+		return tview->super->lookup_uid(view, seq, uid_r);
 	}
 }
 
@@ -90,8 +91,8 @@
 	struct mail_index_view_transaction *tview =
 		(struct mail_index_view_transaction *)view;
 
-	if (tview->parent->lookup_uid_range(view, first_uid, last_uid,
-					    first_seq_r, last_seq_r) < 0)
+	if (tview->super->lookup_uid_range(view, first_uid, last_uid,
+					   first_seq_r, last_seq_r) < 0)
 		return -1;
 
 	/* FIXME: we don't need this function yet.. new UIDs might be 0 as
@@ -117,7 +118,7 @@
 	unsigned int append_count;
 	uint32_t seq, message_count;
 
-	if (tview->parent->lookup_first(view, flags, flags_mask, seq_r) < 0)
+	if (tview->super->lookup_first(view, flags, flags_mask, seq_r) < 0)
 		return -1;
 
 	if (*seq_r != 0)
@@ -168,8 +169,8 @@
 
 	/* not updated, return the existing value */
 	if (seq < tview->t->first_new_seq) {
-		return tview->parent->lookup_ext_full(view, seq, ext_id,
-						      map_r, data_r);
+		return tview->super->lookup_ext_full(view, seq, ext_id,
+						     map_r, data_r);
 	}
 
 	*data_r = NULL;
@@ -184,11 +185,11 @@
 		(struct mail_index_view_transaction *)view;
 
 	/* FIXME: check updates */
-	return tview->parent->get_header_ext(view, map, ext_id,
-					     data_r, data_size_r);
+	return tview->super->get_header_ext(view, map, ext_id,
+					    data_r, data_size_r);
 }
 
-static struct mail_index_view_methods view_methods = {
+static struct mail_index_view_vfuncs trans_view_vfuncs = {
 	_tview_close,
         _tview_get_message_count,
 	_tview_get_header,
@@ -215,8 +216,8 @@
 
 	tview = i_new(struct mail_index_view_transaction, 1);
 	mail_index_view_clone(&tview->view, t->view);
-	tview->view.methods = view_methods;
-	tview->parent = &t->view->methods;
+	tview->view.v = trans_view_vfuncs;
+	tview->super = &t->view->v;
 	tview->t = t;
 
 	mail_index_transaction_ref(t);

Index: mail-index-transaction.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-transaction.c,v
retrieving revision 1.77
retrieving revision 1.78
diff -u -d -r1.77 -r1.78
--- mail-index-transaction.c	28 Jun 2006 13:10:38 -0000	1.77
+++ mail-index-transaction.c	28 Jun 2006 16:31:05 -0000	1.78
@@ -15,31 +15,8 @@
 #include <stddef.h>
 #include <stdlib.h>
 
-struct mail_index_transaction *
-mail_index_transaction_begin(struct mail_index_view *view,
-			     bool hide, bool external)
-{
-	struct mail_index_transaction *t;
-
-	/* don't allow syncing view while there's ongoing transactions */
-	mail_index_view_transaction_ref(view);
- 	mail_index_view_ref(view);
-
-	t = i_new(struct mail_index_transaction, 1);
-	t->refcount = 1;
-	t->view = view;
-	t->hide_transaction = hide;
-	t->external = external;
-	t->first_new_seq = mail_index_view_get_messages_count(t->view)+1;
-
-	if (view->syncing) {
-		/* transaction view cannot work if new records are being added
-		   in two places. make sure it doesn't happen. */
-		t->no_appends = TRUE;
-	}
-
-	return t;
-}
+void (*hook_mail_index_transaction_created)
+		(struct mail_index_transaction *t) = NULL;
 
 static void mail_index_transaction_free(struct mail_index_transaction *t)
 {
@@ -340,18 +317,12 @@
 	i_free(old_to_new_map);
 }
 
-int mail_index_transaction_commit(struct mail_index_transaction **_t,
-				  uint32_t *log_file_seq_r,
-				  uoff_t *log_file_offset_r)
+static int _mail_index_transaction_commit(struct mail_index_transaction *t,
+					  uint32_t *log_file_seq_r,
+					  uoff_t *log_file_offset_r)
 {
-	struct mail_index_transaction *t = *_t;
 	int ret;
 
-	if (mail_index_view_is_inconsistent(t->view)) {
-		mail_index_transaction_rollback(_t);
-		return -1;
-	}
-
 	if (t->cache_trans_ctx != NULL) {
 		mail_cache_transaction_commit(t->cache_trans_ctx);
                 t->cache_trans_ctx = NULL;
@@ -367,19 +338,40 @@
 						  log_file_offset_r);
 	}
 
-	mail_index_transaction_unref(_t);
+	mail_index_transaction_unref(&t);
 	return ret;
 }
 
-void mail_index_transaction_rollback(struct mail_index_transaction **_t)
+static void _mail_index_transaction_rollback(struct mail_index_transaction *t)
 {
-	struct mail_index_transaction *t = *_t;
-
 	if (t->cache_trans_ctx != NULL) {
 		mail_cache_transaction_rollback(t->cache_trans_ctx);
                 t->cache_trans_ctx = NULL;
 	}
-        mail_index_transaction_unref(_t);
+        mail_index_transaction_unref(&t);
+}
+
+int mail_index_transaction_commit(struct mail_index_transaction **_t,
+				  uint32_t *log_file_seq_r,
+				  uoff_t *log_file_offset_r)
+{
+	struct mail_index_transaction *t = *_t;
+
+	if (mail_index_view_is_inconsistent(t->view)) {
+		mail_index_transaction_rollback(_t);
+		return -1;
+	}
+
+	*_t = NULL;
+	return t->v.commit(t, log_file_seq_r, log_file_offset_r);
+}
+
+void mail_index_transaction_rollback(struct mail_index_transaction **_t)
+{
+	struct mail_index_transaction *t = *_t;
+
+	*_t = NULL;
+	t->v.rollback(t);
 }
 
 struct mail_index_record *
@@ -951,3 +943,40 @@
 
 	t->log_updates = TRUE;
 }
+
+struct mail_index_transaction_vfuncs trans_vfuncs = {
+	_mail_index_transaction_commit,
+	_mail_index_transaction_rollback
+};
+
+struct mail_index_transaction *
+mail_index_transaction_begin(struct mail_index_view *view,
+			     bool hide, bool external)
+{
+	struct mail_index_transaction *t;
+
+	/* don't allow syncing view while there's ongoing transactions */
+	mail_index_view_transaction_ref(view);
+ 	mail_index_view_ref(view);
+
+	t = i_new(struct mail_index_transaction, 1);
+	t->refcount = 1;
+	t->v = trans_vfuncs;
+	t->view = view;
+	t->hide_transaction = hide;
+	t->external = external;
+	t->first_new_seq = mail_index_view_get_messages_count(t->view)+1;
+
+	if (view->syncing) {
+		/* transaction view cannot work if new records are being added
+		   in two places. make sure it doesn't happen. */
+		t->no_appends = TRUE;
+	}
+
+	ARRAY_CREATE(&t->mail_index_transaction_module_contexts, default_pool,
+		     void *, I_MIN(5, mail_index_module_id));
+
+	if (hook_mail_index_transaction_created != NULL)
+		hook_mail_index_transaction_created(t);
+	return t;
+}

Index: mail-index-view-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-view-private.h,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- mail-index-view-private.h	28 Jun 2006 13:10:38 -0000	1.24
+++ mail-index-view-private.h	28 Jun 2006 16:31:05 -0000	1.25
@@ -9,7 +9,7 @@
 };
 ARRAY_DEFINE_TYPE(view_log_sync_pos, struct mail_index_view_log_sync_pos);
 
-struct mail_index_view_methods {
+struct mail_index_view_vfuncs {
 	void (*close)(struct mail_index_view *view);
 	uint32_t (*get_messages_count)(struct mail_index_view *view);
 	const struct mail_index_header *
@@ -35,7 +35,7 @@
 struct mail_index_view {
 	int refcount;
 
-	struct mail_index_view_methods methods;
+	struct mail_index_view_vfuncs v;
 	struct mail_index *index;
         struct mail_transaction_log_view *log_view;
 
@@ -56,6 +56,9 @@
 	/* Transaction log offsets which we don't want to return in view sync */
 	ARRAY_TYPE(view_log_sync_pos) syncs_hidden;
 
+	/* Module-specific contexts. See mail_index_module_id. */
+	ARRAY_DEFINE(mail_index_view_module_contexts, void);
+
 	int transactions;
 	unsigned int lock_id;
 

Index: mail-index-view.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-view.c,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -d -r1.46 -r1.47
--- mail-index-view.c	28 Jun 2006 13:10:38 -0000	1.46
+++ mail-index-view.c	28 Jun 2006 16:31:05 -0000	1.47
@@ -11,13 +11,14 @@
 {
 	memset(dest, 0, sizeof(dest));
 	dest->refcount = 1;
-	dest->methods = src->methods;
+	dest->v = src->v;
 	dest->index = src->index;
 	dest->log_view = mail_transaction_log_view_open(src->index->log);
 
 	dest->indexid = src->indexid;
 	dest->map = src->map;
-	dest->map->refcount++;
+	if (dest->map != NULL)
+		dest->map->refcount++;
 	dest->hdr = src->hdr;
 	dest->broken_counters = src->broken_counters;
 
@@ -452,18 +453,18 @@
 	if (--view->refcount > 0)
 		return;
 
-	view->methods.close(view);
+	view->v.close(view);
 }
 
 uint32_t mail_index_view_get_messages_count(struct mail_index_view *view)
 {
-	return view->methods.get_messages_count(view);
+	return view->v.get_messages_count(view);
 }
 
 const struct mail_index_header *
 mail_index_get_header(struct mail_index_view *view)
 {
-	return view->methods.get_header(view);
+	return view->v.get_header(view);
 }
 
 int mail_index_lookup(struct mail_index_view *view, uint32_t seq,
@@ -478,7 +479,7 @@
 			   struct mail_index_map **map_r,
 			   const struct mail_index_record **rec_r)
 {
-	return view->methods.lookup_full(view, seq, map_r, rec_r);
+	return view->v.lookup_full(view, seq, map_r, rec_r);
 }
 
 int mail_index_lookup_keywords(struct mail_index_view *view, uint32_t seq,
@@ -561,21 +562,21 @@
 int mail_index_lookup_uid(struct mail_index_view *view, uint32_t seq,
 			  uint32_t *uid_r)
 {
-	return view->methods.lookup_uid(view, seq, uid_r);
+	return view->v.lookup_uid(view, seq, uid_r);
 }
 
 int mail_index_lookup_uid_range(struct mail_index_view *view,
 				uint32_t first_uid, uint32_t last_uid,
 				uint32_t *first_seq_r, uint32_t *last_seq_r)
 {
-	return view->methods.lookup_uid_range(view, first_uid, last_uid,
-					      first_seq_r, last_seq_r);
+	return view->v.lookup_uid_range(view, first_uid, last_uid,
+					first_seq_r, last_seq_r);
 }
 
 int mail_index_lookup_first(struct mail_index_view *view, enum mail_flags flags,
 			    uint8_t flags_mask, uint32_t *seq_r)
 {
-	return view->methods.lookup_first(view, flags, flags_mask, seq_r);
+	return view->v.lookup_first(view, flags, flags_mask, seq_r);
 }
 
 int mail_index_lookup_ext(struct mail_index_view *view, uint32_t seq,
@@ -583,29 +584,27 @@
 {
 	struct mail_index_map *map;
 
-	return view->methods.lookup_ext_full(view, seq, ext_id, &map, data_r);
+	return view->v.lookup_ext_full(view, seq, ext_id, &map, data_r);
 }
 
 int mail_index_lookup_ext_full(struct mail_index_view *view, uint32_t seq,
 			       uint32_t ext_id, struct mail_index_map **map_r,
 			       const void **data_r)
 {
-	return view->methods.lookup_ext_full(view, seq, ext_id, map_r, data_r);
+	return view->v.lookup_ext_full(view, seq, ext_id, map_r, data_r);
 }
 
 int mail_index_get_header_ext(struct mail_index_view *view, uint32_t ext_id,
 			      const void **data_r, size_t *data_size_r)
 {
-	return view->methods.get_header_ext(view, NULL, ext_id,
-					    data_r, data_size_r);
+	return view->v.get_header_ext(view, NULL, ext_id, data_r, data_size_r);
 }
 
 int mail_index_map_get_header_ext(struct mail_index_view *view,
 				  struct mail_index_map *map, uint32_t ext_id,
 				  const void **data_r, size_t *data_size_r)
 {
-	return view->methods.get_header_ext(view, map, ext_id,
-					    data_r, data_size_r);
+	return view->v.get_header_ext(view, map, ext_id, data_r, data_size_r);
 }
 
 int mail_index_ext_get_size(struct mail_index_view *view __attr_unused__,
@@ -639,7 +638,7 @@
 	return 0;
 }
 
-static struct mail_index_view_methods view_methods = {
+static struct mail_index_view_vfuncs view_vfuncs = {
 	_view_close,
 	_view_get_messages_count,
 	_view_get_header,
@@ -659,7 +658,7 @@
 
 	view = i_new(struct mail_index_view, 1);
 	view->refcount = 1;
-	view->methods = view_methods;
+	view->v = view_vfuncs;
 	view->index = index;
 	view->log_view = mail_transaction_log_view_open(index->log);
 

Index: mail-index.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index.c,v
retrieving revision 1.236
retrieving revision 1.237
diff -u -d -r1.236 -r1.237
--- mail-index.c	28 Jun 2006 13:10:38 -0000	1.236
+++ mail-index.c	28 Jun 2006 16:31:05 -0000	1.237
@@ -18,6 +18,8 @@
 #include <time.h>
 #include <sys/stat.h>
 
+unsigned int mail_index_module_id = 0;
+
 static int mail_index_try_open_only(struct mail_index *index);
 static void mail_index_create_in_memory(struct mail_index *index,
 					const struct mail_index_header *hdr);
@@ -38,6 +40,9 @@
 	ARRAY_CREATE(&index->sync_lost_handlers, default_pool,
 		     mail_index_sync_lost_handler_t *, 4);
 
+	ARRAY_CREATE(&index->mail_index_module_contexts, default_pool,
+		     void *, I_MIN(5, mail_index_module_id));
+
 	index->mode = 0600;
 	index->gid = (gid_t)-1;
 

Index: mail-index.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index.h,v
retrieving revision 1.159
retrieving revision 1.160
diff -u -d -r1.159 -r1.160
--- mail-index.h	28 Jun 2006 13:10:38 -0000	1.159
+++ mail-index.h	28 Jun 2006 16:31:05 -0000	1.160
@@ -142,6 +142,8 @@
 	enum mail_index_sync_type type;
 };
 
+extern unsigned int mail_index_module_id;
+
 ARRAY_DEFINE_TYPE(keyword_indexes, unsigned int);
 
 struct mail_index;



More information about the dovecot-cvs mailing list