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),
241 (__u64)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);
273 void print_lustre_cfg(struct lustre_cfg *lcfg, int *skip)
275 enum lcfg_command_type cmd = le32_to_cpu(lcfg->lcfg_command);
287 print_setup_cfg(lcfg);
300 case(LCFG_ADD_UUID):{
305 case(LCFG_DEL_UUID):{
310 case(LCFG_ADD_CONN):{
315 case(LCFG_DEL_CONN):{
320 case(LCFG_LOV_ADD_OBD):{
321 printf("lov_modify_tgts add ");
325 case(LCFG_LOV_DEL_OBD):{
326 printf("lov_modify_tgts del ");
330 case(LCFG_MOUNTOPT):{
331 printf("mount_option ");
335 case(LCFG_DEL_MOUNTOPT):{
336 printf("del_mount_option ");
340 case(LCFG_SET_TIMEOUT):{
341 printf("set_timeout=%d ", lcfg->lcfg_num);
344 case(LCFG_SET_LDLM_TIMEOUT):{
345 printf("set_ldlm_timeout=%d ", lcfg->lcfg_num);
348 case(LCFG_SET_UPCALL):{
349 printf("set_lustre_upcall ");
359 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
360 char createtime[26], canceltime[26] = "";
363 if (marker->cm_flags & CM_SKIP) {
364 if (marker->cm_flags & CM_START) {
365 printf("SKIP START ");
373 if (marker->cm_flags & CM_EXCLUDE) {
374 if (marker->cm_flags & CM_START)
375 printf("EXCLUDE START ");
377 printf("EXCLUDE END ");
380 /* Handle overflow of 32-bit time_t gracefully.
381 * The copy to time_tmp is needed in any case to
382 * keep the pointer happy, even on 64-bit systems. */
383 time_tmp = marker->cm_createtime;
384 if (time_tmp == marker->cm_createtime) {
385 ctime_r(&time_tmp, createtime);
386 createtime[strlen(createtime) - 1] = 0;
388 strcpy(createtime, "in the distant future");
391 if (marker->cm_canceltime) {
392 /* Like cm_createtime, we try to handle overflow of
393 * 32-bit time_t gracefully. The copy to time_tmp
394 * is also needed on 64-bit systems to keep the
395 * pointer happy, see bug 16771 */
396 time_tmp = marker->cm_canceltime;
397 if (time_tmp == marker->cm_canceltime) {
398 ctime_r(&time_tmp, canceltime);
399 canceltime[strlen(canceltime) - 1] = 0;
401 strcpy(canceltime, "in the distant future");
405 printf("marker %3d (flags=%#04x, v%d.%d.%d.%d) %-15s '%s' %s-%s",
406 marker->cm_step, marker->cm_flags,
407 OBD_OCD_VERSION_MAJOR(marker->cm_vers),
408 OBD_OCD_VERSION_MINOR(marker->cm_vers),
409 OBD_OCD_VERSION_PATCH(marker->cm_vers),
410 OBD_OCD_VERSION_FIX(marker->cm_vers),
411 marker->cm_tgtname, marker->cm_comment,
412 createtime, canceltime);
415 case(LCFG_POOL_NEW):{
420 case(LCFG_POOL_ADD):{
425 case(LCFG_POOL_REM):{
426 printf("pool remove ");
430 case(LCFG_POOL_DEL):{
431 printf("pool destroy ");
436 printf("unsupported cmd_code = %x\n",cmd);
442 void print_records(struct llog_rec_hdr **recs, int rec_number)
447 for(i = 0; i < rec_number; i++) {
448 printf("#%.2d (%.3d)", le32_to_cpu(recs[i]->lrh_index),
449 le32_to_cpu(recs[i]->lrh_len));
451 lopt = le32_to_cpu(recs[i]->lrh_type);
453 if (recs[i]->padding == CANCELLED)
456 if (lopt == OBD_CFG_REC) {
457 struct lustre_cfg *lcfg;
458 lcfg = (struct lustre_cfg *)((char*)(recs[i]) +
459 sizeof(struct llog_rec_hdr));
460 print_lustre_cfg(lcfg, &skip);
461 } else if (lopt == LLOG_PAD_MAGIC) {
464 printf("unknown type %x\n", lopt);