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>
49 #include <lnet/nidstr.h>
50 #include <lustre/lustre_idl.h>
51 #include <lustre/lustreapi.h>
52 #include <lustre_cfg.h>
54 static inline int ext2_test_bit(int nr, const void *addr)
56 #if __BYTE_ORDER == __BIG_ENDIAN
57 const unsigned char *tmp = addr;
58 return (tmp[nr >> 3] >> (nr & 7)) & 1;
60 const unsigned long *tmp = addr;
61 return ((1UL << (nr & (BITS_PER_LONG - 1))) &
62 ((tmp)[nr / BITS_PER_LONG])) != 0;
66 int llog_pack_buffer(int fd, struct llog_log_hdr **llog_buf,
67 struct llog_rec_hdr ***recs, int *recs_number);
69 void print_llog_header(struct llog_log_hdr *llog_buf);
70 void print_records(struct llog_rec_hdr **recs_buf,int rec_number);
71 void llog_unpack_buffer(int fd, struct llog_log_hdr *llog_buf,
72 struct llog_rec_hdr **recs_buf);
74 #define CANCELLED 0x678
76 #define PTL_CMD_BASE 100
77 char* portals_command[17]=
98 int main(int argc, char **argv)
102 struct llog_log_hdr *llog_buf = NULL;
103 struct llog_rec_hdr **recs_buf = NULL;
108 printf("Usage: llog_reader filename\n");
112 fd = open(argv[1],O_RDONLY);
115 llapi_error(LLAPI_MSG_ERROR, rc, "Could not open the file %s.",
119 rc = llog_pack_buffer(fd, &llog_buf, &recs_buf, &rec_number);
121 llapi_error(LLAPI_MSG_ERROR, rc, "Could not pack buffer.");
125 print_llog_header(llog_buf);
126 print_records(recs_buf,rec_number);
127 llog_unpack_buffer(fd,llog_buf,recs_buf);
136 int llog_pack_buffer(int fd, struct llog_log_hdr **llog,
137 struct llog_rec_hdr ***recs,
140 int rc = 0, recs_num,rd;
143 char *file_buf=NULL, *recs_buf=NULL;
144 struct llog_rec_hdr **recs_pr=NULL;
151 llapi_error(LLAPI_MSG_ERROR, rc, "Got file stat error.");
154 file_size = st.st_size;
155 if (file_size == 0) {
157 llapi_error(LLAPI_MSG_ERROR, rc, "File is empty.");
161 file_buf = malloc(file_size);
162 if (file_buf == NULL){
164 llapi_error(LLAPI_MSG_ERROR, rc, "Memory Alloc for file_buf.");
167 *llog = (struct llog_log_hdr*)file_buf;
169 rd = read(fd,file_buf,file_size);
172 llapi_error(LLAPI_MSG_ERROR, rc, "Read file error.");
176 /* the llog header not countable here.*/
177 recs_num = le32_to_cpu((*llog)->llh_count)-1;
179 recs_buf = malloc(recs_num * sizeof(struct llog_rec_hdr *));
180 if (recs_buf == NULL){
182 llapi_error(LLAPI_MSG_ERROR, rc, "Memory Alloc for recs_buf.");
185 recs_pr = (struct llog_rec_hdr **)recs_buf;
187 ptr = file_buf + le32_to_cpu((*llog)->llh_hdr.lrh_len);
190 while (i < recs_num){
191 struct llog_rec_hdr *cur_rec;
194 if (ptr + sizeof(struct llog_rec_hdr) >
195 file_buf + file_size) {
197 llapi_error(LLAPI_MSG_ERROR, rc,
198 "The log is corrupt (too big at %d)", i);
202 cur_rec = (struct llog_rec_hdr *)ptr;
203 idx = le32_to_cpu(cur_rec->lrh_index);
204 recs_pr[i] = cur_rec;
206 if (ext2_test_bit(idx, LLOG_HDR_BITMAP(*llog))) {
207 if (le32_to_cpu(cur_rec->lrh_type) != OBD_CFG_REC)
208 printf("rec #%d type=%x len=%u\n", idx,
209 cur_rec->lrh_type, cur_rec->lrh_len);
211 printf("Bit %d of %d not set\n", idx, recs_num);
212 cur_rec->lrh_id = CANCELLED;
213 /* The header counts only set records */
217 ptr += le32_to_cpu(cur_rec->lrh_len);
218 if ((ptr - file_buf) > file_size) {
219 printf("The log is corrupt (too big at %d)\n", i);
227 *recs_number = recs_num;
242 void llog_unpack_buffer(int fd, struct llog_log_hdr *llog_buf,
243 struct llog_rec_hdr **recs_buf)
250 void print_llog_header(struct llog_log_hdr *llog_buf)
254 printf("Header size : %u\n",
255 le32_to_cpu(llog_buf->llh_hdr.lrh_len));
257 t = le64_to_cpu(llog_buf->llh_timestamp);
258 printf("Time : %s", ctime(&t));
260 printf("Number of records: %u\n",
261 le32_to_cpu(llog_buf->llh_count)-1);
263 printf("Target uuid : %s \n",
264 (char *)(&llog_buf->llh_tgtuuid));
266 /* Add the other info you want to view here */
268 printf("-----------------------\n");
272 static void print_1_cfg(struct lustre_cfg *lcfg)
277 printf("nid=%s("LPX64") ", libcfs_nid2str(lcfg->lcfg_nid),
280 printf("nal=%d ", lcfg->lcfg_nal);
281 for (i = 0; i < lcfg->lcfg_bufcount; i++)
282 printf("%d:%.*s ", i, lcfg->lcfg_buflens[i],
283 (char*)lustre_cfg_buf(lcfg, i));
288 static void print_setup_cfg(struct lustre_cfg *lcfg)
290 struct lov_desc *desc;
292 if ((lcfg->lcfg_bufcount == 2) &&
293 (lcfg->lcfg_buflens[1] == sizeof(*desc))) {
294 printf("lov_setup ");
295 printf("0:%s ", lustre_cfg_string(lcfg, 0));
296 printf("1:(struct lov_desc)\n");
297 desc = (struct lov_desc*)(lustre_cfg_string(lcfg, 1));
298 printf("\t\tuuid=%s ", (char*)desc->ld_uuid.uuid);
299 printf("stripe:cnt=%u ", desc->ld_default_stripe_count);
300 printf("size="LPU64" ", desc->ld_default_stripe_size);
301 printf("offset="LPU64" ", desc->ld_default_stripe_offset);
302 printf("pattern=%#x", desc->ld_pattern);
311 void print_lustre_cfg(struct lustre_cfg *lcfg, int *skip)
313 enum lcfg_command_type cmd = le32_to_cpu(lcfg->lcfg_command);
325 print_setup_cfg(lcfg);
338 case(LCFG_ADD_UUID):{
343 case(LCFG_DEL_UUID):{
348 case(LCFG_ADD_CONN):{
353 case(LCFG_DEL_CONN):{
358 case(LCFG_LOV_ADD_OBD):{
359 printf("lov_modify_tgts add ");
363 case(LCFG_LOV_DEL_OBD):{
364 printf("lov_modify_tgts del ");
369 printf("modify_mdc_tgts add ");
374 printf("modify_mdc_tgts del ");
378 case(LCFG_MOUNTOPT):{
379 printf("mount_option ");
383 case(LCFG_DEL_MOUNTOPT):{
384 printf("del_mount_option ");
388 case(LCFG_SET_TIMEOUT):{
389 printf("set_timeout=%d ", lcfg->lcfg_num);
392 case(LCFG_SET_LDLM_TIMEOUT):{
393 printf("set_ldlm_timeout=%d ", lcfg->lcfg_num);
396 case(LCFG_SET_UPCALL):{
397 printf("set_lustre_upcall ");
406 case(LCFG_SET_PARAM):{
407 printf("set_param ");
411 case(LCFG_SPTLRPC_CONF):{
412 printf("sptlrpc_conf ");
417 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
418 char createtime[26], canceltime[26] = "";
421 if (marker->cm_flags & CM_SKIP) {
422 if (marker->cm_flags & CM_START) {
423 printf("SKIP START ");
431 if (marker->cm_flags & CM_EXCLUDE) {
432 if (marker->cm_flags & CM_START)
433 printf("EXCLUDE START ");
435 printf("EXCLUDE END ");
438 /* Handle overflow of 32-bit time_t gracefully.
439 * The copy to time_tmp is needed in any case to
440 * keep the pointer happy, even on 64-bit systems. */
441 time_tmp = marker->cm_createtime;
442 if (time_tmp == marker->cm_createtime) {
443 ctime_r(&time_tmp, createtime);
444 createtime[strlen(createtime) - 1] = 0;
446 strcpy(createtime, "in the distant future");
449 if (marker->cm_canceltime) {
450 /* Like cm_createtime, we try to handle overflow of
451 * 32-bit time_t gracefully. The copy to time_tmp
452 * is also needed on 64-bit systems to keep the
453 * pointer happy, see bug 16771 */
454 time_tmp = marker->cm_canceltime;
455 if (time_tmp == marker->cm_canceltime) {
456 ctime_r(&time_tmp, canceltime);
457 canceltime[strlen(canceltime) - 1] = 0;
459 strcpy(canceltime, "in the distant future");
463 printf("marker %3d (flags=%#04x, v%d.%d.%d.%d) %-15s '%s' %s-%s",
464 marker->cm_step, marker->cm_flags,
465 OBD_OCD_VERSION_MAJOR(marker->cm_vers),
466 OBD_OCD_VERSION_MINOR(marker->cm_vers),
467 OBD_OCD_VERSION_PATCH(marker->cm_vers),
468 OBD_OCD_VERSION_FIX(marker->cm_vers),
469 marker->cm_tgtname, marker->cm_comment,
470 createtime, canceltime);
473 case(LCFG_POOL_NEW):{
478 case(LCFG_POOL_ADD):{
483 case(LCFG_POOL_REM):{
484 printf("pool remove ");
488 case(LCFG_POOL_DEL):{
489 printf("pool destroy ");
494 printf("unsupported cmd_code = %x\n",cmd);
500 static void print_logid(struct llog_logid_rec *lid)
502 printf("ogen=%X name="DOSTID"\n",
503 lid->lid_id.lgl_ogen,
504 POSTID(&lid->lid_id.lgl_oi));
507 static void print_hsm_action(struct llog_agent_req_rec *larr)
512 sz = larr->arr_hai.hai_len - sizeof(larr->arr_hai);
513 printf("lrh=[type=%X len=%d idx=%d] fid="DFID
514 " compound/cookie="LPX64"/"LPX64
515 " status=%s action=%s archive#=%d flags="LPX64
516 " create="LPU64" change="LPU64
517 " extent="LPX64"-"LPX64" gid="LPX64" datalen=%d"
519 larr->arr_hdr.lrh_type,
520 larr->arr_hdr.lrh_len, larr->arr_hdr.lrh_index,
521 PFID(&larr->arr_hai.hai_fid),
522 larr->arr_compound_id, larr->arr_hai.hai_cookie,
523 agent_req_status2name(larr->arr_status),
524 hsm_copytool_action2name(larr->arr_hai.hai_action),
525 larr->arr_archive_id,
527 larr->arr_req_create, larr->arr_req_change,
528 larr->arr_hai.hai_extent.offset,
529 larr->arr_hai.hai_extent.length,
530 larr->arr_hai.hai_gid, sz,
531 hai_dump_data_field(&larr->arr_hai, buf, sizeof(buf)));
534 void print_records(struct llog_rec_hdr **recs, int rec_number)
539 for (i = 0; i < rec_number; i++) {
540 printf("#%.2d (%.3d)", le32_to_cpu(recs[i]->lrh_index),
541 le32_to_cpu(recs[i]->lrh_len));
543 lopt = le32_to_cpu(recs[i]->lrh_type);
545 if (recs[i]->lrh_id == CANCELLED)
551 (struct lustre_cfg *)((char *)(recs[i]) +
552 sizeof(struct llog_rec_hdr)), &skip);
557 case LLOG_LOGID_MAGIC:
558 print_logid((struct llog_logid_rec *)recs[i]);
561 print_hsm_action((struct llog_agent_req_rec *)recs[i]);
564 printf("unknown type %x\n", lopt);