summaryrefslogtreecommitdiff
path: root/src/MultiFileAllocationIterator.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2010-07-04 15:03:35 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2010-07-04 15:03:35 +0000
commita5cc350dcf6cf83a84b5845e0f61230f1f42e7c7 (patch)
tree38d73b2aebcdd3c26d76782690d6bb10fe29ad86 /src/MultiFileAllocationIterator.cc
parent8f10241e25d796655a8aaaf7cf69c7061d05bc43 (diff)
2010-07-04 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
When allocating disk space, for Linux system with fallocate() system call, first check file system supports fallocate. This just run fallocate with small chunk and see it succeeds or fails. If it succeeds, use fallocate() to allocate entire file otherwise fall back to traditional slower method: writing zeros. This behavior is enabled in --file-allocation=prealloc, so this is enabled by default for most modern Linux. * configure.ac * src/AbstractDiskWriter.cc * src/AbstractDiskWriter.h * src/AbstractSingleDiskAdaptor.cc * src/AdaptiveFileAllocationIterator.cc * src/AdaptiveFileAllocationIterator.h * src/DefaultPieceStorage.cc * src/DiskAdaptor.cc * src/DiskAdaptor.h * src/FallocFileAllocationIterator.cc * src/Makefile.am * src/MultiFileAllocationIterator.cc * src/OptionHandlerFactory.cc * test/FallocFileAllocationIteratorTest.cc * test/Makefile.am
Diffstat (limited to 'src/MultiFileAllocationIterator.cc')
-rw-r--r--src/MultiFileAllocationIterator.cc29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/MultiFileAllocationIterator.cc b/src/MultiFileAllocationIterator.cc
index 8fa15a97..9a0dc3f5 100644
--- a/src/MultiFileAllocationIterator.cc
+++ b/src/MultiFileAllocationIterator.cc
@@ -35,15 +35,16 @@
#include "MultiFileAllocationIterator.h"
#include "MultiDiskAdaptor.h"
#include "FileEntry.h"
-#include "SingleFileAllocationIterator.h"
-#ifdef HAVE_POSIX_FALLOCATE
+#include "AdaptiveFileAllocationIterator.h"
+#ifdef HAVE_SOME_FALLOCATE
# include "FallocFileAllocationIterator.h"
-#endif // HAVE_POSIX_FALLOCATE
+#endif // HAVE_SOME_FALLOCATE
#include "DiskWriter.h"
namespace aria2 {
-MultiFileAllocationIterator::MultiFileAllocationIterator(MultiDiskAdaptor* diskAdaptor):
+MultiFileAllocationIterator::MultiFileAllocationIterator
+(MultiDiskAdaptor* diskAdaptor):
diskAdaptor_(diskAdaptor),
entries_(diskAdaptor_->diskWriterEntries_.begin(),
diskAdaptor_->diskWriterEntries_.end()),
@@ -54,7 +55,8 @@ MultiFileAllocationIterator::~MultiFileAllocationIterator() {}
void MultiFileAllocationIterator::allocateChunk()
{
- while(fileAllocationIterator_.isNull() || fileAllocationIterator_->finished()) {
+ while(fileAllocationIterator_.isNull() ||
+ fileAllocationIterator_->finished()) {
if(entries_.empty()) {
break;
}
@@ -65,21 +67,19 @@ void MultiFileAllocationIterator::allocateChunk()
diskAdaptor_->openIfNot(entry, &DiskWriterEntry::openFile);
if(entry->needsFileAllocation() && entry->size() < fileEntry->getLength()) {
// Calling private function of MultiDiskAdaptor.
-#ifdef HAVE_POSIX_FALLOCATE
+#ifdef HAVE_SOME_FALLOCATE
if(diskAdaptor_->doesFallocate()) {
fileAllocationIterator_.reset
(new FallocFileAllocationIterator(entry->getDiskWriter().get(),
entry->size(),
fileEntry->getLength()));
} else
-#endif // HAVE_POSIX_FALLOCATE
+#endif // HAVE_SOME_FALLOCATE
{
- SharedHandle<SingleFileAllocationIterator> fa
- (new SingleFileAllocationIterator(entry->getDiskWriter().get(),
- entry->size(),
- fileEntry->getLength()));
- fa->init();
- fileAllocationIterator_ = fa;
+ fileAllocationIterator_.reset
+ (new AdaptiveFileAllocationIterator(entry->getDiskWriter().get(),
+ entry->size(),
+ fileEntry->getLength()));
}
}
}
@@ -91,7 +91,8 @@ void MultiFileAllocationIterator::allocateChunk()
bool MultiFileAllocationIterator::finished()
{
- return entries_.empty() && (fileAllocationIterator_.isNull() || fileAllocationIterator_->finished());
+ return entries_.empty() &&
+ (fileAllocationIterator_.isNull() || fileAllocationIterator_->finished());
}
off_t MultiFileAllocationIterator::getCurrentLength()