From: Francis Deslauriers Date: Tue, 27 Apr 2021 18:26:09 +0000 (-0400) Subject: Use new ioctl macros with fixed ioctl direction X-Git-Tag: v2.13.0-rc2~48 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=c7a7f1e8e5f64fb31f1a1fe45ec7bd4b81af2fb4;p=lttng-tools.git Use new ioctl macros with fixed ioctl direction Update the ioctl commands to follow the changes in this commit: commit 8c71721f7a868b575b05e24bc3a3dcc967e6d5d6 Author: Mathieu Desnoyers 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 Signed-off-by: Jérémie Galarneau Change-Id: I2604ea5902fec3bf574c7a249cb65784685a0ae8 --- diff --git a/src/common/kernel-ctl/kernel-ctl.c b/src/common/kernel-ctl/kernel-ctl.c index 877de5f86..5373c7039 100644 --- a/src/common/kernel-ctl/kernel-ctl.c +++ b/src/common/kernel-ctl/kernel-ctl.c @@ -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; } diff --git a/src/common/kernel-ctl/kernel-ioctl.h b/src/common/kernel-ctl/kernel-ioctl.h index 6da9676a2..b9af57a6b 100644 --- a/src/common/kernel-ctl/kernel-ioctl.h +++ b/src/common/kernel-ctl/kernel-ioctl.h @@ -128,9 +128,9 @@ #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 @@ -141,9 +141,9 @@ /* 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) @@ -170,11 +170,11 @@ /* 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 \ @@ -193,5 +193,23 @@ #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 */