Skip to content

Commit

Permalink
DHT (distributed hash table) initial commit
Browse files Browse the repository at this point in the history
Patches applied:

 * avati@zresearch.com/glusterfs--dht--1.0--base-0
   tag of gluster@sv.gnu.org/glusterfs--mainline--3.0--patch-349

 * avati@zresearch.com/glusterfs--dht--1.0--patch-1
   intermediate commit
  • Loading branch information
avati authored and amarts committed May 5, 2017
1 parent 8dcde0c commit 5dc7cbf
Show file tree
Hide file tree
Showing 32 changed files with 5,023 additions and 837 deletions.
2 changes: 2 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ AC_CONFIG_FILES([Makefile
xlators/cluster/afr/src/Makefile
xlators/cluster/stripe/Makefile
xlators/cluster/stripe/src/Makefile
xlators/cluster/dht/Makefile
xlators/cluster/dht/src/Makefile
xlators/performance/Makefile
xlators/performance/write-behind/Makefile
xlators/performance/write-behind/src/Makefile
Expand Down
38 changes: 6 additions & 32 deletions libglusterfs/src/call-stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,6 @@

#include "call-stub.h"

static void
loc_wipe (loc_t *loc)
{
GF_VALIDATE_OR_GOTO ("call-stub", loc, out);

FREE (loc->path);
if (loc->inode)
inode_unref (loc->inode);
out:
return;
}


static void
loc_copy (loc_t *dest, loc_t *src)
{
GF_VALIDATE_OR_GOTO ("call-stub", dest, out);
GF_VALIDATE_OR_GOTO ("call-stub", src, out);

dest->path = strdup (src->path);
dest->ino = src->ino;
if (src->inode)
dest->inode = inode_ref (src->inode);
out:
return;
}


static call_stub_t *
stub_new (call_frame_t *frame,
Expand Down Expand Up @@ -919,20 +892,21 @@ call_stub_t *
fop_link_stub (call_frame_t *frame,
fop_link_t fn,
loc_t *oldloc,
const char *newpath)
loc_t *newloc)
{
call_stub_t *stub = NULL;

GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
GF_VALIDATE_OR_GOTO ("call-stub", oldloc, out);
GF_VALIDATE_OR_GOTO ("call-stub", newpath, out);
GF_VALIDATE_OR_GOTO ("call-stub", newloc, out);

stub = stub_new (frame, 1, GF_FOP_LINK);
GF_VALIDATE_OR_GOTO ("call-stub", stub, out);

stub->args.link.fn = fn;
loc_copy (&stub->args.link.oldloc, oldloc);
stub->args.link.newpath = strdup (newpath);
loc_copy (&stub->args.link.newloc, newloc);

out:
return stub;
}
Expand Down Expand Up @@ -2023,9 +1997,9 @@ call_resume_wind (call_stub_t *stub)
stub->args.link.fn (stub->frame,
stub->frame->this,
&stub->args.link.oldloc,
stub->args.link.newpath);
&stub->args.link.newloc);
loc_wipe (&stub->args.link.oldloc);
FREE (stub->args.link.newpath);
loc_wipe (&stub->args.link.newloc);
}
break;

