From 2aa48a2e1da58b8460b14eba1441d560cf0f136e Mon Sep 17 00:00:00 2001 From: nikita Date: Sun, 18 Jun 2006 15:37:42 +0000 Subject: [PATCH] add lustre/utils/req-layout: an utility to print out request formats --- lustre/include/lustre_req_layout.h | 11 ++- lustre/ptlrpc/layout.c | 10 +++ lustre/utils/Makefile.am | 3 +- lustre/utils/req-layout.c | 148 +++++++++++++++++++++++++++++++++++++ 4 files changed, 168 insertions(+), 4 deletions(-) create mode 100644 lustre/utils/req-layout.c diff --git a/lustre/include/lustre_req_layout.h b/lustre/include/lustre_req_layout.h index 52877a0..61decbf 100644 --- a/lustre/include/lustre_req_layout.h +++ b/lustre/include/lustre_req_layout.h @@ -29,9 +29,6 @@ #ifndef _LUSTRE_REQ_LAYOUT_H__ #define _LUSTRE_REQ_LAYOUT_H__ -/* struct ptlrpc_request, lustre_msg* */ -#include - struct req_msg_field; struct req_format; struct req_capsule; @@ -52,6 +49,11 @@ struct req_capsule { int *rc_area; }; +#if !defined(__REQ_LAYOUT_USER__) + +/* struct ptlrpc_request, lustre_msg* */ +#include + void req_capsule_init(struct req_capsule *pill, struct ptlrpc_request *req, enum req_location location, int *area); void req_capsule_fini(struct req_capsule *pill); @@ -82,6 +84,9 @@ int req_capsule_field_present(const struct req_capsule *pill, int req_layout_init(void); void req_layout_fini(void); +/* __REQ_LAYOUT_USER__ */ +#endif + extern const struct req_format RQF_SEQ_QUERY; extern const struct req_format RQF_FLD_QUERY; extern const struct req_format RQF_MDS_GETSTATUS; diff --git a/lustre/ptlrpc/layout.c b/lustre/ptlrpc/layout.c index 4c44202..e02636f 100644 --- a/lustre/ptlrpc/layout.c +++ b/lustre/ptlrpc/layout.c @@ -26,6 +26,8 @@ * license text for more details. */ +#if !defined(__REQ_LAYOUT_USER__) + #ifndef EXPORT_SYMTAB # define EXPORT_SYMTAB #endif @@ -46,6 +48,9 @@ /* obd2cli_tgt() (required by DEBUG_REQ()) */ #include +/* __REQ_LAYOUT_USER__ */ +#endif + /* struct ptlrpc_request, lustre_msg* */ #include @@ -480,6 +485,8 @@ const struct req_format RQF_LDLM_INTENT_UNLINK = ldlm_intent_unlink_client, ldlm_intent_server); EXPORT_SYMBOL(RQF_LDLM_INTENT_UNLINK); +#if !defined(__REQ_LAYOUT_USER__) + int req_layout_init(void) { int i; @@ -738,3 +745,6 @@ int req_capsule_field_present(const struct req_capsule *pill, return __req_msg(pill, loc)->bufcount > offset; } EXPORT_SYMBOL(req_capsule_field_present); + +/* __REQ_LAYOUT_USER__ */ +#endif diff --git a/lustre/utils/Makefile.am b/lustre/utils/Makefile.am index 3b53350..f89a42e 100644 --- a/lustre/utils/Makefile.am +++ b/lustre/utils/Makefile.am @@ -17,7 +17,7 @@ rootsbin_PROGRAMS = mount.lustre sbin_PROGRAMS = lctl obdio obdbarrier lload wirecheck wiretest \ mount_lustre mkfs_lustre mkfs.lustre \ tunefs_lustre tunefs.lustre l_getgroups -bin_PROGRAMS = lfs llog_reader create_iam +bin_PROGRAMS = lfs llog_reader create_iam req_layout lib_LIBRARIES = liblustreapi.a sbin_SCRIPTS = $(sbin_scripts) bin_SCRIPTS = $(bin_scripts) @@ -45,6 +45,7 @@ wiretest_SOURCES = wiretest.c obdio_SOURCES = obdio.c obdiolib.c obdiolib.h obdbarrier_SOURCES = obdbarrier.c obdiolib.c obdiolib.h create_iam_SOURCES = create_iam.c +req_layout_SOURCES = create-iam.c llog_reader_SOURCES = llog_reader.c llog_reader_LDADD := $(LIBPTLCTL) diff --git a/lustre/utils/req-layout.c b/lustre/utils/req-layout.c new file mode 100644 index 0000000..a13412c --- /dev/null +++ b/lustre/utils/req-layout.c @@ -0,0 +1,148 @@ +/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- + * vim:expandtab:shiftwidth=8:tabstop=8: + * + * create_iam.c + * User-level tool for printing request layouts + * + * Copyright (c) 2006 Cluster File Systems, Inc. + * Author: Nikita Danilov + * + * This file is part of the Lustre file system, http://www.lustre.org + * Lustre is a trademark of Cluster File Systems, Inc. + * + * You may have signed or agreed to another license before downloading + * this software. If so, you are bound by the terms and conditions + * of that agreement, and the following does not apply to you. See the + * LICENSE file included with this distribution for more information. + * + * If you did not agree to a different license, then this copy of Lustre + * is open source software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * In either case, Lustre is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * license text for more details. + */ + +#include +#include +#include + +#include + +#define __REQ_LAYOUT_USER__ (1) + +#define ARRAY_SIZE(a) ((sizeof (a))/(sizeof (a)[0])) +#define lustre_swab_generic_32s NULL +#define lustre_swab_lu_range NULL +#define lustre_swab_md_fld NULL +#define lustre_swab_mdt_body NULL +#define lustre_swab_obd_statfs NULL +#define lustre_swab_connect NULL +#define lustre_swab_ldlm_request NULL +#define lustre_swab_ldlm_reply NULL +#define lustre_swab_ldlm_intent NULL +#define lustre_swab_lov_mds_md NULL +#define lustre_swab_mds_rec_unlink NULL +#define lustre_swab_mdt_rec_link NULL +#define lustre_swab_mdt_rec_rename NULL +#define lustre_swab_mdt_rec_create NULL +#define lustre_swab_mdt_rec_setattr NULL + +#define EXPORT_SYMBOL(name) + +/* + * Yes, include .c file. + */ +#include "../ptlrpc/layout.c" + +void usage(void) +{ + fprintf(stderr, "req-layout -- prints lustre request layouts\n"); +} + +void printt_field(const char *prefix, const struct req_msg_field *fld) +{ +} + +void print_layout(const struct req_format *rf) +{ + int j; + int k; + + int offset; + int variable; + + static const char *prefix[RCL_NR] = { + [RCL_CLIENT] = "C", + [RCL_SERVER] = "S" + }; + + printf("L %s (%i/%i)\n", rf->rf_name, + rf->rf_fields[RCL_CLIENT].nr, rf->rf_fields[RCL_SERVER].nr); + + for (j = 0; j < RCL_NR; ++j) { + offset = 0; + variable = 0; + for (k = 0; k < rf->rf_fields[j].nr; ++k) { + const struct req_msg_field *fld; + + fld = rf->rf_fields[j].d[k]; + + printf(" F%s %0i [%03.3i%s %-20.20s (", + prefix[j], k, offset, + variable ? " + ...]" : "] ", + fld->rmf_name); + if (fld->rmf_size > 0) { + printf("%3.3i) ", fld->rmf_size); + offset += fld->rmf_size; + } else { + printf("var) "); + variable = 1; + } + if (fld->rmf_flags & RMF_F_STRING) + printf("string"); + printf("\n"); + } + if (k > 0 && j != RCL_NR - 1) + printf(" -----------------------------------\n"); + } +} + +void print_layouts(void) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(req_formats); ++i) { + print_layout(req_formats[i]); + printf("\n"); + } +} + +int main(int argc, char **argv) +{ + int result; + int opt; + int verbose; + + verbose = 0; + do { + opt = getopt(argc, argv, "hb:k:r:p:v"); + switch (opt) { + case 'v': + verbose++; + case -1: + break; + case '?': + default: + fprintf(stderr, "Unable to parse options."); + case 'h': + usage(); + return 0; + } + } while (opt != -1); + print_layouts(); + return 0; +} -- 1.8.3.1