4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Intel Corporation.
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>
46 #include <libcfs/libcfs.h>
47 #include <lustre/lustre_idl.h>
48 #include <lustre_cfg.h>
50 static inline int ext2_test_bit(int nr, const void *addr)
52 #if __BYTE_ORDER == __BIG_ENDIAN
53 const unsigned char *tmp = addr;
54 return (tmp[nr >> 3] >> (nr & 7)) & 1;
56 return test_bit(nr, addr);
60 int llog_pack_buffer(int fd, struct llog_log_hdr **llog_buf,
61 struct llog_rec_hdr ***recs, int *recs_number);
63 void print_llog_header(struct llog_log_hdr *llog_buf);
64 void print_records(struct llog_rec_hdr **recs_buf,int rec_number);
65 void llog_unpack_buffer(int fd, struct llog_log_hdr *llog_buf,
66 struct llog_rec_hdr **recs_buf);
68 #define CANCELLED 0x678
70 #define PTL_CMD_BASE 100
71 char* portals_command[17]=
92 int main(int argc, char **argv)
96 struct llog_log_hdr *llog_buf = NULL;
97 struct llog_rec_hdr **recs_buf = NULL;
102 printf("Usage: llog_reader filename\n");
106 fd = open(argv[1],O_RDONLY);
108 printf("Could not open the file %s\n", argv[1]);
111 rc = llog_pack_buffer(fd, &llog_buf, &recs_buf, &rec_number);
113 printf("Could not pack buffer; rc=%d\n", rc);
117 print_llog_header(llog_buf);
118 print_records(recs_buf,rec_number);
119 llog_unpack_buffer(fd,llog_buf,recs_buf);
128 int llog_pack_buffer(int fd, struct llog_log_hdr **llog,
129 struct llog_rec_hdr ***recs,
132 int rc = 0, recs_num,rd;
135 char *file_buf=NULL, *recs_buf=NULL;
136 struct llog_rec_hdr **recs_pr=NULL;
142 printf("Get file stat error.\n");
145 file_size = st.st_size;
147 file_buf = malloc(file_size);
148 if (file_buf == NULL){
149 printf("Memory Alloc for file_buf error.\n");
153 *llog = (struct llog_log_hdr*)file_buf;
155 rd = read(fd,file_buf,file_size);
157 printf("Read file error.\n");
162 /* the llog header not countable here.*/
163 recs_num = le32_to_cpu((*llog)->llh_count)-1;
165 recs_buf = malloc(recs_num * sizeof(struct llog_rec_hdr *));
166 if (recs_buf == NULL){
167 printf("Memory Alloc for recs_buf error.\n");
171 recs_pr = (struct llog_rec_hdr **)recs_buf;
173 ptr = file_buf + le32_to_cpu((*llog)->llh_hdr.lrh_len);
176 while (i < recs_num){
177 struct llog_rec_hdr *cur_rec = (struct llog_rec_hdr*)ptr;
178 int idx = le32_to_cpu(cur_rec->lrh_index);
179 recs_pr[i] = cur_rec;
181 if (ext2_test_bit(idx, (*llog)->llh_bitmap)) {
182 if (le32_to_cpu(cur_rec->lrh_type) != OBD_CFG_REC)
183 printf("rec #%d type=%x len=%u\n", idx,
184 cur_rec->lrh_type, cur_rec->lrh_len);
186 printf("Bit %d of %d not set\n", idx, recs_num);
187 cur_rec->lrh_id = CANCELLED;
188 /* The header counts only set records */
192 ptr += le32_to_cpu(cur_rec->lrh_len);
193 if ((ptr - file_buf) > file_size) {
194 printf("The log is corrupt (too big at %d)\n", i);
202 *recs_number = recs_num;
217 void llog_unpack_buffer(int fd, struct llog_log_hdr *llog_buf,
218 struct llog_rec_hdr **recs_buf)
225 void print_llog_header(struct llog_log_hdr *llog_buf)
229 printf("Header size : %u\n",
230 le32_to_cpu(llog_buf->llh_hdr.lrh_len));
232 t = le64_to_cpu(llog_buf->llh_timestamp);
233 printf("Time : %s", ctime(&t));
235 printf("Number of records: %u\n",
236 le32_to_cpu(llog_buf->llh_count)-1);
238 printf("Target uuid : %s \n",
239 (char *)(&llog_buf->llh_tgtuuid));
241 /* Add the other info you want to view here */
243 printf("-----------------------\n");
247 static void print_1_cfg(struct lustre_cfg *lcfg)
252 printf("nid=%s("LPX64") ", libcfs_nid2str(lcfg->lcfg_nid),
255 printf("nal=%d ", lcfg->lcfg_nal);
256 for (i = 0; i < lcfg->lcfg_bufcount; i++)
257 printf("%d:%.*s ", i, lcfg->lcfg_buflens[i],
258 (char*)lustre_cfg_buf(lcfg, i));
263 static void print_setup_cfg(struct lustre_cfg *lcfg)
265 struct lov_desc *desc;
267 if ((lcfg->lcfg_bufcount == 2) &&
268 (lcfg->lcfg_buflens[1] == sizeof(*desc))) {
269 printf("lov_setup ");
270 printf("0:%s ", lustre_cfg_string(lcfg, 0));
271 printf("1:(struct lov_desc)\n");
272 desc = (struct lov_desc*)(lustre_cfg_string(lcfg, 1));
273 printf("\t\tuuid=%s ", (char*)desc->ld_uuid.uuid);
274 printf("stripe:cnt=%u ", desc->ld_default_stripe_count);
275 printf("size="LPU64" ", desc->ld_default_stripe_size);
276 printf("offset="LPU64" ", desc->ld_default_stripe_offset);
277 printf("pattern=%#x", desc->ld_pattern);
286 void print_lustre_cfg(struct lustre_cfg *lcfg, int *skip)
288 enum lcfg_command_type cmd = le32_to_cpu(lcfg->lcfg_command);
300 print_setup_cfg(lcfg);
313 case(LCFG_ADD_UUID):{
318 case(LCFG_DEL_UUID):{
323 case(LCFG_ADD_CONN):{
328 case(LCFG_DEL_CONN):{
333 case(LCFG_LOV_ADD_OBD):{
334 printf("lov_modify_tgts add ");
338 case(LCFG_LOV_DEL_OBD):{
339 printf("lov_modify_tgts del ");
344 printf("modify_mdc_tgts add ");
349 printf("modify_mdc_tgts del ");
353 case(LCFG_MOUNTOPT):{
354 printf("mount_option ");
358 case(LCFG_DEL_MOUNTOPT):{
359 printf("del_mount_option ");
363 case(LCFG_SET_TIMEOUT):{
364 printf("set_timeout=%d ", lcfg->lcfg_num);
367 case(LCFG_SET_LDLM_TIMEOUT):{
368 printf("set_ldlm_timeout=%d ", lcfg->lcfg_num);
371 case(LCFG_SET_UPCALL):{
372 printf("set_lustre_upcall ");
381 case(LCFG_SET_PARAM):{
382 printf("set_param ");
386 case(LCFG_SPTLRPC_CONF):{
387 printf("sptlrpc_conf ");
392 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
393 char createtime[26], canceltime[26] = "";
396 if (marker->cm_flags & CM_SKIP) {
397 if (marker->cm_flags & CM_START) {
398 printf("SKIP START ");
406 if (marker->cm_flags & CM_EXCLUDE) {
407 if (marker->cm_flags & CM_START)
408 printf("EXCLUDE START ");
410 printf("EXCLUDE END ");
413 /* Handle overflow of 32-bit time_t gracefully.
414 * The copy to time_tmp is needed in any case to
415 * keep the pointer happy, even on 64-bit systems. */
416 time_tmp = marker->cm_createtime;
417 if (time_tmp == marker->cm_createtime) {
418 ctime_r(&time_tmp, createtime);
419 createtime[strlen(createtime) - 1] = 0;
421 strcpy(createtime, "in the distant future");
424 if (marker->cm_canceltime) {
425 /* Like cm_createtime, we try to handle overflow of
426 * 32-bit time_t gracefully. The copy to time_tmp
427 * is also needed on 64-bit systems to keep the
428 * pointer happy, see bug 16771 */
429 time_tmp = marker->cm_canceltime;
430 if (time_tmp == marker->cm_canceltime) {
431 ctime_r(&time_tmp, canceltime);
432 canceltime[strlen(canceltime) - 1] = 0;
434 strcpy(canceltime, "in the distant future");
438 printf("marker %3d (flags=%#04x, v%d.%d.%d.%d) %-15s '%s' %s-%s",
439 marker->cm_step, marker->cm_flags,
440 OBD_OCD_VERSION_MAJOR(marker->cm_vers),
441 OBD_OCD_VERSION_MINOR(marker->cm_vers),
442 OBD_OCD_VERSION_PATCH(marker->cm_vers),
443 OBD_OCD_VERSION_FIX(marker->cm_vers),
444 marker->cm_tgtname, marker->cm_comment,
445 createtime, canceltime);
448 case(LCFG_POOL_NEW):{
453 case(LCFG_POOL_ADD):{
458 case(LCFG_POOL_REM):{
459 printf("pool remove ");
463 case(LCFG_POOL_DEL):{
464 printf("pool destroy ");
469 printf("unsupported cmd_code = %x\n",cmd);
475 static void print_logid(struct llog_logid_rec *lid)
477 printf("ogen=%X name="DOSTID"\n",
478 lid->lid_id.lgl_ogen,
479 POSTID(&lid->lid_id.lgl_oi));
482 static void print_hsm_action(struct llog_agent_req_rec *larr)
487 sz = larr->arr_hai.hai_len - sizeof(larr->arr_hai);
488 printf("lrh=[type=%X len=%d idx=%d] fid="DFID
489 " compound/cookie="LPX64"/"LPX64
490 " status=%s action=%s archive#=%d flags="LPX64
491 " create="LPU64" change="LPU64
492 " extent="LPX64"-"LPX64" gid="LPX64" datalen=%d"
494 larr->arr_hdr.lrh_type,
495 larr->arr_hdr.lrh_len, larr->arr_hdr.lrh_index,
496 PFID(&larr->arr_hai.hai_fid),
497 larr->arr_compound_id, larr->arr_hai.hai_cookie,
498 agent_req_status2name(larr->arr_status),
499 hsm_copytool_action2name(larr->arr_hai.hai_action),
500 larr->arr_archive_id,
502 larr->arr_req_create, larr->arr_req_change,
503 larr->arr_hai.hai_extent.offset,
504 larr->arr_hai.hai_extent.length,
505 larr->arr_hai.hai_gid, sz,
506 hai_dump_data_field(&larr->arr_hai, buf, sizeof(buf)));
509 void print_records(struct llog_rec_hdr **recs, int rec_number)
514 for (i = 0; i < rec_number; i++) {
515 printf("#%.2d (%.3d)", le32_to_cpu(recs[i]->lrh_index),
516 le32_to_cpu(recs[i]->lrh_len));
518 lopt = le32_to_cpu(recs[i]->lrh_type);
520 if (recs[i]->lrh_id == CANCELLED)
526 (struct lustre_cfg *)((char *)(recs[i]) +
527 sizeof(struct llog_rec_hdr)), &skip);
532 case LLOG_LOGID_MAGIC:
533 print_logid((struct llog_logid_rec *)recs[i]);
536 print_hsm_action((struct llog_agent_req_rec *)recs[i]);
539 printf("unknown type %x\n", lopt);