mirror of https://github.com/aria2/aria2
Use enum to select file allocation method
parent
27e44439ea
commit
e2fcd6d72c
|
@ -98,20 +98,22 @@ void AbstractSingleDiskAdaptor::truncate(int64_t length)
|
||||||
SharedHandle<FileAllocationIterator>
|
SharedHandle<FileAllocationIterator>
|
||||||
AbstractSingleDiskAdaptor::fileAllocationIterator()
|
AbstractSingleDiskAdaptor::fileAllocationIterator()
|
||||||
{
|
{
|
||||||
|
switch(getFileAllocationMethod()) {
|
||||||
#ifdef HAVE_SOME_FALLOCATE
|
#ifdef HAVE_SOME_FALLOCATE
|
||||||
if(doesFallocate()) {
|
case(DiskAdaptor::FILE_ALLOC_FALLOC): {
|
||||||
SharedHandle<FallocFileAllocationIterator> h
|
SharedHandle<FallocFileAllocationIterator> h
|
||||||
(new FallocFileAllocationIterator
|
(new FallocFileAllocationIterator
|
||||||
(diskWriter_.get(), size() ,totalLength_));
|
(diskWriter_.get(), size() ,totalLength_));
|
||||||
return h;
|
return h;
|
||||||
} else
|
}
|
||||||
#endif // HAVE_SOME_FALLOCATE
|
#endif // HAVE_SOME_FALLOCATE
|
||||||
{
|
default: {
|
||||||
SharedHandle<AdaptiveFileAllocationIterator> h
|
SharedHandle<AdaptiveFileAllocationIterator> h
|
||||||
(new AdaptiveFileAllocationIterator
|
(new AdaptiveFileAllocationIterator
|
||||||
(diskWriter_.get(), size(), totalLength_));
|
(diskWriter_.get(), size(), totalLength_));
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractSingleDiskAdaptor::enableReadOnly()
|
void AbstractSingleDiskAdaptor::enableReadOnly()
|
||||||
|
|
|
@ -634,7 +634,7 @@ void DefaultPieceStorage::initStorage()
|
||||||
diskAdaptor_ = multiDiskAdaptor;
|
diskAdaptor_ = multiDiskAdaptor;
|
||||||
}
|
}
|
||||||
if(option_->get(PREF_FILE_ALLOCATION) == V_FALLOC) {
|
if(option_->get(PREF_FILE_ALLOCATION) == V_FALLOC) {
|
||||||
diskAdaptor_->enableFallocate();
|
diskAdaptor_->setFileAllocationMethod(DiskAdaptor::FILE_ALLOC_FALLOC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
DiskAdaptor::DiskAdaptor()
|
DiskAdaptor::DiskAdaptor()
|
||||||
: fallocate_(false)
|
: fileAllocationMethod_(FILE_ALLOC_ADAPTIVE)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
DiskAdaptor::~DiskAdaptor() {}
|
DiskAdaptor::~DiskAdaptor() {}
|
||||||
|
|
|
@ -48,11 +48,12 @@ class FileEntry;
|
||||||
class FileAllocationIterator;
|
class FileAllocationIterator;
|
||||||
|
|
||||||
class DiskAdaptor:public BinaryStream {
|
class DiskAdaptor:public BinaryStream {
|
||||||
private:
|
|
||||||
std::vector<SharedHandle<FileEntry> > fileEntries_;
|
|
||||||
|
|
||||||
bool fallocate_;
|
|
||||||
public:
|
public:
|
||||||
|
enum FileAllocationMethod {
|
||||||
|
FILE_ALLOC_ADAPTIVE,
|
||||||
|
FILE_ALLOC_FALLOC
|
||||||
|
};
|
||||||
|
|
||||||
DiskAdaptor();
|
DiskAdaptor();
|
||||||
virtual ~DiskAdaptor();
|
virtual ~DiskAdaptor();
|
||||||
|
|
||||||
|
@ -100,20 +101,20 @@ public:
|
||||||
// successfully changed.
|
// successfully changed.
|
||||||
virtual size_t utime(const Time& actime, const Time& modtime) = 0;
|
virtual size_t utime(const Time& actime, const Time& modtime) = 0;
|
||||||
|
|
||||||
void enableFallocate()
|
void setFileAllocationMethod(FileAllocationMethod method)
|
||||||
{
|
{
|
||||||
fallocate_ = true;
|
fileAllocationMethod_ = method;
|
||||||
}
|
}
|
||||||
|
|
||||||
void disableFallocate()
|
int getFileAllocationMethod() const
|
||||||
{
|
{
|
||||||
fallocate_ = false;
|
return fileAllocationMethod_;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool doesFallocate() const
|
private:
|
||||||
{
|
std::vector<SharedHandle<FileEntry> > fileEntries_;
|
||||||
return fallocate_;
|
|
||||||
}
|
FileAllocationMethod fileAllocationMethod_;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SharedHandle<DiskAdaptor> DiskAdaptorHandle;
|
typedef SharedHandle<DiskAdaptor> DiskAdaptorHandle;
|
||||||
|
|
|
@ -67,20 +67,22 @@ void MultiFileAllocationIterator::allocateChunk()
|
||||||
diskAdaptor_->openIfNot(entry, &DiskWriterEntry::openFile);
|
diskAdaptor_->openIfNot(entry, &DiskWriterEntry::openFile);
|
||||||
if(entry->needsFileAllocation() && entry->size() < fileEntry->getLength()) {
|
if(entry->needsFileAllocation() && entry->size() < fileEntry->getLength()) {
|
||||||
// Calling private function of MultiDiskAdaptor.
|
// Calling private function of MultiDiskAdaptor.
|
||||||
|
switch(diskAdaptor_->getFileAllocationMethod()) {
|
||||||
#ifdef HAVE_SOME_FALLOCATE
|
#ifdef HAVE_SOME_FALLOCATE
|
||||||
if(diskAdaptor_->doesFallocate()) {
|
case(DiskAdaptor::FILE_ALLOC_FALLOC):
|
||||||
fileAllocationIterator_.reset
|
fileAllocationIterator_.reset
|
||||||
(new FallocFileAllocationIterator(entry->getDiskWriter().get(),
|
(new FallocFileAllocationIterator(entry->getDiskWriter().get(),
|
||||||
entry->size(),
|
entry->size(),
|
||||||
fileEntry->getLength()));
|
fileEntry->getLength()));
|
||||||
} else
|
break;
|
||||||
#endif // HAVE_SOME_FALLOCATE
|
#endif // HAVE_SOME_FALLOCATE
|
||||||
{
|
default:
|
||||||
fileAllocationIterator_.reset
|
fileAllocationIterator_.reset
|
||||||
(new AdaptiveFileAllocationIterator(entry->getDiskWriter().get(),
|
(new AdaptiveFileAllocationIterator(entry->getDiskWriter().get(),
|
||||||
entry->size(),
|
entry->size(),
|
||||||
fileEntry->getLength()));
|
fileEntry->getLength()));
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(finished()) {
|
if(finished()) {
|
||||||
|
|
Loading…
Reference in New Issue