aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMilan Broz <gmazyland@gmail.com>2015-03-19 09:39:36 +0100
committerMilan Broz <gmazyland@gmail.com>2015-03-19 09:39:36 +0100
commit3adfe80601fc8e3a8a5122522d645a18111eefdc (patch)
tree6cd9bfc253ee5a0038492fb0594be752450df8cc
parent0bc437d92c30945991881c8b8ca245a016fc1236 (diff)
downloadcryptsetup-3adfe80601fc8e3a8a5122522d645a18111eefdc.tar.gz
Test device read only once for O_DIRECT.
Also do not report error for disappeared device (it is reported later on real access).
-rw-r--r--lib/utils_device.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/lib/utils_device.c b/lib/utils_device.c
index acfbfc6..46c2a0f 100644
--- a/lib/utils_device.c
+++ b/lib/utils_device.c
@@ -111,28 +111,25 @@ static int device_ready(struct device *device, int check_directio)
int devfd = -1, r = 0;
struct stat st;
+ device->o_direct = 0;
if (check_directio) {
log_dbg("Trying to open and read device %s with direct-io.",
device_path(device));
devfd = open(device_path(device), O_RDONLY | O_DIRECT);
- if (devfd >= 0 && device_read_test(devfd) == 0) {
- device->o_direct = 1;
- } else {
- close(devfd);
- devfd = -1;
+ if (devfd >= 0) {
+ if (device_read_test(devfd) == 0) {
+ device->o_direct = 1;
+ } else {
+ close(devfd);
+ devfd = -1;
+ }
}
}
if (devfd < 0) {
- log_dbg("Trying to open and read device %s without direct-io.",
+ log_dbg("Trying to open device %s without direct-io.",
device_path(device));
devfd = open(device_path(device), O_RDONLY);
- if (devfd >= 0 && device_read_test(devfd) == 0) {
- device->o_direct = 0;
- } else {
- close(devfd);
- devfd = -1;
- }
}
if (devfd < 0) {