Loading fs_mgr/libdm/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ cc_test { static_libs: [ "libdm", "libbase", "libfs_mgr", "liblog", ], srcs: [ Loading fs_mgr/libdm/dm.cpp +20 −0 Original line number Diff line number Diff line Loading @@ -302,6 +302,26 @@ bool DeviceMapper::GetDmDevicePathByName(const std::string& name, std::string* p return true; } bool DeviceMapper::GetDeviceNumber(const std::string& name, dev_t* dev) { struct dm_ioctl io; InitIo(&io, name); if (ioctl(fd_, DM_DEV_STATUS, &io) < 0) { PLOG(WARNING) << "DM_DEV_STATUS failed for " << name; return false; } *dev = io.dev; return true; } bool DeviceMapper::GetDeviceString(const std::string& name, std::string* dev) { dev_t num; if (!GetDeviceNumber(name, &num)) { return false; } *dev = std::to_string(major(num)) + ":" + std::to_string(minor(num)); return true; } bool DeviceMapper::GetTableStatus(const std::string& name, std::vector<TargetInfo>* table) { return GetTable(name, 0, table); } Loading fs_mgr/libdm/dm_test.cpp +12 −3 Original line number Diff line number Diff line Loading @@ -132,8 +132,8 @@ TEST(libdm, DmLinear) { // Define a 2-sector device, with each sector mapping to the first sector // of one of our loop devices. DmTable table; ASSERT_TRUE(table.AddTarget(make_unique<DmTargetLinear>(0, 1, loop_a.device(), 0))); ASSERT_TRUE(table.AddTarget(make_unique<DmTargetLinear>(1, 1, loop_b.device(), 0))); ASSERT_TRUE(table.Emplace<DmTargetLinear>(0, 1, loop_a.device(), 0)); ASSERT_TRUE(table.Emplace<DmTargetLinear>(1, 1, loop_b.device(), 0)); ASSERT_TRUE(table.valid()); TempDevice dev("libdm-test-dm-linear", table); Loading @@ -141,6 +141,16 @@ TEST(libdm, DmLinear) { ASSERT_FALSE(dev.path().empty()); ASSERT_TRUE(dev.WaitForUdev()); auto& dm = DeviceMapper::Instance(); dev_t dev_number; ASSERT_TRUE(dm.GetDeviceNumber(dev.name(), &dev_number)); ASSERT_NE(dev_number, 0); std::string dev_string; ASSERT_TRUE(dm.GetDeviceString(dev.name(), &dev_string)); ASSERT_FALSE(dev_string.empty()); // Note: a scope is needed to ensure that there are no open descriptors // when we go to close the device. { Loading @@ -157,7 +167,6 @@ TEST(libdm, DmLinear) { } // Test GetTableStatus. DeviceMapper& dm = DeviceMapper::Instance(); vector<DeviceMapper::TargetInfo> targets; ASSERT_TRUE(dm.GetTableStatus(dev.name(), &targets)); ASSERT_EQ(targets.size(), 2); Loading fs_mgr/libdm/include/libdm/dm.h +8 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ #include <fcntl.h> #include <linux/dm-ioctl.h> #include <linux/kdev_t.h> #include <linux/types.h> #include <stdint.h> #include <sys/sysmacros.h> #include <unistd.h> Loading Loading @@ -111,6 +112,13 @@ class DeviceMapper final { // parameter is not set. bool GetDmDevicePathByName(const std::string& name, std::string* path); // Returns the dev_t for the named device-mapper node. bool GetDeviceNumber(const std::string& name, dev_t* dev); // Returns a major:minor string for the named device-mapper node, that can // be used as inputs to DmTargets that take a block device. bool GetDeviceString(const std::string& name, std::string* dev); // The only way to create a DeviceMapper object. static DeviceMapper& Instance(); Loading fs_mgr/libdm/include/libdm/loop_control.h +3 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,9 @@ class LoopControl final { // Detach the loop device given by 'loopdev' from the attached backing file. bool Detach(const std::string& loopdev) const; // Enable Direct I/O on a loop device. This requires kernel 4.9+. static bool EnableDirectIo(int fd); LoopControl(const LoopControl&) = delete; LoopControl& operator=(const LoopControl&) = delete; LoopControl& operator=(LoopControl&&) = default; Loading Loading
fs_mgr/libdm/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ cc_test { static_libs: [ "libdm", "libbase", "libfs_mgr", "liblog", ], srcs: [ Loading
fs_mgr/libdm/dm.cpp +20 −0 Original line number Diff line number Diff line Loading @@ -302,6 +302,26 @@ bool DeviceMapper::GetDmDevicePathByName(const std::string& name, std::string* p return true; } bool DeviceMapper::GetDeviceNumber(const std::string& name, dev_t* dev) { struct dm_ioctl io; InitIo(&io, name); if (ioctl(fd_, DM_DEV_STATUS, &io) < 0) { PLOG(WARNING) << "DM_DEV_STATUS failed for " << name; return false; } *dev = io.dev; return true; } bool DeviceMapper::GetDeviceString(const std::string& name, std::string* dev) { dev_t num; if (!GetDeviceNumber(name, &num)) { return false; } *dev = std::to_string(major(num)) + ":" + std::to_string(minor(num)); return true; } bool DeviceMapper::GetTableStatus(const std::string& name, std::vector<TargetInfo>* table) { return GetTable(name, 0, table); } Loading
fs_mgr/libdm/dm_test.cpp +12 −3 Original line number Diff line number Diff line Loading @@ -132,8 +132,8 @@ TEST(libdm, DmLinear) { // Define a 2-sector device, with each sector mapping to the first sector // of one of our loop devices. DmTable table; ASSERT_TRUE(table.AddTarget(make_unique<DmTargetLinear>(0, 1, loop_a.device(), 0))); ASSERT_TRUE(table.AddTarget(make_unique<DmTargetLinear>(1, 1, loop_b.device(), 0))); ASSERT_TRUE(table.Emplace<DmTargetLinear>(0, 1, loop_a.device(), 0)); ASSERT_TRUE(table.Emplace<DmTargetLinear>(1, 1, loop_b.device(), 0)); ASSERT_TRUE(table.valid()); TempDevice dev("libdm-test-dm-linear", table); Loading @@ -141,6 +141,16 @@ TEST(libdm, DmLinear) { ASSERT_FALSE(dev.path().empty()); ASSERT_TRUE(dev.WaitForUdev()); auto& dm = DeviceMapper::Instance(); dev_t dev_number; ASSERT_TRUE(dm.GetDeviceNumber(dev.name(), &dev_number)); ASSERT_NE(dev_number, 0); std::string dev_string; ASSERT_TRUE(dm.GetDeviceString(dev.name(), &dev_string)); ASSERT_FALSE(dev_string.empty()); // Note: a scope is needed to ensure that there are no open descriptors // when we go to close the device. { Loading @@ -157,7 +167,6 @@ TEST(libdm, DmLinear) { } // Test GetTableStatus. DeviceMapper& dm = DeviceMapper::Instance(); vector<DeviceMapper::TargetInfo> targets; ASSERT_TRUE(dm.GetTableStatus(dev.name(), &targets)); ASSERT_EQ(targets.size(), 2); Loading
fs_mgr/libdm/include/libdm/dm.h +8 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ #include <fcntl.h> #include <linux/dm-ioctl.h> #include <linux/kdev_t.h> #include <linux/types.h> #include <stdint.h> #include <sys/sysmacros.h> #include <unistd.h> Loading Loading @@ -111,6 +112,13 @@ class DeviceMapper final { // parameter is not set. bool GetDmDevicePathByName(const std::string& name, std::string* path); // Returns the dev_t for the named device-mapper node. bool GetDeviceNumber(const std::string& name, dev_t* dev); // Returns a major:minor string for the named device-mapper node, that can // be used as inputs to DmTargets that take a block device. bool GetDeviceString(const std::string& name, std::string* dev); // The only way to create a DeviceMapper object. static DeviceMapper& Instance(); Loading
fs_mgr/libdm/include/libdm/loop_control.h +3 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,9 @@ class LoopControl final { // Detach the loop device given by 'loopdev' from the attached backing file. bool Detach(const std::string& loopdev) const; // Enable Direct I/O on a loop device. This requires kernel 4.9+. static bool EnableDirectIo(int fd); LoopControl(const LoopControl&) = delete; LoopControl& operator=(const LoopControl&) = delete; LoopControl& operator=(LoopControl&&) = default; Loading