Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 28 additions & 9 deletions treeshr/RemoteAccess.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ static int remote_connect(char *server)
int conid = -1;
MDSSHR_LOAD_LIBROUTINE_LOCAL(MdsIpShr, ReuseCheck, return conid, int, (char *, char *, int));
MDSSHR_LOAD_LIBROUTINE_LOCAL(MdsIpShr, ConnectToMds, return conid, int, (char *));
char unique[128] = "";
if (ReuseCheck(server, unique, 128) < 0)
char unique[HOST_UNIQUE_SIZE] = "";
if (ReuseCheck(server, unique, HOST_UNIQUE_SIZE) < 0)
{
conid = ConnectToMds(server);
if (conid == -1)
Expand All @@ -103,7 +103,7 @@ static int remote_connect(char *server)
TREETHREADSTATIC_INIT;
for (host = TREE_HOSTLIST; host; host = host->next)
{
if (!strcmp(host->unique, unique))
if (!strncmp(host->unique, unique, HOST_UNIQUE_SIZE))
{
conid = host->conid;
host->links++;
Expand All @@ -121,7 +121,7 @@ static int remote_connect(char *server)
host = malloc(sizeof(Host));
host->conid = conid;
host->links = 1;
host->unique = strdup(unique);
strncpy(host->unique, unique, HOST_UNIQUE_SIZE);
host->next = TREE_HOSTLIST;
TREE_HOSTLIST = host;
MDSDBG(HOST_PRI ", server='%s': new", HOST_VAR(host), server);
Expand All @@ -141,8 +141,8 @@ static int remote_disconnect(int conid, int force)
if (conid == -1)
return TreeSUCCESS;
TREETHREADSTATIC_INIT;
Host **prev = &TREE_HOSTLIST, *host = TREE_HOSTLIST;
for (; host; prev = &host->next, host = host->next)
Host **phost = &TREE_HOSTLIST, *host = TREE_HOSTLIST;
for (; host; phost = &host->next, host = host->next)
{
if (host->conid == conid)
{
Expand All @@ -155,21 +155,40 @@ static int remote_disconnect(int conid, int force)
{
if (force)
{
*phost = host->next;
MDSWRN(HOST_PRI " disconnected", HOST_VAR(host));
destroy_host(host);
}
else
{
MDSDBG(HOST_PRI " disconnected", HOST_VAR(host));
MDSDBG(HOST_PRI " idle", HOST_VAR(host));
}
*prev = host->next;
destroy_host(host);
}
break;
}
}
return TreeSUCCESS;
}

void TreeCleanupConnections()
{
TREETHREADSTATIC_INIT;
Host **phost = &TREE_HOSTLIST, *host = TREE_HOSTLIST;
for (; host; host = *phost)
{
if (host->links <= 0)
{
*phost = host->next;
MDSDBG(HOST_PRI " cleaned up", HOST_VAR(host));
destroy_host(host);
}
else
{
phost = &host->next;
}
}
}

///////////////////////////////////////////////////////////////////
///////OLD THICK CLIENT////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
Expand Down
5 changes: 4 additions & 1 deletion treeshr/TreeOpen.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ static int GetVmForTree(TREE_INFO *info, int nomap);
static int MapTree(TREE_INFO *info, TREE_INFO *root, int edit_flag);
static void SubtreeNodeConnect(PINO_DATABASE *dblist, NODE *parent,
NODE *subtreetop);

extern void TreeCleanupConnections();
extern void **TreeCtx();

int TreeClose(char const *tree, int shot)
Expand Down Expand Up @@ -325,6 +325,7 @@ int _TreeClose(void **dbid, char const *tree, int shot)
status = TreeNOT_OPEN;
}
}
TreeCleanupConnections();
return status;
}

Expand Down Expand Up @@ -1351,6 +1352,7 @@ int _TreeOpenEdit(void **dbid, char const *tree_in, int shot_in)
free_top_db(dblist);
}
}
TreeCleanupConnections();
return status;
}

Expand Down Expand Up @@ -1465,6 +1467,7 @@ int _TreeOpenNew(void **dbid, char const *tree_in, int shot_in)
_TreeWriteTree(dbid, 0, 0);
MDS_IO_CLOSE(fd_keepalive);
}
TreeCleanupConnections();
return status;
}

Expand Down
1 change: 0 additions & 1 deletion treeshr/TreeThreadStatic.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ void destroy_host(Host *host)
MDSSHR_LOAD_LIBROUTINE_LOCAL(MdsIpShr, DisconnectFromMds, abort(), void, (int));
MDSDBG(HOST_PRI, HOST_VAR(host));
DisconnectFromMds(host->conid);
free(host->unique);
free(host);
}

Expand Down
3 changes: 2 additions & 1 deletion treeshr/treethreadstatic.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
#include "../mdsshr/mdsthreadstatic.h"
#include "treeshrp.h"

#define HOST_UNIQUE_SIZE 64
typedef struct host
{
struct host *next;
int conid;
int links;
char *unique;
char unique[HOST_UNIQUE_SIZE];
} Host;
#define HOST_PRI "Host(conid=%d, links=%d, unique='%s')"
#define HOST_VAR(h) (h)->conid, (h)->links, (h)->unique
Expand Down