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>
46 #include <libcfs/libcfs.h>
47 #include <lnet/nidstr.h>
48 #include <lustre/lustre_idl.h>
49 #include <lustre/lustreapi.h>
50 #include <lustre_cfg.h>
52 static inline int ext2_test_bit(int nr, const void *addr)
54 #if __BYTE_ORDER == __BIG_ENDIAN
55 const unsigned char *tmp = addr;
56 return (tmp[nr >> 3] >> (nr & 7)) & 1;
58 return test_bit(nr, addr);
62 int llog_pack_buffer(int fd, struct llog_log_hdr **llog_buf,
63 struct llog_rec_hdr ***recs, int *recs_number);
65 void print_llog_header(struct llog_log_hdr *llog_buf);
66 void print_records(struct llog_rec_hdr **recs_buf,int rec_number);
67 void llog_unpack_buffer(int fd, struct llog_log_hdr *llog_buf,
68 struct llog_rec_hdr **recs_buf);
70 #define CANCELLED 0x678
72 #define PTL_CMD_BASE 100
73 char* portals_command[17]=
94 int main(int argc, char **argv)
98 struct llog_log_hdr *llog_buf = NULL;
99 struct llog_rec_hdr **recs_buf = NULL;
104 printf("Usage: llog_reader filename\n");
108 fd = open(argv[1],O_RDONLY);
111 llapi_error(LLAPI_MSG_ERROR, rc, "Could not open the file %s.",
115 rc = llog_pack_buffer(fd, &llog_buf, &recs_buf, &rec_number);
117 llapi_error(LLAPI_MSG_ERROR, rc, "Could not pack buffer.");
121 print_llog_header(llog_buf);
122 print_records(recs_buf,rec_number);
123 llog_unpack_buffer(fd,llog_buf,recs_buf);
132 int llog_pack_buffer(int fd, struct llog_log_hdr **llog,
133 struct llog_rec_hdr ***recs,
136 int rc = 0, recs_num,rd;
139 char *file_buf=NULL, *recs_buf=NULL;
140 struct llog_rec_hdr **recs_pr=NULL;
147 llapi_error(LLAPI_MSG_ERROR, rc, "Got file stat error.");
150 file_size = st.st_size;
151 if (file_size == 0) {
153 llapi_error(LLAPI_MSG_ERROR, rc, "File is empty.");
157 file_buf = malloc(file_size);
158 if (file_buf == NULL){
160 llapi_error(LLAPI_MSG_ERROR, rc, "Memory Alloc for file_buf.");
163 *llog = (struct llog_log_hdr*)file_buf;
165 rd = read(fd,file_buf,file_size);
168 llapi_error(LLAPI_MSG_ERROR, rc, "Read file error.");
172 /* the llog header not countable here.*/
173 recs_num = le32_to_cpu((*llog)->llh_count)-1;
175 recs_buf = malloc(recs_num * sizeof(struct llog_rec_hdr *));
176 if (recs_buf == NULL){
178 llapi_error(LLAPI_MSG_ERROR, rc, "Memory Alloc for recs_buf.");
181 recs_pr = (struct llog_rec_hdr **)recs_buf;
183 ptr = file_buf + le32_to_cpu((*llog)->llh_hdr.lrh_len);
186 while (i < recs_num){
187 struct llog_rec_hdr *cur_rec;
190 if (ptr + sizeof(struct llog_rec_hdr) >
191 file_buf + file_size) {
193 llapi_error(LLAPI_MSG_ERROR, rc,
194 "The log is corrupt (too big at %d)", i);
198 cur_rec = (struct llog_rec_hdr *)ptr;
199 idx = le32_to_cpu(cur_rec->lrh_index);
200 recs_pr[i] = cur_rec;
202 if (ext2_test_bit(idx, (*llog)->llh_bitmap)) {
203 if (le32_to_cpu(cur_rec->lrh_type) != OBD_CFG_REC)
204 printf("rec #%d type=%x len=%u\n", idx,
205 cur_rec->lrh_type, cur_rec->lrh_len);
207 printf("Bit %d of %d not set\n", idx, recs_num);
208 cur_rec->lrh_id = CANCELLED;
209 /* The header counts only set records */
213 ptr += le32_to_cpu(cur_rec->lrh_len);
214 if ((ptr - file_buf) > file_size) {
215 printf("The log is corrupt (too big at %d)\n", i);
223 *recs_number = recs_num;
238 void llog_unpack_buffer(int fd, struct llog_log_hdr *llog_buf,
239 struct llog_rec_hdr **recs_buf)
246 void print_llog_header(struct llog_log_hdr *llog_buf)
250 printf("Header size : %u\n",
251 le32_to_cpu(llog_buf->llh_hdr.lrh_len));
253 t = le64_to_cpu(llog_buf->llh_timestamp);
254 printf("Time : %s", ctime(&t));
256 printf("Number of records: %u\n",
257 le32_to_cpu(llog_buf->llh_count)-1);
259 printf("Target uuid : %s \n",
260 (char *)(&llog_buf->llh_tgtuuid));
262 /* Add the other info you want to view here */
264 printf("-----------------------\n");
268 static void print_1_cfg(struct lustre_cfg *lcfg)
273 printf("nid=%s("LPX64") ", libcfs_nid2str(lcfg->lcfg_nid),
276 printf("nal=%d ", lcfg->lcfg_nal);
277 for (i = 0; i < lcfg->lcfg_bufcount; i++)
278 printf("%d:%.*s ", i, lcfg->lcfg_buflens[i],
279 (char*)lustre_cfg_buf(lcfg, i));
284 static void print_setup_cfg(struct lustre_cfg *lcfg)
286 struct lov_desc *desc;
288 if ((lcfg->lcfg_bufcount == 2) &&
289 (lcfg->lcfg_buflens[1] == sizeof(*desc))) {
290 printf("lov_setup ");
291 printf("0:%s ", lustre_cfg_string(lcfg, 0));
292 printf("1:(struct lov_desc)\n");
293 desc = (struct lov_desc*)(lustre_cfg_string(lcfg, 1));
294 printf("\t\tuuid=%s ", (char*)desc->ld_uuid.uuid);
295 printf("stripe:cnt=%u ", desc->ld_default_stripe_count);
296 printf("size="LPU64" ", desc->ld_default_stripe_size);
297 printf("offset="LPU64" ", desc->ld_default_stripe_offset);
298 printf("pattern=%#x", desc->ld_pattern);
307 void print_lustre_cfg(struct lustre_cfg *lcfg, int *skip)
309 enum lcfg_command_type cmd = le32_to_cpu(lcfg->lcfg_command);
321 print_setup_cfg(lcfg);
334 case(LCFG_ADD_UUID):{
339 case(LCFG_DEL_UUID):{
344 case(LCFG_ADD_CONN):{
349 case(LCFG_DEL_CONN):{
354 case(LCFG_LOV_ADD_OBD):{
355 printf("lov_modify_tgts add ");
359 case(LCFG_LOV_DEL_OBD):{
360 printf("lov_modify_tgts del ");
365 printf("modify_mdc_tgts add ");
370 printf("modify_mdc_tgts del ");
374 case(LCFG_MOUNTOPT):{
375 printf("mount_option ");
379 case(LCFG_DEL_MOUNTOPT):{
380 printf("del_mount_option ");
384 case(LCFG_SET_TIMEOUT):{
385 printf("set_timeout=%d ", lcfg->lcfg_num);
388 case(LCFG_SET_LDLM_TIMEOUT):{
389 printf("set_ldlm_timeout=%d ", lcfg->lcfg_num);
392 case(LCFG_SET_UPCALL):{
393 printf("set_lustre_upcall ");
402 case(LCFG_SET_PARAM):{
403 printf("set_param ");
407 case(LCFG_SPTLRPC_CONF):{
408 printf("sptlrpc_conf ");
413 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
414 char createtime[26], canceltime[26] = "";
417 if (marker->cm_flags & CM_SKIP) {
418 if (marker->cm_flags & CM_START) {
419 printf("SKIP START ");
427 if (marker->cm_flags & CM_EXCLUDE) {
428 if (marker->cm_flags & CM_START)
429 printf("EXCLUDE START ");
431 printf("EXCLUDE END ");
434 /* Handle overflow of 32-bit time_t gracefully.
435 * The copy to time_tmp is needed in any case to
436 * keep the pointer happy, even on 64-bit systems. */
437 time_tmp = marker->cm_createtime;
438 if (time_tmp == marker->cm_createtime) {
439 ctime_r(&time_tmp, createtime);
440 createtime[strlen(createtime) - 1] = 0;
442 strcpy(createtime, "in the distant future");
445 if (marker->cm_canceltime) {
446 /* Like cm_createtime, we try to handle overflow of
447 * 32-bit time_t gracefully. The copy to time_tmp
448 * is also needed on 64-bit systems to keep the
449 * pointer happy, see bug 16771 */
450 time_tmp = marker->cm_canceltime;
451 if (time_tmp == marker->cm_canceltime) {
452 ctime_r(&time_tmp, canceltime);
453 canceltime[strlen(canceltime) - 1] = 0;
455 strcpy(canceltime, "in the distant future");
459 printf("marker %3d (flags=%#04x, v%d.%d.%d.%d) %-15s '%s' %s-%s",
460 marker->cm_step, marker->cm_flags,
461 OBD_OCD_VERSION_MAJOR(marker->cm_vers),
462 OBD_OCD_VERSION_MINOR(marker->cm_vers),
463 OBD_OCD_VERSION_PATCH(marker->cm_vers),
464 OBD_OCD_VERSION_FIX(marker->cm_vers),
465 marker->cm_tgtname, marker->cm_comment,
466 createtime, canceltime);
469 case(LCFG_POOL_NEW):{
474 case(LCFG_POOL_ADD):{
479 case(LCFG_POOL_REM):{
480 printf("pool remove ");
484 case(LCFG_POOL_DEL):{
485 printf("pool destroy ");
490 printf("unsupported cmd_code = %x\n",cmd);
496 static void print_logid(struct llog_logid_rec *lid)
498 printf("ogen=%X name="DOSTID"\n",
499 lid->lid_id.lgl_ogen,
500 POSTID(&lid->lid_id.lgl_oi));
503 static void print_hsm_action(struct llog_agent_req_rec *larr)
508 sz = larr->arr_hai.hai_len - sizeof(larr->arr_hai);
509 printf("lrh=[type=%X len=%d idx=%d] fid="DFID
510 " compound/cookie="LPX64"/"LPX64
511 " status=%s action=%s archive#=%d flags="LPX64
512 " create="LPU64" change="LPU64
513 " extent="LPX64"-"LPX64" gid="LPX64" datalen=%d"
515 larr->arr_hdr.lrh_type,
516 larr->arr_hdr.lrh_len, larr->arr_hdr.lrh_index,
517 PFID(&larr->arr_hai.hai_fid),
518 larr->arr_compound_id, larr->arr_hai.hai_cookie,
519 agent_req_status2name(larr->arr_status),
520 hsm_copytool_action2name(larr->arr_hai.hai_action),
521 larr->arr_archive_id,
523 larr->arr_req_create, larr->arr_req_change,
524 larr->arr_hai.hai_extent.offset,
525 larr->arr_hai.hai_extent.length,
526 larr->arr_hai.hai_gid, sz,
527 hai_dump_data_field(&larr->arr_hai, buf, sizeof(buf)));
530 void print_records(struct llog_rec_hdr **recs, int rec_number)
535 for (i = 0; i < rec_number; i++) {
536 printf("#%.2d (%.3d)", le32_to_cpu(recs[i]->lrh_index),
537 le32_to_cpu(recs[i]->lrh_len));
539 lopt = le32_to_cpu(recs[i]->lrh_type);
541 if (recs[i]->lrh_id == CANCELLED)
547 (struct lustre_cfg *)((char *)(recs[i]) +
548 sizeof(struct llog_rec_hdr)), &skip);
553 case LLOG_LOGID_MAGIC:
554 print_logid((struct llog_logid_rec *)recs[i]);
557 print_hsm_action((struct llog_agent_req_rec *)recs[i]);
560 printf("unknown type %x\n", lopt);