4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 1991, 1998, 2001 by Sun Microsystems, Inc.
24 * All rights reserved.
28 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
29 * Copyright (c) 2012 by Delphix. All rights reserved.
32 #include <sys/types.h>
39 #include <rpc/rpc_msg.h>
41 #include <rpcsvc/nlm_prot.h>
44 extern char *dlc_header
;
45 extern jmp_buf xdr_err
;
47 extern void check_retransmit();
48 static void interpret_nlm_1();
49 static void interpret_nlm_3();
50 static void interpret_nlm_4();
51 static char *nameof_access();
52 static char *nameof_mode();
53 static char *nameof_stat();
54 static char *nameof_stat4();
55 static void show_cancargs();
56 static void show_cancargs4();
57 static void show_lock();
58 static void show_lock4();
59 static void show_lockargs();
60 static void show_lockargs4();
61 static void show_netobj();
62 static void show_nlm_access();
63 static void show_nlm_mode();
64 static void show_notify();
65 static void show_res();
66 static void show_res4();
67 static void show_share();
68 static void show_shareargs();
69 static void show_shareres();
70 static void show_shareres4();
71 static enum nlm_stats
show_stat();
72 static enum nlm4_stats
show_stat4();
73 static void show_testargs();
74 static void show_testargs4();
75 static void show_testres();
76 static void show_testres4();
77 static void show_unlockargs();
78 static void show_unlockargs4();
79 static void skip_netobj();
80 static char *sum_lock();
81 static char *sum_lock4();
82 static char *sum_netobj();
83 static char *sum_notify();
84 static char *sum_share();
87 interpret_nlm(flags
, type
, xid
, vers
, proc
, data
, len
)
88 int flags
, type
, xid
, vers
, proc
;
93 case 1: interpret_nlm_1(flags
, type
, xid
, vers
, proc
, data
, len
);
95 case 3: interpret_nlm_3(flags
, type
, xid
, vers
, proc
, data
, len
);
97 case 4: interpret_nlm_4(flags
, type
, xid
, vers
, proc
, data
, len
);
103 /* ------------ V E R S I O N 1 ---------------------------------- */
105 static char *procnames_short_1
[] = {
114 "CANCEL MSG1", /* 8 */
115 "UNLOCK MSG1", /* 9 */
116 "GRANTED MSG1", /* 10 */
117 "TEST RES1", /* 11 */
118 "LOCK RES1", /* 12 */
119 "CANCEL RES1", /* 13 */
120 "UNLOCK RES1", /* 14 */
121 "GRANTED RES1", /* 15 */
124 static char *procnames_long_1
[] = {
125 "Null procedure", /* 0 */
131 "Test message", /* 6 */
132 "Lock message", /* 7 */
133 "Cancel message", /* 8 */
134 "Unlock message", /* 9 */
135 "Granted message", /* 10 */
136 "Test result", /* 11 */
137 "Lock result", /* 12 */
138 "Cancel result", /* 13 */
139 "Unlock result", /* 14 */
140 "Granted result", /* 15 */
143 /* Highest procedure number that officially belongs to version 1. */
148 interpret_nlm_1(flags
, type
, xid
, vers
, proc
, data
, len
)
149 int flags
, type
, xid
, vers
, proc
;
155 if (proc
< 0 || proc
> MAXPROC_1
)
159 if (setjmp(xdr_err
)) {
163 line
= get_sum_line();
168 procnames_short_1
[proc
]);
169 line
+= strlen(line
);
174 case NLM_GRANTED_MSG
:
176 (void) strcat(line
, sum_netobj("OH"));
177 (void) getxdr_bool(); /* Excl */
178 (void) strcat(line
, sum_lock());
183 (void) strcat(line
, sum_netobj("OH"));
184 (void) getxdr_bool(); /* Block */
185 (void) getxdr_bool(); /* Excl */
186 (void) strcat(line
, sum_lock());
191 (void) strcat(line
, sum_netobj("OH"));
192 (void) getxdr_bool(); /* Block */
193 (void) getxdr_bool(); /* Excl */
194 (void) strcat(line
, sum_lock());
199 (void) strcat(line
, sum_netobj("OH"));
200 (void) strcat(line
, sum_lock());
204 (void) strcat(line
, sum_netobj("OH"));
205 (void) strcat(line
, " ");
207 nameof_stat(getxdr_u_long()));
212 case NLM_GRANTED_RES
:
214 (void) strcat(line
, sum_netobj("OH"));
215 (void) strcat(line
, " ");
217 nameof_stat(getxdr_u_long()));
220 check_retransmit(line
, (ulong_t
)xid
);
222 (void) sprintf(line
, "NLM R %s",
223 procnames_short_1
[proc
]);
224 line
+= strlen(line
);
228 (void) strcat(line
, sum_netobj("OH"));
229 (void) strcat(line
, " ");
231 nameof_stat(getxdr_u_long()));
238 (void) strcat(line
, sum_netobj("OH"));
239 (void) strcat(line
, " ");
241 nameof_stat(getxdr_u_long()));
247 if (flags
& F_DTAIL
) {
248 show_header("NLM: ", "Network Lock Manager", len
);
250 if (setjmp(xdr_err
)) {
253 (void) sprintf(get_line(0, 0),
255 proc
, procnames_long_1
[proc
]);
261 case NLM_GRANTED_MSG
:
282 case NLM_GRANTED_RES
:
301 case NLM_GRANTED_MSG
:
306 case NLM_GRANTED_RES
:
314 #define roundup(sz) ((sz / 4 + (sz % 4 > 0)) * 4)
318 * Make sure an integral number of words
324 int sz
= getxdr_u_long();
326 xdr_skip(roundup(sz
));
335 static char buff
[32];
337 sz
= getxdr_u_long();
338 for (i
= 0; i
< sz
; i
+= 4) {
340 sum
^= (l
>> 16) ^ l
;
342 (void) sprintf(buff
, " %s=%04X", handle
, sum
& 0xFFFF);
355 sz
= getxdr_u_long(); /* size of the netobj */
358 (void) sprintf(get_line(0, 0), fmt
, "<null>");
361 (void) strcpy(buff
, fmt
);
363 chunk
= sz
> 16 ? 16 : sz
;
365 (void) showxdr_hex(chunk
, buff
);
367 * For every line after the first, blank out
368 * everything in the format string before the "%s".
370 for (p
= buff
; *p
!= '%'; p
++)
381 static char buff
[LM_MAXSTRLEN
+ 1];
386 (void) getxdr_string(buff
, LM_MAXSTRLEN
); /* Caller */
387 (void) strcpy(buff
, sum_netobj("FH")); /* Fh */
389 skip_netobj(); /* Owner */
391 off
= getxdr_u_long();
392 len
= getxdr_u_long();
393 (void) sprintf(cp
, " PID=%ld Region=%lu:%lu", id
, off
, len
);
400 showxdr_string(LM_MAXSTRLEN
, "Caller = %s");
401 show_netobj("Filehandle = %s");
402 show_netobj("Lock owner = %s");
403 showxdr_long("Svid = %ld (process id)");
404 showxdr_u_long("Offset = %lu bytes");
405 showxdr_u_long("Length = %lu bytes");
411 show_netobj("Cookie = %s");
412 showxdr_bool("Block = %s");
413 showxdr_bool("Exclusive = %s");
420 show_netobj("Cookie = %s");
421 showxdr_bool("Block = %s");
422 showxdr_bool("Exclusive = %s");
424 showxdr_bool("Reclaim = %s");
425 showxdr_long("State = %ld");
431 show_netobj("Cookie = %s");
438 show_netobj("Cookie = %s");
439 showxdr_bool("Exclusive = %s");
446 show_netobj("Cookie = %s");
454 switch ((enum nlm_stats
) s
) {
455 case nlm_granted
: return ("granted");
456 case nlm_denied
: return ("denied");
457 case nlm_denied_nolocks
:return ("denied (no locks)");
458 case nlm_blocked
: return ("blocked");
459 case nlm_denied_grace_period
: return ("denied (grace period)");
460 case nlm_deadlck
: return ("deadlock");
461 default: return ("?");
465 static enum nlm_stats
470 s
= (enum nlm_stats
) getxdr_u_long();
471 (void) sprintf(get_line(0, 0),
473 s
, nameof_stat((ulong_t
)s
));
481 show_netobj("Cookie = %s");
482 if (show_stat() == nlm_denied
) {
483 showxdr_bool("Exclusive = %s");
484 showxdr_long("Svid = %ld (process id)");
485 show_netobj("Owner handle = %s");
486 showxdr_u_long("Offset = %lu bytes");
487 showxdr_u_long("Length = %lu bytes");
492 /* ------------ V E R S I O N 3 ---------------------------------- */
494 static char *procnames_short_3
[] = {
501 static char *procnames_long_3
[] = {
504 "Unmonitored lock", /* 22 */
508 /* Maximum procedure number for version 3. */
512 interpret_nlm_3(flags
, type
, xid
, vers
, proc
, data
, len
)
513 int flags
, type
, xid
, vers
, proc
;
520 if (proc
< 0 || proc
> MAXPROC_3
)
524 * Version 3 is a superset of version 1
526 if (proc
>= 0 && proc
<= MAXPROC_1
) {
527 interpret_nlm_1(flags
, type
, xid
, vers
, proc
, data
, len
);
532 if (setjmp(xdr_err
)) {
536 line
= get_sum_line();
541 procnames_short_3
[proc
-20]);
542 line
+= strlen(line
);
546 (void) strcat(line
, sum_netobj("OH"));
547 (void) strcat(line
, sum_share());
552 (void) getxdr_u_long(); /* Block */
553 (void) getxdr_u_long(); /* Excl */
554 (void) strcat(line
, sum_lock());
558 " %s", sum_notify());
561 check_retransmit(line
, (ulong_t
)xid
);
563 (void) sprintf(line
, "NLM R %s",
564 procnames_short_3
[proc
-20]);
565 line
+= strlen(line
);
569 pl
= sum_netobj("OH");
571 sprintf(line
, "%s %s %ld",
572 pl
, nameof_stat(i
), getxdr_long());
576 (void) strcat(line
, sum_netobj("OH"));
577 (void) strcat(line
, " ");
579 nameof_stat(getxdr_u_long()));
587 if (flags
& F_DTAIL
) {
588 show_header("NLM: ", "Network Lock Manager", len
);
590 if (setjmp(xdr_err
)) {
593 (void) sprintf(get_line(0, 0),
595 proc
, procnames_long_3
[proc
-20]);
630 switch ((enum fsh_mode
) m
) {
631 case fsm_DN
: return ("deny none");
632 case fsm_DR
: return ("deny read");
633 case fsm_DW
: return ("deny write");
634 case fsm_DRW
: return ("deny read/write");
635 default: return ("?");
643 switch ((enum fsh_access
) a
) {
644 case fsa_NONE
: return ("?");
645 case fsa_R
: return ("read only");
646 case fsa_W
: return ("write only");
647 case fsa_RW
: return ("read/write");
648 default: return ("?");
657 m
= (enum fsh_mode
) getxdr_u_long();
658 (void) sprintf(get_line(0, 0),
660 m
, nameof_mode((uint_t
)m
));
668 a
= (enum fsh_access
) getxdr_u_long();
669 (void) sprintf(get_line(0, 0),
671 a
, nameof_access((uint_t
)a
));
677 static char buff
[LM_MAXSTRLEN
+ 1];
679 ulong_t mode
, access
;
681 (void) getxdr_string(buff
, LM_MAXSTRLEN
); /* Caller */
682 (void) strcpy(buff
, sum_netobj("FH")); /* Fh */
684 skip_netobj(); /* Owner */
685 mode
= getxdr_u_long();
686 access
= getxdr_u_long();
687 (void) sprintf(cp
, " Mode=%lu Access=%lu", mode
, access
);
694 showxdr_string(LM_MAXSTRLEN
, "Caller = %s");
695 show_netobj("Filehandle = %s");
696 show_netobj("Lock owner = %s");
704 show_netobj("Cookie = %s");
706 showxdr_bool("Reclaim = %s");
712 show_netobj("Cookie = %s");
714 showxdr_long("Sequence = %d");
720 showxdr_string(LM_MAXNAMELEN
, "Name = %s");
721 showxdr_long("State = %d");
724 #define NOTIFY_PAD (sizeof (" State=-2147483648") + 1)
729 static char buff
[LM_MAXNAMELEN
+ NOTIFY_PAD
];
733 (void) getxdr_string(buff
, LM_MAXNAMELEN
);
735 state
= getxdr_long();
736 (void) sprintf(cp
, " State=%ld", state
);
740 /* ------------ V E R S I O N 4 ---------------------------------- */
742 static char *procnames_short_4
[] = {
751 "CANCEL MSG4", /* 8 */
752 "UNLOCK MSG4", /* 9 */
753 "GRANTED MSG4", /* 10 */
754 "TEST RES4", /* 11 */
755 "LOCK RES4", /* 12 */
756 "CANCEL RES4", /* 13 */
757 "UNLOCK RES4", /* 14 */
758 "GRANTED RES4", /* 15 */
759 "PROC 16 v4", /* 16 */
760 "PROC 17 v4", /* 17 */
761 "PROC 18 v4", /* 18 */
762 "PROC 19 v4", /* 19 */
769 static char *procnames_long_4
[] = {
770 "Null procedure", /* 0 */
776 "Test message", /* 6 */
777 "Lock message", /* 7 */
778 "Cancel message", /* 8 */
779 "Unlock message", /* 9 */
780 "Granted message", /* 10 */
781 "Test result", /* 11 */
782 "Lock result", /* 12 */
783 "Cancel result", /* 13 */
784 "Unlock result", /* 14 */
785 "Granted result", /* 15 */
786 "Procedure 16", /* 16 */
787 "Procedure 17", /* 17 */
788 "Procedure 18", /* 18 */
789 "Procedure 19", /* 19 */
792 "Unmonitored lock", /* 22 */
796 /* Maximum procedure number for version 4. */
801 interpret_nlm_4(flags
, type
, xid
, vers
, proc
, data
, len
)
802 int flags
, type
, xid
, vers
, proc
;
810 if (proc
< 0 || proc
> MAXPROC_4
)
814 if (setjmp(xdr_err
)) {
818 line
= get_sum_line();
823 procnames_short_4
[proc
]);
824 line
+= strlen(line
);
829 case NLM4_GRANTED_MSG
:
831 (void) strcat(line
, sum_netobj("OH"));
832 (void) getxdr_bool(); /* Excl */
833 (void) strcat(line
, sum_lock4());
838 (void) strcat(line
, sum_netobj("OH"));
839 (void) getxdr_bool(); /* Block */
840 (void) getxdr_bool(); /* Excl */
841 (void) strcat(line
, sum_lock4());
842 /* ignore reclaim, state fields */
845 case NLM4_CANCEL_MSG
:
847 (void) strcat(line
, sum_netobj("OH"));
848 (void) getxdr_bool(); /* Block */
849 (void) getxdr_bool(); /* Excl */
850 (void) strcat(line
, sum_lock4());
853 case NLM4_UNLOCK_MSG
:
855 (void) strcat(line
, sum_netobj("OH"));
856 (void) strcat(line
, sum_lock4());
860 (void) strcat(line
, sum_netobj("OH"));
861 (void) strcat(line
, " ");
863 nameof_stat4(getxdr_u_long()));
866 case NLM4_CANCEL_RES
:
867 case NLM4_UNLOCK_RES
:
868 case NLM4_GRANTED_RES
:
870 (void) strcat(line
, sum_netobj("OH"));
871 (void) strcat(line
, " ");
873 nameof_stat4(getxdr_u_long()));
877 (void) strcat(line
, sum_netobj("OH"));
878 (void) strcat(line
, sum_share());
882 skip_netobj(); /* Cookie */
883 (void) getxdr_bool(); /* Block */
884 (void) getxdr_bool(); /* Excl */
885 (void) strcat(line
, sum_lock4());
886 /* skip reclaim & state fields */
890 " %s", sum_notify());
893 check_retransmit(line
, (ulong_t
)xid
);
895 (void) sprintf(line
, "NLM R %s",
896 procnames_short_4
[proc
]);
897 line
+= strlen(line
);
901 (void) strcat(line
, sum_netobj("OH"));
902 (void) strcat(line
, " ");
904 nameof_stat4(getxdr_u_long()));
912 (void) strcat(line
, sum_netobj("OH"));
913 (void) strcat(line
, " ");
915 nameof_stat4(getxdr_u_long()));
920 pl
= sum_netobj("OH");
922 sprintf(line
, "%s %s %ld",
923 pl
, nameof_stat4(i
), getxdr_long());
931 if (flags
& F_DTAIL
) {
932 show_header("NLM: ", "Network Lock Manager", len
);
934 if (setjmp(xdr_err
)) {
937 (void) sprintf(get_line(0, 0),
939 proc
, procnames_long_4
[proc
]);
945 case NLM4_GRANTED_MSG
:
954 case NLM4_CANCEL_MSG
:
958 case NLM4_UNLOCK_MSG
:
965 case NLM4_CANCEL_RES
:
966 case NLM4_UNLOCK_RES
:
967 case NLM4_GRANTED_RES
:
992 case NLM4_CANCEL_MSG
:
993 case NLM4_UNLOCK_MSG
:
994 case NLM4_GRANTED_MSG
:
997 case NLM4_CANCEL_RES
:
998 case NLM4_UNLOCK_RES
:
999 case NLM4_GRANTED_RES
:
1016 static char buff
[LM_MAXSTRLEN
+ 1];
1019 u_longlong_t off
, len
;
1021 (void) getxdr_string(buff
, LM_MAXSTRLEN
); /* Caller */
1022 (void) strcpy(buff
, sum_netobj("FH")); /* Fh */
1024 skip_netobj(); /* Owner */
1026 off
= getxdr_u_longlong();
1027 len
= getxdr_u_longlong();
1028 (void) sprintf(cp
, " PID=%ld Region=%llu:%llu", id
, off
, len
);
1035 showxdr_string(LM_MAXSTRLEN
, "Caller = %s");
1036 show_netobj("Filehandle = %s");
1037 show_netobj("Lock owner = %s");
1038 showxdr_long("Svid = %ld (process id)");
1039 showxdr_u_longlong("Offset = %llu bytes");
1040 showxdr_u_longlong("Length = %llu bytes");
1046 show_netobj("Cookie = %s");
1047 showxdr_bool("Block = %s");
1048 showxdr_bool("Exclusive = %s");
1055 show_netobj("Cookie = %s");
1056 showxdr_bool("Block = %s");
1057 showxdr_bool("Exclusive = %s");
1059 showxdr_bool("Reclaim = %s");
1060 showxdr_long("State = %ld");
1066 show_netobj("Cookie = %s");
1073 show_netobj("Cookie = %s");
1074 showxdr_bool("Exclusive = %s");
1081 show_netobj("Cookie = %s");
1082 (void) show_stat4();
1089 switch ((enum nlm4_stats
) s
) {
1090 case nlm4_granted
: return ("granted");
1091 case nlm4_denied
: return ("denied");
1092 case nlm4_denied_nolocks
:return ("denied (no locks)");
1093 case nlm4_blocked
: return ("blocked");
1094 case nlm4_denied_grace_period
: return ("denied (grace period)");
1095 case nlm4_deadlck
: return ("deadlock");
1096 case nlm4_rofs
: return ("read-only fs");
1097 case nlm4_stale_fh
: return ("stale fh");
1098 case nlm4_fbig
: return ("file too big");
1099 case nlm4_failed
: return ("failed");
1100 default: return ("?");
1104 static enum nlm4_stats
1109 s
= (enum nlm4_stats
) getxdr_u_long();
1110 (void) sprintf(get_line(0, 0),
1112 s
, nameof_stat4((ulong_t
)s
));
1120 show_netobj("Cookie = %s");
1121 if (show_stat() == nlm_denied
) {
1122 showxdr_bool("Exclusive = %s");
1123 showxdr_long("Svid = %ld (process id)");
1124 show_netobj("Owner handle = %s");
1125 showxdr_u_longlong("Offset = %llu bytes");
1126 showxdr_u_longlong("Length = %llu bytes");
1133 show_netobj("Cookie = %s");
1134 (void) show_stat4();
1135 showxdr_long("Sequence = %d");