From b9f734c9362af1eada8783fae6d93943aab0ecd7 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 3 Aug 2018 10:12:16 -0700 Subject: [PATCH] liblp: Add more logging for logical partition operations. This logs when partition tables update, when partitions resize, and when partitions are unmapped from device mapper. Bug: N/A Test: N/A Change-Id: I1125332c79fccc3ebc556b3b48856901e2503c47 --- fs_mgr/fs_mgr_dm_linear.cpp | 6 +++++- fs_mgr/liblp/builder.cpp | 13 +++++++++---- fs_mgr/liblp/utility.h | 2 ++ fs_mgr/liblp/writer.cpp | 13 +++++++++++-- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/fs_mgr/fs_mgr_dm_linear.cpp b/fs_mgr/fs_mgr_dm_linear.cpp index 05e03e152..aa68ceb18 100644 --- a/fs_mgr/fs_mgr_dm_linear.cpp +++ b/fs_mgr/fs_mgr_dm_linear.cpp @@ -133,7 +133,11 @@ bool CreateLogicalPartition(const std::string& block_device, uint32_t metadata_s bool DestroyLogicalPartition(const std::string& name) { DeviceMapper& dm = DeviceMapper::Instance(); - return dm.DeleteDevice(name); + if (!dm.DeleteDevice(name)) { + return false; + } + LINFO << "Unmapped logical partition " << name; + return true; } } // namespace fs_mgr diff --git a/fs_mgr/liblp/builder.cpp b/fs_mgr/liblp/builder.cpp index eb429b930..42c3eac0c 100644 --- a/fs_mgr/liblp/builder.cpp +++ b/fs_mgr/liblp/builder.cpp @@ -498,13 +498,18 @@ void MetadataBuilder::set_block_device_info(const BlockDeviceInfo& device_info) bool MetadataBuilder::ResizePartition(Partition* partition, uint64_t requested_size) { // Align the space needed up to the nearest sector. uint64_t aligned_size = AlignTo(requested_size, device_info_.logical_block_size); + uint64_t old_size = partition->size(); - if (aligned_size > partition->size()) { - return GrowPartition(partition, aligned_size); - } - if (aligned_size < partition->size()) { + if (aligned_size > old_size) { + if (!GrowPartition(partition, aligned_size)) { + return false; + } + } else if (aligned_size < partition->size()) { ShrinkPartition(partition, aligned_size); } + + LINFO << "Partition " << partition->name() << " will resize from " << old_size << " bytes to " + << aligned_size << " bytes"; return true; } diff --git a/fs_mgr/liblp/utility.h b/fs_mgr/liblp/utility.h index 452227550..6ef512479 100644 --- a/fs_mgr/liblp/utility.h +++ b/fs_mgr/liblp/utility.h @@ -26,6 +26,8 @@ #include "liblp/metadata_format.h" #define LP_TAG "[liblp]" +#define LWARN LOG(WARNING) << LP_TAG +#define LINFO LOG(INFO) << LP_TAG #define LERROR LOG(ERROR) << LP_TAG #define PERROR PLOG(ERROR) << LP_TAG diff --git a/fs_mgr/liblp/writer.cpp b/fs_mgr/liblp/writer.cpp index 156319b31..fc9d83fe3 100644 --- a/fs_mgr/liblp/writer.cpp +++ b/fs_mgr/liblp/writer.cpp @@ -304,7 +304,11 @@ bool FlashPartitionTable(const std::string& block_device, const LpMetadata& meta PERROR << __PRETTY_FUNCTION__ << "open failed: " << block_device; return false; } - return FlashPartitionTable(fd, metadata, slot_number); + if (!FlashPartitionTable(fd, metadata, slot_number)) { + return false; + } + LWARN << "Flashed new logical partition geometry to " << block_device; + return true; } bool UpdatePartitionTable(const std::string& block_device, const LpMetadata& metadata, @@ -314,7 +318,12 @@ bool UpdatePartitionTable(const std::string& block_device, const LpMetadata& met PERROR << __PRETTY_FUNCTION__ << "open failed: " << block_device; return false; } - return UpdatePartitionTable(fd, metadata, slot_number); + if (!UpdatePartitionTable(fd, metadata, slot_number)) { + return false; + } + LINFO << "Updated logical partition table at slot " << slot_number << " on device " + << block_device; + return true; } bool UpdatePartitionTable(int fd, const LpMetadata& metadata, uint32_t slot_number) {