Remove O_SYNC from device open and use fsync().

This speed up wipe operation considerably.
This commit is contained in:
Milan Broz
2018-08-09 12:01:20 +02:00
parent 5b5a64361f
commit 69a844c654
10 changed files with 29 additions and 5 deletions

View File

@@ -104,6 +104,7 @@ int device_is_rotational(struct device *device);
size_t device_alignment(struct device *device);
int device_direct_io(const struct device *device);
int device_fallocate(struct device *device, uint64_t size);
void device_sync(struct device *device, int devfd);
int device_open_locked(struct device *device, int flags);
int device_read_lock(struct crypt_device *cd, struct device *device);

View File

@@ -193,8 +193,10 @@ int LUKS_encrypt_to_storage(char *src, size_t srcLength,
r = 0;
out:
if (devfd >= 0)
if (devfd >= 0) {
device_sync(device, devfd);
close(devfd);
}
if (r)
log_err(ctx, _("IO error while encrypting keyslot."));

View File

@@ -378,8 +378,10 @@ int LUKS_hdr_restore(
/* Be sure to reload new data */
r = LUKS_read_phdr(hdr, 1, 0, ctx);
out:
if (devfd >= 0)
if (devfd >= 0) {
device_sync(device, devfd);
close(devfd);
}
crypt_safe_free(buffer);
return r;
}
@@ -681,6 +683,8 @@ int LUKS_write_phdr(struct luks_phdr *hdr,
&convHdr, hdr_size) < hdr_size ? -EIO : 0;
if (r)
log_err(ctx, _("Error during update of LUKS header on device %s."), device_path(device));
device_sync(device, devfd);
close(devfd);
/* Re-read header from disk to be sure that in-memory and on-disk data are the same. */

View File

@@ -341,6 +341,7 @@ static int hdr_write_disk(struct device *device, struct luks2_hdr *hdr,
LUKS2_HDR_BIN_LEN, offset) < (ssize_t)LUKS2_HDR_BIN_LEN)
r = -EIO;
device_sync(device, devfd);
close(devfd);
return r;
}

View File

@@ -1195,8 +1195,10 @@ out:
crypt_memzero(&tmp_hdr, sizeof(tmp_hdr));
crypt_safe_free(buffer);
if (devfd >= 0)
if (devfd >= 0) {
device_sync(device, devfd);
close(devfd);
}
if (!r) {
LUKS2_hdr_free(hdr);

View File

@@ -79,6 +79,8 @@ static int luks2_encrypt_to_storage(char *src, size_t srcLength,
r = -EIO;
else
r = 0;
device_sync(device, devfd);
close(devfd);
} else
r = -EIO;

View File

@@ -461,6 +461,7 @@ static int move_keyslot_areas(struct crypt_device *cd, off_t offset_from,
r = 0;
out:
device_sync(device, devfd);
close(devfd);
crypt_memzero(buf, buf_size);
free(buf);

View File

@@ -229,6 +229,16 @@ static int _open_locked(struct device *device, int flags)
return fd;
}
/*
* Common wrapper for device sync.
* FIXME: file descriptor will be in struct later.
*/
void device_sync(struct device *device, int devfd)
{
if (fsync(devfd) == -1)
log_dbg("Cannot sync device %s.", device_path(device));
}
/*
* in non-locked mode returns always fd or -1
*
@@ -242,7 +252,6 @@ static int device_open_internal(struct device *device, int flags)
{
int devfd;
flags |= O_SYNC;
if (device->o_direct)
flags |= O_DIRECT;

View File

@@ -213,7 +213,7 @@ int crypt_wipe_device(struct crypt_device *cd,
}
}
fsync(devfd);
device_sync(device, devfd);
out:
close(devfd);
free(sf);

View File

@@ -201,6 +201,8 @@ int VERITY_write_sb(struct crypt_device *cd,
if (r)
log_err(cd, _("Error during update of verity header on device %s."),
device_path(device));
device_sync(device, devfd);
close(devfd);
return r;