Use new ioctl macros with fixed ioctl direction
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Tue, 27 Apr 2021 18:26:09 +0000 (14:26 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 28 Apr 2021 21:20:25 +0000 (17:20 -0400)
Update the ioctl commands to follow the changes in this commit:
  commit 8c71721f7a868b575b05e24bc3a3dcc967e6d5d6
  Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  Date:   Tue Apr 20 11:05:19 2021 -0400

      Fix: LTTng-modules ABI ioctl wrong direction

This commit uses the new command first, and if -ENOSYS is returned by
the LTTng kernel tracer it falls back to the old command.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I2604ea5902fec3bf574c7a249cb65784685a0ae8

src/common/kernel-ctl/kernel-ctl.c
src/common/kernel-ctl/kernel-ioctl.h

index 877de5f8660bfb0c534a92815818b2296b5e53d5..5373c703943f7710576337bb9995e8cb4321f28b 100644 (file)
@@ -210,12 +210,28 @@ end:
 
 int kernctl_track_pid(int fd, int pid)
 {
-       return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_SESSION_TRACK_PID, pid);
+       int ret = LTTNG_IOCTL_CHECK(
+                       fd, LTTNG_KERNEL_ABI_SESSION_TRACK_PID, pid);
+
+       if (ret == -ENOSYS) {
+               ret = LTTNG_IOCTL_CHECK(fd,
+                               LTTNG_KERNEL_ABI_OLD_SESSION_TRACK_PID, pid);
+       }
+
+       return ret;
 }
 
 int kernctl_untrack_pid(int fd, int pid)
 {
-       return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_SESSION_UNTRACK_PID, pid);
+       int ret = LTTNG_IOCTL_CHECK(
+                       fd, LTTNG_KERNEL_ABI_SESSION_UNTRACK_PID, pid);
+
+       if (ret == -ENOSYS) {
+               ret = LTTNG_IOCTL_CHECK(fd,
+                               LTTNG_KERNEL_ABI_OLD_SESSION_UNTRACK_PID, pid);
+       }
+
+       return ret;
 }
 
 int kernctl_list_tracker_pids(int fd)
@@ -247,6 +263,7 @@ static enum lttng_kernel_abi_tracker_type get_kernel_tracker_type(
 int kernctl_track_id(int fd, enum lttng_process_attr process_attr, int id)
 {
        struct lttng_kernel_abi_tracker_args args;
+       int ret;
 
        args.id = id;
        args.type = get_kernel_tracker_type(process_attr);
@@ -254,12 +271,20 @@ int kernctl_track_id(int fd, enum lttng_process_attr process_attr, int id)
                errno = EINVAL;
                return -1;
        }
-       return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_SESSION_TRACK_ID, &args);
+
+       ret = LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_SESSION_TRACK_ID, &args);
+       if (ret == -ENOSYS) {
+               ret = LTTNG_IOCTL_CHECK(fd,
+                               LTTNG_KERNEL_ABI_OLD_SESSION_TRACK_ID, &args);
+       }
+
+       return ret;
 }
 
 int kernctl_untrack_id(int fd, enum lttng_process_attr process_attr, int id)
 {
        struct lttng_kernel_abi_tracker_args args;
+       int ret;
 
        args.id = id;
        args.type = get_kernel_tracker_type(process_attr);
@@ -267,12 +292,20 @@ int kernctl_untrack_id(int fd, enum lttng_process_attr process_attr, int id)
                errno = EINVAL;
                return -1;
        }
-       return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_SESSION_UNTRACK_ID, &args);
+
+       ret = LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_SESSION_UNTRACK_ID, &args);
+       if (ret == -ENOSYS) {
+               ret = LTTNG_IOCTL_CHECK(fd,
+                               LTTNG_KERNEL_ABI_OLD_SESSION_UNTRACK_ID, &args);
+       }
+
+       return ret;
 }
 
 int kernctl_list_tracker_ids(int fd, enum lttng_process_attr process_attr)
 {
        struct lttng_kernel_abi_tracker_args args;
+       int ret;
 
        args.id = -1;
        args.type = get_kernel_tracker_type(process_attr);
@@ -280,8 +313,16 @@ int kernctl_list_tracker_ids(int fd, enum lttng_process_attr process_attr)
                errno = EINVAL;
                return -1;
        }
-       return LTTNG_IOCTL_NO_CHECK(
+
+       ret = LTTNG_IOCTL_NO_CHECK(
                        fd, LTTNG_KERNEL_ABI_SESSION_LIST_TRACKER_IDS, &args);
+       if (ret == -ENOSYS) {
+               ret = LTTNG_IOCTL_NO_CHECK(fd,
+                               LTTNG_KERNEL_ABI_OLD_SESSION_LIST_TRACKER_IDS,
+                               &args);
+       }
+
+       return ret;
 }
 
 int kernctl_session_regenerate_metadata(int fd)
@@ -306,6 +347,12 @@ int kernctl_session_set_name(int fd, const char *name)
 
        ret = LTTNG_IOCTL_CHECK(
                        fd, LTTNG_KERNEL_ABI_SESSION_SET_NAME, &session_name);
