From 7fe7f4ca06b9c8d128f7ba36988e36f8141ed53d Mon Sep 17 00:00:00 2001 From: Shaun Tancheff Date: Fri, 3 Feb 2023 02:17:16 -0600 Subject: [PATCH] LU-16520 build: Move strscpy to libcfs common header Ensure strscpy is available to lustre Test-Parameters: trivial Fixes: 0b406c91d17 ("LU-13642 lnet: modify lnet_inetdev to work with large NIDS") Signed-off-by: Shaun Tancheff Change-Id: I0c3673c2aa7e6b61671521a8cabde8a364f7f6f8 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/49863 Tested-by: jenkins Tested-by: Maloo Reviewed-by: jsimmons Reviewed-by: Jian Yu Reviewed-by: Petros Koutoupis Reviewed-by: Oleg Drokin --- libcfs/autoconf/lustre-libcfs.m4 | 27 ++++++++++++++++++++++++++- libcfs/include/libcfs/linux/linux-misc.h | 4 ++++ lnet/autoconf/lustre-lnet.m4 | 20 -------------------- lnet/lnet/config.c | 4 ---- 4 files changed, 30 insertions(+), 25 deletions(-) diff --git a/libcfs/autoconf/lustre-libcfs.m4 b/libcfs/autoconf/lustre-libcfs.m4 index 0757b4e..eb6dac2 100644 --- a/libcfs/autoconf/lustre-libcfs.m4 +++ b/libcfs/autoconf/lustre-libcfs.m4 @@ -598,6 +598,29 @@ AC_DEFUN([LIBCFS_KERNEL_PARAM_LOCK],[ ]) # LIBCFS_KERNEL_PARAM_LOCK # +# LIBCFS_STRSCPY_EXISTS +# +# Linux commit v4.2-rc1-2-g30035e45753b +# string: provide strscpy() +# +# If strscpy exists, prefer it over strlcpy +# +AC_DEFUN([LIBCFS_SRC_STRSCPY_EXISTS], [ + LB2_LINUX_TEST_SRC([strscpy_exists], [ + #include + ],[ + strscpy((char *)NULL, (const char *)NULL, 0); + ],[-Werror]) +]) +AC_DEFUN([LIBCFS_STRSCPY_EXISTS], [ + AC_MSG_CHECKING([if kernel strscpy is available]) + LB2_LINUX_TEST_RESULT([strscpy_exists], [ + AC_DEFINE(HAVE_STRSCPY, 1, + [kernel strscpy is available]) + ]) +]) # LIBCFS_STRSCPY_EXISTS + +# # Kernel version 4.2 changed topology_thread_cpumask # to topology_sibling_cpumask # @@ -2281,9 +2304,10 @@ AC_DEFUN([LIBCFS_PROG_LINUX_SRC], [ LIBCFS_SRC_WAIT_WOKEN # 4.0 LIBCFS_SRC_KTIME_MS_DELTA - # 4.2 + # 4.1 LIBCFS_SRC_KERNEL_PARAM_LOCK # 4.2 + LIBCFS_SRC_STRSCPY_EXISTS LIBCFS_SRC_HAVE_TOPOLOGY_SIBLING_CPUMASK # 4.4 LIBCFS_SRC_KSTRTOBOOL_FROM_USER @@ -2425,6 +2449,7 @@ AC_DEFUN([LIBCFS_PROG_LINUX_RESULTS], [ # 4.1 LIBCFS_KERNEL_PARAM_LOCK # 4.2 + LIBCFS_STRSCPY_EXISTS LIBCFS_HAVE_TOPOLOGY_SIBLING_CPUMASK # 4.4 LIBCFS_KSTRTOBOOL_FROM_USER diff --git a/libcfs/include/libcfs/linux/linux-misc.h b/libcfs/include/libcfs/linux/linux-misc.h index 841db69..7d854e7 100644 --- a/libcfs/include/libcfs/linux/linux-misc.h +++ b/libcfs/include/libcfs/linux/linux-misc.h @@ -177,6 +177,10 @@ static inline void *cfs_kallsyms_lookup_name(const char *name) } #endif +#ifndef HAVE_STRSCPY +#define strscpy(s1, s2, sz) strlcpy((s1), (s2), (sz)) +#endif + #ifndef HAVE_KOBJ_TYPE_DEFAULT_GROUPS #define default_groups default_attrs #define KOBJ_ATTR_GROUPS(_name) _name##_attrs diff --git a/lnet/autoconf/lustre-lnet.m4 b/lnet/autoconf/lustre-lnet.m4 index 6aff70a..7421cfb 100644 --- a/lnet/autoconf/lustre-lnet.m4 +++ b/lnet/autoconf/lustre-lnet.m4 @@ -724,25 +724,6 @@ AC_SUBST(KFILND) AC_SUBST(EXTRA_SYMBOLS) ]) # LN_CONFIG_KFILND -# LN_CONFIG_STRSCPY_EXISTS -# -# If strscpy exists, prefer it over strlcpy -# -AC_DEFUN([LN_CONFIG_STRSCPY_EXISTS], [ -tmp_flags="$EXTRA_KCFLAGS" -EXTRA_KCFLAGS="-Werror" -LB_CHECK_COMPILE([kernel strscpy is available], -strscpy_exists, [ - #include -],[ - strscpy((char *)NULL, (const char *)NULL, 0); -],[ - AC_DEFINE(HAVE_STRSCPY, 1, - [kernel strscpy is available]) -]) -EXTRA_KCFLAGS="$tmp_flags" -]) # LN_CONFIG_STRSCPY_EXISTS - # LN_CONFIG_SOCK_CREATE_KERN # # 4.x sock_create_kern() added a first parameter as 'struct net *' @@ -969,7 +950,6 @@ AC_MSG_NOTICE([LNet kernel checks LN_CONFIG_BACKOFF LN_CONFIG_O2IB LN_CONFIG_GNILND -LN_CONFIG_STRSCPY_EXISTS LN_CONFIG_KFILND # 3.10 LN_EXPORT_KMAP_TO_PAGE diff --git a/lnet/lnet/config.c b/lnet/lnet/config.c index fdc1aa4b..81eaa39 100644 --- a/lnet/lnet/config.c +++ b/lnet/lnet/config.c @@ -52,10 +52,6 @@ static int lnet_tbnob = 0; /* track text buf allocation */ #define SPACESTR " \t\v\r\n" #define DELIMITERS ":()[]" -#ifndef HAVE_STRSCPY -#define strscpy(s1, s2, sz) strlcpy((s1), (s2), (sz)) -#endif - static void lnet_syntax(const char *name, const char *str, int offset, int width) { -- 1.8.3.1