Skip to content

Commit b8d29c8

Browse files
committed
Add support for exclusion of kernel event
Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
1 parent cfcf594 commit b8d29c8

File tree

4 files changed

+131
-2
lines changed

4 files changed

+131
-2
lines changed

lttng-abi.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,6 +1462,18 @@ long lttng_event_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
14621462
(struct lttng_kernel_filter_bytecode __user *) arg);
14631463
}
14641464

1465+
}
1466+
case LTTNG_KERNEL_EXCLUSION:
1467+
switch (*evtype) {
1468+
case LTTNG_TYPE_EVENT:
1469+
return -EINVAL;
1470+
case LTTNG_TYPE_ENABLER:
1471+
{
1472+
enabler = file->private_data;
1473+
return lttng_enabler_attach_exclusion(enabler,
1474+
(struct lttng_kernel_event_exclusion __user *) arg);
1475+
}
1476+
14651477
}
14661478
default:
14671479
return -ENOIOCTLCMD;

lttng-abi.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ struct lttng_kernel_filter_bytecode {
173173
uint64_t seqnum;
174174
char data[0];
175175
} __attribute__((packed));
176+
#define LTTNG_KERNEL_EXCLUSION_PADDING 32
177+
struct lttng_kernel_event_exclusion {
178+
uint32_t count;
179+
char padding[LTTNG_KERNEL_EXCLUSION_PADDING];
180+
char names[LTTNG_KERNEL_SYM_NAME_LEN][0];
181+
} __attribute__((packed));
176182

