ShingledFS 2.0
SMR-AwareFUSE-basedFileSystem

fuseops.c File Reference

Implementation of the FUSE operations needed by Shingled FS. More...

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <pthread.h>
#include <dirent.h>
#include <assert.h>
#include <sys/xattr.h>
#include <sys/vfs.h>
#include "shingledfs.h"
#include "emulator.h"
#include "helper.h"
#include "failstop.h"
#include "buffercache.h"
#include "log.h"
#include "inode.h"
#include "band_bitmap.h"
#include "band_log.h"
#include "cleaning_thread.h"

Go to the source code of this file.

Functions

void * shingledfs_init (struct fuse_conn_info *conn)
 Initializes the Shingled File System, preparing it for usage.
int shingledfs_mkdir (const char *path, mode_t mode)
 Creates a new directory.
int shingledfs_rmdir (const char *path)
 Removes a directory.
int shingledfs_opendir (const char *path, struct fuse_file_info *fi)
 Opens the specified directory.
int shingledfs_readdir (const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi)
 Reads the list of files in the specified directory.
int shingledfs_releasedir (const char *path, struct fuse_file_info *fi)
 Closes the open directory.
int shingledfs_mknod (const char *path, mode_t mode, dev_t dev)
 Creates a new file node.
int shingledfs_open (const char *path, struct fuse_file_info *fi)
 Opens the specified file.
int shingledfs_read (const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi)
 Reads data from an open file.
int shingledfs_write (const char *path, const char *buf, size_t size, off_t offset, struct fuse_file_info *fi)
 Write data to an open file.
int shingledfs_flush (const char *path, struct fuse_file_info *fi)
 Flushes file contents to disk.
int shingledfs_release (const char *path, struct fuse_file_info *fi)
 Closes an open file.
int shingledfs_rename (const char *path, const char *path_new)
 Renames a file.
int shingledfs_unlink (const char *path)
 Deletes a file.
int shingledfs_truncate (const char *path, off_t offset)
 Truncates the file at the specified offset.
int shingledfs_getattr (const char *path, struct stat *statbuf)
 Truncates the file at the specified offset.
int shingledfs_fgetattr (const char *path, struct stat *statbuf, struct fuse_file_info *fi)
 Retrieves the attributes for the specified file.
int shingledfs_setxattr (const char *path, const char *name, const char *value, size_t size, int flags)
 Sets the extended attributes.
int shingledfs_getxattr (const char *path, const char *name, char *value, size_t size)
 Retrieves the value associated with an extended attribute.
int shingledfs_listxattr (const char *path, char *list, size_t size)
 Retrieves the list of extended attributes.
int shingledfs_removexattr (const char *path, const char *name)
 Removes an extended attribute.
int shingledfs_access (const char *path, int mask)
 Returns the access mask for the specified path.
int shingledfs_utime (const char *path, struct utimbuf *tv)
 Sets the access and/or modification times of the specified file.
int shingledfs_chmod (const char *path, mode_t mode)
 Changes the permission bits of a file.
int shingledfs_chown (const char *path, uid_t uid, gid_t gid)
 Changes the owner and group of a file.
int shingledfs_symlink (const char *path, const char *path_target)
 Creates a symbolic link.
int shingledfs_readlink (const char *path, char *buf, size_t size)
 Reads the target of a symbolic link.
int shingledfs_link (const char *path, const char *path_target)
 Creates a hard link.
int shingledfs_statfs (const char *path, struct statvfs *statv)
 Returns ShingledFS file system statistics.

Detailed Description

Implementation of the FUSE operations needed by Shingled FS.

Author:
Anand Suresh <anandsuresh@cmu.edu>
Bug:
shingledfs_link() is bound to fail under certain conditions.
See also:
shingledfs_link for more details

Definition in file fuseops.c.


Function Documentation

int shingledfs_access ( const char *  path,
int  mask 
)

Returns the access mask for the specified path.

Todo:
Implement access() correctly when the file is not open. This should involve check the uid and gid of the file and the current user and the access permissions set in st_mode in the file's attributes.
Parameters:
pathPath to the file whose access permissions are to be checked
maskPermissions to check for
Returns:
0 on success; -errno on failure

