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