4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2014, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 /* Interpret configuration llogs */
40 #include <sys/types.h>
47 #include <libcfs/libcfs.h>
48 #include <lnet/nidstr.h>
49 #include <lustre/lustre_idl.h>
50 #include <lustre/lustreapi.h>
51 #include <lustre_cfg.h>
53 static inline int ext2_test_bit(int nr, const void *addr)
55 #if __BYTE_ORDER == __BIG_ENDIAN
56 const unsigned char *tmp = addr;
57 return (tmp[nr >> 3] >> (nr & 7)) & 1;
59 const unsigned long *tmp = addr;
60 return ((1UL << (nr & (BITS_PER_LONG - 1))) &
61 ((tmp)[nr / BITS_PER_LONG])) != 0;
65 int llog_pack_buffer(int fd, struct llog_log_hdr **llog_buf,
66 struct llog_rec_hdr ***recs, int *recs_number);
68 void print_llog_header(struct llog_log_hdr *llog_buf);
69 void print_records(struct llog_rec_hdr **recs_buf,int rec_number);
70 void llog_unpack_buffer(int fd, struct llog_log_hdr *llog_buf,
71 struct llog_rec_hdr **recs_buf);
73 #define CANCELLED 0x678
75 #define PTL_CMD_BASE 100
76 char* portals_command[17]=
97 int main(int argc, char **argv)
101 struct llog_log_hdr *llog_buf = NULL;
102 struct llog_rec_hdr **recs_buf = NULL;
107 printf("Usage: llog_reader filename\n");
111 fd = open(argv[1],O_RDONLY);
114 llapi_error(LLAPI_MSG_ERROR, rc, "Could not open the file %s.",
118 rc = llog_pack_buffer(fd, &llog_buf, &recs_buf, &rec_number);
120 llapi_error(LLAPI_MSG_ERROR, rc, "Could not pack buffer.");
124 print_llog_header(llog_buf);
125 print_records(recs_buf,rec_number);
126 llog_unpack_buffer(fd,llog_buf,recs_buf);
135 int llog_pack_buffer(int fd, struct llog_log_hdr **llog,
136 struct llog_rec_hdr ***recs,
139 int rc = 0, recs_num,rd;
142 char *file_buf=NULL, *recs_buf=NULL;
143 struct llog_rec_hdr **recs_pr=NULL;
150 llapi_error(LLAPI_MSG_ERROR, rc, "Got file stat error.");
153 file_size = st.st_size;
154 if (file_size == 0) {
156 llapi_error(LLAPI_MSG_ERROR, rc, "File is empty.");
160 file_buf = malloc(file_size);
161 if (file_buf == NULL){
163 llapi_error(LLAPI_MSG_ERROR, rc, "Memory Alloc for file_buf.");
166 *llog = (struct llog_log_hdr*)file_buf;
168 rd = read(fd,file_buf,file_size);
171 llapi_error(LLAPI_MSG_ERROR, rc, "Read file error.");
175 /* the llog header not countable here.*/
176 recs_num = le32_to_cpu((*llog)->llh_count)-1;
178 recs_buf = malloc(recs_num * sizeof(struct llog_rec_hdr *));
179 if (recs_buf == NULL){
181 llapi_error(LLAPI_MSG_ERROR, rc, "Memory Alloc for recs_buf.");
184 recs_pr = (struct llog_rec_hdr **)recs_buf;
186 ptr = file_buf + le32_to_cpu((*llog)->llh_hdr.lrh_len);
189 while (i < recs_num){
190 struct llog_rec_hdr *cur_rec;
193 if (ptr + sizeof(struct llog_rec_hdr) >
194 file_buf + file_size) {
196 llapi_error(LLAPI_MSG_ERROR, rc,
197 "The log is corrupt (too big at %d)", i);
201 cur_rec = (struct llog_rec_hdr *)ptr;
202 idx = le32_to_cpu(cur_rec->lrh_index);
203 recs_pr[i] = cur_rec;
205 if (ext2_test_bit(idx, (*llog)->llh_bitmap)) {
206 if (le32_to_cpu(cur_rec->lrh_type) != OBD_CFG_REC)
207 printf("rec #%d type=%x len=%u\n", idx,
208 cur_rec->lrh_type, cur_rec->lrh_len);
210 printf("Bit %d of %d not set\n", idx, recs_num);
211 cur_rec->lrh_id = CANCELLED;
212 /* The header counts only set records */
216 ptr += le32_to_cpu(cur_rec->lrh_len);
217 if ((ptr - file_buf) > file_size) {
218 printf("The log is corrupt (too big at %d)\n", i);
226 *recs_number = recs_num;
241 void llog_unpack_buffer(int fd, struct llog_log_hdr *llog_buf,
242 struct llog_rec_hdr **recs_buf)
249 void print_llog_header(struct llog_log_hdr *llog_buf)
253 printf("Header size : %u\n",
254 le32_to_cpu(llog_buf->llh_hdr.lrh_len));
256 t = le64_to_cpu(llog_buf->llh_timestamp);
257 printf("Time : %s", ctime(&t));
259 printf("Number of records: %u\n",
260 le32_to_cpu(llog_buf->llh_count)-1);
262 printf("Target uuid : %s \n",
263 (char *)(&llog_buf->llh_tgtuuid));
265 /* Add the other info you want to view here */
267 printf("-----------------------\n");
271 static void print_1_cfg(struct lustre_cfg *lcfg)
276 printf("nid=%s("LPX64") ", libcfs_nid2str(lcfg->lcfg_nid),
279 printf("nal=%d ", lcfg->lcfg_nal);
280 for (i = 0; i < lcfg->lcfg_bufcount; i++)
281 printf("%d:%.*s ", i, lcfg->lcfg_buflens[i],
282 (char*)lustre_cfg_buf(lcfg, i));
287 static void print_setup_cfg(struct lustre_cfg *lcfg)
289 struct lov_desc *desc;
291 if ((lcfg->lcfg_bufcount == 2) &&
292 (lcfg->lcfg_buflens[1] == sizeof(*desc))) {
293 printf("lov_setup ");
294 printf("0:%s ", lustre_cfg_string(lcfg, 0));
295 printf("1:(struct lov_desc)\n");
296 desc = (struct lov_desc*)(lustre_cfg_string(lcfg, 1));
297 printf("\t\tuuid=%s ", (char*)desc->ld_uuid.uuid);
298 printf("stripe:cnt=%u ", desc->ld_default_stripe_count);
299 printf("size="LPU64" ", desc->ld_default_stripe_size);
300 printf("offset="LPU64" ", desc->ld_default_stripe_offset);
301 printf("pattern=%#x", desc->ld_pattern);
310 void print_lustre_cfg(struct lustre_cfg *lcfg, int *skip)
312 enum lcfg_command_type cmd = le32_to_cpu(lcfg->lcfg_command);
324 print_setup_cfg(lcfg);
337 case(LCFG_ADD_UUID):{
342 case(LCFG_DEL_UUID):{
347 case(LCFG_ADD_CONN):{
352 case(LCFG_DEL_CONN):{
357 case(LCFG_LOV_ADD_OBD):{
358 printf("lov_modify_tgts add ");
362 case(LCFG_LOV_DEL_OBD):{
363 printf("lov_modify_tgts del ");
368 printf("modify_mdc_tgts add ");
373 printf("modify_mdc_tgts del ");
377 case(LCFG_MOUNTOPT):{
378 printf("mount_option ");
382 case(LCFG_DEL_MOUNTOPT):{
383 printf("del_mount_option ");
387 case(LCFG_SET_TIMEOUT):{
388 printf("set_timeout=%d ", lcfg->lcfg_num);
391 case(LCFG_SET_LDLM_TIMEOUT):{
392 printf("set_ldlm_timeout=%d ", lcfg->lcfg_num);
395 case(LCFG_SET_UPCALL):{
396 printf("set_lustre_upcall ");
405 case(LCFG_SET_PARAM):{
406 printf("set_param ");
410 case(LCFG_SPTLRPC_CONF):{
411 printf("sptlrpc_conf ");
416 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
417 char createtime[26], canceltime[26] = "";
420 if (marker->cm_flags & CM_SKIP) {
421 if (marker->cm_flags & CM_START) {
422 printf("SKIP START ");
430 if (marker->cm_flags & CM_EXCLUDE) {
431 if (marker->cm_flags & CM_START)
432 printf("EXCLUDE START ");
434 printf("EXCLUDE END ");
437 /* Handle overflow of 32-bit time_t gracefully.
438 * The copy to time_tmp is needed in any case to
439 * keep the pointer happy, even on 64-bit systems. */
440 time_tmp = marker->cm_createtime;
441 if (time_tmp == marker->cm_createtime) {
442 ctime_r(&time_tmp, createtime);
443 createtime[strlen(createtime) - 1] = 0;
445 strcpy(createtime, "in the distant future");
448 if (marker->cm_canceltime) {
449 /* Like cm_createtime, we try to handle overflow of
450 * 32-bit time_t gracefully. The copy to time_tmp
451 * is also needed on 64-bit systems to keep the
452 * pointer happy, see bug 16771 */
453 time_tmp = marker->cm_canceltime;
454 if (time_tmp == marker->cm_canceltime) {
455 ctime_r(&time_tmp, canceltime);
456 canceltime[strlen(canceltime) - 1] = 0;
458 strcpy(canceltime, "in the distant future");
462 printf("marker %3d (flags=%#04x, v%d.%d.%d.%d) %-15s '%s' %s-%s",
463 marker->cm_step, marker->cm_flags,
464 OBD_OCD_VERSION_MAJOR(marker->cm_vers),
465 OBD_OCD_VERSION_MINOR(marker->cm_vers),
466 OBD_OCD_VERSION_PATCH(marker->cm_vers),
467 OBD_OCD_VERSION_FIX(marker->cm_vers),
468 marker->cm_tgtname, marker->cm_comment,
469 createtime, canceltime);
472 case(LCFG_POOL_NEW):{
477 case(LCFG_POOL_ADD):{
482 case(LCFG_POOL_REM):{
483 printf("pool remove ");
487 case(LCFG_POOL_DEL):{
488 printf("pool destroy ");
493 printf("unsupported cmd_code = %x\n",cmd);
499 static void print_logid(struct llog_logid_rec *lid)
501 printf("ogen=%X name="DOSTID"\n",
502 lid->lid_id.lgl_ogen,
503 POSTID(&lid->lid_id.lgl_oi));
506 static void print_hsm_action(struct llog_agent_req_rec *larr)
511 sz = larr->arr_hai.hai_len - sizeof(larr->arr_hai);
512 printf("lrh=[type=%X len=%d idx=%d] fid="DFID
513 " compound/cookie="LPX64"/"LPX64
514 " status=%s action=%s archive#=%d flags="LPX64
515 " create="LPU64" change="LPU64
516 " extent="LPX64"-"LPX64" gid="LPX64" datalen=%d"
518 larr->arr_hdr.lrh_type,
519 larr->arr_hdr.lrh_len, larr->arr_hdr.lrh_index,
520 PFID(&larr->arr_hai.hai_fid),
521 larr->arr_compound_id, larr->arr_hai.hai_cookie,
522 agent_req_status2name(larr->arr_status),
523 hsm_copytool_action2name(larr->arr_hai.hai_action),
524 larr->arr_archive_id,
526 larr->arr_req_create, larr->arr_req_change,
527 larr->arr_hai.hai_extent.offset,
528 larr->arr_hai.hai_extent.length,
529 larr->arr_hai.hai_gid, sz,
530 hai_dump_data_field(&larr->arr_hai, buf, sizeof(buf)));
533 void print_records(struct llog_rec_hdr **recs, int rec_number)
538 for (i = 0; i < rec_number; i++) {
539 printf("#%.2d (%.3d)", le32_to_cpu(recs[i]->lrh_index),
540 le32_to_cpu(recs[i]->lrh_len));
542 lopt = le32_to_cpu(recs[i]->lrh_type);
544 if (recs[i]->lrh_id == CANCELLED)
550 (struct lustre_cfg *)((char *)(recs[i]) +
551 sizeof(struct llog_rec_hdr)), &skip);
556 case LLOG_LOGID_MAGIC:
557 print_logid((struct llog_logid_rec *)recs[i]);
560 print_hsm_action((struct llog_agent_req_rec *)recs[i]);
563 printf("unknown type %x\n", lopt);