Expand Down
4 changes: 2 additions & 2 deletions libglusterfs/src/call-stub.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ typedef struct {
struct {
fop_link_t fn;
loc_t oldloc;
const char *newpath;
loc_t newloc;
} link;
struct {
fop_link_cbk_t fn;
Expand Down Expand Up @@ -749,7 +749,7 @@ call_stub_t *
fop_link_stub (call_frame_t *frame,
fop_link_t fn,
loc_t *oldloc,
const char *newpath);
loc_t *newloc);

call_stub_t *
fop_link_cbk_stub (call_frame_t *frame,
Expand Down
6 changes: 3 additions & 3 deletions libglusterfs/src/defaults.c
Original file line number Diff line number Diff line change
Expand Up @@ -637,14 +637,14 @@ default_link_cbk (call_frame_t *frame,
int32_t
default_link (call_frame_t *frame,
xlator_t *this,
loc_t *loc,
const char *newname)
loc_t *oldloc,
loc_t *newloc)
{
STACK_WIND (frame,
default_link_cbk,
FIRST_CHILD(this),
FIRST_CHILD(this)->fops->link,
loc, newname);
oldloc, newloc);
return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions libglusterfs/src/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ int32_t default_rename (call_frame_t *frame,

int32_t default_link (call_frame_t *frame,
xlator_t *this,
loc_t *loc,
const char *newpath);
loc_t *oldloc,
loc_t *newloc);

int32_t default_create (call_frame_t *frame,
xlator_t *this,
Expand Down
24 changes: 22 additions & 2 deletions libglusterfs/src/dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ data_to_int64 (data_t *data)
ERR_ABORT (str);
memcpy (str, data->data, data->len);
str[data->len] = '\0';
return strtoll (str, NULL, 0);
return strtoull (str, NULL, 0);
}

int32_t
Expand All @@ -993,7 +993,7 @@ data_to_int32 (data_t *data)
memcpy (str, data->data, data->len);
str[data->len] = '\0';

return strtol (str, NULL, 0);
return strtoul (str, NULL, 0);
}

int16_t
Expand Down Expand Up @@ -1271,6 +1271,26 @@ dict_get_int32 (dict_t *this, char *key, int32_t *val)
return ret;
}


int
dict_set_int32 (dict_t *this, char *key, int32_t val)
{
data_t * data = NULL;
int ret = 0;

data = data_from_int32 (val);
if (!data) {
ret = -EINVAL;
goto err;
}

ret = dict_set (this, key, data);

err:
return ret;
}


