Distributed Hash Table File System for Linux








protocol_pkt.h File Reference

#include "magma_setup.h"
#include "debug.h"
#include "net_layer.h"
#include "vulcano.h"

Defines

#define PATH_LENGTH   1024
#define send_context(s, uid, gid)
#define recv_context(s, uid, gid)
#define send_res(s, i)   if (i == -1) send(s, &magma_error, 1, SEND_FLAGS); else send(s, &magma_ok, 1, SEND_FLAGS);
#define recv_res(s, i)   { uint8_t x; recv(s,&x,1,RECV_FLAGS); i = (x == magma_ok) ? 0 : -1; }
#define send_errno(s, errno)   send_uint32_t(s,errno)
#define recv_errno(s, errno)   recv_uint32_t(s,errno)
#define send_blkcnt_t(s, i)   send_uint32_t(s,i)
#define recv_blkcnt_t(s, i)   recv_uint32_t(s,i)
#define send_blksize_t(s, i)   send_uint32_t(s,i)
#define recv_blksize_t(s, i)   recv_uint32_t(s,i)
#define send_dev_t(s, i)   send_uint32_t(s,i)
#define recv_dev_t(s, i)   recv_uint32_t(s,i)
#define send_ino_t(s, i)   send_uint32_t(s,i)
#define recv_ino_t(s, i)   recv_uint32_t(s,i)
#define send_mode_t(s, i)   send_uint32_t(s,i)
#define recv_mode_t(s, i)   recv_uint32_t(s,i)
#define send_nlink_t(s, i)   send_uint32_t(s,i)
#define recv_nlink_t(s, i)   recv_uint32_t(s,i)
#define send_off_t(s, i)   send_uint32_t(s,i)
#define recv_off_t(s, i)   recv_uint32_t(s,i)
#define send_size_t(s, i)   send_uint32_t(s,i)
#define recv_size_t(s, i)   recv_uint32_t(s,i)
#define send_time_t(s, i)   send_uint32_t(s,i)
#define recv_time_t(s, i)   recv_uint32_t(s,i)
#define send_DIR_t(s, dirp)
#define recv_DIR_t(s, dirp)
#define pktqs_getattr(s, uid, gid, path)
#define pktqr_getattr(s, uid, gid, path)
#define pktas_getattr(s, res, statbuf, server_error)
#define pktar_getattr(s, res, statbuf, server_error)
#define pktqs_readlink(s, uid, gid, path, size)
#define pktqr_readlink(s, uid, gid, path, size)
#define pktas_readlink(s, length, lpath, server_error)
#define pktar_readlink(s, length, lpath, server_error)
#define READDIR_STOPPER   0
#define pktqs_readdir(s, uid, gid, path)
#define pktqr_readdir(s, uid, gid, path)
#define pktas_readdir(s, dp, server_errno)
#define pktar_readdir(s, dir_state, server_errno)
#define send_readdir_offset(s, offset)   send_off_t(s,offset);
#define recv_readdir_offset(s, offset)   recv_off_t(s,offset);
#define send_readdir_entry(s, path, offset)
#define recv_readdir_entry(s, path, offset)
#define old_send_readdir_terminate(s)   {char t = '\0'; xsend(s,&(t),sizeof(char));}
#define send_readdir_terminate(s)   {unsigned int t = 0; xsend(s,&(t),sizeof(unsigned int));}
#define send_readdir_buffer_full(s)   {off_t stop = READDIR_STOPPER; xsend(s,&(stop),sizeof(off_t));}
#define pktqs_mknod(s, uid, gid, mode, rdev, path)
#define pktqr_mknod(s, uid, gid, mode, rdev, path)
#define pktas_mknod(s, res, server_errno)
#define pktar_mknod(s, res, server_errno)
#define pktqs_mkdir(s, uid, gid, mode, path)
#define pktqr_mkdir(s, uid, gid, mode, path)
#define pktas_mkdir(s, res, server_errno)
#define pktar_mkdir(s, res, server_errno)
#define pktqs_unlink(s, uid, gid, path)
#define pktqr_unlink(s, uid, gid, path)
#define pktas_unlink(s, res, server_errno)
#define pktar_unlink(s, res, server_errno)
#define pktqs_rmdir(s, uid, gid, path)
#define pktqr_rmdir(s, uid, gid, path)
#define pktas_rmdir(s, res, server_errno)
#define pktar_rmdir(s, res, server_errno)
#define pktqs_symlink(s, uid, gid, from, to)
#define pktqr_symlink(s, uid, gid, from, to)
#define pktas_symlink(s, res, server_errno)
#define pktar_symlink(s, res, server_errno)
#define pktqs_rename(s, uid, gid, from, to)
#define pktqr_rename(s, uid, gid, from, to)
#define pktas_rename(s, res, server_errno)
#define pktar_rename(s, res, server_errno)
#define pktqs_link(s, uid, gid, from, to)
#define pktqr_link(s, uid, gid, from, to)
#define pktas_link(s, res, server_errno)
#define pktar_link(s, res, server_errno)
#define pktqs_chmod(s, uid, gid, mode, path)
#define pktqr_chmod(s, uid, gid, mode, path)
#define pktas_chmod(s, res, server_errno)
#define pktar_chmod(s, res, server_errno)
#define pktqs_chown(s, uid, gid, new_uid, new_gid, path)
#define pktqr_chown(s, uid, gid, new_uid, new_gid, path)
#define pktas_chown(s, res, server_errno)
#define pktar_chown(s, res, server_errno)
#define pktqs_truncate(s, uid, gid, offset, path)
#define pktqr_truncate(s, uid, gid, offset, path)
#define pktas_truncate(s, res, server_errno)
#define pktar_truncate(s, res, server_errno)
#define pktqs_utime(s, uid, gid, atime, mtime, path)
#define pktqr_utime(s, uid, gid, atime, mtime, path)
#define pktas_utime(s, res, server_errno)
#define pktar_utime(s, res, server_errno)
#define pktqs_open(s, uid, gid, flags, path)
#define pktqr_open(s, uid, gid, flags, path)
#define pktas_open(s, res, server_errno)
#define pktar_open(s, res, server_errno)
#define pktqs_read(s, uid, gid, size, offset, path)
#define pktqr_read(s, uid, gid, size, offset, path)
#define pktas_read(s, res, buffer, server_errno)
#define pktar_read(s, res, buffer, server_errno)
#define pktqs_write(s, uid, gid, size, offset, path, data)
#define pktqr_write(s, uid, gid, size, offset, path, data)
#define pktas_write(s, res, server_errno)
#define pktar_write(s, res, server_errno)
#define pktqs_statfs(s, uid, gid, path)
#define pktqr_statfs(s, uid, gid, path)
#define pktas_statfs(s, res, stbuf, server_errno)
#define pktar_statfs(s, res, stbuf, server_errno)
#define pktqs_add_flare_to_parent(s, path)
#define pktqr_add_flare_to_parent(s, path)   cnetstrcpy(s, &(path))
#define pktas_add_flare_to_parent(s, res, server_errno)
#define pktar_add_flare_to_parent(s, res, server_errno)
#define pktqs_remove_flare_from_parent(s, path)
#define pktqr_remove_flare_from_parent(s, path)   cnetstrcpy(s, &(path))
#define pktas_remove_flare_from_parent(s, res, server_errno)
#define pktar_remove_flare_from_parent(s, res, server_errno)
#define pktqs_f_opendir(s, uid, gid, path)
#define pktqr_f_opendir(s, uid, gid, path)
#define pktas_f_opendir(s, res, server_errno)
#define pktar_f_opendir(s, res, server_errno)
#define pktqs_f_readdir(s, dirp)
#define pktqr_f_readdir(s, dirp)
#define pktas_f_readdir(s, res, offset, dentry, server_errno)
#define pktar_f_readdir(s, res, offset, dentry, server_errno)
#define pktqs_f_closedir(s, dirp)
#define pktqr_f_closedir(s, dirp)
#define pktas_f_closedir(s, res, server_errno)
#define pktar_f_closedir(s, res, server_errno)
#define pkt_send_heartbeat(s)
#define pkt_recv_heartbeat(s, hb_buffer)
#define pktqs_join_network(s, node)
#define pktqr_join_network(s, new_node)
#define pktas_join_network(s, res, node)
#define pktar_join_network(s, res, node)
#define pktqs_transmit_node(s, start_key, direction)
#define pktqr_transmit_node(s, start_key, direction)
#define pktas_transmit_node(s, node)
#define pktar_transmit_node(s, node)
#define pktqs_get_key(s, key)
#define pktqr_get_key(s, key)   xread(s,&(key), SHA_DIGEST_LENGTH * 2 + 1)
#define pktas_get_key(s, path)   cnetstrsend(s, path)
#define pktar_get_key(s, path)   cnetstrcpy(s, &(path))
#define pktqs_drop_key(s, key)
#define pktqr_drop_key(s, key)   xread(s, &(key), SHA_DIGEST_LENGTH * 2 + 1)
#define pktas_drop_key(s, result)   send_res(s, result)
#define pktar_drop_key(s, result)   recv_res(s, result)
#define pktqs_get_key_content(s, key)
#define pktqr_get_key_content(s, key)   xread(s, &(key), SHA_DIGEST_LENGTH)
#define pktas_get_key_content(s, size, buffer)
#define pktar_get_key_content(s, size, buffer)
#define pktqs_put_key(node)
#define pktqr_put_key()
#define pktas_put_key(node, data, size)
#define pktar_put_key(node, data, size)

