Whamcloud - gitweb
LU-4961 lustre: remove liblustre.h and obd.h from userspace
[fs/lustre-release.git] / lustre / utils / llog_reader.c
index d2f1f1a..2a1903b 100644 (file)
@@ -1,6 +1,4 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
  * GPL HEADER START
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  * GPL HEADER END
  */
 /*
- * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright (c) 2011, 2012, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <endian.h>
 #include <fcntl.h>
 
 #include <time.h>
-#include <liblustre.h>
+#include <libcfs/libcfs.h>
 #include <lustre/lustre_idl.h>
+#include <lustre_cfg.h>
+
+static inline int ext2_test_bit(int nr, const void *addr)
+{
+#if __BYTE_ORDER == __BIG_ENDIAN
+       const unsigned char *tmp = addr;
+       return (tmp[nr >> 3] >> (nr & 7)) & 1;
+#else
+       return test_bit(nr, addr);
+#endif
+}
 
 int llog_pack_buffer(int fd, struct llog_log_hdr **llog_buf,
                      struct llog_rec_hdr ***recs, int *recs_number);
@@ -167,16 +179,16 @@ int llog_pack_buffer(int fd, struct llog_log_hdr **llog,
                 recs_pr[i] = cur_rec;
 
                 if (ext2_test_bit(idx, (*llog)->llh_bitmap)) {
-                        if (le32_to_cpu(cur_rec->lrh_type) != OBD_CFG_REC) 
+                        if (le32_to_cpu(cur_rec->lrh_type) != OBD_CFG_REC)
                                 printf("rec #%d type=%x len=%u\n", idx,
                                        cur_rec->lrh_type, cur_rec->lrh_len);
                 } else {
                         printf("Bit %d of %d not set\n", idx, recs_num);
-                        cur_rec->padding = CANCELLED;
+                        cur_rec->lrh_id = CANCELLED;
                         /* The header counts only set records */
                         i--;
                 }
-                
+
                 ptr += le32_to_cpu(cur_rec->lrh_len);
                 if ((ptr - file_buf) > file_size) {
                         printf("The log is corrupt (too big at %d)\n", i);
@@ -350,7 +362,10 @@ void print_lustre_cfg(struct lustre_cfg *lcfg, int *skip)
         }
         case(LCFG_SET_TIMEOUT):{
                 printf("set_timeout=%d ", lcfg->lcfg_num);
-                print_1_cfg(lcfg);
+                break;
+        }
+        case(LCFG_SET_LDLM_TIMEOUT):{
+                printf("set_ldlm_timeout=%d ", lcfg->lcfg_num);
                 break;
         }
         case(LCFG_SET_UPCALL):{
@@ -358,8 +373,18 @@ void print_lustre_cfg(struct lustre_cfg *lcfg, int *skip)
                 print_1_cfg(lcfg);
                 break;
         }
-        case(LCFG_PARAM):{
-                printf("param ");
+       case(LCFG_PARAM):{
+               printf("param ");
+               print_1_cfg(lcfg);
+               break;
+       }
+       case(LCFG_SET_PARAM):{
+               printf("set_param ");
+               print_1_cfg(lcfg);
+               break;
+       }
+        case(LCFG_SPTLRPC_CONF):{
+                printf("sptlrpc_conf ");
                 print_1_cfg(lcfg);
                 break;
         }
@@ -379,7 +404,7 @@ void print_lustre_cfg(struct lustre_cfg *lcfg, int *skip)
                 }
 
                 if (marker->cm_flags & CM_EXCLUDE) {
-                        if (marker->cm_flags & CM_START) 
+                        if (marker->cm_flags & CM_START)
                                 printf("EXCLUDE START ");
                         else
                                 printf("EXCLUDE END   ");
@@ -447,28 +472,72 @@ void print_lustre_cfg(struct lustre_cfg *lcfg, int *skip)
         return;
 }
 
+static void print_logid(struct llog_logid_rec *lid)
+{
+       printf("ogen=%X name="DOSTID"\n",
+               lid->lid_id.lgl_ogen,
+               POSTID(&lid->lid_id.lgl_oi));
+}
+
+static void print_hsm_action(struct llog_agent_req_rec *larr)
+{
+       char    buf[12];
+       int     sz;
+
+       sz = larr->arr_hai.hai_len - sizeof(larr->arr_hai);
+       printf("lrh=[type=%X len=%d idx=%d] fid="DFID
+              " compound/cookie="LPX64"/"LPX64
+              " status=%s action=%s archive#=%d flags="LPX64
+              " create="LPU64" change="LPU64
+              " extent="LPX64"-"LPX64" gid="LPX64" datalen=%d"
+              " data=[%s]\n",
+              larr->arr_hdr.lrh_type,
+              larr->arr_hdr.lrh_len, larr->arr_hdr.lrh_index,
+              PFID(&larr->arr_hai.hai_fid),
+              larr->arr_compound_id, larr->arr_hai.hai_cookie,
+              agent_req_status2name(larr->arr_status),
+              hsm_copytool_action2name(larr->arr_hai.hai_action),
+              larr->arr_archive_id,
+              larr->arr_flags,
+              larr->arr_req_create, larr->arr_req_change,
+              larr->arr_hai.hai_extent.offset,
+              larr->arr_hai.hai_extent.length,
+              larr->arr_hai.hai_gid, sz,
+              hai_dump_data_field(&larr->arr_hai, buf, sizeof(buf)));
+}
+
 void print_records(struct llog_rec_hdr **recs, int rec_number)
 {
-        __u32 lopt;
-        int i, skip = 0;
-        
-        for(i = 0; i < rec_number; i++) {
-                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]->padding == CANCELLED) 
-                        printf("NOT SET ");
-            
-                if (lopt == OBD_CFG_REC) {
-                        struct lustre_cfg *lcfg;
-                        lcfg = (struct lustre_cfg *)((char*)(recs[i]) +
-                                                     sizeof(struct llog_rec_hdr));
-                        print_lustre_cfg(lcfg, &skip);
-                } else if (lopt == LLOG_PAD_MAGIC) {
-                        printf("padding\n");
-                } else
-                        printf("unknown type %x\n", lopt);
-        }
+       __u32 lopt;
+       int i, skip = 0;
+
+       for (i = 0; i < rec_number; i++) {
+               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_logid((struct llog_logid_rec *)recs[i]);
+                       break;
+               case HSM_AGENT_REC:
+                       print_hsm_action((struct llog_agent_req_rec *)recs[i]);
+                       break;
+               default:
+                       printf("unknown type %x\n", lopt);
+                       break;
+               }
+       }
 }