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