+
+void print_changelog_rec(struct llog_changelog_rec *rec)
+{
+ time_t secs;
+ struct tm ts;
+
+ secs = __le64_to_cpu(rec->cr.cr_time) >> 30;
+ gmtime_r(&secs, &ts);
+ 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,
+ __le32_to_cpu(rec->cr_hdr.lrh_id),
+ (unsigned long long)__le64_to_cpu(rec->cr.cr_index),
+ __le32_to_cpu(rec->cr.cr_flags),
+ changelog_type2str(__le32_to_cpu(rec->cr.cr_type)),
+ __le32_to_cpu(rec->cr.cr_type),
+ ts.tm_hour, ts.tm_min, ts.tm_sec,
+ (int)(__le64_to_cpu(rec->cr.cr_time) & ((1 << 30) - 1)),
+ ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday,
+ PFID(&rec->cr.cr_tfid));
+
+ if (rec->cr.cr_flags & CLF_JOBID) {
+ struct changelog_ext_jobid *jid =
+ changelog_rec_jobid(&rec->cr);
+
+ if (jid->cr_jobid[0] != '\0')
+ printf(" jobid:%s", jid->cr_jobid);
+ }
+
+ if (rec->cr.cr_flags & CLF_EXTRA_FLAGS) {
+ struct changelog_ext_extra_flags *ef =
+ changelog_rec_extra_flags(&rec->cr);
+
+ printf(" cr_extra_flags:0x%llx",
+ (unsigned long long)__le64_to_cpu(ef->cr_extra_flags));
+
+ if (ef->cr_extra_flags & CLFE_UIDGID) {
+ struct changelog_ext_uidgid *uidgid =
+ changelog_rec_uidgid(&rec->cr);
+
+ printf(" user:%u:%u",
+ __le32_to_cpu(uidgid->cr_uid),
+ __le32_to_cpu(uidgid->cr_gid));
+ }
+ if (ef->cr_extra_flags & CLFE_NID) {
+ struct changelog_ext_nid *nid =
+ changelog_rec_nid(&rec->cr);
+
+ printf(" nid:%s",
+ libcfs_nid2str(nid->cr_nid));
+ }
+
+ if (ef->cr_extra_flags & CLFE_OPEN) {
+ struct changelog_ext_openmode *omd =
+ changelog_rec_openmode(&rec->cr);
+ char mode[] = "---";
+
+ /* exec mode must be exclusive */
+ if (__le32_to_cpu(omd->cr_openflags) & MDS_FMODE_EXEC) {
+ mode[2] = 'x';
+ } else {
+ if (__le32_to_cpu(omd->cr_openflags) &
+ MDS_FMODE_READ)
+ mode[0] = 'r';
+ if (__le32_to_cpu(omd->cr_openflags) &
+ (MDS_FMODE_WRITE | MDS_OPEN_TRUNC | MDS_OPEN_APPEND))
+ mode[1] = 'w';
+ }
+
+ if (strcmp(mode, "---") != 0)
+ printf(" mode:%s", mode);
+ }
+
+ if (ef->cr_extra_flags & CLFE_XATTR) {
+ struct changelog_ext_xattr *xattr =
+ changelog_rec_xattr(&rec->cr);
+
+ if (xattr->cr_xattr[0] != '\0')
+ printf(" xattr:%s", xattr->cr_xattr);
+ }
+ }
+
+ if (rec->cr.cr_namelen)
+ printf(" parent:"DFID" name:%.*s", PFID(&rec->cr.cr_pfid),
+ __le32_to_cpu(rec->cr.cr_namelen),
+ changelog_rec_name(&rec->cr));
+
+ if (rec->cr.cr_flags & CLF_RENAME) {
+ struct changelog_ext_rename *rnm =
+ changelog_rec_rename(&rec->cr);
+
+ if (!fid_is_zero(&rnm->cr_sfid))
+ printf(" source_fid:"DFID" source_parent_fid:"DFID
+ " %.*s",
+ PFID(&rnm->cr_sfid),
+ PFID(&rnm->cr_spfid),
+ (int)__le32_to_cpu(
+ changelog_rec_snamelen(&rec->cr)),
+ changelog_rec_sname(&rec->cr));
+ }
+ printf("\n");
+}
+
+static void lustre_swab_lu_fid(struct lu_fid *fid)
+{
+ fid->f_seq = __swab64(fid->f_seq);
+ fid->f_oid = __swab32(fid->f_oid);
+ fid->f_ver = __swab32(fid->f_ver);
+}
+
+static inline size_t
+update_op_size(unsigned int param_count)
+{
+ return offsetof(struct update_op, uop_params_off[param_count]);
+}
+
+
+static inline struct update_op *
+update_op_next_op(const struct update_op *uop)
+{
+ return (struct update_op *)((char *)uop +
+ update_op_size(uop->uop_param_count));
+}
+
+static void lustre_swab_update_ops(struct update_ops *uops,
+ unsigned int op_count)
+{
+ unsigned int i;
+ unsigned int j;
+
+ struct update_op *op =
+ (struct update_op *)((char *)&uops->uops_op[0]);
+
+ for (i = 0; i < op_count; i++, op = update_op_next_op(op)) {
+ lustre_swab_lu_fid(&op->uop_fid);
+ op->uop_type = __swab16(op->uop_type);
+ op->uop_param_count = __swab16(op->uop_param_count);
+ for (j = 0; j < op->uop_param_count; j++)
+ op->uop_params_off[j] = __swab16(op->uop_params_off[j]);
+ }
+}
+static const char *update_op_str(__u16 opc)
+{
+ static const char *opc_str[] = {
+ [OUT_START] = "start",
+ [OUT_CREATE] = "create",
+ [OUT_DESTROY] = "destroy",
+ [OUT_REF_ADD] = "ref_add",
+ [OUT_REF_DEL] = "ref_del",
+ [OUT_ATTR_SET] = "attr_set",
+ [OUT_ATTR_GET] = "attr_get",
+ [OUT_XATTR_SET] = "xattr_set",
+ [OUT_XATTR_GET] = "xattr_get",
+ [OUT_XATTR_LIST] = "xattr_list",
+ [OUT_INDEX_LOOKUP] = "lookup",
+ [OUT_INDEX_INSERT] = "insert",
+ [OUT_INDEX_DELETE] = "delete",
+ [OUT_WRITE] = "write",
+ [OUT_XATTR_DEL] = "xattr_del",
+ [OUT_PUNCH] = "punch",
+ [OUT_READ] = "read",
+ [OUT_NOOP] = "noop",
+ };
+
+ if (opc < (sizeof(opc_str) / sizeof((opc_str)[0])) &&
+ opc_str[opc] != NULL)
+ return opc_str[opc];
+ else
+ return "unknown";
+}
+
+char *buf2str(void *buf, unsigned int size)
+{
+ const char *hex = "0123456789ABCDEF";
+ char *buf_c = buf;
+ static char string[128];
+ int i, j = 0;
+ bool format_hex = false;
+
+ if (size > 0 && buf_c[size - 1] == 0)
+ size--;
+ for (i = 0; i < size; i++) {
+ if (buf_c[i] >= 0x20 && buf_c[i] <= 0x7E) {
+ string[j++] = buf_c[i];
+ format_hex = false;
+ } else if (j < sizeof(string) - 6) {
+ if (!format_hex) {
+ string[j++] = '\\';
+ string[j++] = 'x';
+ format_hex = true;
+ }
+ string[j++] = hex[(buf_c[i] >> 4) & 0xF];
+ string[j++] = hex[buf_c[i] & 0xF];
+ } else {
+ break;
+ }
+ if (j == sizeof(string) - 2)
+ break;
+ }
+ string[j] = 0;
+ return string;
+}
+
+void print_update_rec(struct llog_update_record *lur)
+{
+ struct update_records *rec = &lur->lur_update_rec;
+ unsigned int i, j, up_count, pm_count;
+ struct update_op *op;
+ struct object_update_param *pm;
+
+ up_count = __le32_to_cpu(rec->ur_update_count);
+ pm_count = __le32_to_cpu(rec->ur_param_count);
+ printf("updatelog record master_transno:%llu batchid:%llu flags:0x%x u_index:%d u_count:%d p_count:%d\n",
+ (unsigned long long)__le64_to_cpu(rec->ur_master_transno),
+ (unsigned long long)__le64_to_cpu(rec->ur_batchid),
+ __le32_to_cpu(rec->ur_flags),
+ __le32_to_cpu(rec->ur_index),
+ up_count,
+ pm_count);
+
+ op = (struct update_op *)((char *)&rec->ur_ops.uops_op[0] + 0);
+ if (op->uop_type != __le16_to_cpu(op->uop_type))
+ lustre_swab_update_ops(&rec->ur_ops, up_count);
+
+ for (i = 0; i < up_count; i++, op = update_op_next_op(op)) {
+ printf("\t"DFID" type:%s/%d params:%d ",
+ PFID(&op->uop_fid), update_op_str(op->uop_type),
+ op->uop_type, op->uop_param_count);
+ for (j = 0; j < op->uop_param_count; j++)
+ printf("p_%d:%d ", j, op->uop_params_off[j]);
+ printf("\n");
+ }
+ pm = (struct object_update_param *) op;
+ for (i = 0; i < pm_count; i++) {
+ printf("\tp_%d - %d/%s\n", i, pm->oup_len,
+ buf2str(pm->oup_buf, pm->oup_len));
+ pm = (struct object_update_param *)((char *)(pm + 1) +
+ pm->oup_len);
+ }
+ printf("\n");
+
+}
+
+static void print_unlink_rec(struct llog_unlink_rec *lur)
+{
+ printf("unlink record id:0x%x target %llx:%x:%x\n",
+ __le32_to_cpu(lur->lur_hdr.lrh_id),
+ __le64_to_cpu(lur->lur_oid),
+ __le32_to_cpu(lur->lur_oseq),
+ __le32_to_cpu(lur->lur_count));
+}
+
+static void print_unlink64_rec(struct llog_unlink64_rec *lur)
+{
+ printf("unlink64 record id:0x%x target "DFID"\n",
+ __le32_to_cpu(lur->lur_hdr.lrh_id),
+ PFID(&lur->lur_fid));
+}
+
+static void print_setattr64_rec(struct llog_setattr64_rec *lsr)
+{
+ printf("setattr64 record id:0x%x target "DFID" valid %llx uid %u:%u gid %u:%u\n",
+ __le32_to_cpu(lsr->lsr_hdr.lrh_id),
+ PFID(&lsr->lsr_oi.oi_fid),
+ __le64_to_cpu(lsr->lsr_valid),
+ __le32_to_cpu(lsr->lsr_uid_h),
+ __le32_to_cpu(lsr->lsr_uid),
+ __le32_to_cpu(lsr->lsr_gid_h),
+ __le32_to_cpu(lsr->lsr_gid));
+}
+
+static void print_setattr64_rec_v2(struct llog_setattr64_rec_v2 *lsr)
+{
+ printf("setattr64 v2 record id:0x%x target "DFID" valid %llx uid %u:%u gid %u:%u prj %u\n",
+ __le32_to_cpu(lsr->lsr_hdr.lrh_id),
+ PFID(&lsr->lsr_oi.oi_fid),
+ __le64_to_cpu(lsr->lsr_valid),
+ __le32_to_cpu(lsr->lsr_uid_h),
+ __le32_to_cpu(lsr->lsr_uid),
+ __le32_to_cpu(lsr->lsr_gid_h),
+ __le32_to_cpu(lsr->lsr_gid),
+ __le32_to_cpu(lsr->lsr_projid));
+}
+
+
+static void print_records(struct llog_rec_hdr **recs,
+ int rec_number, int is_ext)
+{
+ __u32 lopt;
+ int i, skip = 0;
+
+ for (i = 0; i < rec_number; i++) {
+ if (!recs[i]) {
+ llapi_printf(LLAPI_MSG_NORMAL,
+ "uninitialized llog record at index %d\n",
+ i);
+ break;
+ }
+ printf("#%.2d (%.3d)", __le32_to_cpu(recs[i]->lrh_index),
+ __le32_to_cpu(recs[i]->lrh_len));
+
+ lopt = __le32_to_cpu(recs[i]->lrh_type);
+
+ if (recs[i]->lrh_id == CANCELLED)
+ printf("NOT SET ");
+
+ switch (lopt) {
+ case OBD_CFG_REC:
+ print_lustre_cfg(
+ (struct lustre_cfg *)((char *)(recs[i]) +
+ sizeof(struct llog_rec_hdr)), &skip);
+ break;
+ case LLOG_PAD_MAGIC:
+ printf("padding\n");
+ break;
+ case LLOG_LOGID_MAGIC:
+ print_log_path((struct llog_logid_rec *)recs[i],
+ is_ext);
+ break;
+ case HSM_AGENT_REC:
+ print_hsm_action((struct llog_agent_req_rec *)recs[i]);
+ break;
+ case CHANGELOG_REC:
+ print_changelog_rec((struct llog_changelog_rec *)
+ recs[i]);
+ break;
+ case CHANGELOG_USER_REC:
+ case CHANGELOG_USER_REC2:
+ printf("changelog_user record id:0x%x\n",
+ __le32_to_cpu(recs[i]->lrh_id));
+ break;
+ case UPDATE_REC:
+ print_update_rec((struct llog_update_record *)recs[i]);
+ break;
+ case MDS_UNLINK_REC:
+ print_unlink_rec((struct llog_unlink_rec *)recs[i]);
+ break;
+ case MDS_UNLINK64_REC:
+ print_unlink64_rec((struct llog_unlink64_rec *)recs[i]);
+ break;
+ case MDS_SETATTR64_REC:
+ if (__le32_to_cpu(recs[i]->lrh_len) >
+ sizeof(struct llog_setattr64_rec)) {
+ print_setattr64_rec_v2(
+ (struct llog_setattr64_rec_v2 *)recs[i]);
+ } else {
+ print_setattr64_rec(
+ (struct llog_setattr64_rec *)recs[i]);
+ }
+ break;
+ default:
+ printf("unknown type %x\n", lopt);
+ break;
+ }
+ }
+}
+
+/** @} llog_reader */