Functions

char * explain_network_error (uint8_t error)

Variables

const uint8_t magma_ok
const uint8_t magma_error
const int8_t DIR_IS_CLOSE
const int8_t DIR_IS_OPEN
const uint8_t MAGMA_OK
const uint8_t MAGMA_NODE_NAME_COLLISION
const uint8_t MAGMA_FQDN_NAME_COLLISION
const uint8_t MAGMA_IP_PORT_COLLISION
const uint8_t MAGMA_CONNECTION_REFUSED
const int16_t NO_MORE_NODES_TO_BE_SENT
const int16_t MORE_NODES_TO_BE_SENT
const int16_t PREVIOUS_NODE
const int16_t NEXT_NODE

Define Documentation

#define old_send_readdir_terminate (  )     {char t = '\0'; xsend(s,&(t),sizeof(char));}

#define PATH_LENGTH   1024

EXPLANATION OF MACRO NAMES:

each macro defining a piece of protocol about exchanging data between nodes and clients, is named ptk<something>. Following two letters are:

qs: query to be sent qr: query to be received as: answer to be sent ar: answer to be received

a typical flow will be:

client: pktqs_<operation>(params...) server: pktqr_<operation>(params...) pktas_<operation>(params...) client: pktar_<operation>(params...)

there is one exception: READDIR! readdir is performed in N steps.

client: pktqs_readdir(args) server: pktqr_readdir(args) pktas_readdir(args) client: pktar_readdir(args)

then following cycle is repeated N times (where N is the number of entries in read directory):

client: send_readdir_offset(s,offset); server: recv_readdir_offset(s,offset); send_readdir_entry(s,path,offset); client: recv_readdir_entry(s,path,offset);

when server reaches end of directory will signal client using:

server: send_readdir_terminate(s);

instead of using send_readdir_entry(). client has no special couterpart because is listening on recv_readdir_entry() and should simply check if strlen(path) == 0

when client can't accept more input will signal server with

client: send_readdir_buffer_full(s);

and server should simply check if offset is -1.

#define pkt_recv_heartbeat ( s,
hb_buffer   ) 

Value:

{\
        recv(s, &(hb_buffer), sizeof(optype_t), MSG_PEEK);\
        if (hb_buffer == MAGMA_OP_TYPE_HEARTBEAT) {\
                recv(s, &(hb_buffer), sizeof(optype_t));\
                xsend(s, &(MAGMA_OP_TYPE_HEARTBEAT), sizeof(optype_t));\
        }\
}

#define pkt_send_heartbeat (  ) 

Value:

