Distributed Hash Table File System for Linux








magma_flare.h File Reference

#include "magma_setup.h"
#include "magma_flare_types.h"

Defines

#define flare_generic_setup()
#define magma_lstat(uid, gid, path, stbuf)   magma_getattr(uid, gid, path, stbuf);
#define magma_link(uid, gid, from, to)   magma_symlink(uid, gid, from, to)

Functions

int flare_system_init (int bootstrap, char *bootserver, int bootport, int start_balancer)
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)
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_sync_cache ()
void magma_flush_cache ()
void magma_cleanup (int s)
void clean_shutdown ()
void magma_set_state (uint8_t state)
uint8_t magma_get_state ()
void magma_network_loop (int single_thread)

Variables

const uint8_t MAGMA_OFF
const uint8_t MAGMA_RUNNING
const uint8_t MAGMA_DHT_REBUILD
const uint8_t MAGMA_SHUTDOWN

Define Documentation

 
#define flare_generic_setup (  ) 

Value:

magma_config_myself(strdup("magma-tool"),strdup("magma-tool.magmafs.net"),strdup("127.0.0.1"),12000,1,1);\
        flare_system_init(1,NULL,0,0);
perform a generic setup for the flare system. as you can guess from name "magma-tool", this macro is intended for magma command line tools, like magma_ls.

#define magma_link ( uid,
gid,
from,
to   )     magma_symlink(uid, gid, from, to)

link() equivalent. Since magma use crosslink devices to store flares, doing hardlink is not always passible. Hard link are transformed in symlink transparently.

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

#define magma_lstat ( uid,
gid,
path,
stbuf   )     magma_getattr(uid, gid, path, stbuf);


Function Documentation

void clean_shutdown (  ) 

perform clean shutdown, what else?

perform a clean server shutdown and exits main process

int flare_system_init ( int  bootstrap,
char *  bootserver,
int  bootport,
int  start_balancer 
)

This call should be used on top of any program using the flare system to reserve resources internally used!

If bootstrap == 1, bootserver and bootport are ignored, so flare_system_init(1,NULL,0,0) is a valid call.

Before calling flare_system_init(), call magma_config_myself(). (see vulcano.h)

Actually it is declared inside magma_flare_internals.c but is exported by magma_flare.h because is needed to initialize the flare system.

Parameters:
bootstrap if true, new lava will be created, if false this node will remote bootstrap
bootserver remote boot server used if bootstrap is false
bootport remote boot port used if bootstrap is false
start_balancer if true, balancer thread will be started
Returns:
Always 0. Return value can be ignored since, in case of failure, exit(N) is called.

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  ) 

closedir() equivalent. Close an open directory flare handle. If directory has been modified, reflect changes on disk.

Parameters:
dirp handle to open directory flare
Returns:
nothing. Always succeed.
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

uint8_t magma_get_state (  ) 

get this node state

Returns:
this node current state

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 
)

opendir() equivalent. Opens a directory flare for reading and inserting/removing data.

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

readdir() equivalent. Read next entry from and opened directory flare given as magma_DIR_t handle.

Parameters:
dirp handle to open directory flare
Returns:
0 on success, -1 on error and sets errno
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 
)

seekdir() equivalent. Reposition directory pointer to another location.

Parameters:
dirp handle to open directory flare
offset new handle position
Returns:
nothing. Always succeed.
seek inside a directory (only if a local one)

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

void magma_set_state ( uint8_t  state  ) 

set this node state to one of previous MAGMA_* states

Parameters:
state new state
Returns:
nothing. Always succeed.

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  ) 

telldir() equivalent. Tell current directory handle position.

Parameters:
dirp handle to open directory flare
Returns:
current directory handle position
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?


Variable Documentation

const uint8_t MAGMA_DHT_REBUILD

this node is rebuilding DHT

const uint8_t MAGMA_OFF

this node is not operating

const uint8_t MAGMA_RUNNING

this node is up'n'running

const uint8_t MAGMA_SHUTDOWN

this node is shutting down

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