Skip to content

Commit

Permalink
workq: For client request added pointer to ConfigurationParser Handle…
Browse files Browse the repository at this point in the history
…ConnectionRequest

- now each call to HandleConnectionRequest passes the pointer to the respective
  ConfigurationParser object of the daemon
  • Loading branch information
franku committed Sep 4, 2018
1 parent 9fa5107 commit 4fc6889
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 26 deletions.
4 changes: 2 additions & 2 deletions core/src/dird/socket_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct s_addr_port {

ConnectionPool *get_client_connections() { return client_connections; }

static void *HandleConnectionRequest(void *arg)
static void *HandleConnectionRequest(ConfigurationParser *my_config, void *arg)
{
BareosSocket *bs = (BareosSocket *)arg;
char name[MAX_NAME_LENGTH];
Expand Down Expand Up @@ -120,7 +120,7 @@ extern "C" void *connect_thread(void *arg)
*/
sock_fds = New(alist(10, not_owned_by_alist));
BnetThreadServerTcp((dlist *)arg, me->MaxConnections, sock_fds, &socket_workq, me->nokeepalive,
HandleConnectionRequest);
HandleConnectionRequest, my_config);

return NULL;
}
Expand Down
5 changes: 3 additions & 2 deletions core/src/filed/socket_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static alist *sock_fds = NULL;
* - If it was a connection from an SD, call handle_stored_connection()
* - Otherwise it was a connection from the DIR, call handle_director_connection()
*/
static void *HandleConnectionRequest(void *arg)
static void *HandleConnectionRequest(ConfigurationParser *config, void *arg)
{
BareosSocket *bs = (BareosSocket *)arg;
char tbuf[100];
Expand Down Expand Up @@ -112,7 +112,8 @@ void StartSocketServer(dlist *addrs)
sock_fds,
&socket_workq,
me->nokeepalive,
HandleConnectionRequest);
HandleConnectionRequest,
my_config);
}

