diff options
author | 2021-03-18 14:21:54 -0700 | |
---|---|---|
committer | 2021-03-18 14:24:21 -0700 | |
commit | 256a1a450402fde4a958c7680600d2c94c7c737e (patch) | |
tree | 97eb9035c7e4c6bf73ca6da717c672dbb229467b /services/incremental | |
parent | 463ec227c62975953cd298259b88d640c755d7ca (diff) |
[incfs] Use the new libincfs API for file status checking
libincfs got a new set of functions for checking the file loaded
status, which works more efficiently than getting filled ranges.
Bug: 183067554
Test: atest IncrementalServiceTest
Change-Id: I3b96bf409f1778c5a89e4802e2005197f70ce0cb
Diffstat (limited to 'services/incremental')
-rw-r--r-- | services/incremental/BinderIncrementalService.cpp | 5 | ||||
-rw-r--r-- | services/incremental/IncrementalService.cpp | 27 | ||||
-rw-r--r-- | services/incremental/IncrementalService.h | 4 | ||||
-rw-r--r-- | services/incremental/ServiceWrappers.cpp | 7 | ||||
-rw-r--r-- | services/incremental/ServiceWrappers.h | 3 | ||||
-rw-r--r-- | services/incremental/test/IncrementalServiceTest.cpp | 45 |
6 files changed, 42 insertions, 49 deletions
diff --git a/services/incremental/BinderIncrementalService.cpp b/services/incremental/BinderIncrementalService.cpp index 8f12b2e5c132..9869b075b36f 100644 --- a/services/incremental/BinderIncrementalService.cpp +++ b/services/incremental/BinderIncrementalService.cpp @@ -255,13 +255,12 @@ binder::Status BinderIncrementalService::unlink(int32_t storageId, const std::st binder::Status BinderIncrementalService::isFileFullyLoaded(int32_t storageId, const std::string& path, int32_t* _aidl_return) { - *_aidl_return = mImpl.isFileFullyLoaded(storageId, path); + *_aidl_return = (int)mImpl.isFileFullyLoaded(storageId, path); return ok(); } binder::Status BinderIncrementalService::isFullyLoaded(int32_t storageId, int32_t* _aidl_return) { - *_aidl_return = mImpl.getLoadingProgress(storageId, /*stopOnFirstIncomplete=*/true) - .blocksRemainingOrError(); + *_aidl_return = (int)mImpl.isMountFullyLoaded(storageId); return ok(); } diff --git a/services/incremental/IncrementalService.cpp b/services/incremental/IncrementalService.cpp index db70d44d37f6..ebfcc3262ef5 100644 --- a/services/incremental/IncrementalService.cpp +++ b/services/incremental/IncrementalService.cpp @@ -1980,35 +1980,30 @@ int IncrementalService::setFileContent(const IfsMountPtr& ifs, const incfs::File return 0; } -int IncrementalService::isFileFullyLoaded(StorageId storage, std::string_view filePath) const { +incfs::LoadingState IncrementalService::isFileFullyLoaded(StorageId storage, + std::string_view filePath) const { std::unique_lock l(mLock); const auto ifs = getIfsLocked(storage); if (!ifs) { LOG(ERROR) << "isFileFullyLoaded failed, invalid storageId: " << storage; - return -EINVAL; + return incfs::LoadingState(-EINVAL); } const auto storageInfo = ifs->storages.find(storage); if (storageInfo == ifs->storages.end()) { LOG(ERROR) << "isFileFullyLoaded failed, no storage: " << storage; - return -EINVAL; + return incfs::LoadingState(-EINVAL); } l.unlock(); - return isFileFullyLoadedFromPath(*ifs, filePath); + return mIncFs->isFileFullyLoaded(ifs->control, filePath); } -int IncrementalService::isFileFullyLoadedFromPath(const IncFsMount& ifs, - std::string_view filePath) const { - const auto [filledBlocks, totalBlocks] = mIncFs->countFilledBlocks(ifs.control, filePath); - if (filledBlocks < 0) { - LOG(ERROR) << "isFileFullyLoadedFromPath failed to get filled blocks count for: " - << filePath << " errno: " << filledBlocks; - return filledBlocks; - } - if (totalBlocks < filledBlocks) { - LOG(ERROR) << "isFileFullyLoadedFromPath failed to get total num of blocks"; - return -EINVAL; +incfs::LoadingState IncrementalService::isMountFullyLoaded(StorageId storage) const { + const auto ifs = getIfs(storage); + if (!ifs) { + LOG(ERROR) << "isMountFullyLoaded failed, invalid storageId: " << storage; + return incfs::LoadingState(-EINVAL); } - return totalBlocks - filledBlocks; + return mIncFs->isEverythingFullyLoaded(ifs->control); } IncrementalService::LoadingProgress IncrementalService::getLoadingProgress( diff --git a/services/incremental/IncrementalService.h b/services/incremental/IncrementalService.h index bc441c792084..aa80bd43cc57 100644 --- a/services/incremental/IncrementalService.h +++ b/services/incremental/IncrementalService.h @@ -164,7 +164,8 @@ public: std::string_view newPath); int unlink(StorageId storage, std::string_view path); - int isFileFullyLoaded(StorageId storage, std::string_view filePath) const; + incfs::LoadingState isFileFullyLoaded(StorageId storage, std::string_view filePath) const; + incfs::LoadingState isMountFullyLoaded(StorageId storage) const; LoadingProgress getLoadingProgress(StorageId storage, bool stopOnFirstIncomplete) const; @@ -412,7 +413,6 @@ private: int setStorageParams(IncFsMount& ifs, StorageId storageId, bool enableReadLogs); binder::Status applyStorageParams(IncFsMount& ifs, bool enableReadLogs); - int isFileFullyLoadedFromPath(const IncFsMount& ifs, std::string_view filePath) const; LoadingProgress getLoadingProgressFromPath(const IncFsMount& ifs, std::string_view path, bool stopOnFirstIncomplete) const; diff --git a/services/incremental/ServiceWrappers.cpp b/services/incremental/ServiceWrappers.cpp index 2a061226b713..eb204c5466e0 100644 --- a/services/incremental/ServiceWrappers.cpp +++ b/services/incremental/ServiceWrappers.cpp @@ -197,6 +197,13 @@ public: } return {filledBlockCount, totalBlocksCount}; } + incfs::LoadingState isFileFullyLoaded(const Control& control, + std::string_view path) const final { + return incfs::isFullyLoaded(control, path); + } + incfs::LoadingState isEverythingFullyLoaded(const Control& control) const final { + return incfs::isEverythingFullyLoaded(control); + } ErrorCode link(const Control& control, std::string_view from, std::string_view to) const final { return incfs::link(control, from, to); } diff --git a/services/incremental/ServiceWrappers.h b/services/incremental/ServiceWrappers.h index 231b76ff1701..2f3eb24182e4 100644 --- a/services/incremental/ServiceWrappers.h +++ b/services/incremental/ServiceWrappers.h @@ -102,6 +102,9 @@ public: virtual std::string toString(FileId fileId) const = 0; virtual std::pair<IncFsBlockIndex, IncFsBlockIndex> countFilledBlocks( const Control& control, std::string_view path) const = 0; + virtual incfs::LoadingState isFileFullyLoaded(const Control& control, + std::string_view path) const = 0; + virtual incfs::LoadingState isEverythingFullyLoaded(const Control& control) const = 0; virtual ErrorCode link(const Control& control, std::string_view from, std::string_view to) const = 0; virtual ErrorCode unlink(const Control& control, std::string_view path) const = 0; diff --git a/services/incremental/test/IncrementalServiceTest.cpp b/services/incremental/test/IncrementalServiceTest.cpp index 45b796bf4704..50d1e3612cb0 100644 --- a/services/incremental/test/IncrementalServiceTest.cpp +++ b/services/incremental/test/IncrementalServiceTest.cpp @@ -366,6 +366,9 @@ public: MOCK_CONST_METHOD2(countFilledBlocks, std::pair<IncFsBlockIndex, IncFsBlockIndex>(const Control& control, std::string_view path)); + MOCK_CONST_METHOD2(isFileFullyLoaded, + incfs::LoadingState(const Control& control, std::string_view path)); + MOCK_CONST_METHOD1(isEverythingFullyLoaded, incfs::LoadingState(const Control& control)); MOCK_CONST_METHOD3(link, ErrorCode(const Control& control, std::string_view from, std::string_view to)); @@ -1563,51 +1566,37 @@ TEST_F(IncrementalServiceTest, testMakeDirectories) { ASSERT_EQ(res, 0); } -TEST_F(IncrementalServiceTest, testIsFileFullyLoadedFailsWithNoFile) { - mIncFs->countFilledBlocksFails(); - mFs->hasNoFile(); - - TemporaryDir tempDir; - int storageId = - mIncrementalService->createStorage(tempDir.path, mDataLoaderParcel, - IncrementalService::CreateOptions::CreateNew); - ASSERT_EQ(-1, mIncrementalService->isFileFullyLoaded(storageId, "base.apk")); -} - -TEST_F(IncrementalServiceTest, testIsFileFullyLoadedFailsWithFailedRanges) { - mIncFs->countFilledBlocksFails(); - mFs->hasFiles(); - +TEST_F(IncrementalServiceTest, testIsFileFullyLoadedNoData) { TemporaryDir tempDir; int storageId = mIncrementalService->createStorage(tempDir.path, mDataLoaderParcel, IncrementalService::CreateOptions::CreateNew); - EXPECT_CALL(*mIncFs, countFilledBlocks(_, _)).Times(1); - ASSERT_EQ(-1, mIncrementalService->isFileFullyLoaded(storageId, "base.apk")); + EXPECT_CALL(*mIncFs, isFileFullyLoaded(_, _)) + .Times(1) + .WillOnce(Return(incfs::LoadingState::MissingBlocks)); + ASSERT_GT((int)mIncrementalService->isFileFullyLoaded(storageId, "base.apk"), 0); } -TEST_F(IncrementalServiceTest, testIsFileFullyLoadedSuccessWithEmptyRanges) { - mIncFs->countFilledBlocksEmpty(); - mFs->hasFiles(); - +TEST_F(IncrementalServiceTest, testIsFileFullyLoadedError) { TemporaryDir tempDir; int storageId = mIncrementalService->createStorage(tempDir.path, mDataLoaderParcel, IncrementalService::CreateOptions::CreateNew); - EXPECT_CALL(*mIncFs, countFilledBlocks(_, _)).Times(1); - ASSERT_EQ(0, mIncrementalService->isFileFullyLoaded(storageId, "base.apk")); + EXPECT_CALL(*mIncFs, isFileFullyLoaded(_, _)) + .Times(1) + .WillOnce(Return(incfs::LoadingState(-1))); + ASSERT_LT((int)mIncrementalService->isFileFullyLoaded(storageId, "base.apk"), 0); } TEST_F(IncrementalServiceTest, testIsFileFullyLoadedSuccess) { - mIncFs->countFilledBlocksFullyLoaded(); - mFs->hasFiles(); - TemporaryDir tempDir; int storageId = mIncrementalService->createStorage(tempDir.path, mDataLoaderParcel, IncrementalService::CreateOptions::CreateNew); - EXPECT_CALL(*mIncFs, countFilledBlocks(_, _)).Times(1); - ASSERT_EQ(0, mIncrementalService->isFileFullyLoaded(storageId, "base.apk")); + EXPECT_CALL(*mIncFs, isFileFullyLoaded(_, _)) + .Times(1) + .WillOnce(Return(incfs::LoadingState::Full)); + ASSERT_EQ(0, (int)mIncrementalService->isFileFullyLoaded(storageId, "base.apk")); } TEST_F(IncrementalServiceTest, testGetLoadingProgressSuccessWithNoFile) { |