[Skiboot] [PATCH RFC 3/5] external/opal-prd: Refactor the handle_prd_control() function
Neelesh Gupta
neelegup at linux.vnet.ibm.com
Wed Jul 29 02:43:44 AEST 2015
Depending upon the control message type, the daemon parses the incoming
messages, invoke the corresponding HBRT interface and sends the response
back to the waiting client. Putting all this into one leads to cumbersome
switch-case and a fat function.
This patch creates the individual functions for different types of control
messages keeping the common code into the handle_prd_control(). It also
does clean up and minor fixes.
Signed-off-by: Neelesh Gupta <neelegup at linux.vnet.ibm.com>
---
external/opal-prd/opal-prd.c | 117 +++++++++++++++++++++++++++---------------
1 file changed, 75 insertions(+), 42 deletions(-)
diff --git a/external/opal-prd/opal-prd.c b/external/opal-prd/opal-prd.c
index 585d086..4940da4 100644
--- a/external/opal-prd/opal-prd.c
+++ b/external/opal-prd/opal-prd.c
@@ -1013,72 +1013,105 @@ static int handle_prd_msg(struct opal_prd_ctx *ctx)
return 0;
}
-static int handle_prd_control(struct opal_prd_ctx *ctx, int fd)
+static void handle_prd_control_occ_error(struct control_msg *msg, int *size)
{
- struct control_msg msg;
- bool enabled;
- int rc;
+ if (*size != sizeof(*msg)) {
+ pr_log(LOG_WARNING, "CTRL: process_occ_error, failed to "
+ "receive control message: %m");
+ goto out;
+ }
- rc = recv(fd, &msg, sizeof(msg), MSG_TRUNC);
- if (rc != sizeof(msg)) {
- pr_log(LOG_WARNING, "CTRL: failed to receive "
- "control message: %m");
- msg.type = CONTROL_MSG_INVALID;
- rc = -1;
- goto out_send;
+ if (!hservice_runtime->process_occ_error) {
+ pr_log_nocall("process_occ_error");
+ goto out;
}
- enabled = false;
- rc = -1;
+ pr_debug("CTRL: calling process_occ_error(0)");
+ call_process_occ_error(0);
+ msg->response = 0;
+
+out:
+ *size = sizeof(*msg);
+}
+
+static void handle_prd_control_occ_reset(struct control_msg *msg, int *size)
+{
+ if (*size != sizeof(*msg)) {
+ pr_log(LOG_WARNING, "CTRL: process_occ_reset, failed to "
+ "receive control message: %m");
+ goto out;
+ }
+
+ if (!hservice_runtime->process_occ_reset) {
+ pr_log_nocall("process_occ_reset");
+ goto out;
+ }
+
+ pr_debug("CTRL: calling process_occ_reset(0)");
+ call_process_occ_reset(0);
+ msg->response = 0;
+out:
+ *size = sizeof(*msg);
+}
+
+static void handle_prd_control_occ_actuation(struct control_msg *msg, int *size,
+ bool enable)
+{
+ if (*size != sizeof(*msg)) {
+ pr_log(LOG_WARNING, "CTRL: enable_occ_actuation, failed to "
+ "receive control message: %m");
+ goto out;
+ }
+
+ if (hservice_runtime->enable_occ_actuation) {
+ pr_log_nocall("enable_occ_actuation");
+ goto out;
+ }
+
+ pr_debug("CTRL: calling enable_occ_actuation(%s)",
+ enable ? "true" : "false");
+ msg->response = call_enable_occ_actuation(enable);
+
+out:
+ *size = sizeof(*msg);
+}
+
+static void handle_prd_control(struct opal_prd_ctx *ctx, int fd)
+{
+ struct control_msg msg;
+ bool enabled = false;
+ int rc, size;
+
+ size = recv(fd, &msg, sizeof(msg), MSG_TRUNC);
+ msg.response = -1;
switch (msg.type) {
case CONTROL_MSG_ENABLE_OCCS:
enabled = true;
/* fall through */
case CONTROL_MSG_DISABLE_OCCS:
- if (!hservice_runtime->enable_occ_actuation) {
- pr_log_nocall("enable_occ_actuation");
- } else {
- pr_debug("CTRL: calling enable_occ_actuation(%s)",
- enabled ? "true" : "false");
- rc = call_enable_occ_actuation(enabled);
- pr_debug("CTRL: -> %d", rc);
- }
+ handle_prd_control_occ_actuation(&msg, &size, enabled);
break;
case CONTROL_MSG_TEMP_OCC_RESET:
- if (hservice_runtime->process_occ_reset) {
- pr_debug("CTRL: calling process_occ_reset(0)");
- call_process_occ_reset(0);
- rc = 0;
- } else {
- pr_log_nocall("process_occ_reset");
- }
+ handle_prd_control_occ_reset(&msg, &size);
break;
case CONTROL_MSG_TEMP_OCC_ERROR:
- if (hservice_runtime->process_occ_error) {
- pr_debug("CTRL: calling process_occ_error(0)");
- call_process_occ_error(0);
- rc = 0;
- } else {
- pr_log_nocall("process_occ_error");
- }
+ handle_prd_control_occ_error(&msg, &size);
break;
default:
pr_log(LOG_WARNING, "CTRL: Unknown control message action %d",
msg.type);
+ msg.type = CONTROL_MSG_INVALID;
+ size = sizeof(msg);
+ break;
}
-out_send:
- /* send a response */
- msg.response = rc;
- rc = send(fd, &msg, sizeof(msg), MSG_DONTWAIT | MSG_NOSIGNAL);
+ rc = send(fd, &msg, size, MSG_DONTWAIT | MSG_NOSIGNAL);
if (rc && (errno == EAGAIN || errno == EWOULDBLOCK || errno == EPIPE))
pr_debug("CTRL: control send() returned %d, ignoring failure",
rc);
- else if (rc != sizeof(msg))
+ else if (rc != size)
pr_log(LOG_NOTICE, "CTRL: Failed to send control response: %m");
-
- return 0;
}
static int run_attn_loop(struct opal_prd_ctx *ctx)
More information about the Skiboot
mailing list