Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1265128

[PATCH] staging: lustre: add libcfs version of cfs_strrstr

From James Simmons <jsimmons@infradead.org>
Newsgroups linux.kernel
Subject [PATCH] staging: lustre: add libcfs version of cfs_strrstr
Date 2015-11-08 17:40 +0100
Message-ID <qsBay-2w9-9@gated-at.bofh.it> (permalink)
References <qsBax-2w9-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Fan Yong <fan.yong@intel.com>

Create a kernel side function that does the same
thing as userland strrstr. This is from patch
http://review.whamcloud.com/7666.

Signed-off-by: Fan Yong <fan.yong@intel.com>
ntel-bug-id: https://jira.hpdd.intel.com/browse/LU-3951
Reviewed-on: http://review.whamcloud.com/7666
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: Alex Zhuravlev <alexey.zhuravlev@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
---
 .../lustre/include/linux/libcfs/libcfs_string.h    |    1 +
 .../staging/lustre/lustre/libcfs/libcfs_string.c   |   27 ++++++++++++++++++++
 2 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_string.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_string.h
index d8d2e7d..052f684 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_string.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_string.h
@@ -44,6 +44,7 @@
 #define __LIBCFS_STRING_H__
 
 /* libcfs_string.c */
+char *cfs_strrstr(const char *haystack, const char *needle);
 /* string comparison ignoring case */
 int cfs_strncasecmp(const char *s1, const char *s2, size_t n);
 /* Convert a text string to a bitmask */
diff --git a/drivers/staging/lustre/lustre/libcfs/libcfs_string.c b/drivers/staging/lustre/lustre/libcfs/libcfs_string.c
index 05630f8..4e399ef 100644
--- a/drivers/staging/lustre/lustre/libcfs/libcfs_string.c
+++ b/drivers/staging/lustre/lustre/libcfs/libcfs_string.c
@@ -42,6 +42,33 @@
 
 #include "../../include/linux/libcfs/libcfs.h"
 
+char *cfs_strrstr(const char *haystack, const char *needle)
+{
+	char *ptr;
+
+	if (unlikely(!haystack || !needle))
+		return NULL;
+
+	if (strlen(needle) == 1)
+		return strrchr(haystack, needle[0]);
+
+	ptr = strstr(haystack, needle);
+	if (ptr) {
+		while (1) {
+			char *tmp;
+
+			tmp = strstr(&ptr[1], needle);
+			if (!tmp)
+				return ptr;
+
+			ptr = tmp;
+		}
+	}
+
+	return NULL;
+}
+EXPORT_SYMBOL(cfs_strrstr);
+
 /* Convert a text string to a bitmask */
 int cfs_str2mask(const char *str, const char *(*bit2str)(int bit),
 		 int *oldmask, int minmask, int allmask)
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v2] staging: lustre: remove IOC_LIBCFS_PING_TEST ioctl James Simmons <jsimmons@infradead.org> - 2015-11-08 17:40 +0100
  [PATCH] staging: lustre: add libcfs version of cfs_strrstr James Simmons <jsimmons@infradead.org> - 2015-11-08 17:40 +0100
  [PATCH] staging: lustre: added debugging ability for LFSCK James Simmons <jsimmons@infradead.org> - 2015-11-08 17:40 +0100
  [PATCH] staging: lustre: add sparse locking annotations James Simmons <jsimmons@infradead.org> - 2015-11-08 17:40 +0100
  [PATCH] staging: lustre: export cfs_str2mask James Simmons <jsimmons@infradead.org> - 2015-11-08 17:40 +0100
    Re: [lustre-devel] [PATCH] staging: lustre: export cfs_str2mask "Drokin, Oleg" <oleg.drokin@intel.com> - 2015-11-09 12:10 +0100
      RE: [lustre-devel] [PATCH] staging: lustre: export cfs_str2mask "Simmons, James A." <simmonsja@ornl.gov> - 2015-11-10 01:50 +0100
  [PATCH] staging: lustre: Handle nodemask on UMP machines James Simmons <jsimmons@infradead.org> - 2015-11-08 17:40 +0100
    Re: [PATCH] staging: lustre: Handle nodemask on UMP machines Sudip Mukherjee <sudipm.mukherjee@gmail.com> - 2015-11-09 12:20 +0100
      RE: [lustre-devel] [PATCH] staging: lustre: Handle nodemask on UMP  machines "Simmons, James A." <simmonsja@ornl.gov> - 2015-11-10 01:50 +0100

csiph-web