Tests: add unix socket wrapper unit tests
[lttng-tools.git] / src / common / sessiond-comm / sessiond-comm.h
index 5b70a4ac5baadc40d6ea64928e3d88b58be984b5..d054a8bd05a1f49fef96a1fe8051586a6183bd02 100644 (file)
@@ -1,20 +1,10 @@
 /*
- * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
- *                      Julien Desfossez <julien.desfossez@polymtl.ca>
- *                      Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
+ * Copyright (C) 2011 Julien Desfossez <julien.desfossez@polymtl.ca>
+ * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License, version 2 only,
- * as published by the Free Software Foundation.
+ * SPDX-License-Identifier: GPL-2.0-only
  *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 /*
@@ -35,7 +25,9 @@
 #include <common/compat/socket.h>
 #include <common/uri.h>
 #include <common/defaults.h>
-#include <common/compat/uuid.h>
+#include <common/uuid.h>
+#include <common/macros.h>
+#include <common/optional.h>
 
 #include <arpa/inet.h>
 #include <netinet/in.h>
 #define LTTNG_SESSIOND_COMM_MAX_LISTEN 64
 
 /* Maximum number of FDs that can be sent over a Unix socket */
-#define LTTCOMM_MAX_SEND_FDS           4
+#if defined(__linux__)
+/* Based on the kernel's SCM_MAX_FD which is 253 since 2.6.38 (255 before) */
+#define LTTCOMM_MAX_SEND_FDS           253
+#else
+#define LTTCOMM_MAX_SEND_FDS           16
+#endif
 
 /*
  * Get the error code index from 0 since LTTCOMM_OK start at 1000
 
 enum lttcomm_sessiond_command {
        /* Tracer command */
-       LTTNG_ADD_CONTEXT                     = 0,
+       LTTNG_ADD_CONTEXT                               = 0,
        /* LTTNG_CALIBRATE used to be here */
-       LTTNG_DISABLE_CHANNEL                 = 2,
-       LTTNG_DISABLE_EVENT                   = 3,
-       LTTNG_LIST_SYSCALLS                   = 4,
-       LTTNG_ENABLE_CHANNEL                  = 5,
-       LTTNG_ENABLE_EVENT                    = 6,
+       LTTNG_DISABLE_CHANNEL                           = 2,
+       LTTNG_DISABLE_EVENT                             = 3,
+       LTTNG_LIST_SYSCALLS                             = 4,
+       LTTNG_ENABLE_CHANNEL                            = 5,
+       LTTNG_ENABLE_EVENT                              = 6,
        /* 7 */
        /* Session daemon command */
-       LTTNG_CREATE_SESSION                  = 8,
-       LTTNG_DESTROY_SESSION                 = 9,
-       LTTNG_LIST_CHANNELS                   = 10,
-       LTTNG_LIST_DOMAINS                    = 11,
-       LTTNG_LIST_EVENTS                     = 12,
-       LTTNG_LIST_SESSIONS                   = 13,
-       LTTNG_LIST_TRACEPOINTS                = 14,
-       LTTNG_REGISTER_CONSUMER               = 15,
-       LTTNG_START_TRACE                     = 16,
-       LTTNG_STOP_TRACE                      = 17,
-       LTTNG_LIST_TRACEPOINT_FIELDS          = 18,
+       /* 8 */
+       LTTNG_DESTROY_SESSION                           = 9,
+       LTTNG_LIST_CHANNELS                             = 10,
+       LTTNG_LIST_DOMAINS                              = 11,
+       LTTNG_LIST_EVENTS                               = 12,
+       LTTNG_LIST_SESSIONS                             = 13,
+       LTTNG_LIST_TRACEPOINTS                          = 14,
+       LTTNG_REGISTER_CONSUMER                         = 15,
+       LTTNG_START_TRACE                               = 16,
+       LTTNG_STOP_TRACE                                = 17,
+       LTTNG_LIST_TRACEPOINT_FIELDS                    = 18,
 
        /* Consumer */
