Distributed Hash Table File System for Linux








magma_flare.c File Reference

#include "magma.h"

Defines

#define INCLUDE_FLARE_INTERNALS
#define reduce_file_descriptors()   dbg(LOG_ERR, DEBUG_ERR, "Define a reduce_file_descriptor() function to manage FD starvation")
#define STACK_DEPTH   20

Functions

int magma_getattr (uid_t uid, gid_t gid, const char *path, struct stat *stbuf)
int magma_stat (uid_t uid, gid_t gid, const char *path, struct stat *stbuf)
int magma_statfs (uid_t uid, gid_t gid, const char *path, struct statfs *statbuf)
int magma_mknod (uid_t uid, gid_t gid, const char *path, mode_t mode, dev_t rdev)
int magma_unlink (uid_t uid, gid_t gid, const char *path)
int magma_truncate (uid_t uid, gid_t gid, const char *path, off_t offset)
int magma_utime (uid_t uid, gid_t gid, const char *path, time_t atime, time_t mtime)
int magma_rename (uid_t uid, gid_t gid, const char *from, const char *to)
int magma_chmod (uid_t uid, gid_t gid, const char *path, mode_t mode)
int magma_chown (uid_t uid, gid_t gid, const char *path, uid_t newuid, gid_t newgid)
int magma_open (uid_t uid, gid_t gid, const char *path, int flags)
int magma_read (uid_t uid, gid_t gid, const char *path, size_t size, off_t offset, char *buf)
int magma_write (uid_t uid, gid_t gid, const char *path, size_t size, off_t offset, char *buf)
int magma_mkdir (uid_t uid, gid_t gid, const char *path, mode_t mode)
int magma_rmdir (uid_t uid, gid_t gid, const char *path)
int magma_readlink (uid_t uid, gid_t gid, const char *path, char *buf, size_t size)
int magma_symlink (uid_t uid, gid_t gid, const char *from, const char *to)
void magma_sync_cache ()
void magma_flush_cache ()
magma_DIR_tmagma_opendir (uid_t uid, gid_t gid, const char *path)
char * magma_readdir (magma_DIR_t *dirp)
void magma_seekdir (magma_DIR_t *dirp, off_t offset)
off_t magma_telldir (magma_DIR_t *dirp)
void magma_closedir (magma_DIR_t *dirp)
void magma_cleanup (int s)
void clean_shutdown ()
void magma_network_loop (int single_thread)

Define Documentation

#define INCLUDE_FLARE_INTERNALS

 
#define reduce_file_descriptors (  )     dbg(LOG_ERR, DEBUG_ERR, "Define a reduce_file_descriptor() function to manage FD starvation")

#define STACK_DEPTH   20


Function Documentation

void clean_shutdown (  ) 

perform a clean server shutdown and exits main process

int magma_chmod ( uid_t  uid,
gid_t  gid,
const char *  path,
mode_t  mode 
)

chmod() equivalent. Changes mode to a flare.

Parameters:
uid UID requesting the operation
gid GID requesting the operation
path path of the flare requested
mode new flare mode
Returns:
0 on success, -1 on error and sets errno

int magma_chown ( uid_t  uid,
gid_t  gid,
const char *  path,
uid_t  newuid,
gid_t  newgid 
)

chown() equivalent. Changes ownership to a flare.

Parameters:
uid UID requesting the operation
gid GID requesting the operation
path path of the flare requested
newuid new UID to be assigned to the flare
newgid new GID to be assigned to the flare
Returns:
0 on success, -1 on error and sets errno

void magma_cleanup ( int  s  ) 

hook for signal()

Parameters:
s signal received

void magma_closedir ( magma_DIR_t dirp  ) 

close opened directory.

Parameters:
dirp magma_DIR_t pointer of opened directory

void magma_flush_cache (  ) 

write cache on disk and delete it from memory

int magma_getattr ( uid_t  uid,
gid_t  gid,
const char *  path,
struct stat *  stbuf 
)

magma flare system interface mimics as closer as possible libc function interface. every function listed below set errno on its exit.

each function gets a uid and gid to assign the operation to a used and to chek permission lstat() equivalent. Fills struct stat stbuf of informations relating to flare path.

Parameters:
uid UID requesting the operation
gid GID requesting the operation
path path of the flare requested
stbuf struct stat result buffer
Returns:
0 on success, -1 on error and sets errno

int magma_mkdir ( uid_t  uid,
gid_t  gid,
const char *  path,
mode_t  mode 
)

mkdir() equivalent. Create a new directory flare.

Parameters:
uid UID requesting the operation
gid GID requesting the operation
path path of the directory
mode directory permission
Returns:
0 on success, -1 on error and sets errno

int magma_mknod ( uid_t  uid,
gid_t  gid,
const char *  path,
mode_t  mode,
dev_t  rdev 
)

mknod() equivalent. Create new regular, FIFO char and block dev flares. Returns an error if used to create a directory.

Parameters:
uid UID requesting the operation
gid GID requesting the operation
path path of the flare to be created
mode permission and flare type (see mknod(2) for more info)
rdev major and minor number if flare is a char or block device
Returns:
0 on success, -1 on error and sets errno

void magma_network_loop ( int  single_thread  ) 

This is the core of network event loop provided by magma. So far, it simply accept new connections and spawn a new thread to manage it. If single_thread is true, no new thread is created and network loop serve answers by pipelining them (only for debug purposes).

