Merge "[incfs] Use the new libincfs API for file status checking" into sc-dev

This commit is contained in:
TreeHugger Robot
2021-03-19 01:19:05 +00:00
committed by Android (Google) Code Review
6 changed files with 42 additions and 49 deletions

View File

@@ -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();
}

View File

@@ -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;
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);
}
if (totalBlocks < filledBlocks) {
LOG(ERROR) << "isFileFullyLoadedFromPath failed to get total num of blocks";
return -EINVAL;
}
return totalBlocks - filledBlocks;
return mIncFs->isEverythingFullyLoaded(ifs->control);
}
IncrementalService::LoadingProgress IncrementalService::getLoadingProgress(

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -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();
TEST_F(IncrementalServiceTest, testIsFileFullyLoadedNoData) {
TemporaryDir tempDir;
int storageId =
mIncrementalService->createStorage(tempDir.path, mDataLoaderParcel,
IncrementalService::CreateOptions::CreateNew);
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, testIsFileFullyLoadedFailsWithFailedRanges) {
mIncFs->countFilledBlocksFails();
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(-1, mIncrementalService->isFileFullyLoaded(storageId, "base.apk"));
}
TEST_F(IncrementalServiceTest, testIsFileFullyLoadedSuccessWithEmptyRanges) {
mIncFs->countFilledBlocksEmpty();
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(-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) {