From b762319d5ad0884adfb2f79c956a798fba665566 Mon Sep 17 00:00:00 2001 From: James Simmons Date: Wed, 25 May 2022 10:20:23 -0400 Subject: [PATCH] LU-14195 libcfs: test for nla_strscpy During the development of the Linux 5.10 kernel the function nla_strlcpy() was replaced by nla_strscpy(). Handle this change for Lustre. Test-parameters: trivial Change-Id: I47f12add619cfd88a3692f0760b8bcc35b7877d9 Signed-off-by: James Simmons Reviewed-on: https://review.whamcloud.com/46876 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Neil Brown Reviewed-by: Jian Yu Reviewed-by: Oleg Drokin --- contrib/scripts/spelling.txt | 1 + libcfs/autoconf/lustre-libcfs.m4 | 51 ++++++++++++++++++++++++++------- libcfs/include/libcfs/linux/linux-net.h | 4 +++ 3 files changed, 46 insertions(+), 10 deletions(-) diff --git a/contrib/scripts/spelling.txt b/contrib/scripts/spelling.txt index b5e3f24..1f1ed81 100644 --- a/contrib/scripts/spelling.txt +++ b/contrib/scripts/spelling.txt @@ -182,6 +182,7 @@ mti_spec||mdi_spec mti_tattr||mdi_tattr mti_tpattr||mdi_tpattr mti_xattr_buf||mdi_xattr_buf +nla_strlcpy|nla_strscpy OS_STATE_DEGRADED||OS_STATFS_DEGRADED OS_STATE_READONLY||OS_STATFS_READONLY OS_STATE_NOPRECREATE||OS_STATFS_NOPRECREATE diff --git a/libcfs/autoconf/lustre-libcfs.m4 b/libcfs/autoconf/lustre-libcfs.m4 index c711c85..e1bc40d 100644 --- a/libcfs/autoconf/lustre-libcfs.m4 +++ b/libcfs/autoconf/lustre-libcfs.m4 @@ -1772,17 +1772,31 @@ list_cmp_func_t, [ EXTRA_KCFLAGS="$tmp_flags" ]) # LIBCFS_HAVE_LIST_CMP_FUNC_T -AC_DEFUN([LIBCFS_PROG_LINUX_SRC], [ - LIBCFS_SRC_HAVE_PROC_OPS - - AC_MSG_CHECKING([for available kernel interfaces to libcfs]) - LB2_LINUX_TEST_COMPILE_ALL([libcfs]) - AC_MSG_RESULT([done]) -]) -AC_DEFUN([LIBCFS_PROG_LINUX_RESULTS], [ - # 5.6 - LIBCFS_HAVE_PROC_OPS +# +# LIBCFS_NLA_STRSCPY +# +# Kernel version 5.10-rc3 commit 872f690341948b502c93318f806d821c56772c42 +# replaced nla_strlcpy() with nla_strscpy(). +# +AC_DEFUN([LIBCFS_SRC_NLA_STRSCPY], [ + LB2_LINUX_TEST_SRC([nla_strscpy], [ + #include + ],[ + if (nla_strscpy(NULL, NULL, 0) < 0) + return -EINVAL; + ],[ + ],[]) ]) +AC_DEFUN([LIBCFS_NLA_STRSCPY], [ + AC_MSG_CHECKING([if 'nla_strscpy()' exists]) + LB2_LINUX_TEST_RESULT([nla_strscpy], [ + AC_DEFINE(HAVE_NLA_STRSCPY, 1, + ['nla_strscpy' is available]) + AC_MSG_RESULT(yes) + ],[ + AC_MSG_RESULT(no) + ]) +]) # LIBCFS_NLA_STRSCPY # # LIBCFS_HAVE_CIPHER_HEADER @@ -1834,6 +1848,23 @@ param_set_uint_minmax, [ ]) ]) # LIBCFS_PARAM_SET_UINT_MINMAX +AC_DEFUN([LIBCFS_PROG_LINUX_SRC], [ + # 5.6 + LIBCFS_SRC_HAVE_PROC_OPS + # 5.10 + LIBCFS_SRC_NLA_STRSCPY + + AC_MSG_CHECKING([for available kernel interfaces to libcfs]) + LB2_LINUX_TEST_COMPILE_ALL([libcfs]) + AC_MSG_RESULT([done]) +]) +AC_DEFUN([LIBCFS_PROG_LINUX_RESULTS], [ + # 5.6 + LIBCFS_HAVE_PROC_OPS + # 5.10 + LIBCFS_NLA_STRSCPY +]) + # # LIBCFS_PROG_LINUX # diff --git a/libcfs/include/libcfs/linux/linux-net.h b/libcfs/include/libcfs/linux/linux-net.h index a9502a3..4d43894 100644 --- a/libcfs/include/libcfs/linux/linux-net.h +++ b/libcfs/include/libcfs/linux/linux-net.h @@ -30,6 +30,10 @@ char *nla_strdup(const struct nlattr *nla, gfp_t flags); #endif /* !HAVE_NLA_STRDUP */ +#ifndef HAVE_NLA_STRSCPY +#define nla_strscpy nla_strlcpy +#endif /* !HAVE_NLA_STRSCPY */ + #ifndef HAVE_NL_PARSE_WITH_EXT_ACK #define NL_SET_BAD_ATTR(extack, attr) -- 1.8.3.1