Parameters:
single_thread if true, requests are managed in this thread
Todo:
Using a better threading mechanism will provide better performances. New incoming connections should be placed in a queue and serviced by pre started threads. When changing this, change also garbage collector.

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

open() equivalent.

Parameters:
uid UID requesting the operation
gid GID requesting the operation
path path of the flare requested
flags describe the type of open (read, write, ...) (see open(2) for more informations)
Returns:
0 on success, -1 on error and sets errno

magma_DIR_t* magma_opendir ( uid_t  uid,
gid_t  gid,
const char *  path 
)

open a magma directory returning a magma_DIR_t directory pointer. set offset to zero.

Parameters:
uid UID of user requesting opendir
gid GID of user requesting opendir
path the path to be opened

int magma_read ( uid_t  uid,
gid_t  gid,
const char *  path,
size_t  size,
off_t  offset,
char *  buf 
)

read() equivalent. Read some data from a regular flare.

Parameters:
uid UID requesting the operation
gid GID requesting the operation
path path of the flare requested
size requested data length
offset requested data position inside the flare
buf memory region to store read data
Returns:
0 on success, -1 on error and sets errno
Todo:
Is present a test to ensure that flare is a regular one?

char* magma_readdir ( magma_DIR_t dirp  ) 

return next entry in opened directory

Parameters:
dirp a magma_DIR_t pointer

int magma_readlink ( uid_t  uid,
gid_t  gid,
const char *  path,
char *  buf,
size_t  size 
)

readlink() equivalent. Read target of a link.

Parameters:
uid UID requesting the operation
gid GID requesting the operation
path path of the flare requested
buf memory location to store link target
size dimension of buffer buf
Returns:
0 on success, -1 on error and sets errno

int magma_rename ( uid_t  uid,
gid_t  gid,
const char *  from,
const char *  to 
)

rename() equivalent. Change name to a flare.

Parameters:
uid UID requesting the operation
gid GID requesting the operation
from original flare path
to new flare path
Returns:
0 on success, -1 on error and sets errno
Todo:
So far magma uses a typical errno (EXDEV) which means cross link rename to refuse renaming a flare, since that can involve up to four magma nodes. Can be changed in the future...

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

rmdir() equivalent. Delete a directory flare.

Parameters:
uid UID requesting the operation
gid GID requesting the operation
path path of the flare requested
Returns:
0 on success, -1 on error and sets errno
Todo:
Is there a test to ensure it's a directory flare?

void magma_seekdir ( magma_DIR_t dirp,
off_t  offset 
)

seek inside a directory (only if a local one)

Parameters:
dirp magma_DIR_t pointer of opened directory
offset new off_t offset

int magma_stat ( uid_t  uid,
gid_t  gid,
const char *  path,
struct stat *  stbuf 
)

stat() equivalent. Fills struct stat stbuf of informations relating to flare path.

Parameters:
uid UID requesting the operation
gid GID requesting the operation
path path of the flare requested
stbuf struct stat result buffer
Returns:
0 on success, -1 on error and sets errno

int magma_statfs ( uid_t  uid,
gid_t  gid,
const char *  path,
struct statfs *  statbuf 
)

statfs() equivalent. Fills struct statfs statbuf of informations relating to share which holds flare path. Since magma preorganize shares and since flare protocol predeclare the share involved in current connection, passing a path is useless. But parameter has been mantained so far.

Parameters:
uid UID requesting the operation
gid GID requesting the operation
path path of the flare requested
statbuf struct stat result buffer
Returns:
0 on success, -1 on error and sets errno

int magma_symlink ( uid_t  uid,
gid_t  gid,
const char *  from,
const char *  to 
)

symlink() equivalent. Create a symbolic link.

Parameters:
uid UID requesting the operation
gid GID requesting the operation
from path of the symbolic link
to target path of this link
Returns:
0 on success, -1 on error and sets errno

void magma_sync_cache (  ) 

write cache on disk

off_t magma_telldir ( magma_DIR_t dirp  ) 

return current offset in opened directory

Parameters:
dirp magma_DIR_t pointer of opened directory

int magma_truncate ( uid_t  uid,
gid_t  gid,
const char *  path,
off_t  offset 
)

truncate() equivalent. Truncate a regular flare.

Parameters:
uid UID requesting the operation
gid GID requesting the operation
path path of the flare requested
offset the truncation point
Returns:
0 on success, -1 on error and sets errno
Todo:
There is a check to ensure this flare is a regular one?

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

unlink() equivalent. Delete a regular, FIFO, char or block dev flare.

Parameters:
uid UID requesting the operation
gid GID requesting the operation
path path of the flare to be unlinked
Returns:
0 on success, -1 on error and sets errno

int magma_utime ( uid_t  uid,
gid_t  gid,
const char *  path,
time_t  atime,
time_t  mtime 
)

utime() equivalent. Update access and modification time of a flare.

Parameters:
uid UID requesting the operation
gid GID requesting the operation
path path of the flare requested
atime access time
mtime modification time
Returns:
0 on success, -1 on error and sets errno

int magma_write ( uid_t  uid,
gid_t  gid,
const char *  path,
size_t  size,
off_t  offset,
char *  buf 
)

write() equivalent. Write some data to a regular file. relating to flare path.

Parameters:
uid UID requesting the operation
gid GID requesting the operation
path path of the flare requested
size data length
offset data position inside the flare
buf memory region to store read data
Returns:
0 on success, -1 on error and sets errno
Todo:
Is present a test to ensure that flare is a regular one?

This file last modified Wednesday, 09-Jan-2008 20:02:47 CET