2 * What: /sys/kernel/debug/orangefs/debug-help
4 * Contact: Mike Marshall <hubcap@omnibond.com>
6 * List of client and kernel debug keywords.
9 * What: /sys/kernel/debug/orangefs/client-debug
11 * Contact: Mike Marshall <hubcap@omnibond.com>
13 * Debug setting for "the client", the userspace
14 * helper for the kernel module.
17 * What: /sys/kernel/debug/orangefs/kernel-debug
19 * Contact: Mike Marshall <hubcap@omnibond.com>
21 * Debug setting for the orangefs kernel module.
23 * Any of the keywords, or comma-separated lists
24 * of keywords, from debug-help can be catted to
25 * client-debug or kernel-debug.
27 * "none", "all" and "verbose" are special keywords
28 * for client-debug. Setting client-debug to "all"
29 * is kind of like trying to drink water from a
30 * fire hose, "verbose" triggers most of the same
31 * output except for the constant flow of output
32 * from the main wait loop.
34 * "none" and "all" are similar settings for kernel-debug
35 * no need for a "verbose".
37 #include <linux/debugfs.h>
38 #include <linux/slab.h>
40 #include <linux/uaccess.h>
42 #include "orangefs-debugfs.h"
44 #include "orangefs-kernel.h"
46 static int orangefs_debug_disabled
= 1;
48 static int orangefs_debug_help_open(struct inode
*, struct file
*);
50 const struct file_operations debug_help_fops
= {
51 .open
= orangefs_debug_help_open
,
53 .release
= seq_release
,
57 static void *help_start(struct seq_file
*, loff_t
*);
58 static void *help_next(struct seq_file
*, void *, loff_t
*);
59 static void help_stop(struct seq_file
*, void *);
60 static int help_show(struct seq_file
*, void *);
62 static const struct seq_operations help_debug_ops
= {
70 * Used to protect data in ORANGEFS_KMOD_DEBUG_FILE and
71 * ORANGEFS_KMOD_DEBUG_FILE.
73 static DEFINE_MUTEX(orangefs_debug_lock
);
75 int orangefs_debug_open(struct inode
*, struct file
*);
77 static ssize_t
orangefs_debug_read(struct file
*,
82 static ssize_t
orangefs_debug_write(struct file
*,
87 static const struct file_operations kernel_debug_fops
= {
88 .open
= orangefs_debug_open
,
89 .read
= orangefs_debug_read
,
90 .write
= orangefs_debug_write
,
91 .llseek
= generic_file_llseek
,
95 * initialize kmod debug operations, create orangefs debugfs dir and
96 * ORANGEFS_KMOD_DEBUG_HELP_FILE.
98 int orangefs_debugfs_init(void)
103 debug_dir
= debugfs_create_dir("orangefs", NULL
);
107 help_file_dentry
= debugfs_create_file(ORANGEFS_KMOD_DEBUG_HELP_FILE
,
112 if (!help_file_dentry
)
115 orangefs_debug_disabled
= 0;
120 orangefs_debugfs_cleanup();
125 void orangefs_debugfs_cleanup(void)
127 debugfs_remove_recursive(debug_dir
);
130 /* open ORANGEFS_KMOD_DEBUG_HELP_FILE */
131 static int orangefs_debug_help_open(struct inode
*inode
, struct file
*file
)
136 gossip_debug(GOSSIP_DEBUGFS_DEBUG
,
137 "orangefs_debug_help_open: start\n");
139 if (orangefs_debug_disabled
)
142 ret
= seq_open(file
, &help_debug_ops
);
146 ((struct seq_file
*)(file
->private_data
))->private = inode
->i_private
;
151 gossip_debug(GOSSIP_DEBUGFS_DEBUG
,
152 "orangefs_debug_help_open: rc:%d:\n",
158 * I think start always gets called again after stop. Start
159 * needs to return NULL when it is done. The whole "payload"
160 * in this case is a single (long) string, so by the second
161 * time we get to start (pos = 1), we're done.
163 static void *help_start(struct seq_file
*m
, loff_t
*pos
)
165 void *payload
= NULL
;
167 gossip_debug(GOSSIP_DEBUGFS_DEBUG
, "help_start: start\n");
170 payload
= m
->private;
175 static void *help_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
177 gossip_debug(GOSSIP_DEBUGFS_DEBUG
, "help_next: start\n");
182 static void help_stop(struct seq_file
*m
, void *p
)
184 gossip_debug(GOSSIP_DEBUGFS_DEBUG
, "help_stop: start\n");
187 static int help_show(struct seq_file
*m
, void *v
)
189 gossip_debug(GOSSIP_DEBUGFS_DEBUG
, "help_show: start\n");
197 * initialize the kernel-debug file.
199 int orangefs_kernel_debug_init(void)
204 char *k_buffer
= NULL
;
206 gossip_debug(GOSSIP_DEBUGFS_DEBUG
, "%s: start\n", __func__
);
208 k_buffer
= kzalloc(ORANGEFS_MAX_DEBUG_STRING_LEN
, GFP_KERNEL
);
212 if (strlen(kernel_debug_string
) + 1 < ORANGEFS_MAX_DEBUG_STRING_LEN
) {
213 strcpy(k_buffer
, kernel_debug_string
);
214 strcat(k_buffer
, "\n");
216 strcpy(k_buffer
, "none\n");
217 pr_info("%s: overflow 1!\n", __func__
);
220 ret
= debugfs_create_file(ORANGEFS_KMOD_DEBUG_FILE
,
226 pr_info("%s: failed to create %s.\n",
228 ORANGEFS_KMOD_DEBUG_FILE
);
236 orangefs_debugfs_cleanup();
238 gossip_debug(GOSSIP_DEBUGFS_DEBUG
, "%s: rc:%d:\n", __func__
, rc
);
243 * initialize the client-debug file.
245 int orangefs_client_debug_init(void)
249 char *c_buffer
= NULL
;
251 gossip_debug(GOSSIP_DEBUGFS_DEBUG
, "%s: start\n", __func__
);
253 c_buffer
= kzalloc(ORANGEFS_MAX_DEBUG_STRING_LEN
, GFP_KERNEL
);
257 if (strlen(client_debug_string
) + 1 < ORANGEFS_MAX_DEBUG_STRING_LEN
) {
258 strcpy(c_buffer
, client_debug_string
);
259 strcat(c_buffer
, "\n");
261 strcpy(c_buffer
, "none\n");
262 pr_info("%s: overflow! 2\n", __func__
);
265 client_debug_dentry
= debugfs_create_file(ORANGEFS_CLIENT_DEBUG_FILE
,
270 if (!client_debug_dentry
) {
271 pr_info("%s: failed to create %s.\n",
273 ORANGEFS_CLIENT_DEBUG_FILE
);
281 orangefs_debugfs_cleanup();
283 gossip_debug(GOSSIP_DEBUGFS_DEBUG
, "%s: rc:%d:\n", __func__
, rc
);
287 /* open ORANGEFS_KMOD_DEBUG_FILE or ORANGEFS_CLIENT_DEBUG_FILE.*/
288 int orangefs_debug_open(struct inode
*inode
, struct file
*file
)
292 gossip_debug(GOSSIP_DEBUGFS_DEBUG
,
293 "%s: orangefs_debug_disabled: %d\n",
295 orangefs_debug_disabled
);
297 if (orangefs_debug_disabled
)
301 mutex_lock(&orangefs_debug_lock
);
302 file
->private_data
= inode
->i_private
;
303 mutex_unlock(&orangefs_debug_lock
);
306 gossip_debug(GOSSIP_DEBUGFS_DEBUG
,
307 "orangefs_debug_open: rc: %d\n",
312 static ssize_t
orangefs_debug_read(struct file
*file
,
319 ssize_t read_ret
= -ENOMEM
;
321 gossip_debug(GOSSIP_DEBUGFS_DEBUG
, "orangefs_debug_read: start\n");
323 buf
= kmalloc(ORANGEFS_MAX_DEBUG_STRING_LEN
, GFP_KERNEL
);
327 mutex_lock(&orangefs_debug_lock
);
328 sprintf_ret
= sprintf(buf
, "%s", (char *)file
->private_data
);
329 mutex_unlock(&orangefs_debug_lock
);
331 read_ret
= simple_read_from_buffer(ubuf
, count
, ppos
, buf
, sprintf_ret
);
336 gossip_debug(GOSSIP_DEBUGFS_DEBUG
,
337 "orangefs_debug_read: ret: %zu\n",
343 static ssize_t
orangefs_debug_write(struct file
*file
,
344 const char __user
*ubuf
,
352 struct orangefs_kernel_op_s
*new_op
= NULL
;
353 struct client_debug_mask c_mask
= { NULL
, 0, 0 };
355 gossip_debug(GOSSIP_DEBUGFS_DEBUG
,
356 "orangefs_debug_write: %s\n",
357 file
->f_path
.dentry
->d_name
.name
);
360 * Thwart users who try to jamb a ridiculous number
361 * of bytes into the debug file...
363 if (count
> ORANGEFS_MAX_DEBUG_STRING_LEN
+ 1) {
365 count
= ORANGEFS_MAX_DEBUG_STRING_LEN
+ 1;
368 buf
= kzalloc(ORANGEFS_MAX_DEBUG_STRING_LEN
, GFP_KERNEL
);
372 if (copy_from_user(buf
, ubuf
, count
- 1)) {
373 gossip_debug(GOSSIP_DEBUGFS_DEBUG
,
374 "%s: copy_from_user failed!\n",
380 * Map the keyword string from userspace into a valid debug mask.
381 * The mapping process involves mapping the human-inputted string
382 * into a valid mask, and then rebuilding the string from the
383 * verified valid mask.
385 * A service operation is required to set a new client-side
388 if (!strcmp(file
->f_path
.dentry
->d_name
.name
,
389 ORANGEFS_KMOD_DEBUG_FILE
)) {
390 debug_string_to_mask(buf
, &gossip_debug_mask
, 0);
391 debug_mask_to_string(&gossip_debug_mask
, 0);
392 debug_string
= kernel_debug_string
;
393 gossip_debug(GOSSIP_DEBUGFS_DEBUG
,
394 "New kernel debug string is %s\n",
395 kernel_debug_string
);
397 /* Can't reset client debug mask if client is not running. */
398 if (is_daemon_in_service()) {
399 pr_info("%s: Client not running :%d:\n",
401 is_daemon_in_service());
405 debug_string_to_mask(buf
, &c_mask
, 1);
406 debug_mask_to_string(&c_mask
, 1);
407 debug_string
= client_debug_string
;
409 new_op
= op_alloc(ORANGEFS_VFS_OP_PARAM
);
411 pr_info("%s: op_alloc failed!\n", __func__
);
415 new_op
->upcall
.req
.param
.op
=
416 ORANGEFS_PARAM_REQUEST_OP_TWO_MASK_VALUES
;
417 new_op
->upcall
.req
.param
.type
= ORANGEFS_PARAM_REQUEST_SET
;
418 memset(new_op
->upcall
.req
.param
.s_value
,
420 ORANGEFS_MAX_DEBUG_STRING_LEN
);
421 sprintf(new_op
->upcall
.req
.param
.s_value
,
426 /* service_operation returns 0 on success... */
427 rc
= service_operation(new_op
,
429 ORANGEFS_OP_INTERRUPTIBLE
);
432 gossip_debug(GOSSIP_DEBUGFS_DEBUG
,
433 "%s: service_operation failed! rc:%d:\n",
440 mutex_lock(&orangefs_debug_lock
);
441 memset(file
->f_inode
->i_private
, 0, ORANGEFS_MAX_DEBUG_STRING_LEN
);
442 sprintf((char *)file
->f_inode
->i_private
, "%s\n", debug_string
);
443 mutex_unlock(&orangefs_debug_lock
);
452 gossip_debug(GOSSIP_DEBUGFS_DEBUG
,
453 "orangefs_debug_write: rc: %d\n",