Whamcloud - gitweb
LU-9859 libcfs: rework special libcfs string handling 44/57944/4
authorJames Simmons <jsimmons@infradead.org>
Wed, 5 Feb 2025 15:13:02 +0000 (10:13 -0500)
committerOleg Drokin <green@whamcloud.com>
Tue, 11 Feb 2025 05:32:34 +0000 (05:32 +0000)
The header libcfs_string.h contains NID string specific items so
move them to the LNet header lib-types.h. Only functions for
string to or from mask handling is left in libcfs_string.c. We
can merged that into debug.c where it is first used.

Test-Parameters: trivial
Change-Id: I79c56594af065dfd08b8205a05326fa0ebf36d55
Signed-off-by: James Simmons <jsimmons@infradead.org>
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/57944
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Shaun Tancheff <shaun.tancheff@hpe.com>
Reviewed-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Reviewed-by: Timothy Day <timday@amazon.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
libcfs/include/libcfs/Makefile.am
libcfs/include/libcfs/libcfs.h
libcfs/include/libcfs/libcfs_debug.h
libcfs/include/libcfs/libcfs_string.h [deleted file]
libcfs/libcfs/Makefile.in
libcfs/libcfs/debug.c
libcfs/libcfs/libcfs_string.c [deleted file]
lnet/include/lnet/lib-types.h
lnet/lnet/lib-cpt.c
lustre/mdd/mdd_lproc.c

index 1d337cc..cd38c01 100644 (file)
@@ -16,5 +16,4 @@ EXTRA_DIST = \
        libcfs_debug.h \
        libcfs_fail.h \
        libcfs_hash.h \
-       libcfs_private.h \
-       libcfs_string.h
+       libcfs_private.h
index e8e1193..7b35c9b 100644 (file)
@@ -31,7 +31,6 @@
 #include <uapi/linux/lnet/libcfs_ioctl.h>
 #include <libcfs/libcfs_debug.h>
 #include <libcfs/libcfs_private.h>
-#include <libcfs/libcfs_string.h>
 #include <libcfs/libcfs_hash.h>
 #include <libcfs/libcfs_fail.h>
 
index 1375dda..f68ebb1 100644 (file)
@@ -37,6 +37,12 @@ extern char *libcfs_debug_file_path;
 
 struct task_struct;
 
+/* Convert a text string to a bitmask */
+int cfs_str2mask(const char *str, const char *(*bit2str)(int bit),
+                u64 *oldmask, u64 minmask, u64 allmask, u64 defmask);
+int cfs_mask2str(char *str, int size, u64 mask, const char *(*bit2str)(int),
+                char sep);
+
 int libcfs_debug_mask2str(char *str, int size, int mask, int is_subsys);
 int libcfs_debug_str2mask(int *mask, const char *str, int is_subsys);
 void libcfs_debug_dumpstack(struct task_struct *tsk);
diff --git a/libcfs/include/libcfs/libcfs_string.h b/libcfs/include/libcfs/libcfs_string.h
deleted file mode 100644 (file)
index 8f2616f..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-
-/*
- * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
- * Use is subject to license terms.
- *
- * Copyright (c) 2012, 2017, Intel Corporation.
- */
-
-/*
- * This file is part of Lustre, http://www.lustre.org/
- *
- * Generic string manipulation functions.
- *
- * Author: Nathan Rutman <nathan.rutman@sun.com>
- */
-
-#ifndef __LIBCFS_STRING_H__
-#define __LIBCFS_STRING_H__
-
-/* libcfs_string.c */
-/* Convert a text string to a bitmask */
-int cfs_str2mask(const char *str, const char *(*bit2str)(int bit),
-                u64 *oldmask, u64 minmask, u64 allmask, u64 defmask);
-int cfs_mask2str(char *str, int size, u64 mask, const char *(*bit2str)(int),
-                char sep);
-
-/*
- * Structure to represent \<range_expr\> token of the syntax.
- */
-struct cfs_range_expr {
-       /*
-        * Link to cfs_expr_list::el_exprs.
-        */
-       struct list_head        re_link;
-       u32                     re_lo;
-       u32                     re_hi;
-       u32                     re_stride;
-};
-
-struct cfs_expr_list {
-       struct list_head        el_link;
-       struct list_head        el_exprs;
-};
-
-int cfs_expr_list_match(u32 value, struct cfs_expr_list *expr_list);
-int cfs_expr_list_values(struct cfs_expr_list *expr_list,
-                        int max, u32 **values);
-void cfs_expr_list_free(struct cfs_expr_list *expr_list);
-int cfs_expr_list_parse(char *str, int len, unsigned int min, unsigned int max,
-                       struct cfs_expr_list **elpp);
-void cfs_expr_list_free_list(struct list_head *list);
-#define cfs_expr_list_values_free(values, num) CFS_FREE_PTR_ARRAY(values, num)
-
-#endif
index 5ad8ba8..fcbf367 100644 (file)
@@ -21,8 +21,7 @@ default: all
 libcfs-linux-objs := $(addprefix linux/,$(libcfs-linux-objs))
 libcfs-crypto-objs := $(addprefix crypto/,$(libcfs-crypto-objs))
 
