ShingledFS 2.0
SMR-AwareFUSE-basedFileSystem

buffercache.c File Reference

Implements the buffer cache abstraction for ShingledFS. More...

#include <time.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>
#include <pthread.h>
#include <semaphore.h>
#include <sys/xattr.h>
#include "failstop.h"
#include "buffercache.h"
#include "common.h"
#include "helper.h"
#include "inode.h"
#include "band_bitmap.h"
#include "band_log.h"
#include "emulator.h"
#include "emutypes.h"
#include "emuerror.h"

Go to the source code of this file.

Data Structures

struct  bc_file_list_t
 Defines the Buffer Cache File List. More...
struct  bc_request_list_t
 Defines the request list that holds loads/stores from ShingledFS. More...

Defines

#define MAX_FILES   32
 Defines the maximum number of files in 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.
bc_file_tbc_file_search_path (const char *path)
 Searches the BC File List using the file path.
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.

Detailed Description

Implements the buffer cache abstraction for ShingledFS.

Always grab the BC Files list lock first, before grabbing the lock on the BC File record. This ordering results in deadlock prevention.

Author:
Anand Suresh <anandsuresh@cmu.edu>
Bug:
Hard coded the number of files that can be held in the buffer cache. This value should be calculated as buffer_cache_size / EDI_band_size.

Definition in file buffercache.c.


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().