Whamcloud - gitweb
small fix
[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 <lustre/lustre_idl.h>
34
35 #define __REQ_LAYOUT_USER__ (1)
36
37 #define ARRAY_SIZE(a) ((sizeof (a))/(sizeof (a)[0]))
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_obd_statfs NULL
43 #define lustre_swab_connect NULL
44 #define lustre_swab_ldlm_request NULL
45 #define lustre_swab_ldlm_reply NULL
46 #define lustre_swab_ldlm_intent NULL
47 #define lustre_swab_lov_mds_md NULL
48 #define lustre_swab_mds_rec_unlink NULL
49 #define lustre_swab_mdt_rec_link NULL
50 #define lustre_swab_mdt_rec_rename NULL
51 #define lustre_swab_mdt_rec_create NULL
52 #define lustre_swab_mdt_rec_setattr NULL
53
54 #define EXPORT_SYMBOL(name)
55
56 /*
57  * Yes, include .c file.
58  */
59 #include "../ptlrpc/layout.c"
60
61 void usage(void)
62 {
63         fprintf(stderr, "req-layout -- prints lustre request layouts\n");
64 }
65
66 void printt_field(const char *prefix, const struct req_msg_field *fld)
67 {
68 }
69
70 void print_layout(const struct req_format *rf)
71 {
72         int j;
73         int k;
74
75         int offset;
76         int variable;
77
78         static const char *prefix[RCL_NR] = {
79                 [RCL_CLIENT] = "C",
80                 [RCL_SERVER] = "S"
81         };
82
83         printf("L %s (%i/%i)\n", rf->rf_name,
84                rf->rf_fields[RCL_CLIENT].nr, rf->rf_fields[RCL_SERVER].nr);
85
86         for (j = 0; j < RCL_NR; ++j) {
87                 offset = 0;
88                 variable = 0;
89                 for (k = 0; k < rf->rf_fields[j].nr; ++k) {
90                         const struct req_msg_field *fld;
91
92                         fld = rf->rf_fields[j].d[k];
93
94                         printf("        F%s %0i [%03.3i%s %-20.20s (",
95                                prefix[j], k, offset,
96                                variable ? " + ...]" : "]      ",
97                                fld->rmf_name);
98                         if (fld->rmf_size > 0) {
99                                 printf("%3.3i) ", fld->rmf_size);
100                                 offset += fld->rmf_size;
101                         } else {
102                                 printf("var) ");
103                                 variable = 1;
104                         }
105                         if (fld->rmf_flags & RMF_F_STRING)
106                                 printf("string");
107                         printf("\n");
108                 }
109                 if (k > 0 && j != RCL_NR - 1)
110                         printf("        -----------------------------------\n");
111         }
112 }
113
114 void print_layouts(void)
115 {
116         int i;
117
118         for (i = 0; i < ARRAY_SIZE(req_formats); ++i) {
119                 print_layout(req_formats[i]);
120                 printf("\n");
121         }
122 }
123
124 int main(int argc, char **argv)
125 {
126         int result;
127         int opt;
128         int verbose;
129
130         verbose = 0;
131         do {
132                 opt = getopt(argc, argv, "hb:k:r:p:v");
133                 switch (opt) {
134                 case 'v':
135                         verbose++;
136                 case -1:
137                         break;
138                 case '?':
139                 default:
140                         fprintf(stderr, "Unable to parse options.");
141                 case 'h':
142                         usage();
143                         return 0;
144                 }
145         } while (opt != -1);
146         print_layouts();
147         return 0;
148 }