Whamcloud - gitweb
LU-13366 doc: add SEL options to util's man pages
[fs/lustre-release.git] / lustre / utils / llog_reader.c
index e99dc35..c0b6e15 100644 (file)
@@ -185,7 +185,8 @@ int main(int argc, char **argv)
        is_ext = is_fstype_ext(fd);
        if (is_ext < 0) {
                rc = is_ext;
-               printf("Unable to determine type of filesystem containing %s\n",
+               llapi_error(LLAPI_MSG_ERROR, -rc,
+                           "Unable to determine filesystem type for %s",
                       argv[1]);
                goto out_fd;
        }
@@ -233,8 +234,7 @@ int llog_pack_buffer(int fd, struct llog_log_hdr **llog,
        file_size = st.st_size;
        if (file_size < sizeof(**llog)) {
                llapi_error(LLAPI_MSG_ERROR, rc,
-                           "File too small for llog header: "
-                           "need %zd, size %lld\n",
+                           "File too small for llog header: want=%zd got=%lld",
                            sizeof(**llog), file_size);
                rc = -EIO;
                goto out;
@@ -278,7 +278,7 @@ int llog_pack_buffer(int fd, struct llog_log_hdr **llog,
        /* the llog header not countable here.*/
        recs_num = count - 1;
 
-       recs_buf = malloc(recs_num * sizeof(**recs_pr));
+       recs_buf = calloc(recs_num, sizeof(**recs_pr));
        if (recs_buf == NULL) {
                rc = -ENOMEM;
                llapi_error(LLAPI_MSG_ERROR, rc,
@@ -356,7 +356,6 @@ void llog_unpack_buffer(int fd, struct llog_log_hdr *llog_buf,
                free(llog_buf);
        if (recs_buf != NULL)
                free(recs_buf);
-       return;
 }
 
 void print_llog_header(struct llog_log_hdr *llog_buf)
@@ -378,7 +377,6 @@ void print_llog_header(struct llog_log_hdr *llog_buf)
        /* Add the other info you want to view here */
 
        printf("-----------------------\n");
-       return;
 }
 
 static void print_1_cfg(struct lustre_cfg *lcfg)
@@ -393,7 +391,6 @@ static void print_1_cfg(struct lustre_cfg *lcfg)
         for (i = 0; i <  lcfg->lcfg_bufcount; i++)
                 printf("%d:%.*s  ", i, lcfg->lcfg_buflens[i],
                        (char*)lustre_cfg_buf(lcfg, i));
-        return;
 }
 
 static char *lustre_cfg_string(struct lustre_cfg *lcfg, __u32 index)
@@ -449,8 +446,6 @@ static void print_setup_cfg(struct lustre_cfg *lcfg)
                 printf("setup     ");
                 print_1_cfg(lcfg);
         }
-
-        return;
 }
 
 void print_lustre_cfg(struct lustre_cfg *lcfg, int *skip)
@@ -638,7 +633,6 @@ void print_lustre_cfg(struct lustre_cfg *lcfg, int *skip)
                 printf("unsupported cmd_code = %x\n",cmd);
         }
         printf("\n");
-        return;
 }
 
 static void print_hsm_action(struct llog_agent_req_rec *larr)
@@ -648,25 +642,25 @@ static void print_hsm_action(struct llog_agent_req_rec *larr)
 
        sz = larr->arr_hai.hai_len - sizeof(larr->arr_hai);
        printf("lrh=[type=%X len=%d idx=%d] fid="DFID
-              " compound/cookie=%#jx/%#jx"
-              " status=%s action=%s archive#=%d flags=%#jx"
-              " create=%ju change=%ju"
-              " extent=%#jx-%#jx gid=%#jx datalen=%d"
+              " 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",
               larr->arr_hdr.lrh_type,
               larr->arr_hdr.lrh_len, larr->arr_hdr.lrh_index,
               PFID(&larr->arr_hai.hai_fid),
-              (uintmax_t)larr->arr_compound_id,
-              (uintmax_t)larr->arr_hai.hai_cookie,
+              (unsigned long long)larr->arr_compound_id,
+              (unsigned long long)larr->arr_hai.hai_cookie,
               agent_req_status2name(larr->arr_status),
               hsm_copytool_action2name(larr->arr_hai.hai_action),
               larr->arr_archive_id,
-              (uintmax_t)larr->arr_flags,
-              (uintmax_t)larr->arr_req_create,
-              (uintmax_t)larr->arr_req_change,
-              (uintmax_t)larr->arr_hai.hai_extent.offset,
-              (uintmax_t)larr->arr_hai.hai_extent.length,
-              (uintmax_t)larr->arr_hai.hai_gid, sz,
+              (unsigned long long)larr->arr_flags,
+              (unsigned long long)larr->arr_req_create,
+              (unsigned long long)larr->arr_req_change,
+              (unsigned long long)larr->arr_hai.hai_extent.offset,
+              (unsigned long long)larr->arr_hai.hai_extent.length,
+              (unsigned long long)larr->arr_hai.hai_gid, sz,
               hai_dump_data_field(&larr->arr_hai, buf, sizeof(buf)));
 }
 
@@ -680,7 +674,7 @@ void print_changelog_rec(struct llog_changelog_rec *rec)
        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),
-              __le64_to_cpu(rec->cr.cr_index),
+              (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),
@@ -702,7 +696,7 @@ void print_changelog_rec(struct llog_changelog_rec *rec)
                        changelog_rec_extra_flags(&rec->cr);
 
                printf(" cr_extra_flags:0x%llx",
-                      __le64_to_cpu(ef->cr_extra_flags));
+                      (unsigned long long)__le64_to_cpu(ef->cr_extra_flags));
 
                if (ef->cr_extra_flags & CLFE_UIDGID) {
                        struct changelog_ext_uidgid *uidgid =
@@ -779,6 +773,12 @@ static void print_records(struct llog_rec_hdr **recs,
        int i, skip = 0;
 
        for (i = 0; i < rec_number; i++) {
+               if (recs[i] == NULL) {
+                       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));