Merge changes I7bb0b559,If147df2d,I25d7d590
* changes: libsnapshot: Skip initializing snapshot if not created. libdm: Fix DmTable::num_sectors Fix fds libdm_test
This commit is contained in:
commit
58ae8d4780
|
@ -26,6 +26,7 @@ bool DmTable::AddTarget(std::unique_ptr<DmTarget>&& target) {
|
|||
if (!target->Valid()) {
|
||||
return false;
|
||||
}
|
||||
num_sectors_ += target->size();
|
||||
targets_.push_back(std::move(target));
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -114,6 +114,7 @@ TEST(libdm, DmLinear) {
|
|||
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 @@ TEST(libdm, DmSuspendResume) {
|
|||
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 @@ void SnapshotTestHarness::SetupImpl() {
|
|||
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 @@ void SnapshotTestHarness::SetupImpl() {
|
|||
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 @@ void SnapshotTestHarness::MergeImpl() {
|
|||
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));
|
||||
|
|
|
@ -64,7 +64,8 @@ class LoopDevice {
|
|||
public:
|
||||
// Create a loop device for the given file descriptor. It is closed when
|
||||
// LoopDevice is destroyed only if auto_close is true.
|
||||
LoopDevice(int fd, const std::chrono::milliseconds& timeout_ms, bool auto_close = false);
|
||||
LoopDevice(android::base::borrowed_fd fd, const std::chrono::milliseconds& timeout_ms,
|
||||
bool auto_close = false);
|
||||
// Create a loop device for the given file path. It will be opened for
|
||||
// reading and writing and closed when the loop device is detached.
|
||||
LoopDevice(const std::string& path, const std::chrono::milliseconds& timeout_ms);
|
||||
|
@ -81,8 +82,8 @@ class LoopDevice {
|
|||
private:
|
||||
void Init(const std::chrono::milliseconds& timeout_ms);
|
||||
|
||||
android::base::unique_fd fd_;
|
||||
bool owns_fd_;
|
||||
android::base::borrowed_fd fd_;
|
||||
android::base::unique_fd owned_fd_;
|
||||
std::string device_;
|
||||
LoopControl control_;
|
||||
bool valid_ = false;
|
||||
|
|
|
@ -133,18 +133,23 @@ bool LoopControl::EnableDirectIo(int fd) {
|
|||
return true;
|
||||
}
|
||||
|
||||
LoopDevice::LoopDevice(int fd, const std::chrono::milliseconds& timeout_ms, bool auto_close)
|
||||
: fd_(fd), owns_fd_(auto_close) {
|
||||
LoopDevice::LoopDevice(android::base::borrowed_fd fd, const std::chrono::milliseconds& timeout_ms,
|
||||
bool auto_close)
|
||||
: fd_(fd), owned_fd_(-1) {
|
||||
if (auto_close) {
|
||||
owned_fd_.reset(fd.get());
|
||||
}
|
||||
Init(timeout_ms);
|
||||
}
|
||||
|
||||
LoopDevice::LoopDevice(const std::string& path, const std::chrono::milliseconds& timeout_ms)
|
||||
: fd_(-1), owns_fd_(true) {
|
||||
fd_.reset(open(path.c_str(), O_RDWR | O_CLOEXEC));
|
||||
if (fd_ < -1) {
|
||||
: fd_(-1), owned_fd_(-1) {
|
||||
owned_fd_.reset(open(path.c_str(), O_RDWR | O_CLOEXEC));
|
||||
if (owned_fd_ == -1) {
|
||||
PLOG(ERROR) << "open failed for " << path;
|
||||
return;
|
||||
}
|
||||
fd_ = owned_fd_;
|
||||
Init(timeout_ms);
|
||||
}
|
||||
|
||||
|
@ -152,13 +157,10 @@ LoopDevice::~LoopDevice() {
|
|||
if (valid()) {
|
||||
control_.Detach(device_);
|
||||
}
|
||||
if (!owns_fd_) {
|
||||
(void)fd_.release();
|
||||
}
|
||||
}
|
||||
|
||||
void LoopDevice::Init(const std::chrono::milliseconds& timeout_ms) {
|
||||
valid_ = control_.Attach(fd_, timeout_ms, &device_);
|
||||
valid_ = control_.Attach(fd_.get(), timeout_ms, &device_);
|
||||
}
|
||||
|
||||
} // namespace dm
|
||||
|
|
|
@ -1978,7 +1978,7 @@ bool SnapshotManager::InitializeUpdateSnapshots(
|
|||
}
|
||||
|
||||
auto it = all_snapshot_status.find(target_partition->name());
|
||||
CHECK(it != all_snapshot_status.end()) << target_partition->name();
|
||||
if (it == all_snapshot_status.end()) continue;
|
||||
cow_params.partition_name = target_partition->name();
|
||||
std::string cow_name;
|
||||
if (!MapCowDevices(lock, cow_params, it->second, &created_devices_for_cow, &cow_name)) {
|
||||
|
|
Loading…
Reference in New Issue