Commit 44f46410 authored by Martin Brandenburg's avatar Martin Brandenburg

orangefs: clean up debugfs globals

Mostly this is moving code into orangefs-debugfs.c so that globals turn
into static globals.

Then gossip_debug_mask is renamed orangefs_gossip_debug_mask but keeps
global visibility, so it can be used from a macro.
Signed-off-by: default avatarMartin Brandenburg <martin@omnibond.com>
parent a21aae3b
......@@ -11,6 +11,7 @@
#include "orangefs-kernel.h"
#include "orangefs-dev-proto.h"
#include "orangefs-bufmap.h"
#include "orangefs-debugfs.h"
#include <linux/debugfs.h>
#include <linux/slab.h>
......@@ -576,8 +577,6 @@ static long dispatch_ioctl_command(unsigned int command, unsigned long arg)
static __s32 max_down_size = MAX_DEV_REQ_DOWNSIZE;
struct ORANGEFS_dev_map_desc user_desc;
int ret = 0;
struct dev_mask_info_s mask_info = { 0 };
struct dev_mask2_info_s mask2_info = { 0, 0 };
int upstream_kmod = 1;
struct orangefs_sb_info_s *orangefs_sb;
......@@ -668,134 +667,11 @@ static long dispatch_ioctl_command(unsigned int command, unsigned long arg)
return ret;
case ORANGEFS_DEV_CLIENT_MASK:
ret = copy_from_user(&mask2_info,
(void __user *)arg,
sizeof(struct dev_mask2_info_s));
if (ret != 0)
return -EIO;
client_debug_mask.mask1 = mask2_info.mask1_value;
client_debug_mask.mask2 = mask2_info.mask2_value;
pr_info("%s: client debug mask has been been received "
":%llx: :%llx:\n",
__func__,
(unsigned long long)client_debug_mask.mask1,
(unsigned long long)client_debug_mask.mask2);
return ret;
return orangefs_debugfs_new_client_mask((void __user *)arg);
case ORANGEFS_DEV_CLIENT_STRING:
ret = copy_from_user(&client_debug_array_string,
(void __user *)arg,
ORANGEFS_MAX_DEBUG_STRING_LEN);
/*
* The real client-core makes an effort to ensure
* that actual strings that aren't too long to fit in
* this buffer is what we get here. We're going to use
* string functions on the stuff we got, so we'll make
* this extra effort to try and keep from
* flowing out of this buffer when we use the string
* functions, even if somehow the stuff we end up
* with here is garbage.
*/
client_debug_array_string[ORANGEFS_MAX_DEBUG_STRING_LEN - 1] =
'\0';
if (ret != 0) {
pr_info("%s: CLIENT_STRING: copy_from_user failed\n",
__func__);
return -EIO;
}
pr_info("%s: client debug array string has been received.\n",
__func__);
if (!help_string_initialized) {
/* Free the "we don't know yet" default string... */
kfree(debug_help_string);
/* build a proper debug help string */
if (orangefs_prepare_debugfs_help_string(0)) {
gossip_err("%s: no debug help string \n",
__func__);
return -EIO;
}
/* Replace the boilerplate boot-time debug-help file. */
debugfs_remove(help_file_dentry);
help_file_dentry =
debugfs_create_file(
ORANGEFS_KMOD_DEBUG_HELP_FILE,
0444,
debug_dir,
debug_help_string,
&debug_help_fops);
if (!help_file_dentry) {
gossip_err("%s: debugfs_create_file failed for"
" :%s:!\n",
__func__,
ORANGEFS_KMOD_DEBUG_HELP_FILE);
return -EIO;
}
}
debug_mask_to_string(&client_debug_mask, 1);
debugfs_remove(client_debug_dentry);
orangefs_client_debug_init();
help_string_initialized++;
return ret;
return orangefs_debugfs_new_client_string((void __user *)arg);
case ORANGEFS_DEV_DEBUG:
ret = copy_from_user(&mask_info,
(void __user *)arg,
sizeof(mask_info));
if (ret != 0)
return -EIO;
if (mask_info.mask_type == KERNEL_MASK) {
if ((mask_info.mask_value == 0)
&& (kernel_mask_set_mod_init)) {
/*
* the kernel debug mask was set when the
* kernel module was loaded; don't override
* it if the client-core was started without
* a value for ORANGEFS_KMODMASK.
*/
return 0;
}
debug_mask_to_string(&mask_info.mask_value,
mask_info.mask_type);
gossip_debug_mask = mask_info.mask_value;
pr_info("%s: kernel debug mask has been modified to "
":%s: :%llx:\n",
__func__,
kernel_debug_string,
(unsigned long long)gossip_debug_mask);
} else if (mask_info.mask_type == CLIENT_MASK) {
debug_mask_to_string(&mask_info.mask_value,
mask_info.mask_type);
pr_info("%s: client debug mask has been modified to"
":%s: :%llx:\n",
__func__,
client_debug_string,
llu(mask_info.mask_value));
} else {
gossip_lerr("Invalid mask type....\n");
return -EINVAL;
}
return ret;
return orangefs_debugfs_new_debug((void __user *)arg);
default:
return -ENOIOCTLCMD;
}
......
This diff is collapsed.
int orangefs_debugfs_init(void);
int orangefs_kernel_debug_init(void);
int orangefs_debugfs_init(int);
void orangefs_debugfs_cleanup(void);
int orangefs_client_debug_init(void);
int orangefs_prepare_debugfs_help_string(int);
int orangefs_debugfs_new_client_mask(void __user *);
int orangefs_debugfs_new_client_string(void __user *);
int orangefs_debugfs_new_debug(void __user *);
......@@ -99,16 +99,6 @@ enum orangefs_vfs_op_states {
OP_VFS_STATE_GIVEN_UP = 16,
};
/*
* 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;
};
/*
* orangefs kernel memory related flags
*/
......@@ -119,29 +109,6 @@ struct client_debug_mask {
#define ORANGEFS_CACHE_CREATE_FLAGS 0
#endif /* ((defined ORANGEFS_KERNEL_DEBUG) && (defined CONFIG_DEBUG_SLAB)) */
/* these functions are defined in orangefs-utils.c */
int orangefs_prepare_cdm_array(char *debug_array_string);
int orangefs_prepare_debugfs_help_string(int);
/* defined in orangefs-debugfs.c */
int orangefs_client_debug_init(void);
void debug_string_to_mask(char *, void *, int);
void do_c_mask(int, char *, struct client_debug_mask **);
void do_k_mask(int, char *, __u64 **);
void debug_mask_to_string(void *, int);
void do_k_string(void *, int);
void do_c_string(void *, int);
int check_amalgam_keyword(void *, int);
int keyword_is_amalgam(char *);
/*these variables are defined in orangefs-mod.c */
extern char kernel_debug_string[ORANGEFS_MAX_DEBUG_STRING_LEN];
extern char client_debug_string[ORANGEFS_MAX_DEBUG_STRING_LEN];
extern char client_debug_array_string[ORANGEFS_MAX_DEBUG_STRING_LEN];
extern unsigned int kernel_mask_set_mod_init;
extern int orangefs_init_acl(struct inode *inode, struct inode *dir);
extern const struct xattr_handler *orangefs_xattr_handlers[];
......
......@@ -21,30 +21,13 @@
* global variables declared here
*/
/* array of client debug keyword/mask values */
struct client_debug_mask *cdm_array;
int cdm_element_count;
char kernel_debug_string[ORANGEFS_MAX_DEBUG_STRING_LEN] = "none";
char client_debug_string[ORANGEFS_MAX_DEBUG_STRING_LEN];
char client_debug_array_string[ORANGEFS_MAX_DEBUG_STRING_LEN];
char *debug_help_string;
int help_string_initialized;
struct dentry *help_file_dentry;
struct dentry *client_debug_dentry;
struct dentry *debug_dir;
int client_verbose_index;
int client_all_index;
struct orangefs_stats g_orangefs_stats;
/* the size of the hash tables for ops in progress */
int hash_table_size = 509;
static ulong module_parm_debug_mask;
__u64 gossip_debug_mask;
struct client_debug_mask client_debug_mask = { NULL, 0, 0 };
unsigned int kernel_mask_set_mod_init; /* implicitly false */
__u64 orangefs_gossip_debug_mask;
int op_timeout_secs = ORANGEFS_DEFAULT_OP_TIMEOUT_SECS;
int slot_timeout_secs = ORANGEFS_DEFAULT_SLOT_TIMEOUT_SECS;
int dcache_timeout_msecs = 50;
......@@ -100,32 +83,6 @@ static int __init orangefs_init(void)
int ret = -1;
__u32 i = 0;
/* convert input debug mask to a 64-bit unsigned integer */
gossip_debug_mask = (unsigned long long) module_parm_debug_mask;
/*
* set the kernel's gossip debug string; invalid mask values will
* be ignored.
*/
debug_mask_to_string(&gossip_debug_mask, 0);
/* remove any invalid values from the mask */
debug_string_to_mask(kernel_debug_string, &gossip_debug_mask, 0);
/*
* if the mask has a non-zero value, then indicate that the mask
* was set when the kernel module was loaded. The orangefs dev ioctl
* command will look at this boolean to determine if the kernel's
* debug mask should be overwritten when the client-core is started.
*/
if (gossip_debug_mask != 0)
kernel_mask_set_mod_init = true;
pr_info("%s: called with debug mask: :%s: :%llx:\n",
__func__,
kernel_debug_string,
(unsigned long long)gossip_debug_mask);
ret = bdi_init(&orangefs_backing_dev_info);
if (ret)
......@@ -179,14 +136,10 @@ static int __init orangefs_init(void)
if (ret)
goto cleanup_key_table;
ret = orangefs_debugfs_init();
ret = orangefs_debugfs_init(module_parm_debug_mask);
if (ret)
goto debugfs_init_failed;
ret = orangefs_kernel_debug_init();
if (ret)
goto kernel_debug_init_failed;
ret = orangefs_sysfs_init();
if (ret)
goto sysfs_init_failed;
......@@ -214,8 +167,6 @@ static int __init orangefs_init(void)
sysfs_init_failed:
kernel_debug_init_failed:
debugfs_init_failed:
orangefs_debugfs_cleanup();
......
......@@ -656,401 +656,3 @@ __s32 ORANGEFS_util_translate_mode(int mode)
return ret;
}
#undef NUM_MODES
/*
* After obtaining a string representation of the client's debug
* keywords and their associated masks, this function is called to build an
* array of these values.
*/
int orangefs_prepare_cdm_array(char *debug_array_string)
{
int i;
int rc = -EINVAL;
char *cds_head = NULL;
char *cds_delimiter = NULL;
int keyword_len = 0;
gossip_debug(GOSSIP_UTILS_DEBUG, "%s: start\n", __func__);
/*
* figure out how many elements the cdm_array needs.
*/
for (i = 0; i < strlen(debug_array_string); i++)
if (debug_array_string[i] == '\n')
cdm_element_count++;
if (!cdm_element_count) {
pr_info("No elements in client debug array string!\n");
goto out;
}
cdm_array =
kzalloc(cdm_element_count * sizeof(struct client_debug_mask),
GFP_KERNEL);
if (!cdm_array) {
pr_info("malloc failed for cdm_array!\n");
rc = -ENOMEM;
goto out;
}
cds_head = debug_array_string;
for (i = 0; i < cdm_element_count; i++) {
cds_delimiter = strchr(cds_head, '\n');
*cds_delimiter = '\0';
keyword_len = strcspn(cds_head, " ");
cdm_array[i].keyword = kzalloc(keyword_len + 1, GFP_KERNEL);
if (!cdm_array[i].keyword) {
rc = -ENOMEM;
goto out;
}
sscanf(cds_head,
"%s %llx %llx",
cdm_array[i].keyword,
(unsigned long long *)&(cdm_array[i].mask1),
(unsigned long long *)&(cdm_array[i].mask2));
if (!strcmp(cdm_array[i].keyword, ORANGEFS_VERBOSE))
client_verbose_index = i;
if (!strcmp(cdm_array[i].keyword, ORANGEFS_ALL))
client_all_index = i;
cds_head = cds_delimiter + 1;
}
rc = cdm_element_count;
gossip_debug(GOSSIP_UTILS_DEBUG, "%s: rc:%d:\n", __func__, rc);
out:
return rc;
}
/*
* /sys/kernel/debug/orangefs/debug-help can be catted to
* see all the available kernel and client debug keywords.
*
* When the kernel boots, we have no idea what keywords the
* client supports, nor their associated masks.
*
* We pass through this function once at boot and stamp a
* boilerplate "we don't know" message for the client in the
* debug-help file. We pass through here again when the client
* starts and then we can fill out the debug-help file fully.
*
* The client might be restarted any number of times between
* reboots, we only build the debug-help file the first time.
*/
int orangefs_prepare_debugfs_help_string(int at_boot)
{
int rc = -EINVAL;
int i;
int byte_count = 0;
char *client_title = "Client Debug Keywords:\n";
char *kernel_title = "Kernel Debug Keywords:\n";
gossip_debug(GOSSIP_UTILS_DEBUG, "%s: start\n", __func__);
if (at_boot) {
byte_count += strlen(HELP_STRING_UNINITIALIZED);
client_title = HELP_STRING_UNINITIALIZED;
} else {
/*
* fill the client keyword/mask array and remember
* how many elements there were.
*/
cdm_element_count =
orangefs_prepare_cdm_array(client_debug_array_string);
if (cdm_element_count <= 0)
goto out;
/* Count the bytes destined for debug_help_string. */
byte_count += strlen(client_title);
for (i = 0; i < cdm_element_count; i++) {
byte_count += strlen(cdm_array[i].keyword + 2);
if (byte_count >= DEBUG_HELP_STRING_SIZE) {
pr_info("%s: overflow 1!\n", __func__);
goto out;
}
}
gossip_debug(GOSSIP_UTILS_DEBUG,
"%s: cdm_element_count:%d:\n",
__func__,
cdm_element_count);
}
byte_count += strlen(kernel_title);
for (i = 0; i < num_kmod_keyword_mask_map; i++) {
byte_count +=
strlen(s_kmod_keyword_mask_map[i].keyword + 2);
if (byte_count >= DEBUG_HELP_STRING_SIZE) {
pr_info("%s: overflow 2!\n", __func__);
goto out;
}
}
/* build debug_help_string. */
debug_help_string = kzalloc(DEBUG_HELP_STRING_SIZE, GFP_KERNEL);
if (!debug_help_string) {
rc = -ENOMEM;
goto out;
}
strcat(debug_help_string, client_title);
if (!at_boot) {
for (i = 0; i < cdm_element_count; i++) {
strcat(debug_help_string, "\t");
strcat(debug_help_string, cdm_array[i].keyword);
strcat(debug_help_string, "\n");
}
}
strcat(debug_help_string, "\n");
strcat(debug_help_string, kernel_title);
for (i = 0; i < num_kmod_keyword_mask_map; i++) {
strcat(debug_help_string, "\t");
strcat(debug_help_string, s_kmod_keyword_mask_map[i].keyword);
strcat(debug_help_string, "\n");
}
rc = 0;
out:
return rc;
}
/*
* kernel = type 0
* client = type 1
*/
void debug_mask_to_string(void *mask, int type)
{
int i;
int len = 0;
char *debug_string;
int element_count = 0;
gossip_debug(GOSSIP_UTILS_DEBUG, "%s: start\n", __func__);
if (type) {
debug_string = client_debug_string;
element_count = cdm_element_count;
} else {
debug_string = kernel_debug_string;
element_count = num_kmod_keyword_mask_map;
}
memset(debug_string, 0, ORANGEFS_MAX_DEBUG_STRING_LEN);
/*
* Some keywords, like "all" or "verbose", are amalgams of
* numerous other keywords. Make a special check for those
* before grinding through the whole mask only to find out
* later...
*/
if (check_amalgam_keyword(mask, type))
goto out;
/* Build the debug string. */
for (i = 0; i < element_count; i++)
if (type)
do_c_string(mask, i);
else
do_k_string(mask, i);
len = strlen(debug_string);
if ((len) && (type))
client_debug_string[len - 1] = '\0';
else if (len)
kernel_debug_string[len - 1] = '\0';
else if (type)
strcpy(client_debug_string, "none");
else
strcpy(kernel_debug_string, "none");
out:
gossip_debug(GOSSIP_UTILS_DEBUG, "%s: string:%s:\n", __func__, debug_string);
return;
}
void do_k_string(void *k_mask, int index)
{
__u64 *mask = (__u64 *) k_mask;
if (keyword_is_amalgam((char *) s_kmod_keyword_mask_map[index].keyword))
goto out;
if (*mask & s_kmod_keyword_mask_map[index].mask_val) {
if ((strlen(kernel_debug_string) +
strlen(s_kmod_keyword_mask_map[index].keyword))
< ORANGEFS_MAX_DEBUG_STRING_LEN - 1) {
strcat(kernel_debug_string,
s_kmod_keyword_mask_map[index].keyword);
strcat(kernel_debug_string, ",");
} else {
gossip_err("%s: overflow!\n", __func__);
strcpy(kernel_debug_string, ORANGEFS_ALL);
goto out;
}
}
out:
return;
}
void do_c_string(void *c_mask, int index)
{
struct client_debug_mask *mask = (struct client_debug_mask *) c_mask;
if (keyword_is_amalgam(cdm_array[index].keyword))
goto out;
if ((mask->mask1 & cdm_array[index].mask1) ||
(mask->mask2 & cdm_array[index].mask2)) {
if ((strlen(client_debug_string) +
strlen(cdm_array[index].keyword) + 1)
< ORANGEFS_MAX_DEBUG_STRING_LEN - 2) {
strcat(client_debug_string,
cdm_array[index].keyword);
strcat(client_debug_string, ",");
} else {
gossip_err("%s: overflow!\n", __func__);
strcpy(client_debug_string, ORANGEFS_ALL);
goto out;
}
}
out:
return;
}
int keyword_is_amalgam(char *keyword)
{
int rc = 0;
if ((!strcmp(keyword, ORANGEFS_ALL)) || (!strcmp(keyword, ORANGEFS_VERBOSE)))
rc = 1;
return rc;
}
/*
* kernel = type 0
* client = type 1
*
* return 1 if we found an amalgam.
*/
int check_amalgam_keyword(void *mask, int type)
{
__u64 *k_mask;
struct client_debug_mask *c_mask;
int k_all_index = num_kmod_keyword_mask_map - 1;
int rc = 0;
if (type) {
c_mask = (struct client_debug_mask *) mask;
if ((c_mask->mask1 == cdm_array[client_all_index].mask1) &&
(c_mask->mask2 == cdm_array[client_all_index].mask2)) {
strcpy(client_debug_string, ORANGEFS_ALL);
rc = 1;
goto out;
}
if ((c_mask->mask1 == cdm_array[client_verbose_index].mask1) &&
(c_mask->mask2 == cdm_array[client_verbose_index].mask2)) {
strcpy(client_debug_string, ORANGEFS_VERBOSE);
rc = 1;
goto out;
}
} else {
k_mask = (__u64 *) mask;
if (*k_mask >= s_kmod_keyword_mask_map[k_all_index].mask_val) {
strcpy(kernel_debug_string, ORANGEFS_ALL);
rc = 1;
goto out;
}
}
out:
return rc;
}
/*
* kernel = type 0
* client = type 1
*/
void debug_string_to_mask(char *debug_string, void *mask, int type)
{
char *unchecked_keyword;
int i;
char *strsep_fodder = kstrdup(debug_string, GFP_KERNEL);
char *original_pointer;
int element_count = 0;
struct client_debug_mask *c_mask;
__u64 *k_mask;
gossip_debug(GOSSIP_UTILS_DEBUG, "%s: start\n", __func__);
if (type) {
c_mask = (struct client_debug_mask *)mask;
element_count = cdm_element_count;
} else {
k_mask = (__u64 *)mask;
*k_mask = 0;
element_count = num_kmod_keyword_mask_map;
}
original_pointer = strsep_fodder;
while ((unchecked_keyword = strsep(&strsep_fodder, ",")))
if (strlen(unchecked_keyword)) {
for (i = 0; i < element_count; i++)
if (type)
do_c_mask(i,
unchecked_keyword,
&c_mask);
else
do_k_mask(i,
unchecked_keyword,
&k_mask);
}
kfree(original_pointer);
}
void do_c_mask(int i,
char *unchecked_keyword,
struct client_debug_mask **sane_mask)
{
if (!strcmp(cdm_array[i].keyword, unchecked_keyword)) {
(**sane_mask).mask1 = (**sane_mask).mask1 | cdm_array[i].mask1;
(**sane_mask).mask2 = (**sane_mask).mask2 | cdm_array[i].mask2;
}
}
void do_k_mask(int i, char *unchecked_keyword, __u64 **sane_mask)
{
if (!strcmp(s_kmod_keyword_mask_map[i].keyword, unchecked_keyword))
**sane_mask = (**sane_mask) |
s_kmod_keyword_mask_map[i].mask_val;
}
......@@ -4,26 +4,6 @@
#include <linux/slab.h>
#include <linux/ioctl.h>
extern struct client_debug_mask *cdm_array;
extern char *debug_help_string;
extern int help_string_initialized;
extern struct dentry *debug_dir;
extern struct dentry *help_file_dentry;
extern struct dentry *client_debug_dentry;
extern const struct file_operations debug_help_fops;
extern int client_all_index;
extern int client_verbose_index;
extern int cdm_element_count;
#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"
/* pvfs2-config.h ***********************************************************/
#define ORANGEFS_VERSION_MAJOR 2
#define ORANGEFS_VERSION_MINOR 9
......@@ -426,13 +406,12 @@ do { \
printk(KERN_DEBUG fmt, ##__VA_ARGS__); \
} while (0)
#else
extern __u64 gossip_debug_mask;
extern struct client_debug_mask client_debug_mask;
extern __u64 orangefs_gossip_debug_mask;
/* try to avoid function call overhead by checking masks in macro */
#define gossip_debug(mask, fmt, ...) \
do { \
if (gossip_debug_mask & (mask)) \
if (orangefs_gossip_debug_mask & (mask)) \
printk(KERN_DEBUG fmt, ##__VA_ARGS__); \
} while (0)
#endif /* GOSSIP_DISABLE_DEBUG */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment