#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);
#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)
char *lwp_name = lwp->lpd_obd->obd_name;
char *server_uuid = NULL;
char *ptr;
+ int uuid_len = -1;
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;
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);
}
- 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);