From: Shaun Tancheff Date: Wed, 23 Oct 2024 06:25:55 +0000 (-0700) Subject: LU-16520 build: Move strscpy to libcfs common header X-Git-Tag: 2.15.6-RC1~33 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=refs%2Fchanges%2F66%2F56766%2F4;p=fs%2Flustre-release.git 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 Signed-off-by: Shaun Tancheff Change-Id: I0c3673c2aa7e6b61671521a8cabde8a364f7f6f8 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/56766 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Yang Sheng Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- diff --git a/libcfs/autoconf/lustre-libcfs.m4 b/libcfs/autoconf/lustre-libcfs.m4 index 37c2762..b777240 100644 --- a/libcfs/autoconf/lustre-libcfs.m4 +++ b/libcfs/autoconf/lustre-libcfs.m4 @@ -614,6 +614,31 @@ 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 + ],[ + char buf[129]; + + strscpy(buf, "something", sizeof(buf)); + ],[-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 # @@ -2289,9 +2314,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 @@ -2434,6 +2460,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 c542c19..f8b19e1 100644 --- a/libcfs/include/libcfs/linux/linux-misc.h +++ b/libcfs/include/libcfs/linux/linux-misc.h @@ -198,6 +198,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 e8fb1aa..5d90e64 100644 --- a/lnet/autoconf/lustre-lnet.m4 +++ b/lnet/autoconf/lustre-lnet.m4 @@ -697,25 +697,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 *' @@ -942,7 +923,6 @@ AC_MSG_NOTICE([LNet kernel checks LN_CONFIG_BACKOFF LN_CONFIG_O2IB 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 09fe96d..01dd3d8 100644 --- a/lnet/lnet/config.c +++ b/lnet/lnet/config.c @@ -51,10 +51,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) {