2009-03-28 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Guarded #ifdef HAVE_POSIX_FALLOCATE
	* src/AbstractSingleDiskAdaptor.cc
	* src/DefaultPieceStorage.cc
	* src/DiskAdaptor.h
	* src/DiskAdaptor.h
	* src/MultiFileAllocationIterator.cc
pull/1/head
Tatsuhiro Tsujikawa 2009-03-28 12:46:13 +00:00
parent a69f499ccf
commit 6cbb6d2850
6 changed files with 45 additions and 18 deletions

View File

@ -1,3 +1,12 @@
2009-03-28 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Guarded #ifdef HAVE_POSIX_FALLOCATE
* src/AbstractSingleDiskAdaptor.cc
* src/DefaultPieceStorage.cc
* src/DiskAdaptor.h
* src/DiskAdaptor.h
* src/MultiFileAllocationIterator.cc
2009-03-28 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> 2009-03-28 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Run Run

View File

@ -35,7 +35,9 @@
#include "AbstractSingleDiskAdaptor.h" #include "AbstractSingleDiskAdaptor.h"
#include "File.h" #include "File.h"
#include "SingleFileAllocationIterator.h" #include "SingleFileAllocationIterator.h"
#include "FallocFileAllocationIterator.h" #ifdef HAVE_POSIX_FALLOCATE
# include "FallocFileAllocationIterator.h"
#endif // HAVE_POSIX_FALLOCATE
#include "DiskWriter.h" #include "DiskWriter.h"
namespace aria2 { namespace aria2 {
@ -91,17 +93,19 @@ void AbstractSingleDiskAdaptor::truncate(uint64_t length)
FileAllocationIteratorHandle AbstractSingleDiskAdaptor::fileAllocationIterator() FileAllocationIteratorHandle AbstractSingleDiskAdaptor::fileAllocationIterator()
{ {
#ifdef HAVE_POSIX_FALLOCATE
if(_fallocate) { if(_fallocate) {
SharedHandle<FallocFileAllocationIterator> h SharedHandle<FallocFileAllocationIterator> h
(new FallocFileAllocationIterator(this, size(), totalLength)); (new FallocFileAllocationIterator(this, size(), totalLength));
return h; return h;
} else { } else
SingleFileAllocationIteratorHandle h #endif // HAVE_POSIX_FALLOCATE
(new SingleFileAllocationIterator(this, size(), totalLength)); {
h->init(); SingleFileAllocationIteratorHandle h
return h; (new SingleFileAllocationIterator(this, size(), totalLength));
} h->init();
return h;
}
} }
void AbstractSingleDiskAdaptor::enableDirectIO() void AbstractSingleDiskAdaptor::enableDirectIO()

View File

@ -498,9 +498,11 @@ void DefaultPieceStorage::initStorage()
} }
diskAdaptor->setStoreDir(downloadContext->getDir()); diskAdaptor->setStoreDir(downloadContext->getDir());
diskAdaptor->setFileEntries(downloadContext->getFileEntries()); diskAdaptor->setFileEntries(downloadContext->getFileEntries());
#ifdef HAVE_POSIX_FALLOCATE
if(option->get(PREF_FILE_ALLOCATION) == V_FALLOC) { if(option->get(PREF_FILE_ALLOCATION) == V_FALLOC) {
diskAdaptor->enableFallocate(); diskAdaptor->enableFallocate();
} }
#endif // HAVE_POSIX_FALLOCATE
} }
void DefaultPieceStorage::setBitfield(const unsigned char* bitfield, void DefaultPieceStorage::setBitfield(const unsigned char* bitfield,

View File

@ -43,7 +43,10 @@
namespace aria2 { namespace aria2 {
DiskAdaptor::DiskAdaptor(): DiskAdaptor::DiskAdaptor():
_fallocate(false), logger(LogFactory::getInstance()) {} #ifdef HAVE_POSIX_FALLOCATE
_fallocate(false),
#endif // HAVE_POSIX_FALLOCATE
logger(LogFactory::getInstance()) {}
DiskAdaptor::~DiskAdaptor() {} DiskAdaptor::~DiskAdaptor() {}

View File

@ -50,7 +50,9 @@ class DiskAdaptor:public BinaryStream {
protected: protected:
std::string storeDir; std::string storeDir;
std::deque<SharedHandle<FileEntry> > fileEntries; std::deque<SharedHandle<FileEntry> > fileEntries;
#ifdef HAVE_POSIX_FALLOCATE
bool _fallocate; bool _fallocate;
#endif // HAVE_POSIX_FALLOCATE
Logger* logger; Logger* logger;
public: public:
DiskAdaptor(); DiskAdaptor();
@ -109,6 +111,7 @@ 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;
#ifdef HAVE_POSIX_FALLOCATE
void enableFallocate() void enableFallocate()
{ {
_fallocate = true; _fallocate = true;
@ -123,6 +126,7 @@ public:
{ {
return _fallocate; return _fallocate;
} }
#endif // HAVE_POSIX_FALLOCATE
}; };
typedef SharedHandle<DiskAdaptor> DiskAdaptorHandle; typedef SharedHandle<DiskAdaptor> DiskAdaptorHandle;

View File

@ -36,7 +36,9 @@
#include "MultiDiskAdaptor.h" #include "MultiDiskAdaptor.h"
#include "FileEntry.h" #include "FileEntry.h"
#include "SingleFileAllocationIterator.h" #include "SingleFileAllocationIterator.h"
#include "FallocFileAllocationIterator.h" #ifdef HAVE_POSIX_FALLOCATE
# include "FallocFileAllocationIterator.h"
#endif // HAVE_POSIX_FALLOCATE
#include "DiskWriter.h" #include "DiskWriter.h"
namespace aria2 { namespace aria2 {
@ -62,19 +64,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.
#ifdef HAVE_POSIX_FALLOCATE
if(_diskAdaptor->doesFallocate()) { if(_diskAdaptor->doesFallocate()) {
_fileAllocationIterator.reset _fileAllocationIterator.reset
(new FallocFileAllocationIterator(entry->getDiskWriter().get(), (new FallocFileAllocationIterator(entry->getDiskWriter().get(),
entry->size(), entry->size(),
fileEntry->getLength())); fileEntry->getLength()));
} else { } else
SharedHandle<SingleFileAllocationIterator> fa #endif // HAVE_POSIX_FALLOCATE
(new SingleFileAllocationIterator(entry->getDiskWriter().get(), {
entry->size(), SharedHandle<SingleFileAllocationIterator> fa
fileEntry->getLength())); (new SingleFileAllocationIterator(entry->getDiskWriter().get(),
fa->init(); entry->size(),
_fileAllocationIterator = fa; fileEntry->getLength()));
} fa->init();
_fileAllocationIterator = fa;
}
} }
} }
if(finished()) { if(finished()) {