+       if (ret == -ENOSYS) {
+               ret = LTTNG_IOCTL_CHECK(fd,
+                               LTTNG_KERNEL_ABI_OLD_SESSION_SET_NAME,
+                               &session_name);
+       }
+
 end:
        return ret;
 }
@@ -323,6 +370,12 @@ int kernctl_session_set_creation_time(int fd, time_t time)
 
        ret = LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_SESSION_SET_CREATION_TIME,
                        &creation_time);
+       if (ret == -ENOSYS) {
+               ret = LTTNG_IOCTL_CHECK(fd,
+                               LTTNG_KERNEL_ABI_OLD_SESSION_SET_CREATION_TIME,
+                               &creation_time);
+       }
+
 end:
        return ret;
 }
index 6da9676a2fb2cc73b8f2ac2b0930c6cedb954ec7..b9af57a6b353d581cf9afa521ae19e030867b365 100644 (file)
 #define LTTNG_KERNEL_ABI_SESSION_START         _IO(0xF6, 0x56)
 #define LTTNG_KERNEL_ABI_SESSION_STOP          _IO(0xF6, 0x57)
 #define LTTNG_KERNEL_ABI_SESSION_TRACK_PID             \
-       _IOR(0xF6, 0x58, int32_t)
+       _IOW(0xF6, 0x58, int32_t)
 #define LTTNG_KERNEL_ABI_SESSION_UNTRACK_PID   \
-       _IOR(0xF6, 0x59, int32_t)
+       _IOW(0xF6, 0x59, int32_t)
 /*
  * ioctl 0x58 and 0x59 are duplicated here. It works, since _IOR vs _IO
  * are generating two different ioctl numbers, but this was not done on
 /* 0x5A and 0x5B are reserved for a future ABI-breaking cleanup. */
 #define LTTNG_KERNEL_ABI_SESSION_STATEDUMP         _IO(0xF6, 0x5C)
 #define LTTNG_KERNEL_ABI_SESSION_SET_NAME              \
-       _IOR(0xF6, 0x5D, struct lttng_kernel_abi_session_name)
+       _IOW(0xF6, 0x5D, struct lttng_kernel_abi_session_name)
 #define LTTNG_KERNEL_ABI_SESSION_SET_CREATION_TIME             \
-       _IOR(0xF6, 0x5E, struct lttng_kernel_abi_session_creation_time)
+       _IOW(0xF6, 0x5E, struct lttng_kernel_abi_session_creation_time)
 
 /* Channel FD ioctl */
 #define LTTNG_KERNEL_ABI_STREAM                        _IO(0xF6, 0x62)
 
 /* Session FD ioctl (continued) */
 #define LTTNG_KERNEL_ABI_SESSION_LIST_TRACKER_IDS      \
-       _IOR(0xF6, 0xA0, struct lttng_kernel_abi_tracker_args)
+       _IOW(0xF6, 0xA0, struct lttng_kernel_abi_tracker_args)
 #define LTTNG_KERNEL_ABI_SESSION_TRACK_ID              \
-       _IOR(0xF6, 0xA1, struct lttng_kernel_abi_tracker_args)
+       _IOW(0xF6, 0xA1, struct lttng_kernel_abi_tracker_args)
 #define LTTNG_KERNEL_ABI_SESSION_UNTRACK_ID            \
-       _IOR(0xF6, 0xA2, struct lttng_kernel_abi_tracker_args)
+       _IOW(0xF6, 0xA2, struct lttng_kernel_abi_tracker_args)
 
 /* Event notifier group file descriptor ioctl */
 #define LTTNG_KERNEL_ABI_EVENT_NOTIFIER_CREATE                 \
 #define LTTNG_KERNEL_ABI_COUNTER_CLEAR         \
        _IOW(0xF6, 0xC2, struct lttng_kernel_abi_counter_clear)
 
+/*
+  * Those ioctl numbers use the wrong direction, but are kept for ABI backward
+  * compatibility.
+  */
+ #define LTTNG_KERNEL_ABI_OLD_SESSION_SET_NAME        \
+     _IOR(0xF6, 0x5D, struct lttng_kernel_abi_session_name)
+ #define LTTNG_KERNEL_ABI_OLD_SESSION_SET_CREATION_TIME    \
+     _IOR(0xF6, 0x5E, struct lttng_kernel_abi_session_creation_time)
+ #define LTTNG_KERNEL_ABI_OLD_SESSION_TRACK_PID        \
+     _IOW(0xF6, 0x58, int32_t)
+ #define LTTNG_KERNEL_ABI_OLD_SESSION_UNTRACK_PID    \
+     _IOW(0xF6, 0x59, int32_t)
+ #define LTTNG_KERNEL_ABI_OLD_SESSION_LIST_TRACKER_IDS    \
+     _IOR(0xF6, 0xA0, struct lttng_kernel_abi_tracker_args)
+ #define LTTNG_KERNEL_ABI_OLD_SESSION_TRACK_ID        \
+     _IOR(0xF6, 0xA1, struct lttng_kernel_abi_tracker_args)
+ #define LTTNG_KERNEL_ABI_OLD_SESSION_UNTRACK_ID        \
+     _IOR(0xF6, 0xA2, struct lttng_kernel_abi_tracker_args)
 
 #endif /* _LTT_KERNEL_IOCTL_H */
This page took 0.034841 seconds and 4 git commands to generate.