mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-13 11:50:10 +01:00
Do not run direct-io read check on block devices.
Block devices must support direct-io. This check causes more problems than it solves - for Opal locked device it disables direct-io and we can later possible read wrong data (if kernel does not flush cache).
This commit is contained in:
@@ -127,19 +127,19 @@ static size_t device_alignment_fd(int devfd)
|
|||||||
return (size_t)alignment;
|
return (size_t)alignment;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int device_read_test(struct crypt_device *cd, int devfd, struct device *device)
|
static int device_read_test(struct crypt_device *cd, int devfd)
|
||||||
{
|
{
|
||||||
char buffer[512];
|
char buffer[512];
|
||||||
int r;
|
int r;
|
||||||
size_t minsize = 0, blocksize, alignment;
|
size_t minsize = 0, blocksize, alignment;
|
||||||
const char *dm_name;
|
struct stat st;
|
||||||
|
|
||||||
/* skip check for suspended DM devices */
|
/* skip check for block devices, direct-io must work there */
|
||||||
dm_name = device_dm_name(device);
|
if (fstat(devfd, &st) < 0)
|
||||||
if (dm_name && dm_status_suspended(cd, dm_name) > 0) {
|
return -EINVAL;
|
||||||
log_dbg(cd, "Device %s is suspended, assuming direct-io is supported.", dm_name);
|
|
||||||
|
if (S_ISBLK(st.st_mode))
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
blocksize = device_block_size_fd(devfd, &minsize);
|
blocksize = device_block_size_fd(devfd, &minsize);
|
||||||
alignment = device_alignment_fd(devfd);
|
alignment = device_alignment_fd(devfd);
|
||||||
@@ -154,7 +154,7 @@ static int device_read_test(struct crypt_device *cd, int devfd, struct device *d
|
|||||||
minsize = sizeof(buffer);
|
minsize = sizeof(buffer);
|
||||||
|
|
||||||
if (read_blockwise(devfd, blocksize, alignment, buffer, minsize) == (ssize_t)minsize) {
|
if (read_blockwise(devfd, blocksize, alignment, buffer, minsize) == (ssize_t)minsize) {
|
||||||
log_dbg(cd, "Direct-io is supported and works.");
|
log_dbg(cd, "Direct-io read works.");
|
||||||
r = 0;
|
r = 0;
|
||||||
} else {
|
} else {
|
||||||
log_dbg(cd, "Direct-io read failed.");
|
log_dbg(cd, "Direct-io read failed.");
|
||||||
@@ -183,12 +183,12 @@ static int device_ready(struct crypt_device *cd, struct device *device)
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (device->o_direct) {
|
if (device->o_direct) {
|
||||||
log_dbg(cd, "Trying to open and read device %s with direct-io.",
|
log_dbg(cd, "Trying to open device %s with direct-io.",
|
||||||
device_path(device));
|
device_path(device));
|
||||||
device->o_direct = 0;
|
device->o_direct = 0;
|
||||||
devfd = open(device_path(device), O_RDONLY | O_DIRECT);
|
devfd = open(device_path(device), O_RDONLY | O_DIRECT);
|
||||||
if (devfd >= 0) {
|
if (devfd >= 0) {
|
||||||
if (device_read_test(cd, devfd, device) == 0) {
|
if (device_read_test(cd, devfd) == 0) {
|
||||||
device->o_direct = 1;
|
device->o_direct = 1;
|
||||||
} else {
|
} else {
|
||||||
close(devfd);
|
close(devfd);
|
||||||
|
|||||||
Reference in New Issue
Block a user