Skip to content

Commit

Permalink
resource: worker-control: add service_link_defs[] param to worker_con…
Browse files Browse the repository at this point in the history
…trol_run_worker and worker_control_run_new_worker

When a new worker is created, we need to be able to provide service link
definition array so that all required service links are established for the
worker too.

The reason is that the "worker resource" is created as a top level
resource in the worker process (so without having a parent) and hence
we can't inherit the service links from the parent anymore.
  • Loading branch information
prajnoha committed Dec 11, 2023
1 parent d7d95a3 commit d8f7bbb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/include/resource/worker-control.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,10 @@ struct worker_params {
};

int worker_control_get_new_worker(sid_resource_t *worker_control_res, struct worker_params *params, sid_resource_t **res_p);
int worker_control_run_new_worker(sid_resource_t *worker_control_res, struct worker_params *params);
int worker_control_run_worker(sid_resource_t *worker_control_res);
int worker_control_run_new_worker(sid_resource_t *worker_control_res,
struct worker_params *params,
sid_resource_service_link_def_t service_link_defs[]);
int worker_control_run_worker(sid_resource_t *worker_control_res, sid_resource_service_link_def_t service_link_defs[]);
sid_resource_t *worker_control_get_idle_worker(sid_resource_t *worker_control_res);
sid_resource_t *worker_control_find_worker(sid_resource_t *worker_control_res, const char *id);

Expand Down
14 changes: 8 additions & 6 deletions src/resource/worker-control.c
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ int worker_control_get_new_worker(sid_resource_t *worker_control_res, struct wor
return _do_worker_control_get_new_worker(worker_control_res, params, res_p, false);
}

static int _run_internal_worker(sid_resource_t *worker_control_res)
static int _run_internal_worker(sid_resource_t *worker_control_res, sid_resource_service_link_def_t service_link_defs[])
{
struct worker_control *worker_control = sid_resource_get_data(worker_control_res);
struct worker_kickstart kickstart;
Expand All @@ -954,7 +954,7 @@ static int _run_internal_worker(sid_resource_t *worker_control_res)
id,
&kickstart,
SID_RESOURCE_PRIO_NORMAL,
SID_RESOURCE_NO_SERVICE_LINKS);
service_link_defs);
if (!res) {
(void) sid_resource_unref(sid_resource_search(worker_control_res, SID_RESOURCE_SEARCH_TOP, NULL, NULL));
return -1;
Expand Down Expand Up @@ -1027,7 +1027,7 @@ static int _run_external_worker(sid_resource_t *worker_control_res)
return r;
}

int worker_control_run_worker(sid_resource_t *worker_control_res)
int worker_control_run_worker(sid_resource_t *worker_control_res, sid_resource_service_link_def_t service_link_defs[])
{
struct worker_control *worker_control = sid_resource_get_data(worker_control_res);

Expand All @@ -1037,7 +1037,7 @@ int worker_control_run_worker(sid_resource_t *worker_control_res)
worker_control->worker_init.prepared = false;

if (worker_control->worker_type == WORKER_TYPE_INTERNAL)
return _run_internal_worker(worker_control_res);
return _run_internal_worker(worker_control_res, service_link_defs);

return _run_external_worker(worker_control_res);
}
Expand All @@ -1046,7 +1046,9 @@ int worker_control_run_worker(sid_resource_t *worker_control_res)
* FIXME: Cleanup resources before running the external worker or do
* something to make valgrind happy, otherwise it will report memleaks.
*/
int worker_control_run_new_worker(sid_resource_t *worker_control_res, struct worker_params *params)
int worker_control_run_new_worker(sid_resource_t *worker_control_res,
struct worker_params *params,
sid_resource_service_link_def_t service_link_defs[])
{
struct worker_control *worker_control = sid_resource_get_data(worker_control_res);
sid_resource_t *proxy_res;
Expand All @@ -1070,7 +1072,7 @@ int worker_control_run_new_worker(sid_resource_t *worker_control_res, struct wor
/*
* WORKER HERE
*/
return worker_control_run_worker(worker_control_res);
return worker_control_run_worker(worker_control_res, service_link_defs);
}

sid_resource_t *worker_control_get_idle_worker(sid_resource_t *worker_control_res)
Expand Down

0 comments on commit d8f7bbb

Please sign in to comment.