/*
* What: /sys/kernel/debug/orangefs/debug-help
* Date: June 2015
* Contact: Mike Marshall <hubcap@omnibond.com>
* Description:
* List of client and kernel debug keywords.
*
*
* What: /sys/kernel/debug/orangefs/client-debug
* Date: June 2015
* Contact: Mike Marshall <hubcap@omnibond.com>
* Description:
* Debug setting for "the client", the userspace
* helper for the kernel module.
*
*
* What: /sys/kernel/debug/orangefs/kernel-debug
* Date: June 2015
* Contact: Mike Marshall <hubcap@omnibond.com>
* Description:
* Debug setting for the orangefs kernel module.
*
* Any of the keywords, or comma-separated lists
* of keywords, from debug-help can be catted to
* client-debug or kernel-debug.
*
* "none", "all" and "verbose" are special keywords
* for client-debug. Setting client-debug to "all"
* is kind of like trying to drink water from a
* fire hose, "verbose" triggers most of the same
* output except for the constant flow of output
* from the main wait loop.
*
* "none" and "all" are similar settings for kernel-debug
* no need for a "verbose".
*/
#include <linux/debugfs.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
#include "orangefs-debugfs.h"
#include "protocol.h"
#include "orangefs-kernel.h"
#define DEBUG_HELP_STRING_SIZE 4096
#define HELP_STRING_UNINITIALIZED \
"Client Debug Keywords are unknown until the first time\n" \
"the client is started after boot.\n"
#define ORANGEFS_KMOD_DEBUG_HELP_FILE "debug-help"
#define ORANGEFS_KMOD_DEBUG_FILE "kernel-debug"
#define ORANGEFS_CLIENT_DEBUG_FILE "client-debug"
#define ORANGEFS_VERBOSE "verbose"
#define ORANGEFS_ALL "all"
/*
* An array of client_debug_mask will be built to hold debug keyword/mask
* values fetched from userspace.
*/
struct client_debug_mask {
char *keyword;
__u64 mask1;
__u64 mask2;
};
static int orangefs_kernel_debug_init(void);
static int orangefs_debug_help_open(struct inode *, struct file *);
static void *help_start(struct seq_file *, loff_t *);
static void *help_next(struct seq_file *, void *, loff_t *);
static void help_stop(struct seq_file *, void *);
static int help_show(struct seq_file *, void *);
static int orangefs_debug_open(struct inode *, struct file *);
static ssize_t orangefs_debug_read(struct file *,
char __user *,
size_t,
loff_t *);
static ssize_t orangefs_debug_write(struct file *,
const char __user *,
size_t,
loff_t *);
static int orangefs_prepare_cdm_array(char *);
static void debug_mask_to_string(void *, int);
static void do_k_string(void *, int);
static void do_c_string(void *, int);
static int keyword_is_amalgam(char *);
static int check_amalgam_keyword(void *, int);
static void debug_string_to_mask(char *, void *, int);
static void do_c_mask(int, char *, struct client_debug_mask **);
static void do_k_mask(int, char *, __u64 **);
static char kernel_debug_string[ORANGEFS_MAX_DEBUG_STRING_LEN] = "none";
static char *debug_help_string;
static char client_debug_string[ORANGEFS_MAX_DEBUG_STRING_LEN];
static char client_debug_array_string[ORANGEFS_MAX_DEBUG_STRING_LEN];
static struct dentry *help_file_dentry;
static struct dentry *client_debug_dentry;
static struct dentry *debug_dir;
static unsigned int kernel_mask_set_mod_init;
static int orangefs_debug_disabled = 1;
static int help_string_initialized;
static const struct seq_operations help_debug_ops = {
.start = help_start,
.next = help_next,
.stop = help_stop,
.show = help_show,
};
const struct file_operations debug_help_fops = {
.open = orangefs_debug_help_open,
.read = seq_read,
.release = seq_release,
.llseek = seq_lseek,
};
static const struct file_operations kernel_debug_fops = {
.open = orangefs_debug_open,
.read = orangefs_debug_read,
.write = orangefs_debug_write,
.llseek = generic_file_llseek,
};
static int client_all_index;
static int client_verbose_index;
static struct client_debug_mask *cdm_array;
static int cdm_element_count;
static struct client_debug_mask client_debug_mask;
/*
* Used to protect data in ORANGEFS_KMOD_DEBUG_FILE and
* ORANGEFS_KMOD_DEBUG_FILE.
*/
static DEFINE_MUTEX(orangefs_debug_lock);
/*
* initialize kmod debug operations, create orangefs debugfs dir and
* ORANGEFS_KMOD_DEBUG_HELP_FILE.
*/
int orangefs_debugfs_init(