summaryrefslogtreecommitdiff
path: root/usr/src/cmd/mdb/common/modules/ii/ii.c
blob: 6169ca0f7395f3646937f323af6d3f4b32b4bf1f (plain)
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
/*
 * 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 <sys/types.h>
#include <sys/mdb_modapi.h>

#include <sys/nsctl/nsctl.h>
#include <sys/unistat/spcs_s.h>
#include <sys/unistat/spcs_s_k.h>


#include <sys/nsctl/dsw.h>
#include <sys/nsctl/dsw_dev.h>

#include <sys/nsctl/nsvers.h>

#define	offsetof(s, m)  ((size_t)(&((s *)0)->m))


const mdb_bitmask_t bi_flags_bits[] = {
	{ "DSW_GOLDEN", DSW_GOLDEN, DSW_GOLDEN },
	{ "DSW_COPYINGP", DSW_COPYINGP, DSW_COPYINGP },
	{ "DSW_COPYINGM", DSW_COPYINGM, DSW_COPYINGM },
	{ "DSW_COPYINGS", DSW_COPYINGS, DSW_COPYINGS },
	{ "DSW_COPYINGX", DSW_COPYINGX, DSW_COPYINGX },
	{ "DSW_BMPOFFLINE", DSW_BMPOFFLINE, DSW_BMPOFFLINE },
	{ "DSW_SHDOFFLINE", DSW_SHDOFFLINE, DSW_SHDOFFLINE },
	{ "DSW_MSTOFFLINE", DSW_MSTOFFLINE, DSW_MSTOFFLINE },
	{ "DSW_OVROFFLINE", DSW_OVROFFLINE, DSW_OVROFFLINE },
	{ "DSW_TREEMAP", DSW_TREEMAP, DSW_TREEMAP },
	{ "DSW_OVERFLOW", DSW_OVERFLOW, DSW_OVERFLOW },
	{ "DSW_SHDEXPORT", DSW_SHDEXPORT, DSW_SHDEXPORT },
	{ "DSW_SHDIMPORT", DSW_SHDIMPORT, DSW_SHDIMPORT },
	{ "DSW_VOVERFLOW", DSW_VOVERFLOW, DSW_VOVERFLOW },
	{ "DSW_HANGING", DSW_HANGING, DSW_HANGING },
	{ "DSW_CFGOFFLINE", DSW_CFGOFFLINE, DSW_CFGOFFLINE },
	{ "DSW_OVRHDRDRTY", DSW_OVRHDRDRTY, DSW_OVRHDRDRTY },
	{ "DSW_RESIZED", DSW_RESIZED, DSW_RESIZED },
	{ "DSW_FRECLAIM", DSW_FRECLAIM, DSW_FRECLAIM },
	{ NULL, 0, 0 }
};

const mdb_bitmask_t bi_state_bits[] = {
	{ "DSW_IOCTL", DSW_IOCTL, DSW_IOCTL },
	{ "DSW_CLOSING", DSW_CLOSING, DSW_CLOSING },
	{ "DSW_MSTTARGET", DSW_MSTTARGET, DSW_MSTTARGET },
	{ "DSW_MULTIMST", DSW_MULTIMST, DSW_MULTIMST },
	{ NULL, 0, 0 }
};
static uintptr_t nextaddr;
/*
 * Display a ii_fd_t
 * Requires an address.
 */
/*ARGSUSED*/
static int
ii_fd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
{
	ii_fd_t fd;

	if (!(flags & DCMD_ADDRSPEC))
		return (DCMD_USAGE);

	if (mdb_vread(&fd, sizeof (fd), addr) != sizeof (fd)) {
		mdb_warn("failed to read ii_fd_t at 0x%p", addr);
		return (DCMD_ERR);
	}

	mdb_inc_indent(4);
	mdb_printf("ii_info: 0x%p ii_bmp: %d ii_shd: %d ii_ovr: %d ii_optr: "
	    "0x%p\nii_oflags: 0x%x\n", fd.ii_info, fd.ii_bmp, fd.ii_shd,
	    fd.ii_ovr, fd.ii_optr, fd.ii_oflags);
	mdb_dec_indent(4);

	return (DCMD_OK);
}

/*
 * displays a ii_info_dev structure.
 */
