@@ -1144,7 +1144,7 @@ int lttng_session_list_tracker_pids(struct lttng_session *session)
11441144 * Enabler management.
11451145 */
11461146static
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+
11651207static
11661208int 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+
14501542int lttng_enabler_attach_context (struct lttng_enabler * enabler ,
14511543 struct lttng_kernel_context * context_param )
14521544{
@@ -1457,13 +1549,19 @@ static
14571549void 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
0 commit comments