Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http: Report errors reading discs #11700

Merged
merged 3 commits into from
Dec 27, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Loaders: Refactor chaining to avoid dup code.
  • Loading branch information
unknownbrackets committed Dec 27, 2018
commit 7f84c87931eaafd1ddb3928292bf8ee85c5be195
24 changes: 5 additions & 19 deletions Core/FileLoaders/CachingFileLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@

// Takes ownership of backend.
CachingFileLoader::CachingFileLoader(FileLoader *backend)
: backend_(backend) {
: ProxiedFileLoader(backend) {
}

void CachingFileLoader::Prepare() {
std::call_once(preparedFlag_, [this](){
filesize_ = backend_->FileSize();
filesize_ = ProxiedFileLoader::FileSize();
if (filesize_ > 0) {
InitCache();
}
Expand All @@ -41,27 +41,25 @@ CachingFileLoader::~CachingFileLoader() {
if (filesize_ > 0) {
ShutdownCache();
}
// Takes ownership.
delete backend_;
}

bool CachingFileLoader::Exists() {
if (exists_ == -1) {
exists_ = backend_->Exists() ? 1 : 0;
exists_ = ProxiedFileLoader::Exists() ? 1 : 0;
}
return exists_ == 1;
}

bool CachingFileLoader::ExistsFast() {
if (exists_ == -1) {
return backend_->ExistsFast();
return ProxiedFileLoader::ExistsFast();
}
return exists_ == 1;
}

bool CachingFileLoader::IsDirectory() {
if (isDirectory_ == -1) {
isDirectory_ = backend_->IsDirectory() ? 1 : 0;
isDirectory_ = ProxiedFileLoader::IsDirectory() ? 1 : 0;
}
return isDirectory_ == 1;
}
Expand All @@ -71,10 +69,6 @@ s64 CachingFileLoader::FileSize() {
return filesize_;
}

std::string CachingFileLoader::Path() const {
return backend_->Path();
}

size_t CachingFileLoader::ReadAt(s64 absolutePos, size_t bytes, void *data, Flags flags) {
Prepare();
if (absolutePos >= filesize_) {
Expand Down Expand Up @@ -288,11 +282,3 @@ void CachingFileLoader::StartReadAhead(s64 pos) {
});
th.detach();
}

bool CachingFileLoader::IsRemote() {
return backend_->IsRemote();
}

void CachingFileLoader::Cancel() {
backend_->Cancel();
}
7 changes: 1 addition & 6 deletions Core/FileLoaders/CachingFileLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,21 @@
#include "Common/CommonTypes.h"
#include "Core/Loaders.h"

class CachingFileLoader : public FileLoader {
class CachingFileLoader : public ProxiedFileLoader {
public:
CachingFileLoader(FileLoader *backend);
~CachingFileLoader() override;

bool IsRemote() override;
bool Exists() override;
bool ExistsFast() override;
bool IsDirectory() override;
s64 FileSize() override;
std::string Path() const override;

size_t ReadAt(s64 absolutePos, size_t bytes, size_t count, void *data, Flags flags = Flags::NONE) override {
return ReadAt(absolutePos, bytes * count, data, flags) / bytes;
}
size_t ReadAt(s64 absolutePos, size_t bytes, void *data, Flags flags = Flags::NONE) override;

void Cancel() override;

private:
void Prepare();
void InitCache();
Expand All @@ -61,7 +57,6 @@ class CachingFileLoader : public FileLoader {
};

s64 filesize_ = 0;
FileLoader *backend_;
int exists_ = -1;
int isDirectory_ = -1;
u64 generation_;
Expand Down
28 changes: 5 additions & 23 deletions Core/FileLoaders/DiskCachingFileLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ std::mutex DiskCachingFileLoader::cachesMutex_;

// Takes ownership of backend.
DiskCachingFileLoader::DiskCachingFileLoader(FileLoader *backend)
: backend_(backend) {
: ProxiedFileLoader(backend) {
}

void DiskCachingFileLoader::Prepare() {
std::call_once(preparedFlag_, [this]() {
filesize_ = backend_->FileSize();
filesize_ = ProxiedFileLoader::FileSize();
if (filesize_ > 0) {
InitCache();
}
Expand All @@ -57,13 +57,11 @@ DiskCachingFileLoader::~DiskCachingFileLoader() {
if (filesize_ > 0) {
ShutdownCache();
}
// Takes ownership.
delete backend_;
}

bool DiskCachingFileLoader::Exists() {
Prepare();
return backend_->Exists();
return ProxiedFileLoader::Exists();
}

bool DiskCachingFileLoader::ExistsFast() {
Expand All @@ -72,19 +70,11 @@ bool DiskCachingFileLoader::ExistsFast() {
return true;
}

bool DiskCachingFileLoader::IsDirectory() {
return backend_->IsDirectory();
}

s64 DiskCachingFileLoader::FileSize() {
Prepare();
return filesize_;
}

std::string DiskCachingFileLoader::Path() const {
return backend_->Path();
}

size_t DiskCachingFileLoader::ReadAt(s64 absolutePos, size_t bytes, void *data, Flags flags) {
Prepare();
size_t readSize;
Expand Down Expand Up @@ -115,14 +105,6 @@ size_t DiskCachingFileLoader::ReadAt(s64 absolutePos, size_t bytes, void *data,
return readSize;
}

bool DiskCachingFileLoader::IsRemote() {
return backend_->IsRemote();
}

void DiskCachingFileLoader::Cancel() {
backend_->Cancel();
}

std::vector<std::string> DiskCachingFileLoader::GetCachedPathsInUse() {
std::lock_guard<std::mutex> guard(cachesMutex_);

Expand All @@ -139,7 +121,7 @@ std::vector<std::string> DiskCachingFileLoader::GetCachedPathsInUse() {
void DiskCachingFileLoader::InitCache() {
std::lock_guard<std::mutex> guard(cachesMutex_);

std::string path = backend_->Path();
std::string path = ProxiedFileLoader::Path();
auto &entry = caches_[path];
if (!entry) {
entry = new DiskCachingFileLoaderCache(path, filesize_);
Expand All @@ -155,7 +137,7 @@ void DiskCachingFileLoader::ShutdownCache() {
if (cache_->Release()) {
// If it ran out of counts, delete it.
delete cache_;
caches_.erase(backend_->Path());
caches_.erase(ProxiedFileLoader::Path());
}
cache_ = nullptr;
}
Expand Down
8 changes: 1 addition & 7 deletions Core/FileLoaders/DiskCachingFileLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,20 @@

class DiskCachingFileLoaderCache;

class DiskCachingFileLoader : public FileLoader {
class DiskCachingFileLoader : public ProxiedFileLoader {
public:
DiskCachingFileLoader(FileLoader *backend);
~DiskCachingFileLoader() override;

bool IsRemote() override;
bool Exists() override;
bool ExistsFast() override;
bool IsDirectory() override;
s64 FileSize() override;
std::string Path() const override;

size_t ReadAt(s64 absolutePos, size_t bytes, size_t count, void *data, Flags flags = Flags::NONE) override {
return ReadAt(absolutePos, bytes * count, data, flags) / bytes;
}
size_t ReadAt(s64 absolutePos, size_t bytes, void *data, Flags flags = Flags::NONE) override;

void Cancel() override;

static std::vector<std::string> GetCachedPathsInUse();

private:
Expand All @@ -55,7 +50,6 @@ class DiskCachingFileLoader : public FileLoader {

std::once_flag preparedFlag_;
s64 filesize_ = 0;
FileLoader *backend_;
DiskCachingFileLoaderCache *cache_ = nullptr;

// We don't support concurrent disk cache access (we use memory cached indexes.)
Expand Down
20 changes: 5 additions & 15 deletions Core/FileLoaders/RamCachingFileLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

// Takes ownership of backend.
RamCachingFileLoader::RamCachingFileLoader(FileLoader *backend)
: backend_(backend) {
: ProxiedFileLoader(backend) {
filesize_ = backend->FileSize();
if (filesize_ > 0) {
InitCache();
Expand All @@ -39,27 +39,25 @@ RamCachingFileLoader::~RamCachingFileLoader() {
if (filesize_ > 0) {
ShutdownCache();
}
// Takes ownership.
delete backend_;
}

bool RamCachingFileLoader::Exists() {
if (exists_ == -1) {
exists_ = backend_->Exists() ? 1 : 0;
exists_ = ProxiedFileLoader::Exists() ? 1 : 0;
}
return exists_ == 1;
}

bool RamCachingFileLoader::ExistsFast() {
if (exists_ == -1) {
return backend_->ExistsFast();
return ProxiedFileLoader::ExistsFast();
}
return exists_ == 1;
}

bool RamCachingFileLoader::IsDirectory() {
if (isDirectory_ == -1) {
isDirectory_ = backend_->IsDirectory() ? 1 : 0;
isDirectory_ = ProxiedFileLoader::IsDirectory() ? 1 : 0;
}
return isDirectory_ == 1;
}
Expand All @@ -68,10 +66,6 @@ s64 RamCachingFileLoader::FileSize() {
return filesize_;
}

std::string RamCachingFileLoader::Path() const {
return backend_->Path();
}

size_t RamCachingFileLoader::ReadAt(s64 absolutePos, size_t bytes, void *data, Flags flags) {
size_t readSize = 0;
if (cache_ == nullptr || (flags & Flags::HINT_UNCACHED) != 0) {
Expand Down Expand Up @@ -129,7 +123,7 @@ void RamCachingFileLoader::Cancel() {
aheadCancel_ = true;
}

backend_->Cancel();
ProxiedFileLoader::Cancel();
}

size_t RamCachingFileLoader::ReadFromCache(s64 pos, size_t bytes, void *data) {
Expand Down Expand Up @@ -270,7 +264,3 @@ u32 RamCachingFileLoader::NextAheadBlock() {

return 0xFFFFFFFF;
}

bool RamCachingFileLoader::IsRemote() {
return backend_->IsRemote();
}
5 changes: 1 addition & 4 deletions Core/FileLoaders/RamCachingFileLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,15 @@
#include "Common/CommonTypes.h"
#include "Core/Loaders.h"

class RamCachingFileLoader : public FileLoader {
class RamCachingFileLoader : public ProxiedFileLoader {
public:
RamCachingFileLoader(FileLoader *backend);
~RamCachingFileLoader() override;

bool IsRemote() override;
bool Exists() override;
bool ExistsFast() override;
bool IsDirectory() override;
s64 FileSize() override;
std::string Path() const override;

size_t ReadAt(s64 absolutePos, size_t bytes, size_t count, void *data, Flags flags = Flags::NONE) override {
return ReadAt(absolutePos, bytes * count, data, flags) / bytes;
Expand All @@ -59,7 +57,6 @@ class RamCachingFileLoader : public FileLoader {
};

s64 filesize_ = 0;
FileLoader *backend_;
u8 *cache_ = nullptr;
int exists_ = -1;
int isDirectory_ = -1;
Expand Down
33 changes: 8 additions & 25 deletions Core/FileLoaders/RetryingFileLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,47 +19,38 @@

// Takes ownership of backend.
RetryingFileLoader::RetryingFileLoader(FileLoader *backend)
: backend_(backend) {
}

RetryingFileLoader::~RetryingFileLoader() {
// Takes ownership.
delete backend_;
: ProxiedFileLoader(backend) {
}

bool RetryingFileLoader::Exists() {
if (!backend_->Exists()) {
if (!ProxiedFileLoader::Exists()) {
// Retry once, immediately.
return backend_->Exists();
return ProxiedFileLoader::Exists();
}
return true;
}

bool RetryingFileLoader::ExistsFast() {
if (!backend_->ExistsFast()) {
if (!ProxiedFileLoader::ExistsFast()) {
// Retry once, immediately.
return backend_->ExistsFast();
return ProxiedFileLoader::ExistsFast();
}
return true;
}

bool RetryingFileLoader::IsDirectory() {
// Can't tell if it's an error either way.
return backend_->IsDirectory();
return ProxiedFileLoader::IsDirectory();
}

s64 RetryingFileLoader::FileSize() {
s64 filesize = backend_->FileSize();
s64 filesize = ProxiedFileLoader::FileSize();
if (filesize == 0) {
return backend_->FileSize();
return ProxiedFileLoader::FileSize();
}
return filesize;
}

std::string RetryingFileLoader::Path() const {
return backend_->Path();
}

size_t RetryingFileLoader::ReadAt(s64 absolutePos, size_t bytes, void *data, Flags flags) {
size_t readSize = backend_->ReadAt(absolutePos, bytes, data, flags);

Expand All @@ -72,11 +63,3 @@ size_t RetryingFileLoader::ReadAt(s64 absolutePos, size_t bytes, void *data, Fla

return readSize;
}

bool RetryingFileLoader::IsRemote() {
return backend_->IsRemote();
}

void RetryingFileLoader::Cancel() {
backend_->Cancel();
}
Loading