mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-01-23 00:07:07 +03:00
linux/blkdev.c: Fall back to buffered IO when O_DIRECT fails
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
7e196f5399
commit
36db254cec
@ -180,13 +180,26 @@ struct block_device *blkdev_get_by_path(const char *path, fmode_t mode,
|
||||
if (mode & FMODE_EXCL)
|
||||
flags |= O_EXCL;
|
||||
#endif
|
||||
buffered_fd = open(path, flags);
|
||||
if (buffered_fd < 0)
|
||||
return ERR_PTR(-errno);
|
||||
|
||||
fd = open(path, flags|O_DIRECT);
|
||||
if (fd < 0)
|
||||
fd = dup(buffered_fd);
|
||||
if (fd < 0) {
|
||||
close(buffered_fd);
|
||||
return ERR_PTR(-errno);
|
||||
}
|
||||
|
||||
sync_fd = xopen(path, flags|O_DIRECT|O_SYNC);
|
||||
buffered_fd = xopen(path, flags);
|
||||
sync_fd = open(path, flags|O_DIRECT|O_SYNC);
|
||||
if (sync_fd < 0)
|
||||
sync_fd = open(path, flags|O_SYNC);
|
||||
if (sync_fd < 0) {
|
||||
close(fd);
|
||||
close(buffered_fd);
|
||||
return ERR_PTR(-errno);
|
||||
}
|
||||
|
||||
bdev = malloc(sizeof(*bdev));
|
||||
memset(bdev, 0, sizeof(*bdev));
|
||||
|
Loading…
Reference in New Issue
Block a user