summaryrefslogtreecommitdiff
path: root/fs_mgr/libdm/loop_control.cpp
diff options
context:
space:
mode:
authorDavid Anderson <dvander@google.com>2019-06-12 19:13:21 -0700
committerDavid Anderson <dvander@google.com>2019-06-19 19:29:15 -0700
commitea0dda1473dbb7a4e124123ccd72b316d5e703df (patch)
tree68eb5c88e0cb8343d1b0a2a50fc55baeef0ff8c6 /fs_mgr/libdm/loop_control.cpp
parentd106f1e22546611df0353077409ef1a55fd32954 (diff)
libdm: Add LoopControl helpers for enabling direct IO.
Bug: 134536978 Test: manual test Change-Id: Iae25434ac54186fd6006b56eeb7a7f577a880053
Diffstat (limited to 'fs_mgr/libdm/loop_control.cpp')
-rw-r--r--fs_mgr/libdm/loop_control.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/fs_mgr/libdm/loop_control.cpp b/fs_mgr/libdm/loop_control.cpp
index 0beb1a63e..16bf4b038 100644
--- a/fs_mgr/libdm/loop_control.cpp
+++ b/fs_mgr/libdm/loop_control.cpp
@@ -91,6 +91,27 @@ bool LoopControl::FindFreeLoopDevice(std::string* loopdev) const {
return true;
}
+bool LoopControl::EnableDirectIo(int fd) {
+#if !defined(LOOP_SET_BLOCK_SIZE)
+ static constexpr int LOOP_SET_BLOCK_SIZE = 0x4C09;
+#endif
+#if !defined(LOOP_SET_DIRECT_IO)
+ static constexpr int LOOP_SET_DIRECT_IO = 0x4C08;
+#endif
+
+ // Note: the block size has to be >= the logical block size of the underlying
+ // block device, *not* the filesystem block size.
+ if (ioctl(fd, LOOP_SET_BLOCK_SIZE, 4096)) {
+ PLOG(ERROR) << "Could not set loop device block size";
+ return false;
+ }
+ if (ioctl(fd, LOOP_SET_DIRECT_IO, 1)) {
+ PLOG(ERROR) << "Could not set loop direct IO";
+ return false;
+ }
+ return true;
+}
+
LoopDevice::LoopDevice(int fd, bool auto_close) : fd_(fd), owns_fd_(auto_close) {
Init();
}