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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
31 /** \defgroup llog_reader Lustre Log Reader
33 * Interpret llogs used for storing configuration and changelog data
44 #include <sys/types.h>
46 #include <sys/param.h>
53 #include <linux/magic.h>
56 #include <linux/lnet/nidstr.h>
57 #include <linux/lustre/lustre_cfg.h>
58 #include <linux/lustre/lustre_fid.h>
59 #include <linux/lustre/lustre_ostid.h>
60 #include <linux/lustre/lustre_log_user.h>
61 #include <lustre/lustreapi.h>
63 static inline int ext2_test_bit(int nr, const void *addr)
65 #if __BYTE_ORDER == __BIG_ENDIAN
66 const unsigned char *tmp = addr;
68 return (tmp[nr >> 3] >> (nr & 7)) & 1;
70 const unsigned long *tmp = addr;
72 return ((1UL << (nr & (__WORDSIZE - 1))) &
73 ((tmp)[nr / __WORDSIZE])) != 0;
77 int llog_pack_buffer(int fd, struct llog_log_hdr **llog_buf,
78 struct llog_rec_hdr ***recs, int *recs_number);
80 void print_llog_header(struct llog_log_hdr *llog_buf);
81 static void print_records(struct llog_rec_hdr **recs_buf,
82 int rec_number, int is_ext);
83 void llog_unpack_buffer(int fd, struct llog_log_hdr *llog_buf,
84 struct llog_rec_hdr **recs_buf);
86 #define CANCELLED 0x678
88 #define PTL_CMD_BASE 100
89 char *portals_command[17] = {
109 int is_fstype_ext(int fd)
114 rc = fstatfs(fd, &st);
116 llapi_error(LLAPI_MSG_ERROR, rc, "Got statfs error.");
120 return (st.f_type == EXT4_SUPER_MAGIC);
124 * Attempt to display a path to the object (file) containing changelog entries,
125 * referred to by this changelog_catalog record.
127 * This path depends on the implementation of the OSD device; zfs-osd and
128 * ldiskfs-osd are different.
130 * Assumes that if the file system containing the changelog_catalog is
131 * ext{2,3,4}, the backend is ldiskfs-osd; otherwise it is either zfs-osd or at
132 * least names objects based on FID and the zfs-osd path (which includes the
133 * FID) will be sufficient.
135 * The Object ID stored in the record is also displayed untranslated.
137 #define OSD_OI_FID_NR (1UL << 7)
138 static void print_log_path(struct llog_logid_rec *lid, int is_ext)
140 char object_path[255];
141 struct lu_fid fid_from_logid;
143 logid_to_fid(&lid->lid_id, &fid_from_logid);
146 * Llogs with regular llog SEQ such as FID_SEQ_LLOG and
147 * FID_SEQ_LLOG_NAME are stored under O/ directory but
148 * update llogs are using normal FIDs and stored under
149 * 'update_log_dir' directory with FID format name
150 * Distinguish them by FID sequence
152 if (fid_from_logid.f_seq != FID_SEQ_LLOG &&
153 fid_from_logid.f_seq != FID_SEQ_LLOG_NAME)
154 snprintf(object_path, sizeof(object_path),
155 "update_log_dir/"DFID, PFID(&fid_from_logid));
157 snprintf(object_path, sizeof(object_path),
158 "O/%ju/d%u/%u", (uintmax_t)fid_from_logid.f_seq,
159 fid_from_logid.f_oid % 32,
160 fid_from_logid.f_oid);
162 snprintf(object_path, sizeof(object_path),
163 "oi.%ju/"DFID_NOBRACE,
164 (uintmax_t)(fid_from_logid.f_seq &
165 (OSD_OI_FID_NR - 1)),
166 PFID(&fid_from_logid));
168 printf("fid="DFID" path=%s\n", PFID(&fid_from_logid),
172 int main(int argc, char **argv)
177 struct llog_log_hdr *llog_buf = NULL;
178 struct llog_rec_hdr **recs_buf = NULL;
183 printf("Usage: llog_reader filename\n");
187 fd = open(argv[1], O_RDONLY);
190 llapi_error(LLAPI_MSG_ERROR, rc, "Could not open the file %s.",
195 is_ext = is_fstype_ext(fd);
198 llapi_error(LLAPI_MSG_ERROR, -rc,
199 "Unable to determine filesystem type for %s",
204 rc = llog_pack_buffer(fd, &llog_buf, &recs_buf, &rec_number);
206 llapi_error(LLAPI_MSG_ERROR, rc, "Could not pack buffer.");
211 print_llog_header(llog_buf);
213 print_records(recs_buf, rec_number, is_ext);
214 llog_unpack_buffer(fd, llog_buf, recs_buf);
222 int llog_pack_buffer(int fd, struct llog_log_hdr **llog,
223 struct llog_rec_hdr ***recs,
226 int rc = 0, recs_num, rd = 0;
229 char *file_buf = NULL, *recs_buf = NULL;
230 struct llog_rec_hdr **recs_pr = NULL;
232 int count, errors = 0;
241 llapi_error(LLAPI_MSG_ERROR, rc, "Got file stat error.");
245 file_size = st.st_size;
246 if (file_size < sizeof(**llog)) {
247 llapi_error(LLAPI_MSG_ERROR, rc,
248 "File too small for llog header: want=%zd got=%lld",
249 sizeof(**llog), file_size);
254 file_buf = malloc(file_size);
257 llapi_error(LLAPI_MSG_ERROR, rc, "Memory Alloc for file_buf.");
260 *llog = (struct llog_log_hdr *)file_buf;
263 rc = read(fd, file_buf + rd, file_size - rd);
266 } while (rc > 0 && rd < file_size);
268 if (rd < file_size) {
269 rc = rc < 0 ? -errno : -EIO;
270 llapi_error(LLAPI_MSG_ERROR, rc,
271 "Error reading llog header: need %zd, got %d",
276 count = __le32_to_cpu((*llog)->llh_count);
279 llapi_error(LLAPI_MSG_ERROR, rc,
280 "corrupted llog: negative record number %d",
283 } else if (count == 0) {
284 llapi_printf(LLAPI_MSG_NORMAL,
285 "uninitialized llog: zero record number\n");
289 /* the llog header not countable here.*/
290 recs_num = count - 1;
294 recs_buf = calloc(recs_num, sizeof(**recs_pr));
297 llapi_error(LLAPI_MSG_ERROR, rc,
298 "Error allocating %zd bytes for recs_buf",
299 recs_num * sizeof(**recs_pr));
302 recs_pr = (struct llog_rec_hdr **)recs_buf;
304 ptr = file_buf + __le32_to_cpu((*llog)->llh_hdr.lrh_len);
308 while (ptr < (file_buf + file_size)) {
309 struct llog_rec_hdr *cur_rec;
311 unsigned long offset;
313 offset = (unsigned long)ptr - (unsigned long)file_buf;
314 if (offset + sizeof(**recs_pr) > file_size) {
315 printf("error: rec header is trimmed by EOF, last idx #%d offset %lu\n",
320 cur_rec = (struct llog_rec_hdr *)ptr;
321 idx = __le32_to_cpu(cur_rec->lrh_index);
322 if (cur_rec->lrh_len == 0 ||
323 cur_rec->lrh_len > (*llog)->llh_hdr.lrh_len) {
324 cur_rec->lrh_len = (*llog)->llh_hdr.lrh_len -
325 offset % (*llog)->llh_hdr.lrh_len;
326 printf("off %lu skip %u to next chunk.\n", offset,
328 } else if (ext2_test_bit(idx, LLOG_HDR_BITMAP(*llog))) {
329 printf("rec #%d type=%x len=%u offset %lu\n", idx,
330 cur_rec->lrh_type, cur_rec->lrh_len, offset);
331 recs_pr[i] = cur_rec;
334 cur_rec->lrh_id = CANCELLED;
335 if (cur_rec->lrh_type == LLOG_PAD_MAGIC &&
336 ((offset + cur_rec->lrh_len) & 0x7) != 0) {
337 printf("error: rec #%d wrong padding len=%u offset %lu to 0x%lx\n",
338 idx, cur_rec->lrh_len, offset,
339 offset + cur_rec->lrh_len);
342 /* The header counts only set records */
345 while (++last_idx < idx) {
346 printf("error: rec #%d is missing%s set in bitmap\n",
348 ext2_test_bit(last_idx, LLOG_HDR_BITMAP(*llog)) ?
352 /* index may decrease only when crosses index zero in catalog */
353 if (last_idx > idx && idx != 1) {
354 printf("error: rec #%d index is less than last #%d\n",
360 ptr += __le32_to_cpu(cur_rec->lrh_len);
361 if ((ptr - file_buf) > file_size) {
362 printf("error: rec #%d is trimmed by EOF, offset %lu\n",
369 while (++last_idx < LLOG_HDR_BITMAP_SIZE((*llog))) {
370 if (ext2_test_bit(last_idx, LLOG_HDR_BITMAP(*llog))) {
371 printf("error: rec #%d is set in bitmap only\n",
377 printf("error: header reports %d records but %d were found\n",
380 /* don't set rc to output what was found */
382 llapi_error(LLAPI_MSG_NO_ERRNO, 0,
383 "The llog is corrupted, %d errors found", errors);
386 /* don't try to output more recs than was found or allocated */
387 *recs_number = i > recs_num ? recs_num : i;
398 void llog_unpack_buffer(int fd, struct llog_log_hdr *llog_buf,
399 struct llog_rec_hdr **recs_buf)
407 void print_llog_header(struct llog_log_hdr *llog_buf)
410 unsigned int lrh_len = __le32_to_cpu(llog_buf->llh_hdr.lrh_len);
411 struct llog_rec_tail *tail = ((struct llog_rec_tail *)((char *)llog_buf+
412 lrh_len - sizeof(llog_buf->llh_tail)));
414 printf("Header size : %u\t llh_size : %u\n", lrh_len,
415 __le32_to_cpu(llog_buf->llh_size));
417 t = __le64_to_cpu(llog_buf->llh_timestamp);
418 printf("Time : %s", ctime(&t));
420 printf("Number of records: %u\tcat_idx: %u\tlast_idx: %u\n",
421 __le32_to_cpu(llog_buf->llh_count)-1,
422 __le32_to_cpu(llog_buf->llh_cat_idx),
423 __le32_to_cpu(tail->lrt_index));
424 printf("Flags: %#x\n", __le32_to_cpu(llog_buf->llh_flags));
425 printf("Target uuid : %s\n",
426 (char *)(&llog_buf->llh_tgtuuid));
428 /* Add the other info you want to view here */
430 printf("-----------------------\n");
433 static void print_1_cfg(struct lustre_cfg *lcfg)
438 printf("nid=%s(%#jx) ", libcfs_nid2str(lcfg->lcfg_nid),
439 (uintmax_t)lcfg->lcfg_nid);
441 printf("nal=%d ", lcfg->lcfg_nal);
442 for (i = 0; i < lcfg->lcfg_bufcount; i++)
443 printf("%d:%.*s ", i, lcfg->lcfg_buflens[i],
444 (char *)lustre_cfg_buf(lcfg, i));
447 static char *lustre_cfg_string(struct lustre_cfg *lcfg, __u32 index)
451 if (lcfg->lcfg_buflens[index] == 0)
454 s = lustre_cfg_buf(lcfg, index);
459 * make sure it's NULL terminated, even if this kills a char
460 * of data. Try to use the padding first though.
462 if (s[lcfg->lcfg_buflens[index] - 1] != '\0') {
463 size_t last = __ALIGN_KERNEL(lcfg->lcfg_buflens[index], 8) - 1;
466 /* Use the smaller value */
467 if (last > lcfg->lcfg_buflens[index])
468 last = lcfg->lcfg_buflens[index];
474 "Truncated buf %d to '%s' (lost '%c'...)\n",
481 static void print_setup_cfg(struct lustre_cfg *lcfg)
483 struct lov_desc *desc;
485 if ((lcfg->lcfg_bufcount == 2) &&
486 (lcfg->lcfg_buflens[1] == sizeof(*desc))) {
487 printf("lov_setup ");
488 printf("0:%s ", lustre_cfg_string(lcfg, 0));
489 printf("1:(struct lov_desc)\n");
490 desc = (struct lov_desc *)(lustre_cfg_string(lcfg, 1));
491 printf("\t\tuuid=%s ", (char *)desc->ld_uuid.uuid);
492 printf("stripe:cnt=%u ", desc->ld_default_stripe_count);
493 printf("size=%ju ", (uintmax_t)desc->ld_default_stripe_size);
494 printf("offset=%ju ",
495 (uintmax_t)desc->ld_default_stripe_offset);
496 printf("pattern=%#x", desc->ld_pattern);
503 void print_lustre_cfg(struct lustre_cfg *lcfg, int *skip)
505 enum lcfg_command_type cmd = __le32_to_cpu(lcfg->lcfg_command);
517 print_setup_cfg(lcfg);
530 case(LCFG_ADD_UUID):{
535 case(LCFG_DEL_UUID):{
540 case(LCFG_ADD_CONN):{
545 case(LCFG_DEL_CONN):{
550 case(LCFG_LOV_ADD_OBD):{
551 printf("lov_modify_tgts add ");
555 case(LCFG_LOV_DEL_OBD):{
556 printf("lov_modify_tgts del ");
561 printf("modify_mdc_tgts add ");
566 printf("modify_mdc_tgts del ");
570 case(LCFG_MOUNTOPT):{
571 printf("mount_option ");
575 case(LCFG_DEL_MOUNTOPT):{
576 printf("del_mount_option ");
580 case(LCFG_SET_TIMEOUT):{
581 printf("set_timeout=%d ", lcfg->lcfg_num);
584 case(LCFG_SET_LDLM_TIMEOUT):{
585 printf("set_ldlm_timeout=%d ", lcfg->lcfg_num);
588 case(LCFG_SET_UPCALL):{
589 printf("set_lustre_upcall ");
598 case(LCFG_SET_PARAM):{
599 printf("set_param ");
603 case(LCFG_SPTLRPC_CONF):{
604 printf("sptlrpc_conf ");
609 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
610 char createtime[26], canceltime[26] = "";
613 if (marker->cm_flags & CM_START &&
614 marker->cm_flags & CM_SKIP) {
615 printf("SKIP START ");
617 } else if (marker->cm_flags & CM_END) {
622 if (marker->cm_flags & CM_EXCLUDE) {
623 if (marker->cm_flags & CM_START)
624 printf("EXCLUDE START ");
626 printf("EXCLUDE END ");
630 * Handle overflow of 32-bit time_t gracefully.
631 * The copy to time_tmp is needed in any case to
632 * keep the pointer happy, even on 64-bit systems.
634 time_tmp = marker->cm_createtime;
635 if (time_tmp == marker->cm_createtime) {
636 ctime_r(&time_tmp, createtime);
637 createtime[strlen(createtime) - 1] = 0;
639 strcpy(createtime, "in the distant future");
642 if (marker->cm_canceltime) {
644 * Like cm_createtime, we try to handle overflow of
645 * 32-bit time_t gracefully. The copy to time_tmp
646 * is also needed on 64-bit systems to keep the
647 * pointer happy, see bug 16771
649 time_tmp = marker->cm_canceltime;
650 if (time_tmp == marker->cm_canceltime) {
651 ctime_r(&time_tmp, canceltime);
652 canceltime[strlen(canceltime) - 1] = 0;
654 strcpy(canceltime, "in the distant future");
658 printf("marker %3d (flags=%#04x, v%d.%d.%d.%d) %-15s '%s' %s-%s",
659 marker->cm_step, marker->cm_flags,
660 OBD_OCD_VERSION_MAJOR(marker->cm_vers),
661 OBD_OCD_VERSION_MINOR(marker->cm_vers),
662 OBD_OCD_VERSION_PATCH(marker->cm_vers),
663 OBD_OCD_VERSION_FIX(marker->cm_vers),
664 marker->cm_tgtname, marker->cm_comment,
665 createtime, canceltime);
668 case(LCFG_POOL_NEW):{
673 case(LCFG_POOL_ADD):{
678 case(LCFG_POOL_REM):{
679 printf("pool remove ");
683 case(LCFG_POOL_DEL):{
684 printf("pool destroy ");
689 printf("unsupported cmd_code = %x\n", cmd);
694 static void print_hsm_action(struct llog_agent_req_rec *larr)
699 sz = larr->arr_hai.hai_len - sizeof(larr->arr_hai);
700 printf("lrh=[type=%X len=%d idx=%d] fid="DFID" compound/cookie=%#llx/%#llx status=%s action=%s archive#=%d flags=%#llx create=%llu change=%llu extent=%#llx-%#llx gid=%#llx datalen=%d data=[%s]\n",
701 larr->arr_hdr.lrh_type,
702 larr->arr_hdr.lrh_len, larr->arr_hdr.lrh_index,
703 PFID(&larr->arr_hai.hai_fid),
704 (unsigned long long)larr->arr_compound_id,
705 (unsigned long long)larr->arr_hai.hai_cookie,
706 agent_req_status2name(larr->arr_status),
707 hsm_copytool_action2name(larr->arr_hai.hai_action),
708 larr->arr_archive_id,
709 (unsigned long long)larr->arr_flags,
710 (unsigned long long)larr->arr_req_create,
711 (unsigned long long)larr->arr_req_change,
712 (unsigned long long)larr->arr_hai.hai_extent.offset,
713 (unsigned long long)larr->arr_hai.hai_extent.length,
714 (unsigned long long)larr->arr_hai.hai_gid, sz,
715 hai_dump_data_field(&larr->arr_hai, buf, sizeof(buf)));
718 void print_changelog_rec(struct llog_changelog_rec *rec)
723 secs = __le64_to_cpu(rec->cr.cr_time) >> 30;
724 gmtime_r(&secs, &ts);
725 printf("changelog record id:0x%x index:%llu cr_flags:0x%x cr_type:%s(0x%x) date:'%02d:%02d:%02d.%09d %04d.%02d.%02d' target:"DFID,
726 __le32_to_cpu(rec->cr_hdr.lrh_id),
727 (unsigned long long)__le64_to_cpu(rec->cr.cr_index),
728 __le32_to_cpu(rec->cr.cr_flags),
729 changelog_type2str(__le32_to_cpu(rec->cr.cr_type)),
730 __le32_to_cpu(rec->cr.cr_type),
731 ts.tm_hour, ts.tm_min, ts.tm_sec,
732 (int)(__le64_to_cpu(rec->cr.cr_time) & ((1 << 30) - 1)),
733 ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday,
734 PFID(&rec->cr.cr_tfid));
736 if (rec->cr.cr_flags & CLF_JOBID) {
737 struct changelog_ext_jobid *jid =
738 changelog_rec_jobid(&rec->cr);
740 if (jid->cr_jobid[0] != '\0')
741 printf(" jobid:%s", jid->cr_jobid);
744 if (rec->cr.cr_flags & CLF_EXTRA_FLAGS) {
745 struct changelog_ext_extra_flags *ef =
746 changelog_rec_extra_flags(&rec->cr);
748 printf(" cr_extra_flags:0x%llx",
749 (unsigned long long)__le64_to_cpu(ef->cr_extra_flags));
751 if (ef->cr_extra_flags & CLFE_UIDGID) {
752 struct changelog_ext_uidgid *uidgid =
753 changelog_rec_uidgid(&rec->cr);
755 printf(" user:%u:%u",
756 __le32_to_cpu(uidgid->cr_uid),
757 __le32_to_cpu(uidgid->cr_gid));
759 if (ef->cr_extra_flags & CLFE_NID) {
760 struct changelog_ext_nid *nid =
761 changelog_rec_nid(&rec->cr);
764 libcfs_nid2str(nid->cr_nid));
767 if (ef->cr_extra_flags & CLFE_OPEN) {
768 struct changelog_ext_openmode *omd =
769 changelog_rec_openmode(&rec->cr);
772 /* exec mode must be exclusive */
773 if (__le32_to_cpu(omd->cr_openflags) & MDS_FMODE_EXEC) {
776 if (__le32_to_cpu(omd->cr_openflags) &
779 if (__le32_to_cpu(omd->cr_openflags) &
780 (MDS_FMODE_WRITE | MDS_OPEN_TRUNC | MDS_OPEN_APPEND))
784 if (strcmp(mode, "---") != 0)
785 printf(" mode:%s", mode);
788 if (ef->cr_extra_flags & CLFE_XATTR) {
789 struct changelog_ext_xattr *xattr =
790 changelog_rec_xattr(&rec->cr);
792 if (xattr->cr_xattr[0] != '\0')
793 printf(" xattr:%s", xattr->cr_xattr);
797 if (rec->cr.cr_namelen)
798 printf(" parent:"DFID" name:%.*s", PFID(&rec->cr.cr_pfid),
799 __le32_to_cpu(rec->cr.cr_namelen),
800 changelog_rec_name(&rec->cr));
802 if (rec->cr.cr_flags & CLF_RENAME) {
803 struct changelog_ext_rename *rnm =
804 changelog_rec_rename(&rec->cr);
806 if (!fid_is_zero(&rnm->cr_sfid))
807 printf(" source_fid:"DFID" source_parent_fid:"DFID
810 PFID(&rnm->cr_spfid),
812 changelog_rec_snamelen(&rec->cr)),
813 changelog_rec_sname(&rec->cr));
818 static void lustre_swab_lu_fid(struct lu_fid *fid)
820 fid->f_seq = __swab64(fid->f_seq);
821 fid->f_oid = __swab32(fid->f_oid);
822 fid->f_ver = __swab32(fid->f_ver);
826 update_op_size(unsigned int param_count)
828 return offsetof(struct update_op, uop_params_off[param_count]);
832 static inline struct update_op *
833 update_op_next_op(const struct update_op *uop)
835 return (struct update_op *)((char *)uop +
836 update_op_size(uop->uop_param_count));
839 static void lustre_swab_update_ops(struct update_ops *uops,
840 unsigned int op_count)
845 struct update_op *op =
846 (struct update_op *)((char *)&uops->uops_op[0]);
848 for (i = 0; i < op_count; i++, op = update_op_next_op(op)) {
849 lustre_swab_lu_fid(&op->uop_fid);
850 op->uop_type = __swab16(op->uop_type);
851 op->uop_param_count = __swab16(op->uop_param_count);
852 for (j = 0; j < op->uop_param_count; j++)
853 op->uop_params_off[j] = __swab16(op->uop_params_off[j]);
856 static const char *update_op_str(__u16 opc)
858 static const char *opc_str[] = {
859 [OUT_START] = "start",
860 [OUT_CREATE] = "create",
861 [OUT_DESTROY] = "destroy",
862 [OUT_REF_ADD] = "ref_add",
863 [OUT_REF_DEL] = "ref_del",
864 [OUT_ATTR_SET] = "attr_set",
865 [OUT_ATTR_GET] = "attr_get",
866 [OUT_XATTR_SET] = "xattr_set",
867 [OUT_XATTR_GET] = "xattr_get",
868 [OUT_XATTR_LIST] = "xattr_list",
869 [OUT_INDEX_LOOKUP] = "lookup",
870 [OUT_INDEX_INSERT] = "insert",
871 [OUT_INDEX_DELETE] = "delete",
872 [OUT_WRITE] = "write",
873 [OUT_XATTR_DEL] = "xattr_del",
874 [OUT_PUNCH] = "punch",
879 if (opc < (sizeof(opc_str) / sizeof((opc_str)[0])) &&
880 opc_str[opc] != NULL)
886 char *buf2str(void *buf, unsigned int size)
888 const char *hex = "0123456789ABCDEF";
890 static char string[128];
892 bool format_hex = false;
894 if (size > 0 && buf_c[size - 1] == 0)
896 for (i = 0; i < size; i++) {
897 if (buf_c[i] >= 0x20 && buf_c[i] <= 0x7E) {
898 string[j++] = buf_c[i];
900 } else if (j < sizeof(string) - 6) {
906 string[j++] = hex[(buf_c[i] >> 4) & 0xF];
907 string[j++] = hex[buf_c[i] & 0xF];
911 if (j == sizeof(string) - 2)
919 object_update_param_size(const struct object_update_param *param)
921 return roundup(sizeof(*param) + param->oup_len, sizeof(__u64));
924 void print_update_rec(struct llog_update_record *lur)
926 struct update_records *rec = &lur->lur_update_rec;
927 unsigned int i, j, up_count, pm_count;
928 struct update_op *op;
929 struct object_update_param *pm;
931 up_count = __le32_to_cpu(rec->ur_update_count);
932 pm_count = __le32_to_cpu(rec->ur_param_count);
933 printf("updatelog record master_transno:%llu batchid:%llu flags:0x%x u_index:%d u_count:%d p_count:%d\n",
934 (unsigned long long)__le64_to_cpu(rec->ur_master_transno),
935 (unsigned long long)__le64_to_cpu(rec->ur_batchid),
936 __le32_to_cpu(rec->ur_flags),
937 __le32_to_cpu(rec->ur_index),
941 op = (struct update_op *)((char *)&rec->ur_ops.uops_op[0] + 0);
942 if (op->uop_type != __le16_to_cpu(op->uop_type))
943 lustre_swab_update_ops(&rec->ur_ops, up_count);
945 for (i = 0; i < up_count; i++, op = update_op_next_op(op)) {
946 printf("\t"DFID" type:%s/%d params:%d ",
947 PFID(&op->uop_fid), update_op_str(op->uop_type),
948 op->uop_type, op->uop_param_count);
949 for (j = 0; j < op->uop_param_count; j++)
950 printf("p_%d:%d ", j, op->uop_params_off[j]);
953 pm = (struct object_update_param *) op;
954 for (i = 0; i < pm_count; i++) {
955 printf("\tp_%d - %d/%s\n", i, pm->oup_len,
956 buf2str(pm->oup_buf, pm->oup_len));
957 pm = (struct object_update_param *)((char *)pm +
958 object_update_param_size(pm));
964 static void print_unlink_rec(struct llog_unlink_rec *lur)
966 printf("unlink record id:0x%x target %llx:%x:%x\n",
967 __le32_to_cpu(lur->lur_hdr.lrh_id),
968 (unsigned long long)__le64_to_cpu(lur->lur_oid),
969 __le32_to_cpu(lur->lur_oseq),
970 __le32_to_cpu(lur->lur_count));
973 static void print_unlink64_rec(struct llog_unlink64_rec *lur)
975 printf("unlink64 record id:0x%x target "DFID"\n",
976 __le32_to_cpu(lur->lur_hdr.lrh_id),
977 PFID(&lur->lur_fid));
980 static void print_setattr64_rec(struct llog_setattr64_rec *lsr)
982 printf("setattr64 record id:0x%x target "DFID" valid %llx uid %u:%u gid %u:%u\n",
983 __le32_to_cpu(lsr->lsr_hdr.lrh_id),
984 PFID(&lsr->lsr_oi.oi_fid),
985 (unsigned long long)__le64_to_cpu(lsr->lsr_valid),
986 __le32_to_cpu(lsr->lsr_uid_h),
987 __le32_to_cpu(lsr->lsr_uid),
988 __le32_to_cpu(lsr->lsr_gid_h),
989 __le32_to_cpu(lsr->lsr_gid));
992 static void print_setattr64_rec_v2(struct llog_setattr64_rec_v2 *lsr)
994 printf("setattr64 v2 record id:0x%x target "DFID" valid %llx uid %u:%u gid %u:%u prj %u\n",
995 __le32_to_cpu(lsr->lsr_hdr.lrh_id),
996 PFID(&lsr->lsr_oi.oi_fid),
997 (unsigned long long)__le64_to_cpu(lsr->lsr_valid),
998 __le32_to_cpu(lsr->lsr_uid_h),
999 __le32_to_cpu(lsr->lsr_uid),
1000 __le32_to_cpu(lsr->lsr_gid_h),
1001 __le32_to_cpu(lsr->lsr_gid),
1002 __le32_to_cpu(lsr->lsr_projid));
1006 static void print_records(struct llog_rec_hdr **recs,
1007 int rec_number, int is_ext)
1012 for (i = 0; i < rec_number; i++) {
1014 llapi_printf(LLAPI_MSG_NORMAL,
1015 "uninitialized llog record at index %d\n",
1019 printf("#%.2d (%.3d)", __le32_to_cpu(recs[i]->lrh_index),
1020 __le32_to_cpu(recs[i]->lrh_len));
1022 lopt = __le32_to_cpu(recs[i]->lrh_type);
1024 if (recs[i]->lrh_id == CANCELLED)
1030 (struct lustre_cfg *)((char *)(recs[i]) +
1031 sizeof(struct llog_rec_hdr)), &skip);
1033 case LLOG_PAD_MAGIC:
1034 printf("padding\n");
1036 case LLOG_LOGID_MAGIC:
1037 print_log_path((struct llog_logid_rec *)recs[i],
1041 print_hsm_action((struct llog_agent_req_rec *)recs[i]);
1044 print_changelog_rec((struct llog_changelog_rec *)
1047 case CHANGELOG_USER_REC:
1048 case CHANGELOG_USER_REC2:
1049 printf("changelog_user record id:0x%x\n",
1050 __le32_to_cpu(recs[i]->lrh_id));
1053 print_update_rec((struct llog_update_record *)recs[i]);
1055 case MDS_UNLINK_REC:
1056 print_unlink_rec((struct llog_unlink_rec *)recs[i]);
1058 case MDS_UNLINK64_REC:
1059 print_unlink64_rec((struct llog_unlink64_rec *)recs[i]);
1061 case MDS_SETATTR64_REC:
1062 if (__le32_to_cpu(recs[i]->lrh_len) >
1063 sizeof(struct llog_setattr64_rec)) {
1064 print_setattr64_rec_v2(
1065 (struct llog_setattr64_rec_v2 *)recs[i]);
1067 print_setattr64_rec(
1068 (struct llog_setattr64_rec *)recs[i]);
1072 printf("unknown type %x\n", lopt);
1078 /** @} llog_reader */