Updated the pages_io() test with Ingo's latest changes.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20489 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2007-04-01 11:31:22 +00:00
parent fd93718c93
commit df0ca8cae0
+45 -27
View File
@@ -1,3 +1,9 @@
/*
* Copyright 2004-2007, Axel Dörfler, [email protected]. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#include <OS.h>
#include <fs_interface.h>
@@ -10,6 +16,10 @@
#define TRACE(x) printf x
#define dprintf printf
#ifndef ASSERT
# define ASSERT(x) ;
#endif
// maximum number of iovecs per request
#define MAX_IO_VECS 64 // 256 kB
#define MAX_FILE_IO_VECS 32
@@ -489,7 +499,7 @@ pages_io(file_cache_ref *ref, off_t offset, const iovec *vecs, size_t count,
size = fileVecs[0].length;
}
//ASSERT(size <= fileVecs[0].length);
ASSERT(size <= fileVecs[0].length);
// If the file portion was contiguous, we're already done now
if (size == numBytes)
@@ -530,36 +540,43 @@ pages_io(file_cache_ref *ref, off_t offset, const iovec *vecs, size_t count,
fileLeft = min_c(fileVec.length, bytesLeft);
printf("FILE VEC [%lu] length %Ld\n", fileVecIndex, fileLeft);
TRACE(("FILE VEC [%lu] length %Ld\n", fileVecIndex, fileLeft));
// process the complete fileVec
while (fileLeft > 0) {
iovec tempVecs[MAX_TEMP_IO_VECS];
uint32 tempCount = 1;
uint32 tempCount = 0;
size = min_c(vecs[i].iov_len - vecOffset, fileLeft);
// size tracks how much of what is left of the current fileVec
// (fileLeft) has been assigned to tempVecs
size = 0;
tempVecs[0].iov_base = (void *)((addr_t)vecs[i].iov_base + vecOffset);
tempVecs[0].iov_len = size;
// assign what is left of the current fileVec to the tempVecs
for (size = 0; size < fileLeft && i < count
&& tempCount < MAX_TEMP_IO_VECS;) {
// try to satisfy one iovec per iteration (or as much as
// possible)
TRACE(("fill vec %ld, offset = %lu, size = %lu\n",
i, vecOffset, size));
if (size >= fileLeft)
vecOffset += size;
else
vecOffset = 0;
while (size < fileLeft && ++i < count
&& tempCount < MAX_TEMP_IO_VECS) {
TRACE(("fill vec %ld, offset = %lu, size = %lu\n", i, vecOffset, size));
tempVecs[tempCount].iov_base = vecs[i].iov_base;
// is this iovec larger than the file_io_vec?
if (vecs[i].iov_len + size > fileLeft) {
size += tempVecs[tempCount].iov_len
= vecOffset = fileLeft - size;
tempCount++;
break;
// bytes left of the current iovec
size_t vecLeft = vecs[i].iov_len - vecOffset;
if (vecLeft == 0) {
vecOffset = 0;
i++;
continue;
}
size += tempVecs[tempCount].iov_len = vecs[i].iov_len;
// actually available bytes
size_t tempVecSize = min_c(vecLeft, fileLeft - size);
tempVecs[tempCount].iov_base
= (void *)((addr_t)vecs[i].iov_base + vecOffset);
tempVecs[tempCount].iov_len = tempVecSize;
tempCount++;
size += tempVecSize;
vecOffset += tempVecSize;
}
size_t bytes = size;
@@ -573,20 +590,21 @@ printf("FILE VEC [%lu] length %Ld\n", fileVecIndex, fileLeft);
if (status < B_OK)
return status;
totalSize += size;
totalSize += bytes;
bytesLeft -= size;
fileOffset += size;
fileLeft -= size;
printf("-> file left = %Lu\n", fileLeft);
//dprintf("-> file left = %Lu\n", fileLeft);
if (size != bytes) {
// there are no more bytes, let's bail out
if (size != bytes || i >= count) {
// there are no more bytes or iovecs, let's bail out
*_numBytes = totalSize;
return B_OK;
}
}
}
*_numBytes = totalSize;
return B_OK;
}