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>
49 #include <libcfs/libcfs.h>
50 #include <lnet/nidstr.h>
51 #include <lustre/lustre_idl.h>
52 #include <lustre/lustreapi.h>
53 #include <lustre_cfg.h>
55 static inline int ext2_test_bit(int nr, const void *addr)
57 #if __BYTE_ORDER == __BIG_ENDIAN
58 const unsigned char *tmp = addr;
59 return (tmp[nr >> 3] >> (nr & 7)) & 1;
61 const unsigned long *tmp = addr;
62 return ((1UL << (nr & (BITS_PER_LONG - 1))) &
63 ((tmp)[nr / BITS_PER_LONG])) != 0;
67 int llog_pack_buffer(int fd, struct llog_log_hdr **llog_buf,
68 struct llog_rec_hdr ***recs, int *recs_number);
70 void print_llog_header(struct llog_log_hdr *llog_buf);
71 void print_records(struct llog_rec_hdr **recs_buf,int rec_number);
72 void llog_unpack_buffer(int fd, struct llog_log_hdr *llog_buf,
73 struct llog_rec_hdr **recs_buf);
75 #define CANCELLED 0x678
77 #define PTL_CMD_BASE 100
78 char* portals_command[17]=
99 int main(int argc, char **argv)
103 struct llog_log_hdr *llog_buf = NULL;
104 struct llog_rec_hdr **recs_buf = NULL;
109 printf("Usage: llog_reader filename\n");
113 fd = open(argv[1],O_RDONLY);
116 llapi_error(LLAPI_MSG_ERROR, rc, "Could not open the file %s.",
120 rc = llog_pack_buffer(fd, &llog_buf, &recs_buf, &rec_number);
122 llapi_error(LLAPI_MSG_ERROR, rc, "Could not pack buffer.");
126 print_llog_header(llog_buf);
127 print_records(recs_buf,rec_number);
128 llog_unpack_buffer(fd,llog_buf,recs_buf);
137 int llog_pack_buffer(int fd, struct llog_log_hdr **llog,
138 struct llog_rec_hdr ***recs,
141 int rc = 0, recs_num,rd;
144 char *file_buf=NULL, *recs_buf=NULL;
145 struct llog_rec_hdr **recs_pr=NULL;
152 llapi_error(LLAPI_MSG_ERROR, rc, "Got file stat error.");
155 file_size = st.st_size;
156 if (file_size == 0) {
158 llapi_error(LLAPI_MSG_ERROR, rc, "File is empty.");
162 file_buf = malloc(file_size);
163 if (file_buf == NULL){
165 llapi_error(LLAPI_MSG_ERROR, rc, "Memory Alloc for file_buf.");
168 *llog = (struct llog_log_hdr*)file_buf;
170 rd = read(fd,file_buf,file_size);
173 llapi_error(LLAPI_MSG_ERROR, rc, "Read file error.");
177 /* the llog header not countable here.*/
178 recs_num = le32_to_cpu((*llog)->llh_count)-1;
180 recs_buf = malloc(recs_num * sizeof(struct llog_rec_hdr *));
181 if (recs_buf == NULL){
183 llapi_error(LLAPI_MSG_ERROR, rc, "Memory Alloc for recs_buf.");
186 recs_pr = (struct llog_rec_hdr **)recs_buf;
188 ptr = file_buf + le32_to_cpu((*llog)->llh_hdr.lrh_len);
191 while (i < recs_num){
192 struct llog_rec_hdr *cur_rec;
195 if (ptr + sizeof(struct llog_rec_hdr) >
196 file_buf + file_size) {
198 llapi_error(LLAPI_MSG_ERROR, rc,
199 "The log is corrupt (too big at %d)", i);
203 cur_rec = (struct llog_rec_hdr *)ptr;
204 idx = le32_to_cpu(cur_rec->lrh_index);
205 recs_pr[i] = cur_rec;
207 if (ext2_test_bit(idx, (*llog)->llh_bitmap)) {
208 if (le32_to_cpu(cur_rec->lrh_type) != OBD_CFG_REC)
209 printf("rec #%d type=%x len=%u\n", idx,
210 cur_rec->lrh_type, cur_rec->lrh_len);
212 printf("Bit %d of %d not set\n", idx, recs_num);
213 cur_rec->lrh_id = CANCELLED;
214 /* The header counts only set records */
218 ptr += le32_to_cpu(cur_rec->lrh_len);
219 if ((ptr - file_buf) > file_size) {
220 printf("The log is corrupt (too big at %d)\n", i);
228 *recs_number = recs_num;
243 void llog_unpack_buffer(int fd, struct llog_log_hdr *llog_buf,
244 struct llog_rec_hdr **recs_buf)
251 void print_llog_header(struct llog_log_hdr *llog_buf)
255 printf("Header size : %u\n",
256 le32_to_cpu(llog_buf->llh_hdr.lrh_len));
258 t = le64_to_cpu(llog_buf->llh_timestamp);
259 printf("Time : %s", ctime(&t));
261 printf("Number of records: %u\n",
262 le32_to_cpu(llog_buf->llh_count)-1);
264 printf("Target uuid : %s \n",
265 (char *)(&llog_buf->llh_tgtuuid));
267 /* Add the other info you want to view here */
269 printf("-----------------------\n");
273 static void print_1_cfg(struct lustre_cfg *lcfg)
278 printf("nid=%s("LPX64") ", libcfs_nid2str(lcfg->lcfg_nid),
281 printf("nal=%d ", lcfg->lcfg_nal);
282 for (i = 0; i < lcfg->lcfg_bufcount; i++)
283 printf("%d:%.*s ", i, lcfg->lcfg_buflens[i],
284 (char*)lustre_cfg_buf(lcfg, i));
289 static void print_setup_cfg(struct lustre_cfg *lcfg)
291 struct lov_desc *desc;
293 if ((lcfg->lcfg_bufcount == 2) &&
294 (lcfg->lcfg_buflens[1] == sizeof(*desc))) {
295 printf("lov_setup ");
296 printf("0:%s ", lustre_cfg_string(lcfg, 0));
297 printf("1:(struct lov_desc)\n");
298 desc = (struct lov_desc*)(lustre_cfg_string(lcfg, 1));
299 printf("\t\tuuid=%s ", (char*)desc->ld_uuid.uuid);
300 printf("stripe:cnt=%u ", desc->ld_default_stripe_count);
301 printf("size="LPU64" ", desc->ld_default_stripe_size);
302 printf("offset="LPU64" ", desc->ld_default_stripe_offset);
303 printf("pattern=%#x", desc->ld_pattern);
312 void print_lustre_cfg(struct lustre_cfg *lcfg, int *skip)
314 enum lcfg_command_type cmd = le32_to_cpu(lcfg->lcfg_command);
326 print_setup_cfg(lcfg);
339 case(LCFG_ADD_UUID):{
344 case(LCFG_DEL_UUID):{
349 case(LCFG_ADD_CONN):{
354 case(LCFG_DEL_CONN):{
359 case(LCFG_LOV_ADD_OBD):{
360 printf("lov_modify_tgts add ");
364 case(LCFG_LOV_DEL_OBD):{
365 printf("lov_modify_tgts del ");
370 printf("modify_mdc_tgts add ");
375 printf("modify_mdc_tgts del ");
379 case(LCFG_MOUNTOPT):{
380 printf("mount_option ");
384 case(LCFG_DEL_MOUNTOPT):{
385 printf("del_mount_option ");
389 case(LCFG_SET_TIMEOUT):{
390 printf("set_timeout=%d ", lcfg->lcfg_num);
393 case(LCFG_SET_LDLM_TIMEOUT):{
394 printf("set_ldlm_timeout=%d ", lcfg->lcfg_num);
397 case(LCFG_SET_UPCALL):{
398 printf("set_lustre_upcall ");
407 case(LCFG_SET_PARAM):{
408 printf("set_param ");
412 case(LCFG_SPTLRPC_CONF):{
413 printf("sptlrpc_conf ");
418 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
419 char createtime[26], canceltime[26] = "";
422 if (marker->cm_flags & CM_SKIP) {
423 if (marker->cm_flags & CM_START) {
424 printf("SKIP START ");
432 if (marker->cm_flags & CM_EXCLUDE) {
433 if (marker->cm_flags & CM_START)
434 printf("EXCLUDE START ");
436 printf("EXCLUDE END ");
439 /* Handle overflow of 32-bit time_t gracefully.
440 * The copy to time_tmp is needed in any case to
441 * keep the pointer happy, even on 64-bit systems. */
442 time_tmp = marker->cm_createtime;
443 if (time_tmp == marker->cm_createtime) {
444 ctime_r(&time_tmp, createtime);
445 createtime[strlen(createtime) - 1] = 0;
447 strcpy(createtime, "in the distant future");
450 if (marker->cm_canceltime) {
451 /* Like cm_createtime, we try to handle overflow of
452 * 32-bit time_t gracefully. The copy to time_tmp
453 * is also needed on 64-bit systems to keep the
454 * pointer happy, see bug 16771 */
455 time_tmp = marker->cm_canceltime;
456 if (time_tmp == marker->cm_canceltime) {
457 ctime_r(&time_tmp, canceltime);
458 canceltime[strlen(canceltime) - 1] = 0;
460 strcpy(canceltime, "in the distant future");
464 printf("marker %3d (flags=%#04x, v%d.%d.%d.%d) %-15s '%s' %s-%s",
465 marker->cm_step, marker->cm_flags,
466 OBD_OCD_VERSION_MAJOR(marker->cm_vers),
467 OBD_OCD_VERSION_MINOR(marker->cm_vers),
468 OBD_OCD_VERSION_PATCH(marker->cm_vers),
469 OBD_OCD_VERSION_FIX(marker->cm_vers),
470 marker->cm_tgtname, marker->cm_comment,
471 createtime, canceltime);
474 case(LCFG_POOL_NEW):{
479 case(LCFG_POOL_ADD):{
484 case(LCFG_POOL_REM):{
485 printf("pool remove ");
489 case(LCFG_POOL_DEL):{
490 printf("pool destroy ");
495 printf("unsupported cmd_code = %x\n",cmd);
501 static void print_logid(struct llog_logid_rec *lid)
503 printf("ogen=%X name="DOSTID"\n",
504 lid->lid_id.lgl_ogen,
505 POSTID(&lid->lid_id.lgl_oi));
508 static void print_hsm_action(struct llog_agent_req_rec *larr)
513 sz = larr->arr_hai.hai_len - sizeof(larr->arr_hai);
514 printf("lrh=[type=%X len=%d idx=%d] fid="DFID
515 " compound/cookie="LPX64"/"LPX64
516 " status=%s action=%s archive#=%d flags="LPX64
517 " create="LPU64" change="LPU64
518 " extent="LPX64"-"LPX64" gid="LPX64" datalen=%d"
520 larr->arr_hdr.lrh_type,
521 larr->arr_hdr.lrh_len, larr->arr_hdr.lrh_index,
522 PFID(&larr->arr_hai.hai_fid),
523 larr->arr_compound_id, larr->arr_hai.hai_cookie,
524 agent_req_status2name(larr->arr_status),
525 hsm_copytool_action2name(larr->arr_hai.hai_action),
526 larr->arr_archive_id,
528 larr->arr_req_create, larr->arr_req_change,
529 larr->arr_hai.hai_extent.offset,
530 larr->arr_hai.hai_extent.length,
531 larr->arr_hai.hai_gid, sz,
532 hai_dump_data_field(&larr->arr_hai, buf, sizeof(buf)));
535 void print_records(struct llog_rec_hdr **recs, int rec_number)
540 for (i = 0; i < rec_number; i++) {
541 printf("#%.2d (%.3d)", le32_to_cpu(recs[i]->lrh_index),
542 le32_to_cpu(recs[i]->lrh_len));
544 lopt = le32_to_cpu(recs[i]->lrh_type);
546 if (recs[i]->lrh_id == CANCELLED)
552 (struct lustre_cfg *)((char *)(recs[i]) +
553 sizeof(struct llog_rec_hdr)), &skip);
558 case LLOG_LOGID_MAGIC:
559 print_logid((struct llog_logid_rec *)recs[i]);
562 print_hsm_action((struct llog_agent_req_rec *)recs[i]);
565 printf("unknown type %x\n", lopt);