Fix: lttng-load: support legacy PID tracker specification
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 7 Apr 2020 04:46:39 +0000 (00:46 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 7 Apr 2020 14:25:09 +0000 (10:25 -0400)
The 2.12 release changes the way tracked process attributes are
expressed in the MI and save/restore formats. While the MI schema was
bumped to 4.0, the save/restore schema only undergoes a minor bump to
accomodate existing users.

The original commit introducing this change justified the breaking
change as saved PIDs being fairly unlikely. However, even the
'INCLUDE_ALL' policy will specify a 'trackers' node, which no longer
existed and made all existing configurations incompatible.

A legacy load path is introduced to support the former PID tracker
serialization format and preserve the compatibility with existing
configurations.

Configurations generated by the 2.11 releases are included to test
this new legacy path.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ied6532c42cb2d1a5c9e39785cc4e47aaf89b8288

src/common/config/session-config.c
src/common/config/session.xsd
tests/regression/tools/save-load/Makefile.am
tests/regression/tools/save-load/test_load
tests/regression/tools/save-load/tracker_legacy_all.lttng [new file with mode: 0644]
tests/regression/tools/save-load/tracker_legacy_none.lttng [new file with mode: 0644]
tests/regression/tools/save-load/tracker_legacy_selective.lttng [new file with mode: 0644]

index c7f471a1c2162c3c40d9d8a35ce1d0d348a5a0f0..a8ea68eda42fdb92fc0177d02a6c239d6d281bd4 100644 (file)
@@ -154,6 +154,13 @@ LTTNG_HIDDEN const char * const config_element_process_attr_gid_value = "gid";
 LTTNG_HIDDEN const char * const config_element_process_attr_vgid_value = "vgid";
 LTTNG_HIDDEN const char * const config_element_process_attr_tracker_type = "process_attr_tracker_type";
 
+/* Used for support of legacy tracker serialization (< 2.12). */
+LTTNG_HIDDEN const char * const config_element_trackers_legacy = "trackers";
+LTTNG_HIDDEN const char * const config_element_pid_tracker_legacy = "pid_tracker";
+LTTNG_HIDDEN const char * const config_element_tracker_targets_legacy = "targets";
+LTTNG_HIDDEN const char * const config_element_tracker_pid_target_legacy = "pid_target";
+LTTNG_HIDDEN const char * const config_element_tracker_pid_legacy = "pid";
+
 LTTNG_HIDDEN const char * const config_element_rotation_schedules = "rotation_schedules";
 LTTNG_HIDDEN const char * const config_element_rotation_schedule_periodic = "periodic";
 LTTNG_HIDDEN const char * const config_element_rotation_schedule_periodic_time_us = "time_us";
@@ -2725,12 +2732,143 @@ static int get_tracker_elements(enum lttng_process_attr process_attr,
        return ret;
 }
 
+static int process_legacy_pid_tracker_node(
+               xmlNodePtr trackers_node, struct lttng_handle *handle)
+{
+       int ret = 0, child_count;
+       xmlNodePtr targets_node = NULL;
+       xmlNodePtr node;
+       const char *element_id_tracker;
+       const char *element_target_id;
+       const char *element_id;
+       const char *element_id_alias;
+       const char *element_name;
+       enum lttng_error_code tracker_handle_ret_code;
+       struct lttng_process_attr_tracker_handle *tracker_handle = NULL;
+       enum lttng_process_attr_tracker_handle_status status;
+       const enum lttng_process_attr process_attr =
+                       handle->domain.type == LTTNG_DOMAIN_UST ?
+                                       LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID :
+                                       LTTNG_PROCESS_ATTR_PROCESS_ID;
+
+       assert(handle);
+
+       tracker_handle_ret_code = lttng_session_get_tracker_handle(
+                       handle->session_name, handle->domain.type,
+                       process_attr,
+                       &tracker_handle);
+       if (tracker_handle_ret_code != LTTNG_OK) {
+               ret = LTTNG_ERR_INVALID;
+               goto end;
+       }
+
+       ret = get_tracker_elements(process_attr, &element_id_tracker,
+                       &element_target_id, &element_id, &element_id_alias,
+                       &element_name);
+       if (ret) {
+               goto end;
+       }
+
+       /* Get the targets node */
+       for (node = xmlFirstElementChild(trackers_node); node;
+                       node = xmlNextElementSibling(node)) {
+               if (!strcmp((const char *) node->name,
+                               config_element_tracker_targets_legacy)) {
+                       targets_node = node;
+                       break;
+               }
+       }       
+
+       if (!targets_node) {
+               ret = LTTNG_ERR_INVALID;
+               goto end;
+       }
+
+       /* Go through all id target node */
+       child_count = xmlChildElementCount(targets_node);
+       status = lttng_process_attr_tracker_handle_set_tracking_policy(
+                       tracker_handle,
+                       child_count == 0 ? LTTNG_TRACKING_POLICY_EXCLUDE_ALL :
+                                          LTTNG_TRACKING_POLICY_INCLUDE_SET);
+       if (status != LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK) {
+               ret = LTTNG_ERR_UNK;
+               goto end;
+       }
+
+       /* Add all tracked values. */
+       for (node = xmlFirstElementChild(targets_node); node;
+                       node = xmlNextElementSibling(node)) {
+               xmlNodePtr pid_target_node = node;
+
+               /* get pid_target node and track it */
+               for (node = xmlFirstElementChild(pid_target_node); node;
+                               node = xmlNextElementSibling(node)) {
+                       if (!strcmp((const char *) node->name,
+                                           config_element_tracker_pid_legacy)) {
+                               int64_t id;
+                               xmlChar *content = xmlNodeGetContent(node);
+
+                               if (!content) {
+                                       ret = LTTNG_ERR_LOAD_INVALID_CONFIG;
+                                       goto end;
+                               }
+
+                               ret = parse_int(content, &id);
+                               free(content);
+                               if (ret) {
+                                       ret = LTTNG_ERR_LOAD_INVALID_CONFIG;
+                                       goto end;
+                               }
+
+                               switch (process_attr) {
+                               case LTTNG_PROCESS_ATTR_PROCESS_ID:
+                                       status = lttng_process_attr_process_id_tracker_handle_add_pid(
+                                                       tracker_handle,
+                                                       (pid_t) id);
+                                       break;
+                               case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID:
+                                       status = lttng_process_attr_virtual_process_id_tracker_handle_add_pid(
+                                                       tracker_handle,
+                                                       (pid_t) id);
+                                       break;
+                               default:
+                                       ret = LTTNG_ERR_INVALID;
+                                       goto end;
+                               }
+                       }
+                       switch (status) {
+                       case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_OK:
+                               continue;
+                       case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_INVALID:
+                               ret = LTTNG_ERR_INVALID;
+                               break;
+                       case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_EXISTS:
+                               ret = LTTNG_ERR_PROCESS_ATTR_EXISTS;
+                               break;
+                       case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_MISSING:
+                               ret = LTTNG_ERR_PROCESS_ATTR_MISSING;
+                               break;
+                       case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_ERROR:
+                       case LTTNG_PROCESS_ATTR_TRACKER_HANDLE_STATUS_COMMUNICATION_ERROR:
+                       default:
+                               ret = LTTNG_ERR_UNK;
+                               goto end;
+                       }
+               }
+               node = pid_target_node;
+       }
+
+end:
+       lttng_process_attr_tracker_handle_destroy(tracker_handle);
+       return ret;
+ }
+
 static int process_id_tracker_node(xmlNodePtr id_tracker_node,
                struct lttng_handle *handle,
                enum lttng_process_attr process_attr)
 {
        int ret = 0, child_count;
-       xmlNodePtr targets_node = NULL;
+       xmlNodePtr values_node = NULL;
        xmlNodePtr node;
        const char *element_id_tracker;
        const char *element_target_id;
@@ -2759,23 +2897,23 @@ static int process_id_tracker_node(xmlNodePtr id_tracker_node,
                goto end;
        }
 
-       /* get the targets node */
+       /* get the values node */
        for (node = xmlFirstElementChild(id_tracker_node); node;
                        node = xmlNextElementSibling(node)) {
                if (!strcmp((const char *) node->name,
                                config_element_process_attr_values)) {
-                       targets_node = node;
+                       values_node = node;
                        break;
                }
        }
 
-       if (!targets_node) {
+       if (!values_node) {
                ret = LTTNG_ERR_INVALID;
                goto end;
        }
 
        /* Go through all id target node */
-       child_count = xmlChildElementCount(targets_node);
+       child_count = xmlChildElementCount(values_node);
        status = lttng_process_attr_tracker_handle_set_tracking_policy(
                        tracker_handle,
                        child_count == 0 ? LTTNG_TRACKING_POLICY_EXCLUDE_ALL :
@@ -2786,7 +2924,7 @@ static int process_id_tracker_node(xmlNodePtr id_tracker_node,
        }
 
        /* Add all tracked values. */
-       for (node = xmlFirstElementChild(targets_node); node;
+       for (node = xmlFirstElementChild(values_node); node;
                        node = xmlNextElementSibling(node)) {
                xmlNodePtr id_target_node = node;
 
@@ -3027,7 +3165,16 @@ int process_domain_node(xmlNodePtr domain_node, const char *session_name)
        for (node = xmlFirstElementChild(domain_node); node;
                        node = xmlNextElementSibling(node)) {
                if (!strcmp((const char *) node->name,
-                               config_element_process_attr_trackers)) {
+                                   config_element_process_attr_trackers) ||
+                               !strcmp((const char *) node->name,
+                                               config_element_trackers_legacy)) {
+                       if (trackers_node) {
+                               ERR("Only one instance of `%s` or `%s` is allowed in a session configuration",
+                                               config_element_process_attr_trackers,
+                                               config_element_trackers_legacy);
+                               ret = -1;
+                               goto end;
+                       }
                        trackers_node = node;
                        break;
                }
@@ -3093,6 +3240,13 @@ int process_domain_node(xmlNodePtr domain_node, const char *session_name)
                                goto end;
                        }
                }
+               if (!strcmp((const char *) node->name,
+                                   config_element_pid_tracker_legacy)) {
+                       ret = process_legacy_pid_tracker_node(node, handle);
+                       if (ret) {
+                               goto end;
+                       }
+               }
        }
 
 end:
index 814723b2a39fbdb7f06ecaca9ab05b04cab34b9f..986fb2dda175a8df19f3cec1be20264ab92e4052 100644 (file)
@@ -394,6 +394,35 @@ by its signed 32-bit representation when converted to msec.
        </xs:sequence>
 </xs:complexType>
 
+<xs:complexType name="pid_target_type">
+       <xs:all>
+               <xs:element name="pid" type="xs:integer" />
+       </xs:all>
+</xs:complexType>
+
+<!-- Maps to a list of pid_targets (legacy)-->
+<xs:complexType name="targets_type">
+       <xs:sequence>
+               <xs:choice>
+                       <xs:element name="pid_target" type="pid_target_type" minOccurs="0" maxOccurs="unbounded" />
+               </xs:choice>
+       </xs:sequence>
+</xs:complexType>
+
+<!-- Maps to a pid_tracker (legacy)-->
+<xs:complexType name="pid_tracker_type">
+       <xs:all>
+               <xs:element name="targets" type="targets_type" />
+       </xs:all>
+</xs:complexType>
+
+<!-- Maps to a list of trackers (legacy)-->
+<xs:complexType name="trackers_type">
+       <xs:sequence minOccurs="0" maxOccurs="unbounded">
+               <xs:element name="pid_tracker" type="pid_tracker_type" maxOccurs="1" />
+       </xs:sequence>
+</xs:complexType>
+
 <!-- Maps to struct lttng_domain, contains channels and pid_process_attr_tracker -->
 <xs:complexType name="domain_type">
        <xs:all>
@@ -401,6 +430,8 @@ by its signed 32-bit representation when converted to msec.
                <xs:element name="buffer_type" type="domain_buffer_type"/>
                <xs:element name="channels" type="channel_list_type" minOccurs="0"/>
                <xs:element name="process_attr_trackers" type="process_attr_tracker_type" minOccurs="0"/>
+               <!-- Support of legacy tracker specification -->
+               <xs:element name="trackers" type="trackers_type" minOccurs="0"/>
        </xs:all>
 </xs:complexType>
 
index f833661f3da02ae730d7441ba0a269e8fcced612..3361744e9c85a878a7d34d351471267aeb3ea61c 100644 (file)
@@ -2,7 +2,8 @@
 
 noinst_SCRIPTS = test_save test_load test_autoload
 EXTRA_DIST = $(noinst_SCRIPTS) load-42.lttng load-42-complex.lttng \
-       load-42-trackers.lttng
+       load-42-trackers.lttng tracker_legacy_none.lttng \
+       tracker_legacy_all.lttng tracker_legacy_selective.lttng
 
 SUBDIRS = configuration
 
index db54a177a795fa41fd406c1512d26292ffe9a359..4f18dec2d8a052342dd3e45619bac2178b0df84f 100755 (executable)
@@ -16,7 +16,7 @@ EVENT_NAME="tp:tptest"
 
 DIR=$(readlink -f $TESTDIR)
 
-NUM_TESTS=72
+NUM_TESTS=75
 
 source $TESTDIR/utils/utils.sh
 
@@ -101,6 +101,9 @@ function test_all_load()
        destroy_lttng_session_ok $SESSION_NAME
        destroy_lttng_session_ok "$SESSION_NAME-complex"
        destroy_lttng_session_ok "$SESSION_NAME-trackers"
+       destroy_lttng_session_ok "tracker_legacy_all"
+       destroy_lttng_session_ok "tracker_legacy_none"
+       destroy_lttng_session_ok "tracker_legacy_selective"
 
        stop_lttng_relayd
 }
diff --git a/tests/regression/tools/save-load/tracker_legacy_all.lttng b/tests/regression/tools/save-load/tracker_legacy_all.lttng
new file mode 100644 (file)
index 0000000..5552345
--- /dev/null
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<sessions>
+       <session>
+               <name>tracker_legacy_all</name>
+               <domains>
+                       <domain>
+                               <type>UST</type>
+                               <buffer_type>PER_UID</buffer_type>
+                               <channels>
+                                       <channel>
+                                               <name>channel0</name>
+                                               <enabled>true</enabled>
+                                               <overwrite_mode>DISCARD</overwrite_mode>
+                                               <subbuffer_size>524288</subbuffer_size>
+                                               <subbuffer_count>4</subbuffer_count>
+                                               <switch_timer_interval>0</switch_timer_interval>
+                                               <read_timer_interval>0</read_timer_interval>
+                                               <output_type>MMAP</output_type>
+                                               <blocking_timeout>0</blocking_timeout>
+                                               <monitor_timer_interval>1000000</monitor_timer_interval>
+                                               <tracefile_size>0</tracefile_size>
+                                               <tracefile_count>0</tracefile_count>
+                                               <live_timer_interval>0</live_timer_interval>
+                                               <events>
+                                                       <event>
+                                                               <name>*</name>
+                                                               <enabled>true</enabled>
+                                                               <type>TRACEPOINT</type>
+                                                               <loglevel_type>ALL</loglevel_type>
+                                                       </event>
+                                               </events>
+                                               <contexts/>
+                                       </channel>
+                               </channels>
+                               <trackers/>
+                       </domain>
+                       <domain>
+                               <type>JUL</type>
+                               <buffer_type>PER_UID</buffer_type>
+                               <channels/>
+                       </domain>
+                       <domain>
+                               <type>LOG4J</type>
+                               <buffer_type>PER_UID</buffer_type>
+                               <channels/>
+                       </domain>
+                       <domain>
+                               <type>PYTHON</type>
+                               <buffer_type>PER_UID</buffer_type>
+                               <channels/>
+                       </domain>
+               </domains>
+               <started>false</started>
+               <output>
+                       <consumer_output>
+                               <enabled>true</enabled>
+                               <destination>
+                                       <path>/tmp/2.11/home/lttng-traces/tracker_legacy_all-20200406-221343</path>
+                               </destination>
+                       </consumer_output>
+               </output>
+       </session>
+</sessions>
diff --git a/tests/regression/tools/save-load/tracker_legacy_none.lttng b/tests/regression/tools/save-load/tracker_legacy_none.lttng
new file mode 100644 (file)
index 0000000..47aeb29
--- /dev/null
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<sessions>
+       <session>
+               <name>tracker_legacy_none</name>
+               <domains>
+                       <domain>
+                               <type>UST</type>
+                               <buffer_type>PER_UID</buffer_type>
+                               <channels>
+                                       <channel>
+                                               <name>channel0</name>
+                                               <enabled>true</enabled>
+                                               <overwrite_mode>DISCARD</overwrite_mode>
+                                               <subbuffer_size>524288</subbuffer_size>
+                                               <subbuffer_count>4</subbuffer_count>
+                                               <switch_timer_interval>0</switch_timer_interval>
+                                               <read_timer_interval>0</read_timer_interval>
+                                               <output_type>MMAP</output_type>
+                                               <blocking_timeout>0</blocking_timeout>
+                                               <monitor_timer_interval>1000000</monitor_timer_interval>
+                                               <tracefile_size>0</tracefile_size>
+                                               <tracefile_count>0</tracefile_count>
+                                               <live_timer_interval>0</live_timer_interval>
+                                               <events>
+                                                       <event>
+                                                               <name>*</name>
+                                                               <enabled>true</enabled>
+                                                               <type>TRACEPOINT</type>
+                                                               <loglevel_type>ALL</loglevel_type>
+                                                       </event>
+                                               </events>
+                                               <contexts/>
+                                       </channel>
+                               </channels>
+                               <trackers>
+                                       <pid_tracker>
+                                               <targets/>
+                                       </pid_tracker>
+                               </trackers>
+                       </domain>
+                       <domain>
+                               <type>JUL</type>
+                               <buffer_type>PER_UID</buffer_type>
+                               <channels/>
+                       </domain>
+                       <domain>
+                               <type>LOG4J</type>
+                               <buffer_type>PER_UID</buffer_type>
+                               <channels/>
+                       </domain>
+                       <domain>
+                               <type>PYTHON</type>
+                               <buffer_type>PER_UID</buffer_type>
+                               <channels/>
+                       </domain>
+               </domains>
+               <started>false</started>
+               <output>
+                       <consumer_output>
+                               <enabled>true</enabled>
+                               <destination>
+                                       <path>/tmp/2.11/home/lttng-traces/tracker_legacy_none-20200406-221335</path>
+                               </destination>
+                       </consumer_output>
+               </output>
+       </session>
+</sessions>
diff --git a/tests/regression/tools/save-load/tracker_legacy_selective.lttng b/tests/regression/tools/save-load/tracker_legacy_selective.lttng
new file mode 100644 (file)
index 0000000..11c0169
--- /dev/null
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<sessions>
+       <session>
+               <name>tracker_legacy_selective</name>
+               <domains>
+                       <domain>
+                               <type>UST</type>
+                               <buffer_type>PER_UID</buffer_type>
+                               <channels>
+                                       <channel>
+                                               <name>channel0</name>
+                                               <enabled>true</enabled>
+                                               <overwrite_mode>DISCARD</overwrite_mode>
+                                               <subbuffer_size>524288</subbuffer_size>
+                                               <subbuffer_count>4</subbuffer_count>
+                                               <switch_timer_interval>0</switch_timer_interval>
+                                               <read_timer_interval>0</read_timer_interval>
+                                               <output_type>MMAP</output_type>
+                                               <blocking_timeout>0</blocking_timeout>
+                                               <monitor_timer_interval>1000000</monitor_timer_interval>
+                                               <tracefile_size>0</tracefile_size>
+                                               <tracefile_count>0</tracefile_count>
+                                               <live_timer_interval>0</live_timer_interval>
+                                               <events>
+                                                       <event>
+                                                               <name>*</name>
+                                                               <enabled>true</enabled>
+                                                               <type>TRACEPOINT</type>
+                                                               <loglevel_type>ALL</loglevel_type>
+                                                       </event>
+                                               </events>
+                                               <contexts/>
+                                       </channel>
+                               </channels>
+                               <trackers>
+                                       <pid_tracker>
+                                               <targets>
+                                                       <pid_target>
+                                                               <pid>42</pid>
+                                                       </pid_target>
+                                                       <pid_target>
+                                                               <pid>1337</pid>
+                                                       </pid_target>
+                                               </targets>
+                                       </pid_tracker>
+                               </trackers>
+                       </domain>
+                       <domain>
+                               <type>JUL</type>
+                               <buffer_type>PER_UID</buffer_type>
+                               <channels/>
+                       </domain>
+                       <domain>
+                               <type>LOG4J</type>
+                               <buffer_type>PER_UID</buffer_type>
+                               <channels/>
+                       </domain>
+                       <domain>
+                               <type>PYTHON</type>
+                               <buffer_type>PER_UID</buffer_type>
+                               <channels/>
+                       </domain>
+               </domains>
+               <started>false</started>
+               <output>
+                       <consumer_output>
+                               <enabled>true</enabled>
+                               <destination>
+                                       <path>/tmp/2.11/home/lttng-traces/tracker_legacy_selective-20200406-221328</path>
+                               </destination>
+                       </consumer_output>
+               </output>
+       </session>
+</sessions>
This page took 0.034234 seconds and 4 git commands to generate.