-       LTTNG_DISABLE_CONSUMER                = 19,
-       LTTNG_ENABLE_CONSUMER                 = 20,
-       LTTNG_SET_CONSUMER_URI                = 21,
+       LTTNG_DISABLE_CONSUMER                          = 19,
+       LTTNG_ENABLE_CONSUMER                           = 20,
+       LTTNG_SET_CONSUMER_URI                          = 21,
        /* 22 */
        /* 23 */
-       LTTNG_DATA_PENDING                    = 24,
-       LTTNG_SNAPSHOT_ADD_OUTPUT             = 25,
-       LTTNG_SNAPSHOT_DEL_OUTPUT             = 26,
-       LTTNG_SNAPSHOT_LIST_OUTPUT            = 27,
-       LTTNG_SNAPSHOT_RECORD                 = 28,
-       LTTNG_CREATE_SESSION_SNAPSHOT         = 29,
-       LTTNG_CREATE_SESSION_LIVE             = 30,
-       LTTNG_SAVE_SESSION                    = 31,
-       LTTNG_TRACK_PID                       = 32,
-       LTTNG_UNTRACK_PID                     = 33,
-       LTTNG_LIST_TRACKER_PIDS               = 34,
-       LTTNG_SET_SESSION_SHM_PATH            = 40,
-       LTTNG_REGENERATE_METADATA             = 41,
-       LTTNG_REGENERATE_STATEDUMP            = 42,
-       LTTNG_REGISTER_TRIGGER                = 43,
-       LTTNG_UNREGISTER_TRIGGER              = 44,
-       LTTNG_ROTATE_SESSION                  = 45,
-       LTTNG_ROTATION_GET_INFO               = 46,
-       LTTNG_ROTATION_SET_SCHEDULE           = 47,
-       LTTNG_SESSION_LIST_ROTATION_SCHEDULES = 48,
+       LTTNG_DATA_PENDING                              = 24,
+       LTTNG_SNAPSHOT_ADD_OUTPUT                       = 25,
+       LTTNG_SNAPSHOT_DEL_OUTPUT                       = 26,
+       LTTNG_SNAPSHOT_LIST_OUTPUT                      = 27,
+       LTTNG_SNAPSHOT_RECORD                           = 28,
+       /* 29 */
+       /* 30 */
+       LTTNG_SAVE_SESSION                              = 31,
+       LTTNG_PROCESS_ATTR_TRACKER_ADD_INCLUDE_VALUE    = 32,
+       LTTNG_PROCESS_ATTR_TRACKER_REMOVE_INCLUDE_VALUE = 33,
+       LTTNG_PROCESS_ATTR_TRACKER_GET_POLICY           = 34,
+       LTTNG_PROCESS_ATTR_TRACKER_SET_POLICY           = 35,
+       LTTNG_PROCESS_ATTR_TRACKER_GET_INCLUSION_SET     = 36,
+       LTTNG_SET_SESSION_SHM_PATH                      = 40,
+       LTTNG_REGENERATE_METADATA                       = 41,
+       LTTNG_REGENERATE_STATEDUMP                      = 42,
+       LTTNG_REGISTER_TRIGGER                          = 43,
+       LTTNG_UNREGISTER_TRIGGER                        = 44,
+       LTTNG_ROTATE_SESSION                            = 45,
+       LTTNG_ROTATION_GET_INFO                         = 46,
+       LTTNG_ROTATION_SET_SCHEDULE                     = 47,
+       LTTNG_SESSION_LIST_ROTATION_SCHEDULES           = 48,
+       LTTNG_CREATE_SESSION_EXT                        = 49,
+       LTTNG_CLEAR_SESSION                             = 50,
 };
 
 enum lttcomm_relayd_command {
@@ -128,14 +129,18 @@ enum lttcomm_relayd_command {
        RELAYD_STREAMS_SENT                 = 16,
        /* Ask the relay to reset the metadata trace file (2.8+) */
        RELAYD_RESET_METADATA               = 17,
-       /* Ask the relay to rotate a stream file (2.11+) */
-       RELAYD_ROTATE_STREAM                = 18,
-       /* Rename a chunk after the rotation is completed (2.11+) */
-       RELAYD_ROTATE_RENAME                = 19,
-       /* Check if a chunk has data pending (2.11+) */
-       RELAYD_ROTATE_PENDING               = 20,
-       /* Create a folder on the relayd FS (2.11+) */
-       RELAYD_MKDIR                        = 21,
+       /* Ask the relay to rotate a set of stream files (2.11+) */
+       RELAYD_ROTATE_STREAMS                = 18,
+       /* Ask the relay to create a trace chunk (2.11+) */
+       RELAYD_CREATE_TRACE_CHUNK           = 19,
+       /* Ask the relay to close a trace chunk (2.11+) */
+       RELAYD_CLOSE_TRACE_CHUNK            = 20,
+       /* Ask the relay whether a trace chunk exists (2.11+) */
+       RELAYD_TRACE_CHUNK_EXISTS           = 21,
+       /* Get the current configuration of a relayd peer (2.12+) */
+       RELAYD_GET_CONFIGURATION            = 22,
+
+       /* Feature branch specific commands start at 10000. */
 };
 
 /*
@@ -143,7 +148,13 @@ enum lttcomm_relayd_command {
  */
 enum lttcomm_return_code {
        LTTCOMM_CONSUMERD_SUCCESS            = 0,   /* Everything went fine. */
-       LTTCOMM_CONSUMERD_COMMAND_SOCK_READY = 1,   /* Command socket ready */
+       /*
+        * Some code paths use -1 to express an error, others
+        * negate this consumer return code. Starting codes at
+        * 100 ensures there is no mix-up between this error value
+        * and legitimate status codes.
+        */
+       LTTCOMM_CONSUMERD_COMMAND_SOCK_READY = 100, /* Command socket ready */
        LTTCOMM_CONSUMERD_SUCCESS_RECV_FD,          /* Success on receiving fds */
        LTTCOMM_CONSUMERD_ERROR_RECV_FD,            /* Error on receiving fds */
        LTTCOMM_CONSUMERD_ERROR_RECV_CMD,           /* Error on receiving command */
@@ -165,10 +176,15 @@ enum lttcomm_return_code {
        LTTCOMM_CONSUMERD_CHAN_NOT_FOUND,           /* Channel not found. */
        LTTCOMM_CONSUMERD_ALREADY_SET,              /* Resource already set. */
        LTTCOMM_CONSUMERD_ROTATION_FAIL,            /* Rotation has failed. */
-       LTTCOMM_CONSUMERD_ROTATE_RENAME_FAILED,     /* Rotation rename has failed. */
-       LTTCOMM_CONSUMERD_ROTATION_PENDING_LOCAL_FAILED, /* Rotation pending relay failed. */
-       LTTCOMM_CONSUMERD_ROTATION_PENDING_RELAY_FAILED, /* Rotation pending relay failed. */
-       LTTCOMM_CONSUMERD_MKDIR_FAILED,             /* mkdir has failed. */
+       LTTCOMM_CONSUMERD_SNAPSHOT_FAILED,          /* snapshot has failed. */
+       LTTCOMM_CONSUMERD_CREATE_TRACE_CHUNK_FAILED,/* Trace chunk creation failed. */
+       LTTCOMM_CONSUMERD_CLOSE_TRACE_CHUNK_FAILED, /* Trace chunk creation failed. */
+       LTTCOMM_CONSUMERD_INVALID_PARAMETERS,       /* Invalid parameters. */
+       LTTCOMM_CONSUMERD_TRACE_CHUNK_EXISTS_LOCAL, /* Trace chunk exists on consumer daemon. */
+       LTTCOMM_CONSUMERD_TRACE_CHUNK_EXISTS_REMOTE,/* Trace chunk exists on relay daemon. */
+       LTTCOMM_CONSUMERD_UNKNOWN_TRACE_CHUNK,      /* Unknown trace chunk. */
+       LTTCOMM_CONSUMERD_RELAYD_CLEAR_DISALLOWED,  /* Relayd does not accept clear command. */
+       LTTCOMM_CONSUMERD_UNKNOWN_ERROR,            /* Unknown error. */
 
        /* MUST be last element */
        LTTCOMM_NR,                                             /* Last element */
@@ -249,6 +265,13 @@ struct lttcomm_proto_ops {
                        size_t len, int flags);
 };
 
+struct process_attr_integral_value_comm {
+       union {
+               int64_t _signed;
+               uint64_t _unsigned;
+       } u;
+} LTTNG_PACKED;
+
 /*
  * Data structure received from lttng client to session daemon.
  */
@@ -336,8 +359,35 @@ struct lttcomm_session_msg {
                        char shm_path[PATH_MAX];
                } LTTNG_PACKED set_shm_path;
                struct {
-                       uint32_t pid;
-               } LTTNG_PACKED pid_tracker;
+                       /* enum lttng_process_attr */
+                       int32_t process_attr;
+                       /* enum lttng_process_attr_value_type */
+                       int32_t value_type;
+
+                       struct process_attr_integral_value_comm integral_value;
+                       /*
+                        * For user/group names, a variable length,
+                        * zero-terminated, string of length 'name_len'
+                        * (including the terminator) follows.
+                        *
+                        * integral_value should not be used in those cases.
+                        */
+                       uint32_t name_len;
+               } LTTNG_PACKED process_attr_tracker_add_remove_include_value;
+               struct {
+                       /* enum lttng_process_attr */
+                       int32_t process_attr;
+               } LTTNG_PACKED process_attr_tracker_get_inclusion_set;
+               struct {
+                       /* enum lttng_process_attr */
+                       int32_t process_attr;
+               } LTTNG_PACKED process_attr_tracker_get_tracking_policy;
+               struct {
+                       /* enum lttng_process_attr */
+                       int32_t process_attr;
+                       /* enum lttng_tracking_policy */
+                       int32_t tracking_policy;
+               } LTTNG_PACKED process_attr_tracker_set_tracking_policy;
                struct {
                        uint32_t length;
                } LTTNG_PACKED trigger;
@@ -354,10 +404,22 @@ struct lttcomm_session_msg {
                        uint8_t set;
                        uint64_t value;
                } LTTNG_PACKED rotation_set_schedule;
+               struct {
+                       /*
+                        * Includes the null-terminator.
+                        * Must be an absolute path.
+                        *
+                        * Size bounded by LTTNG_PATH_MAX.
+                        */
+                       uint16_t home_dir_size;
+                       uint64_t session_descriptor_size;
+                       /* An lttng_session_descriptor follows. */
+               } LTTNG_PACKED create_session;
        } u;
 } LTTNG_PACKED;
 
 #define LTTNG_FILTER_MAX_LEN   65536
