Whamcloud - gitweb
LU-8648 all: remove all Sun license and URL references
[fs/lustre-release.git] / lustre / utils / req-layout.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2015, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  *
32  * lustre/utils/req-layout.c
33  *
34  * User-level tool for printing request layouts
35  *
36  * Author: Nikita Danilov <nikita@clusterfs.com>
37  */
38
39 #include <errno.h>
40 #include <limits.h>
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include <string.h>
44 #include <unistd.h>
45
46 #include <linux/types.h>
47
48 #define __REQ_LAYOUT_USER__ (1)
49 #define EXPORT_SYMBOL(s)
50
51 #include <lustre/lustre_idl.h>
52 #include <lustre_req_layout.h>
53 #include <lustre/lustreapi.h>
54
55 #ifndef ARRAY_SIZE
56 # define ARRAY_SIZE(a) ((sizeof(a)) / (sizeof((a)[0])))
57 #endif /* !ARRAY_SIZE */
58
59 #define lustre_swab_generic_32s NULL
60 #define lustre_swab_lu_seq_range NULL
61 #define lustre_swab_mdt_body NULL
62 #define lustre_swab_mdt_ioepoch NULL
63 #define lustre_swab_ptlrpc_body NULL
64 #define lustre_swab_obd_statfs NULL
65 #define lustre_swab_connect NULL
66 #define lustre_swab_ldlm_request NULL
67 #define lustre_swab_ldlm_reply NULL
68 #define lustre_swab_ldlm_intent NULL
69 #define lustre_swab_layout_intent NULL
70 /* #define lustre_swab_lov_mds_md NULL */
71 #define lustre_swab_mdt_rec_reint NULL
72 #define lustre_swab_lustre_capa NULL
73 #define lustre_swab_lustre_capa_key NULL
74 #define lustre_swab_llogd_conn_body NULL
75 #define lustre_swab_llog_hdr NULL
76 #define lustre_swab_llogd_body NULL
77 #define lustre_swab_obd_quotactl NULL
78 #define lustre_swab_mgs_target_info NULL
79 #define lustre_swab_niobuf_remote NULL
80 #define lustre_swab_obd_ioobj NULL
81 #define lustre_swab_ost_body NULL
82 #define lustre_swab_ost_last_id NULL
83 #define lustre_swab_fiemap NULL
84 #define lustre_swab_idx_info NULL
85 #define lustre_swab_qdata NULL
86 #define lustre_swab_quota_body NULL
87 #define lustre_swab_ost_lvb_v1 NULL
88 #define lustre_swab_ost_lvb NULL
89 #define lustre_swab_gl_desc NULL
90 #define lustre_swab_mgs_config_body NULL
91 #define lustre_swab_mgs_config_res NULL
92 #define lustre_swab_swap_layouts NULL
93 #define lustre_swab_lu_fid NULL
94 #define lustre_swab_ost_id NULL
95 #define lustre_swab_hsm_progress_kernel NULL
96 #define lustre_swab_hsm_user_item NULL
97 #define lustre_swab_hsm_user_state NULL
98 #define lustre_swab_hsm_state_set NULL
99 #define lustre_swab_hsm_current_action NULL
100 #define lustre_swab_hsm_request NULL
101 #define lustre_swab_close_data NULL
102 #define lustre_swab_object_update NULL
103 #define lustre_swab_object_update_result NULL
104 #define lustre_swab_object_update_reply NULL
105 #define lustre_swab_object_update_request NULL
106 #define lustre_swab_out_update_header NULL
107 #define lustre_swab_out_update_buffer NULL
108
109 #define dump_rniobuf NULL
110 #define dump_ioo NULL
111 #define dump_obdo NULL
112 #define dump_ost_body NULL
113 #define dump_rcs NULL
114 #define lustre_swab_lmv_user_md NULL
115 #define lustre_swab_lfsck_request NULL
116 #define lustre_swab_lfsck_reply NULL
117 #define lustre_swab_ladvise_hdr NULL
118 #define lustre_swab_ladvise NULL
119
120 /*
121  * Yes, include .c file.
122  */
123 #include "../ptlrpc/layout.c"
124
125 void usage(void)
126 {
127         fprintf(stderr, "req-layout -- prints lustre request layouts\n");
128 }
129
130 void printt_field(const char *prefix, const struct req_msg_field *fld)
131 {
132 }
133
134 void print_layout(const struct req_format *rf)
135 {
136         int j;
137         int k;
138
139         int offset;
140         int variable;
141
142         static const char *prefix[RCL_NR] = {
143                 [RCL_CLIENT] = "C",
144                 [RCL_SERVER] = "S"
145         };
146
147         printf("L %s (%zu/%zu)\n", rf->rf_name,
148                rf->rf_fields[RCL_CLIENT].nr, rf->rf_fields[RCL_SERVER].nr);
149
150         for (j = 0; j < RCL_NR; ++j) {
151                 offset = 0;
152                 variable = 0;
153                 for (k = 0; k < rf->rf_fields[j].nr; ++k) {
154                         const struct req_msg_field *fld;
155
156                         fld = rf->rf_fields[j].d[k];
157
158                         printf("        F%s %i [%3.3i%s %-20.20s (",
159                                prefix[j], k, offset,
160                                variable ? " + ...]" : "]      ",
161                                fld->rmf_name);
162                         if (fld->rmf_size > 0) {
163                                 printf("%3.3i) ", fld->rmf_size);
164                                 offset += fld->rmf_size;
165                         } else {
166                                 printf("var) ");
167                                 variable = 1;
168                         }
169                         if (fld->rmf_flags & RMF_F_STRING)
170                                 printf("string");
171                         printf("\n");
172                 }
173                 if (k > 0 && j != RCL_NR - 1)
174                         printf("        -----------------------------------\n");
175         }
176 }
177
178 void print_layouts(void)
179 {
180         int i;
181
182         for (i = 0; i < ARRAY_SIZE(req_formats); ++i) {
183                 print_layout(req_formats[i]);
184                 printf("\n");
185         }
186 }
187
188 int main(int argc, char **argv)
189 {
190         int opt;
191         int verbose;
192
193         verbose = 0;
194         do {
195                 opt = getopt(argc, argv, "hb:k:r:p:v");
196                 switch (opt) {
197                 case 'v':
198                         verbose++;
199                 case -1:
200                         break;
201                 case '?':
202                 default:
203                         fprintf(stderr, "Unable to parse options.");
204                 case 'h':
205                         usage();
206                         return 0;
207                 }
208         } while (opt != -1);
209         print_layouts();
210         return 0;
211 }