From 5a2f398eca68b2b0330ddcec2b222bf76875f82f Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Wed, 28 Nov 2007 14:22:28 +0000 Subject: 2007-11-28 Tatsuhiro Tsujikawa Added direct I/O support. The current implementation uses O_DIRECT, which is not posix standard and is tested on linux 2.6.21. Currently only file allocation uses direct I/O. * src/SingleFileAllocationIterator.{h, cc} * test/SingleFileAllocationIteratorTest.cc * src/MultiFileAllocationIterator.{h, cc} * test/MultiFileAllocationIteratorTest.cc * src/BinaryStream.h * src/DiskWriter.h * src/AbstractDiskWriter.{h, cc} * src/ByteArrayDiskWriter.h * src/DiskAdaptor.h * src/AbstractSingleDiskAdaptor.{h, cc} * src/MultiDiskAdaptor.{h, cc} * src/FileAllocationEntry.cc * src/Util.{h, cc} * src/OptionHandlerFactory.cc * src/prefs.h * src/version_usage.cc * src/option_processing.cc Moved FileAllocationMan::markCurrentFileAllocationEntryDone() to handleException. * src/MultiFileAllocationIterator.cc Added EINTR handling * src/SocketCore.cc --- src/SingleFileAllocationIterator.cc | 47 +++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 20 deletions(-) (limited to 'src/SingleFileAllocationIterator.cc') diff --git a/src/SingleFileAllocationIterator.cc b/src/SingleFileAllocationIterator.cc index 1384c163..620410fa 100644 --- a/src/SingleFileAllocationIterator.cc +++ b/src/SingleFileAllocationIterator.cc @@ -33,35 +33,42 @@ */ /* copyright --> */ #include "SingleFileAllocationIterator.h" -#include "AbstractSingleDiskAdaptor.h" +#include "BinaryStream.h" +#include "Util.h" +#include "a2io.h" -#define BUFSIZE 16*1024 +#define BUFSIZE (256*1024) -SingleFileAllocationIterator::SingleFileAllocationIterator(AbstractSingleDiskAdaptor* diskAdaptor):_diskAdaptor(diskAdaptor), _offset(diskAdaptor->size()) {} +SingleFileAllocationIterator::SingleFileAllocationIterator(BinaryStream* stream, int64_t offset, int64_t totalLength):_stream(stream), _offset(offset), _totalLength(totalLength), _buffer(0) +{} -SingleFileAllocationIterator::~SingleFileAllocationIterator() {} +SingleFileAllocationIterator::~SingleFileAllocationIterator() +{ + delete [] _buffer; +} -void SingleFileAllocationIterator::allocateChunk() +void SingleFileAllocationIterator::init() { - int32_t bufSize = BUFSIZE; - unsigned char buf[BUFSIZE]; - memset(buf, 0, bufSize); - - _diskAdaptor->writeData(buf, bufSize, _offset); - _offset += bufSize; - - if(_diskAdaptor->getTotalLength() < _offset) { - _diskAdaptor->truncate(getTotalLength()); - _offset = getTotalLength(); - } +#ifdef HAVE_POSIX_MEMALIGN + _buffer = (unsigned char*)Util::allocateAlignedMemory(512, BUFSIZE); +#else + _buffer = new unsigned char[BUFSIZE]; +#endif // HAVE_POSIX_MEMALIGN + memset(_buffer, 0, BUFSIZE); } -bool SingleFileAllocationIterator::finished() +void SingleFileAllocationIterator::allocateChunk() { - return getCurrentLength() >= getTotalLength(); + _stream->writeData(_buffer, BUFSIZE, _offset); + _offset += BUFSIZE; + + if(_totalLength < _offset) { + _stream->truncate(_totalLength); + _offset = _totalLength; + } } -int64_t SingleFileAllocationIterator::getTotalLength() +bool SingleFileAllocationIterator::finished() { - return _diskAdaptor->getTotalLength(); + return _offset >= _totalLength; } -- cgit