177183
/* LTTng file descriptor ioctl */
178184
#define LTTNG_KERNEL_SESSION _IO(0xF6, 0x45)
@@ -224,6 +230,7 @@ struct lttng_kernel_filter_bytecode {
224230

225231
/* Event FD ioctl */
226232
#define LTTNG_KERNEL_FILTER _IO(0xF6, 0x90)
233+
#define LTTNG_KERNEL_EXCLUSION _IO(0xF6, 0x91)
227234

228235
/* LTTng-specific ioctls for the lib ringbuffer */
229236
/* returns the timestamp begin of the current sub-buffer */

lttng-events.c

Lines changed: 100 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,7 +1144,7 @@ int lttng_session_list_tracker_pids(struct lttng_session *session)
11441144
* Enabler management.
11451145
*/
11461146
static
1147-
int lttng_match_enabler_star_glob(const char *desc_name,
1147+
int lttng_match_event_pattern_star_glob(const char *desc_name,
11481148
const char *pattern)
11491149
{
11501150
if (!strutils_star_glob_match(pattern, LTTNG_SIZE_MAX,
@@ -1162,6 +1162,48 @@ int lttng_match_enabler_name(const char *desc_name,
11621162
return 1;
11631163
}
11641164

1165+
static
1166+
int lttng_match_enabler_exclusion(const char *desc_name,
1167+
struct lttng_enabler *enabler)
1168+
{
1169+
struct lttng_excluder_node *excluder;
1170+
/**
1171+
* Iterate over the list of excluders of this enabler. If the
1172+
* event matches with an excluder, return 'do not enable'
1173+
*/
1174+
list_for_each_entry(excluder, &enabler->excluder_head, node) {
1175+
int count;
1176+
1177+
for (count = 0; count < excluder->exclusion.count; count++) {
1178+
int len;
1179+
char *excluder_name;
1180+
1181+
excluder_name = (char *) (excluder->exclusion.names) +
1182+
(count * LTTNG_KERNEL_SYM_NAME_LEN);
1183+
1184+
len = strnlen(excluder_name, LTTNG_KERNEL_SYM_NAME_LEN);
1185+
1186+
if (len <= 0) {
1187+
continue;
1188+
}
1189+
1190+
/**
1191+
* If the event name matches with the exclusion,
1192+
* return 0 to signify that this event should _not_ be
1193+
* enabled
1194+
*/
1195+
if (lttng_match_event_pattern_star_glob(desc_name, excluder_name)) {
1196+
return 0;
1197+
}
1198+
}
1199+
}
1200+
/**
1201+
* If none of the exclusions match with the event name,
1202+
* return 1 to signify that this event should be enabled
1203+
*/
1204+
return 1;
1205+
}
1206+
11651207
static
11661208
int lttng_desc_match_enabler(const struct lttng_event_desc *desc,
11671209
struct lttng_enabler *enabler)
@@ -1194,7 +1236,17 @@ int lttng_desc_match_enabler(const struct lttng_event_desc *desc,
11941236
}
11951237
switch (enabler->type) {
11961238
case LTTNG_ENABLER_STAR_GLOB:
1197-
return lttng_match_enabler_star_glob(desc_name, enabler_name);
1239+
{
1240+
/**
1241+
* Return 'does not match' if the event name does not match with
1242+
* the enabler.
1243+
*/
1244+
if (!lttng_match_event_pattern_star_glob(desc_name, enabler_name)) {
1245+
return 0;
1246+
}
1247+
1248+
return lttng_match_enabler_exclusion(desc_name, enabler);
1249+
}
11981250
case LTTNG_ENABLER_NAME:
11991251
return lttng_match_enabler_name(desc_name, enabler_name);
12001252
default:
@@ -1386,6 +1438,7 @@ struct lttng_enabler *lttng_enabler_create(enum lttng_enabler_type type,
13861438
return NULL;
13871439
enabler->type = type;
13881440
INIT_LIST_HEAD(&enabler->filter_bytecode_head);
1441+
INIT_LIST_HEAD(&enabler->excluder_head);
13891442
memcpy(&enabler->event_param, event_param,
13901443
sizeof(enabler->event_param));
13911444
enabler->chan = chan;
@@ -1447,6 +1500,45 @@ int lttng_enabler_attach_bytecode(struct lttng_enabler *enabler,
14471500
return ret;
14481501
}
14491502

1503+
int lttng_enabler_attach_exclusion(struct lttng_enabler *enabler,
1504+
struct lttng_kernel_event_exclusion __user *exclusion)
1505+
{
1506+
struct lttng_excluder_node *excluder_node;
1507+
uint32_t exclusion_count;
1508+
int ret;
1509+
1510+
ret = get_user(exclusion_count, &exclusion->count);
1511+
if (ret) {
1512+
goto error;
1513+
}
1514+
1515+
excluder_node = kzalloc(sizeof(*excluder_node) +
1516+
(exclusion_count * LTTNG_KERNEL_SYM_NAME_LEN),
1517+
GFP_KERNEL);
1518+
if (!excluder_node) {
1519+
ret = -ENOMEM;
1520+
goto error;
1521+
}
1522+
1523+
ret = copy_from_user(&excluder_node->exclusion, exclusion,
1524+
sizeof(*exclusion) + (exclusion_count * LTTNG_KERNEL_SYM_NAME_LEN));
1525+
if (ret) {
1526+
goto error_free;
1527+
}
1528+
1529+
excluder_node->enabler = enabler;
1530+
excluder_node->exclusion.count = exclusion_count;
1531+
1532+
list_add_tail(&excluder_node->node, &enabler->excluder_head);
1533+
lttng_session_lazy_sync_enablers(enabler->chan->session);
1534+
return 0;
1535+
1536+
error_free:
1537+
kfree(excluder_node);
1538+
error:
1539+
return ret;
1540+
}
1541+
14501542
int lttng_enabler_attach_context(struct lttng_enabler *enabler,
14511543
struct lttng_kernel_context *context_param)
14521544
{
@@ -1457,13 +1549,19 @@ static
14571549
void lttng_enabler_destroy(struct lttng_enabler *enabler)
14581550
{
14591551
struct lttng_filter_bytecode_node *filter_node, *tmp_filter_node;
1552+
struct lttng_excluder_node *excluder_node, *tmp_excluder_node;
14601553

14611554
/* Destroy filter bytecode */
14621555
list_for_each_entry_safe(filter_node, tmp_filter_node,
14631556
&enabler->filter_bytecode_head, node) {
14641557
kfree(filter_node);
14651558
}
14661559

1560+
list_for_each_entry_safe(excluder_node, tmp_excluder_node,
1561+
&enabler->excluder_head, node) {
1562+
kfree(excluder_node);
1563+
}
1564+
14671565
/* Destroy contexts */
14681566
lttng_destroy_context(enabler->ctx);
14691567

lttng-events.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,15 @@ struct lttng_filter_bytecode_node {
258258
*/
259259
struct lttng_kernel_filter_bytecode bc;
260260
};
261+
struct lttng_excluder_node {
262+
struct list_head node;
263+
struct lttng_enabler *enabler;
264+
/*
265+
* struct lttng_kernel_event_exclusion has var. sized array, must be
266+
* last field.
267+
*/
268+
struct lttng_kernel_event_exclusion exclusion;
269+
};
261270

262271
/*
263272
* Filter return value masks.
@@ -340,6 +349,7 @@ struct lttng_enabler {
340349
struct list_head node; /* per-session list of enablers */
341350
/* head list of struct lttng_ust_filter_bytecode_node */
342351
struct list_head filter_bytecode_head;
352+
struct list_head excluder_head;
343353

344354
struct lttng_kernel_event event_param;
345355
struct lttng_channel *chan;
@@ -655,6 +665,8 @@ static inline long lttng_channel_syscall_mask(struct lttng_channel *channel,
655665
void lttng_filter_sync_state(struct lttng_bytecode_runtime *runtime);
656666
int lttng_enabler_attach_bytecode(struct lttng_enabler *enabler,
657667
struct lttng_kernel_filter_bytecode __user *bytecode);
668+
int lttng_enabler_attach_exclusion(struct lttng_enabler *enabler,
669+
struct lttng_kernel_event_exclusion __user *exclusion);
658670
void lttng_enabler_event_link_bytecode(struct lttng_event *event,
659671
struct lttng_enabler *enabler);
660672

0 commit comments

Comments
 (0)