mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-05 16:00:05 +01:00
Remove O_SYNC from device open and use fsync().
This speed up wipe operation considerably.
This commit is contained in:
@@ -104,6 +104,7 @@ int device_is_rotational(struct device *device);
|
|||||||
size_t device_alignment(struct device *device);
|
size_t device_alignment(struct device *device);
|
||||||
int device_direct_io(const struct device *device);
|
int device_direct_io(const struct device *device);
|
||||||
int device_fallocate(struct device *device, uint64_t size);
|
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_open_locked(struct device *device, int flags);
|
||||||
int device_read_lock(struct crypt_device *cd, struct device *device);
|
int device_read_lock(struct crypt_device *cd, struct device *device);
|
||||||
|
|||||||
@@ -193,8 +193,10 @@ int LUKS_encrypt_to_storage(char *src, size_t srcLength,
|
|||||||
|
|
||||||
r = 0;
|
r = 0;
|
||||||
out:
|
out:
|
||||||
if (devfd >= 0)
|
if (devfd >= 0) {
|
||||||
|
device_sync(device, devfd);
|
||||||
close(devfd);
|
close(devfd);
|
||||||
|
}
|
||||||
if (r)
|
if (r)
|
||||||
log_err(ctx, _("IO error while encrypting keyslot."));
|
log_err(ctx, _("IO error while encrypting keyslot."));
|
||||||
|
|
||||||
|
|||||||
@@ -378,8 +378,10 @@ int LUKS_hdr_restore(
|
|||||||
/* Be sure to reload new data */
|
/* Be sure to reload new data */
|
||||||
r = LUKS_read_phdr(hdr, 1, 0, ctx);
|
r = LUKS_read_phdr(hdr, 1, 0, ctx);
|
||||||
out:
|
out:
|
||||||
if (devfd >= 0)
|
if (devfd >= 0) {
|
||||||
|
device_sync(device, devfd);
|
||||||
close(devfd);
|
close(devfd);
|
||||||
|
}
|
||||||
crypt_safe_free(buffer);
|
crypt_safe_free(buffer);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@@ -681,6 +683,8 @@ int LUKS_write_phdr(struct luks_phdr *hdr,
|
|||||||
&convHdr, hdr_size) < hdr_size ? -EIO : 0;
|
&convHdr, hdr_size) < hdr_size ? -EIO : 0;
|
||||||
if (r)
|
if (r)
|
||||||
log_err(ctx, _("Error during update of LUKS header on device %s."), device_path(device));
|
log_err(ctx, _("Error during update of LUKS header on device %s."), device_path(device));
|
||||||
|
|
||||||
|
device_sync(device, devfd);
|
||||||
close(devfd);
|
close(devfd);
|
||||||
|
|
||||||
/* Re-read header from disk to be sure that in-memory and on-disk data are the same. */
|
/* Re-read header from disk to be sure that in-memory and on-disk data are the same. */
|
||||||
|
|||||||
@@ -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)
|
LUKS2_HDR_BIN_LEN, offset) < (ssize_t)LUKS2_HDR_BIN_LEN)
|
||||||
r = -EIO;
|
r = -EIO;
|
||||||
|
|
||||||
|
device_sync(device, devfd);
|
||||||
close(devfd);
|
close(devfd);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1195,8 +1195,10 @@ out:
|
|||||||
crypt_memzero(&tmp_hdr, sizeof(tmp_hdr));
|
crypt_memzero(&tmp_hdr, sizeof(tmp_hdr));
|
||||||
crypt_safe_free(buffer);
|
crypt_safe_free(buffer);
|
||||||
|
|
||||||
if (devfd >= 0)
|
if (devfd >= 0) {
|
||||||
|
device_sync(device, devfd);
|
||||||
close(devfd);
|
close(devfd);
|
||||||
|
}
|
||||||
|
|
||||||
if (!r) {
|
if (!r) {
|
||||||
LUKS2_hdr_free(hdr);
|
LUKS2_hdr_free(hdr);
|
||||||
|
|||||||
@@ -79,6 +79,8 @@ static int luks2_encrypt_to_storage(char *src, size_t srcLength,
|
|||||||
r = -EIO;
|
r = -EIO;
|
||||||
else
|
else
|
||||||
r = 0;
|
r = 0;
|
||||||
|
|
||||||
|
device_sync(device, devfd);
|
||||||
close(devfd);
|
close(devfd);
|
||||||
} else
|
} else
|
||||||
r = -EIO;
|
r = -EIO;
|
||||||
|
|||||||
@@ -461,6 +461,7 @@ static int move_keyslot_areas(struct crypt_device *cd, off_t offset_from,
|
|||||||
|
|
||||||
r = 0;
|
r = 0;
|
||||||
out:
|
out:
|
||||||
|
device_sync(device, devfd);
|
||||||
close(devfd);
|
close(devfd);
|
||||||
crypt_memzero(buf, buf_size);
|
crypt_memzero(buf, buf_size);
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|||||||
@@ -229,6 +229,16 @@ static int _open_locked(struct device *device, int flags)
|
|||||||
return fd;
|
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
|
* 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;
|
int devfd;
|
||||||
|
|
||||||
flags |= O_SYNC;
|
|
||||||
if (device->o_direct)
|
if (device->o_direct)
|
||||||
flags |= O_DIRECT;
|
flags |= O_DIRECT;
|
||||||
|
|
||||||
|
|||||||
@@ -213,7 +213,7 @@ int crypt_wipe_device(struct crypt_device *cd,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fsync(devfd);
|
device_sync(device, devfd);
|
||||||
out:
|
out:
|
||||||
close(devfd);
|
close(devfd);
|
||||||
free(sf);
|
free(sf);
|
||||||
|
|||||||
@@ -201,6 +201,8 @@ int VERITY_write_sb(struct crypt_device *cd,
|
|||||||
if (r)
|
if (r)
|
||||||
log_err(cd, _("Error during update of verity header on device %s."),
|
log_err(cd, _("Error during update of verity header on device %s."),
|
||||||
device_path(device));
|
device_path(device));
|
||||||
|
|
||||||
|
device_sync(device, devfd);
|
||||||
close(devfd);
|
close(devfd);
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
|
|||||||
Reference in New Issue
Block a user