cfs_strrstr() is only used in one place, and it can easily be open
coded there without increasing code complexity. In particular the
fact that the "needle" cannot meaningfully be at the start of the
"haystack", means a simple loop does all we need.
In fact, there is room to improve the code in lwp_setup()
- sprintf isn't needed as the result is a constant that can
be calculated at compile time
- adding the nul termination is then not needed as the buffer
being copied to was initialised to zeroes.
Signed-off-by: Mr NeilBrown <neilb@suse.de>
Change-Id: I52b4abb36cf809d3bd9eebcc752959b0a81bfc13
Reviewed-on: https://review.whamcloud.com/40861
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Alex Zhuravlev <bzzz@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
#define __LIBCFS_STRING_H__
/* libcfs_string.c */
#define __LIBCFS_STRING_H__
/* libcfs_string.c */
-char *cfs_strrstr(const char *haystack, const char *needle);
/* Convert a text string to a bitmask */
int cfs_str2mask(const char *str, const char *(*bit2str)(int bit),
int *oldmask, int minmask, int allmask);
/* Convert a text string to a bitmask */
int cfs_str2mask(const char *str, const char *(*bit2str)(int bit),
int *oldmask, int minmask, int allmask);
#include <libcfs/libcfs.h>
#include <libcfs/libcfs_string.h>
#include <libcfs/libcfs.h>
#include <libcfs/libcfs_string.h>
-char *cfs_strrstr(const char *haystack, const char *needle)
-{
- char *ptr;
-
- if (unlikely(haystack == NULL || needle == NULL))
- return NULL;
-
- if (strlen(needle) == 1)
- return strrchr(haystack, needle[0]);
-
- ptr = strstr(haystack, needle);
- if (ptr != NULL) {
- while (1) {
- char *tmp;
-
- tmp = strstr(&ptr[1], needle);
- if (tmp == NULL)
- 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)
/* Convert a text string to a bitmask */
int cfs_str2mask(const char *str, const char *(*bit2str)(int bit),
int *oldmask, int minmask, int allmask)
char *lwp_name = lwp->lpd_obd->obd_name;
char *server_uuid = NULL;
char *ptr;
char *lwp_name = lwp->lpd_obd->obd_name;
char *server_uuid = NULL;
char *ptr;
struct obd_import *imp;
int len = strlen(lwp_name) + 1;
int rc;
struct obd_import *imp;
int len = strlen(lwp_name) + 1;
int rc;
+ const char *lwp_marker = "-" LUSTRE_LWP_NAME "-";
ENTRY;
lwp->lpd_notify_task = NULL;
ENTRY;
lwp->lpd_notify_task = NULL;
if (server_uuid == NULL)
GOTO(out, rc = -ENOMEM);
if (server_uuid == NULL)
GOTO(out, rc = -ENOMEM);
- snprintf(server_uuid, len, "-%s-", LUSTRE_LWP_NAME);
- ptr = cfs_strrstr(lwp_name, server_uuid);
- if (ptr == NULL) {
+ ptr = lwp_name;
+ while (ptr && (ptr = strstr(ptr+1, lwp_marker)) != NULL)
+ uuid_len = ptr - lwp_name;
+
+ if (uuid_len < 0) {
CERROR("%s: failed to get server_uuid from lwp_name: rc = %d\n",
lwp_name, -EINVAL);
GOTO(out, rc = -EINVAL);
}
CERROR("%s: failed to get server_uuid from lwp_name: rc = %d\n",
lwp_name, -EINVAL);
GOTO(out, rc = -EINVAL);
}
- strncpy(server_uuid, lwp_name, ptr - lwp_name);
- server_uuid[ptr - lwp_name] = '\0';
+ strncpy(server_uuid, lwp_name, uuid_len);
strlcat(server_uuid, "_UUID", len);
lustre_cfg_bufs_reset(bufs, lwp_name);
lustre_cfg_bufs_set_string(bufs, 1, server_uuid);
strlcat(server_uuid, "_UUID", len);
lustre_cfg_bufs_reset(bufs, lwp_name);
lustre_cfg_bufs_set_string(bufs, 1, server_uuid);