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, 2015, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 /** \defgroup llog_reader Lustre Log Reader
38 * Interpret llogs used for storing configuration and changelog data
44 #include <sys/types.h>
52 #include <linux/magic.h>
55 #include <lnet/nidstr.h>
56 #include <lustre/lustre_idl.h>
57 #include <lustre/lustreapi.h>
58 #include <lustre_log_user.h>
59 #include <lustre_cfg.h>
61 static inline int ext2_test_bit(int nr, const void *addr)
63 #if __BYTE_ORDER == __BIG_ENDIAN
64 const unsigned char *tmp = addr;
65 return (tmp[nr >> 3] >> (nr & 7)) & 1;
67 const unsigned long *tmp = addr;
68 return ((1UL << (nr & (BITS_PER_LONG - 1))) &
69 ((tmp)[nr / BITS_PER_LONG])) != 0;
73 int llog_pack_buffer(int fd, struct llog_log_hdr **llog_buf,
74 struct llog_rec_hdr ***recs, int *recs_number);
76 void print_llog_header(struct llog_log_hdr *llog_buf);
77 static void print_records(struct llog_rec_hdr **recs_buf,
78 int rec_number, int is_ext);
79 void llog_unpack_buffer(int fd, struct llog_log_hdr *llog_buf,
80 struct llog_rec_hdr **recs_buf);
82 #define CANCELLED 0x678
84 #define PTL_CMD_BASE 100
85 char* portals_command[17]=
106 int is_fstype_ext(int fd)
111 rc = fstatfs(fd, &st);
113 llapi_error(LLAPI_MSG_ERROR, rc, "Got statfs error.");
117 return (st.f_type == EXT4_SUPER_MAGIC);
122 * Attempt to display a path to the object (file) containing changelog entries,
123 * referred to by this changelog_catalog record.
125 * This path depends on the implementation of the OSD device; zfs-osd and
126 * ldiskfs-osd are different.
128 * Assumes that if the file system containing the changelog_catalog is
129 * ext{2,3,4}, the backend is ldiskfs-osd; otherwise it is either zfs-osd or at
130 * least names objects based on FID and the zfs-osd path (which includes the
131 * FID) will be sufficient.
133 * The Object ID stored in the record is also displayed untranslated.
135 #define OSD_OI_FID_NR (1UL << 7)
136 static void print_log_path(struct llog_logid_rec *lid, int is_ext)
139 char object_path[255];
140 struct lu_fid fid_from_logid;
142 logid_to_fid(&lid->lid_id, &fid_from_logid);
145 snprintf(object_path, sizeof(object_path),
146 "O/"LPU64"/d%u/%u", fid_from_logid.f_seq,
147 fid_from_logid.f_oid % 32, fid_from_logid.f_oid);
149 snprintf(object_path, sizeof(object_path),
150 "oi."LPU64"/"DFID_NOBRACE,
151 fid_from_logid.f_seq & (OSD_OI_FID_NR - 1) ,
152 PFID(&fid_from_logid));
154 printf("ogen=%X id="DOSTID" path=%s\n",
155 lid->lid_id.lgl_ogen, POSTID(&lid->lid_id.lgl_oi),
159 int main(int argc, char **argv)
164 struct llog_log_hdr *llog_buf = NULL;
165 struct llog_rec_hdr **recs_buf = NULL;
170 printf("Usage: llog_reader filename\n");
174 fd = open(argv[1], O_RDONLY);
177 llapi_error(LLAPI_MSG_ERROR, rc, "Could not open the file %s.",
182 is_ext = is_fstype_ext(fd);
184 printf("Unable to determine type of filesystem containing %s\n",
189 rc = llog_pack_buffer(fd, &llog_buf, &recs_buf, &rec_number);
191 llapi_error(LLAPI_MSG_ERROR, rc, "Could not pack buffer.");
195 print_llog_header(llog_buf);
196 print_records(recs_buf, rec_number, is_ext);
197 llog_unpack_buffer(fd, llog_buf, recs_buf);
207 int llog_pack_buffer(int fd, struct llog_log_hdr **llog,
208 struct llog_rec_hdr ***recs,
211 int rc = 0, recs_num, rd;
214 char *file_buf = NULL, *recs_buf = NULL;
215 struct llog_rec_hdr **recs_pr = NULL;
222 llapi_error(LLAPI_MSG_ERROR, rc, "Got file stat error.");
225 file_size = st.st_size;
226 if (file_size == 0) {
228 llapi_error(LLAPI_MSG_ERROR, rc, "File is empty.");
232 file_buf = malloc(file_size);
233 if (file_buf == NULL) {
235 llapi_error(LLAPI_MSG_ERROR, rc, "Memory Alloc for file_buf.");
238 *llog = (struct llog_log_hdr *)file_buf;
240 rd = read(fd, file_buf, file_size);
241 if (rd < file_size) {
243 llapi_error(LLAPI_MSG_ERROR, rc, "Read file error.");
247 /* the llog header not countable here.*/
248 recs_num = le32_to_cpu((*llog)->llh_count) - 1;
250 recs_buf = malloc(recs_num * sizeof(struct llog_rec_hdr *));
251 if (recs_buf == NULL) {
253 llapi_error(LLAPI_MSG_ERROR, rc, "Memory Alloc for recs_buf.");
256 recs_pr = (struct llog_rec_hdr **)recs_buf;
258 ptr = file_buf + le32_to_cpu((*llog)->llh_hdr.lrh_len);
261 while (ptr < (file_buf + file_size)) {
262 struct llog_rec_hdr *cur_rec;
264 unsigned long offset;
266 if (ptr + sizeof(struct llog_rec_hdr) >
267 file_buf + file_size) {
269 llapi_error(LLAPI_MSG_ERROR, rc,
270 "The log is corrupt (too big at %d)", i);
274 cur_rec = (struct llog_rec_hdr *)ptr;
275 idx = le32_to_cpu(cur_rec->lrh_index);
276 recs_pr[i] = cur_rec;
277 offset = (unsigned long)ptr - (unsigned long)file_buf;
278 if (cur_rec->lrh_len == 0 ||
279 cur_rec->lrh_len > (*llog)->llh_hdr.lrh_len) {
280 cur_rec->lrh_len = (*llog)->llh_hdr.lrh_len -
281 offset % (*llog)->llh_hdr.lrh_len;
282 printf("off %lu skip %u to next chunk.\n", offset,
285 } else if (ext2_test_bit(idx, LLOG_HDR_BITMAP(*llog))) {
286 printf("rec #%d type=%x len=%u offset %lu\n", idx,
287 cur_rec->lrh_type, cur_rec->lrh_len, offset);
289 printf("Bit %d of %d not set\n", idx, recs_num);
290 cur_rec->lrh_id = CANCELLED;
291 /* The header counts only set records */
295 ptr += le32_to_cpu(cur_rec->lrh_len);
296 if ((ptr - file_buf) > file_size) {
297 printf("The log is corrupt (too big at %d)\n", i);
305 *recs_number = recs_num;
320 void llog_unpack_buffer(int fd, struct llog_log_hdr *llog_buf,
321 struct llog_rec_hdr **recs_buf)
328 void print_llog_header(struct llog_log_hdr *llog_buf)
332 printf("Header size : %u\n",
333 le32_to_cpu(llog_buf->llh_hdr.lrh_len));
335 t = le64_to_cpu(llog_buf->llh_timestamp);
336 printf("Time : %s", ctime(&t));
338 printf("Number of records: %u\n",
339 le32_to_cpu(llog_buf->llh_count)-1);
341 printf("Target uuid : %s \n",
342 (char *)(&llog_buf->llh_tgtuuid));
344 /* Add the other info you want to view here */
346 printf("-----------------------\n");
350 static void print_1_cfg(struct lustre_cfg *lcfg)
355 printf("nid=%s("LPX64") ", libcfs_nid2str(lcfg->lcfg_nid),
358 printf("nal=%d ", lcfg->lcfg_nal);
359 for (i = 0; i < lcfg->lcfg_bufcount; i++)
360 printf("%d:%.*s ", i, lcfg->lcfg_buflens[i],
361 (char*)lustre_cfg_buf(lcfg, i));
366 static void print_setup_cfg(struct lustre_cfg *lcfg)
368 struct lov_desc *desc;
370 if ((lcfg->lcfg_bufcount == 2) &&
371 (lcfg->lcfg_buflens[1] == sizeof(*desc))) {
372 printf("lov_setup ");
373 printf("0:%s ", lustre_cfg_string(lcfg, 0));
374 printf("1:(struct lov_desc)\n");
375 desc = (struct lov_desc*)(lustre_cfg_string(lcfg, 1));
376 printf("\t\tuuid=%s ", (char*)desc->ld_uuid.uuid);
377 printf("stripe:cnt=%u ", desc->ld_default_stripe_count);
378 printf("size="LPU64" ", desc->ld_default_stripe_size);
379 printf("offset="LPU64" ", desc->ld_default_stripe_offset);
380 printf("pattern=%#x", desc->ld_pattern);
389 void print_lustre_cfg(struct lustre_cfg *lcfg, int *skip)
391 enum lcfg_command_type cmd = le32_to_cpu(lcfg->lcfg_command);
403 print_setup_cfg(lcfg);
416 case(LCFG_ADD_UUID):{
421 case(LCFG_DEL_UUID):{
426 case(LCFG_ADD_CONN):{
431 case(LCFG_DEL_CONN):{
436 case(LCFG_LOV_ADD_OBD):{
437 printf("lov_modify_tgts add ");
441 case(LCFG_LOV_DEL_OBD):{
442 printf("lov_modify_tgts del ");
447 printf("modify_mdc_tgts add ");
452 printf("modify_mdc_tgts del ");
456 case(LCFG_MOUNTOPT):{
457 printf("mount_option ");
461 case(LCFG_DEL_MOUNTOPT):{
462 printf("del_mount_option ");
466 case(LCFG_SET_TIMEOUT):{
467 printf("set_timeout=%d ", lcfg->lcfg_num);
470 case(LCFG_SET_LDLM_TIMEOUT):{
471 printf("set_ldlm_timeout=%d ", lcfg->lcfg_num);
474 case(LCFG_SET_UPCALL):{
475 printf("set_lustre_upcall ");
484 case(LCFG_SET_PARAM):{
485 printf("set_param ");
489 case(LCFG_SPTLRPC_CONF):{
490 printf("sptlrpc_conf ");
495 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
496 char createtime[26], canceltime[26] = "";
499 if (marker->cm_flags & CM_START &&
500 marker->cm_flags & CM_SKIP) {
501 printf("SKIP START ");
503 } else if (marker->cm_flags & CM_END) {
508 if (marker->cm_flags & CM_EXCLUDE) {
509 if (marker->cm_flags & CM_START)
510 printf("EXCLUDE START ");
512 printf("EXCLUDE END ");
515 /* Handle overflow of 32-bit time_t gracefully.
516 * The copy to time_tmp is needed in any case to
517 * keep the pointer happy, even on 64-bit systems. */
518 time_tmp = marker->cm_createtime;
519 if (time_tmp == marker->cm_createtime) {
520 ctime_r(&time_tmp, createtime);
521 createtime[strlen(createtime) - 1] = 0;
523 strcpy(createtime, "in the distant future");
526 if (marker->cm_canceltime) {
527 /* Like cm_createtime, we try to handle overflow of
528 * 32-bit time_t gracefully. The copy to time_tmp
529 * is also needed on 64-bit systems to keep the
530 * pointer happy, see bug 16771 */
531 time_tmp = marker->cm_canceltime;
532 if (time_tmp == marker->cm_canceltime) {
533 ctime_r(&time_tmp, canceltime);
534 canceltime[strlen(canceltime) - 1] = 0;
536 strcpy(canceltime, "in the distant future");
540 printf("marker %3d (flags=%#04x, v%d.%d.%d.%d) %-15s '%s' %s-%s",
541 marker->cm_step, marker->cm_flags,
542 OBD_OCD_VERSION_MAJOR(marker->cm_vers),
543 OBD_OCD_VERSION_MINOR(marker->cm_vers),
544 OBD_OCD_VERSION_PATCH(marker->cm_vers),
545 OBD_OCD_VERSION_FIX(marker->cm_vers),
546 marker->cm_tgtname, marker->cm_comment,
547 createtime, canceltime);
550 case(LCFG_POOL_NEW):{
555 case(LCFG_POOL_ADD):{
560 case(LCFG_POOL_REM):{
561 printf("pool remove ");
565 case(LCFG_POOL_DEL):{
566 printf("pool destroy ");
571 printf("unsupported cmd_code = %x\n",cmd);
577 static void print_hsm_action(struct llog_agent_req_rec *larr)
582 sz = larr->arr_hai.hai_len - sizeof(larr->arr_hai);
583 printf("lrh=[type=%X len=%d idx=%d] fid="DFID
584 " compound/cookie="LPX64"/"LPX64
585 " status=%s action=%s archive#=%d flags="LPX64
586 " create="LPU64" change="LPU64
587 " extent="LPX64"-"LPX64" gid="LPX64" datalen=%d"
589 larr->arr_hdr.lrh_type,
590 larr->arr_hdr.lrh_len, larr->arr_hdr.lrh_index,
591 PFID(&larr->arr_hai.hai_fid),
592 larr->arr_compound_id, larr->arr_hai.hai_cookie,
593 agent_req_status2name(larr->arr_status),
594 hsm_copytool_action2name(larr->arr_hai.hai_action),
595 larr->arr_archive_id,
597 larr->arr_req_create, larr->arr_req_change,
598 larr->arr_hai.hai_extent.offset,
599 larr->arr_hai.hai_extent.length,
600 larr->arr_hai.hai_gid, sz,
601 hai_dump_data_field(&larr->arr_hai, buf, sizeof(buf)));
604 void print_changelog_rec(struct llog_changelog_rec *rec)
606 printf("changelog record id:0x%x cr_flags:0x%x cr_type:%s(0x%x)\n",
607 le32_to_cpu(rec->cr_hdr.lrh_id),
608 le32_to_cpu(rec->cr.cr_flags),
609 changelog_type2str(le32_to_cpu(rec->cr.cr_type)),
610 le32_to_cpu(rec->cr.cr_type));
613 static void print_records(struct llog_rec_hdr **recs,
614 int rec_number, int is_ext)
619 for (i = 0; i < rec_number; i++) {
620 printf("#%.2d (%.3d)", le32_to_cpu(recs[i]->lrh_index),
621 le32_to_cpu(recs[i]->lrh_len));
623 lopt = le32_to_cpu(recs[i]->lrh_type);
625 if (recs[i]->lrh_id == CANCELLED)
631 (struct lustre_cfg *)((char *)(recs[i]) +
632 sizeof(struct llog_rec_hdr)), &skip);
637 case LLOG_LOGID_MAGIC:
638 print_log_path((struct llog_logid_rec *)recs[i],
642 print_hsm_action((struct llog_agent_req_rec *)recs[i]);
645 print_changelog_rec((struct llog_changelog_rec *)
648 case CHANGELOG_USER_REC:
649 printf("changelog_user record id:0x%x\n",
650 le32_to_cpu(recs[i]->lrh_id));
653 printf("unknown type %x\n", lopt);
659 /** @} llog_reader */