dovecot-2.0: lib-storage: If disable_reflink_copy_to=TRUE, disab...

dovecot at dovecot.org dovecot at dovecot.org
Tue Nov 23 17:59:27 EET 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/10c2540e91b9
changeset: 12458:10c2540e91b9
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Nov 23 15:59:09 2010 +0000
description:
lib-storage: If disable_reflink_copy_to=TRUE, disable hardlink/refcount copying.

diffstat:

 src/lib-storage/index/dbox-multi/mdbox-save.c  |  3 ++-
 src/lib-storage/index/dbox-single/sdbox-copy.c |  9 +--------
 src/lib-storage/index/maildir/maildir-copy.c   |  9 +--------
 src/lib-storage/mail-copy.c                    |  8 ++++++++
 src/lib-storage/mail-copy.h                    |  6 ++++++
 src/lib-storage/mail-storage-private.h         |  4 ++++
 6 files changed, 22 insertions(+), 17 deletions(-)

diffs (111 lines):

diff -r 490138318288 -r 10c2540e91b9 src/lib-storage/index/dbox-multi/mdbox-save.c
--- a/src/lib-storage/index/dbox-multi/mdbox-save.c	Tue Nov 23 15:30:32 2010 +0000
+++ b/src/lib-storage/index/dbox-multi/mdbox-save.c	Tue Nov 23 15:59:09 2010 +0000
@@ -408,7 +408,8 @@
 
 	ctx->ctx.finished = TRUE;
 
-	if (mail->box->storage != _ctx->transaction->box->storage)
+	if (mail->box->storage != _ctx->transaction->box->storage ||
+	    _ctx->transaction->box->disable_reflink_copy_to)
 		return mail_storage_copy(_ctx, mail);
 	src_mbox = (struct mdbox_mailbox *)mail->box;
 
diff -r 490138318288 -r 10c2540e91b9 src/lib-storage/index/dbox-single/sdbox-copy.c
--- a/src/lib-storage/index/dbox-single/sdbox-copy.c	Tue Nov 23 15:30:32 2010 +0000
+++ b/src/lib-storage/index/dbox-single/sdbox-copy.c	Tue Nov 23 15:59:09 2010 +0000
@@ -138,13 +138,6 @@
 	return 1;
 }
 
-static bool
-sdbox_compatible_file_modes(struct mailbox *box1, struct mailbox *box2)
-{
-	return box1->file_create_mode == box2->file_create_mode &&
-		box1->file_create_gid == box2->file_create_gid;
-}
-
 int sdbox_copy(struct mail_save_context *_ctx, struct mail *mail)
 {
 	struct dbox_save_context *ctx = (struct dbox_save_context *)_ctx;
@@ -155,7 +148,7 @@
 	i_assert((_t->flags & MAILBOX_TRANSACTION_FLAG_EXTERNAL) != 0);
 
 	ctx->finished = TRUE;
-	if (sdbox_compatible_file_modes(&mbox->box, mail->box)) {
+	if (mail_storage_copy_can_use_hardlink(mail->box, &mbox->box)) {
 		T_BEGIN {
 			ret = sdbox_copy_hardlink(_ctx, mail);
 		} T_END;
diff -r 490138318288 -r 10c2540e91b9 src/lib-storage/index/maildir/maildir-copy.c
--- a/src/lib-storage/index/maildir/maildir-copy.c	Tue Nov 23 15:30:32 2010 +0000
+++ b/src/lib-storage/index/maildir/maildir-copy.c	Tue Nov 23 15:59:09 2010 +0000
@@ -122,13 +122,6 @@
 	return 1;
 }
 
-static bool
-maildir_compatible_file_modes(struct mailbox *box1, struct mailbox *box2)
-{
-	return box1->file_create_mode == box2->file_create_mode &&
-		box1->file_create_gid == box2->file_create_gid;
-}
-
 int maildir_copy(struct mail_save_context *ctx, struct mail *mail)
 {
 	struct mailbox_transaction_context *_t = ctx->transaction;
@@ -138,7 +131,7 @@
 	i_assert((_t->flags & MAILBOX_TRANSACTION_FLAG_EXTERNAL) != 0);
 
 	if (mbox->storage->set->maildir_copy_with_hardlinks &&
-	    maildir_compatible_file_modes(&mbox->box, mail->box)) {
+	    mail_storage_copy_can_use_hardlink(mail->box, &mbox->box)) {
 		T_BEGIN {
 			ret = maildir_copy_hardlink(ctx, mail);
 		} T_END;
diff -r 490138318288 -r 10c2540e91b9 src/lib-storage/mail-copy.c
--- a/src/lib-storage/mail-copy.c	Tue Nov 23 15:30:32 2010 +0000
+++ b/src/lib-storage/mail-copy.c	Tue Nov 23 15:59:09 2010 +0000
@@ -74,3 +74,11 @@
 	}
 	return mailbox_save_finish(&ctx);
 }
+
+bool mail_storage_copy_can_use_hardlink(struct mailbox *src,
+					struct mailbox *dest)
+{
+	return src->file_create_mode == src->file_create_mode &&
+		src->file_create_gid == src->file_create_gid &&
+		!dest->disable_reflink_copy_to;
+}
diff -r 490138318288 -r 10c2540e91b9 src/lib-storage/mail-copy.h
--- a/src/lib-storage/mail-copy.h	Tue Nov 23 15:30:32 2010 +0000
+++ b/src/lib-storage/mail-copy.h	Tue Nov 23 15:59:09 2010 +0000
@@ -3,7 +3,13 @@
 
 struct mail;
 struct mail_save_context;
+struct mailbox;
 
 int mail_storage_copy(struct mail_save_context *ctx, struct mail *mail);
 
+/* Returns TRUE if mail can be copied using hard linking from src to dest.
+   (Assuming the storage itself supports this.) */
+bool mail_storage_copy_can_use_hardlink(struct mailbox *src,
+					struct mailbox *dest);
+
 #endif
diff -r 490138318288 -r 10c2540e91b9 src/lib-storage/mail-storage-private.h
--- a/src/lib-storage/mail-storage-private.h	Tue Nov 23 15:30:32 2010 +0000
+++ b/src/lib-storage/mail-storage-private.h	Tue Nov 23 15:59:09 2010 +0000
@@ -284,6 +284,10 @@
 	unsigned int inbox_user:1;
 	/* TRUE if this is an INBOX for this namespace (user or shared) */
 	unsigned int inbox_any:1;
+	/* When copying to this mailbox, require that mailbox_copy() uses
+	   mailbox_save_*() to actually save a new physical copy rather than
+	   simply incrementing a reference count (e.g. via hard link) */
+	unsigned int disable_reflink_copy_to:1;
 };
 
 struct mail_vfuncs {


More information about the dovecot-cvs mailing list