From b1793e30c8b40eecb8ebd479f4801e2f1fe769b3 Mon Sep 17 00:00:00 2001 From: Shaun Tancheff Date: Tue, 26 Mar 2024 00:19:09 -0700 Subject: [PATCH] LU-16520 build: Move strscpy to libcfs common header Ensure strscpy is available to lustre Lustre-change: https://review.whamcloud.com/49863 Lustre-commit: 7fe7f4ca06b9c8d128f7ba36988e36f8141ed53d 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/ex/lustre-release/+/54570 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Yang Sheng Reviewed-by: Andreas Dilger --- 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 89d7fc6..fbf2b5e 100644 --- a/libcfs/autoconf/lustre-libcfs.m4 +++ b/libcfs/autoconf/lustre-libcfs.m4 @@ -530,6 +530,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 # @@ -2146,9 +2169,10 @@ AC_DEFUN([LIBCFS_PROG_LINUX_SRC], [ LIBCFS_SRC_KTIME_GET_SECONDS # 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 @@ -2283,6 +2307,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 6bd8020..d318cce 100644 --- a/libcfs/include/libcfs/linux/linux-misc.h +++ b/libcfs/include/libcfs/linux/linux-misc.h @@ -193,6 +193,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 0bddb78..c1e3c90 100644 --- a/lnet/autoconf/lustre-lnet.m4 +++ b/lnet/autoconf/lustre-lnet.m4 @@ -723,25 +723,6 @@ AC_SUBST(GNICPPFLAGS) AC_SUBST(GNILND) ]) # LN_CONFIG_GNILND -# 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 @@ LN_CONFIG_BACKOFF LN_CONFIG_O2IB LN_CONFIG_O2IB_KERNEL LN_CONFIG_GNILND -LN_CONFIG_STRSCPY_EXISTS # 3.10 LN_EXPORT_KMAP_TO_PAGE # 3.15 diff --git a/lnet/lnet/config.c b/lnet/lnet/config.c index c3c2d43..a19fa98 100644 --- a/lnet/lnet/config.c +++ b/lnet/lnet/config.c @@ -53,10 +53,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