Loading [MathJax]/extensions/tex2jax.js
CS350 COS
COS
All Data Structures Files Functions Variables Typedefs Macros
bufcache.h File Reference
#include <sys/queue.h>
Include dependency graph for bufcache.h:

Go to the source code of this file.

Data Structures

struct  BufCacheEntry
 

Typedefs

typedef struct BufCacheEntry BufCacheEntry
 

Functions

void BufCache_Init ()
 
int BufCache_Alloc (Disk *disk, uint64_t diskOffset, BufCacheEntry **entry)
 
void BufCache_Release (BufCacheEntry *entry)
 
int BufCache_Read (Disk *disk, uint64_t diskOffset, BufCacheEntry **entry)
 
int BufCache_Write (BufCacheEntry *entry)
 

Typedef Documentation

◆ BufCacheEntry

typedef struct BufCacheEntry BufCacheEntry

Function Documentation

◆ BufCache_Alloc()

int BufCache_Alloc ( Disk disk,
uint64_t  diskOffset,
BufCacheEntry **  entry 
)

BufCache_Alloc –

Allocate a buffer cache entry to allow writing new data to disk.

Parameters
[in]diskDisk object
[in]diskOffsetBlock offset within the disk
[out]entryIf successful, this contains the buffer cache entry.
Return values
0if successful
Returns
Otherwise returns an error code.

Definition at line 178 of file bufcache.c.

179{
180 int status;
181
183
184 status = BufCacheLookup(disk, diskOffset, entry);
185 if (*entry == NULL) {
186 status = BufCacheAlloc(disk, diskOffset, entry);
187 }
188
189 cacheAlloc++;
190
192
193 return status;
194}
Spinlock cacheLock
Definition: bufcache.c:18
static int BufCacheLookup(Disk *disk, uint64_t diskOffset, BufCacheEntry **entry)
Definition: bufcache.c:97
static int BufCacheAlloc(Disk *disk, uint64_t diskOffset, BufCacheEntry **entry)
Definition: bufcache.c:133
uint64_t diskOffset
Definition: newfs_o2fs.c:28
void Spinlock_Unlock(Spinlock *lock) __UNLOCK_EX(*lock)
Definition: spinlock.c:109
void Spinlock_Lock(Spinlock *lock) __LOCK_EX(*lock)
Definition: spinlock.c:75
#define NULL
Definition: stddef.h:6
Here is the call graph for this function:

◆ BufCache_Init()

void BufCache_Init ( )
Here is the caller graph for this function:

◆ BufCache_Read()

int BufCache_Read ( Disk disk,
uint64_t  diskOffset,
BufCacheEntry **  entry 
)

BufCache_Read –

Read block from disk into the buffer cache.

Parameters
[in]diskDisk object
[in]diskOffsetBlock offset within the disk
[out]entryIf successful, this contains the buffer cache entry.
Return values
0if successful
Returns
Otherwise returns an error code.

Definition at line 229 of file bufcache.c.

230{
231 int status;
232 void *buf;
233 SGArray sga;
234
236 status = BufCacheLookup(disk, diskOffset, entry);
237 if (*entry != NULL) {
238 cacheHit++;
240 return status;
241 }
242 cacheMiss++;
243
244 status = BufCacheAlloc(disk, diskOffset, entry);
245 if (status != 0) {
247 return status;
248 }
249
250 buf = (*entry)->buffer;
251 SGArray_Init(&sga);
253
254 /*
255 * XXX: Need to avoid holding cacheLock while reading from the disk, but
256 * need ensure other cores doesn't issue a read to the same block.
257 */
258 status = Disk_Read(disk, buf, &sga, NULL, NULL);
260
261 return status;
262}
#define BLOCKSIZE
int Disk_Read(Disk *disk, void *buf, SGArray *sga, DiskCB cb, void *arg)
Definition: disk.c:44
static char buf[4096]
Definition: ethdump.c:10
void SGArray_Init(SGArray *sga)
Definition: sga.c:12
int SGArray_Append(SGArray *sga, uint64_t off, uint64_t len)
Definition: sga.c:18
Definition: sga.h:14
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BufCache_Release()

void BufCache_Release ( BufCacheEntry entry)

BufCache_Release –

Release a buffer cache entry. If no other references are held the buffer cache entry is placed on the LRU list.

Parameters
[in]entryBuffer cache entry.

Definition at line 205 of file bufcache.c.

206{
208
209 entry->refCount--;
210 if (entry->refCount == 0) {
211 TAILQ_INSERT_TAIL(&lruList, entry, lruEntry);
212 }
213
215}
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:641
uint64_t refCount
Definition: bufcache.h:10
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BufCache_Write()

int BufCache_Write ( BufCacheEntry entry)

BufCache_Write –

Write a buffer cache entry to disk.

Return values
0if successful
Returns
Otherwise an error code is returned.

Definition at line 273 of file bufcache.c.

274{
275 void *buf = entry->buffer;
276 SGArray sga;
277
278 SGArray_Init(&sga);
279 SGArray_Append(&sga, entry->diskOffset, BLOCKSIZE);
280
281 return Disk_Write(entry->disk, buf, &sga, NULL, NULL);
282}
int Disk_Write(Disk *disk, void *buf, SGArray *sga, DiskCB cb, void *arg)
Definition: disk.c:50
void * buffer
Definition: bufcache.h:11
Disk * disk
Definition: bufcache.h:8
uint64_t diskOffset
Definition: bufcache.h:9
Here is the call graph for this function:
Here is the caller graph for this function: