Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * What:		/sys/kernel/debug/orangefs/debug-help
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  * Date:		June 2015
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * Contact:		Mike Marshall <hubcap@omnibond.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  * Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  * 			List of client and kernel debug keywords.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  * What:		/sys/kernel/debug/orangefs/client-debug
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  * Date:		June 2015
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  * Contact:		Mike Marshall <hubcap@omnibond.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)  * Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14)  * 			Debug setting for "the client", the userspace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15)  * 			helper for the kernel module.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18)  * What:		/sys/kernel/debug/orangefs/kernel-debug
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19)  * Date:		June 2015
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20)  * Contact:		Mike Marshall <hubcap@omnibond.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21)  * Description:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22)  * 			Debug setting for the orangefs kernel module.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24)  * 			Any of the keywords, or comma-separated lists
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25)  * 			of keywords, from debug-help can be catted to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26)  * 			client-debug or kernel-debug.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28)  * 			"none", "all" and "verbose" are special keywords
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29)  * 			for client-debug. Setting client-debug to "all"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30)  * 			is kind of like trying to drink water from a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31)  * 			fire hose, "verbose" triggers most of the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32)  * 			output except for the constant flow of output
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33)  * 			from the main wait loop.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35)  * 			"none" and "all" are similar settings for kernel-debug
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36)  * 			no need for a "verbose".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) #include "orangefs-debugfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) #include "protocol.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) #include "orangefs-kernel.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) #define DEBUG_HELP_STRING_SIZE 4096
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) #define HELP_STRING_UNINITIALIZED \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 	"Client Debug Keywords are unknown until the first time\n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) 	"the client is started after boot.\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) #define ORANGEFS_KMOD_DEBUG_HELP_FILE "debug-help"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) #define ORANGEFS_KMOD_DEBUG_FILE "kernel-debug"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) #define ORANGEFS_CLIENT_DEBUG_FILE "client-debug"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) #define ORANGEFS_VERBOSE "verbose"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) #define ORANGEFS_ALL "all"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58)  * An array of client_debug_mask will be built to hold debug keyword/mask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59)  * values fetched from userspace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) struct client_debug_mask {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 	char *keyword;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 	__u64 mask1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 	__u64 mask2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) static void orangefs_kernel_debug_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) static int orangefs_debug_help_open(struct inode *, struct file *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) static void *help_start(struct seq_file *, loff_t *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) static void *help_next(struct seq_file *, void *, loff_t *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) static void help_stop(struct seq_file *, void *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) static int help_show(struct seq_file *, void *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) static int orangefs_debug_open(struct inode *, struct file *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) static ssize_t orangefs_debug_read(struct file *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 				 char __user *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 				 size_t,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 				 loff_t *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) static ssize_t orangefs_debug_write(struct file *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 				  const char __user *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 				  size_t,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 				  loff_t *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) static int orangefs_prepare_cdm_array(char *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) static void debug_mask_to_string(void *, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) static void do_k_string(void *, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) static void do_c_string(void *, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) static int keyword_is_amalgam(char *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) static int check_amalgam_keyword(void *, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) static void debug_string_to_mask(char *, void *, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) static void do_c_mask(int, char *, struct client_debug_mask **);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) static void do_k_mask(int, char *, __u64 **);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) static char kernel_debug_string[ORANGEFS_MAX_DEBUG_STRING_LEN] = "none";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) static char *debug_help_string;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) static char client_debug_string[ORANGEFS_MAX_DEBUG_STRING_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) static char client_debug_array_string[ORANGEFS_MAX_DEBUG_STRING_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) static struct dentry *client_debug_dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) static struct dentry *debug_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) static unsigned int kernel_mask_set_mod_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) static int orangefs_debug_disabled = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) static int help_string_initialized;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) static const struct seq_operations help_debug_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 	.start	= help_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 	.next	= help_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 	.stop	= help_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 	.show	= help_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) static const struct file_operations debug_help_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 	.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 	.open           = orangefs_debug_help_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 	.read           = seq_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 	.release        = seq_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 	.llseek         = seq_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) static const struct file_operations kernel_debug_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 	.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 	.open           = orangefs_debug_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 	.read           = orangefs_debug_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 	.write		= orangefs_debug_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 	.llseek         = generic_file_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) static int client_all_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) static int client_verbose_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) static struct client_debug_mask *cdm_array;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) static int cdm_element_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) static struct client_debug_mask client_debug_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141)  * Used to protect data in ORANGEFS_KMOD_DEBUG_FILE and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142)  * ORANGEFS_KMOD_DEBUG_FILE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) static DEFINE_MUTEX(orangefs_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) /* Used to protect data in ORANGEFS_KMOD_DEBUG_HELP_FILE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) static DEFINE_MUTEX(orangefs_help_file_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150)  * initialize kmod debug operations, create orangefs debugfs dir and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151)  * ORANGEFS_KMOD_DEBUG_HELP_FILE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) void orangefs_debugfs_init(int debug_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 	/* convert input debug mask to a 64-bit unsigned integer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156)         orangefs_gossip_debug_mask = (unsigned long long)debug_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 	 * set the kernel's gossip debug string; invalid mask values will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 	 * be ignored.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 	debug_mask_to_string(&orangefs_gossip_debug_mask, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 	/* remove any invalid values from the mask */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 	debug_string_to_mask(kernel_debug_string, &orangefs_gossip_debug_mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 	    0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 	 * if the mask has a non-zero value, then indicate that the mask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 	 * was set when the kernel module was loaded.  The orangefs dev ioctl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 	 * command will look at this boolean to determine if the kernel's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 	 * debug mask should be overwritten when the client-core is started.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 	if (orangefs_gossip_debug_mask != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 		kernel_mask_set_mod_init = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	pr_info("%s: called with debug mask: :%s: :%llx:\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 		__func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 		kernel_debug_string,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 		(unsigned long long)orangefs_gossip_debug_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 	debug_dir = debugfs_create_dir("orangefs", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 	debugfs_create_file(ORANGEFS_KMOD_DEBUG_HELP_FILE, 0444, debug_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 			    debug_help_string, &debug_help_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 	orangefs_debug_disabled = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 	orangefs_kernel_debug_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193)  * initialize the kernel-debug file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) static void orangefs_kernel_debug_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 	int rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 	char *k_buffer = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 	gossip_debug(GOSSIP_DEBUGFS_DEBUG, "%s: start\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	k_buffer = kzalloc(ORANGEFS_MAX_DEBUG_STRING_LEN, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 	if (!k_buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 	if (strlen(kernel_debug_string) + 1 < ORANGEFS_MAX_DEBUG_STRING_LEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 		strcpy(k_buffer, kernel_debug_string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 		strcat(k_buffer, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 		strcpy(k_buffer, "none\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 		pr_info("%s: overflow 1!\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 	debugfs_create_file(ORANGEFS_KMOD_DEBUG_FILE, 0444, debug_dir, k_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 			    &kernel_debug_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 	gossip_debug(GOSSIP_DEBUGFS_DEBUG, "%s: rc:%d:\n", __func__, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) void orangefs_debugfs_cleanup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 	debugfs_remove_recursive(debug_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) /* open ORANGEFS_KMOD_DEBUG_HELP_FILE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) static int orangefs_debug_help_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	int rc = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	gossip_debug(GOSSIP_DEBUGFS_DEBUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 		     "orangefs_debug_help_open: start\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 	if (orangefs_debug_disabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	ret = seq_open(file, &help_debug_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 	((struct seq_file *)(file->private_data))->private = inode->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 	rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 	gossip_debug(GOSSIP_DEBUGFS_DEBUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 		     "orangefs_debug_help_open: rc:%d:\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 		     rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255)  * I think start always gets called again after stop. Start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256)  * needs to return NULL when it is done. The whole "payload"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257)  * in this case is a single (long) string, so by the second
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258)  * time we get to start (pos = 1), we're done.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) static void *help_start(struct seq_file *m, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 	void *payload = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	gossip_debug(GOSSIP_DEBUGFS_DEBUG, "help_start: start\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	mutex_lock(&orangefs_help_file_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 	if (*pos == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 		payload = m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 	return payload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) static void *help_next(struct seq_file *m, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 	(*pos)++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 	gossip_debug(GOSSIP_DEBUGFS_DEBUG, "help_next: start\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) static void help_stop(struct seq_file *m, void *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 	gossip_debug(GOSSIP_DEBUGFS_DEBUG, "help_stop: start\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 	mutex_unlock(&orangefs_help_file_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) static int help_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 	gossip_debug(GOSSIP_DEBUGFS_DEBUG, "help_show: start\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	seq_puts(m, v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298)  * initialize the client-debug file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) static int orangefs_client_debug_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	int rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 	char *c_buffer = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 	gossip_debug(GOSSIP_DEBUGFS_DEBUG, "%s: start\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 	c_buffer = kzalloc(ORANGEFS_MAX_DEBUG_STRING_LEN, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 	if (!c_buffer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 	if (strlen(client_debug_string) + 1 < ORANGEFS_MAX_DEBUG_STRING_LEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 		strcpy(c_buffer, client_debug_string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 		strcat(c_buffer, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 		strcpy(c_buffer, "none\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 		pr_info("%s: overflow! 2\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 	client_debug_dentry = debugfs_create_file(ORANGEFS_CLIENT_DEBUG_FILE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 						  0444,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 						  debug_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 						  c_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 						  &kernel_debug_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 	rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 	gossip_debug(GOSSIP_DEBUGFS_DEBUG, "%s: rc:%d:\n", __func__, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) /* open ORANGEFS_KMOD_DEBUG_FILE or ORANGEFS_CLIENT_DEBUG_FILE.*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) static int orangefs_debug_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 	int rc = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 	gossip_debug(GOSSIP_DEBUGFS_DEBUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 		     "%s: orangefs_debug_disabled: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 		     __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 		     orangefs_debug_disabled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 	if (orangefs_debug_disabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 	rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 	mutex_lock(&orangefs_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 	file->private_data = inode->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 	mutex_unlock(&orangefs_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 	gossip_debug(GOSSIP_DEBUGFS_DEBUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 		     "orangefs_debug_open: rc: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 		     rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) static ssize_t orangefs_debug_read(struct file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 				 char __user *ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 				 size_t count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 				 loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 	char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 	int sprintf_ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 	ssize_t read_ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 	gossip_debug(GOSSIP_DEBUGFS_DEBUG, "orangefs_debug_read: start\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 	buf = kmalloc(ORANGEFS_MAX_DEBUG_STRING_LEN, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 	if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 	mutex_lock(&orangefs_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 	sprintf_ret = sprintf(buf, "%s", (char *)file->private_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 	mutex_unlock(&orangefs_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 	read_ret = simple_read_from_buffer(ubuf, count, ppos, buf, sprintf_ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 	kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 	gossip_debug(GOSSIP_DEBUGFS_DEBUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 		     "orangefs_debug_read: ret: %zu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 		     read_ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 	return read_ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) static ssize_t orangefs_debug_write(struct file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 				  const char __user *ubuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 				  size_t count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 				  loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 	char *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 	int rc = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	size_t silly = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 	char *debug_string;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 	struct orangefs_kernel_op_s *new_op = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 	struct client_debug_mask c_mask = { NULL, 0, 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 	char *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 	gossip_debug(GOSSIP_DEBUGFS_DEBUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 		"orangefs_debug_write: %pD\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 		file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 	if (count == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 	 * Thwart users who try to jamb a ridiculous number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 	 * of bytes into the debug file...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 	if (count > ORANGEFS_MAX_DEBUG_STRING_LEN + 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 		silly = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 		count = ORANGEFS_MAX_DEBUG_STRING_LEN + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 	buf = kzalloc(ORANGEFS_MAX_DEBUG_STRING_LEN, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 	if (!buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 	if (copy_from_user(buf, ubuf, count - 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 		gossip_debug(GOSSIP_DEBUGFS_DEBUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 			     "%s: copy_from_user failed!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 			     __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 	 * Map the keyword string from userspace into a valid debug mask.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 	 * The mapping process involves mapping the human-inputted string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	 * into a valid mask, and then rebuilding the string from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 	 * verified valid mask.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 	 * A service operation is required to set a new client-side
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 	 * debug mask.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 	if (!strcmp(file->f_path.dentry->d_name.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 		    ORANGEFS_KMOD_DEBUG_FILE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 		debug_string_to_mask(buf, &orangefs_gossip_debug_mask, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 		debug_mask_to_string(&orangefs_gossip_debug_mask, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 		debug_string = kernel_debug_string;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 		gossip_debug(GOSSIP_DEBUGFS_DEBUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 			     "New kernel debug string is %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 			     kernel_debug_string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 		/* Can't reset client debug mask if client is not running. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 		if (is_daemon_in_service()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 			pr_info("%s: Client not running :%d:\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 				__func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 				is_daemon_in_service());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 		debug_string_to_mask(buf, &c_mask, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 		debug_mask_to_string(&c_mask, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 		debug_string = client_debug_string;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 		new_op = op_alloc(ORANGEFS_VFS_OP_PARAM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 		if (!new_op) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 			pr_info("%s: op_alloc failed!\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 		new_op->upcall.req.param.op =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 			ORANGEFS_PARAM_REQUEST_OP_TWO_MASK_VALUES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 		new_op->upcall.req.param.type = ORANGEFS_PARAM_REQUEST_SET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 		memset(new_op->upcall.req.param.s_value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 		       0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 		       ORANGEFS_MAX_DEBUG_STRING_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 		sprintf(new_op->upcall.req.param.s_value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 			"%llx %llx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 			c_mask.mask1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 			c_mask.mask2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 		/* service_operation returns 0 on success... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 		rc = service_operation(new_op,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 				       "orangefs_param",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 					ORANGEFS_OP_INTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 		if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 			gossip_debug(GOSSIP_DEBUGFS_DEBUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 				     "%s: service_operation failed! rc:%d:\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 				     __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 				     rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 		op_release(new_op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 	mutex_lock(&orangefs_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 	s = file_inode(file)->i_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	memset(s, 0, ORANGEFS_MAX_DEBUG_STRING_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 	sprintf(s, "%s\n", debug_string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 	mutex_unlock(&orangefs_debug_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 	*ppos += count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 	if (silly)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 		rc = silly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 		rc = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 	gossip_debug(GOSSIP_DEBUGFS_DEBUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 		     "orangefs_debug_write: rc: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 		     rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 	kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512)  * After obtaining a string representation of the client's debug
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513)  * keywords and their associated masks, this function is called to build an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514)  * array of these values.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) static int orangefs_prepare_cdm_array(char *debug_array_string)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 	int rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 	char *cds_head = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 	char *cds_delimiter = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 	int keyword_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 	gossip_debug(GOSSIP_UTILS_DEBUG, "%s: start\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 	 * figure out how many elements the cdm_array needs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 	for (i = 0; i < strlen(debug_array_string); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 		if (debug_array_string[i] == '\n')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 			cdm_element_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 	if (!cdm_element_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 		pr_info("No elements in client debug array string!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 	cdm_array = kcalloc(cdm_element_count, sizeof(*cdm_array), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	if (!cdm_array) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 		rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 	cds_head = debug_array_string;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	for (i = 0; i < cdm_element_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 		cds_delimiter = strchr(cds_head, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 		*cds_delimiter = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 		keyword_len = strcspn(cds_head, " ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 		cdm_array[i].keyword = kzalloc(keyword_len + 1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 		if (!cdm_array[i].keyword) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 			rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 		sscanf(cds_head,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 		       "%s %llx %llx",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 		       cdm_array[i].keyword,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 		       (unsigned long long *)&(cdm_array[i].mask1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 		       (unsigned long long *)&(cdm_array[i].mask2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 		if (!strcmp(cdm_array[i].keyword, ORANGEFS_VERBOSE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 			client_verbose_index = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 		if (!strcmp(cdm_array[i].keyword, ORANGEFS_ALL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 			client_all_index = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 		cds_head = cds_delimiter + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 	rc = cdm_element_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 	gossip_debug(GOSSIP_UTILS_DEBUG, "%s: rc:%d:\n", __func__, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584)  * /sys/kernel/debug/orangefs/debug-help can be catted to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585)  * see all the available kernel and client debug keywords.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587)  * When orangefs.ko initializes, we have no idea what keywords the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588)  * client supports, nor their associated masks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590)  * We pass through this function once at module-load and stamp a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591)  * boilerplate "we don't know" message for the client in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592)  * debug-help file. We pass through here again when the client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593)  * starts and then we can fill out the debug-help file fully.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595)  * The client might be restarted any number of times between
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596)  * module reloads, we only build the debug-help file the first time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) int orangefs_prepare_debugfs_help_string(int at_boot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	char *client_title = "Client Debug Keywords:\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	char *kernel_title = "Kernel Debug Keywords:\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 	size_t string_size =  DEBUG_HELP_STRING_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	size_t result_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	size_t i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 	char *new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 	int rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 	gossip_debug(GOSSIP_UTILS_DEBUG, "%s: start\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 	if (at_boot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 		client_title = HELP_STRING_UNINITIALIZED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 	/* build a new debug_help_string. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	new = kzalloc(DEBUG_HELP_STRING_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	if (!new) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 		rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 	 * strlcat(dst, src, size) will append at most
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 	 * "size - strlen(dst) - 1" bytes of src onto dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 	 * null terminating the result, and return the total
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 	 * length of the string it tried to create.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 	 * We'll just plow through here building our new debug
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 	 * help string and let strlcat take care of assuring that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 	 * dst doesn't overflow.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	strlcat(new, client_title, string_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 	if (!at_boot) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634)                 /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 		 * fill the client keyword/mask array and remember
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 		 * how many elements there were.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 		cdm_element_count =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 			orangefs_prepare_cdm_array(client_debug_array_string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 		if (cdm_element_count <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 			kfree(new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 		for (i = 0; i < cdm_element_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 			strlcat(new, "\t", string_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 			strlcat(new, cdm_array[i].keyword, string_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 			strlcat(new, "\n", string_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 	strlcat(new, "\n", string_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	strlcat(new, kernel_title, string_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 	for (i = 0; i < num_kmod_keyword_mask_map; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 		strlcat(new, "\t", string_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 		strlcat(new, s_kmod_keyword_mask_map[i].keyword, string_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 		result_size = strlcat(new, "\n", string_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 	/* See if we tried to put too many bytes into "new"... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 	if (result_size >= string_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 		kfree(new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 	if (at_boot) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 		debug_help_string = new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 		mutex_lock(&orangefs_help_file_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 		memset(debug_help_string, 0, DEBUG_HELP_STRING_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 		strlcat(debug_help_string, new, string_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 		mutex_unlock(&orangefs_help_file_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 	rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) out:	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683)  * kernel = type 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684)  * client = type 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) static void debug_mask_to_string(void *mask, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 	int len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 	char *debug_string;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 	int element_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 	gossip_debug(GOSSIP_UTILS_DEBUG, "%s: start\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 	if (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 		debug_string = client_debug_string;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 		element_count = cdm_element_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 		debug_string = kernel_debug_string;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 		element_count = num_kmod_keyword_mask_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 	memset(debug_string, 0, ORANGEFS_MAX_DEBUG_STRING_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 	 * Some keywords, like "all" or "verbose", are amalgams of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 	 * numerous other keywords. Make a special check for those
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 	 * before grinding through the whole mask only to find out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 	 * later...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	if (check_amalgam_keyword(mask, type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	/* Build the debug string. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	for (i = 0; i < element_count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 		if (type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 			do_c_string(mask, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 			do_k_string(mask, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 	len = strlen(debug_string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	if ((len) && (type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 		client_debug_string[len - 1] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	else if (len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 		kernel_debug_string[len - 1] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	else if (type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 		strcpy(client_debug_string, "none");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 		strcpy(kernel_debug_string, "none");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) gossip_debug(GOSSIP_UTILS_DEBUG, "%s: string:%s:\n", __func__, debug_string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) static void do_k_string(void *k_mask, int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 	__u64 *mask = (__u64 *) k_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 	if (keyword_is_amalgam((char *) s_kmod_keyword_mask_map[index].keyword))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 	if (*mask & s_kmod_keyword_mask_map[index].mask_val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 		if ((strlen(kernel_debug_string) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 		     strlen(s_kmod_keyword_mask_map[index].keyword))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 			< ORANGEFS_MAX_DEBUG_STRING_LEN - 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 				strcat(kernel_debug_string,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 				       s_kmod_keyword_mask_map[index].keyword);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 				strcat(kernel_debug_string, ",");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 				gossip_err("%s: overflow!\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 				strcpy(kernel_debug_string, ORANGEFS_ALL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) static void do_c_string(void *c_mask, int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 	struct client_debug_mask *mask = (struct client_debug_mask *) c_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 	if (keyword_is_amalgam(cdm_array[index].keyword))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	if ((mask->mask1 & cdm_array[index].mask1) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 	    (mask->mask2 & cdm_array[index].mask2)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 		if ((strlen(client_debug_string) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 		     strlen(cdm_array[index].keyword) + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 			< ORANGEFS_MAX_DEBUG_STRING_LEN - 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 				strcat(client_debug_string,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 				       cdm_array[index].keyword);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 				strcat(client_debug_string, ",");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 				gossip_err("%s: overflow!\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 				strcpy(client_debug_string, ORANGEFS_ALL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) static int keyword_is_amalgam(char *keyword)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 	if ((!strcmp(keyword, ORANGEFS_ALL)) || (!strcmp(keyword, ORANGEFS_VERBOSE)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 		rc = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801)  * kernel = type 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802)  * client = type 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804)  * return 1 if we found an amalgam.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) static int check_amalgam_keyword(void *mask, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 	__u64 *k_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 	struct client_debug_mask *c_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 	int k_all_index = num_kmod_keyword_mask_map - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 	int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 	if (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 		c_mask = (struct client_debug_mask *) mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 		if ((c_mask->mask1 == cdm_array[client_all_index].mask1) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 		    (c_mask->mask2 == cdm_array[client_all_index].mask2)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 			strcpy(client_debug_string, ORANGEFS_ALL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 			rc = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 		if ((c_mask->mask1 == cdm_array[client_verbose_index].mask1) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 		    (c_mask->mask2 == cdm_array[client_verbose_index].mask2)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 			strcpy(client_debug_string, ORANGEFS_VERBOSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 			rc = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 		k_mask = (__u64 *) mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 		if (*k_mask >= s_kmod_keyword_mask_map[k_all_index].mask_val) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 			strcpy(kernel_debug_string, ORANGEFS_ALL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 			rc = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846)  * kernel = type 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847)  * client = type 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) static void debug_string_to_mask(char *debug_string, void *mask, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 	char *unchecked_keyword;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 	char *strsep_fodder = kstrdup(debug_string, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 	char *original_pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 	int element_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 	struct client_debug_mask *c_mask = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 	__u64 *k_mask = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 	gossip_debug(GOSSIP_UTILS_DEBUG, "%s: start\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 	if (type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 		c_mask = (struct client_debug_mask *)mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 		element_count = cdm_element_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 		k_mask = (__u64 *)mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 		*k_mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 		element_count = num_kmod_keyword_mask_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 	original_pointer = strsep_fodder;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 	while ((unchecked_keyword = strsep(&strsep_fodder, ",")))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 		if (strlen(unchecked_keyword)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 			for (i = 0; i < element_count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 				if (type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 					do_c_mask(i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 						  unchecked_keyword,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 						  &c_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 				else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 					do_k_mask(i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 						  unchecked_keyword,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 						  &k_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 	kfree(original_pointer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) static void do_c_mask(int i, char *unchecked_keyword,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888)     struct client_debug_mask **sane_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 	if (!strcmp(cdm_array[i].keyword, unchecked_keyword)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 		(**sane_mask).mask1 = (**sane_mask).mask1 | cdm_array[i].mask1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 		(**sane_mask).mask2 = (**sane_mask).mask2 | cdm_array[i].mask2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) static void do_k_mask(int i, char *unchecked_keyword, __u64 **sane_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 	if (!strcmp(s_kmod_keyword_mask_map[i].keyword, unchecked_keyword))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 		**sane_mask = (**sane_mask) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 				s_kmod_keyword_mask_map[i].mask_val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) int orangefs_debugfs_new_client_mask(void __user *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 	struct dev_mask2_info_s mask2_info = {0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 	ret = copy_from_user(&mask2_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 			     (void __user *)arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 			     sizeof(struct dev_mask2_info_s));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 	if (ret != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 	client_debug_mask.mask1 = mask2_info.mask1_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 	client_debug_mask.mask2 = mask2_info.mask2_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 	pr_info("%s: client debug mask has been been received "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 		":%llx: :%llx:\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 		__func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 		(unsigned long long)client_debug_mask.mask1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 		(unsigned long long)client_debug_mask.mask2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) int orangefs_debugfs_new_client_string(void __user *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 	ret = copy_from_user(&client_debug_array_string,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 			     (void __user *)arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 			     ORANGEFS_MAX_DEBUG_STRING_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 	if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 		pr_info("%s: CLIENT_STRING: copy_from_user failed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 			__func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	 * The real client-core makes an effort to ensure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 	 * that actual strings that aren't too long to fit in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 	 * this buffer is what we get here. We're going to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 	 * string functions on the stuff we got, so we'll make
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 	 * this extra effort to try and keep from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	 * flowing out of this buffer when we use the string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 	 * functions, even if somehow the stuff we end up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 	 * with here is garbage.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 	client_debug_array_string[ORANGEFS_MAX_DEBUG_STRING_LEN - 1] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 		'\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 	pr_info("%s: client debug array string has been received.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 		__func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 	if (!help_string_initialized) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 		/* Build a proper debug help string. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 		ret = orangefs_prepare_debugfs_help_string(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 			gossip_err("%s: no debug help string \n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 				   __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 	debug_mask_to_string(&client_debug_mask, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 	debugfs_remove(client_debug_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	orangefs_client_debug_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 	help_string_initialized++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) int orangefs_debugfs_new_debug(void __user *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	struct dev_mask_info_s mask_info = {0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 	ret = copy_from_user(&mask_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 			     (void __user *)arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 			     sizeof(mask_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 	if (ret != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	if (mask_info.mask_type == KERNEL_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 		if ((mask_info.mask_value == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 		    && (kernel_mask_set_mod_init)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 			 * the kernel debug mask was set when the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 			 * kernel module was loaded; don't override
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 			 * it if the client-core was started without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 			 * a value for ORANGEFS_KMODMASK.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 		debug_mask_to_string(&mask_info.mask_value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 				     mask_info.mask_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 		orangefs_gossip_debug_mask = mask_info.mask_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 		pr_info("%s: kernel debug mask has been modified to "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 			":%s: :%llx:\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 			__func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 			kernel_debug_string,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 			(unsigned long long)orangefs_gossip_debug_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	} else if (mask_info.mask_type == CLIENT_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 		debug_mask_to_string(&mask_info.mask_value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 				     mask_info.mask_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 		pr_info("%s: client debug mask has been modified to"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 			":%s: :%llx:\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 			__func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 			client_debug_string,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 			llu(mask_info.mask_value));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 		gossip_err("Invalid mask type....\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) }