magma_flare_internals.h File Reference
#include "magma_setup.h"#include "magma_flare_types.h"Defines | |
| #define | MAGMA_ACL_FILE "/etc/magma/acl" |
| #define | MAGMA_EXPORTS_FILE "/etc/magma/exports" |
| #define | MAGMA_EXPORTS_FILE_BACK "/etc/magma/exports.back" |
| #define | DHT_PATH "/.dht" |
| #define | RUN_PATH "/var/run/magma/" |
| #define | magma_flare_upcast(f, res) |
| #define | print_flare_cast(flare) |
| #define | open_flare_metadata(flare) open(flare->metadata, O_RDWR|O_CREAT) |
| #define | open_flare_contents(flare) open(flare->contents, O_RDWR|O_CREAT) |
| #define | __isreg(flare) S_ISREG(flare->st.st_mode) |
| #define | __isdir(flare) S_ISDIR(flare->st.st_mode) |
| #define | __ischr(flare) S_ISCHR(flare->st.st_mode) |
| #define | __isblk(flare) S_ISBLK(flare->st.st_mode) |
| #define | __isfifo(flare) S_ISFIFO(flare->st.st_mode) |
| #define | __issock(flare) S_ISSOCK(flare->st.st_mode) |
| #define | __islnk(flare) S_ISLNK(flare->st.st_mode) |
| #define | TOUCH_ATIME 1 |
| #define | TOUCH_CTIME 2 |
| #define | TOUCH_MTIME 4 |
| #define | lock_flare_read(f) |
| #define | unlock_flare_read(f) |
| #define | lock_flare_write(f) |
| #define | unlock_flare_write(f) |
| #define | OPERATION_R 1 |
| #define | OPERATION_W 2 |
| #define | OPERATION_X 4 |
| #define | explain_permission(optype) |
| #define | dir_border_formula(d) d->item.dir->pages + d->item.dir->lastpage * pagesize |
| #define | get_directory_border(d, border, res, st) |
| #define | CHECK_LOAD 1 |
| #define | DONT_CHECK_LOAD 0 |
| #define | magma_add_to_cache(flare) magma_add_to_cache_after(flare,magma_cache,CHECK_LOAD) |
| #define | IS_LEAF(flare) ((flare->left == NULL) && (flare->right == NULL)) |
| #define | MOST_LOADED(flare1, flare2) |
| #define | CHECK_LOAD_TIMEOUT 10 |
| #define | BALANCER_KEY_DELTA 10 |
| #define | route_key(key) internal_route_key(key,lava->middle_node,0) |
| #define | redundant_route_key(key) internal_route_key(key,lava->middle_node,1) |
| #define | route_path(path) internal_route_path(path,0) |
| #define | redundant_route_path(path) internal_route_path(path,1) |
| #define | magma_count_cache_elements() magma_count_cache_elements_on_node(magma_cache) |
Functions | |
| magma_flare_t * | magma_new_flare (const char *path) |
| int | magma_cast_to_dir (magma_flare_t *flare) |
| magma_flare_t * | magma_new_dir_flare (const char *path) |
| int | magma_cast_to_file (magma_flare_t *flare) |
| magma_flare_t * | magma_new_file_flare (const char *path) |
| int | magma_cast_to_blockdev (magma_flare_t *flare) |
| magma_flare_t * | magma_new_blockdev_flare (const char *path) |
| int | magma_cast_to_chardev (magma_flare_t *flare) |
| magma_flare_t * | magma_new_chardev_flare (const char *path) |
| int | magma_cast_to_symlink (magma_flare_t *flare) |
| magma_flare_t * | magma_new_symlink_flare (const char *path) |
| int | magma_cast_to_fifo (magma_flare_t *flare) |
| magma_flare_t * | magma_new_fifo_flare (const char *path) |
| int | magma_destroy_flare (magma_flare_t *flare) |
| int | magma_check_flare (magma_flare_t *flare) |
| int | magma_erase_flare_from_disk (magma_flare_t *flare) |
| int | magma_erase_flare (magma_flare_t *flare) |
| int | magma_init_flare_on_disk (magma_flare_t *flare) |
| int | magma_save_flare (magma_flare_t *flare) |
| int | magma_load_flare (magma_flare_t *flare) |
| int | magma_touch_flare (magma_flare_t *flare, int mode) |
| unsigned int | magma_get_flare_inode (magma_flare_t *flare) |
| void | print_flare (magma_flare_t *flare) |
| uint8_t | check_permission (magma_flare_t *flare, uid_t uid, gid_t gid, uint8_t operations) |
| int | allocate_blank_page () |
| int | magma_grow_directory (magma_flare_t *dir) |
| int | check_directory_size (char *border, magma_DIR_t *dirp, int res, struct stat *st, int do_grow_file) |
| char * | magma_get_slot (magma_DIR_t *dirp, int do_grow_file) |
| char * | magma_get_empty_slot (magma_DIR_t *dirp) |
| char * | magma_get_full_slot (magma_DIR_t *dirp) |
| int | magma_get_slot_length (magma_DIR_t *dirp, char *slot) |
| int | magma_push_dirent (magma_DIR_t *dirp, char *path) |
| int | magma_pop_dirent (magma_DIR_t *dirp, char *dirent) |
| int | magma_add_flare_to_parent (magma_flare_t *flare) |
| int | magma_remove_flare_from_parent (magma_flare_t *flare) |
| int | magma_dir_is_empty (magma_flare_t *dir) |
| magma_flare_t * | magma_search (const char *path) |
| magma_flare_t * | magma_search_by_hash (const unsigned char *hash) |
| magma_flare_t * | magma_search_by_armour (const char *armoured) |
| magma_flare_t * | magma_search_or_create (const char *hash) |
| magma_flare_t * | magma_search_or_create_by_hash (const char *hash) |
| magma_flare_t * | magma_search_under_node (const char *hash, magma_flare_t *startnode) |
| magma_flare_t * | magma_add_to_cache_after (magma_flare_t *flare, magma_flare_t *node, int checkload) |
| int | magma_remove_from_cache (magma_flare_t *flare) |
| void * | balance (void *data) |
| int | check_filesystem (void) |
| int | bootstrap_network () |
| magma_node_t * | internal_route_key (const char *key, magma_node_t *node, int redundant_space) |
| magma_node_t * | internal_route_path (const char *path, int redundant_space) |
| int | compare_nodes (const magma_node_t *n1, const magma_node_t *n2) |
| int | magma_parse_acl_file (const char *filename) |
| int | magma_validate_connection (struct in_addr *s, const char *share, const char *path, char optype) |
| void | magma_save_cache_node (magma_flare_t *node, int remove) |
| long long int | magma_count_cache_elements_on_node (magma_flare_t *node) |
| char * | magma_simplify_path (const char *path) |
Variables | |
| magma_share_t * | shares |
| const char | dht_path [] |
| const char | run_path [] |
| uid_t | flare_system_uid |
| gid_t | flare_system_gid |
| int | pagesize |
| char * | blank_page |
| magma_flare_t * | magma_cache |
| magma_network_t * | lava |
Define Documentation
| #define __isblk | ( | flare | ) | S_ISBLK(flare->st.st_mode) |
| #define __ischr | ( | flare | ) | S_ISCHR(flare->st.st_mode) |
| #define __isdir | ( | flare | ) | S_ISDIR(flare->st.st_mode) |
| #define __isfifo | ( | flare | ) | S_ISFIFO(flare->st.st_mode) |
| #define __islnk | ( | flare | ) | S_ISLNK(flare->st.st_mode) |
| #define __isreg | ( | flare | ) | S_ISREG(flare->st.st_mode) |
| #define __issock | ( | flare | ) | S_ISSOCK(flare->st.st_mode) |
| #define BALANCER_KEY_DELTA 10 |
| #define CHECK_LOAD 1 |
| #define CHECK_LOAD_TIMEOUT 10 |
| #define DHT_PATH "/.dht" |
| #define dir_border_formula | ( | d | ) | d->item.dir->pages + d->item.dir->lastpage * pagesize |
Is equivalent to directory d border address
| #define DONT_CHECK_LOAD 0 |
| #define explain_permission | ( | optype | ) |
Value:
{\
if (optype & OPERATION_R) {\
dbg(LOG_ERR, DEBUG_ERR, "Reading not allowed");\
}\
if (optype & OPERATION_W) {\
dbg(LOG_ERR, DEBUG_ERR, "Writing not allowed");\
}\
if (optype & OPERATION_X) {\
dbg(LOG_ERR, DEBUG_ERR, "Executing not allowed");\
}\
}
| #define get_directory_border | ( | d, | |||
| border, | |||||
| res, | |||||
| st | ) |
Value:
{\
res = -1;\
if ((d->item.dir->pages != NULL) && (d->item.dir->lastpage != 0)) {\
border = dir_border_formula(d);\
} else if ((res = lstat(d->contents, &st)) != -1) {\
border = st.st_size + d->item.dir->pages;\
} else\
border = NULL;\
}
The formula gets memory location for directory pages (d->item.dir->pages) and adds the allocated amount of space got from total page number (d->item.dir->lastpage) multiplyed by pagesize.
- Parameters:
-
d directory flare to be bordered border resulting border location (as char*) res result of lstat() if done st struct stat filled by lstat() if done. Should be used only if res != -1.
| #define IS_LEAF | ( | flare | ) | ((flare->left == NULL) && (flare->right == NULL)) |
| #define lock_flare_read | ( | f | ) |
Value:
{\
dbg(LOG_INFO, DEBUG_MUTEX, "[R+] lock on \"%s\" @ %s:%d", f->path, __FILE__, __LINE__);\
pthread_rwlock_rdlock(&(f->rwlock));\
f->in_use = f->in_use <= 0 ? 1 : f->in_use + 1;\
}
| #define lock_flare_write | ( | f | ) |
Value:
{\
dbg(LOG_INFO, DEBUG_MUTEX, "[W+] lock on \"%s\" @ %s:%d", f->path, __FILE__, __LINE__);\
pthread_rwlock_wrlock(&(f->rwlock));\
f->in_use = f->in_use <= 0 ? 1 : f->in_use + 1;\
}
| #define MAGMA_ACL_FILE "/etc/magma/acl" |
| #define magma_add_to_cache | ( | flare | ) | magma_add_to_cache_after(flare,magma_cache,CHECK_LOAD) |
| #define magma_count_cache_elements | ( | ) | magma_count_cache_elements_on_node(magma_cache) |
| #define MAGMA_EXPORTS_FILE "/etc/magma/exports" |
| #define MAGMA_EXPORTS_FILE_BACK "/etc/magma/exports.back" |
| #define magma_flare_upcast | ( | f, | |||
| res | ) |
Value:
{\
if (__isdir(f)) { res = magma_cast_to_dir(f); }\
else if (__isreg(f)) { res = magma_cast_to_file(f); }\
else if (__isblk(f)) { res = magma_cast_to_blockdev(f); }\
else if (__ischr(f)) { res = magma_cast_to_chardev(f); }\
else if (__isfifo(f)) { res = magma_cast_to_fifo(f); }\
else if (__islnk(f)) { res = magma_cast_to_symlink(f); }\
else {\
dbg(LOG_ERR, DEBUG_ERR, "flare %s can't be upcasted!", f->path)\
res = 0;\
}\
}
| #define MOST_LOADED | ( | flare1, | |||
| flare2 | ) |
Value:
(\
((flare1 != NULL) && (flare2 != NULL))\
?\
((flare1->load > flare2->load) ? flare1 : flare2)\
:\
((flare1 != NULL) ? flare1 : flare2)\
)
| #define open_flare_contents | ( | flare | ) | open(flare->contents, O_RDWR|O_CREAT) |
| #define open_flare_metadata | ( | flare | ) | open(flare->metadata, O_RDWR|O_CREAT) |
| #define OPERATION_R 1 |
| #define OPERATION_W 2 |
| #define OPERATION_X 4 |
| #define print_flare_cast | ( | flare | ) |
Value:
{\
if (__isreg(flare)) { dbg(LOG_INFO, DEBUG_FLARE, "Flare is a regular file"); }\
else if (__isdir(flare)) { dbg(LOG_INFO, DEBUG_FLARE, "Flare is a directory"); }\
else if (__isblk(flare)) { dbg(LOG_INFO, DEBUG_FLARE, "Flare is a block dev"); }\
else if (__ischr(flare)) { dbg(LOG_INFO, DEBUG_FLARE, "Flare is a char dev"); }\
else if (__isfifo(flare)) { dbg(LOG_INFO, DEBUG_FLARE, "Flare is a FIFO"); }\
else if (__islnk(flare)) { dbg(LOG_INFO, DEBUG_FLARE, "Flare is a symlink"); }\
else { dbg(LOG_INFO, DEBUG_FLARE, "Flare is not casted?"); }\
}
| #define redundant_route_key | ( | key | ) | internal_route_key(key,lava->middle_node,1) |
| #define redundant_route_path | ( | path | ) | internal_route_path(path,1) |
| #define route_key | ( | key | ) | internal_route_key(key,lava->middle_node,0) |
| #define route_path | ( | path | ) | internal_route_path(path,0) |
| #define RUN_PATH "/var/run/magma/" |
| #define TOUCH_ATIME 1 |
| #define TOUCH_CTIME 2 |
| #define TOUCH_MTIME 4 |
| #define unlock_flare_read | ( | f | ) |
Value:
{\
pthread_rwlock_unlock(&(f->rwlock));\
f->in_use--;\
dbg(LOG_INFO, DEBUG_MUTEX, "[R-] lock on \"%s\" @ %s:%d", f->path, __FILE__, __LINE__);\
}
| #define unlock_flare_write | ( | f | ) |
Value:
{\
pthread_rwlock_unlock(&(f->rwlock));\
f->in_use--;\
dbg(LOG_INFO, DEBUG_MUTEX, "[W-] lock on \"%s\" @ %s:%d", f->path, __FILE__, __LINE__);\
}
Function Documentation
| int allocate_blank_page | ( | ) |
Preallocate a blank page of pagesize bytes used for directory mmap() operations
- Returns:
- 1 on success, 0 on failure
| void* balance | ( | void * | data | ) |
This is the balancer thread function which periodically checks for lava network overall load and perform balancing on sibling vulcanos.
- Parameters:
-
data magma_node_t structure rappresenting this node, declared (void *) according to pthread specification
- Returns:
- NULL (result can be safely ignored)
| int bootstrap_network | ( | ) |
Bootstrap a new lava ring network. First checks the filesystem using check_filesystem(). Than init myself node by assigning the whole key space to this node. Finally creates "/" flare directory and "/.dht" flare directory.
| int check_directory_size | ( | char * | border, | |
| magma_DIR_t * | dirp, | |||
| int | res, | |||
| struct stat * | st, | |||
| int | do_grow_file | |||
| ) |
Checks if current directory size can hold a new slot of NAME_MAX size. Strange res and st parameters are due to previous coding state when check_directory_size was directly embedded in magma_get_slot(), which is currently the only function to call this one.
- Parameters:
-
border directory ending address dirp directory handle res result of previous lstat() st struct stat filled by previous lstat() do_grow_file if equals to GROW_FILE, directory is grown by one page if needed
- Returns:
- 0 on success, -1 on failure (errno is set to ENOSPC)
| int check_filesystem | ( | void | ) |
Performs prechecking of filesystem, creating storage directory.
- Returns:
- always 0. In case of failure, will exit(1) the program.
| uint8_t check_permission | ( | magma_flare_t * | flare, | |
| uid_t | uid, | |||
| gid_t | gid, | |||
| uint8_t | operations | |||
| ) |
Check if a user with specified uid and gid is allowed to perform "operations" operation on flare
- Parameters:
-
flare the flare to be accessed uid UID accessing the flare gid GID accessing the flare operations bitmask field of required operations
- Returns:
- 0 if success, a uint8_t with failing operations otherwise
| int compare_nodes | ( | const magma_node_t * | n1, | |
| const magma_node_t * | n2 | |||
| ) |
Compares two nodes to check if are the same.
- Parameters:
-
n1 first given node n2 second given node
- Returns:
- 1 if nodes are the same, 0 otherwise
| magma_node_t* internal_route_key | ( | const char * | key, | |
| magma_node_t * | node, | |||
| int | redundant_space | |||
| ) |
route a key in key space. never use this function directly. use macros route_key() and redundant_route_key()
- Parameters:
-
key pointer to key to be routed node pointer to node used for operation in this round redundant_space if true, use redundant key space for routing
- Returns:
- pointer to owner node, NULL in case of failure.
| magma_node_t* internal_route_path | ( | const char * | path, | |
| int | redundant_space | |||
| ) |
route a file path in key space. never use this function directly. use macros route_path() and redundant_route_path()
- Parameters:
-
path pointer to path to be routed redundant_space if true, use redundant key space for routing
- Returns:
- pointer to owner node, NULL in case of failure.
| int magma_add_flare_to_parent | ( | magma_flare_t * | flare | ) |
Adds a flare to parent directory. barely just a wrapper around magma_push_dirent() which also check for existance of new entry
- Parameters:
-
flare the flare to be added
- Returns:
- 0 on success, -1 on failure (errno is set accordingly)
| magma_flare_t* magma_add_to_cache_after | ( | magma_flare_t * | flare, | |
| magma_flare_t * | node, | |||
| int | checkload | |||
| ) |
Adds an entry to magma to caching system. should never be used directly. Always use macro magma_add_to_cache() instead. This function use recursion to traverse the entire tree. magma_add_to_cache() simply calls this function with magma_cache as second param.
- Parameters:
-
flare is the flare to be added to cache node is the flare inside the cache to match for positioning checkload if equals to CHECK_LOAD, load of parent branch is updated
- Returns:
- the node added if succesful, NULL otherwise.
| int magma_cast_to_blockdev | ( | magma_flare_t * | flare | ) |
cast a flare to a block device flare
- Parameters:
-
flare the flare to be casted
- Returns:
- 1 on success, 0 otherwise
| int magma_cast_to_chardev | ( | magma_flare_t * | flare | ) |
cast a flare to a character device flare
- Parameters:
-
flare the flare to be casted
- Returns:
- 1 on success, 0 otherwise
| int magma_cast_to_dir | ( | magma_flare_t * | flare | ) |
cast a flare to a directory flare
- Parameters:
-
flare the flare to be casted
- Returns:
- 1 on success, 0 otherwise
| int magma_cast_to_fifo | ( | magma_flare_t * | flare | ) |
cast a flare to a FIFO flare
- Parameters:
-
flare the flare to be casted
- Returns:
- 1 on success, 0 otherwise
| int magma_cast_to_file | ( | magma_flare_t * | flare | ) |
cast a flare to a regular file flare
- Parameters:
-
flare the flare to be casted
- Returns:
- 1 on success, 0 otherwise
| int magma_cast_to_symlink | ( | magma_flare_t * | flare | ) |
cast a flare to a symbolic link flare
- Parameters:
-
flare the flare to be casted
- Returns:
- 1 on success, 0 otherwise
| int magma_check_flare | ( | magma_flare_t * | flare | ) |
check if flare is still on disk (has not been removed by external agent able to access repository space)
- Parameters:
-
flare flare to be checked
- Returns:
- 0 on success, -1 on failure (errno is set accordingly)
| long long int magma_count_cache_elements_on_node | ( | magma_flare_t * | node | ) |
recursively counts element below given node
- Parameters:
-
node the node to calculated
- Returns:
- load of the node
| int magma_destroy_flare | ( | magma_flare_t * | flare | ) |
free resources used by a flare
- Parameters:
-
flare the flare to be destroyed
- Returns:
- 0 on success, 1 otherwise
- Todo:
- Why 0 on success? Should be better 1 on success!
| int magma_dir_is_empty | ( | magma_flare_t * | dir | ) |
Check if a directory is empty.
- Parameters:
-
dir the directory to be test for emptiness
- Returns:
- 0 if directory dir is not empty (there is at least 1 entry before end of last page), 1 otherwise (or dir has some problem like being NULL pointer...)
- Todo:
- If this check is used while doing a "rmdir" should it return 0 if even if only "." and ".." are listed? Please verify.
| int magma_erase_flare | ( | magma_flare_t * | flare | ) |
Erase a flare from parent and from disk, basically calling remove_flare_from_parent() and erase_flare_from_disk() in sequence. Flare is also removed from cache.
- Parameters:
-
flare the flare to be saved
- Returns:
- 0 on success, -1 on failure
| int magma_erase_flare_from_disk | ( | magma_flare_t * | flare | ) |
Erase a flare from disk
- Parameters:
-
flare the flare to be saved
- Returns:
- 0 on success, -1 on failure
| char* magma_get_empty_slot | ( | magma_DIR_t * | dirp | ) |
Calls magma_get_slot() until a new empty slot (a slot not pointing to a valid entry) is found.
- Parameters:
-
dirp magma_DIR_t pointer used to track offset inside directory
- Returns:
- a pointer to next free slot inside directory. Modifying this pointer contents means working on directory contents.
| unsigned int magma_get_flare_inode | ( | magma_flare_t * | flare | ) |
Return a flare inode. that function should be expanded to consider vulcano on which flare is located. inodes should be 64bit integers and should be ORed with vulcano number in MSB to allow a consistent numbering scheme for all nodes. that should result in 16bit for vulcano network (which is 65535 nodes! quite a big SAN) and 48 bits for local inodes.
- Parameters:
-
flare the flare
- Returns:
- unsigned value rappresenting flare inode
- Todo:
- this function should still be coded!!!
| char* magma_get_full_slot | ( | magma_DIR_t * | dirp | ) |
Calls magma_get_slot() until a new valid slot (a slot pointing to a valid entry) is found.
- Parameters:
-
dirp magma_DIR_t pointer used to track offset inside directory
- Returns:
- a pointer to filled slot. Modifying this pointer contents means working on directory contents.
| char* magma_get_slot | ( | magma_DIR_t * | dirp, | |
| int | do_grow_file | |||
| ) |
get a slot inside a directory. a slot is basically a valid position. using a magma_DIR_t pointer, this function can keep track of current position, using offset member. offset should always refer to a valid entry or to empty space.
if it points to a valid entry, magma_get_slot() will move offset forward of length of current entry plus 1 position for \0 null terminator.
if it points to free space, simply forwards offset by 1.
it does not check if next slot is big enough to store a new entry. just check if from current offset position to end of last page there is enough space to store a NAME_MAX entry (usually 255 characters). if not, a new page is allocated using magma_grow_directory(). there is just an exception: if was called with do_grow_file equals to DONT_GROW_FILE, directory will not be grown.
- Parameters:
-
dirp magma_DIR_t pointer used to track current position do_grow_file if GROW_FILE, directory will be grown, if DONT_GROW_FILE, directory will be unaltered
- Returns:
- a pointer to found slot. Modifying this pointer contents means changing directory contents.
| int magma_get_slot_length | ( | magma_DIR_t * | dirp, | |
| char * | slot | |||
| ) |
Return slot length without risk to have an overflow on mmap()ed directory area.
- Parameters:
-
dirp magma_DIR_t pointer used to track offset inside directory slot the (valid or not) slot to be mesured
- Returns:
- slot length
| int magma_grow_directory | ( | magma_flare_t * | dir | ) |
Grow a directory's contents file by 1 page.
- Parameters:
-
dir the directory flare to be grown
- Returns:
- 0 on success, -1 otherwise.
- Todo:
- Why errno is not set accordingly to return value?
| int magma_init_flare_on_disk | ( | magma_flare_t * | flare | ) |
create a flare on disk. that is: making directory, creating metadata and contents files and issuing chmod on everything, using flare->st.st_mode ORed with user read and write permissions.
- Parameters:
-
flare magma_flare_t structure to use as model
- Returns:
- 0 on success, -1 on error (errno is set accordingly)
- Todo:
- check errno in this function, it's not always set.
| int magma_load_flare | ( | magma_flare_t * | flare | ) |
Load a flare from disk.
- Parameters:
-
flare the flare to be loaded
- Returns:
- 1 on success, 0 otherwise (errno is set accordingly)
- Todo:
- Please check if errno is always set accordingly
| magma_flare_t* magma_new_blockdev_flare | ( | const char * | path | ) |
create a new, upcasted block device flare
- Parameters:
-
path the path of the new flare
- Returns:
- a pointer to the new flare
| magma_flare_t* magma_new_chardev_flare | ( | const char * | path | ) |
create a new, upcasted character device flare
- Parameters:
-
path the path of the new flare
- Returns:
- a pointer to the new flare
| magma_flare_t* magma_new_dir_flare | ( | const char * | path | ) |
create a new, upcasted directory flare
- Parameters:
-
path the path of new directory flare
- Returns:
- a pointer to new directory flare
| magma_flare_t* magma_new_fifo_flare | ( | const char * | path | ) |
create a new, upcasted FIFO flare
- Parameters:
-
path the path of the new flare
- Returns:
- a pointer to the new flare
| magma_flare_t* magma_new_file_flare | ( | const char * | path | ) |
create a new, upcasted regular file flare
- Parameters:
-
path the path of the new flare
- Returns:
- a pointer to the new flare
| magma_flare_t* magma_new_flare | ( | const char * | path | ) |
Create new uncasted flares.
- Parameters:
-
path the path of new uncasted flare
- Returns:
- a pointer to new flare
| magma_flare_t* magma_new_symlink_flare | ( | const char * | path | ) |
create a new, upcasted symlink flare
- Parameters:
-
path the path of the new flare
- Returns:
- a pointer to the new flare
| int magma_parse_acl_file | ( | const char * | filename | ) |
parse a file formatted with ACL syntax and fill *shares list
- Parameters:
-
filename path to ACL file
| int magma_pop_dirent | ( | magma_DIR_t * | dirp, | |
| char * | dirent | |||
| ) |
Remove an entry from pointed directory. after removing, directory is msync()ed to disk.
- Parameters:
-
dirp magma_DIR_t structure pointing to an open directory dirent the entry to be removed
- Returns:
- 0.
| int magma_push_dirent | ( | magma_DIR_t * | dirp, | |
| char * | path | |||
| ) |
Add a new entry inside a directory. This function should never be called outside.
- Parameters:
-
dirp magma_DIR_t pointer to track offset and access directory path the new dirent to be added
- Returns:
- 0 on success, -1 otherwise (errno is set accordingly)
| int magma_remove_flare_from_parent | ( | magma_flare_t * | flare | ) |
Removes a flare from parent directory. barely just a wrapper around magma_pop_dirent() which also do remote operation if necessary
- Parameters:
-
flare the flare to be saved
- Returns:
- 0 on success, -1 on failure (errno is set accordingly)
| int magma_remove_from_cache | ( | magma_flare_t * | flare | ) |
remove an entry from the cache. flare removal is done under locking mechanism as follows.
first: the manipulation mutex is locked (that means that just a manipulation per time can be done. this place a concurrency problem that will be solved in future.)
second: the flare parent is locked. cache can't be traversed starting by the flare parent.
that prevents access to that sublevel of the cache to magma_search_under_node() and to magma_add_to_cache()
- Parameters:
-
flare the flare to be removed. should be already placed inside the b-tree cache (that's being connected to a parent)
- Returns:
- 1 on success, 0 on failure
| void magma_save_cache_node | ( | magma_flare_t * | node, | |
| int | remove | |||
| ) |
sync to disk a cache node. if remove is true, node is also deleted from volatile memory
- Parameters:
-
node the node of the cache to sync remove if true, the node is also destroyed
| int magma_save_flare | ( | magma_flare_t * | flare | ) |
save a flare to disk. if flare does not exists, magma_create_flare() is called. then, flare st, path, hash, xlated, parent_path, parent_hash and parent_xlated members are dumped inside metadata.
if flare is a directory, pages are msync()ed to disk.
- Parameters:
-
flare the flare to be saved
- Returns:
- 1 on success, 0 on failure
| magma_flare_t* magma_search | ( | const char * | path | ) |
searches flares from internal cache. if an entry is not available, a null pointer is returned.
if entry is missing, it will *NOT* be created. this function just query cache contents, don't update or add nothing. a more generic function, called magma_search_or_create() exists and should be preferred as main interface to flare subsystem.
- Parameters:
-
path the path to be searched
- Returns:
- a pointer to the flare if found, NULL otherwise
| magma_flare_t* magma_search_by_armour | ( | const char * | armoured | ) |
searches flares from internal cache. if an entry is not available, a null pointer is returned. cache is searched by armoured version of binary hash
if entry is missing, it will *NOT* be created. this function just query cache contents, don't update or add nothing. a more generic function, called magma_search_or_create() exists and should be preferred as main interface to flare subsystem.
- Parameters:
-
armoured the armoured rapresentation of searched flare
- Returns:
- a pointer to the flare if found, NULL otherwise
| magma_flare_t* magma_search_by_hash | ( | const unsigned char * | hash | ) |
searches flares from internal cache. if an entry is not available, a null pointer is returned. cache is searched by binary hash
if entry is missing, it will *NOT* be created. this function just query cache contents, don't update or add nothing. a more generic function, called magma_search_or_create() exists and should be preferred as main interface to flare subsystem.
- Parameters:
-
hash the binary hash of the flare to be searched
- Returns:
- a pointer to the flare if found, NULL otherwise
| magma_flare_t* magma_search_or_create | ( | const char * | path | ) |
searches flares from internal cache. if flare is not found, a new one is created using new_flare() macro.
after a flare has ben got (from cache or from scratch) is checked on disk and, if found, loaded from disk.
in both cases, if flare->is_upcasted is false, flare basically does not exists on disk, or is not loadable.
- Parameters:
-
path the path to be searched
- Returns:
- a pointer to the flare or NULL if something went wrong
| magma_flare_t* magma_search_or_create_by_hash | ( | const char * | hash | ) |
| magma_flare_t* magma_search_under_node | ( | const char * | hash, | |
| magma_flare_t * | startnode | |||
| ) |
provide searching facility from the cache. should never be used. use magma_search() or (better) magma_search_or_create() instead.
Note: magma_search_under_node returns flare in locked state. That should allow operation in not destructive ways. Each function getting a flare from magma_search_under_node should than unlock flare.
- Parameters:
-
hash the hash key to be searched startnode is the node used during this iteration to match
- Returns:
- a pointer to the flare if found, NULL otherwise
| char* magma_simplify_path | ( | const char * | path | ) |
simplify given path by removing /./ and /../ and ////+
- Parameters:
-
path the path to be simplified
- Returns:
- simplified path
| int magma_touch_flare | ( | magma_flare_t * | flare, | |
| int | mode | |||
| ) |
update flare atime, ctime and/or mtime. mode is a ORed combination of TOUCH_ATIME, TOUCH_CTIME and TOUCH_MTIME.
- Parameters:
-
flare the flare to be updated mode a bitmask of fields to be modified
- Returns:
- 0 on success, -1 on failure (errno is set accordingly)
- Todo:
- set errno also if flare == NULL
| int magma_validate_connection | ( | struct in_addr * | s, | |
| const char * | share, | |||
| const char * | path, | |||
| char | optype | |||
| ) |
validate incoming connection using ACLs
- Parameters:
-
s requesting IP address share the share this request belong to path subpath requested (relative to *share) optype operation requested, can be 'r' or 'w'
- Returns:
- true if valid, false otherwise
| void print_flare | ( | magma_flare_t * | flare | ) |
outputs to debugging facility all informations avalable about given flare.
- Parameters:
-
flare the flare to be printed
Variable Documentation
| char* blank_page |
This is a pointer to a pagesize wide memory region filled with 0. Is used mainly by mmap() operations to grow directory size.
| const char dht_path[] |
the path of the distributed hashtable profile directory
| gid_t flare_system_gid |
GID of group magma got from system files scanning
| uid_t flare_system_uid |
UID of user magma got from system files scanning
structure hosting the lava ring
Caching is implemented using a b-tree of magma_flare_t objects. Three methods are provided for b-tree access:
magma_search() will search an entry from the cache and return corresponding magma_flare_t object.
magma_search_or_create() will use magma_search() to find requested flare and will use magma_new_flare() if flare is not in cache. if flare can be loaded from disk, will also be upcasted. if flare is returned not upcasted, probably don't exists on disk (or bad things happened!)
magma_flare_t object is returned by address, not copied! So any operation on its data will modify cache internal copy. That's because magma_flare_t object also contain a mutex and a read/write lock for object access control.
magma_add_to_cache will add a magma_flare_t object to cache performing placement operations recursively.
magma_remove_from_cache will remove a magma_tree_node_t object from the cache, relinking the tree to remain consistent.
magma internal cache, organized like a b-tree. magma_cache is the starting node.
| int pagesize |
instead of calling getpagesize() every time page size is needed, flare system stores this value one here and than refers to pagesize later in code.
| const char run_path[] |
the path on real filesystem of the directory in which running data (pid, status) are saved
linked list head for magma exported shares