{\
        if ((xsend(s, &(MAGMA_OP_TYPE_HEARTBEAT), sizeof(optype_t)) == -1)) {\
                if ((errno != EAGAIN) && (errno != ECONNREFUSED)) {\
                        dbg(LOG_INFO, DEBUG_PFUSE, "Should (re)open connection to server...");\
                        shutdown(s, SHUT_WR);\
                        s = 0;\
                } else {\
                        int res = 0, c = 0, d = 0;\
                        for ( c = 0; c < 16; c++ ) {\
                                res = recv(s, &(d), sizeof(int), MSG_DONTWAIT);\
                                if ( res > 0 ) {\
                                        dbg(LOG_INFO, DEBUG_PFUSE, "Got hearbeat answer from server");\
                                        break;\
                                } else if ( res == -1 && errno == EAGAIN ) {\
                                        usleep(50000);\
                                }\
                        }\
                }\
        }\
}

#define pktar_add_flare_to_parent ( s,
res,
server_errno   ) 

Value:

{\
        recv_res(s,res);\
        if (res == -1) recv_errno(s,server_errno);\
}

#define pktar_chmod ( s,
res,
server_errno   ) 

Value:

{\
        recv_res(s,res);\
        if (res == -1) recv_errno(s,server_errno);\
}

#define pktar_chown ( s,
res,
server_errno   ) 

Value:

{\
        recv_res(s,res);\
        if (res == -1) recv_errno(s,server_errno);\
}

#define pktar_drop_key ( s,
result   )     recv_res(s, result)

#define pktar_f_closedir ( s,
res,
server_errno   ) 

Value:

{\
        server_errno = 0;\
        recv_res(s, res);\
        if (res == -1) {\
                recv_errno(s,server_errno);\
        }\
}

#define pktar_f_opendir ( s,
res,
server_errno   ) 

Value:

{\
        recv_res(s,res);\
        if (res == -1) recv_errno(s,server_errno);\
}

#define pktar_f_readdir ( s,
res,
offset,
dentry,
server_errno   ) 

Value:

{\
        recv_res(s, res);\
        if (res == -1) {\
                recv_errno(s,server_errno);\
        } else {\
                recv_off_t(s, offset);\
                cnetstrcpy(s, &(dentry));\
        }\
}

#define pktar_get_key ( s,
path   )     cnetstrcpy(s, &(path))

#define pktar_get_key_content ( s,
size,
buffer   ) 

Value:

{\
        recv_size_t(s, size);\
        buffer = malloc(size);\
        if (size) xread(s, buffer, size);\
}

#define pktar_getattr ( s,
res,
statbuf,
server_error   ) 

Value:

{\
        server_errno = 0;\
        recv_res(s,res);\
        if (res == -1)\
                recv_errno(s,server_error)\
        else {\
                recv_dev_t(s,(statbuf->st_dev));\
                recv_ino_t(s,(statbuf->st_ino));\
                recv_mode_t(s,(statbuf->st_mode));\
                recv_nlink_t(s,(statbuf->st_nlink));\
                recv_context(s, statbuf->st_uid, statbuf->st_gid);\
                recv_dev_t(s,(statbuf->st_dev));\
                recv_off_t(s,(statbuf->st_size));\
                recv_blksize_t(s,(statbuf->st_blksize));\
                recv_blkcnt_t(s,(statbuf->st_blocks));\
                recv_time_t(s,(statbuf->st_atime));\
                recv_time_t(s,(statbuf->st_mtime));\
                recv_time_t(s,(statbuf->st_ctime));\
        }\
}

#define pktar_join_network ( s,
res,
node   ) 

Value:

{\
        xread(s,&res,sizeof(uint8_t));\
        if (res == 0) {\
                xread(s, (node)->start_key, SHA_DIGEST_LENGTH * 2 + 1);\
                xread(s, (node)->stop_key, SHA_DIGEST_LENGTH * 2 + 1);\
        }\
}

#define pktar_link ( s,
res,
server_errno   ) 

Value:

{\
        recv_res(s,res);\
        if (res == -1) recv_errno(s,server_errno);\
}

#define pktar_mkdir ( s,
res,
server_errno   ) 

Value:

{\
        recv_res(s,res);\
        if (res == -1) recv_errno(s,server_errno);\
}

#define pktar_mknod ( s,
res,
server_errno   ) 

Value:

{\
        recv_res(s,res);\
        if (res == -1) recv_errno(s,server_errno);\
}

#define pktar_open ( s,
res,
server_errno   ) 

Value:

{\
        recv_res(s,res);\
        if (res == -1) recv_errno(s,server_errno);\
}

#define pktar_put_key ( node,
data,
size   ) 

Value:

{\
}

#define pktar_read ( s,
res,
buffer,
server_errno   ) 

Value:

{\
        recv_res(s,res);\
        if (res == -1)\
                recv_errno(s,server_errno)\
        else {\
                recv_size_t(s,res);\
                xread(s,buffer,res);\
        }\
}

#define pktar_readdir ( s,
dir_state,
server_errno   ) 

Value:

{\
        recv(s, &(dir_state), sizeof(int8_t),SEND_FLAGS);\
        if (dir_state == DIR_IS_CLOSE)\
                recv_errno(s,server_errno);\
}

#define pktar_readlink ( s,
length,
lpath,
server_error   ) 

Value:

{\
        server_error = 0;\
        recv_res(s, length);\
        if (length != -1) {\
                cnetstrcpy(s,&lpath);\
                length = strlen(lpath);\
        } else {\
                recv_errno(s,server_errno);\
        }\
}

#define pktar_remove_flare_from_parent ( s,
res,
server_errno   ) 

Value:

{\
        recv_res(s,res);\
        if (res == -1) recv_errno(s,server_errno);\
}

#define pktar_rename ( s,
res,
server_errno   ) 

Value:

{\
        recv_res(s,res);\
        if (res == -1) recv_errno(s,server_errno);\
}

#define pktar_rmdir ( s,
res,
server_errno   ) 

Value:

{\
        recv_res(s,res);\
        if (res == -1) recv_errno(s,server_errno);\
}

#define pktar_statfs ( s,
res,
stbuf,
server_errno   ) 

Value:

{\
        recv_res(s,res);\
        if (res == -1) recv_errno(s,server_errno) else xread(s, stbuf,sizeof(struct statfs));\
}

