1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 /* Interpret configuration llogs */
40 #include <sys/types.h>
45 #include <liblustre.h>
46 #include <lustre/lustre_idl.h>
48 int llog_pack_buffer(int fd, struct llog_log_hdr **llog_buf,
49 struct llog_rec_hdr ***recs, int *recs_number);
51 void print_llog_header(struct llog_log_hdr *llog_buf);
52 void print_records(struct llog_rec_hdr **recs_buf,int rec_number);
53 void llog_unpack_buffer(int fd, struct llog_log_hdr *llog_buf,
54 struct llog_rec_hdr **recs_buf);
56 #define CANCELLED 0x678
58 #define PTL_CMD_BASE 100
59 char* portals_command[17]=
80 int main(int argc, char **argv)
84 struct llog_log_hdr *llog_buf = NULL;
85 struct llog_rec_hdr **recs_buf = NULL;
90 printf("Usage: llog_reader filename\n");
94 fd = open(argv[1],O_RDONLY);
96 printf("Could not open the file %s\n", argv[1]);
99 rc = llog_pack_buffer(fd, &llog_buf, &recs_buf, &rec_number);
101 printf("Could not pack buffer; rc=%d\n", rc);
105 print_llog_header(llog_buf);
106 print_records(recs_buf,rec_number);
107 llog_unpack_buffer(fd,llog_buf,recs_buf);
116 int llog_pack_buffer(int fd, struct llog_log_hdr **llog,
117 struct llog_rec_hdr ***recs,
120 int rc = 0, recs_num,rd;
123 char *file_buf=NULL, *recs_buf=NULL;
124 struct llog_rec_hdr **recs_pr=NULL;
130 printf("Get file stat error.\n");
133 file_size = st.st_size;
135 file_buf = malloc(file_size);
136 if (file_buf == NULL){
137 printf("Memory Alloc for file_buf error.\n");
141 *llog = (struct llog_log_hdr*)file_buf;
143 rd = read(fd,file_buf,file_size);
145 printf("Read file error.\n");
150 /* the llog header not countable here.*/
151 recs_num = le32_to_cpu((*llog)->llh_count)-1;
153 recs_buf = malloc(recs_num * sizeof(struct llog_rec_hdr *));
154 if (recs_buf == NULL){
155 printf("Memory Alloc for recs_buf error.\n");
159 recs_pr = (struct llog_rec_hdr **)recs_buf;
161 ptr = file_buf + le32_to_cpu((*llog)->llh_hdr.lrh_len);
164 while (i < recs_num){
165 struct llog_rec_hdr *cur_rec = (struct llog_rec_hdr*)ptr;
166 int idx = le32_to_cpu(cur_rec->lrh_index);
167 recs_pr[i] = cur_rec;
169 if (ext2_test_bit(idx, (*llog)->llh_bitmap)) {
170 if (le32_to_cpu(cur_rec->lrh_type) != OBD_CFG_REC)
171 printf("rec #%d type=%x len=%u\n", idx,
172 cur_rec->lrh_type, cur_rec->lrh_len);
174 printf("Bit %d of %d not set\n", idx, recs_num);
175 cur_rec->padding = CANCELLED;
176 /* The header counts only set records */
180 ptr += le32_to_cpu(cur_rec->lrh_len);
181 if ((ptr - file_buf) > file_size) {
182 printf("The log is corrupt (too big at %d)\n", i);
190 *recs_number = recs_num;
205 void llog_unpack_buffer(int fd, struct llog_log_hdr *llog_buf,
206 struct llog_rec_hdr **recs_buf)
213 void print_llog_header(struct llog_log_hdr *llog_buf)
217 printf("Header size : %u\n",
218 le32_to_cpu(llog_buf->llh_hdr.lrh_len));
220 t = le64_to_cpu(llog_buf->llh_timestamp);
221 printf("Time : %s", ctime(&t));
223 printf("Number of records: %u\n",
224 le32_to_cpu(llog_buf->llh_count)-1);
226 printf("Target uuid : %s \n",
227 (char *)(&llog_buf->llh_tgtuuid));
229 /* Add the other info you want to view here */
231 printf("-----------------------\n");
235 static void print_1_cfg(struct lustre_cfg *lcfg)
240 printf("nid=%s("LPX64") ", libcfs_nid2str(lcfg->lcfg_nid),
243 printf("nal=%d ", lcfg->lcfg_nal);
244 for (i = 0; i < lcfg->lcfg_bufcount; i++)
245 printf("%d:%.*s ", i, lcfg->lcfg_buflens[i],
246 (char*)lustre_cfg_buf(lcfg, i));
251 static void print_setup_cfg(struct lustre_cfg *lcfg)
253 struct lov_desc *desc;
255 if ((lcfg->lcfg_bufcount == 2) &&
256 (lcfg->lcfg_buflens[1] == sizeof(*desc))) {
257 printf("lov_setup ");
258 printf("0:%s ", lustre_cfg_string(lcfg, 0));
259 printf("1:(struct lov_desc)\n");
260 desc = (struct lov_desc*)(lustre_cfg_string(lcfg, 1));
261 printf("\t\tuuid=%s ", (char*)desc->ld_uuid.uuid);
262 printf("stripe:cnt=%u ", desc->ld_default_stripe_count);
263 printf("size="LPU64" ", desc->ld_default_stripe_size);
264 printf("offset="LPU64" ", desc->ld_default_stripe_offset);
265 printf("pattern=%#x", desc->ld_pattern);
274 void print_lustre_cfg(struct lustre_cfg *lcfg, int *skip)
276 enum lcfg_command_type cmd = le32_to_cpu(lcfg->lcfg_command);
288 print_setup_cfg(lcfg);
301 case(LCFG_ADD_UUID):{
306 case(LCFG_DEL_UUID):{
311 case(LCFG_ADD_CONN):{
316 case(LCFG_DEL_CONN):{
321 case(LCFG_LOV_ADD_OBD):{
322 printf("lov_modify_tgts add ");
326 case(LCFG_LOV_DEL_OBD):{
327 printf("lov_modify_tgts del ");
332 printf("modify_mdc_tgts add ");
337 printf("modify_mdc_tgts del ");
341 case(LCFG_MOUNTOPT):{
342 printf("mount_option ");
346 case(LCFG_DEL_MOUNTOPT):{
347 printf("del_mount_option ");
351 case(LCFG_SET_TIMEOUT):{
352 printf("set_timeout=%d ", lcfg->lcfg_num);
356 case(LCFG_SET_UPCALL):{
357 printf("set_lustre_upcall ");
367 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
368 char createtime[26], canceltime[26] = "";
370 if (marker->cm_flags & CM_SKIP) {
371 if (marker->cm_flags & CM_START) {
372 printf("SKIP START ");
379 if (marker->cm_flags & CM_EXCLUDE) {
380 if (marker->cm_flags & CM_START)
381 printf("EXCLUDE START ");
383 printf("EXCLUDE END ");
385 ctime_r(&marker->cm_createtime, createtime);
386 createtime[strlen(createtime) - 1] = 0;
387 if (marker->cm_canceltime) {
388 ctime_r(&marker->cm_canceltime, canceltime);
389 canceltime[strlen(canceltime) - 1] = 0;
391 printf("marker %3d (flags=%#04x, v%d.%d.%d.%d) %-15s '%s' %s-%s",
392 marker->cm_step, marker->cm_flags,
393 OBD_OCD_VERSION_MAJOR(marker->cm_vers),
394 OBD_OCD_VERSION_MINOR(marker->cm_vers),
395 OBD_OCD_VERSION_PATCH(marker->cm_vers),
396 OBD_OCD_VERSION_FIX(marker->cm_vers),
397 marker->cm_tgtname, marker->cm_comment,
398 createtime, canceltime);
401 case(LCFG_POOL_NEW):{
406 case(LCFG_POOL_ADD):{
411 case(LCFG_POOL_REM):{
412 printf("pool remove ");
416 case(LCFG_POOL_DEL):{
417 printf("pool destroy ");
422 printf("unsupported cmd_code = %x\n",cmd);
428 void print_records(struct llog_rec_hdr **recs, int rec_number)
433 for(i = 0; i < rec_number; i++) {
434 printf("#%.2d (%.3d)", le32_to_cpu(recs[i]->lrh_index),
435 le32_to_cpu(recs[i]->lrh_len));
437 lopt = le32_to_cpu(recs[i]->lrh_type);
439 if (recs[i]->padding == CANCELLED)
442 if (lopt == OBD_CFG_REC) {
443 struct lustre_cfg *lcfg;
444 lcfg = (struct lustre_cfg *)((char*)(recs[i]) +
445 sizeof(struct llog_rec_hdr));
446 print_lustre_cfg(lcfg, &skip);
447 } else if (lopt == LLOG_PAD_MAGIC) {
450 printf("unknown type %x\n", lopt);