/*
- * Copyright (C) 2011 - Julien Desfossez <julien.desfossez@polymtl.ca>
- * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- * 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ * Copyright (C) 2011 Julien Desfossez <julien.desfossez@polymtl.ca>
+ * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ * Copyright (C) 2016 Jérémie Galarneau <jeremie.galarneau@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.
*/
+#include "lttng/tracker.h"
#define _LGPL_SOURCE
#define __USE_LINUX_IOCTL_DEFS
#include <sys/ioctl.h>
#include <string.h>
#include <common/align.h>
+#include <common/macros.h>
#include <errno.h>
#include <stdarg.h>
#include <assert.h>
+#include <common/time.h>
#include "kernel-ctl.h"
#include "kernel-ioctl.h"
/* open the metadata global channel */
int kernctl_open_metadata(int fd, struct lttng_channel_attr *chops)
{
- struct lttng_kernel_old_channel old_channel;
struct lttng_kernel_channel channel;
if (lttng_kernel_use_old_abi) {
+ struct lttng_kernel_old_channel old_channel;
+
+ memset(&old_channel, 0, sizeof(old_channel));
old_channel.overwrite = chops->overwrite;
old_channel.subbuf_size = chops->subbuf_size;
old_channel.num_subbuf = chops->num_subbuf;
&old_channel);
}
+ memset(&channel, 0, sizeof(channel));
channel.overwrite = chops->overwrite;
channel.subbuf_size = chops->subbuf_size;
channel.num_subbuf = chops->num_subbuf;
return LTTNG_IOCTL_NO_CHECK(fd, LTTNG_KERNEL_SESSION_LIST_TRACKER_PIDS);
}
+static enum lttng_kernel_tracker_type get_kernel_tracker_type(
+ enum lttng_process_attr process_attr)
+{
+ switch (process_attr) {
+ case LTTNG_PROCESS_ATTR_PROCESS_ID:
+ return LTTNG_KERNEL_TRACKER_PID;
+ case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID:
+ return LTTNG_KERNEL_TRACKER_VPID;
+ case LTTNG_PROCESS_ATTR_USER_ID:
+ return LTTNG_KERNEL_TRACKER_UID;
+ case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID:
+ return LTTNG_KERNEL_TRACKER_VUID;
+ case LTTNG_PROCESS_ATTR_GROUP_ID:
+ return LTTNG_KERNEL_TRACKER_GID;
+ case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID:
+ return LTTNG_KERNEL_TRACKER_VGID;
+ default:
+ return LTTNG_KERNEL_TRACKER_UNKNOWN;
+ }
+}
+
+int kernctl_track_id(int fd, enum lttng_process_attr process_attr, int id)
+{
+ struct lttng_kernel_tracker_args args;
+
+ args.id = id;
+ args.type = get_kernel_tracker_type(process_attr);
+ if (args.type == LTTNG_KERNEL_TRACKER_UNKNOWN) {
+ errno = EINVAL;
+ return -1;
+ }
+ return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_SESSION_TRACK_ID, &args);
+}
+
+int kernctl_untrack_id(int fd, enum lttng_process_attr process_attr, int id)
+{
+ struct lttng_kernel_tracker_args args;
+
+ args.id = id;
+ args.type = get_kernel_tracker_type(process_attr);
+ if (args.type == LTTNG_KERNEL_TRACKER_UNKNOWN) {
+ errno = EINVAL;
+ return -1;
+ }
+ return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_SESSION_UNTRACK_ID, &args);
+}
+
+int kernctl_list_tracker_ids(int fd, enum lttng_process_attr process_attr)
+{
+ struct lttng_kernel_tracker_args args;
+
+ args.id = -1;
+ args.type = get_kernel_tracker_type(process_attr);
+ if (args.type == LTTNG_KERNEL_TRACKER_UNKNOWN) {
+ errno = EINVAL;
+ return -1;
+ }
+ return LTTNG_IOCTL_NO_CHECK(
+ fd, LTTNG_KERNEL_SESSION_LIST_TRACKER_IDS, &args);
+}
+
int kernctl_session_regenerate_metadata(int fd)
{
return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_SESSION_METADATA_REGEN);
}
+int kernctl_session_regenerate_statedump(int fd)
+{
+ return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_SESSION_STATEDUMP);
+}
+
+int kernctl_session_set_name(int fd, const char *name)
+{
+ int ret;
+ struct lttng_kernel_session_name session_name;
+
+ ret = lttng_strncpy(session_name.name, name, sizeof(session_name.name));
+ if (ret) {
+ goto end;
+ }
+
+ ret = LTTNG_IOCTL_CHECK(
+ fd, LTTNG_KERNEL_SESSION_SET_NAME, &session_name);
+end:
+ return ret;
+}
+
+int kernctl_session_set_creation_time(int fd, time_t time)
+{
+ int ret;
+ struct lttng_kernel_session_creation_time creation_time;
+
+ ret = time_to_iso8601_str(time, creation_time.iso8601,
+ sizeof(creation_time.iso8601));
+ if (ret) {
+ goto end;
+ }
+
+ ret = LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_SESSION_SET_CREATION_TIME,
+ &creation_time);
+end:
+ return ret;
+}
+
int kernctl_create_stream(int fd)
{
return compat_ioctl_no_arg(fd, LTTNG_KERNEL_OLD_STREAM,
if (lttng_kernel_use_old_abi) {
struct lttng_kernel_old_event old_event;
+ memset(&old_event, 0, sizeof(old_event));
memcpy(old_event.name, ev->name, sizeof(old_event.name));
old_event.instrumentation = ev->instrumentation;
switch (ev->instrumentation) {
if (lttng_kernel_use_old_abi) {
struct lttng_kernel_old_context old_ctx;
+ memset(&old_ctx, 0, sizeof(old_ctx));
old_ctx.ctx = ctx->ctx;
/* only type that uses the union */
if (ctx->ctx == LTTNG_KERNEL_CONTEXT_PERF_CPU_COUNTER) {
return ret;
}
+int kernctl_add_callsite(int fd, struct lttng_kernel_event_callsite *callsite)
+{
+ return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ADD_CALLSITE, callsite);
+}
+
int kernctl_tracepoint_list(int fd)
{
return compat_ioctl_no_arg(fd, LTTNG_KERNEL_OLD_TRACEPOINT_LIST,
LTTNG_KERNEL_WAIT_QUIESCENT);
}
-int kernctl_calibrate(int fd, struct lttng_kernel_calibrate *calibrate)
+int kernctl_buffer_flush(int fd)
{
- int ret;
-
- if (lttng_kernel_use_old_abi == -1) {
- ret = LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_CALIBRATE, calibrate);
- if (!ret) {
- lttng_kernel_use_old_abi = 0;
- goto end;
- }
- lttng_kernel_use_old_abi = 1;
- }
- if (lttng_kernel_use_old_abi) {
- struct lttng_kernel_old_calibrate old_calibrate;
-
- old_calibrate.type = calibrate->type;
- ret = LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_OLD_CALIBRATE,
- &old_calibrate);
- if (ret) {
- goto end;
- }
- calibrate->type = old_calibrate.type;
- } else {
- ret = LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_CALIBRATE, calibrate);
- }
-
-end:
- return ret;
+ return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_FLUSH);
}
+int kernctl_buffer_flush_empty(int fd)
+{
+ return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_FLUSH_EMPTY);
+}
-int kernctl_buffer_flush(int fd)
+int kernctl_buffer_clear(int fd)
{
- return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_FLUSH);
+ return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_CLEAR);
}
/* returns the version of the metadata. */
return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_GET_METADATA_VERSION, version);
}
+int kernctl_metadata_cache_dump(int fd)
+{
+ return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_METADATA_CACHE_DUMP);
+}
/* Buffer operations */
return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_SNAPSHOT);
}
+/*
+ * Get a snapshot of the current ring buffer producer and consumer positions,
+ * regardless of whether or not the two positions are contained within the
+ * same sub-buffer.
+ */
+int kernctl_snapshot_sample_positions(int fd)
+{
+ return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_SNAPSHOT_SAMPLE_POSITIONS);
+}
+
/* Get the consumer position (iteration start) */
int kernctl_snapshot_get_consumed(int fd, unsigned long *pos)
{