void StopSocketServer(bool wait)
Expand Down
8 changes: 5 additions & 3 deletions core/src/lib/bnet_server_tcp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ void BnetThreadServerTcp(dlist *addr_list,
alist *sockfds,
workq_t *client_wq,
bool nokeepalive,
void *handle_client_request(void *bsock))
void *HandleConnectionRequest(ConfigurationParser *config,
void *bsock),
ConfigurationParser *config)
{
int newsockfd, status;
socklen_t clilen;
Expand Down Expand Up @@ -242,7 +244,7 @@ void BnetThreadServerTcp(dlist *addr_list,
/*
* Start work queue thread
*/
if ((status = WorkqInit(client_wq, max_clients, handle_client_request)) != 0) {
if ((status = WorkqInit(client_wq, max_clients, HandleConnectionRequest)) != 0) {
BErrNo be;
be.SetErrno(status);
Emsg1(M_ABORT, 0, _("Could not init client queue: ERR=%s\n"), be.bstrerror());
Expand Down Expand Up @@ -376,7 +378,7 @@ void BnetThreadServerTcp(dlist *addr_list,
/*
* Queue client to be served
*/
if ((status = WorkqAdd(client_wq, (void *)bs, NULL)) != 0) {
if ((status = WorkqAdd(client_wq, config, (void *)bs, NULL)) != 0) {
BErrNo be;
be.SetErrno(status);
Jmsg1(NULL, M_ABORT, 0, _("Could not add job to client queue: ERR=%s\n"),
Expand Down
6 changes: 5 additions & 1 deletion core/src/lib/bnet_sever_tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@
#ifndef BAREOS_LIB_BNET_SEVER_TCP_H_
#define BAREOS_LIB_BNET_SEVER_TCP_H_

class ConfigurationParser;

DLL_IMP_EXP void CleanupBnetThreadServerTcp(alist *sockfds, workq_t *client_wq);
DLL_IMP_EXP void BnetThreadServerTcp(dlist *addr_list,
int max_clients,
alist *sockfds,
workq_t *client_wq,
bool nokeepalive,
void *handle_client_request(void *bsock));
void *HandleConnectionRequest(ConfigurationParser *config,
void *bsock),
ConfigurationParser *config);
DLL_IMP_EXP void BnetStopThreadServerTcp(pthread_t tid);

#endif // BAREOS_LIB_BNET_SEVER_TCP_H_
2 changes: 1 addition & 1 deletion core/src/lib/unittests/bsock_dir_sd_connection_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static void start_sd_server()
return;
}
std::unique_ptr<BareosSocket> bs(create_new_bareos_socket(newsockfd));
storagedaemon::HandleConnectionRequest(bs.get());
storagedaemon::HandleConnectionRequest(my_config, bs.get());

delete storagedaemon::me;
storagedaemon::me = nullptr;
Expand Down
13 changes: 7 additions & 6 deletions core/src/lib/workq.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ extern "C" void *workq_server(void *arg);
* Returns: 0 on success
* errno on failure
*/
int WorkqInit(workq_t *wq, int max_workers, void *(*engine)(void *arg))
int WorkqInit(workq_t *wq, int max_workers, void *(*HandleConnectionRequest)(ConfigurationParser *config, void *arg))
{
int status;

Expand All @@ -80,9 +80,9 @@ int WorkqInit(workq_t *wq, int max_workers, void *(*engine)(void *arg))
}
wq->quit = 0;
wq->first = wq->last = NULL;
wq->max_workers = max_workers; /* max threads to create */
wq->num_workers = 0; /* no threads yet */
wq->engine = engine; /* routine to run */
wq->max_workers = max_workers; /* max threads to create */
wq->num_workers = 0; /* no threads yet */
wq->HandleConnectionRequest = HandleConnectionRequest; /* routine to run */
wq->valid = WORKQ_VALID;
return 0;
}
Expand Down Expand Up @@ -130,7 +130,7 @@ int WorkqDestroy(workq_t *wq)
* priority if non-zero will cause the item to be placed on the
* head of the list instead of the tail.
*/
int WorkqAdd(workq_t *wq, void *element, workq_ele_t **work_item)
int WorkqAdd(workq_t *wq, ConfigurationParser *config, void *element, workq_ele_t **work_item)
{
int status = 0;
workq_ele_t *item;
Expand All @@ -145,6 +145,7 @@ int WorkqAdd(workq_t *wq, void *element, workq_ele_t **work_item)
return ENOMEM;
}
item->data = element;
item->config = config;
item->next = NULL;
P(wq->mutex);

Expand Down Expand Up @@ -228,7 +229,7 @@ void *workq_server(void *arg)
V(wq->mutex);
/* Call user's routine here */
Dmsg0(1400, "Calling user engine.\n");
wq->engine(we->data); /* HandleConnectionRequest */
wq->HandleConnectionRequest(we->config, we->data);
Dmsg0(1400, "Back from user engine.\n");
free(we); /* release work entry */
Dmsg0(1400, "relock mutex\n");
Expand Down
11 changes: 7 additions & 4 deletions core/src/lib/workq.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@
#ifndef BAREOS_LIB_WORKQ_H_
#define BAREOS_LIB_WORKQ_H_ 1

class ConfigurationParser;

/**
* Structure to keep track of work queue request
*/
typedef struct workq_ele_tag {
struct workq_ele_tag *next;
ConfigurationParser *config;
void *data;
} workq_ele_t;

Expand All @@ -54,17 +57,17 @@ typedef struct workq_tag {
int quit; /* workq should quit */
int max_workers; /* max threads */
int num_workers; /* current threads */
void *(*engine)(void *arg); /* user engine */
void *(*HandleConnectionRequest)(ConfigurationParser *config, void *arg);
} workq_t;

#define WORKQ_VALID 0xdec1992

extern int WorkqInit(
workq_t *wq,
int threads, /* maximum threads */
void *(*engine)(void *) /* engine routine */
int threads, /* maximum threads */
void *(*engine)(ConfigurationParser* config, void *) /* engine routine */
);
extern int WorkqDestroy(workq_t *wq);
extern int WorkqAdd(workq_t *wq, void *element, workq_ele_t **work_item);
extern int WorkqAdd(workq_t *wq, ConfigurationParser *config, void *element, workq_ele_t **work_item);

#endif /* BAREOS_LIB_WORKQ_H_ */
8 changes: 4 additions & 4 deletions core/src/stored/ndmp_tape.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ void EndOfNdmpRestore(JobControlRecord *jcr)
}
}

extern "C" void *handle_ndmp_client_request(void *arg)
extern "C" void *HandleNdmpConnectionRequest(ConfigurationParser *config, void *arg)
{
int status;
struct ndmconn *conn;
Expand All @@ -1167,7 +1167,7 @@ extern "C" void *handle_ndmp_client_request(void *arg)
handle = (struct ndmp_session_handle *)arg;
if (!handle) {
Emsg0(M_ABORT, 0,
_("Illegal call to handle_ndmp_client_request with NULL session handle\n"));
_("Illegal call to HandleNdmpConnectionRequest with NULL session handle\n"));
return NULL;
}

Expand Down Expand Up @@ -1394,7 +1394,7 @@ extern "C" void *ndmp_thread_server(void *arg)
/*
* Start work queue thread
*/
if ((status = WorkqInit(ntsa->client_wq, ntsa->max_clients, handle_ndmp_client_request)) != 0) {
if ((status = WorkqInit(ntsa->client_wq, ntsa->max_clients, HandleNdmpConnectionRequest)) != 0) {
BErrNo be;
be.SetErrno(status);
Emsg1(M_ABORT, 0,
Expand Down Expand Up @@ -1515,7 +1515,7 @@ extern "C" void *ndmp_thread_server(void *arg)
/*
* Queue client to be served
*/
if ((status = WorkqAdd(ntsa->client_wq, (void *)new_handle, NULL)) != 0) {
if ((status = WorkqAdd(ntsa->client_wq, my_config, (void *)new_handle, NULL)) != 0) {
BErrNo be;
be.SetErrno(status);
Jmsg1(NULL, M_ABORT, 0, _("Could not add job to ndmp client queue: ERR=%s\n"),
Expand Down
5 changes: 3 additions & 2 deletions core/src/stored/socket_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static pthread_t tcp_server_tid;
* - If it was a connection from another SD, call handle_stored_connection()
* - Otherwise it was a connection from the DIR, call handle_director_connection()
*/
void *HandleConnectionRequest(void *arg)
void *HandleConnectionRequest(ConfigurationParser *config, void *arg)
{
BareosSocket *bs = (BareosSocket *)arg;
char name[MAX_NAME_LENGTH];
Expand Down Expand Up @@ -126,7 +126,8 @@ void StartSocketServer(dlist *addrs)
sock_fds,
&socket_workq,
me->nokeepalive,
HandleConnectionRequest);
HandleConnectionRequest,
my_config);
}

void StopSocketServer()
Expand Down
3 changes: 2 additions & 1 deletion core/src/stored/socket_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
#define BAREOS_STORED_SOCKET_SERVER_H_

struct dlist;
class ConfigurationParser;

namespace storagedaemon {

void StartSocketServer(dlist *addrs);
void StopSocketServer();
void *HandleConnectionRequest(void *arg);
void *HandleConnectionRequest(ConfigurationParser *config, void *arg);

} /* namespace storagedaemon */

Expand Down

0 comments on commit 4fc6889

Please sign in to comment.