// SPDX-License-Identifier: GPL-2.0 /* * Copyright (C) 2019-2022 Red Hat, Inc. Daniel Bristot de Oliveira <bristot@kernel.org> * * Runtime reactor interface. * * A runtime monitor can cause a reaction to the detection of an * exception on the model's execution. By default, the monitors have * tracing reactions, printing the monitor output via tracepoints. * But other reactions can be added (on-demand) via this interface. * * == Registering reactors == * * The struct rv_reactor defines a callback function to be executed * in case of a model exception happens. The callback function * receives a message to be (optionally) printed before executing * the reaction. * * A RV reactor is registered via: * int rv_register_reactor(struct rv_reactor *reactor) * And unregistered via: * int rv_unregister_reactor(struct rv_reactor *reactor) * * These functions are exported to modules, enabling reactors to be * dynamically loaded. * * == User interface == * * The user interface resembles the kernel tracing interface and * presents these files: * * "available_reactors" * - List the available reactors, one per line. * * For example: * # cat available_reactors * nop * panic * printk * * "reacting_on" * - It is an on/off general switch for reactors, disabling * all reactions. * * "monitors/MONITOR/reactors" * - List available reactors, with the select reaction for the given * MONITOR inside []. The default one is the nop (no operation) * reactor. * - Writing the name of an reactor enables it to the given * MONITOR. * * For example: * # cat monitors/wip/reactors * [nop] * panic * printk * # echo panic > monitors/wip/reactors * # cat monitors/wip/reactors * nop * [panic] * printk
*/
#include <linux/slab.h>
#include"rv.h"
/* * Interface for the reactor register.
*/ static LIST_HEAD(rv_reactors_list);
if (rv_is_container_monitor(mon))
list_for_each_entry_continue(p, &rv_monitors_list, list) { if (p->parent != mon) break;
monitor_swap_reactors_single(p, reactor, true);
} /* * This call enables and disables the monitor if they were active. * In case of a container, we already disabled all and will enable all. * All nested monitors are enabled also if they were off, we may refine * this logic in the future.
*/
monitor_swap_reactors_single(mon, reactor, false);
}
list_for_each_entry(r, &rv_reactors_list, list) { if (strcmp(reactor->name, r->name) == 0) {
pr_info("Reactor %s is already registered\n", reactor->name); return -EINVAL;
}
}
list_add_tail(&reactor->list, &rv_reactors_list);
return 0;
}
/** * rv_register_reactor - register a rv reactor. * @reactor: The rv_reactor to be registered. * * Returns 0 if successful, error otherwise.
*/ int rv_register_reactor(struct rv_reactor *reactor)
{ int retval = 0;
if (strlen(reactor->name) >= MAX_RV_REACTOR_NAME_SIZE) {
pr_info("Reactor %s has a name longer than %d\n",
reactor->name, MAX_RV_MONITOR_NAME_SIZE); return -EINVAL;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.