]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: If disable_reflink_copy_to=TRUE, disable hardlink/refcount copying.
authorTimo Sirainen <tss@iki.fi>
Tue, 23 Nov 2010 15:59:09 +0000 (15:59 +0000)
committerTimo Sirainen <tss@iki.fi>
Tue, 23 Nov 2010 15:59:09 +0000 (15:59 +0000)
src/lib-storage/index/dbox-multi/mdbox-save.c
src/lib-storage/index/dbox-single/sdbox-copy.c
src/lib-storage/index/maildir/maildir-copy.c
src/lib-storage/mail-copy.c
src/lib-storage/mail-copy.h
src/lib-storage/mail-storage-private.h

index 1f69f1b678c0ecbacc5c8053f0915f4406b5193e..f21507ae49188e727b7764cb058e7e13684b9cdc 100644 (file)
@@ -408,7 +408,8 @@ int mdbox_copy(struct mail_save_context *_ctx, struct mail *mail)
 
        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;
 
index e71a789a0ffdd4b8d609caa2fb9906194ee11d16..3e438f05ed77ff1eb874b1fc3802f740976b3e51 100644 (file)
@@ -138,13 +138,6 @@ sdbox_copy_hardlink(struct mail_save_context *_ctx, struct mail *mail)
        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 @@ int sdbox_copy(struct mail_save_context *_ctx, struct mail *mail)
        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;
index 2703ea173628e1f925a7c4b772f668568072fde5..52f0d56fd53ea6dd3ff14cb779b5d8ab2a9ea39f 100644 (file)
@@ -122,13 +122,6 @@ maildir_copy_hardlink(struct mail_save_context *ctx, struct mail *mail)
        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 @@ int maildir_copy(struct mail_save_context *ctx, struct mail *mail)
        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;
index 8efb0e2dc8670808dfe3b7d5b65dbaf9202d7238..287bee2a3ce13fec80c1b9a046fb2dd3e1225ff5 100644 (file)
@@ -74,3 +74,11 @@ int mail_storage_copy(struct mail_save_context *ctx, struct mail *mail)
        }
        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;
+}
index 0f937ffe250a79f09be817ff82ed2a01e357c3b7..94f691967185d4e5a095bb8cfe6e27f6e1f8a461 100644 (file)
@@ -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
index 720ff4dc339d5ca5a6b15c226292bc7d63dcd023..a72024e51226f13a00fd5ee56b9d0d297c57d0d3 100644 (file)
@@ -284,6 +284,10 @@ struct mailbox {
        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 {