1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include <sys/types.h>
30 #include <liblustre.h>
31 #include <linux/lustre_idl.h>
33 int llog_pack_buffer(int fd, struct llog_log_hdr** llog_buf, struct llog_rec_hdr*** recs, int* recs_number);
35 void print_llog_header(struct llog_log_hdr* llog_buf);
36 void print_records(struct llog_rec_hdr** recs_buf,int rec_number);
37 void llog_unpack_buffer(int fd,struct llog_log_hdr* llog_buf,struct llog_rec_hdr** recs_buf);
39 #define PTL_CMD_BASE 100
40 char* portals_command[17]=
61 int main(int argc, char **argv)
66 struct llog_log_hdr* llog_buf=NULL;
67 struct llog_rec_hdr** recs_buf=NULL;
73 printf("Usage: llog_reader filename \n");
77 fd = open(argv[1],O_RDONLY);
79 printf("Could not open the file %s \n",argv[1]);
82 rc = llog_pack_buffer(fd, &llog_buf, &recs_buf, &rec_number);
86 print_llog_header(llog_buf);
88 print_records(recs_buf,rec_number);
90 llog_unpack_buffer(fd,llog_buf,recs_buf);
98 int llog_pack_buffer(int fd, struct llog_log_hdr** llog,
99 struct llog_rec_hdr*** recs,
102 int rc=0,recs_num,rd;
105 char *file_buf=NULL, *recs_buf=NULL;
106 struct llog_rec_hdr** recs_pr=NULL;
112 printf("Get file stat error.\n");
115 file_size = st.st_size;
117 file_buf = malloc(file_size);
118 if (file_buf == NULL){
119 printf("Memory Alloc for file_buf error.\n");
123 *llog = (struct llog_log_hdr*)file_buf;
125 rd = read(fd,file_buf,file_size);
127 printf("Read file error.\n");
132 /* the llog header not countable here.*/
133 recs_num = le32_to_cpu((*llog)->llh_count)-1;
135 recs_buf = malloc(recs_num*sizeof(struct llog_rec_hdr*));
136 if (recs_buf == NULL){
137 printf("Memory Alloc for recs_buf error.\n");
141 recs_pr = (struct llog_rec_hdr **)recs_buf;
143 ptr = file_buf + le32_to_cpu((*llog)->llh_hdr.lrh_len);
146 while (i < recs_num){
147 struct llog_rec_hdr* cur_rec=(struct llog_rec_hdr*)ptr;
149 while(!ext2_test_bit(cur_idx,(*llog)->llh_bitmap)){
151 ptr += cur_rec->lrh_len;
152 if ((ptr-file_buf) > file_size){
153 printf("The log is corrupted. \n");
158 recs_pr[i] = cur_rec;
159 ptr+=cur_rec->lrh_len;
165 *recs_number=recs_num;
182 void llog_unpack_buffer(int fd,struct llog_log_hdr* llog_buf,struct llog_rec_hdr **recs_buf)
190 void print_llog_header(struct llog_log_hdr* llog_buf)
194 printf("Header size : %d \n",
195 // le32_to_cpu(llog_buf->llh_hdr.lrh_len));
196 llog_buf->llh_hdr.lrh_len);
198 t = le64_to_cpu(llog_buf->llh_timestamp);
199 printf("Time : %s", ctime(&t));
201 printf("Number of records: %d\n",
202 le32_to_cpu(llog_buf->llh_count)-1);
204 printf("Target uuid : %s \n",
205 (char *)(&llog_buf->llh_tgtuuid));
207 /* Add the other infor you want to view here*/
209 printf("-----------------------\n");
213 static void print_1_cfg(struct lustre_cfg *lcfg)
216 for (i = 0; i < lcfg->lcfg_bufcount; i++)
217 printf("%d:%s ", i, lustre_cfg_string(lcfg, i));
221 void print_lustre_cfg(struct lustre_cfg *lcfg)
223 enum lcfg_command_type cmd = le32_to_cpu(lcfg->lcfg_command);
246 case(LCFG_ADD_UUID):{
248 printf("nid=%x ", (unsigned int)lcfg->lcfg_nid);
249 printf("nal_type=%d ", lcfg->lcfg_nal);
253 case(LCFG_DEL_UUID):{
258 case(LCFG_ADD_CONN):{
263 case(LCFG_DEL_CONN):{
268 case(LCFG_LOV_ADD_OBD):{
269 printf("lov_modify_tgts add ");
273 case(LCFG_LOV_DEL_OBD):{
274 printf("lov_modify_tgts del ");
278 case(LCFG_MOUNTOPT):{
279 printf("mount_option ");
283 case(LCFG_DEL_MOUNTOPT):{
284 printf("del_mount_option ");
288 case(LCFG_SET_TIMEOUT):{
289 printf("set_timeout=%d ", lcfg->lcfg_num);
293 case(LCFG_SET_UPCALL):{
294 printf("set_lustre_upcall ");
299 printf("unsupported cmd_code = %x\n",cmd);
305 void print_records(struct llog_rec_hdr** recs,int rec_number)
310 for(i=0;i<rec_number;i++){
312 printf("#%.2d ", le32_to_cpu(recs[i]->lrh_index));
314 lopt = le32_to_cpu(recs[i]->lrh_type);
316 if (lopt == OBD_CFG_REC){
317 struct lustre_cfg *lcfg;
319 lcfg = (struct lustre_cfg *)
320 ((char*)(recs[i]) + sizeof(struct llog_rec_hdr));
321 print_lustre_cfg(lcfg);
324 if (lopt == PTL_CFG_REC){
325 printf("Portals - unknown type\n");