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 CANCELLED 0x678
44 #define PTL_CMD_BASE 100
45 char* portals_command[17]=
66 int main(int argc, char **argv)
70 struct llog_log_hdr *llog_buf = NULL;
71 struct llog_rec_hdr **recs_buf = NULL;
76 printf("Usage: llog_reader filename\n");
80 fd = open(argv[1],O_RDONLY);
82 printf("Could not open the file %s\n", argv[1]);
85 rc = llog_pack_buffer(fd, &llog_buf, &recs_buf, &rec_number);
87 printf("Could not pack buffer; rc=%d\n", rc);
91 print_llog_header(llog_buf);
92 print_records(recs_buf,rec_number);
93 llog_unpack_buffer(fd,llog_buf,recs_buf);
102 int llog_pack_buffer(int fd, struct llog_log_hdr **llog,
103 struct llog_rec_hdr ***recs,
106 int rc = 0, recs_num,rd;
109 char *file_buf=NULL, *recs_buf=NULL;
110 struct llog_rec_hdr **recs_pr=NULL;
116 printf("Get file stat error.\n");
119 file_size = st.st_size;
121 file_buf = malloc(file_size);
122 if (file_buf == NULL){
123 printf("Memory Alloc for file_buf error.\n");
127 *llog = (struct llog_log_hdr*)file_buf;
129 rd = read(fd,file_buf,file_size);
131 printf("Read file error.\n");
136 /* the llog header not countable here.*/
137 recs_num = le32_to_cpu((*llog)->llh_count)-1;
139 recs_buf = malloc(recs_num * sizeof(struct llog_rec_hdr *));
140 if (recs_buf == NULL){
141 printf("Memory Alloc for recs_buf error.\n");
145 recs_pr = (struct llog_rec_hdr **)recs_buf;
147 ptr = file_buf + le32_to_cpu((*llog)->llh_hdr.lrh_len);
150 while (i < recs_num){
151 struct llog_rec_hdr *cur_rec = (struct llog_rec_hdr*)ptr;
152 int idx = le32_to_cpu(cur_rec->lrh_index);
153 recs_pr[i] = cur_rec;
155 if (ext2_test_bit(idx, (*llog)->llh_bitmap)) {
156 if (le32_to_cpu(cur_rec->lrh_type) != OBD_CFG_REC)
157 printf("rec #%d type=%x len=%u\n", idx,
158 cur_rec->lrh_type, cur_rec->lrh_len);
160 printf("Bit %d of %d not set\n", idx, recs_num);
161 cur_rec->padding = CANCELLED;
162 /* The header counts only set records */
166 ptr += le32_to_cpu(cur_rec->lrh_len);
167 if ((ptr - file_buf) > file_size) {
168 printf("The log is corrupt (too big at %d)\n", i);
176 *recs_number = recs_num;
191 void llog_unpack_buffer(int fd, struct llog_log_hdr *llog_buf,
192 struct llog_rec_hdr **recs_buf)
199 void print_llog_header(struct llog_log_hdr *llog_buf)
203 printf("Header size : %u\n",
204 le32_to_cpu(llog_buf->llh_hdr.lrh_len));
206 t = le64_to_cpu(llog_buf->llh_timestamp);
207 printf("Time : %s", ctime(&t));
209 printf("Number of records: %u\n",
210 le32_to_cpu(llog_buf->llh_count)-1);
212 printf("Target uuid : %s \n",
213 (char *)(&llog_buf->llh_tgtuuid));
215 /* Add the other info you want to view here */
217 printf("-----------------------\n");
221 static void print_1_cfg(struct lustre_cfg *lcfg)
226 printf("nid=%s("LPX64") ", libcfs_nid2str(lcfg->lcfg_nid),
229 printf("nal=%d ", lcfg->lcfg_nal);
230 for (i = 0; i < lcfg->lcfg_bufcount; i++)
231 printf("%d:%.*s ", i, lcfg->lcfg_buflens[i],
232 (char*)lustre_cfg_buf(lcfg, i));
237 static void print_setup_cfg(struct lustre_cfg *lcfg)
239 struct lov_desc *desc;
241 if ((lcfg->lcfg_bufcount == 2) &&
242 (lcfg->lcfg_buflens[1] == sizeof(*desc))) {
243 printf("lov_setup ");
244 printf("0:%s ", lustre_cfg_string(lcfg, 0));
245 printf("1:(struct lov_desc)\n");
246 desc = (struct lov_desc*)(lustre_cfg_string(lcfg, 1));
247 printf("\t\tuuid=%s ", (char*)desc->ld_uuid.uuid);
248 printf("stripe:cnt=%u ", desc->ld_default_stripe_count);
249 printf("size="LPU64" ", desc->ld_default_stripe_size);
250 printf("offset="LPU64" ", desc->ld_default_stripe_offset);
251 printf("pattern=%#x", desc->ld_pattern);
260 void print_lustre_cfg(struct lustre_cfg *lcfg, int *skip)
262 enum lcfg_command_type cmd = le32_to_cpu(lcfg->lcfg_command);
274 print_setup_cfg(lcfg);
287 case(LCFG_ADD_UUID):{
292 case(LCFG_DEL_UUID):{
297 case(LCFG_ADD_CONN):{
302 case(LCFG_DEL_CONN):{
307 case(LCFG_LOV_ADD_OBD):{
308 printf("lov_modify_tgts add ");
312 case(LCFG_LOV_DEL_OBD):{
313 printf("lov_modify_tgts del ");
318 printf("modify_mdc_tgts add ");
323 printf("modify_mdc_tgts del ");
327 case(LCFG_MOUNTOPT):{
328 printf("mount_option ");
332 case(LCFG_DEL_MOUNTOPT):{
333 printf("del_mount_option ");
337 case(LCFG_SET_TIMEOUT):{
338 printf("set_timeout=%d ", lcfg->lcfg_num);
342 case(LCFG_SET_UPCALL):{
343 printf("set_lustre_upcall ");
353 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
354 char createtime[26], canceltime[26] = "";
356 if (marker->cm_flags & CM_SKIP) {
357 if (marker->cm_flags & CM_START) {
358 printf("SKIP START ");
365 if (marker->cm_flags & CM_EXCLUDE) {
366 if (marker->cm_flags & CM_START)
367 printf("EXCLUDE START ");
369 printf("EXCLUDE END ");
371 ctime_r(&marker->cm_createtime, createtime);
372 createtime[strlen(createtime) - 1] = 0;
373 if (marker->cm_canceltime) {
374 ctime_r(&marker->cm_canceltime, canceltime);
375 canceltime[strlen(canceltime) - 1] = 0;
377 printf("marker %3d (flags=%#04x, v%d.%d.%d.%d) %-15s '%s' %s-%s",
378 marker->cm_step, marker->cm_flags,
379 OBD_OCD_VERSION_MAJOR(marker->cm_vers),
380 OBD_OCD_VERSION_MINOR(marker->cm_vers),
381 OBD_OCD_VERSION_PATCH(marker->cm_vers),
382 OBD_OCD_VERSION_FIX(marker->cm_vers),
383 marker->cm_tgtname, marker->cm_comment,
384 createtime, canceltime);
388 printf("unsupported cmd_code = %x\n",cmd);
394 void print_records(struct llog_rec_hdr **recs, int rec_number)
399 for(i = 0; i < rec_number; i++) {
400 printf("#%.2d (%.3d)", le32_to_cpu(recs[i]->lrh_index),
401 le32_to_cpu(recs[i]->lrh_len));
403 lopt = le32_to_cpu(recs[i]->lrh_type);
405 if (recs[i]->padding == CANCELLED)
408 if (lopt == OBD_CFG_REC) {
409 struct lustre_cfg *lcfg;
410 lcfg = (struct lustre_cfg *)((char*)(recs[i]) +
411 sizeof(struct llog_rec_hdr));
412 print_lustre_cfg(lcfg, &skip);
413 } else if (lopt == LLOG_PAD_MAGIC) {
416 printf("unknown type %x\n", lopt);