int
dict_set_static_ptr (dict_t *this, char *key, void *ptr)
{
Expand Down
1 change: 1 addition & 0 deletions libglusterfs/src/dict.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ dict_t *dict_copy (dict_t *this,

/* CLEANED UP FUNCTIONS DECLARATIONS */
int dict_get_int32 (dict_t *this, char *key, int32_t *val);
int dict_set_int32 (dict_t *this, char *key, int32_t val);

int dict_set_static_ptr (dict_t *this, char *key, void *ptr);
int dict_get_ptr (dict_t *this, char *key, void **ptr);
Expand Down
49 changes: 22 additions & 27 deletions libglusterfs/src/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,13 @@
#include <assert.h>

/* TODO:
complete inode_table_new ->root
add validation
move latest accessed dentry to list_head of inode
*/

static inode_t *
__inode_unref (inode_t *inode);



static int
hash_name (ino_t par,
const char *name,
Expand Down Expand Up @@ -92,7 +90,7 @@ __dentry_hash (dentry_t *dentry)


static int
__dentry_is_hashed (dentry_t *dentry)
__is_dentry_hashed (dentry_t *dentry)
{
return !list_empty (&dentry->hash);
}
Expand Down Expand Up @@ -133,7 +131,7 @@ __inode_unhash (inode_t *inode)


static int
__inode_is_hashed (inode_t *inode)
__is_inode_hashed (inode_t *inode)
{
return !list_empty (&inode->hash);
}
Expand Down Expand Up @@ -273,7 +271,7 @@ static void
__inode_passivate (inode_t *inode)
{
dentry_t *dentry = NULL;
dentry_t *tmp = NULL;
dentry_t *t = NULL;
inode_table_t *table = NULL;

table = inode->table;
Expand All @@ -286,8 +284,8 @@ __inode_passivate (inode_t *inode)
inode->ino, table->lru_size, table->lru_limit,
table->active_size, table->purge_size);

list_for_each_entry_safe (dentry, tmp, &inode->dentry_list, inode_list) {
if (!__dentry_is_hashed (dentry))
list_for_each_entry_safe (dentry, t, &inode->dentry_list, inode_list) {
if (!__is_dentry_hashed (dentry))
__dentry_unset (dentry);
}
}
Expand All @@ -297,7 +295,7 @@ static void
__inode_retire (inode_t *inode)
{
dentry_t *dentry = NULL;
dentry_t *tmp = NULL;
dentry_t *t = NULL;
inode_table_t *table = NULL;

table = inode->table;
Expand All @@ -313,7 +311,7 @@ __inode_retire (inode_t *inode)
__inode_unhash (inode);
assert (list_empty (&inode->child_list));

list_for_each_entry_safe (dentry, tmp, &inode->dentry_list, inode_list) {
list_for_each_entry_safe (dentry, t, &inode->dentry_list, inode_list) {
__dentry_unset (dentry);
}
}
Expand All @@ -332,7 +330,7 @@ __inode_unref (inode_t *inode)
if (!inode->ref) {
inode->table->active_size--;

if (inode->nlookup && __inode_is_hashed (inode))
if (inode->nlookup && __is_inode_hashed (inode))
__inode_passivate (inode);
else
__inode_retire (inode);
Expand All @@ -345,9 +343,6 @@ __inode_unref (inode_t *inode)
static inode_t *
__inode_ref (inode_t *inode)
{
if (inode->ino != 1)
gf_log ("inode", GF_LOG_DEBUG, "");;

if (!inode->ref) {
inode->table->lru_size--;
__inode_activate (inode);
Expand Down Expand Up @@ -468,7 +463,6 @@ inode_new (inode_table_t *table)
static inode_t *
__inode_lookup (inode_t *inode)
{
/* TODO: search inode->ino inode and perform nlookup++ on that */
inode->nlookup++;

return inode;
Expand Down Expand Up @@ -535,7 +529,7 @@ __copy_dentries (inode_t *oldi, inode_t *newi)
newd = tmp;
}

if (__dentry_is_hashed (dentry)) {
if (__is_dentry_hashed (dentry)) {
__dentry_unhash (dentry);
__dentry_hash (newd);
}
Expand Down Expand Up @@ -653,7 +647,7 @@ inode_lookup (inode_t *inode)

pthread_mutex_lock (&table->lock);
{
if (__inode_is_hashed (inode))
if (__is_inode_hashed (inode))
lookup_inode = inode;
else
lookup_inode = __inode_search (table, inode->ino);
Expand All @@ -676,7 +670,7 @@ inode_forget (inode_t *inode, uint64_t nlookup)

pthread_mutex_lock (&table->lock);
{
if (__inode_is_hashed (inode))
if (__is_inode_hashed (inode))
forget_inode = inode;
else
forget_inode = __inode_search (table, inode->ino);
Expand Down Expand Up @@ -753,7 +747,7 @@ __dentry_search_arbit (inode_t *inode)
dentry_t *trav = NULL;

list_for_each_entry (trav, &inode->dentry_list, inode_list) {
if (__dentry_is_hashed (trav)) {
if (__is_dentry_hashed (trav)) {
dentry = trav;
break;
}
Expand Down Expand Up @@ -859,20 +853,21 @@ inode_path (inode_t *inode, const char *name, char *buf, size_t size)
int
inode_table_prune (inode_table_t *table)
{
int ret = 0;
struct list_head purge = {0, };
int ret = 0;
struct list_head purge = {0, };
inode_t *del = NULL;
inode_t *tmp = NULL;
inode_t *entry = NULL;


INIT_LIST_HEAD (&purge);

pthread_mutex_lock (&table->lock);
{
while (table->lru_limit
&& table->lru_size > (table->lru_limit)) {
struct list_head *next;
inode_t *entry;

next = table->lru.next;
entry = list_entry (next, inode_t, list);
entry = list_entry (table->lru.next, inode_t, list);

table->lru_size--;
__inode_retire (entry);
Expand All @@ -881,18 +876,18 @@ inode_table_prune (inode_table_t *table)
}

list_splice_init (&table->purge, &purge);
table->purge_size = 0;
}
pthread_mutex_unlock (&table->lock);

{
inode_t *del = NULL, *tmp = NULL;

list_for_each_entry_safe (del, tmp, &purge, list) {
list_del_init (&del->list);
__inode_forget (del, 0);
__inode_destroy (del);
}
}

return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion libglusterfs/src/revision.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define GLUSTERFS_REPOSITORY_REVISION "glusterfs--mainline--3.0--patch-379"
#define GLUSTERFS_REPOSITORY_REVISION "glusterfs--mainline--3.0--patch-380"
Loading

0 comments on commit 5dc7cbf

Please sign in to comment.