Whamcloud - gitweb
LU-9325 libcfs: handle complex strings in cfs_str2num_check 17/32217/3
authorJames Simmons <uja.ornl@yahoo.com>
Tue, 8 May 2018 13:30:15 +0000 (09:30 -0400)
committerOleg Drokin <oleg.drokin@intel.com>
Thu, 17 May 2018 02:31:10 +0000 (02:31 +0000)
commit5728fb3009f5f797d1ff68e5ad6de341850c35d4
treef2bee57f941b15e3c70016b96f30d5824b297742
parentbb22454d2203553f657f26e13d6bbeea66270a48
LU-9325 libcfs: handle complex strings in cfs_str2num_check

Originally the function cfs_str2num_check used simple_strtoul
but has been updated to kstrtoul. The string passed into
cfs_str2num_check can be a very complex, for example we could
have 10.37.202.[59-61]. When simple_strtoul was used the first
number until we hit a non-digit character could be extracted
but testing showed that kstrtoul will not return any value if
it detects any non-digit character. Because of this change in
behavior a different approach is needed to handle these types
of complex strings. The use of sscanf was investigated to see
if it could be used to extract numbers from the passed in
string but unlike its glibc counterpart the kernel version
also just reported a error with no results if a non-digit value
in the string was encountered. Another possible approach would
be to use __parse_int directly but that class of functions is
not exported by the kernel. So the approach in this patch is
to scan the string passed in for the first non-digit character
and replace that character with a '\0' so kstrtoul can be used.
Once completed the original character is restored. We also
restore a original behavior that was removed to return 0 when
we encounter any non digit character before the nob count.

Linux-commit : 3ad6152d766039cb8ffd8633d971fb79402e5464

Change-Id: If73d605499e2f05224a14417b0029036db38c8ba
Signed-off-by: Oleg Drokin <green@linuxhacker.ru>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: James Simmons <uja.ornl@yahoo.com>
Reviewed-on: https://review.whamcloud.com/32217
Tested-by: Jenkins
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: Dmitry Eremin <dmitry.eremin@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
libcfs/libcfs/libcfs_string.c
libcfs/libcfs/tracefile.c