Support device/file images if O_DIRECT cannot be used (1.5.1).

On some filesystems (like tmpfs) O_DIRECT cannot be used.
So just try to open device without O_DIRECT in the second try.
This commit is contained in:
Milan Broz
2012-12-29 15:29:43 +01:00
parent 0451e1c23a
commit 6190ad928d
6 changed files with 43 additions and 23 deletions

View File

@@ -47,7 +47,7 @@ static int device_ready(const char *device)
struct stat st;
log_dbg("Trying to open and read device %s.", device);
devfd = open(device, O_RDONLY | O_DIRECT | O_SYNC);
devfd = open(device, O_RDONLY);
if (devfd < 0) {
log_err(NULL, _("Device %s doesn't exist or access denied.\n"), device);
return -EINVAL;
@@ -61,6 +61,20 @@ static int device_ready(const char *device)
return r;
}
int device_open(struct device *device, int flags)
{
int devfd;
devfd = open(device_path(device), flags | O_DIRECT | O_SYNC);
if (devfd < 0 && errno == EINVAL) {
log_dbg("Trying to open device %s without direct-io.",
device_path(device));
devfd = open(device_path(device), flags | O_SYNC);
}
return devfd;
}
int device_alloc(struct device **device, const char *path)
{
struct device *dev;