+static void lustre_swab_lu_fid(struct lu_fid *fid)
+{
+ __swab64s(&fid->f_seq);
+ __swab32s(&fid->f_oid);
+ __swab32s(&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);
+ __swab16s(&op->uop_type);
+ __swab16s(&op->uop_param_count);
+ for (j = 0; j < op->uop_param_count; j++)
+ __swab16s(&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",
+ __le64_to_cpu(rec->ur_master_transno),
+ __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");
+
+}
+