Add action executed event 78/137178/2
authorKrzysztof Opasiak <k.opasiak@samsung.com>
Tue, 4 Jul 2017 15:05:52 +0000 (17:05 +0200)
committerKrzysztof Opasiak <k.opasiak@samsung.com>
Thu, 6 Jul 2017 14:09:11 +0000 (16:09 +0200)
This event should be generated after each action execution
this allows to store action log into data base using our
generic framework.

Add also dummy handler for this event type to avoid some logs
about unhandled event.

Change-Id: If18b2bc7692ef136f6e952fd59350940e021fba5
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Makefile.am
src/action/action_executed_handler.c [new file with mode: 0644]
src/event_types/action_executed_event.c [new file with mode: 0644]
src/event_types/action_executed_event.h [new file with mode: 0644]
src/util/common.h

index 8cfdb92abf02697389a2eb2f80fc1dd022428f54..01fdd27d3d725b53526bcf29c4ee32db5e73439a 100644 (file)
@@ -67,6 +67,7 @@ faultd_SOURCES = \
     src/decision_makers/rv_dm.c \
     src/decision_makers/standard_fault_dm.c \
     src/decision_makers/vip_fault_dm.c \
+    src/event_types/action_executed_event.c \
     src/event_types/decision_made_event.c \
     src/event_types/resource_violation_event.c \
     src/event_types/service_failed_event.c \
