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:
+45
-27
@@ -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 <OS.h>
|
||||||
#include <fs_interface.h>
|
#include <fs_interface.h>
|
||||||
|
|
||||||
@@ -10,6 +16,10 @@
|
|||||||
#define TRACE(x) printf x
|
#define TRACE(x) printf x
|
||||||
#define dprintf printf
|
#define dprintf printf
|
||||||
|
|
||||||
|
#ifndef ASSERT
|
||||||
|
# define ASSERT(x) ;
|
||||||
|
#endif
|
||||||
|
|
||||||
// maximum number of iovecs per request
|
// maximum number of iovecs per request
|
||||||
#define MAX_IO_VECS 64 // 256 kB
|
#define MAX_IO_VECS 64 // 256 kB
|
||||||
#define MAX_FILE_IO_VECS 32
|
#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;
|
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 the file portion was contiguous, we're already done now
|
||||||
if (size == numBytes)
|
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);
|
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) {
|
while (fileLeft > 0) {
|
||||||
iovec tempVecs[MAX_TEMP_IO_VECS];
|
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);
|
// assign what is left of the current fileVec to the tempVecs
|
||||||
tempVecs[0].iov_len = size;
|
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)
|
// bytes left of the current iovec
|
||||||
vecOffset += size;
|
size_t vecLeft = vecs[i].iov_len - vecOffset;
|
||||||
else
|
if (vecLeft == 0) {
|
||||||
vecOffset = 0;
|
vecOffset = 0;
|
||||||
|
i++;
|
||||||
while (size < fileLeft && ++i < count
|
continue;
|
||||||
&& 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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++;
|
tempCount++;
|
||||||
|
|
||||||
|
size += tempVecSize;
|
||||||
|
vecOffset += tempVecSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t bytes = size;
|
size_t bytes = size;
|
||||||
@@ -573,20 +590,21 @@ printf("FILE VEC [%lu] length %Ld\n", fileVecIndex, fileLeft);
|
|||||||
if (status < B_OK)
|
if (status < B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
totalSize += size;
|
totalSize += bytes;
|
||||||
bytesLeft -= size;
|
bytesLeft -= size;
|
||||||
fileOffset += size;
|
fileOffset += size;
|
||||||
fileLeft -= size;
|
fileLeft -= size;
|
||||||
printf("-> file left = %Lu\n", fileLeft);
|
//dprintf("-> file left = %Lu\n", fileLeft);
|
||||||
|
|
||||||
if (size != bytes) {
|
if (size != bytes || i >= count) {
|
||||||
// there are no more bytes, let's bail out
|
// there are no more bytes or iovecs, let's bail out
|
||||||
*_numBytes = totalSize;
|
*_numBytes = totalSize;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*_numBytes = totalSize;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user