X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Futils%2Fllog_reader.c;h=653ab18009f0b72c723f30961ada690c64e7cfbd;hb=ffef6e3271ad1136d3ab1c2ee229b4690a6722a0;hp=4d2f1ffad637682922e010d5118d185b99d835f7;hpb=ade3d1ee9494af32f4e022e30757318a94b7ee96;p=fs%2Flustre-release.git diff --git a/lustre/utils/llog_reader.c b/lustre/utils/llog_reader.c index 4d2f1ff..653ab18 100644 --- a/lustre/utils/llog_reader.c +++ b/lustre/utils/llog_reader.c @@ -15,11 +15,7 @@ * * You should have received a copy of the GNU General Public License * version 2 along with this program; If not, see - * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf - * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. + * http://www.gnu.org/licenses/gpl-2.0.html * * GPL HEADER END */ @@ -27,7 +23,7 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2015, Intel Corporation. + * Copyright (c) 2011, 2017, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -40,7 +36,12 @@ * @{ */ +#include +#include +#include #include +#include +#include #include #include #ifdef HAVE_ENDIAN_H @@ -52,11 +53,12 @@ #include #include #include -#include -#include +#include +#include +#include +#include +#include #include -#include -#include static inline int ext2_test_bit(int nr, const void *addr) { @@ -65,8 +67,8 @@ static inline int ext2_test_bit(int nr, const void *addr) return (tmp[nr >> 3] >> (nr & 7)) & 1; #else const unsigned long *tmp = addr; - return ((1UL << (nr & (BITS_PER_LONG - 1))) & - ((tmp)[nr / BITS_PER_LONG])) != 0; + return ((1UL << (nr & (__WORDSIZE - 1))) & + ((tmp)[nr / __WORDSIZE])) != 0; #endif } @@ -143,17 +145,18 @@ static void print_log_path(struct llog_logid_rec *lid, int is_ext) if (is_ext) snprintf(object_path, sizeof(object_path), - "O/"LPU64"/d%u/%u", fid_from_logid.f_seq, - fid_from_logid.f_oid % 32, fid_from_logid.f_oid); + "O/%ju/d%u/%u", (uintmax_t)fid_from_logid.f_seq, + fid_from_logid.f_oid % 32, + fid_from_logid.f_oid); else snprintf(object_path, sizeof(object_path), - "oi."LPU64"/"DFID_NOBRACE, - fid_from_logid.f_seq & (OSD_OI_FID_NR - 1) , + "oi.%ju/"DFID_NOBRACE, + (uintmax_t)(fid_from_logid.f_seq & (OSD_OI_FID_NR - 1)), PFID(&fid_from_logid)); - printf("ogen=%X id="DOSTID" path=%s\n", - lid->lid_id.lgl_ogen, POSTID(&lid->lid_id.lgl_oi), - object_path); + printf("id="DFID":%x path=%s\n", + PFID(&lid->lid_id.lgl_oi.oi_fid), lid->lid_id.lgl_ogen, + object_path); } int main(int argc, char **argv) @@ -181,9 +184,10 @@ 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", argv[1]); - goto out; + goto out_fd; } rc = llog_pack_buffer(fd, &llog_buf, &recs_buf, &rec_number); @@ -256,7 +260,7 @@ int llog_pack_buffer(int fd, struct llog_log_hdr **llog, } /* the llog header not countable here.*/ - recs_num = le32_to_cpu((*llog)->llh_count) - 1; + recs_num = __le32_to_cpu((*llog)->llh_count) - 1; recs_buf = malloc(recs_num * sizeof(**recs_pr)); if (recs_buf == NULL) { @@ -268,7 +272,7 @@ int llog_pack_buffer(int fd, struct llog_log_hdr **llog, } recs_pr = (struct llog_rec_hdr **)recs_buf; - ptr = file_buf + le32_to_cpu((*llog)->llh_hdr.lrh_len); + ptr = file_buf + __le32_to_cpu((*llog)->llh_hdr.lrh_len); i = 0; while (ptr < (file_buf + file_size)) { @@ -284,7 +288,7 @@ int llog_pack_buffer(int fd, struct llog_log_hdr **llog, } cur_rec = (struct llog_rec_hdr *)ptr; - idx = le32_to_cpu(cur_rec->lrh_index); + idx = __le32_to_cpu(cur_rec->lrh_index); recs_pr[i] = cur_rec; offset = (unsigned long)ptr - (unsigned long)file_buf; if (cur_rec->lrh_len == 0 || @@ -304,7 +308,7 @@ int llog_pack_buffer(int fd, struct llog_log_hdr **llog, i--; } - ptr += le32_to_cpu(cur_rec->lrh_len); + 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); rc = -EINVAL; @@ -339,24 +343,24 @@ void llog_unpack_buffer(int fd, struct llog_log_hdr *llog_buf, void print_llog_header(struct llog_log_hdr *llog_buf) { - time_t t; + time_t t; - printf("Header size : %u\n", - le32_to_cpu(llog_buf->llh_hdr.lrh_len)); + printf("Header size : %u\n", + __le32_to_cpu(llog_buf->llh_hdr.lrh_len)); - t = le64_to_cpu(llog_buf->llh_timestamp); - printf("Time : %s", ctime(&t)); + t = __le64_to_cpu(llog_buf->llh_timestamp); + printf("Time : %s", ctime(&t)); - printf("Number of records: %u\n", - le32_to_cpu(llog_buf->llh_count)-1); + printf("Number of records: %u\n", + __le32_to_cpu(llog_buf->llh_count)-1); - printf("Target uuid : %s \n", - (char *)(&llog_buf->llh_tgtuuid)); + printf("Target uuid : %s\n", + (char *)(&llog_buf->llh_tgtuuid)); - /* Add the other info you want to view here */ + /* Add the other info you want to view here */ - printf("-----------------------\n"); - return; + printf("-----------------------\n"); + return; } static void print_1_cfg(struct lustre_cfg *lcfg) @@ -364,8 +368,8 @@ static void print_1_cfg(struct lustre_cfg *lcfg) int i; if (lcfg->lcfg_nid) - printf("nid=%s("LPX64") ", libcfs_nid2str(lcfg->lcfg_nid), - lcfg->lcfg_nid); + printf("nid=%s(%#jx) ", libcfs_nid2str(lcfg->lcfg_nid), + (uintmax_t)lcfg->lcfg_nid); if (lcfg->lcfg_nal) printf("nal=%d ", lcfg->lcfg_nal); for (i = 0; i < lcfg->lcfg_bufcount; i++) @@ -374,6 +378,38 @@ static void print_1_cfg(struct lustre_cfg *lcfg) return; } +static char *lustre_cfg_string(struct lustre_cfg *lcfg, __u32 index) +{ + char *s; + + if (lcfg->lcfg_buflens[index] == 0) + return NULL; + + s = lustre_cfg_buf(lcfg, index); + if (s == NULL) + return NULL; + + /* + * make sure it's NULL terminated, even if this kills a char + * of data. Try to use the padding first though. + */ + if (s[lcfg->lcfg_buflens[index] - 1] != '\0') { + size_t last = __ALIGN_KERNEL(lcfg->lcfg_buflens[index], 8) - 1; + char lost; + + /* Use the smaller value */ + if (last > lcfg->lcfg_buflens[index]) + last = lcfg->lcfg_buflens[index]; + + lost = s[last]; + s[last] = '\0'; + if (lost != '\0') { + fprintf(stderr, "Truncated buf %d to '%s' (lost '%c'...)\n", + index, s, lost); + } + } + return s; +} static void print_setup_cfg(struct lustre_cfg *lcfg) { @@ -387,8 +423,9 @@ static void print_setup_cfg(struct lustre_cfg *lcfg) desc = (struct lov_desc*)(lustre_cfg_string(lcfg, 1)); printf("\t\tuuid=%s ", (char*)desc->ld_uuid.uuid); printf("stripe:cnt=%u ", desc->ld_default_stripe_count); - printf("size="LPU64" ", desc->ld_default_stripe_size); - printf("offset="LPU64" ", desc->ld_default_stripe_offset); + printf("size=%ju ", (uintmax_t)desc->ld_default_stripe_size); + printf("offset=%ju ", + (uintmax_t)desc->ld_default_stripe_offset); printf("pattern=%#x", desc->ld_pattern); } else { printf("setup "); @@ -400,7 +437,7 @@ static void print_setup_cfg(struct lustre_cfg *lcfg) void print_lustre_cfg(struct lustre_cfg *lcfg, int *skip) { - enum lcfg_command_type cmd = le32_to_cpu(lcfg->lcfg_command); + enum lcfg_command_type cmd = __le32_to_cpu(lcfg->lcfg_command); if (*skip > 0) printf("SKIP "); @@ -593,33 +630,128 @@ 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="LPX64"/"LPX64 - " status=%s action=%s archive#=%d flags="LPX64 - " create="LPU64" change="LPU64 - " extent="LPX64"-"LPX64" gid="LPX64" datalen=%d" + " compound/cookie=%#jx/%#jx" + " status=%s action=%s archive#=%d flags=%#jx" + " create=%ju change=%ju" + " extent=%#jx-%#jx gid=%#jx 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, + (uintmax_t)larr->arr_compound_id, + (uintmax_t)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, + (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, hai_dump_data_field(&larr->arr_hai, buf, sizeof(buf))); } void print_changelog_rec(struct llog_changelog_rec *rec) { - printf("changelog record id:0x%x cr_flags:0x%x cr_type:%s(0x%x)\n", - le32_to_cpu(rec->cr_hdr.lrh_id), - le32_to_cpu(rec->cr.cr_flags), - changelog_type2str(le32_to_cpu(rec->cr.cr_type)), - le32_to_cpu(rec->cr.cr_type)); + 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), + __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", + __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 print_records(struct llog_rec_hdr **recs, @@ -629,10 +761,10 @@ static void print_records(struct llog_rec_hdr **recs, 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)); + 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); + lopt = __le32_to_cpu(recs[i]->lrh_type); if (recs[i]->lrh_id == CANCELLED) printf("NOT SET "); @@ -659,7 +791,7 @@ static void print_records(struct llog_rec_hdr **recs, break; case CHANGELOG_USER_REC: printf("changelog_user record id:0x%x\n", - le32_to_cpu(recs[i]->lrh_id)); + __le32_to_cpu(recs[i]->lrh_id)); break; default: printf("unknown type %x\n", lopt);