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 (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
33 * Copyright (c) 2011 Whamcloud, Inc.
36 * This file is part of Lustre, http://www.lustre.org/
37 * Lustre is a trademark of Sun Microsystems, Inc.
39 /* Interpret configuration llogs */
43 #include <sys/types.h>
48 #include <liblustre.h>
49 #include <lustre/lustre_idl.h>
51 int llog_pack_buffer(int fd, struct llog_log_hdr **llog_buf,
52 struct llog_rec_hdr ***recs, int *recs_number);
54 void print_llog_header(struct llog_log_hdr *llog_buf);
55 void print_records(struct llog_rec_hdr **recs_buf,int rec_number);
56 void llog_unpack_buffer(int fd, struct llog_log_hdr *llog_buf,
57 struct llog_rec_hdr **recs_buf);
59 #define CANCELLED 0x678
61 #define PTL_CMD_BASE 100
62 char* portals_command[17]=
83 int main(int argc, char **argv)
87 struct llog_log_hdr *llog_buf = NULL;
88 struct llog_rec_hdr **recs_buf = NULL;
93 printf("Usage: llog_reader filename\n");
97 fd = open(argv[1],O_RDONLY);
99 printf("Could not open the file %s\n", argv[1]);
102 rc = llog_pack_buffer(fd, &llog_buf, &recs_buf, &rec_number);
104 printf("Could not pack buffer; rc=%d\n", rc);
108 print_llog_header(llog_buf);
109 print_records(recs_buf,rec_number);
110 llog_unpack_buffer(fd,llog_buf,recs_buf);
119 int llog_pack_buffer(int fd, struct llog_log_hdr **llog,
120 struct llog_rec_hdr ***recs,
123 int rc = 0, recs_num,rd;
126 char *file_buf=NULL, *recs_buf=NULL;
127 struct llog_rec_hdr **recs_pr=NULL;
133 printf("Get file stat error.\n");
136 file_size = st.st_size;
138 file_buf = malloc(file_size);
139 if (file_buf == NULL){
140 printf("Memory Alloc for file_buf error.\n");
144 *llog = (struct llog_log_hdr*)file_buf;
146 rd = read(fd,file_buf,file_size);
148 printf("Read file error.\n");
153 /* the llog header not countable here.*/
154 recs_num = le32_to_cpu((*llog)->llh_count)-1;
156 recs_buf = malloc(recs_num * sizeof(struct llog_rec_hdr *));
157 if (recs_buf == NULL){
158 printf("Memory Alloc for recs_buf error.\n");
162 recs_pr = (struct llog_rec_hdr **)recs_buf;
164 ptr = file_buf + le32_to_cpu((*llog)->llh_hdr.lrh_len);
167 while (i < recs_num){
168 struct llog_rec_hdr *cur_rec = (struct llog_rec_hdr*)ptr;
169 int idx = le32_to_cpu(cur_rec->lrh_index);
170 recs_pr[i] = cur_rec;
172 if (ext2_test_bit(idx, (*llog)->llh_bitmap)) {
173 if (le32_to_cpu(cur_rec->lrh_type) != OBD_CFG_REC)
174 printf("rec #%d type=%x len=%u\n", idx,
175 cur_rec->lrh_type, cur_rec->lrh_len);
177 printf("Bit %d of %d not set\n", idx, recs_num);
178 cur_rec->lrh_padding = CANCELLED;
179 /* The header counts only set records */
183 ptr += le32_to_cpu(cur_rec->lrh_len);
184 if ((ptr - file_buf) > file_size) {
185 printf("The log is corrupt (too big at %d)\n", i);
193 *recs_number = recs_num;
208 void llog_unpack_buffer(int fd, struct llog_log_hdr *llog_buf,
209 struct llog_rec_hdr **recs_buf)
216 void print_llog_header(struct llog_log_hdr *llog_buf)
220 printf("Header size : %u\n",
221 le32_to_cpu(llog_buf->llh_hdr.lrh_len));
223 t = le64_to_cpu(llog_buf->llh_timestamp);
224 printf("Time : %s", ctime(&t));
226 printf("Number of records: %u\n",
227 le32_to_cpu(llog_buf->llh_count)-1);
229 printf("Target uuid : %s \n",
230 (char *)(&llog_buf->llh_tgtuuid));
232 /* Add the other info you want to view here */
234 printf("-----------------------\n");
238 static void print_1_cfg(struct lustre_cfg *lcfg)
243 printf("nid=%s("LPX64") ", libcfs_nid2str(lcfg->lcfg_nid),
246 printf("nal=%d ", lcfg->lcfg_nal);
247 for (i = 0; i < lcfg->lcfg_bufcount; i++)
248 printf("%d:%.*s ", i, lcfg->lcfg_buflens[i],
249 (char*)lustre_cfg_buf(lcfg, i));
254 static void print_setup_cfg(struct lustre_cfg *lcfg)
256 struct lov_desc *desc;
258 if ((lcfg->lcfg_bufcount == 2) &&
259 (lcfg->lcfg_buflens[1] == sizeof(*desc))) {
260 printf("lov_setup ");
261 printf("0:%s ", lustre_cfg_string(lcfg, 0));
262 printf("1:(struct lov_desc)\n");
263 desc = (struct lov_desc*)(lustre_cfg_string(lcfg, 1));
264 printf("\t\tuuid=%s ", (char*)desc->ld_uuid.uuid);
265 printf("stripe:cnt=%u ", desc->ld_default_stripe_count);
266 printf("size="LPU64" ", desc->ld_default_stripe_size);
267 printf("offset="LPU64" ", desc->ld_default_stripe_offset);
268 printf("pattern=%#x", desc->ld_pattern);
277 void print_lustre_cfg(struct lustre_cfg *lcfg, int *skip)
279 enum lcfg_command_type cmd = le32_to_cpu(lcfg->lcfg_command);
291 print_setup_cfg(lcfg);
304 case(LCFG_ADD_UUID):{
309 case(LCFG_DEL_UUID):{
314 case(LCFG_ADD_CONN):{
319 case(LCFG_DEL_CONN):{
324 case(LCFG_LOV_ADD_OBD):{
325 printf("lov_modify_tgts add ");
329 case(LCFG_LOV_DEL_OBD):{
330 printf("lov_modify_tgts del ");
335 printf("modify_mdc_tgts add ");
340 printf("modify_mdc_tgts del ");
344 case(LCFG_MOUNTOPT):{
345 printf("mount_option ");
349 case(LCFG_DEL_MOUNTOPT):{
350 printf("del_mount_option ");
354 case(LCFG_SET_TIMEOUT):{
355 printf("set_timeout=%d ", lcfg->lcfg_num);
358 case(LCFG_SET_LDLM_TIMEOUT):{
359 printf("set_ldlm_timeout=%d ", lcfg->lcfg_num);
362 case(LCFG_SET_UPCALL):{
363 printf("set_lustre_upcall ");
372 case(LCFG_SPTLRPC_CONF):{
373 printf("sptlrpc_conf ");
378 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
379 char createtime[26], canceltime[26] = "";
382 if (marker->cm_flags & CM_SKIP) {
383 if (marker->cm_flags & CM_START) {
384 printf("SKIP START ");
392 if (marker->cm_flags & CM_EXCLUDE) {
393 if (marker->cm_flags & CM_START)
394 printf("EXCLUDE START ");
396 printf("EXCLUDE END ");
399 /* Handle overflow of 32-bit time_t gracefully.
400 * The copy to time_tmp is needed in any case to
401 * keep the pointer happy, even on 64-bit systems. */
402 time_tmp = marker->cm_createtime;
403 if (time_tmp == marker->cm_createtime) {
404 ctime_r(&time_tmp, createtime);
405 createtime[strlen(createtime) - 1] = 0;
407 strcpy(createtime, "in the distant future");
410 if (marker->cm_canceltime) {
411 /* Like cm_createtime, we try to handle overflow of
412 * 32-bit time_t gracefully. The copy to time_tmp
413 * is also needed on 64-bit systems to keep the
414 * pointer happy, see bug 16771 */
415 time_tmp = marker->cm_canceltime;
416 if (time_tmp == marker->cm_canceltime) {
417 ctime_r(&time_tmp, canceltime);
418 canceltime[strlen(canceltime) - 1] = 0;
420 strcpy(canceltime, "in the distant future");
424 printf("marker %3d (flags=%#04x, v%d.%d.%d.%d) %-15s '%s' %s-%s",
425 marker->cm_step, marker->cm_flags,
426 OBD_OCD_VERSION_MAJOR(marker->cm_vers),
427 OBD_OCD_VERSION_MINOR(marker->cm_vers),
428 OBD_OCD_VERSION_PATCH(marker->cm_vers),
429 OBD_OCD_VERSION_FIX(marker->cm_vers),
430 marker->cm_tgtname, marker->cm_comment,
431 createtime, canceltime);
434 case(LCFG_POOL_NEW):{
439 case(LCFG_POOL_ADD):{
444 case(LCFG_POOL_REM):{
445 printf("pool remove ");
449 case(LCFG_POOL_DEL):{
450 printf("pool destroy ");
455 printf("unsupported cmd_code = %x\n",cmd);
461 void print_records(struct llog_rec_hdr **recs, int rec_number)
466 for(i = 0; i < rec_number; i++) {
467 printf("#%.2d (%.3d)", le32_to_cpu(recs[i]->lrh_index),
468 le32_to_cpu(recs[i]->lrh_len));
470 lopt = le32_to_cpu(recs[i]->lrh_type);
472 if (recs[i]->lrh_padding == CANCELLED)
475 if (lopt == OBD_CFG_REC) {
476 struct lustre_cfg *lcfg;
477 lcfg = (struct lustre_cfg *)((char*)(recs[i]) +
478 sizeof(struct llog_rec_hdr));
479 print_lustre_cfg(lcfg, &skip);
480 } else if (lopt == LLOG_PAD_MAGIC) {
483 printf("unknown type %x\n", lopt);