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 return test_bit(nr, addr);
63 int llog_pack_buffer(int fd, struct llog_log_hdr **llog_buf,
64 struct llog_rec_hdr ***recs, int *recs_number);
66 void print_llog_header(struct llog_log_hdr *llog_buf);
67 void print_records(struct llog_rec_hdr **recs_buf,int rec_number);
68 void llog_unpack_buffer(int fd, struct llog_log_hdr *llog_buf,
69 struct llog_rec_hdr **recs_buf);
71 #define CANCELLED 0x678
73 #define PTL_CMD_BASE 100
74 char* portals_command[17]=
95 int main(int argc, char **argv)
99 struct llog_log_hdr *llog_buf = NULL;
100 struct llog_rec_hdr **recs_buf = NULL;
105 printf("Usage: llog_reader filename\n");
109 fd = open(argv[1],O_RDONLY);
112 llapi_error(LLAPI_MSG_ERROR, rc, "Could not open the file %s.",
116 rc = llog_pack_buffer(fd, &llog_buf, &recs_buf, &rec_number);
118 llapi_error(LLAPI_MSG_ERROR, rc, "Could not pack buffer.");
122 print_llog_header(llog_buf);
123 print_records(recs_buf,rec_number);
124 llog_unpack_buffer(fd,llog_buf,recs_buf);
133 int llog_pack_buffer(int fd, struct llog_log_hdr **llog,
134 struct llog_rec_hdr ***recs,
137 int rc = 0, recs_num,rd;
140 char *file_buf=NULL, *recs_buf=NULL;
141 struct llog_rec_hdr **recs_pr=NULL;
148 llapi_error(LLAPI_MSG_ERROR, rc, "Got file stat error.");
151 file_size = st.st_size;
152 if (file_size == 0) {
154 llapi_error(LLAPI_MSG_ERROR, rc, "File is empty.");
158 file_buf = malloc(file_size);
159 if (file_buf == NULL){
161 llapi_error(LLAPI_MSG_ERROR, rc, "Memory Alloc for file_buf.");
164 *llog = (struct llog_log_hdr*)file_buf;
166 rd = read(fd,file_buf,file_size);
169 llapi_error(LLAPI_MSG_ERROR, rc, "Read file error.");
173 /* the llog header not countable here.*/
174 recs_num = le32_to_cpu((*llog)->llh_count)-1;
176 recs_buf = malloc(recs_num * sizeof(struct llog_rec_hdr *));
177 if (recs_buf == NULL){
179 llapi_error(LLAPI_MSG_ERROR, rc, "Memory Alloc for recs_buf.");
182 recs_pr = (struct llog_rec_hdr **)recs_buf;
184 ptr = file_buf + le32_to_cpu((*llog)->llh_hdr.lrh_len);
187 while (i < recs_num){
188 struct llog_rec_hdr *cur_rec;
191 if (ptr + sizeof(struct llog_rec_hdr) >
192 file_buf + file_size) {
194 llapi_error(LLAPI_MSG_ERROR, rc,
195 "The log is corrupt (too big at %d)", i);
199 cur_rec = (struct llog_rec_hdr *)ptr;
200 idx = le32_to_cpu(cur_rec->lrh_index);
201 recs_pr[i] = cur_rec;
203 if (ext2_test_bit(idx, (*llog)->llh_bitmap)) {
204 if (le32_to_cpu(cur_rec->lrh_type) != OBD_CFG_REC)
205 printf("rec #%d type=%x len=%u\n", idx,
206 cur_rec->lrh_type, cur_rec->lrh_len);
208 printf("Bit %d of %d not set\n", idx, recs_num);
209 cur_rec->lrh_id = CANCELLED;
210 /* The header counts only set records */
214 ptr += le32_to_cpu(cur_rec->lrh_len);
215 if ((ptr - file_buf) > file_size) {
216 printf("The log is corrupt (too big at %d)\n", i);
224 *recs_number = recs_num;
239 void llog_unpack_buffer(int fd, struct llog_log_hdr *llog_buf,
240 struct llog_rec_hdr **recs_buf)
247 void print_llog_header(struct llog_log_hdr *llog_buf)
251 printf("Header size : %u\n",
252 le32_to_cpu(llog_buf->llh_hdr.lrh_len));
254 t = le64_to_cpu(llog_buf->llh_timestamp);
255 printf("Time : %s", ctime(&t));
257 printf("Number of records: %u\n",
258 le32_to_cpu(llog_buf->llh_count)-1);
260 printf("Target uuid : %s \n",
261 (char *)(&llog_buf->llh_tgtuuid));
263 /* Add the other info you want to view here */
265 printf("-----------------------\n");
269 static void print_1_cfg(struct lustre_cfg *lcfg)
274 printf("nid=%s("LPX64") ", libcfs_nid2str(lcfg->lcfg_nid),
277 printf("nal=%d ", lcfg->lcfg_nal);
278 for (i = 0; i < lcfg->lcfg_bufcount; i++)
279 printf("%d:%.*s ", i, lcfg->lcfg_buflens[i],
280 (char*)lustre_cfg_buf(lcfg, i));
285 static void print_setup_cfg(struct lustre_cfg *lcfg)
287 struct lov_desc *desc;
289 if ((lcfg->lcfg_bufcount == 2) &&
290 (lcfg->lcfg_buflens[1] == sizeof(*desc))) {
291 printf("lov_setup ");
292 printf("0:%s ", lustre_cfg_string(lcfg, 0));
293 printf("1:(struct lov_desc)\n");
294 desc = (struct lov_desc*)(lustre_cfg_string(lcfg, 1));
295 printf("\t\tuuid=%s ", (char*)desc->ld_uuid.uuid);
296 printf("stripe:cnt=%u ", desc->ld_default_stripe_count);
297 printf("size="LPU64" ", desc->ld_default_stripe_size);
298 printf("offset="LPU64" ", desc->ld_default_stripe_offset);
299 printf("pattern=%#x", desc->ld_pattern);
308 void print_lustre_cfg(struct lustre_cfg *lcfg, int *skip)
310 enum lcfg_command_type cmd = le32_to_cpu(lcfg->lcfg_command);
322 print_setup_cfg(lcfg);
335 case(LCFG_ADD_UUID):{
340 case(LCFG_DEL_UUID):{
345 case(LCFG_ADD_CONN):{
350 case(LCFG_DEL_CONN):{
355 case(LCFG_LOV_ADD_OBD):{
356 printf("lov_modify_tgts add ");
360 case(LCFG_LOV_DEL_OBD):{
361 printf("lov_modify_tgts del ");
366 printf("modify_mdc_tgts add ");
371 printf("modify_mdc_tgts del ");
375 case(LCFG_MOUNTOPT):{
376 printf("mount_option ");
380 case(LCFG_DEL_MOUNTOPT):{
381 printf("del_mount_option ");
385 case(LCFG_SET_TIMEOUT):{
386 printf("set_timeout=%d ", lcfg->lcfg_num);
389 case(LCFG_SET_LDLM_TIMEOUT):{
390 printf("set_ldlm_timeout=%d ", lcfg->lcfg_num);
393 case(LCFG_SET_UPCALL):{
394 printf("set_lustre_upcall ");
403 case(LCFG_SET_PARAM):{
404 printf("set_param ");
408 case(LCFG_SPTLRPC_CONF):{
409 printf("sptlrpc_conf ");
414 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
415 char createtime[26], canceltime[26] = "";
418 if (marker->cm_flags & CM_SKIP) {
419 if (marker->cm_flags & CM_START) {
420 printf("SKIP START ");
428 if (marker->cm_flags & CM_EXCLUDE) {
429 if (marker->cm_flags & CM_START)
430 printf("EXCLUDE START ");
432 printf("EXCLUDE END ");
435 /* Handle overflow of 32-bit time_t gracefully.
436 * The copy to time_tmp is needed in any case to
437 * keep the pointer happy, even on 64-bit systems. */
438 time_tmp = marker->cm_createtime;
439 if (time_tmp == marker->cm_createtime) {
440 ctime_r(&time_tmp, createtime);
441 createtime[strlen(createtime) - 1] = 0;
443 strcpy(createtime, "in the distant future");
446 if (marker->cm_canceltime) {
447 /* Like cm_createtime, we try to handle overflow of
448 * 32-bit time_t gracefully. The copy to time_tmp
449 * is also needed on 64-bit systems to keep the
450 * pointer happy, see bug 16771 */
451 time_tmp = marker->cm_canceltime;
452 if (time_tmp == marker->cm_canceltime) {
453 ctime_r(&time_tmp, canceltime);
454 canceltime[strlen(canceltime) - 1] = 0;
456 strcpy(canceltime, "in the distant future");
460 printf("marker %3d (flags=%#04x, v%d.%d.%d.%d) %-15s '%s' %s-%s",
461 marker->cm_step, marker->cm_flags,
462 OBD_OCD_VERSION_MAJOR(marker->cm_vers),
463 OBD_OCD_VERSION_MINOR(marker->cm_vers),
464 OBD_OCD_VERSION_PATCH(marker->cm_vers),
465 OBD_OCD_VERSION_FIX(marker->cm_vers),
466 marker->cm_tgtname, marker->cm_comment,
467 createtime, canceltime);
470 case(LCFG_POOL_NEW):{
475 case(LCFG_POOL_ADD):{
480 case(LCFG_POOL_REM):{
481 printf("pool remove ");
485 case(LCFG_POOL_DEL):{
486 printf("pool destroy ");
491 printf("unsupported cmd_code = %x\n",cmd);
497 static void print_logid(struct llog_logid_rec *lid)
499 printf("ogen=%X name="DOSTID"\n",
500 lid->lid_id.lgl_ogen,
501 POSTID(&lid->lid_id.lgl_oi));
504 static void print_hsm_action(struct llog_agent_req_rec *larr)
509 sz = larr->arr_hai.hai_len - sizeof(larr->arr_hai);
510 printf("lrh=[type=%X len=%d idx=%d] fid="DFID
511 " compound/cookie="LPX64"/"LPX64
512 " status=%s action=%s archive#=%d flags="LPX64
513 " create="LPU64" change="LPU64
514 " extent="LPX64"-"LPX64" gid="LPX64" datalen=%d"
516 larr->arr_hdr.lrh_type,
517 larr->arr_hdr.lrh_len, larr->arr_hdr.lrh_index,
518 PFID(&larr->arr_hai.hai_fid),
519 larr->arr_compound_id, larr->arr_hai.hai_cookie,
520 agent_req_status2name(larr->arr_status),
521 hsm_copytool_action2name(larr->arr_hai.hai_action),
522 larr->arr_archive_id,
524 larr->arr_req_create, larr->arr_req_change,
525 larr->arr_hai.hai_extent.offset,
526 larr->arr_hai.hai_extent.length,
527 larr->arr_hai.hai_gid, sz,
528 hai_dump_data_field(&larr->arr_hai, buf, sizeof(buf)));
531 void print_records(struct llog_rec_hdr **recs, int rec_number)
536 for (i = 0; i < rec_number; i++) {
537 printf("#%.2d (%.3d)", le32_to_cpu(recs[i]->lrh_index),
538 le32_to_cpu(recs[i]->lrh_len));
540 lopt = le32_to_cpu(recs[i]->lrh_type);
542 if (recs[i]->lrh_id == CANCELLED)
548 (struct lustre_cfg *)((char *)(recs[i]) +
549 sizeof(struct llog_rec_hdr)), &skip);
554 case LLOG_LOGID_MAGIC:
555 print_logid((struct llog_logid_rec *)recs[i]);
558 print_hsm_action((struct llog_agent_req_rec *)recs[i]);
561 printf("unknown type %x\n", lopt);