mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-13 11:50:10 +01:00
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.
This commit is contained in:
committed by
Milan Broz
parent
b8beedb621
commit
3d6bcae84c
@@ -158,13 +158,15 @@ WARNING: This is destructive operation and cannot be reverted.
|
|||||||
|
|
||||||
.TP
|
.TP
|
||||||
.B "\-\-use-directio"
|
.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
|
Useful if direct-io operations perform better than normal buffered
|
||||||
operations (e.g. in virtual environments).
|
operations (e.g. in virtual environments).
|
||||||
.TP
|
.TP
|
||||||
.B "\-\-use-fsync"
|
.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
|
.TP
|
||||||
.B "\-\-write-log"
|
.B "\-\-write-log"
|
||||||
Update log file after every block write. This can slow down reencryption
|
Update log file after every block write. This can slow down reencryption
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ struct reenc_ctx {
|
|||||||
char crypt_path_org[PATH_MAX];
|
char crypt_path_org[PATH_MAX];
|
||||||
char crypt_path_new[PATH_MAX];
|
char crypt_path_new[PATH_MAX];
|
||||||
int log_fd;
|
int log_fd;
|
||||||
char *log_buf;
|
char log_buf[SECTOR_SIZE];
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
char *password;
|
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);
|
log_dbg("Closing LUKS reencryption log file %s.", rc->log_file);
|
||||||
if (rc->log_fd != -1)
|
if (rc->log_fd != -1)
|
||||||
close(rc->log_fd);
|
close(rc->log_fd);
|
||||||
free(rc->log_buf);
|
|
||||||
rc->log_buf = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int open_log(struct reenc_ctx *rc)
|
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);
|
rc->log_fd = open(rc->log_file, O_RDWR|O_EXCL|O_CREAT|flags, S_IRUSR|S_IWUSR);
|
||||||
if (rc->log_fd != -1) {
|
if (rc->log_fd != -1) {
|
||||||
@@ -371,12 +369,6 @@ static int open_log(struct reenc_ctx *rc)
|
|||||||
if (rc->log_fd == -1)
|
if (rc->log_fd == -1)
|
||||||
return -EINVAL;
|
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) {
|
if (!rc->in_progress && write_log(rc) < 0) {
|
||||||
close_log(rc);
|
close_log(rc);
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
|||||||
Reference in New Issue
Block a user