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>
Run

View File

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

View File

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

View File

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

View File

@ -50,7 +50,9 @@ class DiskAdaptor:public BinaryStream {
protected:
std::string storeDir;
std::deque<SharedHandle<FileEntry> > fileEntries;
#ifdef HAVE_POSIX_FALLOCATE
bool _fallocate;
#endif // HAVE_POSIX_FALLOCATE
Logger* logger;
public:
DiskAdaptor();
@ -109,6 +111,7 @@ public:
// successfully changed.
virtual size_t utime(const Time& actime, const Time& modtime) = 0;
#ifdef HAVE_POSIX_FALLOCATE
void enableFallocate()
{
_fallocate = true;
@ -123,6 +126,7 @@ public:
{
return _fallocate;
}
#endif // HAVE_POSIX_FALLOCATE
};
typedef SharedHandle<DiskAdaptor> DiskAdaptorHandle;

View File

@ -36,7 +36,9 @@
#include "MultiDiskAdaptor.h"
#include "FileEntry.h"
#include "SingleFileAllocationIterator.h"
#include "FallocFileAllocationIterator.h"
#ifdef HAVE_POSIX_FALLOCATE
# include "FallocFileAllocationIterator.h"
#endif // HAVE_POSIX_FALLOCATE
#include "DiskWriter.h"
namespace aria2 {
@ -62,19 +64,22 @@ void MultiFileAllocationIterator::allocateChunk()
_diskAdaptor->openIfNot(entry, &DiskWriterEntry::openFile);
if(entry->needsFileAllocation() && entry->size() < fileEntry->getLength()) {
// Calling private function of MultiDiskAdaptor.
#ifdef HAVE_POSIX_FALLOCATE
if(_diskAdaptor->doesFallocate()) {
_fileAllocationIterator.reset
(new FallocFileAllocationIterator(entry->getDiskWriter().get(),
entry->size(),
fileEntry->getLength()));
} else {
SharedHandle<SingleFileAllocationIterator> fa
(new SingleFileAllocationIterator(entry->getDiskWriter().get(),
entry->size(),
fileEntry->getLength()));
fa->init();
_fileAllocationIterator = fa;
}
} else
#endif // HAVE_POSIX_FALLOCATE
{
SharedHandle<SingleFileAllocationIterator> fa
(new SingleFileAllocationIterator(entry->getDiskWriter().get(),
entry->size(),
fileEntry->getLength()));
fa->init();
_fileAllocationIterator = fa;
}
}
}
if(finished()) {