kernel: event notifier: kernel-ctl interface
[lttng-tools.git] / src / common / kernel-ctl / kernel-ctl.c
index 5f25adf02dc269debabcbdad5d04729ec0d46eb3..f7b92f045498c870de9181c1e754228353ea033d 100644 (file)
@@ -1,29 +1,20 @@
 /*
- * 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 <common/compat/errno.h>
 #include <stdarg.h>
 #include <assert.h>
 #include <common/time.h>
@@ -230,6 +221,67 @@ int kernctl_list_tracker_pids(int fd)
        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);
@@ -366,6 +418,25 @@ int kernctl_stop_session(int fd)
                        LTTNG_KERNEL_SESSION_STOP);
 }
 
+int kernctl_create_event_notifier_group(int fd)
+{
+       return LTTNG_IOCTL_NO_CHECK(fd,
+                       LTTNG_KERNEL_EVENT_NOTIFIER_GROUP_CREATE);
+}
+
+int kernctl_create_event_notifier_group_notification_fd(int group_fd)
+{
+       return LTTNG_IOCTL_NO_CHECK(group_fd,
+                       LTTNG_KERNEL_EVENT_NOTIFIER_GROUP_NOTIFICATION_FD);
+}
+
+int kernctl_create_event_notifier(int group_fd,
+               const struct lttng_kernel_event_notifier *event_notifier)
+{
+       return LTTNG_IOCTL_NO_CHECK(group_fd,
+                       LTTNG_KERNEL_EVENT_NOTIFIER_CREATE, event_notifier);
+}
+
 int kernctl_filter(int fd, struct lttng_filter_bytecode *filter)
 {
        struct lttng_kernel_filter_bytecode *kb;
@@ -458,6 +529,13 @@ int kernctl_buffer_clear(int fd)
        return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_CLEAR);
 }
 
+int kernctl_get_next_subbuf_metadata_check(int fd, bool *consistent)
+{
+       return LTTNG_IOCTL_NO_CHECK(fd,
+                       RING_RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK,
+                       consistent);
+}
+
 /* returns the version of the metadata. */
 int kernctl_get_metadata_version(int fd, uint64_t *version)
 {
This page took 0.024574 seconds and 4 git commands to generate.