1*287e80b3SSadaf Ebrahimi // SPDX-License-Identifier: LGPL-2.1
2*287e80b3SSadaf Ebrahimi /*
3*287e80b3SSadaf Ebrahimi * Copyright (C) 2021, VMware, Tzvetomir Stoyanov <[email protected]>
4*287e80b3SSadaf Ebrahimi *
5*287e80b3SSadaf Ebrahimi */
6*287e80b3SSadaf Ebrahimi #include <stdlib.h>
7*287e80b3SSadaf Ebrahimi #include <errno.h>
8*287e80b3SSadaf Ebrahimi
9*287e80b3SSadaf Ebrahimi #include "tracefs.h"
10*287e80b3SSadaf Ebrahimi #include "tracefs-local.h"
11*287e80b3SSadaf Ebrahimi
12*287e80b3SSadaf Ebrahimi #define EPROBE_DEFAULT_GROUP "eprobes"
13*287e80b3SSadaf Ebrahimi
14*287e80b3SSadaf Ebrahimi /**
15*287e80b3SSadaf Ebrahimi * tracefs_eprobe_alloc - Allocate new eprobe
16*287e80b3SSadaf Ebrahimi * @system: The system name (NULL for the default eprobes)
17*287e80b3SSadaf Ebrahimi * @event: The name of the event to create
18*287e80b3SSadaf Ebrahimi * @target_system: The system of the target event
19*287e80b3SSadaf Ebrahimi * @target_event: The name of the target event
20*287e80b3SSadaf Ebrahimi * @fetchargs: String with arguments, that will be fetched from @target_event
21*287e80b3SSadaf Ebrahimi *
22*287e80b3SSadaf Ebrahimi * Allocate an eprobe context that will be in the @system group (or eprobes if
23*287e80b3SSadaf Ebrahimi * @system is NULL). Have the name of @event. The new eprobe will be attached to
24*287e80b3SSadaf Ebrahimi * given @target_event which is in the given @target_system. The arguments
25*287e80b3SSadaf Ebrahimi * described in @fetchargs will fetched from the @target_event.
26*287e80b3SSadaf Ebrahimi *
27*287e80b3SSadaf Ebrahimi * The eprobe is not created in the system.
28*287e80b3SSadaf Ebrahimi *
29*287e80b3SSadaf Ebrahimi * Return a pointer to a eprobe context on success, or NULL on error.
30*287e80b3SSadaf Ebrahimi * The returned pointer must be freed with tracefs_dynevent_free()
31*287e80b3SSadaf Ebrahimi *
32*287e80b3SSadaf Ebrahimi */
33*287e80b3SSadaf Ebrahimi struct tracefs_dynevent *
tracefs_eprobe_alloc(const char * system,const char * event,const char * target_system,const char * target_event,const char * fetchargs)34*287e80b3SSadaf Ebrahimi tracefs_eprobe_alloc(const char *system, const char *event,
35*287e80b3SSadaf Ebrahimi const char *target_system, const char *target_event, const char *fetchargs)
36*287e80b3SSadaf Ebrahimi {
37*287e80b3SSadaf Ebrahimi struct tracefs_dynevent *kp;
38*287e80b3SSadaf Ebrahimi char *target;
39*287e80b3SSadaf Ebrahimi
40*287e80b3SSadaf Ebrahimi if (!event || !target_system || !target_event) {
41*287e80b3SSadaf Ebrahimi errno = EINVAL;
42*287e80b3SSadaf Ebrahimi return NULL;
43*287e80b3SSadaf Ebrahimi }
44*287e80b3SSadaf Ebrahimi
45*287e80b3SSadaf Ebrahimi if (!system)
46*287e80b3SSadaf Ebrahimi system = EPROBE_DEFAULT_GROUP;
47*287e80b3SSadaf Ebrahimi
48*287e80b3SSadaf Ebrahimi if (asprintf(&target, "%s.%s", target_system, target_event) < 0)
49*287e80b3SSadaf Ebrahimi return NULL;
50*287e80b3SSadaf Ebrahimi
51*287e80b3SSadaf Ebrahimi kp = dynevent_alloc(TRACEFS_DYNEVENT_EPROBE, system, event, target, fetchargs);
52*287e80b3SSadaf Ebrahimi free(target);
53*287e80b3SSadaf Ebrahimi
54*287e80b3SSadaf Ebrahimi return kp;
55*287e80b3SSadaf Ebrahimi }
56*287e80b3SSadaf Ebrahimi
57