#define pktar_symlink ( s,
res,
server_errno   ) 

Value:

{\
        recv_res(s,res);\
        if (res == -1) recv_errno(s,server_errno);\
}

#define pktar_transmit_node ( s,
node   ) 

Value:

{\
        int16_t more = 0;\
        node = NULL;\
        xread(s, &(more), sizeof(int16_t));\
        if ( more == MORE_NODES_TO_BE_SENT ) {\
                dbg(LOG_INFO, DEBUG_PNODE, "One more node to be received!");\
                node = magma_create_node_empty();\
                if (node != NULL) {\
                        dbg(LOG_INFO, DEBUG_PNODE, "Getting new node...");\
                        netstrcpy(s,node->ip_addr,MAX_IP_LENGTH);\
                        xread(s,&((node->port)),sizeof node->port);\
                        dbg(LOG_INFO, DEBUG_PNODE, "Node is %s:%d", node->ip_addr, node->port);\
                        xnetstrcpy(s,&((node->fqdn_name)),PATH_LENGTH);\
                        dbg(LOG_INFO, DEBUG_PNODE, "FQDN name: %s", node->fqdn_name);\
                        xnetstrcpy(s,&((node->node_name)),PATH_LENGTH);\
                        dbg(LOG_INFO, DEBUG_PNODE, "Node name: %s", node->node_name);\
                        xread(s,&((node->bandwidth)),sizeof node->bandwidth);\
                        dbg(LOG_INFO, DEBUG_PNODE, "Bandwidth: %d", node->bandwidth);\
                        xread(s,&((node->storage)),sizeof node->storage);\
                        dbg(LOG_INFO, DEBUG_PNODE, "Storage: %d", node->storage);\
                        netstrcpy(s,node->start_key,SHA_DIGEST_LENGTH*2+1);\
                        dbg(LOG_INFO, DEBUG_PNODE, "Keys from: %s", node->start_key);\
                        netstrcpy(s,node->stop_key,SHA_DIGEST_LENGTH*2+1);\
                        dbg(LOG_INFO, DEBUG_PNODE, "       to: %s", node->stop_key);\
                        netstrcpy(s,node->resize_start_key,SHA_DIGEST_LENGTH*2+1);\
                        netstrcpy(s,node->resize_stop_key,SHA_DIGEST_LENGTH*2+1);\
                } else dbg(LOG_ERR, DEBUG_ERR, "Can't create node object while receiving transmit_node");\
        } else dbg(LOG_INFO, DEBUG_PNODE, "No more nodes to be received in this direction");\
}

#define pktar_truncate ( s,
res,
server_errno   ) 

Value:

{\
        recv_res(s,res);\
        if (res == -1) recv_errno(s,server_errno);\
}

#define pktar_unlink ( s,
res,
server_errno   ) 

Value:

{\
        recv_res(s,res);\
        if (res == -1) recv_errno(s,server_errno);\
}

#define pktar_utime ( s,
res,
server_errno   ) 

Value:

{\
        recv_res(s,res);\
        if (res == -1) recv_errno(s,server_errno);\
}

#define pktar_write ( s,
res,
server_errno   ) 

Value:

{\
        recv_res(s,res);\
        if (res == -1) recv_errno(s,server_errno) else recv_size_t(s,res);\
}

#define pktas_add_flare_to_parent ( s,
res,
server_errno   ) 

Value:

{\
        int x = server_errno;\
        send_res(s,res);\
        if (res == -1) send_errno(s,x);\
}

#define pktas_chmod ( s,
res,
server_errno   ) 

Value:

{\
        int x = server_errno;\
        send_res(s,res);\
        if (res == -1) send_errno(s,x);\
}

#define pktas_chown ( s,
res,
server_errno   ) 

Value:

{\
        int x = server_errno;\
        send_res(s,res);\
        if (res == -1) send_errno(s,x);\
}

#define pktas_drop_key ( s,
result   )     send_res(s, result)

#define pktas_f_closedir ( s,
res,
server_errno   ) 

Value:

{\
        int x = server_errno;\
        send_res(s, res);\
        if (res == -1) {\
                send_errno(s,x);\
        }\
}

#define pktas_f_opendir ( s,
res,
server_errno   ) 

Value:

{\
        int x = server_errno;\
        send_res(s,res);\
        if (res == -1) send_errno(s,x);\
}

#define pktas_f_readdir ( s,
res,
offset,
dentry,
server_errno   ) 

Value:

{\
        int x = server_errno;\
        send_res(s, res);\
        if (res == -1) {\
                send_errno(s,x);\
        } else {\
                send_off_t(s, offset);\
                cnetstrsend(s, dentry);\
        }\
}

#define pktas_get_key ( s,
path   )     cnetstrsend(s, path)

#define pktas_get_key_content ( s,
size,
buffer   ) 

Value:

{\
        send_size_t(s, size);\
        if (size) xsend(s, buffer, size);\
}

#define pktas_getattr ( s,
res,
statbuf,
server_error   ) 

Value:

{\
        int x = server_error;\
        send_res(s,res);\
        if (res == -1)\
                send_errno(s,x)\
        else {\
                send_dev_t(s,statbuf.st_dev);\
                send_ino_t(s,statbuf.st_ino);\
                send_mode_t(s,statbuf.st_mode);\
                send_nlink_t(s,statbuf.st_nlink);\
                send_context(s, statbuf.st_uid, statbuf.st_gid);\
                send_dev_t(s,statbuf.st_dev);\
                send_off_t(s,statbuf.st_size);\
                send_blksize_t(s,statbuf.st_blksize);\
                send_blkcnt_t(s,statbuf.st_blocks);\
                send_time_t(s,statbuf.st_atime);\
                send_time_t(s,statbuf.st_mtime);\
                send_time_t(s,statbuf.st_ctime);\
        }\
}

#define pktas_join_network ( s,
res,
node   ) 

Value:

{\
        xsend(s,&res,sizeof(uint8_t));\
        if (res == 0) {\
                xsend(s, (node)->start_key, SHA_DIGEST_LENGTH * 2 + 1);\
                xsend(s, (node)->stop_key, SHA_DIGEST_LENGTH * 2 + 1);\
        }\
}

