Whamcloud - gitweb
b=14149
[fs/lustre-release.git] / lustre / utils / req-layout.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  req_layout.c
5  *  User-level tool for printing request layouts
6  *
7  *  Copyright (c) 2006 Cluster File Systems, Inc.
8  *   Author: Nikita Danilov <nikita@clusterfs.com>
9  *
10  *   This file is part of the Lustre file system, http://www.lustre.org
11  *   Lustre is a trademark of Cluster File Systems, Inc.
12  *
13  *   You may have signed or agreed to another license before downloading
14  *   this software.  If so, you are bound by the terms and conditions
15  *   of that agreement, and the following does not apply to you.  See the
16  *   LICENSE file included with this distribution for more information.
17  *
18  *   If you did not agree to a different license, then this copy of Lustre
19  *   is open source software; you can redistribute it and/or modify it
20  *   under the terms of version 2 of the GNU General Public License as
21  *   published by the Free Software Foundation.
22  *
23  *   In either case, Lustre is distributed in the hope that it will be
24  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
25  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26  *   license text for more details.
27  */
28
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <unistd.h>
32
33 #include <liblustre.h>
34 #include <lustre/lustre_idl.h>
35
36 #define __REQ_LAYOUT_USER__ (1)
37
38 #define lustre_swab_generic_32s NULL
39 #define lustre_swab_lu_range NULL
40 #define lustre_swab_md_fld NULL
41 #define lustre_swab_mdt_body NULL
42 #define lustre_swab_mdt_epoch NULL
43 #define lustre_swab_ptlrpc_body NULL
44 #define lustre_swab_obd_statfs NULL
45 #define lustre_swab_connect NULL
46 #define lustre_swab_ldlm_request NULL
47 #define lustre_swab_ldlm_reply NULL
48 #define lustre_swab_ldlm_intent NULL
49 #define lustre_swab_lov_mds_md NULL
50 #define lustre_swab_mdt_rec_reint NULL
51 #define lustre_swab_lustre_capa NULL
52 #define lustre_swab_lustre_capa_key NULL
53 #define lustre_swab_mdt_rec_join NULL
54 #define lustre_swab_llogd_conn_body NULL
55 #define lustre_swab_llog_hdr NULL
56 #define lustre_swab_llogd_body NULL
57 #define lustre_swab_obd_quotactl NULL
58 #define lustre_swab_mgs_target_info NULL
59 #define lustre_swab_niobuf_remote NULL
60 #define lustre_swab_obd_ioobj NULL
61 #define lustre_swab_ost_body NULL
62 #define lustre_swab_ost_last_id NULL
63
64 /*
65  * Yes, include .c file.
66  */
67 #include "../ptlrpc/layout.c"
68
69 void usage(void)
70 {
71         fprintf(stderr, "req-layout -- prints lustre request layouts\n");
72 }
73
74 void printt_field(const char *prefix, const struct req_msg_field *fld)
75 {
76 }
77
78 void print_layout(const struct req_format *rf)
79 {
80         int j;
81         int k;
82
83         int offset;
84         int variable;
85
86         static const char *prefix[RCL_NR] = {
87                 [RCL_CLIENT] = "C",
88                 [RCL_SERVER] = "S"
89         };
90
91         printf("L %s (%i/%i)\n", rf->rf_name,
92                rf->rf_fields[RCL_CLIENT].nr, rf->rf_fields[RCL_SERVER].nr);
93
94         for (j = 0; j < RCL_NR; ++j) {
95                 offset = 0;
96                 variable = 0;
97                 for (k = 0; k < rf->rf_fields[j].nr; ++k) {
98                         const struct req_msg_field *fld;
99
100                         fld = rf->rf_fields[j].d[k];
101
102                         printf("        F%s %i [%3.3i%s %-20.20s (",
103                                prefix[j], k, offset,
104                                variable ? " + ...]" : "]      ",
105                                fld->rmf_name);
106                         if (fld->rmf_size > 0) {
107                                 printf("%3.3i) ", fld->rmf_size);
108                                 offset += fld->rmf_size;
109                         } else {
110                                 printf("var) ");
111                                 variable = 1;
112                         }
113                         if (fld->rmf_flags & RMF_F_STRING)
114                                 printf("string");
115                         printf("\n");
116                 }
117                 if (k > 0 && j != RCL_NR - 1)
118                         printf("        -----------------------------------\n");
119         }
120 }
121
122 void print_layouts(void)
123 {
124         int i;
125
126         for (i = 0; i < ARRAY_SIZE(req_formats); ++i) {
127                 print_layout(req_formats[i]);
128                 printf("\n");
129         }
130 }
131
132 int main(int argc, char **argv)
133 {
134         int opt;
135         int verbose;
136
137         verbose = 0;
138         do {
139                 opt = getopt(argc, argv, "hb:k:r:p:v");
140                 switch (opt) {
141                 case 'v':
142                         verbose++;
143                 case -1:
144                         break;
145                 case '?':
146                 default:
147                         fprintf(stderr, "Unable to parse options.");
148                 case 'h':
149                         usage();
150                         return 0;
151                 }
152         } while (opt != -1);
153         print_layouts();
154         return 0;
155 }