/*ARGSUSED*/
static int
ii_info_dev(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
{
	_ii_info_dev_t ipdev;

	if (!(flags & DCMD_ADDRSPEC))
		return (DCMD_USAGE);

	if (mdb_vread(&ipdev, sizeof (ipdev), addr) != sizeof (ipdev)) {
		mdb_warn("failed to read ii_info_dev_t at 0x%p", addr);
		return (DCMD_ERR);
	}

	mdb_inc_indent(4);
	mdb_printf("bi_fd: 0x%p bi_iodev: 0x%p bi_tok: 0x%p\n",
	    ipdev.bi_fd, ipdev.bi_iodev, ipdev.bi_tok);
	mdb_printf("bi_ref: %d bi_rsrv: %d bi_orsrv: %d\n",
	    ipdev.bi_ref, ipdev.bi_rsrv, ipdev.bi_orsrv);

	/*
	 * use nsc_fd to dump the fd details.... if present.
	 */
	if (ipdev.bi_fd) {
		mdb_printf("nsc_fd structure:\n");
		mdb_inc_indent(4);
		mdb_call_dcmd("nsc_fd", (uintptr_t)(ipdev.bi_fd),
		    flags, 0, NULL);
		mdb_dec_indent(4);
	}
	mdb_dec_indent(4);
	return (DCMD_OK);
}

/*
 * Displays an _ii_overflow structure
 */
/*ARGSUSED*/
static int
ii_overflow(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
{
	_ii_overflow_t ii_overflow;

	nextaddr = 0;
	if (!(flags & DCMD_ADDRSPEC))
		return (DCMD_USAGE);

	if (mdb_vread(&ii_overflow, sizeof (ii_overflow), addr)
		!= sizeof (ii_overflow)) {
		mdb_warn("failed to read ii_overflow_t at 0x%p", addr);
		return (DCMD_ERR);
	}

	mdb_inc_indent(4);
	mdb_printf("_ii_overflow at 0x%p\n", addr);
	mdb_printf("_ii_doverflow_t\n");
	mdb_inc_indent(4);
	mdb_printf("ii_dvolname: %s\n", ii_overflow.ii_volname);
	mdb_printf("ii_dhmagic: %x\n", ii_overflow.ii_hmagic);
	mdb_printf("ii_dhversion: %x\n", ii_overflow.ii_hversion);
	mdb_printf("ii_ddrefcnt: %x\n", ii_overflow.ii_drefcnt);
	mdb_printf("ii_dflags: %x\n", ii_overflow.ii_flags);
	mdb_printf("ii_dfreehead: %x\n", ii_overflow.ii_freehead);
	mdb_printf("ii_dnchunks: %x\n", ii_overflow.ii_nchunks);
	mdb_printf("ii_dunused: %x\n", ii_overflow.ii_unused);
	mdb_printf("ii_dused: %x\n", ii_overflow.ii_used);
	mdb_printf("ii_urefcnt: %x\n", ii_overflow.ii_urefcnt);
	mdb_dec_indent(4);

	mdb_printf("ii_mutex: %x\n", ii_overflow.ii_mutex);
	mdb_printf("ii_kstat_mutex: %x\n", ii_overflow.ii_kstat_mutex);
	mdb_printf("ii_crefcnt: %d\n", ii_overflow.ii_crefcnt);
	mdb_printf("ii_detachcnt: %d\n", ii_overflow.ii_detachcnt);
	mdb_printf("ii_next: %x\n", ii_overflow.ii_next);

	mdb_printf("Overflow volume:\n");
	if (ii_overflow.ii_dev)
		ii_info_dev((uintptr_t)ii_overflow.ii_dev, flags, 0, NULL);

	mdb_printf("  ii_ioname: %s\n", &ii_overflow.ii_ioname);
	mdb_dec_indent(4);

	nextaddr = (uintptr_t)ii_overflow.ii_next;
	return (DCMD_OK);
}
/*ARGSUSED*/
static int
ii_info(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
{
	_ii_info_t ii_info = {0};
	char string[DSW_NAMELEN];

	nextaddr = 0;
	if (!(flags & DCMD_ADDRSPEC))
		return (DCMD_USAGE);

	if (mdb_vread(&ii_info, sizeof (ii_info), addr) != sizeof (ii_info)) {
		mdb_warn("failed to read ii_info_t at 0x%p", addr);
		return (DCMD_ERR);
	}

	mdb_printf(
		"bi_next: 0x%p\n"
		"bi_head: 0x%p\t"
		"bi_sibling: 0x%p\n"
		"bi_master: 0x%p\t"
		"bi_nextmst: 0x%p\n",
		ii_info.bi_next, ii_info.bi_head, ii_info.bi_sibling,
		ii_info.bi_master, ii_info.bi_nextmst);

	mdb_printf("bi_mutex: 0x%p\n", ii_info.bi_mutex);

	/*
	 * Print out all the fds by using ii_info_dev
	 */
	mdb_printf("Cache master:\n");
	if (ii_info.bi_mstdev)
		ii_info_dev((uintptr_t)ii_info.bi_mstdev, flags, 0, NULL);

	mdb_printf("Raw master:\n");
	if (ii_info.bi_mstrdev)
		ii_info_dev((uintptr_t)ii_info.bi_mstrdev, flags, 0, NULL);

	mdb_printf("Cache shadow:\n");
	ii_info_dev((uintptr_t)(addr + offsetof(_ii_info_t, bi_shddev)),
	    flags, 0, NULL);

	mdb_printf("Raw shadow:\n");
	ii_info_dev((uintptr_t)(addr + offsetof(_ii_info_t, bi_shdrdev)),
	    flags, 0, NULL);

	mdb_printf("Bitmap:\n");
	ii_info_dev((uintptr_t)(addr + offsetof(_ii_info_t, bi_bmpdev)),
	    flags, 0, NULL);

	mdb_printf("bi_keyname: %-*s\n", DSW_NAMELEN, ii_info.bi_keyname);
	mdb_printf("bi_bitmap: 0x%p\n", ii_info.bi_bitmap);

	if ((ii_info.bi_cluster == NULL) ||
	    (mdb_vread(&string, sizeof (string), (uintptr_t)ii_info.bi_cluster)
		!= sizeof (string)))
		string[0] = 0;
	mdb_printf("bi_cluster: %s\n", string);

	if ((ii_info.bi_group == NULL) ||
	    (mdb_vread(&string, sizeof (string), (uintptr_t)ii_info.bi_group)
			!= sizeof (string)))
		string[0] = 0;
	mdb_printf("bi_group: %s\n", string);

	mdb_printf("bi_busy: 0x%p\n", ii_info.bi_busy);

	mdb_printf("bi_shdfba: %0x\t", ii_info.bi_shdfba);
	mdb_printf("bi_shdbits: %0x\n", ii_info.bi_shdbits);
	mdb_printf("bi_copyfba: %0x\t", ii_info.bi_copyfba);
	mdb_printf("bi_copybits: %0x\n", ii_info.bi_copybits);

	mdb_printf("bi_size: %0x\n", ii_info.bi_size);

	mdb_printf("bi_flags: 0x%x <%b>\n",
		ii_info.bi_flags, ii_info.bi_flags, bi_flags_bits);

	mdb_printf("bi_state: 0x%x <%b>\n",
		ii_info.bi_state, ii_info.bi_state, bi_state_bits);

	mdb_printf("bi_disabled: %d\n", ii_info.bi_disabled);
	mdb_printf("bi_ioctl: %d\n", ii_info.bi_ioctl);
	mdb_printf("bi_release: %d\t", ii_info.bi_release);
	mdb_printf("bi_rsrvcnt: %d\n", ii_info.bi_rsrvcnt);

	mdb_printf("bi_copydonecv: %x\t", ii_info.bi_copydonecv);
	mdb_printf("bi_reservecv: %x\n", ii_info.bi_reservecv);
	mdb_printf("bi_releasecv: %x\t", ii_info.bi_releasecv);
	mdb_printf("bi_closingcv: %x\n", ii_info.bi_closingcv);
	mdb_printf("bi_ioctlcv: %x\t", ii_info.bi_ioctlcv);
	mdb_printf("bi_busycv: %x\n", ii_info.bi_busycv);
	mdb_call_dcmd("rwlock", (uintptr_t)(addr +
	    offsetof(_ii_info_t, bi_busyrw)), flags, 0, NULL);
	mdb_printf("bi_bitmap_ops: 0x%p\n", ii_info.bi_bitmap_ops);

	mdb_printf("bi_rsrvmutex: %x\t", ii_info.bi_rsrvmutex);
	mdb_printf("bi_rlsemutex: %x\n", ii_info.bi_rlsemutex);
	mdb_printf("bi_bmpmutex: %x\n", ii_info.bi_bmpmutex);

	mdb_printf("bi_mstchks: %d\t", ii_info.bi_mstchks);
	mdb_printf("bi_shdchks: %d\n", ii_info.bi_shdchks);
	mdb_printf("bi_shdchkused: %d\t", ii_info.bi_shdchkused);
	mdb_printf("bi_shdfchk: %d\n", ii_info.bi_shdfchk);

	mdb_printf("bi_overflow\n");
	if (ii_info.bi_overflow)
		ii_overflow((uintptr_t)ii_info.bi_overflow, flags, 0, NULL);

	mdb_printf("bi_iifd:\n");
	if (ii_info.bi_iifd)
		(void) ii_fd((uintptr_t)ii_info.bi_iifd, flags, 0, NULL);

	mdb_printf("bi_throttle_unit: %d\t", ii_info.bi_throttle_unit);
	mdb_printf("bi_throttle_delay: %d\n", ii_info.bi_throttle_delay);

	mdb_printf("bi_linkrw:\n");
	mdb_call_dcmd("rwlock", (uintptr_t)(addr +
	    offsetof(_ii_info_t, bi_linkrw)), flags, 0, NULL);

	mdb_printf("bi_chksmutex: %x\n", ii_info.bi_chksmutex);
	mdb_printf("bi_locked_pid: %x\n", ii_info.bi_locked_pid);
	mdb_printf("bi_kstat: 0x%p\n", ii_info.bi_kstat);
	/* ii_kstat_info_t bi_kstat_io; */

	nextaddr = (uintptr_t)ii_info.bi_next;
	return (DCMD_OK);
}

/*
 * This should be a walker surely.
 */
/*ARGSUSED*/
static int
ii_info_all(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
{
	uintptr_t myaddr;
	/*
	 * we use the global address.
	 */
	if (flags & DCMD_ADDRSPEC)
		return (DCMD_USAGE);

	if (mdb_readsym(&myaddr, sizeof (myaddr), "_ii_info_top") !=
	    sizeof (myaddr)) {
		return (DCMD_ERR);
	}

	mdb_printf("_ii_info_top contains 0x%lx\n", myaddr);

	while (myaddr) {
		ii_info(myaddr, DCMD_ADDRSPEC, 0, NULL);
		myaddr = nextaddr;
	}
	return (DCMD_OK);
}

/*
 * Display general ii module information.
 */

#define	ii_get_print(kvar, str, fmt, val)		\
	if (mdb_readvar(&(val), #kvar) == -1) {		\
		mdb_dec_indent(4);			\
		mdb_warn("unable to read '" #kvar "'");	\
		return (DCMD_ERR);			\
	}						\
	mdb_printf("%-20s" fmt "\n", str ":", val)

/* ARGSUSED */
static int
ii(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
{
	int maj, min, mic, baseline, i;

	if (argc != 0)
		return (DCMD_USAGE);

	if (mdb_readvar(&maj, "dsw_major_rev") == -1) {
		mdb_warn("unable to read 'dsw_major_rev'");
		return (DCMD_ERR);
	}

	if (mdb_readvar(&min, "dsw_minor_rev") == -1) {
		mdb_warn("unable to read 'dsw_minor_rev'");
		return (DCMD_ERR);
	}

	if (mdb_readvar(&mic, "dsw_micro_rev") == -1) {
		mdb_warn("unable to read 'dsw_micro_rev'");
		return (DCMD_ERR);
	}

	if (mdb_readvar(&baseline, "dsw_baseline_rev") == -1) {
		mdb_warn("unable to read 'dsw_baseline_rev'");
		return (DCMD_ERR);
	}

	mdb_printf("Point-in-Time Copy module version: kernel %d.%d.%d.%d; "
	    "mdb %d.%d.%d.%d\n", maj, min, mic, baseline,
	    ISS_VERSION_MAJ, ISS_VERSION_MIN, ISS_VERSION_MIC, ISS_VERSION_NUM);

	mdb_inc_indent(4);
	ii_get_print(ii_debug, "debug", "%d", i);
	ii_get_print(ii_bitmap, "bitmaps", "%d", i);
	mdb_dec_indent(4);

	return (DCMD_OK);
}


/*
 * MDB module linkage information:
 */

static const mdb_dcmd_t dcmds[] = {
{ "ii", NULL, "display ii module info", ii },
{ "ii_fd", NULL, "display ii_fd structure", ii_fd },
{ "ii_info", NULL, "display ii_info structure", ii_info },
{ "ii_info_all", NULL, "display all ii_info structures", ii_info_all },
{ "ii_info_dev", NULL, "display ii_info_dev structure", ii_info_dev},
{ "ii_overflow", NULL, "display ii_overflow structure", ii_overflow},
{ NULL }
};


static const mdb_walker_t walkers[] = {
	{ NULL }
};


static const mdb_modinfo_t modinfo = {
	MDB_API_VERSION, dcmds, walkers
};


const mdb_modinfo_t *
_mdb_init(void)
{
	return (&modinfo);
}