#define pktas_link ( s,
res,
server_errno   ) 

Value:

{\
        int x = server_errno;\
        send_res(s,res);\
        if (res == -1) send_errno(s,x);\
}

#define pktas_mkdir ( s,
res,
server_errno   ) 

Value:

{\
        int x = server_errno;\
        send_res(s,res);\
        if (res == -1) send_errno(s,x);\
}

#define pktas_mknod ( s,
res,
server_errno   ) 

Value:

{\
        int x = server_errno;\
        send_res(s,res);\
        if (res == -1) send_errno(s,x);\
}

#define pktas_open ( s,
res,
server_errno   ) 

Value:

{\
        int x = server_errno;\
        send_res(s,res);\
        if (res == -1) send_errno(s,x);\
}

#define pktas_put_key ( node,
data,
size   ) 

Value:

{\
}

#define pktas_read ( s,
res,
buffer,
server_errno   ) 

Value:

{\
        int x = server_errno;\
        send_res(s,res);\
        if (res == -1)\
                send_errno(s,x)\
        else {\
                send_size_t(s,res);\
                xsend(s, buffer,res);\
        }\
}

#define pktas_readdir ( s,
dp,
server_errno   ) 

Value:

{\
        if (dp == NULL) {\
                int x = server_errno;\
                send(s, &(DIR_IS_CLOSE), sizeof(int8_t),SEND_FLAGS);\
                send_errno(s,x);\
        } else\
                send(s, &(DIR_IS_OPEN), sizeof(int8_t),SEND_FLAGS);\
}

#define pktas_readlink ( s,
length,
lpath,
server_error   ) 

Value:

{\
        int x = server_error;\
        send_res(s,length);\
        if (length == -1) {\
                send_errno(s,x);\
        } else {\
                cnetstrsend(s,lpath);\
        }\
}

#define pktas_remove_flare_from_parent ( s,
res,
server_errno   ) 

Value:

{\
        int x = server_errno;\
        send_res(s,res);\
        if (res == -1) send_errno(s,x);\
}

#define pktas_rename ( s,
res,
server_errno   ) 

Value:

{\
        int x = server_errno;\
        send_res(s,res);\
        if (res == -1) send_errno(s,x);\
}

#define pktas_rmdir ( s,
res,
server_errno   ) 

Value:

{\
        int x = server_errno;\
        send_res(s,res);\
        if (res == -1) send_errno(s,x);\
}

#define pktas_statfs ( s,
res,
stbuf,
server_errno   ) 

Value:

{\
        int x = server_errno;\
        send_res(s,res);\
        if (res == -1) send_errno(s,x) else xsend(s, &(stbuf),sizeof(struct statfs));\
}

#define pktas_symlink ( s,
res,
server_errno   ) 

Value:

{\
        int x = server_errno;\
        send_res(s,res);\
        if (res == -1) send_errno(s,x);\
}

#define pktas_transmit_node ( s,
node   ) 

Value:

{\
        if (node != NULL) {\
                xsend(s,&(MORE_NODES_TO_BE_SENT),sizeof MORE_NODES_TO_BE_SENT);\
                dbg(LOG_INFO, DEBUG_PNODE, "Sending new node %s (%s:%d) @%d@...", node->node_name, node->ip_addr, node->port, strlen(node->ip_addr));\
                xsend(s,node->ip_addr,strlen(node->ip_addr)+1);\
                xsend(s,&((node->port)),sizeof node->port);\
                xsend(s,node->fqdn_name,strlen(node->fqdn_name)+1);\
                dbg(LOG_INFO, DEBUG_PNODE, " FQDN %s @%d@...", node->fqdn_name, strlen(node->fqdn_name));\
                xsend(s,node->node_name,strlen(node->node_name)+1);\
                dbg(LOG_INFO, DEBUG_PNODE, " NAME %s @%d@...", node->node_name, strlen(node->node_name));\
                xsend(s,&((node->bandwidth)),sizeof node->bandwidth);\
                dbg(LOG_INFO, DEBUG_PNODE, " BANDWIDTH %d ...", node->bandwidth);\
                xsend(s,&((node->storage)),sizeof node->storage);\
                dbg(LOG_INFO, DEBUG_PNODE, " STORAGE %d ...", node->storage);\
                xsend(s,node->start_key,SHA_DIGEST_LENGTH*2+1);\
                dbg(LOG_INFO, DEBUG_PNODE, " STARTKEY %s", node->start_key);\
                xsend(s,node->stop_key,SHA_DIGEST_LENGTH*2+1);\
                dbg(LOG_INFO, DEBUG_PNODE, "  STOPKEY %s", node->stop_key);\
                xsend(s,node->resize_start_key,SHA_DIGEST_LENGTH*2+1);\
                xsend(s,node->resize_stop_key,SHA_DIGEST_LENGTH*2+1);\
        } else\
                xsend(s,&(NO_MORE_NODES_TO_BE_SENT),sizeof NO_MORE_NODES_TO_BE_SENT);\
}

#define pktas_truncate ( s,
res,
server_errno   ) 

Value:

{\
        int x = server_errno;\
        send_res(s,res);\
        if (res == -1) send_errno(s,x);\
}

#define pktas_unlink ( s,
res,
server_errno   ) 

Value:

{\
        int x = server_errno;\
        send_res(s,res);\
        if (res == -1) send_errno(s,x);\
}

#define pktas_utime ( s,
res,
server_errno   ) 

Value:

{\
        int x = server_errno;\
        send_res(s,res);\
        if (res == -1) send_errno(s,x);\
}

#define pktas_write ( s,
res,
server_errno   ) 

Value:

{\
        int x = server_errno;\
        send_res(s,res);\
        if (res == -1) send_errno(s,x) else send_size_t(s,res);\
}

#define pktqr_add_flare_to_parent ( s,
path   )     cnetstrcpy(s, &(path))

#define pktqr_chmod ( s,
uid,
gid,
mode,
path   ) 

Value:

{\
        recv_context(s,uid,gid);\
        cnetstrcpy(s,&(path));\
        recv_mode_t(s,mode);\
}