+#define LTTNG_SESSION_DESCRIPTOR_MAX_LEN       65536
 
 /*
  * Filter bytecode data. The reloc table is located at the end of the
@@ -421,6 +483,21 @@ struct lttcomm_event_extended_header {
        uint32_t userspace_probe_location_len;
 } LTTNG_PACKED;
 
+/*
+ * Command header of the reply to an LTTNG_DESTROY_SESSION command.
+ */
+struct lttcomm_session_destroy_command_header {
+       /* enum lttng_session */
+       int32_t rotation_state;
+};
+
+/*
+ * tracker command header.
+ */
+struct lttcomm_tracker_command_header {
+       uint32_t nb_tracker_id;
+} LTTNG_PACKED;
+
 /*
  * Data structure for the response from sessiond to the lttng client.
  */
@@ -430,6 +507,7 @@ struct lttcomm_lttng_msg {
        uint32_t pid;           /* pid_t */
        uint32_t cmd_header_size;
        uint32_t data_size;
+       uint32_t fd_count;
 } LTTNG_PACKED;
 
 struct lttcomm_lttng_output_id {
@@ -447,9 +525,9 @@ struct lttcomm_consumer_msg {
                struct {
                        uint64_t channel_key;
                        uint64_t session_id;
+                       /* ID of the session's current trace chunk. */
+                       LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED chunk_id;
                        char pathname[PATH_MAX];
-                       uint32_t uid;
-                       uint32_t gid;
                        uint64_t relayd_id;
                        /* nb_init_streams is the number of streams open initially. */
                        uint32_t nb_init_streams;
@@ -463,6 +541,8 @@ struct lttcomm_consumer_msg {
                        uint32_t monitor;
                        /* timer to check the streams usage in live mode (usec). */
                        unsigned int live_timer_interval;
+                       /* is part of a live session */
+                       uint8_t is_live;
                        /* timer to sample a channel's positions (usec). */
                        unsigned int monitor_timer_interval;
                } LTTNG_PACKED channel; /* Only used by Kernel. */
@@ -472,13 +552,6 @@ struct lttcomm_consumer_msg {
                        int32_t cpu;    /* On which CPU this stream is assigned. */
                        /* Tells the consumer if the stream should be or not monitored. */
                        uint32_t no_monitor;
-                       /*
-                        * The archive id that was "current" at the time this
-                        * stream was created. This is used to determine
-                        * whether a rotation request was sent before or after
-                        * the creation of a stream.
-                        */
-                       uint64_t trace_archive_id;
                } LTTNG_PACKED stream;  /* Only used by Kernel. */
                struct {
                        uint64_t net_index;
@@ -503,17 +576,23 @@ struct lttcomm_consumer_msg {
                        uint32_t switch_timer_interval;         /* usec */
                        uint32_t read_timer_interval;           /* usec */
                        unsigned int live_timer_interval;       /* usec */
+                       uint8_t is_live;                        /* is part of a live session */
                        uint32_t monitor_timer_interval;        /* usec */
                        int32_t output;                         /* splice, mmap */
                        int32_t type;                           /* metadata or per_cpu */
                        uint64_t session_id;                    /* Tracing session id */
                        char pathname[PATH_MAX];                /* Channel file path. */
                        char name[LTTNG_SYMBOL_NAME_LEN];       /* Channel name. */
-                       uint32_t uid;                           /* User ID of the session */
-                       uint32_t gid;                           /* Group ID ot the session */
+                       /* Credentials used to open the UST buffer shared mappings. */
+                       struct {
+                               uint32_t uid;
+                               uint32_t gid;
+                       } LTTNG_PACKED buffer_credentials;
                        uint64_t relayd_id;                     /* Relayd id if apply. */
                        uint64_t key;                           /* Unique channel key. */
-                       unsigned char uuid[UUID_LEN];   /* uuid for ust tracer. */
+                       /* ID of the session's current trace chunk. */
+                       LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED chunk_id;
+                       unsigned char uuid[LTTNG_UUID_LEN];     /* uuid for ust tracer. */
                        uint32_t chan_id;                       /* Channel ID on the tracer side. */
                        uint64_t tracefile_size;        /* bytes */
                        uint32_t tracefile_count;       /* number of tracefiles */
@@ -528,13 +607,6 @@ struct lttcomm_consumer_msg {
                         */
                        uint32_t ust_app_uid;
                        int64_t blocking_timeout;
-                       /*
-                        * The archive id that was "current" at the time this
-                        * channel was created. This is used to determine
-                        * whether a rotation request was sent before or after
-                        * the creation of a channel.
-                        */
-                       uint64_t trace_archive_id;
                        char root_shm_path[PATH_MAX];
                        char shm_path[PATH_MAX];
                } LTTNG_PACKED ask_channel;
@@ -570,12 +642,6 @@ struct lttcomm_consumer_msg {
                        uint64_t relayd_id;             /* Relayd id if apply. */
                        uint64_t key;
                        uint64_t nb_packets_per_stream;
-                       /*
-                        * The session's current trace archive id is propagated
-                        * since a snapshot triggers the creation of an
-                        * ephemeral metadata stream.
-                        */
-                       uint64_t trace_archive_id;
                } LTTNG_PACKED snapshot_channel;
                struct {
                        uint64_t channel_key;
@@ -593,20 +659,10 @@ struct lttcomm_consumer_msg {
                        uint64_t session_id;
                } LTTNG_PACKED regenerate_metadata;
                struct {
-                       char pathname[PATH_MAX];
                        uint32_t metadata; /* This is a metadata channel. */
                        uint64_t relayd_id; /* Relayd id if apply. */
                        uint64_t key;
-                       uint64_t new_chunk_id;
                } LTTNG_PACKED rotate_channel;
-               struct {
-                       char old_path[LTTNG_PATH_MAX];
-                       char new_path[LTTNG_PATH_MAX];
-                       uint64_t relayd_id; /* Relayd id if apply. */
-                       uint64_t session_id;
-                       uint32_t uid;
-                       uint32_t gid;
-               } LTTNG_PACKED rotate_rename;
                struct {
                        uint64_t session_id;
                        uint64_t chunk_id;
@@ -617,12 +673,48 @@ struct lttcomm_consumer_msg {
                        uint64_t chunk_id;
                } LTTNG_PACKED check_rotation_pending_relay;
                struct {
-                       char path[LTTNG_PATH_MAX];
-                       uint64_t relayd_id; /* Relayd id if apply. */
+                       /*
+                        * Relayd id, if applicable (remote).
+                        *
+                        * A directory file descriptor referring to the chunk's
+                        * output folder is transmitted if the chunk is local
+                        * (relayd_id unset).
+                        *
+                        * `override_name` is left NULL (all-zeroes) if the
+                        * chunk's name is not overridden.
+                        */
+                       LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED relayd_id;
+                       char override_name[LTTNG_NAME_MAX];
+                       uint64_t session_id;
+                       uint64_t chunk_id;
+                       uint64_t creation_timestamp;
+                       LTTNG_OPTIONAL_COMM(struct {
+                               uint32_t uid;
+                               uint32_t gid;
+                       } LTTNG_PACKED ) LTTNG_PACKED credentials;
+               } LTTNG_PACKED create_trace_chunk;
+               struct {
+                       LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED relayd_id;
                        uint64_t session_id;
-                       uint32_t uid;
-                       uint32_t gid;
-               } LTTNG_PACKED mkdir;
+                       uint64_t chunk_id;
+                       uint64_t close_timestamp;
+                       /* enum lttng_trace_chunk_command_type */
+                       LTTNG_OPTIONAL_COMM(uint32_t) LTTNG_PACKED close_command;
+               } LTTNG_PACKED close_trace_chunk;
+               struct {
+                       LTTNG_OPTIONAL_COMM(uint64_t) LTTNG_PACKED relayd_id;
+                       uint64_t session_id;
+                       uint64_t chunk_id;
+               } LTTNG_PACKED trace_chunk_exists;
+               struct {
+                       lttng_uuid sessiond_uuid;
+               } LTTNG_PACKED init;
+               struct {
+                       uint64_t key;
+               } LTTNG_PACKED clear_channel;
+               struct {
+                       uint64_t key;
+               } LTTNG_PACKED open_channel_packets;
        } u;
 } LTTNG_PACKED;
 
@@ -656,6 +748,12 @@ struct lttcomm_consumer_status_channel {
        unsigned int stream_count;
 } LTTNG_PACKED;
 
+struct lttcomm_consumer_close_trace_chunk_reply {
+       enum lttcomm_return_code ret_code;
+       uint32_t path_length;
+       char path[];
+};
+
 #ifdef HAVE_LIBLTTNG_UST_CTL
 
 #include <lttng/ust-abi.h>
This page took 0.030375 seconds and 5 git commands to generate.