#include "afs/sysincludes.h"
#include "afsincludes.h"
#if !defined(UKERNEL)
-#include "h/param.h"
+#if !defined(AFS_LINUX26_ENV)
+# include "h/param.h"
+#endif
#include "h/types.h"
#include "h/time.h"
#if defined(AFS_AIX31_ENV)
return;
}
-void *
-DRead(struct dcache *adc, int page)
+int
+DRead(struct dcache *adc, int page, struct DirBuffer *entry)
{
/* Read a page from the disk. */
struct buffer *tb, *tb2;
int code;
AFS_STATCNT(DRead);
+
+ memset(entry, 0, sizeof(struct DirBuffer));
+
ObtainWriteLock(&afs_bufferLock, 256);
#define bufmatch(tb) (tb->page == page && tb->fid == adc->index)
tb->accesstime = timecounter++;
AFS_STATS(afs_stats_cmperf.bufHits++);
ReleaseWriteLock(&tb->lock);
- return tb->data;
+ entry->buffer = tb;
+ entry->data = tb->data;
+ return 0;
} else {
struct buffer **bufhead;
bufhead = &(phTable[pHash(adc->index, page)]);
tb2->accesstime = timecounter++;
AFS_STATS(afs_stats_cmperf.bufHits++);
ReleaseWriteLock(&tb2->lock);
- return tb2->data;
+ entry->buffer = tb2;
+ entry->data = tb2->data;
+ return 0;
}
if ((tb = tb2->hashNext)) {
if (bufmatch(tb)) {
tb->accesstime = timecounter++;
AFS_STATS(afs_stats_cmperf.bufHits++);
ReleaseWriteLock(&tb->lock);
- return tb->data;
+ entry->buffer = tb;
+ entry->data = tb->data;
+ return 0;
}
} else
break;
tb = afs_newslot(adc, page, (tb ? tb : tb2));
if (!tb) {
ReleaseWriteLock(&afs_bufferLock);
- return NULL;
+ return EIO;
}
ObtainWriteLock(&tb->lock, 260);
tb->lockers++;
afs_reset_inode(&tb->inode);
tb->lockers--;
ReleaseWriteLock(&tb->lock);
- return NULL;
+ return ENOENT; /* past the end */
}
tfile = afs_CFileOpen(&adc->f.inode);
code =
afs_reset_inode(&tb->inode);
tb->lockers--;
ReleaseWriteLock(&tb->lock);
- return NULL;
+ return EIO;
}
/* Note that findslot sets the page field in the buffer equal to
* what it is searching for. */
ReleaseWriteLock(&tb->lock);
- return tb->data;
+ entry->buffer = tb;
+ entry->data = tb->data;
+ return 0;
}
static void
AFS_STATS(afs_stats_cmperf.bufFlushDirty++);
}
+ /* Zero out the data so we don't leak something we shouldn't. */
+ memset(lp->data, 0, AFS_BUFFER_PAGESIZE);
/* Now fill in the header. */
lp->fid = adc->index;
afs_copy_inode(&lp->inode, &adc->f.inode);
}
void
-DRelease(void *loc, int flag)
+DRelease(struct DirBuffer *entry, int flag)
{
- /* Release a buffer, specifying whether or not the buffer has been
- * modified by the locker. */
- struct buffer *bp = (struct buffer *)loc;
- int index;
struct buffer *tp;
AFS_STATCNT(DRelease);
- if (!bp)
+
+ tp = entry->buffer;
+ if (tp == NULL)
return;
- /* look for buffer by scanning Unix buffers for appropriate address */
- /* careful: despite the declaration above at this point bp is still simply
- * an address inside the buffer, not a pointer to the buffer header */
- tp = Buffers;
- for (index = 0; index < nbuffers; index += NPB, tp += NPB) {
- if ( (char *) bp >= (char *) tp->data &&
- (char *) bp < (char *) tp->data + AFS_BUFFER_PAGESIZE * NPB) {
- /* we found the right range */
- index += ((char *) bp - (char *) tp->data) >> LOGPS;
- break;
- }
- }
- tp = &(Buffers[index]);
+
+ tp = entry->buffer;
ObtainWriteLock(&tp->lock, 261);
tp->lockers--;
if (flag)
}
int
-DVOffset(void *ap)
+DVOffset(struct DirBuffer *entry)
{
- /* Return the byte within a file represented by a buffer pointer. */
- int index;
- struct buffer *tp;
+ struct buffer *bp;
+
AFS_STATCNT(DVOffset);
- /* look for buffer by scanning Unix buffers for appropriate address */
- /* see comment in DRelease about the meaning of ap/bp */
- tp = Buffers;
- for (index = 0; index < nbuffers; index += NPB, tp += NPB) {
- if ( (char *) ap >= (char *) tp->data &&
- (char *) ap < (char *) tp->data + AFS_BUFFER_PAGESIZE * NPB) {
- /* we found the right range */
- index += ((char *) ap - (char *) tp->data) >> LOGPS;
- break;
- }
- }
- if (index < 0 || index >= nbuffers)
- return -1;
- tp = &(Buffers[index]);
- return AFS_BUFFER_PAGESIZE * tp->page + (int)(((char *)ap) - tp->data);
+
+ bp = entry->buffer;
+ return AFS_BUFFER_PAGESIZE * bp->page
+ + (char *)entry->data - (char *)bp->data;
}
/*!
ReleaseReadLock(&afs_bufferLock);
}
-void
+int
DFlush(void)
{
/* Flush all the modified buffers. */
}
}
ReleaseReadLock(&afs_bufferLock);
+
+ return 0;
}
-void *
-DNew(struct dcache *adc, int page)
+int
+DNew(struct dcache *adc, int page, struct DirBuffer *entry)
{
- /* Same as read, only do *not* even try to read the page, since it probably doesn't exist. */
+ /* Same as read, only do *not* even try to read the page, since it
+ * probably doesn't exist. */
struct buffer *tb;
AFS_STATCNT(DNew);
+
ObtainWriteLock(&afs_bufferLock, 264);
if ((tb = afs_newslot(adc, page, NULL)) == 0) {
ReleaseWriteLock(&afs_bufferLock);
- return 0;
+ return EIO;
}
/* extend the chunk, if needed */
/* Do it now, not in DFlush or afs_newslot when the data is written out,
* DFlush due to lock hierarchy issues */
if ((page + 1) * AFS_BUFFER_PAGESIZE > adc->f.chunkBytes) {
afs_AdjustSize(adc, (page + 1) * AFS_BUFFER_PAGESIZE);
- afs_WriteDCache(adc, 1);
+ osi_Assert(afs_WriteDCache(adc, 1) == 0);
}
ObtainWriteLock(&tb->lock, 265);
tb->lockers++;
ReleaseWriteLock(&afs_bufferLock);
ReleaseWriteLock(&tb->lock);
- return tb->data;
+ entry->buffer = tb;
+ entry->data = tb->data;
+
+ return 0;
}
void