#define pktqr_chown ( s,
uid,
gid,
new_uid,
new_gid,
path   ) 

Value:

{\
        recv_context(s,uid,gid);\
        cnetstrcpy(s,&(path));\
        recv_context(s,new_uid,new_gid);\
}

#define pktqr_drop_key ( s,
key   )     xread(s, &(key), SHA_DIGEST_LENGTH * 2 + 1)

#define pktqr_f_closedir ( s,
dirp   ) 

Value:

{\
        recv_DIR_t(s,dirp);\
}

#define pktqr_f_opendir ( s,
uid,
gid,
path   ) 

Value:

{\
        recv_context(s,uid,gid);\
        cnetstrcpy(s, &(path));\
}

#define pktqr_f_readdir ( s,
dirp   ) 

Value:

{\
        recv_DIR_t(s,dirp);\
}

#define pktqr_get_key ( s,
key   )     xread(s,&(key), SHA_DIGEST_LENGTH * 2 + 1)

#define pktqr_get_key_content ( s,
key   )     xread(s, &(key), SHA_DIGEST_LENGTH)

#define pktqr_getattr ( s,
uid,
gid,
path   ) 

Value:

{\
        recv_context(s,uid,gid);\
        cnetstrcpy(s,&(path));\
}

#define pktqr_join_network ( s,
new_node   ) 

Value:

{\
        char *ip_addr = NULL;\
        cnetstrcpy(s, &ip_addr);\
        strcpy(new_node->ip_addr, ip_addr);\
        recv_uint16_t(s, new_node->port);\
        cnetstrcpy(s, &(new_node->node_name));\
        cnetstrcpy(s, &(new_node->fqdn_name));\
        recv_uint32_t(s, new_node->bandwidth);\
}

#define pktqr_link ( s,
uid,
gid,
from,
to   ) 

Value:

{\
        recv_context(s,uid,gid);\
        cnetstrcpy(s,&(from));\
        cnetstrcpy(s,&(to));\
}

#define pktqr_mkdir ( s,
uid,
gid,
mode,
path   ) 

Value:

{\
        recv_context(s,uid,gid);\
        cnetstrcpy(s,&(path));\
        recv_mode_t(s,mode);\
}

#define pktqr_mknod ( s,
uid,
gid,
mode,
rdev,
path   ) 

Value:

{\
        recv_context(s,uid,gid);\
        cnetstrcpy(s,&(path));\
        recv_mode_t(s,mode);\
        recv_dev_t(s,rdev);\
}

#define pktqr_open ( s,
uid,
gid,
flags,
path   ) 

Value:

{\
        recv_context(s,uid,gid);\
        cnetstrcpy(s,&(path));\
        recv_uint16_t(s,flags);\
}

 
#define pktqr_put_key (  ) 

#define pktqr_read ( s,
uid,
gid,
size,
offset,
path   ) 

Value:

{\
        recv_context(s,uid,gid);\
        cnetstrcpy(s,&(path));\
        recv_size_t(s,size);\
        recv_off_t(s,offset);\
}

#define pktqr_readdir ( s,
uid,
gid,
path   ) 

Value:

{\
        recv_context(s,uid,gid);\
        cnetstrcpy(s,&(path));\
}

#define pktqr_readlink ( s,
uid,
gid,
path,
size   ) 

Value:

{\
        recv_context(s,uid,gid);\
        recv_size_t(s,size);\
        cnetstrcpy(s,&(path));\
}

#define pktqr_remove_flare_from_parent ( s,
path   )     cnetstrcpy(s, &(path))

#define pktqr_rename ( s,
uid,
gid,
from,
to   ) 

Value:

{\
        recv_context(s,uid,gid);\
        cnetstrcpy(s,&(from));\
        cnetstrcpy(s,&(to));\
}

#define pktqr_rmdir ( s,
uid,
gid,
path   ) 

Value:

{\
        recv_context(s,uid,gid);\
        cnetstrcpy(s,&(path));\
}

#define pktqr_statfs ( s,
uid,
gid,
path   ) 

Value:

{\
        recv_context(s,uid,gid);\
        cnetstrcpy(s,&(path));\
}

#define pktqr_symlink ( s,
uid,
gid,
from,
to   ) 

Value:

{\
        recv_context(s,uid,gid);\
        cnetstrcpy(s,&(from));\
        cnetstrcpy(s,&(to));\
}

#define pktqr_transmit_node ( s,
start_key,
direction   ) 

Value:

{\
        xread(s,&(direction),sizeof direction);\
        xnetstrcpy(s,&(start_key),SHA_DIGEST_LENGTH*2+1);\
        dbg(LOG_INFO, DEBUG_PNODE, "Asked for node sibling of %s", start_key);\
}

#define pktqr_truncate ( s,
uid,
gid,
offset,
path   ) 

Value:

{\
        recv_context(s,uid,gid);\
        cnetstrcpy(s,&(path));\
        recv_off_t(s,offset);\
}

#define pktqr_unlink ( s,
uid,
gid,
path   ) 

Value:

{\
        recv_context(s,uid,gid);\
        cnetstrcpy(s,&(path));\
}

#define pktqr_utime ( s,
uid,
gid,
atime,
mtime,
path   ) 

Value:

{\
        recv_context(s,uid,gid);\
        cnetstrcpy(s,&(path));\
        recv_time_t(s,atime);\
        recv_time_t(s,mtime);\
}

#define pktqr_write ( s,
uid,
gid,
size,
offset,
path,
data   ) 

Value:

{\
        recv_context(s,uid,gid);\
        cnetstrcpy(s,&(path));\
        recv_size_t(s,size);\
        recv_off_t(s,offset);\
        data = NULL;\
        int i = 0;\
        for (; i < 10; i++) {\
                data = malloc(size);\
                if (data != NULL) break;\
        }\
        xread(s, data, size);\
}

#define pktqs_add_flare_to_parent ( s,
path   ) 

Value:

#define pktqs_chmod ( s,
uid,
gid,
mode,
path   ) 

Value:

{\
        xsend(s, &(MAGMA_OP_TYPE_CHMOD), sizeof(optype_t));\
        send_context(s,uid,gid);\
        cnetstrsend(s,path);\
        send_mode_t(s,mode);\
}