Definition at line 1084 of file fuseops.c.

References translate_path(), and xattr_get().

int shingledfs_chmod ( const char *  path,
mode_t  mode 
)

Changes the permission bits of a file.

Parameters:
pathPath to the file whose permission bits are to be changed
modeThe new permission bits to be set
Returns:
0 on success; -1 on failure

Definition at line 1190 of file fuseops.c.

References translate_path(), xattr_get(), and xattr_set().

int shingledfs_chown ( const char *  path,
uid_t  uid,
gid_t  gid 
)

Changes the owner and group of a file.

Todo:
Fix this function to account for Attribute Replication
Parameters:
pathPath to the file whose owner and group is to be changed
uidThe UID of the user who is the new owner of the file
gidThe GID of the group that can access the file
Returns:
0 on success; -1 on failure

Definition at line 1238 of file fuseops.c.

References translate_path(), xattr_get(), and xattr_set().

int shingledfs_fgetattr ( const char *  path,
struct stat *  statbuf,
struct fuse_file_info *  fi 
)

Retrieves the attributes for the specified file.

This function relies on the file descriptor of an open file, passed in the fuse_file_info structure.

As per documentation in fuse/fuse.h, this is currently only called after create(), but may later be used for invocations of fstat() as well.

Parameters:
pathPath to the file whose attributes are to be retrived
statbufBuffer to hold the retrieved stats
file_infofuse_file_info structure from the call to open()
Returns:
0 on success; -errno on failure

Definition at line 902 of file fuseops.c.

int shingledfs_flush ( const char *  path,
struct fuse_file_info *  fi 
)

Flushes file contents to disk.

For ShingledFS, this function does nothing! We want to write file contents to disk on close(), not before that!

Parameters:
pathPath to the open file.
file_infoFUSE structure created when the file was opened.
Returns:
0, to indicate success

Definition at line 519 of file fuseops.c.

int shingledfs_getattr ( const char *  path,
struct stat *  statbuf 
)

Truncates the file at the specified offset.

This function relies on the file descriptor of an open file, passed in the fuse_file_info structure.

Parameters:
pathPath to the file whose attributes are to be retrived
offsetOffset into the file to truncate at
file_infofuse_file_info structure from the call to open() or create()
Returns:
0 on success; -errno on failure Retrieves the attributes for the specified file.
Todo:
Is it cheaper to perform a comparison on with every open file in the BC to determine location? The "file is open" code path takes 3 system calls!
Parameters:
pathPath to the file whose attributes are to be retrived
statbufBuffer to hold the retrieved stats
Returns:
0 on success; -errno on failure

Definition at line 841 of file fuseops.c.

References translate_path(), and xattr_get().

int shingledfs_getxattr ( const char *  path,
const char *  name,
char *  value,
size_t  size 
)

Retrieves the value associated with an extended attribute.

Parameters:
pathPath to the file whose extended attribute are to be retrieved
nameName of the extended attribute to retrieve
valueBuffer to hold the value of the extended attribute
sizeSize of the data in the buffer
Returns:
0 on success; -1 on failure

Definition at line 971 of file fuseops.c.

References translate_path(), and xattr_get().

void* shingledfs_init ( struct fuse_conn_info *  conn)

Initializes the Shingled File System, preparing it for usage.

Todo:
Buffer Cache size hard coded!
Parameters:
connFUSE structure detailing connection information

Definition at line 50 of file fuseops.c.

References bc_init(), init_inodebitmap(), init_inodelist(), read_edi_parameters(), and shingledfs_data.

int shingledfs_link ( const char *  path,
const char *  path_target 
)

Creates a hard link.

Todo:
This function might not be suited for the ShingledFS architecture. Consider what happens to a hard link when the target is opened. The file is deleted and replaced with a symlink to a file on tmpFS. With the deletion, the hard link is removed! Unless the hard links are tracked and recreated on each open and BC eviction, this is bound to fail!
Parameters:
pathPath to the hard link to be created
path_targetPath to the target of the symbolic link
Returns:
0 on success; -1 on failure

Definition at line 1364 of file fuseops.c.

References translate_path(), xattr_get(), and xattr_set().

