Commit 9c65b62e authored by Sebastien Gougeaud's avatar Sebastien Gougeaud Committed by Thomas Leibovici
Browse files

refactor: reorganize admin source file



Separating static and API functions.

Change-Id: I54dd48e696d124279da3698ec80ccaea6e0c93a8
Signed-off-by: default avatarSebastien Gougeaud <sebastien.gougeaud@cea.fr>
Reviewed-on: https://gerrit.ccc.ocre.cea.fr/gerrit/c/phobos/+/6791

Reviewed-by: default avatarQuentin Bouget <quentin.bouget@cea.fr>
Reviewed-by: Linter
Reviewed-by: default avatarThomas Leibovici <thomas.leibovici@cea.fr>
Tested-by: default avatarJenkins s8open_nr <s8open_nr@ccc.ocre.cea.fr>
parent 0707ba20
......@@ -52,6 +52,10 @@ const struct pho_config_item cfg_admin[] = {
},
};
/* ****************************************************************************/
/* Static Functions ***********************************************************/
/* ****************************************************************************/
static int _send_and_receive(struct admin_handle *adm, pho_req_t *req,
pho_resp_t **resp)
{
......@@ -91,54 +95,6 @@ static int _send_and_receive(struct admin_handle *adm, pho_req_t *req,
return 0;
}
void phobos_admin_fini(struct admin_handle *adm)
{
int rc;
rc = pho_comm_close(&adm->comm);
if (rc)
pho_error(rc, "Cannot close the communication socket");
dss_fini(&adm->dss);
}
int phobos_admin_init(struct admin_handle *adm, const bool lrs_required)
{
const char *sock_path;
int rc;
memset(adm, 0, sizeof(*adm));
adm->comm = pho_comm_info_init();
rc = pho_cfg_init_local(NULL);
if (rc && rc != -EALREADY)
return rc;
sock_path = PHO_CFG_GET(cfg_admin, PHO_CFG_ADMIN, lrs_socket);
rc = dss_init(&adm->dss);
if (rc)
LOG_GOTO(out, rc, "Cannot initialize DSS");
rc = pho_comm_open(&adm->comm, sock_path, false);
if (!lrs_required && rc == -ENOTCONN) {
pho_warn("Cannot contact 'phobosd', but not required: will continue");
rc = 0;
} else if (rc) {
LOG_GOTO(out, rc, "Cannot contact 'phobosd': will abort");
} else {
adm->daemon_is_online = true;
}
out:
if (rc) {
pho_error(rc, "Error during Admin initialization");
phobos_admin_fini(adm);
}
return rc;
}
static int _admin_notify(struct admin_handle *adm, struct pho_id *id,
enum notify_op op)
{
......@@ -187,6 +143,58 @@ out:
return rc;
}
/* ****************************************************************************/
/* API Functions **************************************************************/
/* ****************************************************************************/
void phobos_admin_fini(struct admin_handle *adm)
{
int rc;
rc = pho_comm_close(&adm->comm);
if (rc)
pho_error(rc, "Cannot close the communication socket");
dss_fini(&adm->dss);
}
int phobos_admin_init(struct admin_handle *adm, const bool lrs_required)
{
const char *sock_path;
int rc;
memset(adm, 0, sizeof(*adm));
adm->comm = pho_comm_info_init();
rc = pho_cfg_init_local(NULL);
if (rc && rc != -EALREADY)
return rc;
sock_path = PHO_CFG_GET(cfg_admin, PHO_CFG_ADMIN, lrs_socket);
rc = dss_init(&adm->dss);
if (rc)
LOG_GOTO(out, rc, "Cannot initialize DSS");
rc = pho_comm_open(&adm->comm, sock_path, false);
if (!lrs_required && rc == -ENOTCONN) {
pho_warn("Cannot contact 'phobosd', but not required: will continue");
rc = 0;
} else if (rc) {
LOG_GOTO(out, rc, "Cannot contact 'phobosd': will abort");
} else {
adm->daemon_is_online = true;
}
out:
if (rc) {
pho_error(rc, "Error during Admin initialization");
phobos_admin_fini(adm);
}
return rc;
}
/**
* TODO: admin_device_add will have the responsability to add the device
* to the DSS, to then remove this part of code from the CLI.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment