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, 2014, 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 <lnet/nidstr.h>
48 #include <lustre/lustre_idl.h>
49 #include <lustre_cfg.h>
51 static inline int ext2_test_bit(int nr, const void *addr)
53 #if __BYTE_ORDER == __BIG_ENDIAN
54 const unsigned char *tmp = addr;
55 return (tmp[nr >> 3] >> (nr & 7)) & 1;
57 return test_bit(nr, addr);
61 int llog_pack_buffer(int fd, struct llog_log_hdr **llog_buf,
62 struct llog_rec_hdr ***recs, int *recs_number);
64 void print_llog_header(struct llog_log_hdr *llog_buf);
65 void print_records(struct llog_rec_hdr **recs_buf,int rec_number);
66 void llog_unpack_buffer(int fd, struct llog_log_hdr *llog_buf,
67 struct llog_rec_hdr **recs_buf);
69 #define CANCELLED 0x678
71 #define PTL_CMD_BASE 100
72 char* portals_command[17]=
93 int main(int argc, char **argv)
97 struct llog_log_hdr *llog_buf = NULL;
98 struct llog_rec_hdr **recs_buf = NULL;
103 printf("Usage: llog_reader filename\n");
107 fd = open(argv[1],O_RDONLY);
109 printf("Could not open the file %s\n", argv[1]);
112 rc = llog_pack_buffer(fd, &llog_buf, &recs_buf, &rec_number);
114 printf("Could not pack buffer; rc=%d\n", rc);
118 print_llog_header(llog_buf);
119 print_records(recs_buf,rec_number);
120 llog_unpack_buffer(fd,llog_buf,recs_buf);
129 int llog_pack_buffer(int fd, struct llog_log_hdr **llog,
130 struct llog_rec_hdr ***recs,
133 int rc = 0, recs_num,rd;
136 char *file_buf=NULL, *recs_buf=NULL;
137 struct llog_rec_hdr **recs_pr=NULL;
143 printf("Get file stat error.\n");
146 file_size = st.st_size;
148 file_buf = malloc(file_size);
149 if (file_buf == NULL){
150 printf("Memory Alloc for file_buf error.\n");
154 *llog = (struct llog_log_hdr*)file_buf;
156 rd = read(fd,file_buf,file_size);
158 printf("Read file error.\n");
163 /* the llog header not countable here.*/
164 recs_num = le32_to_cpu((*llog)->llh_count)-1;
166 recs_buf = malloc(recs_num * sizeof(struct llog_rec_hdr *));
167 if (recs_buf == NULL){
168 printf("Memory Alloc for recs_buf error.\n");
172 recs_pr = (struct llog_rec_hdr **)recs_buf;
174 ptr = file_buf + le32_to_cpu((*llog)->llh_hdr.lrh_len);
177 while (i < recs_num){
178 struct llog_rec_hdr *cur_rec = (struct llog_rec_hdr*)ptr;
179 int idx = le32_to_cpu(cur_rec->lrh_index);
180 recs_pr[i] = cur_rec;
182 if (ext2_test_bit(idx, (*llog)->llh_bitmap)) {
183 if (le32_to_cpu(cur_rec->lrh_type) != OBD_CFG_REC)
184 printf("rec #%d type=%x len=%u\n", idx,
185 cur_rec->lrh_type, cur_rec->lrh_len);
187 printf("Bit %d of %d not set\n", idx, recs_num);
188 cur_rec->lrh_id = CANCELLED;
189 /* The header counts only set records */
193 ptr += le32_to_cpu(cur_rec->lrh_len);
194 if ((ptr - file_buf) > file_size) {
195 printf("The log is corrupt (too big at %d)\n", i);
203 *recs_number = recs_num;
218 void llog_unpack_buffer(int fd, struct llog_log_hdr *llog_buf,
219 struct llog_rec_hdr **recs_buf)
226 void print_llog_header(struct llog_log_hdr *llog_buf)
230 printf("Header size : %u\n",
231 le32_to_cpu(llog_buf->llh_hdr.lrh_len));
233 t = le64_to_cpu(llog_buf->llh_timestamp);
234 printf("Time : %s", ctime(&t));
236 printf("Number of records: %u\n",
237 le32_to_cpu(llog_buf->llh_count)-1);
239 printf("Target uuid : %s \n",
240 (char *)(&llog_buf->llh_tgtuuid));
242 /* Add the other info you want to view here */
244 printf("-----------------------\n");
248 static void print_1_cfg(struct lustre_cfg *lcfg)
253 printf("nid=%s("LPX64") ", libcfs_nid2str(lcfg->lcfg_nid),
256 printf("nal=%d ", lcfg->lcfg_nal);
257 for (i = 0; i < lcfg->lcfg_bufcount; i++)
258 printf("%d:%.*s ", i, lcfg->lcfg_buflens[i],
259 (char*)lustre_cfg_buf(lcfg, i));
264 static void print_setup_cfg(struct lustre_cfg *lcfg)
266 struct lov_desc *desc;
268 if ((lcfg->lcfg_bufcount == 2) &&
269 (lcfg->lcfg_buflens[1] == sizeof(*desc))) {
270 printf("lov_setup ");
271 printf("0:%s ", lustre_cfg_string(lcfg, 0));
272 printf("1:(struct lov_desc)\n");
273 desc = (struct lov_desc*)(lustre_cfg_string(lcfg, 1));
274 printf("\t\tuuid=%s ", (char*)desc->ld_uuid.uuid);
275 printf("stripe:cnt=%u ", desc->ld_default_stripe_count);
276 printf("size="LPU64" ", desc->ld_default_stripe_size);
277 printf("offset="LPU64" ", desc->ld_default_stripe_offset);
278 printf("pattern=%#x", desc->ld_pattern);
287 void print_lustre_cfg(struct lustre_cfg *lcfg, int *skip)
289 enum lcfg_command_type cmd = le32_to_cpu(lcfg->lcfg_command);
301 print_setup_cfg(lcfg);
314 case(LCFG_ADD_UUID):{
319 case(LCFG_DEL_UUID):{
324 case(LCFG_ADD_CONN):{
329 case(LCFG_DEL_CONN):{
334 case(LCFG_LOV_ADD_OBD):{
335 printf("lov_modify_tgts add ");
339 case(LCFG_LOV_DEL_OBD):{
340 printf("lov_modify_tgts del ");
345 printf("modify_mdc_tgts add ");
350 printf("modify_mdc_tgts del ");
354 case(LCFG_MOUNTOPT):{
355 printf("mount_option ");
359 case(LCFG_DEL_MOUNTOPT):{
360 printf("del_mount_option ");
364 case(LCFG_SET_TIMEOUT):{
365 printf("set_timeout=%d ", lcfg->lcfg_num);
368 case(LCFG_SET_LDLM_TIMEOUT):{
369 printf("set_ldlm_timeout=%d ", lcfg->lcfg_num);
372 case(LCFG_SET_UPCALL):{
373 printf("set_lustre_upcall ");
382 case(LCFG_SET_PARAM):{
383 printf("set_param ");
387 case(LCFG_SPTLRPC_CONF):{
388 printf("sptlrpc_conf ");
393 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
394 char createtime[26], canceltime[26] = "";
397 if (marker->cm_flags & CM_SKIP) {
398 if (marker->cm_flags & CM_START) {
399 printf("SKIP START ");
407 if (marker->cm_flags & CM_EXCLUDE) {
408 if (marker->cm_flags & CM_START)
409 printf("EXCLUDE START ");
411 printf("EXCLUDE END ");
414 /* Handle overflow of 32-bit time_t gracefully.
415 * The copy to time_tmp is needed in any case to
416 * keep the pointer happy, even on 64-bit systems. */
417 time_tmp = marker->cm_createtime;
418 if (time_tmp == marker->cm_createtime) {
419 ctime_r(&time_tmp, createtime);
420 createtime[strlen(createtime) - 1] = 0;
422 strcpy(createtime, "in the distant future");
425 if (marker->cm_canceltime) {
426 /* Like cm_createtime, we try to handle overflow of
427 * 32-bit time_t gracefully. The copy to time_tmp
428 * is also needed on 64-bit systems to keep the
429 * pointer happy, see bug 16771 */
430 time_tmp = marker->cm_canceltime;
431 if (time_tmp == marker->cm_canceltime) {
432 ctime_r(&time_tmp, canceltime);
433 canceltime[strlen(canceltime) - 1] = 0;
435 strcpy(canceltime, "in the distant future");
439 printf("marker %3d (flags=%#04x, v%d.%d.%d.%d) %-15s '%s' %s-%s",
440 marker->cm_step, marker->cm_flags,
441 OBD_OCD_VERSION_MAJOR(marker->cm_vers),
442 OBD_OCD_VERSION_MINOR(marker->cm_vers),
443 OBD_OCD_VERSION_PATCH(marker->cm_vers),
444 OBD_OCD_VERSION_FIX(marker->cm_vers),
445 marker->cm_tgtname, marker->cm_comment,
446 createtime, canceltime);
449 case(LCFG_POOL_NEW):{
454 case(LCFG_POOL_ADD):{
459 case(LCFG_POOL_REM):{
460 printf("pool remove ");
464 case(LCFG_POOL_DEL):{
465 printf("pool destroy ");
470 printf("unsupported cmd_code = %x\n",cmd);
476 static void print_logid(struct llog_logid_rec *lid)
478 printf("ogen=%X name="DOSTID"\n",
479 lid->lid_id.lgl_ogen,
480 POSTID(&lid->lid_id.lgl_oi));
483 static void print_hsm_action(struct llog_agent_req_rec *larr)
488 sz = larr->arr_hai.hai_len - sizeof(larr->arr_hai);
489 printf("lrh=[type=%X len=%d idx=%d] fid="DFID
490 " compound/cookie="LPX64"/"LPX64
491 " status=%s action=%s archive#=%d flags="LPX64
492 " create="LPU64" change="LPU64
493 " extent="LPX64"-"LPX64" gid="LPX64" datalen=%d"
495 larr->arr_hdr.lrh_type,
496 larr->arr_hdr.lrh_len, larr->arr_hdr.lrh_index,
497 PFID(&larr->arr_hai.hai_fid),
498 larr->arr_compound_id, larr->arr_hai.hai_cookie,
499 agent_req_status2name(larr->arr_status),
500 hsm_copytool_action2name(larr->arr_hai.hai_action),
501 larr->arr_archive_id,
503 larr->arr_req_create, larr->arr_req_change,
504 larr->arr_hai.hai_extent.offset,
505 larr->arr_hai.hai_extent.length,
506 larr->arr_hai.hai_gid, sz,
507 hai_dump_data_field(&larr->arr_hai, buf, sizeof(buf)));
510 void print_records(struct llog_rec_hdr **recs, int rec_number)
515 for (i = 0; i < rec_number; i++) {
516 printf("#%.2d (%.3d)", le32_to_cpu(recs[i]->lrh_index),
517 le32_to_cpu(recs[i]->lrh_len));
519 lopt = le32_to_cpu(recs[i]->lrh_type);
521 if (recs[i]->lrh_id == CANCELLED)
527 (struct lustre_cfg *)((char *)(recs[i]) +
528 sizeof(struct llog_rec_hdr)), &skip);
533 case LLOG_LOGID_MAGIC:
534 print_logid((struct llog_logid_rec *)recs[i]);
537 print_hsm_action((struct llog_agent_req_rec *)recs[i]);
540 printf("unknown type %x\n", lopt);