#define pktqs_chown ( s,
uid,
gid,
new_uid,
new_gid,
path   ) 

Value:

{\
        xsend(s, &(MAGMA_OP_TYPE_CHOWN), sizeof(optype_t));\
        send_context(s,uid,gid);\
        cnetstrsend(s,path);\
        send_context(s,new_uid,new_gid);\
}

#define pktqs_drop_key ( s,
key   ) 

Value:

{\
        xsend(s, &(MAGMA_OP_TYPE_DROP_KEY), sizeof(optype_t));\
        xsend(s, key, SHA_DIGEST_LENGTH * 2 + 1);\
}

#define pktqs_f_closedir ( s,
dirp   ) 

Value:

{\
        xsend(s, &(MAGMA_OP_TYPE_F_CLOSEDIR), sizeof(optype_t));\
        send_DIR_t(s,dirp);\
}

#define pktqs_f_opendir ( s,
uid,
gid,
path   ) 

Value:

{\
        xsend(s, &(MAGMA_OP_TYPE_F_OPENDIR), sizeof(optype_t));\
        send_context(s,uid,gid);\
        cnetstrsend(s,path);\
}

#define pktqs_f_readdir ( s,
dirp   ) 

Value:

{\
        xsend(s, &(MAGMA_OP_TYPE_F_READDIR), sizeof(optype_t));\
        send_DIR_t(s,dirp);\
}

#define pktqs_get_key ( s,
key   ) 

Value:

{\
        xsend(s, &(MAGMA_OP_TYPE_GET_KEY), sizeof(optype_t));\
        xsend(s, key, SHA_DIGEST_LENGTH * 2 + 1);\
}

#define pktqs_get_key_content ( s,
key   ) 

Value:

#define pktqs_getattr ( s,
uid,
gid,
path   ) 

Value:

{\
        xsend(s, &(MAGMA_OP_TYPE_GETATTR),sizeof(optype_t));\
        send_context(s,uid,gid);\
        cnetstrsend(s,path);\
}

#define pktqs_join_network ( s,
node   ) 

Value:

{\
        xsend(s, &(MAGMA_OP_TYPE_JOIN),sizeof(optype_t));\
        cnetstrsend(s, (node)->ip_addr);\
        send_uint16_t(s, (node)->port);\
        cnetstrsend(s, (node)->node_name);\
        cnetstrsend(s, (node)->fqdn_name);\
        send_uint32_t(s, (node)->bandwidth);\
}

#define pktqs_link ( s,
uid,
gid,
from,
to   ) 

Value:

{\
        xsend(s, &(MAGMA_OP_TYPE_LINK), sizeof(optype_t));\
        send_context(s,uid,gid);\
        cnetstrsend(s,from);\
        cnetstrsend(s,to);\
}

#define pktqs_mkdir ( s,
uid,
gid,
mode,
path   ) 

Value:

{\
        xsend(s, &(MAGMA_OP_TYPE_MKDIR), sizeof(optype_t));\
        send_context(s,uid,gid);\
        cnetstrsend(s,path);\
        send_mode_t(s,mode);\
}

#define pktqs_mknod ( s,
uid,
gid,
mode,
rdev,
path   ) 

Value:

{\
        xsend(s, &(MAGMA_OP_TYPE_MKNOD), sizeof(optype_t));\
        send_context(s,uid,gid);\
        cnetstrsend(s,path);\
        send_mode_t(s,mode);\
        send_dev_t(s,rdev);\
}

#define pktqs_open ( s,
uid,
gid,
flags,
path   ) 

Value:

{\
        xsend(s, &(MAGMA_OP_TYPE_OPEN), sizeof(optype_t));\
        send_context(s,uid,gid);\
        cnetstrsend(s,path);\
        send_uint16_t(s,flags);\
}

#define pktqs_put_key ( node   ) 

Value:

{\
        xsend(node->socket, &(MAGMA_OP_TYPE_PUT_KEY), sizeof(optype_t));\
}

#define pktqs_read ( s,
uid,
gid,
size,
offset,
path   ) 

Value:

{\
        xsend(s, &(MAGMA_OP_TYPE_READ), sizeof(optype_t));\
        send_context(s,uid,gid);\
        cnetstrsend(s,path);\
        send_size_t(s,size);\
        send_off_t(s,offset);\
}

#define pktqs_readdir ( s,
uid,
gid,
path   ) 

Value:

{\
        xsend(s, &(MAGMA_OP_TYPE_READDIR), sizeof(optype_t));\
        send_context(s,uid,gid);\
        cnetstrsend(s,path);\
}

#define pktqs_readlink ( s,
uid,
gid,
path,
size   ) 

Value:

{\
        xsend(s, &(MAGMA_OP_TYPE_READLINK),sizeof(optype_t));\
        send_context(s,uid,gid);\
        send_size_t(s,size);\
        cnetstrsend(s,path);\
}

#define pktqs_remove_flare_from_parent ( s,
path   ) 

Value:

#define pktqs_rename ( s,
uid,
gid,
from,
to   ) 

Value:

{\
        xsend(s, &(MAGMA_OP_TYPE_RENAME), sizeof(optype_t));\
        send_context(s,uid,gid);\
        cnetstrsend(s,from);\
        cnetstrsend(s,to);\
}

#define pktqs_rmdir ( s,
uid,
gid,
path   ) 

Value:

{\
        xsend(s, &(MAGMA_OP_TYPE_RMDIR), sizeof(optype_t));\
        send_context(s,uid,gid);\
        cnetstrsend(s,path);\
}

#define pktqs_statfs ( s,
uid,
gid,
path   ) 

Value:

{\
        xsend(s, &(MAGMA_OP_TYPE_STATFS), sizeof(optype_t));\
        send_context(s,uid,gid);\
        cnetstrsend(s,path);\
}

#define pktqs_symlink ( s,
uid,
gid,
from,
to   ) 

Value:

{\
        xsend(s, &(MAGMA_OP_TYPE_SYMLINK), sizeof(optype_t));\
        send_context(s,uid,gid);\
        cnetstrsend(s,from);\
        cnetstrsend(s,to);\
}

