ShingledFS 2.0
SMR-AwareFUSE-basedFileSystem

buffercache.h File Reference

Macros, Type Definitions and Function Prototypes pertaining to the Buffer Cache abstraction for ShingledFS. More...

#include <pthread.h>

Go to the source code of this file.

Data Structures

struct  bc_file
 Defines a Cached File record. More...
struct  bc_request
 Defines a request placed by ShingledFS to load/store a file. More...

Typedefs

typedef struct bc_file bc_file_t
 Defines a Cached File record.
typedef struct bc_request bc_request_t
 Defines a request placed by ShingledFS to load/store a file.

Enumerations

enum  bc_state_t
 

Defines the state of a Cached File record.


enum  bc_operation_t
 

Defines an operation performed by the Buffer Cache.


Functions

void bc_init (size_t cache_size)
 Initializes the Buffer Cache system.
bc_file_tbc_open (const char *path)
 Loads a file into the buffer cache.
void bc_close (bc_file_t *file)
 Saves a file in the buffer cache to disk.
int bc_unlink (const char *path)
 Deletes the specified file from the buffer cache.
int bc_rename (const char *path, const char *path_new)
 Renames the specified file in the buffer cache.
void bc_clean ()
 Cleans the Buffer Cache by removing a file that can be evicted.
void bc_generate_tmpFS_path (char *path_out, const char *path_in)
 Generates a file path on tmpFS for a file on the unshingled partition.
bc_file_tbc_file_search_path (const char *path)
 Searches the BC File List using the file path.

Detailed Description

Macros, Type Definitions and Function Prototypes pertaining to the Buffer Cache abstraction for ShingledFS.

Author:
Anand Suresh <anandsuresh@cmu.edu>

Definition in file buffercache.h.


Typedef Documentation

typedef struct bc_file bc_file_t

Defines a Cached File record.

Todo:
Hide any items that do not need to be exposed to FUSE. Currently, the only thing that FUSE needs is the file descriptor and the dirty flag. However, its better to store a pointer to this struct in FUSE for constant- order searching of the record for a file. So, move all other fields into another struct and save a void pointer to that struct within this struct. This way only the Buffer Cache code can access the internal fields, whereas FUSE can use the values that it is concerned with.

A thread will lock the structure by using the built-in mutex, increment the ref-count on open() or decrement it on close(), and pass the record to a worker thread to load/unload the file data from/to the EDI.

Should the file be in a loading state, a thread can increment/decrement the ref-count as applicable, and wait on the condition variable for the worker thread to wake it up once the transfer is complete.

Worker threads will load/save the file from/to the EDI, lock the mutex, and check the ref-count. If the ref-count is greater than 0, then the worker will broadcast on the condition variable to awaken any threads waiting for the transfer to finish.

Parameters:
pathThe path to the open file
inodeThe inode number of the file
statsThe attributes of the file, cached in memory for fast access
fdThe file descriptor assigned to the open file
ref_countThe reference count for the open file
dirtyFlag describing whether the file was written to since the load
stateCurrent state of the file
mutexThe mutex protecting the open_file record
cond_varThe condition variable used to wait on the open_file record
prevPointer to the previous open file node
nextPointer to the next open file node
typedef struct bc_request bc_request_t

Defines a request placed by ShingledFS to load/store a file.

Parameters:
filePointer to the BC File Record that holds the file information
opThe operation to perform: load or store.
nextPointer to the next BC Request Record

Function Documentation

void bc_clean ( )

Cleans the Buffer Cache by removing a file that can be evicted.

This function is called when the Buffer Cache has no more space to write data to. Essentially, it searches for a file that can be evicted, and removes it from the buffer cache. The space occupied by the file is consequently freed up for use.

Definition at line 590 of file buffercache.c.

Referenced by shingledfs_write().

void bc_close ( bc_file_t file)

Saves a file in the buffer cache to disk.

Parameters:
filePointer to the BC File record of the file that needs to be closed

Definition at line 302 of file buffercache.c.

References inode_unlink().

Referenced by shingledfs_release().

bc_file_t* bc_file_search_path ( const char *  path)

Searches the BC File List using the file path.

This function DOES NOT perform any locking. It is the responsibility of the caller to ensure that the correct locks are held before attempting to dequeue a file.

Parameters:
pathPath of the file to be searched for
Returns:
Pointer to the BC File Record of the specified file

Definition at line 901 of file buffercache.c.

Referenced by bc_open(), bc_rename(), and bc_unlink().

void bc_generate_tmpFS_path ( char *  path_out,
const char *  path_in 
)

Generates a file path on tmpFS for a file on the unshingled partition.

This function only fails when the output path exceeds PATH_MAX

Todo:
Improve this function to run faster. All that is needed is a unique path on tmpFS. There is no need to convert all /'s to _'s in the input path
Parameters:
path_outBuffer that will hold the generated path
path_inPath to the file on the unshingled partition
path_tmpfsPath to the tmpFS partition
path_unshingledPath to the unshingled partition

Definition at line 1091 of file buffercache.c.

Referenced by bc_rename(), bc_unlink(), and shingledfs_rename().

void bc_init ( size_t  cache_size)

Initializes the Buffer Cache system.

This function initializes the necessary data structures and spawns the worker threads that handle data transfer between the buffer cache and the EDI.

Parameters:
cache_sizeSize of the Buffer Cache in bytes

Definition at line 135 of file buffercache.c.

References MAX_FILES.

Referenced by shingledfs_init().

bc_file_t* bc_open ( const char *  path)

Loads a file into the buffer cache.

Parameters:
pathPath to the file to be loaded into the buffer cache
Returns:
Pointer to the BC File record, on success

Definition at line 178 of file buffercache.c.

References bc_file_search_path(), xattr_get(), and xattr_path().

Referenced by shingledfs_open().

int bc_rename ( const char *  path,
const char *  path_new 
)

Renames the specified file in the buffer cache.

Parameters:
pathPath to the existing file
path_newPath to the renamed file
Returns:
0 on success; -1 on failure due to transitive symlinks

Definition at line 475 of file buffercache.c.

References bc_file_search_path(), bc_generate_tmpFS_path(), and inode_unlink().

Referenced by shingledfs_rename().

int bc_unlink ( const char *  path)

Deletes the specified file from the buffer cache.

Parameters:
pathPath to the file to be unloaded
Returns:
0 on success; -1 on failure due to transitive symlinks

Definition at line 401 of file buffercache.c.

References bc_file_search_path(), and bc_generate_tmpFS_path().

Referenced by shingledfs_unlink().