int shingledfs_listxattr ( const char *  path,
char *  list,
size_t  size 
)

Retrieves the list of extended attributes.

Parameters:
pathPath to the file whose extended attributes are to be set
listBuffer to hold the list of extended attributes
sizeSize of the data in the buffer
Returns:
0 on success; -1 on failure

Definition at line 1014 of file fuseops.c.

References translate_path().

int shingledfs_mkdir ( const char *  path,
mode_t  mode 
)

Creates a new directory.

Documentation in fuse/fuse.h mentions that the mode bit for the directory may not have been set. So it should be ORed with S_IFDIR to ensure that correct directory mode is setup.

Parameters:
pathPath to the new directory
modePermissions to set for the newly created directory
Returns:
0 on success; -errno on failure

Definition at line 114 of file fuseops.c.

References translate_path().

int shingledfs_mknod ( const char *  path,
mode_t  mode,
dev_t  dev 
)

Creates a new file node.

This function calls mknod() to create the requested file along with its Attribute Replication file, into which the attributes of the file are stored.

This function is called by FUSE to create non-directory non-symlink nodes. If create() is defined, then that is called. However, create() only works in Linux kernel after 2.6.15. So it was better to implement the mknod() function instead of create().

Parameters:
pathPath to the file to create
modeAccess mode specifications for the newly created file
file_infofuse_file_info structure from the call to opendir()
Returns:
0 on success; -errno on failure

Definition at line 317 of file fuseops.c.

References translate_path(), xattr_path(), and xattr_set().

int shingledfs_open ( const char *  path,
struct fuse_file_info *  fi 
)

Opens the specified file.

Essentially, this function just calls

See also:
bc_open() to load the file into the buffer cache, and stores the
bc_file_t record of the newly opened file.
Parameters:
pathPath to the file to create
file_infofuse_file_info structure to store file-related data
Returns:
0 on success; -errno on failure

Definition at line 383 of file fuseops.c.

References bc_open(), and translate_path().

int shingledfs_opendir ( const char *  path,
struct fuse_file_info *  fi 
)

Opens the specified directory.

Parameters:
pathPath to the directory to open
fiFUSE File Info structure to store the Directory Pointer
Returns:
0 on success; -errno on failure

Definition at line 170 of file fuseops.c.

References translate_path().

int shingledfs_read ( const char *  path,
char *  buf,
size_t  size,
off_t  offset,
struct fuse_file_info *  fi 
)

Reads data from an open file.

Parameters:
pathPath to the open file.
bufBuffer to hold the data read from the file.
sizeSize of the data to read from the file (in bytes)
offsetOffset into the file from where the data is to be read.
file_infoFUSE structure created when the file was opened.
Returns:
The no. of bytes read, on success; 0 on EOF; -1 on failure

Definition at line 420 of file fuseops.c.

int shingledfs_readdir ( const char *  path,
void *  buf,
fuse_fill_dir_t  filler,
off_t  offset,
struct fuse_file_info *  fi 
)

Reads the list of files in the specified directory.

This function filters out all ShingledFS internal files.

Parameters:
pathPath to the directory
bufBuffer to hold the list of files in the directory
fill_dirPointer to function that will fill out the buffer
offset
file_infofuse_file_info structure from the call to opendir()
Returns:
0 on success; -errno on failure

Definition at line 210 of file fuseops.c.

References FILE_PREFIX.

int shingledfs_readlink ( const char *  path,
char *  buf,
size_t  size 
)

Reads the target of a symbolic link.

Parameters:
pathPath to the symbolic link whose target is to be determined
bufBuffer to hold the target path
sizeSize of the buffer
Returns:
0 on success; -1 on failure

Definition at line 1320 of file fuseops.c.

References translate_path().

int shingledfs_release ( const char *  path,
struct fuse_file_info *  fi 
)

Closes an open file.

Parameters:
pathPath to the file to close
file_infofuse_file_info structure to store file-related data
Returns:
0 on success; -errno on failure

Definition at line 540 of file fuseops.c.

References bc_close(), and translate_path().

int shingledfs_releasedir ( const char *  path,
struct fuse_file_info *  fi 
)