#define pktqs_transmit_node ( s,
start_key,
direction   ) 

Value:

{\
        xsend(s,&(MAGMA_OP_TYPE_TRANSMIT_NODE),sizeof(optype_t));\
        xsend(s,&(direction),sizeof direction);\
        xsend(s,start_key,SHA_DIGEST_LENGTH*2+1);\
        dbg(LOG_INFO, DEBUG_PNODE, "Asking for node sibling of %s", start_key);\
}

#define pktqs_truncate ( s,
uid,
gid,
offset,
path   ) 

Value:

{\
        xsend(s, &(MAGMA_OP_TYPE_TRUNCATE), sizeof(optype_t));\
        send_context(s,uid,gid);\
        cnetstrsend(s,path);\
        send_off_t(s,offset);\
}

#define pktqs_unlink ( s,
uid,
gid,
path   ) 

Value:

{\
        xsend(s, &(MAGMA_OP_TYPE_UNLINK), sizeof(optype_t));\
        send_context(s,uid,gid);\
        cnetstrsend(s,path);\
}

#define pktqs_utime ( s,
uid,
gid,
atime,
mtime,
path   ) 

Value:

{\
        xsend(s, &(MAGMA_OP_TYPE_UTIME), sizeof(optype_t));\
        send_context(s,uid,gid);\
        cnetstrsend(s,path);\
        send_time_t(s,atime);\
        send_time_t(s,mtime);\
}

#define pktqs_write ( s,
uid,
gid,
size,
offset,
path,
data   ) 

Value:

{\
        xsend(s, &(MAGMA_OP_TYPE_WRITE), sizeof(optype_t));\
        send_context(s,uid,gid);\
        cnetstrsend(s,path);\
        send_size_t(s,size);\
        send_off_t(s,offset);\
        xsend(s, data, size);\
}

#define READDIR_STOPPER   0

#define recv_blkcnt_t ( s,
 )     recv_uint32_t(s,i)

#define recv_blksize_t ( s,
 )     recv_uint32_t(s,i)

#define recv_context ( s,
uid,
gid   ) 

Value:

{\
        recv_uint32_t(s, uid);\
        recv_uint32_t(s, gid);\
}

#define recv_dev_t ( s,
 )     recv_uint32_t(s,i)

#define recv_DIR_t ( s,
dirp   ) 

Value:

{\
        recv_uint32_t(s,dirp->read);\
        recv_off_t(s,dirp->offset);\
        recv_uint8_t(s,dirp->modified);\
        recv_context(s,dirp->uid,dirp->gid);\
        recv(s,dirp->binhash,SHA_DIGEST_LENGTH,RECV_FLAGS);\
}

#define recv_errno ( s,
errno   )     recv_uint32_t(s,errno)

#define recv_ino_t ( s,
 )     recv_uint32_t(s,i)

#define recv_mode_t ( s,
 )     recv_uint32_t(s,i)

#define recv_nlink_t ( s,
 )     recv_uint32_t(s,i)

#define recv_off_t ( s,
 )     recv_uint32_t(s,i)

#define recv_readdir_entry ( s,
path,
offset   ) 

Value:

{\
        cnetstrcpy(s,&(path));\
        if (*path != '\0') recv_off_t(s,offset);\
}

#define recv_readdir_offset ( s,
offset   )     recv_off_t(s,offset);

#define recv_res ( s,
 )     { uint8_t x; recv(s,&x,1,RECV_FLAGS); i = (x == magma_ok) ? 0 : -1; }

#define recv_size_t ( s,
 )     recv_uint32_t(s,i)

#define recv_time_t ( s,
 )     recv_uint32_t(s,i)

#define send_blkcnt_t ( s,
 )     send_uint32_t(s,i)

#define send_blksize_t ( s,
 )     send_uint32_t(s,i)

#define send_context ( s,
uid,
gid   ) 

Value:

{\
        send_uint32_t(s, uid);\
        send_uint32_t(s, gid);\
}

#define send_dev_t ( s,
 )     send_uint32_t(s,i)

#define send_DIR_t ( s,
dirp   ) 

Value:

{\
        send_uint32_t(s,dirp->read);\
        send_off_t(s,dirp->offset);\
        send_uint8_t(s,dirp->modified);\
        send_context(s,dirp->uid,dirp->gid);\
        send(s,dirp->binhash,SHA_DIGEST_LENGTH,SEND_FLAGS);\
}

#define send_errno ( s,
errno   )     send_uint32_t(s,errno)

#define send_ino_t ( s,
 )     send_uint32_t(s,i)

#define send_mode_t ( s,
 )     send_uint32_t(s,i)

#define send_nlink_t ( s,
 )     send_uint32_t(s,i)

#define send_off_t ( s,
 )     send_uint32_t(s,i)

#define send_readdir_buffer_full (  )     {off_t stop = READDIR_STOPPER; xsend(s,&(stop),sizeof(off_t));}

#define send_readdir_entry ( s,
path,
offset   ) 

Value:

{\
        cnetstrsend(s,path);\
        send_off_t(s,offset);\
}

#define send_readdir_offset ( s,
offset   )     send_off_t(s,offset);

#define send_readdir_terminate (  )     {unsigned int t = 0; xsend(s,&(t),sizeof(unsigned int));}

#define send_res ( s,
 )     if (i == -1) send(s, &magma_error, 1, SEND_FLAGS); else send(s, &magma_ok, 1, SEND_FLAGS);

#define send_size_t ( s,
 )     send_uint32_t(s,i)

#define send_time_t ( s,
 )     send_uint32_t(s,i)


Function Documentation

char* explain_network_error ( uint8_t  error  ) 


Variable Documentation

const int8_t DIR_IS_CLOSE

const int8_t DIR_IS_OPEN

const uint8_t MAGMA_CONNECTION_REFUSED

const uint8_t magma_error

const uint8_t MAGMA_IP_PORT_COLLISION

const uint8_t MAGMA_OK

const uint8_t magma_ok

const int16_t MORE_NODES_TO_BE_SENT

const int16_t NEXT_NODE

const int16_t NO_MORE_NODES_TO_BE_SENT

const int16_t PREVIOUS_NODE

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