libdm: Fix DmTable::num_sectors
Test: libdm_test
Change-Id: If147df2d5c4f3b3df7ca57200f16a9ad59ae8327
diff --git a/fs_mgr/libdm/dm_table.cpp b/fs_mgr/libdm/dm_table.cpp
index 15c7ce1..efe03ab 100644
--- a/fs_mgr/libdm/dm_table.cpp
+++ b/fs_mgr/libdm/dm_table.cpp
@@ -26,6 +26,7 @@
if (!target->Valid()) {
return false;
}
+ num_sectors_ += target->size();
targets_.push_back(std::move(target));
return true;
}
diff --git a/fs_mgr/libdm/dm_test.cpp b/fs_mgr/libdm/dm_test.cpp
index eed21dc..39c908d 100644
--- a/fs_mgr/libdm/dm_test.cpp
+++ b/fs_mgr/libdm/dm_test.cpp
@@ -114,6 +114,7 @@
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());
+ ASSERT_EQ(2u, table.num_sectors());
TempDevice dev("libdm-test-dm-linear", table);
ASSERT_TRUE(dev.valid());
@@ -176,6 +177,7 @@
DmTable table;
ASSERT_TRUE(table.Emplace<DmTargetLinear>(0, 1, loop_a.device(), 0));
ASSERT_TRUE(table.valid());
+ ASSERT_EQ(1u, table.num_sectors());
TempDevice dev("libdm-test-dm-suspend-resume", table);
ASSERT_TRUE(dev.valid());
@@ -292,6 +294,7 @@
ASSERT_TRUE(origin_table.AddTarget(make_unique<DmTargetSnapshotOrigin>(
0, kBaseDeviceSize / kSectorSize, base_loop_->device())));
ASSERT_TRUE(origin_table.valid());
+ ASSERT_EQ(kBaseDeviceSize / kSectorSize, origin_table.num_sectors());
origin_dev_ = std::make_unique<TempDevice>("libdm-test-dm-snapshot-origin", origin_table);
ASSERT_TRUE(origin_dev_->valid());
@@ -303,6 +306,7 @@
0, kBaseDeviceSize / kSectorSize, base_loop_->device(), cow_loop_->device(),
SnapshotStorageMode::Persistent, 8)));
ASSERT_TRUE(snap_table.valid());
+ ASSERT_EQ(kBaseDeviceSize / kSectorSize, snap_table.num_sectors());
snapshot_dev_ = std::make_unique<TempDevice>("libdm-test-dm-snapshot", snap_table);
ASSERT_TRUE(snapshot_dev_->valid());
@@ -322,6 +326,7 @@
make_unique<DmTargetSnapshot>(0, kBaseDeviceSize / kSectorSize, base_loop_->device(),
cow_loop_->device(), SnapshotStorageMode::Merge, 8)));
ASSERT_TRUE(merge_table.valid());
+ ASSERT_EQ(kBaseDeviceSize / kSectorSize, merge_table.num_sectors());
DeviceMapper& dm = DeviceMapper::Instance();
ASSERT_TRUE(dm.LoadTableAndActivate("libdm-test-dm-snapshot", merge_table));