[incfs] Use a more efficient getBlockCount() for incfs v2

v2 IncFS driver gives a very lightweight function to check the
loading progress on a file, use it instead of counting the
filled ranges

+ remove the unused mockable toString(IncFsFileId)

Bug: 183067554
Test: atest IncrementalServiceTest
Change-Id: Icd3bd891d671b27654f4194787a15a00cba1eb80
This commit is contained in:
Yurii Zubrytskyi
2021-03-18 16:59:47 -07:00
committed by Alex Buynytskyy
parent 667d242404
commit 4375a74535
4 changed files with 15 additions and 4 deletions

View File

@@ -2860,7 +2860,7 @@ void IncrementalService::DataLoaderStub::onDump(int fd) {
dprintf(fd, " lastPendingReads: \n");
const auto control = mService.mIncFs->openMount(mHealthPath);
for (auto&& pendingRead : mLastPendingReads) {
dprintf(fd, " fileId: %s\n", mService.mIncFs->toString(pendingRead.id).c_str());
dprintf(fd, " fileId: %s\n", IncFsWrapper::toString(pendingRead.id).c_str());
const auto metadata = mService.mIncFs->getMetadata(control, pendingRead.id);
dprintf(fd, " metadataHex: %s\n", toHexString(metadata).c_str());
dprintf(fd, " blockIndex: %d\n", pendingRead.block);

View File

@@ -134,6 +134,10 @@ private:
} mLooper;
};
std::string IncFsWrapper::toString(FileId fileId) {
return incfs::toString(fileId);
}
class RealIncFs final : public IncFsWrapper {
public:
RealIncFs() = default;
@@ -173,9 +177,16 @@ public:
FileId getFileId(const Control& control, std::string_view path) const final {
return incfs::getFileId(control, path);
}
std::string toString(FileId fileId) const final { return incfs::toString(fileId); }
std::pair<IncFsBlockIndex, IncFsBlockIndex> countFilledBlocks(
const Control& control, std::string_view path) const final {
if (incfs::features() & Features::v2) {
const auto counts = incfs::getBlockCount(control, path);
if (!counts) {
return {-errno, -errno};
}
return {counts->filledDataBlocks + counts->filledHashBlocks,
counts->totalDataBlocks + counts->totalHashBlocks};
}
const auto fileId = incfs::getFileId(control, path);
const auto fd = incfs::openForSpecialOps(control, fileId);
int res = fd.get();

View File

@@ -84,6 +84,8 @@ public:
void(std::string_view root, std::string_view backingDir,
std::span<std::pair<std::string_view, std::string_view>> binds)>;
static std::string toString(FileId fileId);
virtual ~IncFsWrapper() = default;
virtual Features features() const = 0;
virtual void listExistingMounts(const ExistingMountCallback& cb) const = 0;
@@ -99,7 +101,6 @@ public:
virtual incfs::RawMetadata getMetadata(const Control& control, FileId fileid) const = 0;
virtual incfs::RawMetadata getMetadata(const Control& control, std::string_view path) const = 0;
virtual FileId getFileId(const Control& control, std::string_view path) const = 0;
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,

View File

@@ -362,7 +362,6 @@ public:
MOCK_CONST_METHOD2(getMetadata, RawMetadata(const Control& control, FileId fileid));
MOCK_CONST_METHOD2(getMetadata, RawMetadata(const Control& control, std::string_view path));
MOCK_CONST_METHOD2(getFileId, FileId(const Control& control, std::string_view path));
MOCK_CONST_METHOD1(toString, std::string(FileId fileId));
MOCK_CONST_METHOD2(countFilledBlocks,
std::pair<IncFsBlockIndex, IncFsBlockIndex>(const Control& control,
std::string_view path));