Blame SOURCES/cryptsetup-1.6.7-use-fsync-isntead-of-odirect.patch

4f8adc
From 3d6bcae84c5f55a82dc0056e3d7da33bee3f00b9 Mon Sep 17 00:00:00 2001
4f8adc
From: Ondrej Kozina <okozina@redhat.com>
4f8adc
Date: Wed, 17 Sep 2014 16:38:39 +0200
4f8adc
Subject: [PATCH] reencrypt: use fsync instead of O_DIRECT flag
4f8adc
4f8adc
O_DIRECT operations directed towards filesystem are problematic:
4f8adc
There's no sane way how to detect specific filesystem requirements
4f8adc
for such operations.
4f8adc
4f8adc
This patch is replacing O_DIRECT flag with O_SYNC flag for all
4f8adc
open() calls related to reencrypt log. The O_SYNC flag is used
4f8adc
when --use-fsync option is detected.
4f8adc
4f8adc
Man page is modified accordingly.
4f8adc
---
4f8adc
 man/cryptsetup-reencrypt.8 |  6 ++++--
4f8adc
 src/cryptsetup_reencrypt.c | 12 ++----------
4f8adc
 2 files changed, 6 insertions(+), 12 deletions(-)
4f8adc
4f8adc
diff --git a/man/cryptsetup-reencrypt.8 b/man/cryptsetup-reencrypt.8
4f8adc
index b3c374c..e0de656 100644
4f8adc
--- a/man/cryptsetup-reencrypt.8
4f8adc
+++ b/man/cryptsetup-reencrypt.8
4f8adc
@@ -158,13 +158,15 @@ WARNING: This is destructive operation and cannot be reverted.
4f8adc
 
4f8adc
 .TP
4f8adc
 .B "\-\-use-directio"
4f8adc
-Use direct-io (O_DIRECT) for all read/write data operations.
4f8adc
+Use direct-io (O_DIRECT) for all read/write data operations related
4f8adc
+to block device undergoing reencryption.
4f8adc
 
4f8adc
 Useful if direct-io operations perform better than normal buffered
4f8adc
 operations (e.g. in virtual environments).
4f8adc
 .TP
4f8adc
 .B "\-\-use-fsync"
4f8adc
-Use fsync call after every written block.
4f8adc
+Use fsync call after every written block. This applies for reencryption
4f8adc
+log files as well.
4f8adc
 .TP
4f8adc
 .B "\-\-write-log"
4f8adc
 Update log file after every block write. This can slow down reencryption
4f8adc
diff --git a/src/cryptsetup_reencrypt.c b/src/cryptsetup_reencrypt.c
4f8adc
index 997c388..a1cc51d 100644
4f8adc
--- a/src/cryptsetup_reencrypt.c
4f8adc
+++ b/src/cryptsetup_reencrypt.c
4f8adc
@@ -76,7 +76,7 @@ struct reenc_ctx {
4f8adc
 	char crypt_path_org[PATH_MAX];
4f8adc
 	char crypt_path_new[PATH_MAX];
4f8adc
 	int log_fd;
4f8adc
-	char *log_buf;
4f8adc
+	char log_buf[SECTOR_SIZE];
4f8adc
 
4f8adc
 	struct {
4f8adc
 		char *password;
4f8adc
@@ -351,13 +351,11 @@ static void close_log(struct reenc_ctx *rc)
4f8adc
 	log_dbg("Closing LUKS reencryption log file %s.", rc->log_file);
4f8adc
 	if (rc->log_fd != -1)
4f8adc
 		close(rc->log_fd);
4f8adc
-	free(rc->log_buf);
4f8adc
-	rc->log_buf = NULL;
4f8adc
 }
4f8adc
 
4f8adc
 static int open_log(struct reenc_ctx *rc)
4f8adc
 {
4f8adc
-	int flags = opt_directio ? O_DIRECT : 0;
4f8adc
+	int flags = opt_fsync ? O_SYNC : 0;
4f8adc
 
4f8adc
 	rc->log_fd = open(rc->log_file, O_RDWR|O_EXCL|O_CREAT|flags, S_IRUSR|S_IWUSR);
4f8adc
 	if (rc->log_fd != -1) {
4f8adc
@@ -371,12 +369,6 @@ static int open_log(struct reenc_ctx *rc)
4f8adc
 	if (rc->log_fd == -1)
4f8adc
 		return -EINVAL;
4f8adc
 
4f8adc
-	if (posix_memalign((void *)&rc->log_buf, alignment(rc->log_fd), SECTOR_SIZE)) {
4f8adc
-		log_err(_("Allocation of aligned memory failed.\n"));
4f8adc
-		close_log(rc);
4f8adc
-		return -ENOMEM;
4f8adc
-	}
4f8adc
-
4f8adc
 	if (!rc->in_progress && write_log(rc) < 0) {
4f8adc
 		close_log(rc);
4f8adc
 		return -EIO;
4f8adc
-- 
4f8adc
1.9.3
4f8adc