File: dminfo.c

package info (click to toggle)
crash 7.0.8-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 36,348 kB
  • ctags: 13,100
  • sloc: ansic: 135,839; makefile: 495
file content (1533 lines) | stat: -rw-r--r-- 42,557 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
/* dminfo.c - crash extension module for device-mapper analysis
 *
 * Copyright (C) 2005 NEC Corporation
 * Copyright (C) 2005 Red Hat, Inc. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#include "defs.h"		/* From the crash source top-level directory */

void dminfo_init(void);
void dminfo_fini(void);

/*
 * Indices of size-offset array (Used by GET_xxx macros)
 *
 * DM_<struct name>_<member name>
 */
enum {
	DM_hash_cell_name_list = 0,
	DM_hash_cell_name,
	DM_hash_cell_md,

	DM_mapped_device_disk,
	DM_mapped_device_map,

	DM_gendisk_major,
	DM_gendisk_first_minor,
	DM_gendisk_disk_name,

	DM_dm_table_num_targets,
	DM_dm_table_targets,
	DM_dm_table_devices,

	DM_dm_target_type,
	DM_dm_target_begin,
	DM_dm_target_len,
	DM_dm_target_private,

	DM_dm_dev_count,
	DM_dm_dev_bdev,
	DM_dm_dev_name,

	DM_dm_io_md,
	DM_dm_io_bio,

	DM_target_type_name,

	DM_target_io_io,

	DM_block_device_bd_disk,

	DM_bio_bi_private,

	DM_bio_list_head,

	DM_linear_c_dev,
	DM_linear_c_start,

	DM_multipath_hw_handler,
	DM_multipath_nr_priority_groups,
	DM_multipath_priority_groups,
	DM_multipath_nr_valid_paths,
	DM_multipath_current_pg,
	DM_multipath_queue_if_no_path,
	DM_multipath_queue_size,

	DM_hw_handler_type,
	DM_hw_handler_type_name,

	DM_priority_group_ps,
	DM_priority_group_pg_num,
	DM_priority_group_bypassed,
	DM_priority_group_nr_pgpaths,
	DM_priority_group_pgpaths,

	DM_path_selector_type,
	DM_path_selector_type_name,

	DM_pgpath_fail_count,
	DM_pgpath_path,

	DM_path_dev,
	DM_path_is_active,

	DM_mirror_set_rh,
	DM_mirror_set_reads,
	DM_mirror_set_writes,
	DM_mirror_set_in_sync,
	DM_mirror_set_nr_mirrors,
	DM_mirror_set_mirror,

	DM_region_hash_log,
	DM_region_hash_quiesced_regions,
	DM_region_hash_recovered_regions,

	DM_dirty_log_type,
	DM_dirty_log_type_name,

	DM_mirror_error_count,
	DM_mirror_dev,
	DM_mirror_offset,

	DM_crypt_config_dev,
	DM_crypt_config_iv_mode,
	DM_crypt_config_tfm,
	DM_crypt_config_key_size,
	DM_crypt_config_key,

	DM_crypto_tfm_crt_u,
	DM_crypto_tfm___crt_alg,

	DM_crypto_alg_cra_name,

	DM_cipher_tfm_cit_mode,

	DM_stripe_c_stripes,
	DM_stripe_c_chunk_mask,
	DM_stripe_c_stripe,

	DM_stripe_dev,

	DM_dm_snapshot_origin,
	DM_dm_snapshot_cow,
	DM_dm_snapshot_chunk_size,
	DM_dm_snapshot_valid,
	DM_dm_snapshot_type,

	NR_DMINFO_MEMBER_TABLE_ENTRY
};

/* Size-offset array for structure's member */
static struct dminfo_member_entry {
	unsigned long offset;
	unsigned long size;
} mbr_ary[NR_DMINFO_MEMBER_TABLE_ENTRY];

/*
 * Macros to retrieve data of given structure's member
 *
 * Macros except for the MSG assume 'struct s' is at 'addr'
 */
#define MSG(msg, s, m) msg ": " s "." m

