kernel/trace/rv/rv_reactors.c

Source file repositories/reference/linux-study-clean/kernel/trace/rv/rv_reactors.c

File Facts

System
Linux kernel
Corpus path
kernel/trace/rv/rv_reactors.c
Extension
.c
Size
10858 bytes
Lines
482
Domain
Core OS
Bucket
Scheduler, Processes, Timers, Sync, And Syscalls
Inferred role
Core OS: operation-table or driver-model contract
Status
pattern implementation candidate

Why This File Exists

Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.

Dependency Surface

Detected Declarations

Annotated Snippet

static const struct file_operations available_reactors_ops = {
	.open    = available_reactors_open,
	.read    = seq_read,
	.llseek  = seq_lseek,
	.release = seq_release
};

/*
 * Monitor's reactor file.
 */
static int monitor_reactor_show(struct seq_file *m, void *p)
{
	struct rv_monitor *mon = m->private;
	struct rv_reactor *reactor = container_of(p, struct rv_reactor, list);

	if (mon->reactor == reactor)
		seq_printf(m, "[%s]\n", reactor->name);
	else
		seq_printf(m, "%s\n", reactor->name);
	return 0;
}

/*
 * available_reactors seq definition.
 */
static const struct seq_operations monitor_reactors_seq_ops = {
	.start	= reactors_start,
	.next	= reactors_next,
	.stop	= reactors_stop,
	.show	= monitor_reactor_show
};

static void monitor_swap_reactors_single(struct rv_monitor *mon,
					 struct rv_reactor *reactor,
					 bool nested)
{
	bool monitor_enabled;

	/* nothing to do */
	if (mon->reactor == reactor)
		return;

	monitor_enabled = mon->enabled;
	if (monitor_enabled)
		rv_disable_monitor(mon);

	mon->reactor = reactor;
	mon->react = reactor->react;

	/* enable only once if iterating through a container */
	if (monitor_enabled && !nested)
		rv_enable_monitor(mon);
}

static void monitor_swap_reactors(struct rv_monitor *mon, struct rv_reactor *reactor)
{
	struct rv_monitor *p = mon;

	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);
}

static ssize_t
monitor_reactors_write(struct file *file, const char __user *user_buf,
		      size_t count, loff_t *ppos)
{
	char buff[MAX_RV_REACTOR_NAME_SIZE + 2];
	struct rv_monitor *mon;
	struct rv_reactor *reactor;
	struct seq_file *seq_f;
	int retval = -EINVAL;
	char *ptr;
	int len;

	if (count < 1 || count > MAX_RV_REACTOR_NAME_SIZE + 1)
		return -EINVAL;

	memset(buff, 0, sizeof(buff));

Annotation

Implementation Notes