Sync device using internal write enabled descriptor.

This commit is contained in:
Ondrej Kozina
2019-05-10 15:27:53 +02:00
committed by Milan Broz
parent ee57b865b0
commit 83c227d53c
10 changed files with 15 additions and 16 deletions

View File

@@ -129,7 +129,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 crypt_device *cd, struct device *device, int devfd); void device_sync(struct crypt_device *cd, struct device *device);
int device_check_size(struct crypt_device *cd, int device_check_size(struct crypt_device *cd,
struct device *device, struct device *device,
uint64_t req_offset, int falloc); uint64_t req_offset, int falloc);

View File

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

View File

@@ -359,8 +359,7 @@ 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) device_sync(ctx, device);
device_sync(ctx, device, devfd);
crypt_safe_free(buffer); crypt_safe_free(buffer);
return r; return r;
} }
@@ -661,7 +660,7 @@ int LUKS_write_phdr(struct luks_phdr *hdr,
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(ctx, device, devfd); device_sync(ctx, device);
/* 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. */
if (!r) { if (!r) {

View File

@@ -345,7 +345,7 @@ static int hdr_write_disk(struct crypt_device *cd,
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(cd, device, devfd); device_sync(cd, device);
return r; return r;
} }

View File

@@ -1256,8 +1256,7 @@ 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) device_sync(cd, device);
device_sync(cd, device, devfd);
return r; return r;
} }

View File

@@ -83,7 +83,7 @@ static int luks2_encrypt_to_storage(char *src, size_t srcLength,
else else
r = 0; r = 0;
device_sync(cd, device, devfd); device_sync(cd, device);
} else } else
r = -EIO; r = -EIO;

View File

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

View File

@@ -240,11 +240,13 @@ static int _open_locked(struct crypt_device *cd, struct device *device, int flag
/* /*
* Common wrapper for device sync. * Common wrapper for device sync.
* FIXME: file descriptor will be in struct later.
*/ */
void device_sync(struct crypt_device *cd, struct device *device, int devfd) void device_sync(struct crypt_device *cd, struct device *device)
{ {
if (fsync(devfd) == -1) if (!device || device->dev_fd < 0)
return;
if (fsync(device->dev_fd) == -1)
log_dbg(cd, "Cannot sync device %s.", device_path(device)); log_dbg(cd, "Cannot sync device %s.", device_path(device));
} }

View File

@@ -215,7 +215,7 @@ int crypt_wipe_device(struct crypt_device *cd,
} }
} }
device_sync(cd, device, devfd); device_sync(cd, device);
out: out:
free(sf); free(sf);
return r; return r;

View File

@@ -199,7 +199,7 @@ int VERITY_write_sb(struct crypt_device *cd,
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(cd, device, devfd); device_sync(cd, device);
return r; return r;
} }