event-rule: userspace probe: force location on create
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Thu, 5 Nov 2020 19:59:58 +0000 (14:59 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 18 Mar 2021 15:02:10 +0000 (11:02 -0400)
Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I5775184c62249c642af0ca0315103e040cb2502d

include/lttng/event-rule/userspace-probe.h
src/bin/lttng/commands/add_trigger.c
src/common/event-rule/userspace-probe.c
tests/regression/tools/notification/notification.c
tests/unit/test_event_rule.c

index dd90966cfb1cbea3110605c8abae3c2d37ab1949..37b366b68b980c280cac7efb3d0d61cb6de16ee9 100644 (file)
@@ -18,21 +18,12 @@ extern "C" {
 /*
  * Create a newly allocated user space probe event rule.
  *
- * Returns a new event rule on success, NULL on failure. This event rule must be
- * destroyed using lttng_event_rule_destroy().
- */
-extern struct lttng_event_rule *lttng_event_rule_userspace_probe_create(void);
-
-/*
- * Set the location of a user space probe event rule.
- *
  * The location is copied internally.
  *
- * Returns LTTNG_EVENT_RULE_STATUS_OK on success, LTTNG_EVENT_RULE_STATUS_INVALID
- * if invalid parameters are passed.
+ * Returns a new event rule on success, NULL on failure. This event rule must be
+ * destroyed using lttng_event_rule_destroy().
  */
-extern enum lttng_event_rule_status lttng_event_rule_userspace_probe_set_location(
-               struct lttng_event_rule *rule,
+extern struct lttng_event_rule *lttng_event_rule_userspace_probe_create(
                const struct lttng_userspace_probe_location *location);
 
 /*
index 092f3c8e2dd3991d03b97ad498a1f5909af3029b..776e24470aabdb78607ad9ffa4fb9fe01c0ea782 100644 (file)
@@ -994,22 +994,14 @@ struct parse_event_rule_res parse_event_rule(int *argc, const char ***argv)
                        goto error;
                }
 
-               res.er = lttng_event_rule_userspace_probe_create();
+               res.er = lttng_event_rule_userspace_probe_create(userspace_probe_location);
                if (!res.er) {
                        ERR("Failed to create userspace probe event rule.");
                        goto error;
                }
 
-               event_rule_status = lttng_event_rule_userspace_probe_set_location(
-                               res.er, userspace_probe_location);
-               if (event_rule_status != LTTNG_EVENT_RULE_STATUS_OK) {
-                       ERR("Failed to set user space probe event rule's location.");
-                       goto error;
-               }
-
-               event_rule_status =
-                               lttng_event_rule_userspace_probe_set_event_name(
-                                               res.er, tracepoint_name);
+               event_rule_status = lttng_event_rule_userspace_probe_set_event_name(
+                               res.er, tracepoint_name);
                if (event_rule_status != LTTNG_EVENT_RULE_STATUS_OK) {
                        ERR("Failed to set user space probe event rule's name to '%s'.",
                                        tracepoint_name);
index 44a7a8043087a2dfdd6f0a4cef93b4e6d093d235..52c7553e90fc52980b9d24e2b3a50b17148c1813 100644 (file)
@@ -187,7 +187,35 @@ lttng_event_rule_userspace_probe_hash(
        return hash;
 }
 
-struct lttng_event_rule *lttng_event_rule_userspace_probe_create(void)
+static
+int userspace_probe_set_location(
+               struct lttng_event_rule_userspace_probe *uprobe,
+               const struct lttng_userspace_probe_location *location)
+{
+       int ret;
+       struct lttng_userspace_probe_location *location_copy = NULL;
+
+       if (!uprobe || !location || uprobe->location) {
+               ret = -1;
+               goto end;
+       }
+
+       location_copy = lttng_userspace_probe_location_copy(location);
+       if (!location_copy) {
+               ret = -1;
+               goto end;
+       }
+
+       uprobe->location = location_copy;
+       location_copy = NULL;
+       ret = 0;
+end:
+       lttng_userspace_probe_location_destroy(location_copy);
+       return ret;
+}
+
+struct lttng_event_rule *lttng_event_rule_userspace_probe_create(
+               const struct lttng_userspace_probe_location *location)
 {
        struct lttng_event_rule *rule = NULL;
        struct lttng_event_rule_userspace_probe *urule;
@@ -212,6 +240,11 @@ struct lttng_event_rule *lttng_event_rule_userspace_probe_create(void)
                        lttng_event_rule_userspace_probe_generate_exclusions;
        urule->parent.hash = lttng_event_rule_userspace_probe_hash;
 
+       if (userspace_probe_set_location(urule, location)) {
+               lttng_event_rule_destroy(rule);
+               rule = NULL;
+       }
+
 end:
        return rule;
 }
@@ -226,8 +259,7 @@ ssize_t lttng_event_rule_userspace_probe_create_from_payload(
        const char *name;
        struct lttng_buffer_view current_buffer_view;
        struct lttng_event_rule *rule = NULL;
-       struct lttng_userspace_probe_location *location;
-       struct lttng_event_rule_userspace_probe *uprobe;
+       struct lttng_userspace_probe_location *location = NULL;
        enum lttng_event_rule_status status;
 
        if (!_event_rule) {
@@ -244,12 +276,6 @@ ssize_t lttng_event_rule_userspace_probe_create_from_payload(
        }
 
        uprobe_comm = (typeof(uprobe_comm)) current_buffer_view.data;
-       rule = lttng_event_rule_userspace_probe_create();
-       if (!rule) {
-               ERR("Failed to create event rule uprobe");
-               ret = -1;
-               goto end;
-       }
 
        /* Skip to payload. */
        offset += current_buffer_view.size;
@@ -297,8 +323,12 @@ ssize_t lttng_event_rule_userspace_probe_create_from_payload(
        /* Skip after the location. */
        offset += uprobe_comm->location_len;
 
-       uprobe = container_of(rule, struct lttng_event_rule_userspace_probe, parent);
-       uprobe->location = location;
+       rule = lttng_event_rule_userspace_probe_create(location);
+       if (!rule) {
+               ERR("Failed to create event rule uprobe.");
+               ret = -1;
+               goto end;
+       }
 
        status = lttng_event_rule_userspace_probe_set_event_name(rule, name);
        if (status != LTTNG_EVENT_RULE_STATUS_OK) {
@@ -315,40 +345,11 @@ ssize_t lttng_event_rule_userspace_probe_create_from_payload(
        rule = NULL;
        ret = offset;
 end:
+       lttng_userspace_probe_location_destroy(location);
        lttng_event_rule_destroy(rule);
        return ret;
 }
 
-enum lttng_event_rule_status lttng_event_rule_userspace_probe_set_location(
-               struct lttng_event_rule *rule,
-               const struct lttng_userspace_probe_location *location)
-{
-       struct lttng_userspace_probe_location *location_copy = NULL;
-       struct lttng_event_rule_userspace_probe *uprobe;
-       enum lttng_event_rule_status status = LTTNG_EVENT_RULE_STATUS_OK;
-
-       if (!rule || !IS_UPROBE_EVENT_RULE(rule) || !location) {
-               status = LTTNG_EVENT_RULE_STATUS_INVALID;
-               goto end;
-       }
-
-       uprobe = container_of(rule, struct lttng_event_rule_userspace_probe, parent);
-       location_copy = lttng_userspace_probe_location_copy(location);
-       if (!location_copy) {
-               status = LTTNG_EVENT_RULE_STATUS_ERROR;
-               goto end;
-       }
-
-       if (uprobe->location) {
-               lttng_userspace_probe_location_destroy(uprobe->location);
-       }
-
-       uprobe->location = location_copy;
-       location_copy = NULL;
-end:
-       lttng_userspace_probe_location_destroy(location_copy);
-       return status;
-}
 
 enum lttng_event_rule_status lttng_event_rule_userspace_probe_get_location(
                const struct lttng_event_rule *rule,
index 5f75334538504d43abd8741e548602792fb766a1..68a76f922a08ded50d602ca606a235300c76c9b5 100644 (file)
@@ -1973,14 +1973,9 @@ static void test_uprobe_event_rule_notification(
                        lttng_session_daemon_notification_endpoint);
        ok(notification_channel, "Notification channel object creation");
 
-       event_rule = lttng_event_rule_userspace_probe_create();
+       event_rule = lttng_event_rule_userspace_probe_create(probe_location);
        ok(event_rule, "kprobe event rule object creation");
 
-       event_rule_status = lttng_event_rule_userspace_probe_set_location(
-                       event_rule, probe_location);
-       ok(event_rule_status == LTTNG_EVENT_RULE_STATUS_OK,
-                       "Setting uprobe event rule location");
-
        event_rule_status = lttng_event_rule_userspace_probe_set_event_name(
                        event_rule, trigger_name);
        ok(event_rule_status == LTTNG_EVENT_RULE_STATUS_OK,
@@ -2628,7 +2623,7 @@ int main(int argc, const char *argv[])
        {
                const char *testapp_path, *test_symbol_name;
 
-               plan_tests(13);
+               plan_tests(12);
 
                if (argc < 7) {
                        fail("Missing parameter for tests to run %d", argc);
index b92a10aac0b6e1a23814b742b2f8ca3490f11c7e..72c37709faab7d5346e5fe6221ea2a974b231f7b 100644 (file)
@@ -37,7 +37,7 @@ int lttng_opt_quiet = 1;
 int lttng_opt_verbose;
 int lttng_opt_mi;
 
-#define NUM_TESTS 185
+#define NUM_TESTS 184
 
 struct tracepoint_test {
        enum lttng_domain_type type;
@@ -261,13 +261,9 @@ static void test_event_rule_userspace_probe(void)
 
        lttng_payload_init(&payload);
 
-       uprobe = lttng_event_rule_userspace_probe_create();
+       uprobe = lttng_event_rule_userspace_probe_create(probe_location);
        ok(uprobe, "uprobe event rule object creation.");
 
-       status = lttng_event_rule_userspace_probe_set_location(uprobe, probe_location);
-       ok(status == LTTNG_EVENT_RULE_STATUS_OK,
-                       "Setting uprobe event rule location.");
-
        status = lttng_event_rule_userspace_probe_get_location(
                        uprobe, &probe_location_tmp);
        ok(status == LTTNG_EVENT_RULE_STATUS_OK,
This page took 0.032567 seconds and 5 git commands to generate.