Whamcloud - gitweb
711eace9c7cf290c27ae47b13585fa7d5d352b7d
[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.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2012, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/utils/req-layout.c
37  *
38  * User-level tool for printing request layouts
39  *
40  * Author: Nikita Danilov <nikita@clusterfs.com>
41  */
42
43 #include <stdio.h>
44 #include <stdlib.h>
45 #include <unistd.h>
46
47 #include <liblustre.h>
48 #include <lustre/lustre_idl.h>
49
50 #define __REQ_LAYOUT_USER__ (1)
51
52 #define lustre_swab_generic_32s NULL
53 #define lustre_swab_lu_seq_range NULL
54 #define lustre_swab_mdt_body NULL
55 #define lustre_swab_mdt_ioepoch NULL
56 #define lustre_swab_ptlrpc_body NULL
57 #define lustre_swab_obd_statfs NULL
58 #define lustre_swab_connect NULL
59 #define lustre_swab_ldlm_request NULL
60 #define lustre_swab_ldlm_reply NULL
61 #define lustre_swab_ldlm_intent NULL
62 #define lustre_swab_layout_intent NULL
63 /* #define lustre_swab_lov_mds_md NULL */
64 #define lustre_swab_mdt_rec_reint NULL
65 #define lustre_swab_lustre_capa NULL
66 #define lustre_swab_lustre_capa_key NULL
67 #define lustre_swab_llogd_conn_body NULL
68 #define lustre_swab_llog_hdr NULL
69 #define lustre_swab_llogd_body NULL
70 #define lustre_swab_obd_quotactl NULL
71 #define lustre_swab_mgs_target_info NULL
72 #define lustre_swab_niobuf_remote NULL
73 #define lustre_swab_obd_ioobj NULL
74 #define lustre_swab_ost_body NULL
75 #define lustre_swab_ost_last_id NULL
76 #define lustre_swab_fiemap NULL
77 #define lustre_swab_idx_info NULL
78 #define lustre_swab_qdata NULL
79 #define lustre_swab_quota_body NULL
80 #define lustre_swab_ost_lvb_v1 NULL
81 #define lustre_swab_ost_lvb NULL
82 #define lustre_swab_gl_desc NULL
83 #define lustre_swab_mgs_config_body NULL
84 #define lustre_swab_mgs_config_res NULL
85 #define lustre_swab_lu_fid NULL
86 #define lustre_swab_hsm_progress_kernel NULL
87 #define lustre_swab_hsm_user_item NULL
88 #define lustre_swab_hsm_user_state NULL
89 #define lustre_swab_hsm_state_set NULL
90 #define lustre_swab_hsm_current_action NULL
91 #define lustre_swab_hsm_request NULL
92 #define lustre_swab_update_buf NULL
93 #define lustre_swab_update_reply_buf NULL
94
95 #define dump_rniobuf NULL
96 #define dump_ioo NULL
97 #define dump_obdo NULL
98 #define dump_ost_body NULL
99 #define dump_rcs NULL
100 #define lustre_swab_lmv_user_md NULL
101
102 /*
103  * Yes, include .c file.
104  */
105 #include "../ptlrpc/layout.c"
106
107 void usage(void)
108 {
109         fprintf(stderr, "req-layout -- prints lustre request layouts\n");
110 }
111
112 void printt_field(const char *prefix, const struct req_msg_field *fld)
113 {
114 }
115
116 void print_layout(const struct req_format *rf)
117 {
118         int j;
119         int k;
120
121         int offset;
122         int variable;
123
124         static const char *prefix[RCL_NR] = {
125                 [RCL_CLIENT] = "C",
126                 [RCL_SERVER] = "S"
127         };
128
129         printf("L %s (%i/%i)\n", rf->rf_name,
130                rf->rf_fields[RCL_CLIENT].nr, rf->rf_fields[RCL_SERVER].nr);
131
132         for (j = 0; j < RCL_NR; ++j) {
133                 offset = 0;
134                 variable = 0;
135                 for (k = 0; k < rf->rf_fields[j].nr; ++k) {
136                         const struct req_msg_field *fld;
137
138                         fld = rf->rf_fields[j].d[k];
139
140                         printf("        F%s %i [%3.3i%s %-20.20s (",
141                                prefix[j], k, offset,
142                                variable ? " + ...]" : "]      ",
143                                fld->rmf_name);
144                         if (fld->rmf_size > 0) {
145                                 printf("%3.3i) ", fld->rmf_size);
146                                 offset += fld->rmf_size;
147                         } else {
148                                 printf("var) ");
149                                 variable = 1;
150                         }
151                         if (fld->rmf_flags & RMF_F_STRING)
152                                 printf("string");
153                         printf("\n");
154                 }
155                 if (k > 0 && j != RCL_NR - 1)
156                         printf("        -----------------------------------\n");
157         }
158 }
159
160 void print_layouts(void)
161 {
162         int i;
163
164         for (i = 0; i < ARRAY_SIZE(req_formats); ++i) {
165                 print_layout(req_formats[i]);
166                 printf("\n");
167         }
168 }
169
170 int main(int argc, char **argv)
171 {
172         int opt;
173         int verbose;
174
175         verbose = 0;
176         do {
177                 opt = getopt(argc, argv, "hb:k:r:p:v");
178                 switch (opt) {
179                 case 'v':
180                         verbose++;
181                 case -1:
182                         break;
183                 case '?':
184                 default:
185                         fprintf(stderr, "Unable to parse options.");
186                 case 'h':
187                         usage();
188                         return 0;
189                 }
190         } while (opt != -1);
191         print_layouts();
192         return 0;
193 }