-libcfs-all-objs := debug.o fail.o module.o tracefile.o \
-                  libcfs_string.o hash.o
+libcfs-all-objs := debug.o fail.o module.o tracefile.o hash.o
 
 libcfs-objs := $(libcfs-linux-objs) $(libcfs-all-objs)
 @LLCRYPT_TRUE@libcfs-objs += $(libcfs-crypto-objs)
index eca35d7..eaf70b9 100644 (file)
@@ -17,7 +17,6 @@
 
 #include <linux/module.h>
 #include <linux/ctype.h>
-#include <libcfs/libcfs_string.h>
 #include <linux/kthread.h>
 #include <linux/stacktrace.h>
 #include <linux/utsname.h>
@@ -267,6 +266,136 @@ static const char *libcfs_debug_dbg2str(int debug)
        return libcfs_debug_masks[debug];
 }
 
+/* convert a binary mask to a string of bit names */
+int cfs_mask2str(char *str, int size, u64 mask, const char *(*bit2str)(int bit),
+                char sep)
+{
+       const char *token;
+       int len = 0;
+       int i;
+
+       if (mask == 0) {                        /* "0" */
+               if (size > 0)
+                       str[0] = '0';
+               len = 1;
+       } else {                                /* space-separated tokens */
+               for (i = 0; i < 64; i++) {
+                       if ((mask & BIT(i)) == 0)
+                               continue;
+
+                       token = bit2str(i);
+                       if (!token)             /* unused bit */
+                               continue;
+
+                       if (len > 0) {          /* separator? */
+                               if (len < size)
+                                       str[len] = sep;
+                               len++;
+                       }
+
+                       while (*token != 0) {
+                               if (len < size)
+                                       str[len] = *token;
+                               token++;
+                               len++;
+                       }
+               }
+       }
+
+       /* terminate 'str' */
+       if (len < size)
+               str[len++] = '\n';
+       if (len < size)
+               str[len] = '\0';
+       else
+               str[size - 1] = '\0';
+
+       return len;
+}
+EXPORT_SYMBOL(cfs_mask2str);
+
+/* Convert a text string to a bitmask */
+int cfs_str2mask(const char *str, const char *(*bit2str)(int bit),
+                u64 *oldmask, u64 minmask, u64 allmask, u64 defmask)
+{
+       const char *debugstr;
+       u64 newmask = *oldmask, found = 0;
+
+       ENTRY;
+       /* <str> must be a list of tokens separated by whitespace or comma,
+        * and optionally an operator ('+' or '-').  If an operator
+        * appears first in <str>, '*oldmask' is used as the starting point
+        * (relative), otherwise minmask is used (absolute).  An operator
+        * applies to all following tokens up to the next operator.
+        */
+       while (*str != 0) {
+               int i, len;
+               char op = 0;
+
+               while (isspace(*str) || *str == ',')
+                       str++;
+               if (*str == 0)
+                       break;
+               if (*str == '+' || *str == '-') {
+                       op = *str++;
+                       while (isspace(*str))
+                               str++;
+                       if (*str == 0)          /* trailing op */
+                               return -EINVAL;
+               } else if (!found)
+                       newmask = minmask;
+
+
+               /* find token length */
+               for (len = 0; str[len] != 0 && !isspace(str[len]) &&
+                    str[len] != '+' && str[len] != '-' && str[len] != ',';
+                    len++);
+
+               /* match token */
+               found = 0;
+               for (i = 0; i < 32; i++) {
+                       debugstr = bit2str(i);
+                       if (debugstr != NULL &&
+                           strlen(debugstr) == len &&
+                           strncasecmp(str, debugstr, len) == 0) {
+                               if (op == '-')
+                                       newmask &= ~BIT(i);
+                              else
+                                       newmask |= BIT(i);
+                               found = 1;
+                               break;
+                       }
+               }
+               if (!found && len == 3 &&
+                   (strncasecmp(str, "ALL", len) == 0)) {
+                       if (op == '-')
+                               newmask = minmask;
+                       else
+                               newmask = allmask;
+                       found = 1;
+               }
+               if (!found && strcasecmp(str, "DEFAULT") == 0) {
+                       if (op == '-')
+                               newmask = (newmask & ~defmask) | minmask;
+                       else if (op == '+')
+                               newmask |= defmask;
+                       else
+                               newmask = defmask;
+                       found = 1;
+               }
+               if (!found) {
+                       CWARN("unknown mask '%.*s'.\n"
+                             "mask usage: [+|-]<all|type> ...\n", len, str);
+                       return -EINVAL;
+               }
+               str += len;
+       }
+
+       *oldmask = newmask;
+       return 0;
+}
+EXPORT_SYMBOL(cfs_str2mask);
+
 int libcfs_debug_mask2str(char *str, int size, int mask, int is_subsys)
 {
        const char *(*bit2str)(int bit) = is_subsys ? libcfs_debug_subsys2str :
diff --git a/libcfs/libcfs/libcfs_string.c b/libcfs/libcfs/libcfs_string.c
deleted file mode 100644 (file)
index f144062..0000000
+++ /dev/null
@@ -1,151 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-
-/*
- * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
- * Use is subject to license terms.
- *
- * Copyright (c) 2012, 2017, Intel Corporation.
- */
-
-/*
- * This file is part of Lustre, http://www.lustre.org/
- *
- * String manipulation functions.
- *
- * Author: Nathan Rutman <nathan.rutman@sun.com>
- */
-
-#include <linux/ctype.h>
-#include <libcfs/libcfs.h>
-#include <libcfs/libcfs_string.h>
-
-
-/* convert a binary mask to a string of bit names */
-int cfs_mask2str(char *str, int size, u64 mask, const char *(*bit2str)(int bit),
-                char sep)
-{
-       int len = 0;
-       const char *token;
-       int i;
-
-       if (mask == 0) {                        /* "0" */
-               if (size > 0)
-                       str[0] = '0';
-               len = 1;
-       } else {                                /* space-separated tokens */
-               for (i = 0; i < 64; i++) {
-                       if ((mask & BIT(i)) == 0)
-                               continue;
-
-                       token = bit2str(i);
-                       if (!token)             /* unused bit */
-                               continue;
-
-                       if (len > 0) {          /* separator? */
-                               if (len < size)
-                                       str[len] = sep;
-                               len++;
-                       }
-
-                       while (*token != 0) {
-                               if (len < size)
-                                       str[len] = *token;
-                               token++;
-                               len++;
-                       }
-               }
-       }
-
-       /* terminate 'str' */
-       if (len < size)
-               str[len++] = '\n';
-       if (len < size)
-               str[len] = '\0';
-       else
-               str[size - 1] = '\0';
-
-       return len;
-}
-EXPORT_SYMBOL(cfs_mask2str);
-
-/* Convert a text string to a bitmask */
-int cfs_str2mask(const char *str, const char *(*bit2str)(int bit),
-                u64 *oldmask, u64 minmask, u64 allmask, u64 defmask)
-{
-       const char *debugstr;
-       u64 newmask = *oldmask, found = 0;
-
-       ENTRY;
-       /* <str> must be a list of tokens separated by whitespace or comma,
-        * and optionally an operator ('+' or '-').  If an operator
-        * appears first in <str>, '*oldmask' is used as the starting point
-        * (relative), otherwise minmask is used (absolute).  An operator
-        * applies to all following tokens up to the next operator.
-        */
-       while (*str != 0) {
-               int i, len;
-               char op = 0;
-
-               while (isspace(*str) || *str == ',')
-                       str++;
-               if (*str == 0)
-                       break;
-               if (*str == '+' || *str == '-') {
-                       op = *str++;
-                       while (isspace(*str))
-                               str++;
-                       if (*str == 0)          /* trailing op */
-                               return -EINVAL;
-               } else if (!found)
-                       newmask = minmask;
-
-
-               /* find token length */
-               for (len = 0; str[len] != 0 && !isspace(str[len]) &&
-                       str[len] != '+' && str[len] != '-' && str[len] != ',';
-                    len++);
-
-               /* match token */
-               found = 0;
-               for (i = 0; i < 32; i++) {
-                       debugstr = bit2str(i);
-                       if (debugstr != NULL &&
-                           strlen(debugstr) == len &&
-                           strncasecmp(str, debugstr, len) == 0) {
-                               if (op == '-')
-                                       newmask &= ~BIT(i);
-                               else
-                                       newmask |= BIT(i);
-                               found = 1;
-                               break;
-                       }
-               }
-               if (!found && len == 3 &&
-                   (strncasecmp(str, "ALL", len) == 0)) {
-                       if (op == '-')
-                               newmask = minmask;
-                       else
-                               newmask = allmask;
-                       found = 1;
-               }
-               if (!found && strcasecmp(str, "DEFAULT") == 0) {
-                       if (op == '-')
-                               newmask = (newmask & ~defmask) | minmask;
-                       else if (op == '+')
-                               newmask |= defmask;
-                       else
-                               newmask = defmask;
-                       found = 1;
-               }
-               if (!found) {
-                       CWARN("unknown mask '%.*s'.\n"
-                             "mask usage: [+|-]<all|type> ...\n", len, str);
-                       return -EINVAL;
-               }
-               str += len;
-       }
-
-       *oldmask = newmask;
-       return 0;
-}
-EXPORT_SYMBOL(cfs_str2mask);
index c3c8124..63711fa 100644 (file)
@@ -37,6 +37,29 @@ int cfs_match_nid_net(struct lnet_nid *nid, u32 net,
                      struct list_head *net_num_list,
                      struct list_head *addr);
 
+/* Structure to represent \<range_expr\> token of the syntax. */
+struct cfs_range_expr {
+       /* Link to cfs_expr_list::el_exprs. */
+       struct list_head        re_link;
+       u32                     re_lo;
+       u32                     re_hi;
+       u32                     re_stride;
+};
+
+struct cfs_expr_list {
+       struct list_head        el_link;
+       struct list_head        el_exprs;
+};
+
+int cfs_expr_list_match(u32 value, struct cfs_expr_list *expr_list);
+int cfs_expr_list_values(struct cfs_expr_list *expr_list,
+                        int max, u32 **values);
+void cfs_expr_list_free(struct cfs_expr_list *expr_list);
+int cfs_expr_list_parse(char *str, int len, unsigned int min, unsigned int max,
+                       struct cfs_expr_list **elpp);
+void cfs_expr_list_free_list(struct list_head *list);
+#define cfs_expr_list_values_free(values, num)  CFS_FREE_PTR_ARRAY(values, num)
+
 /* Max payload size */
 #define LNET_MAX_PAYLOAD       LNET_MTU
 
index 71c2b42..4f5475a 100644 (file)
@@ -18,8 +18,8 @@
 #include <linux/module.h>
 #include <linux/slab.h>
 
-#include <libcfs/libcfs_string.h>
 #include <libcfs/libcfs.h>
+#include <lnet/lib-types.h>
 #include <lnet/lib-cpt.h>
 
 /** virtual processing unit */
index 047c390..5b72f04 100644 (file)
@@ -21,7 +21,6 @@
 #include <obd_class.h>
 #include <obd_support.h>
 #include <lprocfs_status.h>
-#include <libcfs/libcfs_string.h>
 #include "mdd_internal.h"
 
 static ssize_t uuid_show(struct kobject *kobj, struct attribute *attr,