diff --git a/src/action/action_executed_handler.c b/src/action/action_executed_handler.c
new file mode 100644 (file)
index 0000000..1989333
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * This file is part of faultd.
+ *
+ * Copyright © 2017 Samsung Electronics
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <malloc.h>
+
+#include "action_executed_event.h"
+#include "action.h"
+#include "event_processor.h"
+#include "log.h"
+
+static int ae_event_match(struct faultd_event_handler *handler,
+                                                 struct faultd_event *ev)
+{
+       return faultd_event_is_of_type(ev, ACTION_EXECUTED_EVENT_ID);
+}
+
+static int ae_handle_event(struct faultd_event_handler *handler)
+{
+       struct faultd_event *ev = nqueue_pop(&handler->event_queue,
+                                                                                struct faultd_event,
+                                                                                nq_node);
+
+       faultd_event_unref(ev);
+       return 0;
+}
+
+static struct faultd_event_handler action_executed_event_handler = {
+       .name = "action_executed_empty_handler",
+       .event_match = ae_event_match,
+       .handle_event = ae_handle_event,
+
+       .node = LIST_HEAD_INIT(action_executed_event_handler.node),
+};
+
+FAULTD_EVENT_HANDLER_REGISTER(action_executed_event_handler,
+                              action_executed_eh,
+                              FAULTD_MODULE_TYPE_ACTION_EXECUTOR)
diff --git a/src/event_types/action_executed_event.c b/src/event_types/action_executed_event.c
new file mode 100644 (file)
index 0000000..9d60c16
--- /dev/null
@@ -0,0 +1,136 @@
+/*
+ * This file is part of faultd.
+ *
+ * Copyright © 2017 Samsung Electronics
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <ejdb/bson.h>
+#include <stdio.h>
+#include <errno.h>
+#include <malloc.h>
+
+#include "common.h"
+#include "action_executed_event.h"
+
+static int allocate_ae_event(struct faultd_event_type *type,
+                             void *data, struct faultd_event **ev)
+{
+       struct action_executed_event *ae_ev;
+       struct ae_event_data *ae_ev_data = data;
+       int ret;
+
+       ae_ev = calloc(1, sizeof(*ae_ev));
+       if (!ae_ev)
+               return -ENOMEM;
+
+       ret = faultd_event_init_internal(type, &ae_ev->event);
+       if (ret)
+               goto free_ae_ev;
+
+       ae_ev->action = strdup(ae_ev_data->action);
+       ae_ev->action_impl = strdup(ae_ev_data->action_impl);
+
+       if (!ae_ev->action || !ae_ev->action_impl) {
+               ret = -ENOMEM;
+               goto cleanup_strs;
+       }
+
+       ae_ev->action_log = ae_ev_data->action_log;
+       ae_ev->result  = ae_ev_data->result;
+
+       ae_ev->reason = ae_ev_data->reason;
+       if (ae_ev->reason)
+               faultd_event_ref(ae_ev->reason);
+
+       *ev = &ae_ev->event;
+       return 0;
+cleanup_strs:
+       free(ae_ev->action);
+       free(ae_ev->action_impl);
+
+       faultd_event_cleanup_internal(&ae_ev->event);
+free_ae_ev:
+       free(ae_ev);
+
+       return ret;
+}
+
+static void ae_event_release(struct faultd_event *ev)
+{
+       struct action_executed_event *ae_ev =
+               to_action_executed_event(ev);
+
+       if (ae_ev->reason)
+               faultd_event_unref(ae_ev->reason);
+       free(ae_ev->action);
+       free(ae_ev->action_impl);
+       bson_destroy(&ae_ev->action_log);
+       faultd_event_cleanup_internal(&ae_ev->event);
+       free(ae_ev);
+}
+
+static char *ae_event_to_string(struct faultd_event *ev)
+{
+       struct action_executed_event *ae_ev =
+               to_action_executed_event(ev);
+       char *str;
+       char *buf;
+       int len;
+       int ret;
+
+       bson2json(ae_ev->action_log.data, &buf, &len);
+
+       ret = asprintf(&str, "Action Executed Event:"
+                                  " Action: %s"
+                                  " Impl: %s"
+                                  " Log:  %s"
+                                  " Result: %d",
+                                  ae_ev->action,
+                                  ae_ev->action_impl,
+                                  buf,
+                                  ae_ev->result);
+
+       free(buf);
+
+       return ret > 0 ? str : NULL;
+}
+
+static void ae_event_serialize(struct faultd_event *ev, bson *out)
+{
+       struct action_executed_event *ae_ev =
+               to_action_executed_event(ev);
+
+       assert(!BSON_OID_IS_ZERO(ae_ev->reason->oid));
+
+       faultd_event_serialize_internal(ev, out);
+       bson_append_oid(out, AE_EV_REASON, &ae_ev->reason->oid);
+       bson_append_string(out, AE_EV_ACTION, ae_ev->action);
+       bson_append_string(out, AE_EV_ACTION_IMPL, ae_ev->action_impl);
+       bson_append_bson(out, AE_EV_ACTION_LOG, &ae_ev->action_log);
+       bson_append_int(out, AE_EV_RESULT, ae_ev->result);
+}
+
+static struct faultd_event_type action_executed_event_type = {
+       .name = ACTION_EXECUTED_EVENT_ID,
+       .default_ops = {
+               .release = ae_event_release,
+               .serialize = ae_event_serialize,
+               .to_string = ae_event_to_string,
+       },
+       .allocate_event = allocate_ae_event,
+       .node = LIST_HEAD_INIT(action_executed_event_type.node),
+};
+
+FAULTD_EVENT_TYPE_REGISTER(action_executed_event_type, action_executed_et)
diff --git a/src/event_types/action_executed_event.h b/src/event_types/action_executed_event.h
new file mode 100644 (file)
index 0000000..6dd38a6
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * This file is part of faultd.
+ *
+ * Copyright © 2017 Samsung Electronics
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef FAULTD_ACTION_EXECUTED_EVENT_H
+#define FAULTD_ACTION_EXECUTED_EVENT_H
+
+#include <time.h>
+
+#include "action.h"
+#include "event.h"
+#include "common.h"
+
+#define ACTION_EXECUTED_EVENT_ID "action_executed"
+#define AE_EV_REASON "reason"
+#define AE_EV_ACTION "act"
+#define AE_EV_ACTION_IMPL "actimpl"
+#define AE_EV_ACTION_LOG "actlog"
+#define AE_EV_RESULT "res"
+
+struct action_executed_event {
+       struct faultd_event event;
+       struct faultd_event *reason;
+       char *action;
+       char *action_impl;
+       bson action_log;
+       int result;
+};
+
+struct ae_event_data {
+       /* This is referenced by ae event */
+       struct faultd_event *reason;
+       /* Strings are deep copied */
+       char *action;
+       char *action_impl;
+       /* Action log is shallow copied */
+       bson action_log;
+       int result;
+};
+
+#define to_action_executed_event(EVENT)                                                \
+       container_of(EVENT, struct action_executed_event, event)
+
+#endif /* FAULTD_ACTION_EXECUTED_EVENT_H */
index 05e9e2a032a21931bd5130eebc3e89b5031d3fad..0fbcb51a801fb0962d6f720c73acc49c343cf193 100644 (file)
 #include <time.h>
 #include <errno.h>
 
+/*
+ * Value taken from linux kernel.
+ * This value should be never returned to the caller so we may use
+ * it for our internal purpouse
+ */
+#define EPROBE_DEFER   517
+
 /* STR and CONCAT macros need two levels to accept macros as
    arguments */
 #define _STR(A) #A