forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-09-20 a36159eec6ca17402b0e146b86efaf76568dc353
kernel/fs/ocfs2/dlm/dlmdebug.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /* -*- mode: c; c-basic-offset: 8; -*-
23 * vim: noexpandtab sw=8 ts=8 sts=0:
34 *
....@@ -6,22 +7,6 @@
67 * debug functionality for the dlm
78 *
89 * Copyright (C) 2004, 2008 Oracle. All rights reserved.
9
- *
10
- * This program is free software; you can redistribute it and/or
11
- * modify it under the terms of the GNU General Public
12
- * License as published by the Free Software Foundation; either
13
- * version 2 of the License, or (at your option) any later version.
14
- *
15
- * This program is distributed in the hope that it will be useful,
16
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
- * General Public License for more details.
19
- *
20
- * You should have received a copy of the GNU General Public
21
- * License along with this program; if not, write to the
22
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23
- * Boston, MA 021110-1307, USA.
24
- *
2510 */
2611
2712 #include <linux/types.h>
....@@ -32,9 +17,9 @@
3217 #include <linux/debugfs.h>
3318 #include <linux/export.h>
3419
35
-#include "cluster/heartbeat.h"
36
-#include "cluster/nodemanager.h"
37
-#include "cluster/tcp.h"
20
+#include "../cluster/heartbeat.h"
21
+#include "../cluster/nodemanager.h"
22
+#include "../cluster/tcp.h"
3823
3924 #include "dlmapi.h"
4025 #include "dlmcommon.h"
....@@ -42,7 +27,7 @@
4227 #include "dlmdebug.h"
4328
4429 #define MLOG_MASK_PREFIX ML_DLM
45
-#include "cluster/masklog.h"
30
+#include "../cluster/masklog.h"
4631
4732 static int stringify_lockname(const char *lockname, int locklen, char *buf,
4833 int len);
....@@ -259,11 +244,11 @@
259244 memcpy((__be64 *)&inode_blkno_be,
260245 (char *)&lockname[OCFS2_DENTRY_LOCK_INO_START],
261246 sizeof(__be64));
262
- out += snprintf(buf + out, len - out, "%.*s%08x",
247
+ out += scnprintf(buf + out, len - out, "%.*s%08x",
263248 OCFS2_DENTRY_LOCK_INO_START - 1, lockname,
264249 (unsigned int)be64_to_cpu(inode_blkno_be));
265250 } else
266
- out += snprintf(buf + out, len - out, "%.*s",
251
+ out += scnprintf(buf + out, len - out, "%.*s",
267252 locklen, lockname);
268253 return out;
269254 }
....@@ -275,7 +260,7 @@
275260 int i = -1;
276261
277262 while ((i = find_next_bit(nodemap, maxnodes, i + 1)) < maxnodes)
278
- out += snprintf(buf + out, len - out, "%d ", i);
263
+ out += scnprintf(buf + out, len - out, "%d ", i);
279264
280265 return out;
281266 }
....@@ -293,34 +278,34 @@
293278 mle_type = "MIG";
294279
295280 out += stringify_lockname(mle->mname, mle->mnamelen, buf + out, len - out);
296
- out += snprintf(buf + out, len - out,
281
+ out += scnprintf(buf + out, len - out,
297282 "\t%3s\tmas=%3u\tnew=%3u\tevt=%1d\tuse=%1d\tref=%3d\n",
298283 mle_type, mle->master, mle->new_master,
299284 !list_empty(&mle->hb_events),
300285 !!mle->inuse,
301286 kref_read(&mle->mle_refs));
302287
303
- out += snprintf(buf + out, len - out, "Maybe=");
288
+ out += scnprintf(buf + out, len - out, "Maybe=");
304289 out += stringify_nodemap(mle->maybe_map, O2NM_MAX_NODES,
305290 buf + out, len - out);
306
- out += snprintf(buf + out, len - out, "\n");
291
+ out += scnprintf(buf + out, len - out, "\n");
307292
308
- out += snprintf(buf + out, len - out, "Vote=");
293
+ out += scnprintf(buf + out, len - out, "Vote=");
309294 out += stringify_nodemap(mle->vote_map, O2NM_MAX_NODES,
310295 buf + out, len - out);
311
- out += snprintf(buf + out, len - out, "\n");
296
+ out += scnprintf(buf + out, len - out, "\n");
312297
313
- out += snprintf(buf + out, len - out, "Response=");
298
+ out += scnprintf(buf + out, len - out, "Response=");
314299 out += stringify_nodemap(mle->response_map, O2NM_MAX_NODES,
315300 buf + out, len - out);
316
- out += snprintf(buf + out, len - out, "\n");
301
+ out += scnprintf(buf + out, len - out, "\n");
317302
318
- out += snprintf(buf + out, len - out, "Node=");
303
+ out += scnprintf(buf + out, len - out, "Node=");
319304 out += stringify_nodemap(mle->node_map, O2NM_MAX_NODES,
320305 buf + out, len - out);
321
- out += snprintf(buf + out, len - out, "\n");
306
+ out += scnprintf(buf + out, len - out, "\n");
322307
323
- out += snprintf(buf + out, len - out, "\n");
308
+ out += scnprintf(buf + out, len - out, "\n");
324309
325310 return out;
326311 }
....@@ -368,7 +353,7 @@
368353 int out = 0;
369354 unsigned long total = 0;
370355
371
- out += snprintf(buf + out, len - out,
356
+ out += scnprintf(buf + out, len - out,
372357 "Dumping Purgelist for Domain: %s\n", dlm->name);
373358
374359 spin_lock(&dlm->spinlock);
....@@ -380,13 +365,13 @@
380365 out += stringify_lockname(res->lockname.name,
381366 res->lockname.len,
382367 buf + out, len - out);
383
- out += snprintf(buf + out, len - out, "\t%ld\n",
368
+ out += scnprintf(buf + out, len - out, "\t%ld\n",
384369 (jiffies - res->last_used)/HZ);
385370 spin_unlock(&res->spinlock);
386371 }
387372 spin_unlock(&dlm->spinlock);
388373
389
- out += snprintf(buf + out, len - out, "Total on list: %lu\n", total);
374
+ out += scnprintf(buf + out, len - out, "Total on list: %lu\n", total);
390375
391376 return out;
392377 }
....@@ -425,7 +410,7 @@
425410 int i, out = 0;
426411 unsigned long total = 0, longest = 0, bucket_count = 0;
427412
428
- out += snprintf(buf + out, len - out,
413
+ out += scnprintf(buf + out, len - out,
429414 "Dumping MLEs for Domain: %s\n", dlm->name);
430415
431416 spin_lock(&dlm->master_lock);
....@@ -443,7 +428,7 @@
443428 }
444429 spin_unlock(&dlm->master_lock);
445430
446
- out += snprintf(buf + out, len - out,
431
+ out += scnprintf(buf + out, len - out,
447432 "Total: %lu, Longest: %lu\n", total, longest);
448433 return out;
449434 }
....@@ -482,7 +467,7 @@
482467
483468 #define DEBUG_LOCK_VERSION 1
484469 spin_lock(&lock->spinlock);
485
- out = snprintf(buf, len, "LOCK:%d,%d,%d,%d,%d,%d:%lld,%d,%d,%d,%d,%d,"
470
+ out = scnprintf(buf, len, "LOCK:%d,%d,%d,%d,%d,%d:%lld,%d,%d,%d,%d,%d,"
486471 "%d,%d,%d,%d\n",
487472 DEBUG_LOCK_VERSION,
488473 list_type, lock->ml.type, lock->ml.convert_type,
....@@ -506,13 +491,13 @@
506491 int i;
507492 int out = 0;
508493
509
- out += snprintf(buf + out, len - out, "NAME:");
494
+ out += scnprintf(buf + out, len - out, "NAME:");
510495 out += stringify_lockname(res->lockname.name, res->lockname.len,
511496 buf + out, len - out);
512
- out += snprintf(buf + out, len - out, "\n");
497
+ out += scnprintf(buf + out, len - out, "\n");
513498
514499 #define DEBUG_LRES_VERSION 1
515
- out += snprintf(buf + out, len - out,
500
+ out += scnprintf(buf + out, len - out,
516501 "LRES:%d,%d,%d,%ld,%d,%d,%d,%d,%d,%d,%d\n",
517502 DEBUG_LRES_VERSION,
518503 res->owner, res->state, res->last_used,
....@@ -524,17 +509,17 @@
524509 kref_read(&res->refs));
525510
526511 /* refmap */
527
- out += snprintf(buf + out, len - out, "RMAP:");
512
+ out += scnprintf(buf + out, len - out, "RMAP:");
528513 out += stringify_nodemap(res->refmap, O2NM_MAX_NODES,
529514 buf + out, len - out);
530
- out += snprintf(buf + out, len - out, "\n");
515
+ out += scnprintf(buf + out, len - out, "\n");
531516
532517 /* lvb */
533
- out += snprintf(buf + out, len - out, "LVBX:");
518
+ out += scnprintf(buf + out, len - out, "LVBX:");
534519 for (i = 0; i < DLM_LVB_LEN; i++)
535
- out += snprintf(buf + out, len - out,
520
+ out += scnprintf(buf + out, len - out,
536521 "%02x", (unsigned char)res->lvb[i]);
537
- out += snprintf(buf + out, len - out, "\n");
522
+ out += scnprintf(buf + out, len - out, "\n");
538523
539524 /* granted */
540525 list_for_each_entry(lock, &res->granted, list)
....@@ -548,7 +533,7 @@
548533 list_for_each_entry(lock, &res->blocked, list)
549534 out += dump_lock(lock, 2, buf + out, len - out);
550535
551
- out += snprintf(buf + out, len - out, "\n");
536
+ out += scnprintf(buf + out, len - out, "\n");
552537
553538 return out;
554539 }
....@@ -698,41 +683,41 @@
698683 }
699684
700685 /* Domain: xxxxxxxxxx Key: 0xdfbac769 */
701
- out += snprintf(buf + out, len - out,
686
+ out += scnprintf(buf + out, len - out,
702687 "Domain: %s Key: 0x%08x Protocol: %d.%d\n",
703688 dlm->name, dlm->key, dlm->dlm_locking_proto.pv_major,
704689 dlm->dlm_locking_proto.pv_minor);
705690
706691 /* Thread Pid: xxx Node: xxx State: xxxxx */
707
- out += snprintf(buf + out, len - out,
692
+ out += scnprintf(buf + out, len - out,
708693 "Thread Pid: %d Node: %d State: %s\n",
709694 task_pid_nr(dlm->dlm_thread_task), dlm->node_num, state);
710695
711696 /* Number of Joins: xxx Joining Node: xxx */
712
- out += snprintf(buf + out, len - out,
697
+ out += scnprintf(buf + out, len - out,
713698 "Number of Joins: %d Joining Node: %d\n",
714699 dlm->num_joins, dlm->joining_node);
715700
716701 /* Domain Map: xx xx xx */
717
- out += snprintf(buf + out, len - out, "Domain Map: ");
702
+ out += scnprintf(buf + out, len - out, "Domain Map: ");
718703 out += stringify_nodemap(dlm->domain_map, O2NM_MAX_NODES,
719704 buf + out, len - out);
720
- out += snprintf(buf + out, len - out, "\n");
705
+ out += scnprintf(buf + out, len - out, "\n");
721706
722707 /* Exit Domain Map: xx xx xx */
723
- out += snprintf(buf + out, len - out, "Exit Domain Map: ");
708
+ out += scnprintf(buf + out, len - out, "Exit Domain Map: ");
724709 out += stringify_nodemap(dlm->exit_domain_map, O2NM_MAX_NODES,
725710 buf + out, len - out);
726
- out += snprintf(buf + out, len - out, "\n");
711
+ out += scnprintf(buf + out, len - out, "\n");
727712
728713 /* Live Map: xx xx xx */
729
- out += snprintf(buf + out, len - out, "Live Map: ");
714
+ out += scnprintf(buf + out, len - out, "Live Map: ");
730715 out += stringify_nodemap(dlm->live_nodes_map, O2NM_MAX_NODES,
731716 buf + out, len - out);
732
- out += snprintf(buf + out, len - out, "\n");
717
+ out += scnprintf(buf + out, len - out, "\n");
733718
734719 /* Lock Resources: xxx (xxx) */
735
- out += snprintf(buf + out, len - out,
720
+ out += scnprintf(buf + out, len - out,
736721 "Lock Resources: %d (%d)\n",
737722 atomic_read(&dlm->res_cur_count),
738723 atomic_read(&dlm->res_tot_count));
....@@ -744,29 +729,29 @@
744729 cur_mles += atomic_read(&dlm->mle_cur_count[i]);
745730
746731 /* MLEs: xxx (xxx) */
747
- out += snprintf(buf + out, len - out,
732
+ out += scnprintf(buf + out, len - out,
748733 "MLEs: %d (%d)\n", cur_mles, tot_mles);
749734
750735 /* Blocking: xxx (xxx) */
751
- out += snprintf(buf + out, len - out,
736
+ out += scnprintf(buf + out, len - out,
752737 " Blocking: %d (%d)\n",
753738 atomic_read(&dlm->mle_cur_count[DLM_MLE_BLOCK]),
754739 atomic_read(&dlm->mle_tot_count[DLM_MLE_BLOCK]));
755740
756741 /* Mastery: xxx (xxx) */
757
- out += snprintf(buf + out, len - out,
742
+ out += scnprintf(buf + out, len - out,
758743 " Mastery: %d (%d)\n",
759744 atomic_read(&dlm->mle_cur_count[DLM_MLE_MASTER]),
760745 atomic_read(&dlm->mle_tot_count[DLM_MLE_MASTER]));
761746
762747 /* Migration: xxx (xxx) */
763
- out += snprintf(buf + out, len - out,
748
+ out += scnprintf(buf + out, len - out,
764749 " Migration: %d (%d)\n",
765750 atomic_read(&dlm->mle_cur_count[DLM_MLE_MIGRATION]),
766751 atomic_read(&dlm->mle_tot_count[DLM_MLE_MIGRATION]));
767752
768753 /* Lists: Dirty=Empty Purge=InUse PendingASTs=Empty ... */
769
- out += snprintf(buf + out, len - out,
754
+ out += scnprintf(buf + out, len - out,
770755 "Lists: Dirty=%s Purge=%s PendingASTs=%s "
771756 "PendingBASTs=%s\n",
772757 (list_empty(&dlm->dirty_list) ? "Empty" : "InUse"),
....@@ -775,12 +760,12 @@
775760 (list_empty(&dlm->pending_basts) ? "Empty" : "InUse"));
776761
777762 /* Purge Count: xxx Refs: xxx */
778
- out += snprintf(buf + out, len - out,
763
+ out += scnprintf(buf + out, len - out,
779764 "Purge Count: %d Refs: %d\n", dlm->purge_count,
780765 kref_read(&dlm->dlm_refs));
781766
782767 /* Dead Node: xxx */
783
- out += snprintf(buf + out, len - out,
768
+ out += scnprintf(buf + out, len - out,
784769 "Dead Node: %d\n", dlm->reco.dead_node);
785770
786771 /* What about DLM_RECO_STATE_FINALIZE? */
....@@ -790,19 +775,19 @@
790775 state = "INACTIVE";
791776
792777 /* Recovery Pid: xxxx Master: xxx State: xxxx */
793
- out += snprintf(buf + out, len - out,
778
+ out += scnprintf(buf + out, len - out,
794779 "Recovery Pid: %d Master: %d State: %s\n",
795780 task_pid_nr(dlm->dlm_reco_thread_task),
796781 dlm->reco.new_master, state);
797782
798783 /* Recovery Map: xx xx */
799
- out += snprintf(buf + out, len - out, "Recovery Map: ");
784
+ out += scnprintf(buf + out, len - out, "Recovery Map: ");
800785 out += stringify_nodemap(dlm->recovery_map, O2NM_MAX_NODES,
801786 buf + out, len - out);
802
- out += snprintf(buf + out, len - out, "\n");
787
+ out += scnprintf(buf + out, len - out, "\n");
803788
804789 /* Recovery Node State: */
805
- out += snprintf(buf + out, len - out, "Recovery Node State:\n");
790
+ out += scnprintf(buf + out, len - out, "Recovery Node State:\n");
806791 list_for_each_entry(node, &dlm->reco.node_data, list) {
807792 switch (node->state) {
808793 case DLM_RECO_NODE_DATA_INIT:
....@@ -830,7 +815,7 @@
830815 state = "BAD";
831816 break;
832817 }
833
- out += snprintf(buf + out, len - out, "\t%u - %s\n",
818
+ out += scnprintf(buf + out, len - out, "\t%u - %s\n",
834819 node->node_num, state);
835820 }
836821
....@@ -866,109 +851,42 @@
866851 /* end - debug state funcs */
867852
868853 /* files in subroot */
869
-int dlm_debug_init(struct dlm_ctxt *dlm)
854
+void dlm_debug_init(struct dlm_ctxt *dlm)
870855 {
871
- struct dlm_debug_ctxt *dc = dlm->dlm_debug_ctxt;
872
-
873856 /* for dumping dlm_ctxt */
874
- dc->debug_state_dentry = debugfs_create_file(DLM_DEBUGFS_DLM_STATE,
875
- S_IFREG|S_IRUSR,
876
- dlm->dlm_debugfs_subroot,
877
- dlm, &debug_state_fops);
878
- if (!dc->debug_state_dentry) {
879
- mlog_errno(-ENOMEM);
880
- goto bail;
881
- }
857
+ debugfs_create_file(DLM_DEBUGFS_DLM_STATE, S_IFREG|S_IRUSR,
858
+ dlm->dlm_debugfs_subroot, dlm, &debug_state_fops);
882859
883860 /* for dumping lockres */
884
- dc->debug_lockres_dentry =
885
- debugfs_create_file(DLM_DEBUGFS_LOCKING_STATE,
886
- S_IFREG|S_IRUSR,
887
- dlm->dlm_debugfs_subroot,
888
- dlm, &debug_lockres_fops);
889
- if (!dc->debug_lockres_dentry) {
890
- mlog_errno(-ENOMEM);
891
- goto bail;
892
- }
861
+ debugfs_create_file(DLM_DEBUGFS_LOCKING_STATE, S_IFREG|S_IRUSR,
862
+ dlm->dlm_debugfs_subroot, dlm, &debug_lockres_fops);
893863
894864 /* for dumping mles */
895
- dc->debug_mle_dentry = debugfs_create_file(DLM_DEBUGFS_MLE_STATE,
896
- S_IFREG|S_IRUSR,
897
- dlm->dlm_debugfs_subroot,
898
- dlm, &debug_mle_fops);
899
- if (!dc->debug_mle_dentry) {
900
- mlog_errno(-ENOMEM);
901
- goto bail;
902
- }
865
+ debugfs_create_file(DLM_DEBUGFS_MLE_STATE, S_IFREG|S_IRUSR,
866
+ dlm->dlm_debugfs_subroot, dlm, &debug_mle_fops);
903867
904868 /* for dumping lockres on the purge list */
905
- dc->debug_purgelist_dentry =
906
- debugfs_create_file(DLM_DEBUGFS_PURGE_LIST,
907
- S_IFREG|S_IRUSR,
908
- dlm->dlm_debugfs_subroot,
909
- dlm, &debug_purgelist_fops);
910
- if (!dc->debug_purgelist_dentry) {
911
- mlog_errno(-ENOMEM);
912
- goto bail;
913
- }
914
-
915
- return 0;
916
-
917
-bail:
918
- return -ENOMEM;
919
-}
920
-
921
-void dlm_debug_shutdown(struct dlm_ctxt *dlm)
922
-{
923
- struct dlm_debug_ctxt *dc = dlm->dlm_debug_ctxt;
924
-
925
- if (dc) {
926
- debugfs_remove(dc->debug_purgelist_dentry);
927
- debugfs_remove(dc->debug_mle_dentry);
928
- debugfs_remove(dc->debug_lockres_dentry);
929
- debugfs_remove(dc->debug_state_dentry);
930
- kfree(dc);
931
- dc = NULL;
932
- }
869
+ debugfs_create_file(DLM_DEBUGFS_PURGE_LIST, S_IFREG|S_IRUSR,
870
+ dlm->dlm_debugfs_subroot, dlm,
871
+ &debug_purgelist_fops);
933872 }
934873
935874 /* subroot - domain dir */
936
-int dlm_create_debugfs_subroot(struct dlm_ctxt *dlm)
875
+void dlm_create_debugfs_subroot(struct dlm_ctxt *dlm)
937876 {
938877 dlm->dlm_debugfs_subroot = debugfs_create_dir(dlm->name,
939878 dlm_debugfs_root);
940
- if (!dlm->dlm_debugfs_subroot) {
941
- mlog_errno(-ENOMEM);
942
- goto bail;
943
- }
944
-
945
- dlm->dlm_debug_ctxt = kzalloc(sizeof(struct dlm_debug_ctxt),
946
- GFP_KERNEL);
947
- if (!dlm->dlm_debug_ctxt) {
948
- mlog_errno(-ENOMEM);
949
- goto bail;
950
- }
951
-
952
- return 0;
953
-bail:
954
- dlm_destroy_debugfs_subroot(dlm);
955
- return -ENOMEM;
956879 }
957880
958881 void dlm_destroy_debugfs_subroot(struct dlm_ctxt *dlm)
959882 {
960
- debugfs_remove(dlm->dlm_debugfs_subroot);
883
+ debugfs_remove_recursive(dlm->dlm_debugfs_subroot);
961884 }
962885
963886 /* debugfs root */
964
-int dlm_create_debugfs_root(void)
887
+void dlm_create_debugfs_root(void)
965888 {
966889 dlm_debugfs_root = debugfs_create_dir(DLM_DEBUGFS_DIR, NULL);
967
- if (!dlm_debugfs_root) {
968
- mlog_errno(-ENOMEM);
969
- return -ENOMEM;
970
- }
971
- return 0;
972890 }
973891
974892 void dlm_destroy_debugfs_root(void)