1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2006 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 /* Interpret configuration llogs */
26 #include <sys/types.h>
31 #include <liblustre.h>
32 #include <lustre/lustre_idl.h>
34 int llog_pack_buffer(int fd, struct llog_log_hdr **llog_buf,
35 struct llog_rec_hdr ***recs, int *recs_number);
37 void print_llog_header(struct llog_log_hdr *llog_buf);
38 void print_records(struct llog_rec_hdr **recs_buf,int rec_number);
39 void llog_unpack_buffer(int fd, struct llog_log_hdr *llog_buf,
40 struct llog_rec_hdr **recs_buf);
42 #define PTL_CMD_BASE 100
43 char* portals_command[17]=
64 int main(int argc, char **argv)
68 struct llog_log_hdr *llog_buf = NULL;
69 struct llog_rec_hdr **recs_buf = NULL;
74 printf("Usage: llog_reader filename\n");
78 fd = open(argv[1],O_RDONLY);
80 printf("Could not open the file %s\n", argv[1]);
83 rc = llog_pack_buffer(fd, &llog_buf, &recs_buf, &rec_number);
85 printf("Could not pack buffer; rc=%d\n", rc);
89 print_llog_header(llog_buf);
90 print_records(recs_buf,rec_number);
91 llog_unpack_buffer(fd,llog_buf,recs_buf);
100 int llog_pack_buffer(int fd, struct llog_log_hdr **llog,
101 struct llog_rec_hdr ***recs,
104 int rc = 0, recs_num,rd;
107 char *file_buf=NULL, *recs_buf=NULL;
108 struct llog_rec_hdr **recs_pr=NULL;
114 printf("Get file stat error.\n");
117 file_size = st.st_size;
119 file_buf = malloc(file_size);
120 if (file_buf == NULL){
121 printf("Memory Alloc for file_buf error.\n");
125 *llog = (struct llog_log_hdr*)file_buf;
127 rd = read(fd,file_buf,file_size);
129 printf("Read file error.\n");
134 /* the llog header not countable here.*/
135 recs_num = le32_to_cpu((*llog)->llh_count)-1;
137 recs_buf = malloc(recs_num * sizeof(struct llog_rec_hdr *));
138 if (recs_buf == NULL){
139 printf("Memory Alloc for recs_buf error.\n");
143 recs_pr = (struct llog_rec_hdr **)recs_buf;
145 ptr = file_buf + le32_to_cpu((*llog)->llh_hdr.lrh_len);
149 while (i < recs_num){
150 struct llog_rec_hdr *cur_rec = (struct llog_rec_hdr*)ptr;
152 if (ext2_test_bit(cur_idx++, (*llog)->llh_bitmap)) {
153 recs_pr[i++] = cur_rec;
154 ptr += cur_rec->lrh_len;
155 if ((ptr - file_buf) > file_size) {
156 printf("The log is corrupted.\n");
164 *recs_number=recs_num;
179 void llog_unpack_buffer(int fd, struct llog_log_hdr *llog_buf,
180 struct llog_rec_hdr **recs_buf)
187 void print_llog_header(struct llog_log_hdr *llog_buf)
191 printf("Header size : %u\n",
192 llog_buf->llh_hdr.lrh_len);
194 t = le64_to_cpu(llog_buf->llh_timestamp);
195 printf("Time : %s", ctime(&t));
197 printf("Number of records: %u\n",
198 le32_to_cpu(llog_buf->llh_count)-1);
200 printf("Target uuid : %s \n",
201 (char *)(&llog_buf->llh_tgtuuid));
203 /* Add the other info you want to view here */
205 printf("-----------------------\n");
209 static void print_1_cfg(struct lustre_cfg *lcfg)
214 printf("nid=%s("LPX64") ", libcfs_nid2str(lcfg->lcfg_nid),
217 printf("nal=%d ", lcfg->lcfg_nal);
218 for (i = 0; i < lcfg->lcfg_bufcount; i++)
219 printf("%d:%.*s ", i, lcfg->lcfg_buflens[i],
220 (char*)lustre_cfg_buf(lcfg, i));
225 static void print_setup_cfg(struct lustre_cfg *lcfg)
227 struct lov_desc *desc;
229 if ((lcfg->lcfg_bufcount == 2) &&
230 (lcfg->lcfg_buflens[1] == sizeof(*desc))) {
231 printf("lov_setup ");
232 printf("0:%s ", lustre_cfg_string(lcfg, 0));
233 printf("1:(struct lov_desc)\n");
234 desc = (struct lov_desc*)(lustre_cfg_string(lcfg, 1));
235 printf("\t\tuuid=%s ", (char*)desc->ld_uuid.uuid);
236 printf("stripe:cnt=%u ", desc->ld_default_stripe_count);
237 printf("size="LPU64" ", desc->ld_default_stripe_size);
238 printf("offset="LPU64" ", desc->ld_default_stripe_offset);
239 printf("pattern=%#x", desc->ld_pattern);
248 void print_lustre_cfg(struct lustre_cfg *lcfg, int *skip)
250 enum lcfg_command_type cmd = le32_to_cpu(lcfg->lcfg_command);
262 print_setup_cfg(lcfg);
275 case(LCFG_ADD_UUID):{
280 case(LCFG_DEL_UUID):{
285 case(LCFG_ADD_CONN):{
290 case(LCFG_DEL_CONN):{
295 case(LCFG_LOV_ADD_OBD):{
296 printf("lov_modify_tgts add ");
300 case(LCFG_LOV_DEL_OBD):{
301 printf("lov_modify_tgts del ");
306 printf("modify_mdc_tgts add ");
311 printf("modify_mdc_tgts del ");
315 case(LCFG_MOUNTOPT):{
316 printf("mount_option ");
320 case(LCFG_DEL_MOUNTOPT):{
321 printf("del_mount_option ");
325 case(LCFG_SET_TIMEOUT):{
326 printf("set_timeout=%d ", lcfg->lcfg_num);
330 case(LCFG_SET_UPCALL):{
331 printf("set_lustre_upcall ");
341 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
343 if (marker->cm_flags & CM_SKIP) {
344 if (marker->cm_flags & CM_START)
346 if (marker->cm_flags & CM_END)
349 printf("marker %d (flags=%#x, v%d.%d.%d.%d) %.16s '%s' %s:%s",
350 marker->cm_step, marker->cm_flags,
351 OBD_OCD_VERSION_MAJOR(marker->cm_vers),
352 OBD_OCD_VERSION_MINOR(marker->cm_vers),
353 OBD_OCD_VERSION_PATCH(marker->cm_vers),
354 OBD_OCD_VERSION_FIX(marker->cm_vers),
356 marker->cm_comment, ctime(&marker->cm_createtime),
357 marker->cm_canceltime ?
358 ctime(&marker->cm_canceltime) : "");
362 printf("unsupported cmd_code = %x\n",cmd);
368 void print_records(struct llog_rec_hdr **recs, int rec_number)
373 for(i = 0; i < rec_number; i++) {
374 printf("#%.2d ", le32_to_cpu(recs[i]->lrh_index));
376 lopt = le32_to_cpu(recs[i]->lrh_type);
378 if (lopt == OBD_CFG_REC){
379 struct lustre_cfg *lcfg;
381 lcfg = (struct lustre_cfg *)((char*)(recs[i]) +
382 sizeof(struct llog_rec_hdr));
383 print_lustre_cfg(lcfg, &skip);
386 if (lopt == PTL_CFG_REC)
387 printf("Portals - unknown type\n");