/* Initialize the size-offset array */
#define INIT_MBR_TABLE(s, m) \
	do { \
		if (!mbr_ary[DM_##s##_##m].size) { \
			mbr_ary[DM_##s##_##m].offset = MEMBER_OFFSET("struct " #s, #m); \
			mbr_ary[DM_##s##_##m].size   = MEMBER_SIZE("struct " #s, #m); \
		} \
	} while (0)

/*
 * Store the data of member m in ret.
 * Initialize the size-offset array for the member m if needed.
 */
#define GET_VALUE(addr, s, m, ret) \
	do { \
		INIT_MBR_TABLE(s, m); \
		if (sizeof(ret) < mbr_ary[DM_##s##_##m].size) \
			fprintf(fp, "%s\n", \
				MSG("ERROR: GET_VALUE size_check", #s, #m)); \
		readmem(addr + mbr_ary[DM_##s##_##m].offset, KVADDR, &ret, \
			mbr_ary[DM_##s##_##m].size, MSG("GET_VALUE", #s, #m), \
			FAULT_ON_ERROR);\
	} while (0)

/*
 * Store the address of member m in ret.
 * Initialize the size-offset array for the member m if needed.
 */
#define GET_ADDR(addr, s, m, ret) \
	do { \
		INIT_MBR_TABLE(s, m); \
		ret = addr + mbr_ary[DM_##s##_##m].offset; \
	} while (0)

/*
 * Store the string data of member m in ret.
 * Initialize the size-offset array for the member m if needed.
 */
#define GET_STR(addr, s, m, ret, len) \
	do { \
		INIT_MBR_TABLE(s, m); \
		if (!read_string(addr + mbr_ary[DM_##s##_##m].offset, ret, len - 1)) \
			fprintf(fp, "%s\n", MSG("ERROR: GET_STR", #s, #m)); \
	} while (0)

/*
 * Store the string data pointed by member m in ret.
 * Initialize the size-offset array for the member m if needed.
 */
#define GET_PTR_STR(addr, s, m, ret, len) \
	do { \
		unsigned long tmp; \
		INIT_MBR_TABLE(s, m); \
		readmem(addr + mbr_ary[DM_##s##_##m].offset, KVADDR, &tmp, \
			mbr_ary[DM_##s##_##m].size, MSG("GET_PTR_STR", #s, #m),\
			FAULT_ON_ERROR);\
		if (!read_string(tmp, ret, len - 1)) \
			fprintf(fp, "%s\n", MSG("ERROR: GET_PTR_STR", #s, #m));\
	} while (0)

/*
 * Utility function/macro to walk the list
 */
static unsigned long
get_next_from_list_head(unsigned long addr)
{
	unsigned long ret;

	readmem(addr + OFFSET(list_head_next), KVADDR, &ret, sizeof(void *),
		MSG("get_next_from_list_head", "list_head", "next"),
		FAULT_ON_ERROR);

	return ret;
}

#define list_for_each(next, head, last) \
	for (next = get_next_from_list_head(head), last = 0UL; \
		next && next != head && next != last; \
		last = next, next = get_next_from_list_head(next))

/*
 * device-mapper target analyzer
 *
 * device-mapper has various target driver: linear, mirror, multipath, etc.
 * Information specific to target is stored in its own way.
 * Target-specific analyzer is provided for each target driver for this reason.
 */
static struct dminfo_target_analyzer {
	struct dminfo_target_analyzer *next;
	char *target_name;
	int (*ready) (void);	/* returns true if analyzer is available */
	void (*show_table) (unsigned long);  /* display table info */
	void (*show_status) (unsigned long); /* display status info */
	void (*show_queue) (unsigned long);  /* display queued I/O info */
} analyzers_head;

static void
dminfo_register_target_analyzer(struct dminfo_target_analyzer *ta)
{
	ta->next = analyzers_head.next;
	analyzers_head.next = ta;
}

static struct
dminfo_target_analyzer *find_target_analyzer(char *target_type)
{
	struct dminfo_target_analyzer *ta;

	for (ta = analyzers_head.next; ta; ta = ta->next)
		if (!strcmp(ta->target_name, target_type))
			return ta;

	return NULL;
}

/*
 * zero target
 */
static int
zero_ready(void)
{
	return 1;
}

static void
zero_show_table(unsigned long target)
{
	unsigned long long start, len;

	/* Get target information */
	GET_VALUE(target, dm_target, begin, start);
	GET_VALUE(target, dm_target, len, len);

	fprintf(fp, "  begin:%llu len:%llu", start, len);
}

static void
zero_show_status(unsigned long target)
{
	/* zero target has no status */
	fprintf(fp, "  No status info");
}

static void
zero_show_queue(unsigned long target)
{
	/* zero target has no queue */
	fprintf(fp, "  No queue info");
}

static struct dminfo_target_analyzer zero_analyzer = {
	.target_name      = "zero",
	.ready            = zero_ready,
	.show_table       = zero_show_table,
	.show_status      = zero_show_status,
	.show_queue       = zero_show_queue
};

/*
 * error target
 */
static int
error_ready(void)
{
	return 1;
}

static void
error_show_table(unsigned long target)
{
	unsigned long long start, len;

	/* Get target information */
	GET_VALUE(target, dm_target, begin, start);
	GET_VALUE(target, dm_target, len, len);

	fprintf(fp, "  begin:%llu len:%llu", start, len);
}

static void
error_show_status(unsigned long target)
{
	/* error target has no status */
	fprintf(fp, "  No status info");
}

static void
error_show_queue(unsigned long target)
{
	/* error target has no queue */
	fprintf(fp, "  No queue info");
}

static struct dminfo_target_analyzer error_analyzer = {
	.target_name      = "error",
	.ready            = error_ready,
	.show_table       = error_show_table,
	.show_status      = error_show_status,
	.show_queue       = error_show_queue
};

/*
 * linear target
 */
static int
linear_ready(void)
{
	static int debuginfo = 0;

	if (debuginfo)
		return 1;

	if (STRUCT_EXISTS("struct linear_c")) {
		debuginfo = 1;
		return 1;
	} else
		fprintf(fp, "No such struct info: linear_c");

	return 0;
}

static void
linear_show_table(unsigned long target)
{
	unsigned long lc, dm_dev;
	unsigned long long start, len, offset;
	char devt[BUFSIZE];

	/* Get target information */
	GET_VALUE(target, dm_target, begin, start);
	GET_VALUE(target, dm_target, len, len);
	GET_VALUE(target, dm_target, private, lc);
	GET_VALUE(lc, linear_c, dev, dm_dev);
	GET_STR(dm_dev, dm_dev, name, devt, BUFSIZE);
	GET_VALUE(lc, linear_c, start, offset);

	fprintf(fp, "  begin:%llu len:%llu dev:%s offset:%llu",
		start, len, devt, offset);
}

static void
linear_show_status(unsigned long target)
{
	/* linear target has no status */
	fprintf(fp, "  No status info");
}

static void
linear_show_queue(unsigned long target)
{
	/* linear target has no I/O queue */
	fprintf(fp, "  No queue info");
}

static struct dminfo_target_analyzer linear_analyzer = {
	.target_name      = "linear",
	.ready            = linear_ready,
	.show_table       = linear_show_table,
	.show_status      = linear_show_status,
	.show_queue       = linear_show_queue
};

/*
 * mirror target
 */
static int
mirror_ready(void)
{
	static int debuginfo = 0;

	if (debuginfo)
		return 1;

	if (STRUCT_EXISTS("struct mirror_set")) {
		debuginfo = 1;
		return 1;
	} else
		fprintf(fp, "No such struct info: mirror_set");

	return 0;
}

static void
mirror_show_table(unsigned long target)
{
	unsigned int i, nr_mir;
	unsigned long ms, rh, log, log_type, mir_size, mir_head, mir, dm_dev;
	unsigned long long offset;
	char buf[BUFSIZE];

	/* Get the address of struct mirror_set */
	GET_VALUE(target, dm_target, private, ms);

	/* Get the log-type name of the mirror_set */
	GET_ADDR(ms, mirror_set, rh, rh);
	GET_VALUE(rh, region_hash, log, log);
	GET_VALUE(log, dirty_log, type, log_type);
	GET_PTR_STR(log_type, dirty_log_type, name, buf, BUFSIZE);
	fprintf(fp, "  log:%s", buf);

	/*
	 * Display information for each mirror disks.
	 *
	 * mir_head = mirror_set.mirror.
	 * This is the head of struct mirror array.
	 */
	fprintf(fp, " dev:");
	mir_size = STRUCT_SIZE("struct mirror");
	GET_ADDR(ms, mirror_set, mirror, mir_head);
	GET_VALUE(ms, mirror_set, nr_mirrors, nr_mir);
	for (i = 0; i < nr_mir; i++) {
		mir = mir_head + mir_size * i; /* Get next mirror */

		/* Get the devt of the mirror disk */
		GET_VALUE(mir, mirror, dev, dm_dev);
		GET_STR(dm_dev, dm_dev, name, buf, BUFSIZE);

		/* Get the offset of the mirror disk */
		GET_VALUE(mir, mirror, offset, offset);

		fprintf(fp, "%s(%llu)%s", buf, offset,
			i == nr_mir - 1 ? "" : ",");
	}
	if (i != nr_mir)
		fprintf(fp, " ERROR: dev are less than nr_mir:%d", nr_mir);
}

static void
mirror_show_status(unsigned long target)
{
	unsigned int i, nr_mir, synced, nr_error;
	unsigned long ms, mir_size, mir_head, mir, dm_dev;
	char buf[BUFSIZE];

	/* Get the address of struct mirror_set */
	GET_VALUE(target, dm_target, private, ms);

	/* Get the status info of the mirror_set */
	GET_VALUE(ms, mirror_set, in_sync, synced);
	fprintf(fp, "  in_sync:%d", synced);

	/*
	 * Display information for each mirror disks.
	 *
	 * mir_head = mirror_set.mirror.
	 * This is the head of struct mirror array.
	 */
	fprintf(fp, " dev:");
	mir_size = STRUCT_SIZE("struct mirror");
	GET_ADDR(ms, mirror_set, mirror, mir_head);
	GET_VALUE(ms, mirror_set, nr_mirrors, nr_mir);
	for (i = 0; i < nr_mir; i++) {
		mir = mir_head + mir_size * i; /* Get next mirror */

		/* Get the devt of the mirror disk */
		GET_VALUE(mir, mirror, dev, dm_dev);
		GET_STR(dm_dev, dm_dev, name, buf, BUFSIZE);

		/* Get the offset of the mirror disk */
		GET_VALUE(mir, mirror, error_count, nr_error);

		fprintf(fp, "%s(%c,%d)%s", buf, nr_error ? 'D' : 'A', nr_error,
			i == nr_mir - 1 ? "" : ",");
	}
	if (i != nr_mir)
		fprintf(fp, " ERROR: dev are less than nr_mir:%d", nr_mir);
}

static void
mirror_show_queue(unsigned long target)
{
	unsigned long ms, rlist, wlist, rhead, whead;
	unsigned long rh, quis_head, rcov_head, quis_next, rcov_next;

	/* Get the address of struct mirror_set */
	GET_VALUE(target, dm_target, private, ms);

	/* Get the address of queued I/O lists in struct mirror_set */
	GET_ADDR(ms, mirror_set, reads, rlist);
	GET_ADDR(ms, mirror_set, writes, wlist);

	/* Get the head of queued I/O lists */
	GET_VALUE(rlist, bio_list, head, rhead);
	GET_VALUE(wlist, bio_list, head, whead);
	fprintf(fp, "  %s", rhead ? "reads" : "(reads)");
	fprintf(fp, " %s", whead ? "writes" : "(writes)");

	/* Get the address of the struct region_hash */
	GET_ADDR(ms, mirror_set, rh, rh);

	/* Get the address of recover region lists in struct region_hash */
	GET_ADDR(rh, region_hash, quiesced_regions, quis_head);
	GET_ADDR(rh, region_hash, recovered_regions, rcov_head);

	/* Get the head of recover region lists */
	quis_next = get_next_from_list_head(quis_head);
	rcov_next = get_next_from_list_head(rcov_head);

	fprintf(fp, " %s", quis_next != quis_head ? "quiesced" : "(quiesced)");
	fprintf(fp, " %s", rcov_next != rcov_head ? "recovered" : "(recovered)");
}

static struct dminfo_target_analyzer mirror_analyzer = {
	.target_name      = "mirror",
	.ready            = mirror_ready,
	.show_table       = mirror_show_table,
	.show_status      = mirror_show_status,
	.show_queue       = mirror_show_queue
};

/*
 * multipath target
 */
static int
multipath_ready(void)
{
	static int debuginfo = 0;

	if (debuginfo)
		return 1;

	if (STRUCT_EXISTS("struct multipath")) {
		debuginfo = 1;
		return 1;
	} else
		fprintf(fp, "No such struct info: multipath");

	return 0;
}

static void
multipath_show_table(unsigned long target)
{
	int i, j;
	unsigned int queue_if_no_path, nr_pgs, pg_id, nr_paths;
	unsigned long mp, hwh, hwh_type, ps, ps_type, path, dm_dev;
	unsigned long pg_head, pg_next, pg_last;
	unsigned long path_head, path_next, path_last;
	char name[BUFSIZE];

	/* Get the address of struct multipath */
	GET_VALUE(target, dm_target, private, mp);

	/* Get features information */
	GET_VALUE(mp, multipath, queue_if_no_path, queue_if_no_path);

	/* Get the hardware-handler information */
	GET_ADDR(mp, multipath, hw_handler, hwh);
	GET_VALUE(hwh, hw_handler, type, hwh_type);
	if (hwh_type)
		GET_PTR_STR(hwh_type, hw_handler_type, name, name, BUFSIZE);
	else
		strcpy(name, "none");

	/* Get the number of priority groups */
	GET_VALUE(mp, multipath, nr_priority_groups, nr_pgs);

	fprintf(fp, "  queue_if_no_path:%d hwh:%s nr_pgs:%d\n",
		queue_if_no_path, name, nr_pgs);

	/* Display information for each priority group */
	fprintf(fp, "    %-2s  %-13s  %-8s  %s",
		"PG", "PATH_SELECTOR", "NR_PATHS", "PATHS");
	GET_ADDR(mp, multipath, priority_groups, pg_head);
	i = 0;
	list_for_each (pg_next, pg_head, pg_last) {
		/* pg_next == struct priority_group */

		/* Get the index of the priority group */
		GET_VALUE(pg_next, priority_group, pg_num, pg_id);

		/* Get the name of path selector */
		GET_ADDR(pg_next, priority_group, ps, ps);
		GET_VALUE(ps, path_selector, type, ps_type);
		GET_PTR_STR(ps_type, path_selector_type, name, name, BUFSIZE);

		/* Get the number of paths in the priority group */
		GET_VALUE(pg_next, priority_group, nr_pgpaths, nr_paths);

		fprintf(fp, "\n    %-2d  %-13s  %-8d ", pg_id, name, nr_paths);

		/* Display information for each path */
		GET_ADDR(pg_next, priority_group, pgpaths, path_head);
		j = 0;
		list_for_each (path_next, path_head, path_last) {
			/* path_next == struct pgpath */

			/* Get the devt of the pgpath */
			GET_ADDR(path_next, pgpath, path, path);
			GET_VALUE(path, path, dev, dm_dev);
			GET_STR(dm_dev, dm_dev, name, name, BUFSIZE);

			fprintf(fp, " %s", name);
			j++;
		}
		if (j != nr_paths)
			fprintf(fp, " ERROR: paths are less than nr_paths:%d",
				nr_paths);
		i++;
	}
	if (i != nr_pgs)
		fprintf(fp, " ERROR: pgs are less than nr_pgs:%d", nr_pgs);
}

static void
multipath_show_status(unsigned long target)
{
	int i, j;
	unsigned int queue_if_no_path, nr_pgs, pg_id, nr_paths;
	unsigned int bypassed_pg, path_active, nr_fails;
	unsigned long mp, hwh, hwh_type, cur_pg, path, dm_dev;
	unsigned long pg_head, pg_next, pg_last;
	unsigned long path_head, path_next, path_last;
	char buf[BUFSIZE], path_status;

	/* Get the address of struct multipath */
	GET_VALUE(target, dm_target, private, mp);

	/* Get features information */
	GET_VALUE(mp, multipath, queue_if_no_path, queue_if_no_path);

	/* Get the hardware-handler information */
	GET_ADDR(mp, multipath, hw_handler, hwh);
	GET_VALUE(hwh, hw_handler, type, hwh_type);
	if (hwh_type)
		GET_PTR_STR(hwh_type, hw_handler_type, name, buf, BUFSIZE);
	else
		strcpy(buf, "none");

	/* Get the number of priority groups */
	GET_VALUE(mp, multipath, nr_priority_groups, nr_pgs);

	fprintf(fp, "  queue_if_no_path:%d hwh:%s nr_pgs:%d\n",
		queue_if_no_path, buf, nr_pgs);

	/* Display information for each priority group */
	fprintf(fp, "    %-2s  %-9s  %-8s  %s",
		"PG", "PG_STATUS", "NR_PATHS", "PATHS");
	GET_ADDR(mp, multipath, priority_groups, pg_head);
	i = 0;
	list_for_each (pg_next, pg_head, pg_last) {
		/* pg_next == struct priority_group */

		/* Get the index of the priority group */
		GET_VALUE(pg_next, priority_group, pg_num, pg_id);

		/* Get the status of the priority group */
		GET_VALUE(pg_next, priority_group, bypassed, bypassed_pg);
		if (bypassed_pg)
			strcpy(buf, "disabled");
		else {
			GET_VALUE(mp, multipath, current_pg, cur_pg);
			if (pg_next == cur_pg)
				strcpy(buf, "active");
			else
				strcpy(buf, "enabled");
		}

		/* Get the number of paths in the priority group */
		GET_VALUE(pg_next, priority_group, nr_pgpaths, nr_paths);

		fprintf(fp, "\n    %-2d  %-9s  %-8d ", pg_id, buf, nr_paths);

		/* Display information for each path */
		GET_ADDR(pg_next, priority_group, pgpaths, path_head);
		j = 0;
		list_for_each (path_next, path_head, path_last) {
			/* path_next == struct pgpath */

			/* Get the devt of the pgpath */
			GET_ADDR(path_next, pgpath, path, path);
			GET_VALUE(path, path, dev, dm_dev);
			GET_STR(dm_dev, dm_dev, name, buf, BUFSIZE);

			/* Get the status of the path */
			GET_VALUE(path, path, is_active, path_active);
			GET_VALUE(path_next, pgpath, fail_count, nr_fails);
			path_status = path_active ? 'A' : 'F';

			fprintf(fp, " %s(%c,%u)", buf, path_status, nr_fails);
			j++;
		}
		if (j != nr_paths)
			fprintf(fp, " ERROR: paths are less than nr_paths:%d",
				nr_paths);
		i++;
	}
	if (i != nr_pgs)
		fprintf(fp, " ERROR: pgs are less than nr_pgs:%d", nr_pgs);
}

static void
multipath_show_queue(unsigned long target)
{
	unsigned int queue_size;
	unsigned long mp;

	/* Get the address of struct multipath */
	GET_VALUE(target, dm_target, private, mp);

	/* Get the size of queued I/Os in this 'target' */
	GET_VALUE(mp, multipath, queue_size, queue_size);

	fprintf(fp, "  queue_size:%d", queue_size);
}

static struct dminfo_target_analyzer multipath_analyzer = {
	.target_name      = "multipath",
	.ready            = multipath_ready,
	.show_table       = multipath_show_table,
	.show_status      = multipath_show_status,
	.show_queue       = multipath_show_queue
};

/*
 * crypt target
 */
static int
crypt_ready(void)
{
	static int debuginfo = 0;

	if (debuginfo)
		return 1;

	if (STRUCT_EXISTS("struct crypt_config")) {
		debuginfo = 1;
		return 1;
	} else
		fprintf(fp, "No such struct info: crypt_config");

	return 0;
}

#define DMINFO_CRYPTO_TFM_MODE_ECB 0x00000001
#define DMINFO_CRYPTO_TFM_MODE_CBC 0x00000002

static void
crypt_show_table(unsigned long target)
{
	int i, cit_mode, key_size;
	unsigned long cc, tfm, crt_alg, cipher, iv_mode, dm_dev;
	char buf[BUFSIZE], *chainmode;

	/* Get the address of struct crypt_config */
	GET_VALUE(target, dm_target, private, cc);

	/* Get the cipher name of the crypt_tfm */
	GET_VALUE(cc, crypt_config, tfm, tfm);
	GET_VALUE(tfm, crypto_tfm, __crt_alg, crt_alg);
	GET_STR(crt_alg, crypto_alg, cra_name, buf, BUFSIZE);
	fprintf(fp, "  type:%s", buf);

	/* Get the cit_mode of the crypt_tfm */
	GET_ADDR(tfm, crypto_tfm, crt_u, cipher);
	GET_VALUE(cipher, cipher_tfm, cit_mode, cit_mode);

	if (MEMBER_EXISTS("struct crypt_config", "iv_mode")) {
		if (cit_mode == DMINFO_CRYPTO_TFM_MODE_CBC)
			chainmode = "cbc";
		else if (cit_mode == DMINFO_CRYPTO_TFM_MODE_ECB) 
			chainmode = "ecb";
		else
			chainmode = "unknown";

		/* Get the iv_mode of the crypt_config */
		GET_VALUE(cc, crypt_config, iv_mode, iv_mode);
		if (iv_mode) {
			GET_PTR_STR(cc, crypt_config, iv_mode, buf, BUFSIZE);
			fprintf(fp, "-%s-%s", chainmode, buf);
		} else
			fprintf(fp, "-%s", chainmode);

	} else {
		/* Compatibility mode for old dm-crypt cipher strings */
		if (cit_mode == DMINFO_CRYPTO_TFM_MODE_CBC)
			chainmode = "plain";
		else if (cit_mode == DMINFO_CRYPTO_TFM_MODE_ECB) 
			chainmode = "ecb";
		else
			chainmode = "unknown";

		fprintf(fp, "-%s", chainmode);
	}

	/* Get the devt of the crypt_config */
	GET_VALUE(cc, crypt_config, dev, dm_dev);
	GET_STR(dm_dev, dm_dev, name, buf, BUFSIZE);
	fprintf(fp, " dev:%s", buf);

	/*
	 * Get the key of the crypt_config.
	 */
	GET_VALUE(cc, crypt_config, key_size, key_size);
	GET_STR(cc, crypt_config, key, buf, MIN(key_size + 1, BUFSIZE));
	fprintf(fp, " key:");
	for (i = 0; i < key_size; i++)
		fprintf(fp, "%02x", (unsigned char)buf[i]);
}

static void
crypt_show_status(unsigned long target)
{
	/* crypt target has no status */
	fprintf(fp, "  No status info");
}

static void
crypt_show_queue(unsigned long target)
{
	/* crypt target has no queue */
	fprintf(fp, "  No queue info");
}

static struct dminfo_target_analyzer crypt_analyzer = {
	.target_name      = "crypt",
	.ready            = crypt_ready,
	.show_table       = crypt_show_table,
	.show_status      = crypt_show_status,
	.show_queue       = crypt_show_queue
};

/*
 * stripe target
 */
static int
stripe_ready(void)
{
	static int debuginfo = 0;

	if (debuginfo)
		return 1;

	if (STRUCT_EXISTS("struct stripe_c")) {
		debuginfo = 1;
		return 1;
	} else
		fprintf(fp, "No such struct info: stripe_c");

	return 0;
}

static void
stripe_show_table(unsigned long target)
{
	unsigned int i, n_stripe;
	unsigned long sc, stripe_size, s, head, dm_dev;
	unsigned long long mask;
	char buf[BUFSIZE];

	/* Get the address of struct stripe_c */
	GET_VALUE(target, dm_target, private, sc);

	/* Get the chunk_size of the stripe_c */
	GET_VALUE(sc, stripe_c, chunk_mask, mask);
	fprintf(fp, "  chunk_size:%llu", mask + 1);

	/*
	 * Display the information of each stripe disks.
	 *
	 * head = stripe_c.stripe.
	 * This is the head of struct stripe array.
	 */
	stripe_size = STRUCT_SIZE("struct stripe");
	GET_ADDR(sc, stripe_c, stripe, head);
	GET_VALUE(sc, stripe_c, stripes, n_stripe);
	fprintf(fp, " dev:");
	for (i = 0; i < n_stripe; i++) {
		s = head + stripe_size * i; /* Get next stripe */

		/* Get the devt of the stripe disk */
		GET_VALUE(s, stripe, dev, dm_dev);
		GET_STR(dm_dev, dm_dev, name, buf, BUFSIZE);

		fprintf(fp, "%s%s", buf, i == n_stripe - 1 ? "" : ",");
	}
	if (i != n_stripe)
		fprintf(fp, " ERROR: dev are less than n_stripe:%d", n_stripe);
}

static void
stripe_show_status(unsigned long target)
{
	/* stripe target has no status */
	fprintf(fp, "  No status info");
}

static void
stripe_show_queue(unsigned long target)
{
	/* stripe target has no queue */
	fprintf(fp, "  No queue info");
}

static struct dminfo_target_analyzer stripe_analyzer = {
	.target_name      = "striped",
	.ready            = stripe_ready,
	.show_table       = stripe_show_table,
	.show_status      = stripe_show_status,
	.show_queue       = stripe_show_queue
};

/*
 * snapshot target
 */
static int
snapshot_ready(void)
{
	static int debuginfo = 0;

	if (debuginfo)
		return 1;

	if (STRUCT_EXISTS("struct dm_snapshot")) {
		debuginfo = 1;
		return 1;
	} else
		fprintf(fp, "No such struct info: dm_snapshot");

	return 0;
}

static void
snapshot_show_table(unsigned long target)
{
	unsigned long snap, orig_dev, cow_dev;
	unsigned long long chunk_size;
	char orig_name[BUFSIZE], cow_name[BUFSIZE], type;

	/* Get the address of struct dm_snapshot */
	GET_VALUE(target, dm_target, private, snap);

	/* Get snapshot parameters of the dm_snapshot */
	GET_VALUE(snap, dm_snapshot, origin, orig_dev);
	GET_STR(orig_dev, dm_dev, name, orig_name, BUFSIZE);
	GET_VALUE(snap, dm_snapshot, cow, cow_dev);
	GET_STR(cow_dev, dm_dev, name, cow_name, BUFSIZE);
	GET_VALUE(snap, dm_snapshot, type, type);
	GET_VALUE(snap, dm_snapshot, chunk_size, chunk_size);

	fprintf(fp, "  orig:%s cow:%s type:%c chunk_size:%llu",
		orig_name, cow_name, type, chunk_size);
}

static void
snapshot_show_status(unsigned long target)
{
	int valid;
	unsigned long snap;

	/* Get the address of struct dm_snapshot */
	GET_VALUE(target, dm_target, private, snap);

	/* Get snapshot parameters of the dm_snapshot */
	GET_VALUE(snap, dm_snapshot, valid, valid);

	fprintf(fp, "  vaild:%d", valid);
}

static void
snapshot_show_queue(unsigned long target)
{
	fprintf(fp, "  No queue info");
}

static struct dminfo_target_analyzer snapshot_analyzer = {
	.target_name      = "snapshot",
	.ready            = snapshot_ready,
	.show_table       = snapshot_show_table,
	.show_status      = snapshot_show_status,
	.show_queue       = snapshot_show_queue
};

/*
 * snapshot-origin target
 */
static int
origin_ready(void)
{
	return 1;
}

static void
origin_show_table(unsigned long target)
{
	unsigned long dm_dev;
	char buf[BUFSIZE];

	/* Get the name of the struct dm_dev */
	GET_VALUE(target, dm_target, private, dm_dev);
	GET_STR(dm_dev, dm_dev, name, buf, BUFSIZE);

	fprintf(fp, "  orig_dev:%s", buf);
}

static void
origin_show_status(unsigned long target)
{
	/* snapshot-origin target has no status */
	fprintf(fp, "  No status info");
}

static void
origin_show_queue(unsigned long target)
{
	/* snapshot-origin target has no queue */
	fprintf(fp, "  No queue info");
}

static struct dminfo_target_analyzer snapshot_origin_analyzer = {
	.target_name      = "snapshot-origin",
	.ready            = origin_ready,
	.show_table       = origin_show_table,
	.show_status      = origin_show_status,
	.show_queue       = origin_show_queue
};

/*
 * Core part of dminfo
 */
#define DMINFO_LIST   0
#define DMINFO_DEPS   1
#define DMINFO_TABLE  2
#define DMINFO_STATUS 3
#define DMINFO_QUEUE  4

static int
dm_core_ready(void)
{
	static int debuginfo = 0;

	if (debuginfo)
		return 1;

	if (STRUCT_EXISTS("struct hash_cell")) {
		debuginfo = 1;
		return 1;
	} else
		fprintf(fp, "No such struct info: hash_cell\n");

	return 0;
}

/* Display dependency information of the 'table' */
static void
dminfo_show_deps(unsigned long table)
{
	int major, minor, count;
	unsigned long head, next, last, dev, bdev;
	char buf[BUFSIZE];

	/* head = dm_table.devices */
	GET_ADDR(table, dm_table, devices, head);

	fprintf(fp, "  %-3s  %-3s  %-16s  %-5s  %s\n",
		"MAJ", "MIN", "GENDISK", "COUNT", "DEVNAME");

	list_for_each (next, head, last) {
		/* Get dependency information. (next == struct *dm_dev) */
		GET_VALUE(next, dm_dev, count, count);
		GET_VALUE(next, dm_dev, bdev, bdev);
		GET_VALUE(bdev, block_device, bd_disk, dev);
		GET_VALUE(dev, gendisk, major, major);
		GET_VALUE(dev, gendisk, first_minor, minor);
		GET_STR(dev, gendisk, disk_name, buf, BUFSIZE);

		fprintf(fp, "  %-3d  %-3d  %-16lx  %-5d  %s\n",
			major, minor, dev, count, buf);
	}
}

/*
 * Display target specific information in the 'table', if the target
 * analyzer is registered and available.
 */
static void
dminfo_show_details(unsigned long table, unsigned int num_targets, int info_type)
{
	unsigned int i;
	unsigned long head, target_size, target, target_type;
	struct dminfo_target_analyzer *ta;
	char buf[BUFSIZE];

	/*
	 * head = dm_table.targets.
	 * This is the head of struct dm_target array.
	 */
	GET_VALUE(table, dm_table, targets, head);
	target_size = STRUCT_SIZE("struct dm_target");

	fprintf(fp, "  %-16s  %-11s  %s\n",
		"TARGET", "TARGET_TYPE", "PRIVATE_DATA");

	for (i = 0; i < num_targets; i++, fprintf(fp, "\n")) {
		target = head + target_size * i; /* Get next target */

		/* Get target information */
		GET_VALUE(target, dm_target, type, target_type);
		GET_PTR_STR(target_type, target_type, name, buf, BUFSIZE);

		fprintf(fp, "  %-16lx  %-11s", target, buf);

		if (!(ta = find_target_analyzer(buf)) || !ta->ready
			|| !ta->ready())
			continue;

		switch (info_type) {
		case DMINFO_TABLE:
			if (ta->show_table)
				ta->show_table(target);
			break;
		case DMINFO_STATUS:
			if (ta->show_status)
				ta->show_status(target);
			break;
		case DMINFO_QUEUE:
			if (ta->show_queue)
				ta->show_queue(target);
			break;
		default:
			break;
		}
	}

	if (i != num_targets)
		fprintf(fp, " ERROR: targets are less than num_targets:%d",
			num_targets);
}

/*
 * Display lists (and detail information if specified) of existing
 * dm devices.
 */
static void
dminfo_show_list(int additional_info)
{
	int i, major, minor, array_len;
	unsigned int num_targets;
	unsigned long _name_buckets, head, next, last, md, dev, table;
	char buf[BUFSIZE];

	_name_buckets = symbol_value("_name_buckets");
	array_len = get_array_length("_name_buckets", NULL, 0);

	if (additional_info == DMINFO_LIST)
		fprintf(fp, "%-3s  %-3s  %-16s  %-16s  %-7s  %s\n",
			"MAJ", "MIN", "MAP_DEV", "DM_TABLE",
			"TARGETS", "MAPNAME");

	for (i = 0; i < array_len; i++) {
		/* head = _name_buckets[i] */
		head = _name_buckets + (i * SIZE(list_head));

		list_for_each (next, head, last) { /* next == hash_cell */
			/* Get device and table information */
			GET_PTR_STR(next, hash_cell, name, buf, BUFSIZE);
			GET_VALUE(next, hash_cell, md, md);
			GET_VALUE(md, mapped_device, disk, dev);
			GET_VALUE(dev, gendisk, major, major);
			GET_VALUE(dev, gendisk, first_minor, minor);
			GET_VALUE(md, mapped_device, map, table);
			GET_VALUE(table, dm_table, num_targets, num_targets);

			if (additional_info != DMINFO_LIST)
				fprintf(fp, "%-3s  %-3s  %-16s  %-16s  %-7s  %s\n",
					"MAJ", "MIN", "MAP_DEV", "DM_TABLE",
					"TARGETS", "MAPNAME");

			fprintf(fp, "%-3d  %-3d  %-16lx  %-16lx  %-7d  %s\n",
				major, minor, md, table, num_targets, buf);

			switch(additional_info) {
			case DMINFO_DEPS:
				dminfo_show_deps(table);
				break;
			case DMINFO_TABLE:
			case DMINFO_STATUS:
			case DMINFO_QUEUE:
				dminfo_show_details(table, num_targets,
					additional_info);
				break;
			default:
				break;
			}

			if (additional_info != DMINFO_LIST)
				fprintf(fp, "\n");
		}
	}
}

/*
 * Display the original bio information for the 'bio'.
 * If the 'bio' is for dm devices, the original bio information is pointed
 * by bio.bi_private as struct target_io.
 */
static void
dminfo_show_bio(unsigned long bio)
{
	int major, minor;
	unsigned long target_io, dm_io, dm_bio, md, dev;
	char buf[BUFSIZE];

	/* Get original bio and device information */
	GET_VALUE(bio, bio, bi_private, target_io);
	GET_VALUE(target_io, target_io, io, dm_io);
	GET_VALUE(dm_io, dm_io, bio, dm_bio);
	GET_VALUE(dm_io, dm_io, md, md);
	GET_VALUE(md, mapped_device, disk, dev);
	GET_VALUE(dev, gendisk, major, major);
	GET_VALUE(dev, gendisk, first_minor, minor);
	GET_STR(dev, gendisk, disk_name, buf, BUFSIZE);

	fprintf(fp, "%-16s  %-3s  %-3s  %-16s  %s\n",
		"DM_BIO_ADDRESS", "MAJ", "MIN", "MAP_DEV", "DEVNAME");
	fprintf(fp, "%-16lx  %-3d  %-3d  %-16lx  %s\n",
		dm_bio, major, minor, md, buf);
}

static void
cmd_dminfo(void)
{
	int c, additional_info = DMINFO_LIST;
	unsigned long bio;

	if (!dm_core_ready())
		return;

	/* Parse command line option */
	while ((c = getopt(argcnt, args, "b:dlqst")) != EOF) {
		switch(c)
		{
		case 'b':
			bio = stol(optarg, FAULT_ON_ERROR, NULL);
			dminfo_show_bio(bio);
			return;
		case 'd':
			additional_info = DMINFO_DEPS;
			break;
		case 'l':
			additional_info = DMINFO_LIST;
			break;
		case 'q':
			additional_info = DMINFO_QUEUE;
			break;
		case 's':
			additional_info = DMINFO_STATUS;
			break;
		case 't':
			additional_info = DMINFO_TABLE;
			break;
		default:
			argerrs++;
			break;
		}
	}

	if (argerrs)
		cmd_usage(pc->curcmd, SYNOPSIS);

	dminfo_show_list(additional_info);
}

/*
 * dminfo help
 */
static char *help_dminfo[] = {
	"dminfo",				/* command name */
	"device mapper (dm) information",	/* short description */
	"[-b bio | -d | -l | -q | -s | -t]",	/* argument synopsis */
	"  This command displays information about device-mapper mapped ",
        "  devices (dm devices).",
        "  If no argument is entered, displays lists of existing dm devices.",
        "  It's same as -l option.",
	"",
	"    -b bio  displays the information of the dm device which the bio",
	"            is submitted in.  If the bio isn't for dm devices,",
	"            results will be error.",
	"        -d  displays dependency information for existing dm devices.",
	"        -l  displays lists of existing dm devices.",
	"        -q  displays queued I/O information for each target of",
	"            existing dm devices.",
	"        -s  displays status information for each target of existing",
	"            dm devices.",
	"        -t  displays table information for each target of existing",
	"            dm devices.",
	"",
	"EXAMPLE",
	"  Display lists of dm devices.  \"MAP_DEV\" is the address of the",
	"  struct mapped_device.  \"DM_TABLE\" is the address of the struct",
	"  dm_table.  \"TARGETS\" is the number of targets which are in",
	"  the struct dm_table.",
	"",
	"    %s> dminfo",
	"    MAJ  MIN  MAP_DEV           DM_TABLE          TARGETS  MAPNAME",
	"    253  8    c4866c80          c4866280          1        vg0-snap0",
	"    253  6    f6a04a80          f6a04580          1        vg0-lv0-real",
	"    253  0    c4840380          c4841880          1        mp0",
	"    253  5    f7c50c80          c488e480          1        via_cbeheddbdd",
	"    253  7    c4866a80          c4866380          1        vg0-snap0-cow",
	"    253  4    d441e280          c919ed80          1        dummy1",
	"    253  3    f5dc4280          cba81d80          1        dummy0",
	"    253  2    f7c53180          c4866180          1        vg0-lv0",
	"    253  1    f746d280          f746cd80          1        mp0p1",
	"",
	"  Display the dm device information which the bio is submitted in.",
	"  The bio (ceacee80) is a clone of the bio (ceacee00) which is",
	"  submitted in the dm-3 (dummy0).  And the bio (ceacee00) is a clone",
	"  of the bio (ceaced80) which is submitted in the dm-4 (dummy1), too.",
	"  The bio (ceaced80) is the original bio.",
	"",
	"    %s> dminfo -b ceacee80",
	"    DM_BIO_ADDRESS    MAJ  MIN  MAP_DEV           DEVNAME",
	"    ceacee00          253  3    f5dc4280          dm-3",
	"    crash> dminfo -b ceacee00",
	"    DM_BIO_ADDRESS    MAJ  MIN  MAP_DEV           DEVNAME",
	"    ceaced80          253  4    d441e280          dm-4",
	"    crash> dminfo -b ceaced80",
	"    dminfo: invalid kernel virtual address: 64  type: \"GET_VALUE: dm_io.bio\"",
	"",
	"  Display dependency information for each target.",
	"  The vg0-snap0 depends on thd dm-6 (vg0-lv0-real) and the dm-7",
	"  (vg0-snap0-cow)",
	"",
	"    %s> dminfo -d",
	"    MAJ  MIN  MAP_DEV           DM_TABLE          TARGETS  MAPNAME",
	"    253  8    c4866c80          c4866280          1        vg0-snap0",
	"      MAJ  MIN  GENDISK           COUNT  DEVNAME",
	"      253  7    c4866980          1      dm-7",
	"      253  6    f6a04280          1      dm-6",
	"",
	"    MAJ  MIN  MAP_DEV           DM_TABLE          TARGETS  MAPNAME",
	"    253  6    f6a04a80          f6a04580          1        vg0-lv0-real",
	"      MAJ  MIN  GENDISK           COUNT  DEVNAME",
	"      8    0    f7f24c80          1      sda",
	"",
	"    MAJ  MIN  MAP_DEV           DM_TABLE          TARGETS  MAPNAME",
	"    253  7    c4866a80          c4866380          1        vg0-snap0-cow",
	"      MAJ  MIN  GENDISK           COUNT  DEVNAME",
	"      8    0    f7f24c80          1      sda",
	"",
	"    MAJ  MIN  MAP_DEV           DM_TABLE          TARGETS  MAPNAME",
	"    253  2    f7c53180          c4866180          1        vg0-lv0",
	"      MAJ  MIN  GENDISK           COUNT  DEVNAME",
	"      253  6    f6a04280          1      dm-6",
	"",
	"  Display queued I/O information for each target.",
	"  The information is displayed under the \"PRIVATE_DATA\" column.",
	"",
	"    %s> dminfo -q",
	"    MAJ  MIN  MAP_DEV           DM_TABLE          TARGETS  MAPNAME",
	"    253  5    f7c50c80          c488e480          1        via_cbeheddbdd",
	"      TARGET            TARGET_TYPE  PRIVATE_DATA",
	"      f8961080          mirror       (reads) (writes) (quiesced) (recovered)",
	"",
	"      --------------------------------------------------------------",
	"       \"reads/writes\" are members of the struct mirror_set, and",
	"       \"quiesced/recovered\" are members of the struct region_hash.",
	"       If the list is empty, the member is bracketed by \"()\".",
	"      --------------------------------------------------------------",
	"",
	"    MAJ  MIN  MAP_DEV           DM_TABLE          TARGETS  MAPNAME",
	"    253  0    c4840380          c4841880          1        mp0",
	"      TARGET            TARGET_TYPE  PRIVATE_DATA",
	"      f8802080          multipath    queue_size:0",
	"",
	"    MAJ  MIN  MAP_DEV           DM_TABLE          TARGETS  MAPNAME",
	"    253  1    f746d280          f746cd80          1        mp0p1",
	"      TARGET            TARGET_TYPE  PRIVATE_DATA",
	"      f8821080          linear       No queue info",
	"",
	"  Display status information for each target.",
	"  The information is displayed under the \"PRIVATE_DATA\" column.",
	"",
	"    %s> dminfo -s",
	"    MAJ  MIN  MAP_DEV           DM_TABLE          TARGETS  MAPNAME",
	"    253  0    c4840380          c4841880          1        mp0",
	"      TARGET            TARGET_TYPE  PRIVATE_DATA",
	"      f8802080          multipath    queue_if_no_path:0 hwh:none nr_pgs:1",
	"        PG  PG_STATUS  NR_PATHS  PATHS",
	"        1   active     2         8:16(A,0) 8:32(A,0)",
	"",
	"      --------------------------------------------------------------",
	"       Format of \"PATHS\": <major>:<minor>(<status>,<fail_count>)",
	"         Status: A:active, F:faulty",
	"         Fail_count: the value of the struct pgpath.fail_count",
	"      --------------------------------------------------------------",
	"",
	"    MAJ  MIN  MAP_DEV           DM_TABLE          TARGETS  MAPNAME",
	"    253  5    f7c50c80          c488e480          1        via_cbeheddbdd",
	"      TARGET            TARGET_TYPE  PRIVATE_DATA",
	"      f8961080          mirror       in_sync:1 dev:8:16(A,0),8:32(A,0)",
	"",
	"      --------------------------------------------------------------",
	"       Format of \"dev\": <major>:<minor>(<status>,<error_count>)",
	"         Status: A:active, D:degraded",
	"         Error_count: the value of the struct mirror.error_count",
	"      --------------------------------------------------------------",
	"",
	"    MAJ  MIN  MAP_DEV           DM_TABLE          TARGETS  MAPNAME",
	"    253  1    f746d280          f746cd80          1        mp0p1",
	"      TARGET            TARGET_TYPE  PRIVATE_DATA",
	"      f8821080          linear       No status info",
	"",
	"  Display table information for each target.",
	"  The information is displayed under the \"PRIVATE_DATA\" column.",
	"",
	"    %s> dminfo -t",
	"    MAJ  MIN  MAP_DEV           DM_TABLE          TARGETS  MAPNAME",
	"    253  8    c4866c80          c4866280          1        vg0-snap0",
	"      TARGET            TARGET_TYPE  PRIVATE_DATA",
	"      f89b4080          snapshot     orig:253:6 cow:253:7 type:P chunk_size:16",
	"",
	"    MAJ  MIN  MAP_DEV           DM_TABLE          TARGETS  MAPNAME",
	"    253  6    f6a04a80          f6a04580          1        vg0-lv0-real",
	"      TARGET            TARGET_TYPE  PRIVATE_DATA",
	"      f890f080          linear       begin:0 len:204800 dev:8:5 offset:384",
	"",
	"    MAJ  MIN  MAP_DEV           DM_TABLE          TARGETS  MAPNAME",
	"    253  0    c4840380          c4841880          1        mp0",
	"      TARGET            TARGET_TYPE  PRIVATE_DATA",
	"      f8802080          multipath    queue_if_no_path:0 hwh:none nr_pgs:1",
	"        PG  PATH_SELECTOR  NR_PATHS  PATHS",
	"        1   round-robin    2         8:16 8:32",
	"",
	"    MAJ  MIN  MAP_DEV           DM_TABLE          TARGETS  MAPNAME",
	"    253  5    f7c50c80          c488e480          1        via_cbeheddbdd",
	"      TARGET            TARGET_TYPE  PRIVATE_DATA",
	"      f8961080          mirror       log:core dev:8:16(0),8:32(0)",
	"",
	"      --------------------------------------------------------------",
	"       Format of \"dev\": <major>:<minor>(<offset>)",
	"         Offset: the value of the struct mirror.offset",
	"      --------------------------------------------------------------",
	"",
	"    MAJ  MIN  MAP_DEV           DM_TABLE          TARGETS  MAPNAME",
	"    253  7    c4866a80          c4866380          1        vg0-snap0-cow",
	"      TARGET            TARGET_TYPE  PRIVATE_DATA",
	"      f899d080          linear       begin:0 len:8192 dev:8:5 offset:205184",
	"",
	"    MAJ  MIN  MAP_DEV           DM_TABLE          TARGETS  MAPNAME",
	"    253  2    f7c53180          c4866180          1        vg0-lv0",
	"      TARGET            TARGET_TYPE  PRIVATE_DATA",
	"      f8bbc080          snapshot-origin  orig_dev:253:6",
	"",
	"    MAJ  MIN  MAP_DEV           DM_TABLE          TARGETS  MAPNAME",
	"    253  1    f746d280          f746cd80          1        mp0p1",
	"      TARGET            TARGET_TYPE  PRIVATE_DATA",
	"      f8821080          linear       begin:0 len:2040192 dev:253:0 offset:63",
	NULL
};

/*
 * Registering command extension
 */

static struct command_table_entry command_table[] = {
	{"dminfo", cmd_dminfo, help_dminfo, 0},
	{NULL, NULL, NULL, 0},
};

void __attribute__((constructor))
dminfo_init(void)
{
	register_extension(command_table);

	dminfo_register_target_analyzer(&zero_analyzer);
	dminfo_register_target_analyzer(&error_analyzer);
	dminfo_register_target_analyzer(&linear_analyzer);
	dminfo_register_target_analyzer(&mirror_analyzer);
	dminfo_register_target_analyzer(&multipath_analyzer);
	dminfo_register_target_analyzer(&crypt_analyzer);
	dminfo_register_target_analyzer(&stripe_analyzer);
	dminfo_register_target_analyzer(&snapshot_analyzer);
	dminfo_register_target_analyzer(&snapshot_origin_analyzer);
}

void __attribute__((destructor))
dminfo_fini(void)
{
}