Closes the open directory.

Parameters:
pathPath to the directory to close
fifuse_file_info structure storing the Directory Pointer from opendir
Returns:
0 on success; -errno on failure

Definition at line 263 of file fuseops.c.

References translate_path().

int shingledfs_removexattr ( const char *  path,
const char *  name 
)

Removes an extended attribute.

Parameters:
pathPath to the file whose extended attributes are to be removed
nameName of the extended attribute to update
Returns:
0 on success; -1 on failure

Definition at line 1047 of file fuseops.c.

References translate_path().

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

Renames a file.

Parameters:
pathPath to the file to be renamed
path_newPath to the renamed file
Returns:
0 on success; -errno on failure

Definition at line 571 of file fuseops.c.

References bc_generate_tmpFS_path(), bc_rename(), translate_path(), and xattr_path().

int shingledfs_rmdir ( const char *  path)

Removes a directory.

Parameters:
pathPath to the directory to be removed
Returns:
0 on success; -errno on failure

Definition at line 142 of file fuseops.c.

References translate_path().

int shingledfs_setxattr ( const char *  path,
const char *  name,
const char *  value,
size_t  size,
int  flags 
)

Sets the extended attributes.

Parameters:
pathPath to the file whose extended attribute is to be set
nameName of the extended attribute to update
valueBuffer holding the value to be set for the extended attribute
sizeSize of the data in the buffer
flagsFlags to refine operation semantics
Returns:
0 on success; -1 on failure

Definition at line 930 of file fuseops.c.

References translate_path(), and xattr_set().

int shingledfs_statfs ( const char *  path,
struct statvfs *  statv 
)

Returns ShingledFS file system statistics.

Parameters:
pathPath to any file on ShingledFS
statvBuffer to hold the statistics returned
Returns:
0 on success; -1 on failure

Definition at line 1415 of file fuseops.c.

References translate_path().

int shingledfs_symlink ( const char *  path,
const char *  path_target 
)

Creates a symbolic link.

Parameters:
pathPath to the symbolic link to be created
path_targetPath to the target of the symbolic link
Returns:
0 on success; -1 on failure

Definition at line 1287 of file fuseops.c.

References translate_path().

int shingledfs_truncate ( const char *  path,
off_t  offset 
)

Truncates the file at the specified offset.

Todo:
This function does not need to update the inode information as that will result in leaking of data blocks. Instead, ensure that when a file is loaded, the number of blocks is calculated based on its actual file size; NOT the no. of blocks saved in the inode.
Parameters:
pathPath to the file to be truncated
offsetOffset into the file to truncate at
Returns:
0 on success; -errno on failure

Definition at line 722 of file fuseops.c.

References translate_path(), xattr_get(), and xattr_set().

int shingledfs_unlink ( const char *  path)

Deletes a file.

This function deletes the file and its attribute replication file, if any.

Parameters:
pathPath to the file to be deleted
Returns:
0 on success; -errno on failure

Definition at line 648 of file fuseops.c.

References bc_unlink(), inode_unlink(), translate_path(), xattr_get(), and xattr_path().

int shingledfs_utime ( const char *  path,
struct utimbuf *  tv 
)

Sets the access and/or modification times of the specified file.

Todo:
Update to account for attribute replication
Parameters:
pathPath to the file to create utimebuf structure containing the new timestamps
Returns:
0 on success; -errno on failure

Definition at line 1143 of file fuseops.c.

References translate_path(), xattr_get(), and xattr_set().

int shingledfs_write ( const char *  path,
const char *  buf,
size_t  size,
off_t  offset,
struct fuse_file_info *  fi 
)

Write data to an open file.

If the write() fails, this function checks to see if the device is full; i.e. tmpFS is out of space. If this is the case, then

See also:
bc_clean() is called to evict a file to create more space in tmpFS.
Parameters:
pathPath to the open file.
bufBuffer holding the data to be written.
sizeSize of the data to be written (in bytes).
offsetOffset into the file where the data is to be written.
file_infoFUSE structure created when the file was opened.
Returns:
The no. of bytes written, on success; -1 on failure

Definition at line 464 of file fuseops.c.

References bc_clean().