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
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include "mdinclude.h"
typedef struct submirror_cb {
minor_t un_self_id;
int un_nsm;
ushort_t mm_un_nsm;
}submirror_cb_t;
void
print_setname(int setno)
{
char setname[1024];
if (setno != 0) {
if (mdb_readstr(setname, 1024,
(uintptr_t)set_dbs[setno].s_setname) == -1) {
mdb_warn("failed to read setname at 0x%p\n",
set_dbs[setno].s_setname);
}
mdb_printf("%s/", setname);
}
}
void
print_stripe(void *un_addr, void *mdcptr, uint_t verbose)
{
ms_unit_t ms;
int setno;
minor_t un_self_id;
md_parent_t un_parent;
diskaddr_t un_total_blocks;
/* read in the device */
un_self_id = ((mdc_unit_t *)mdcptr)->un_self_id;
un_parent = ((mdc_unit_t *)mdcptr)->un_parent;
un_total_blocks = ((mdc_unit_t *)mdcptr)->un_total_blocks;
if (mdb_vread(&ms, sizeof (ms_unit_t),
(uintptr_t)un_addr) == -1) {
mdb_warn("failed to read ms_unit_t at %p\n", un_addr);
return;
}
setno = MD_MIN2SET(un_self_id);
print_setname(setno);
mdb_printf("d%u: ", MD_MIN2UNIT(un_self_id));
if (un_parent == ((unit_t)-1)) {
mdb_printf("Concat/Stripe");
} else {
mdb_printf("Subdevice of d%u", MD_MIN2UNIT(un_parent));
}
if (verbose) {
mdb_printf("\t< %p::print ms_unit_t >\n", un_addr);
} else {
mdb_printf("\t< %p>\n", un_addr);
}
mdb_inc_indent(2);
mdb_printf("Size: %llu blocks\n", un_total_blocks);
mdb_printf("Rows: %u\n", ms.un_nrows);
mdb_dec_indent(2);
}
/* ARGSUSED */
int
print_submirror(uintptr_t addr, void *arg, submirror_cb_t *data)
{
uintptr_t un_addr;
mdc_unit_t mdc_sm;
if (mdb_vread(&un_addr, sizeof (void *), addr) == -1) {
mdb_warn("failed to read submirror at %p\n", addr);
return (WALK_ERR);
}
if (un_addr != NULL) {
if (mdb_vread(&mdc_sm, sizeof (mdc_unit_t), un_addr) == -1) {
mdb_warn("failed to read mdc_unit_t at %p", un_addr);
return (WALK_ERR);
}
if (mdc_sm.un_parent == data->un_self_id) {
/* this is one of the sub mirrors */
mdb_printf("Submirror %u: d%u ",
data->un_nsm, MD_MIN2UNIT(mdc_sm.un_self_id));
mdb_printf("Size: %llu\n", mdc_sm.un_total_blocks);
data->un_nsm++;
if (data->un_nsm == data->mm_un_nsm)
return (WALK_DONE);
}
}
return (WALK_NEXT);
}
/*
* Construct an RLE count for the number of 'cleared' bits in the given 'bm'
* Output the RLE count in form: [<set>.<cleared>.<set>.<cleared>...]
* RLE is Run Length Encoding, a method for compactly describing a bitmap
* as a series of numbers indicating the count of consecutive set or cleared
* bits.
*
* Input:
* <bm> bitmap to scan
* <size> length of bitmap (in bits)
* <comp_bm> RLE count array to be updated
* <opstr> Descriptive text for bitmap RLE count display
*/
static void
print_comp_bm(unsigned char *bm, uint_t size, ushort_t *comp_bm, char *opstr)
{
int cnt_clean, tot_dirty, cur_idx;
int i, cur_clean, cur_dirty, printit, max_set_cnt, max_reset_cnt;
cnt_clean = 1;
printit = 0;
cur_clean = 0;
cur_dirty = 0;
cur_idx = 0;
tot_dirty = 0;
max_set_cnt = max_reset_cnt = 0;
for (i = 0; i < size; i++) {
if (isset(bm, i)) {
/* If we're counting clean bits, flush the count out */
if (cnt_clean) {
cnt_clean = 0;
comp_bm[cur_idx] = cur_clean;
printit = 1;
if (cur_clean > max_reset_cnt) {
max_reset_cnt = cur_clean;
}
}
cur_clean = 0;
cur_dirty++;
tot_dirty++;
} else {
if (!cnt_clean) {
cnt_clean = 1;
comp_bm[cur_idx] = cur_dirty;
printit = 1;
if (cur_dirty > max_set_cnt) {
max_set_cnt = cur_dirty;
}
}
cur_dirty = 0;
cur_clean++;
}
if (printit) {
mdb_printf("%u.", comp_bm[cur_idx++]);
printit = 0;
}
}
mdb_printf("\nTotal %s bits = %lu\n", opstr, tot_dirty);
mdb_printf("Total %s transactions = %lu\n", opstr, cur_idx);
mdb_printf("Maximum %s set count = %lu, reset count = %lu\n", opstr,
max_set_cnt, max_reset_cnt);
}
void
print_mirror(void *un_addr, void *mdcptr, uint_t verbose)
{
mm_unit_t mm, *mmp;
void **ptr;
int setno = 0;
minor_t un_self_id;
diskaddr_t un_total_blocks;
ushort_t mm_un_nsm;
submirror_cb_t data;
uint_t num_rr, rr_blksize;
ushort_t *comp_rr;
unsigned char *rr_dirty_bm, *rr_goingclean_bm;
uintptr_t un_dbm, un_gcbm;
/* read in the device */
if (mdb_vread(&mm, sizeof (mm_unit_t),
(uintptr_t)un_addr) == -1) {
mdb_warn("failed to read mm_unit_t at %p\n", un_addr);
return;
}
mmp = &mm;
un_self_id = ((mdc_unit_t *)mdcptr)->un_self_id;
un_total_blocks = ((mdc_unit_t *)mdcptr)->un_total_blocks;
mm_un_nsm = mm.un_nsm;
setno = MD_MIN2SET(un_self_id);
print_setname(setno);
mdb_printf("d%u: Mirror", MD_MIN2UNIT(un_self_id));
if (verbose) {
mdb_printf("\t< %p::print mm_unit_t >\n", un_addr);
} else {
mdb_printf("\t< %p >\n", un_addr);
}
mdb_inc_indent(2);
mdb_printf("Size: %llu blocks\n", un_total_blocks);
/*
* Dump out the current un_dirty_bm together with its size
* Also, attempt to Run Length encode the bitmap to see if this
* is a viable option
*/
num_rr = mm.un_rrd_num;
rr_blksize = mm.un_rrd_blksize;
un_dbm = (uintptr_t)mmp->un_dirty_bm;
un_gcbm = (uintptr_t)mmp->un_goingclean_bm;
mdb_printf("RR size: %lu bits\n", num_rr);
mdb_printf("RR block size: %lu blocks\n", rr_blksize);
rr_dirty_bm = (unsigned char *)mdb_alloc(num_rr, UM_SLEEP|UM_GC);
rr_goingclean_bm = (unsigned char *)mdb_alloc(num_rr, UM_SLEEP|UM_GC);
comp_rr = (ushort_t *)mdb_alloc(num_rr * sizeof (ushort_t),
UM_SLEEP|UM_GC);
if (mdb_vread(rr_dirty_bm, num_rr, un_dbm) == -1) {
mdb_warn("failed to read un_dirty_bm at %p\n", un_dbm);
return;
}
if (mdb_vread(rr_goingclean_bm, num_rr, un_gcbm) == -1) {
mdb_warn("failed to read un_goingclean_bm at %p\n", un_gcbm);
return;
}
print_comp_bm(rr_dirty_bm, num_rr, comp_rr, "dirty");
print_comp_bm(rr_goingclean_bm, num_rr, comp_rr, "clean");
/*
* find the sub mirrors, search through each metadevice looking
* at the un_parent.
*/
ptr = mdset[setno].s_un;
data.un_self_id = un_self_id;
data.un_nsm = 0;
data.mm_un_nsm = mm_un_nsm;
if (mdb_pwalk("md_units", (mdb_walk_cb_t)print_submirror, &data,
(uintptr_t)ptr) == -1) {
mdb_warn("unable to walk units\n");
return;
}
mdb_dec_indent(2);
}
void
print_raid(void *un_addr, void *mdcptr, uint_t verbose)
{
mr_unit_t mr;
minor_t un_self_id;
diskaddr_t un_total_blocks;
mdc_unit_t mdc_sc;
void **ptr;
void *addr;
int setno = 0;
int i;
minor_t sc_un_self_id;
md_parent_t sc_parent;
diskaddr_t sc_total_blocks;
/* read in the device */
if (mdb_vread(&mr, sizeof (mr_unit_t), (uintptr_t)un_addr) == -1) {
mdb_warn("failed to read mr_unit_t at %p\n", un_addr);
return;
}
un_self_id = ((mdc_unit_t *)mdcptr)->un_self_id;
un_total_blocks = ((mdc_unit_t *)mdcptr)->un_total_blocks;
setno = MD_MIN2SET(un_self_id);
print_setname(setno);
mdb_printf("d%u: Raid", MD_MIN2UNIT(un_self_id));
if (verbose) {
mdb_printf("\t< %p ::print mr_unit_t>\n", un_addr);
} else {
mdb_printf("\t< %p >\n", un_addr);
}
mdb_inc_indent(2);
mdb_printf("Size: %llu\n", un_total_blocks);
/*
* find the sub components if any, search through each metadevice
* looking at the un_parent.
*/
ptr = mdset[setno].s_un;
for (i = 0; i < md_nunits; i++, ptr++) {
if (mdb_vread(&addr, sizeof (void *), (uintptr_t)ptr) == -1) {
mdb_warn("failed to read addr at %p\n", ptr);
continue;
}
if (addr != NULL) {
if (mdb_vread(&mdc_sc, sizeof (mdc_unit_t),
(uintptr_t)addr) == -1) {
mdb_warn("failed to read mdc_unit_t at %p",
un_addr);
continue;
}
sc_parent = mdc_sc.un_parent;
sc_un_self_id = mdc_sc.un_self_id;
sc_total_blocks = mdc_sc.un_total_blocks;
if (sc_parent == un_self_id) {
/* this is one of the sub components */
mdb_printf("Subdevice %u ",
MD_MIN2UNIT(sc_un_self_id));
mdb_printf("Size: %llu\n", sc_total_blocks);
}
}
}
mdb_dec_indent(2);
}
void
print_sp(void *un_addr, void *mdcptr, uint_t verbose)
{
mp_unit_t mp;
minor_t un_self_id;
diskaddr_t un_total_blocks;
int setno = 0;
uintptr_t extaddr;
int i;
/* read in the device */
if (mdb_vread(&mp, sizeof (mp_unit_t), (uintptr_t)un_addr) == -1) {
mdb_warn("failed to read mp_unit_t at %p\n", un_addr);
return;
}
un_self_id = ((mdc_unit_t *)mdcptr)->un_self_id;
un_total_blocks = ((mdc_unit_t *)mdcptr)->un_total_blocks;
setno = MD_MIN2SET(un_self_id);
print_setname(setno);
mdb_printf("d%u: Soft Partition", MD_MIN2UNIT(un_self_id));
if (verbose) {
mdb_printf("\t< %p ::print mp_unit_t >\n", un_addr);
} else {
mdb_printf("\t< %p >\n", un_addr);
}
mdb_inc_indent(2);
mdb_printf("Size: %llu\n", un_total_blocks);
mdb_inc_indent(2);
mdb_printf("Extent\tStart Block\tBlock count\n");
extaddr = (uintptr_t)un_addr + sizeof (mp_unit_t) - sizeof (mp_ext_t);
for (i = 0; i < mp.un_numexts; i++) {
mp_ext_t mpext;
if (mdb_vread(&mpext, sizeof (mp_ext_t), extaddr) == -1) {
mdb_warn("failed to read mp_ext_t at %p\n", extaddr);
return;
}
mdb_printf(" %d \t %llu\t %llu\n",
i, mpext.un_poff, mpext.un_len);
extaddr += sizeof (mp_ext_t);
}
mdb_dec_indent(2);
mdb_dec_indent(2);
}
void
print_trans(void *un_addr, void *mdcptr, uint_t verbose)
{
mt_unit_t mt;
minor_t un_self_id;
int setno = 0;
/* read in the device */
if (mdb_vread(&mt, sizeof (mt_unit_t), (uintptr_t)un_addr) == -1) {
mdb_warn("failed to read mt_unit_t at %p\n", un_addr);
return;
}
un_self_id = ((mdc_unit32_od_t *)mdcptr)->un_self_id;
setno = MD_MIN2SET(un_self_id);
print_setname(setno);
mdb_printf("d%u: Trans", MD_MIN2UNIT(un_self_id));
if (verbose) {
mdb_printf("\t< %p ::print mt_unit_t>\n", un_addr);
} else {
mdb_printf("\t< %p >\n", un_addr);
}
}
void
print_device(void *un_addr, void *mdcptr, uint_t verbose)
{
u_longlong_t un_type;
un_type = ((mdc_unit_t *)mdcptr)->un_type;
switch (un_type) {
case MD_DEVICE: /* stripe/concat */
print_stripe(un_addr, mdcptr, verbose);
break;
case MD_METAMIRROR:
print_mirror(un_addr, mdcptr, verbose);
break;
case MD_METATRANS:
print_trans(un_addr, mdcptr, verbose);
break;
case MD_METARAID:
print_raid(un_addr, mdcptr, verbose);
break;
case MD_METASP:
print_sp(un_addr, mdcptr, verbose);
break;
case MD_UNDEFINED:
mdb_warn("undefined metadevice at %p\n", un_addr);
break;
default:
mdb_warn("invalid metadevice at %p\n", un_addr);
break;
}
}
/* ARGSUSED */
/*
* usage: ::metastat [-v]
*/
int
metastat(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
{
mdc_unit_t mdc;
uintptr_t un_addr;
uint_t verbose = FALSE;
snarf_sets();
if (mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, TRUE, &verbose, NULL)
!= argc) {
return (DCMD_USAGE);
}
if (!(flags & DCMD_ADDRSPEC)) {
if (mdb_walk_dcmd("md_units", "metastat", argc,
argv) == -1) {
mdb_warn("failed to walk units");
return (DCMD_ERR);
}
return (DCMD_OK);
}
if (!(flags & DCMD_LOOP)) {
/* user passed set addr */
if (mdb_pwalk_dcmd("md_units", "metastat", argc,
argv, addr) == -1) {
mdb_warn("failed to walk units");
return (DCMD_ERR);
}
return (DCMD_OK);
}
if (mdb_vread(&un_addr, sizeof (void *), addr) == -1) {
mdb_warn("failed to read un_addr at %p", addr);
return (DCMD_ERR);
}
if (un_addr != NULL) {
if (mdb_vread(&mdc, sizeof (mdc_unit_t), un_addr) == -1) {
mdb_warn("failed to read mdc_unit_t at %p", un_addr);
return (DCMD_ERR);
}
print_device((void *)un_addr, (void *)&mdc, verbose);
mdb_dec_indent(2);
}
return (DCMD_OK);
}
|