4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #include <mdb/mdb_modapi.h>
28 #include <sys/types.h>
30 #include <sys/vnode.h>
31 #include <sys/fs/ufs_log.h>
35 typedef struct ufslogmap_walk_data
{
37 mapentry_t
*start_addr
;
38 mapentry_t
*prev_addr
;
39 } ufslogmap_walk_data_t
;
42 * Ensure we are started with a user specified address.
43 * We also allocate a ufslogmap_walk_data_t for storage,
44 * and save this using the walk_data pointer.
47 ufslogmap_walk_init(mdb_walk_state_t
*wsp
)
49 ufslogmap_walk_data_t
*uw
;
51 if (wsp
->walk_addr
== (uintptr_t)NULL
) {
52 mdb_warn("must specify an address\n");
56 uw
= mdb_zalloc(sizeof (ufslogmap_walk_data_t
), UM_SLEEP
| UM_GC
);
58 uw
->start_addr
= (mapentry_t
*)wsp
->walk_addr
;
64 * Routine to step through one element of the list.
67 ufslogmap_walk_step(mdb_walk_state_t
*wsp
)
69 ufslogmap_walk_data_t
*uw
= wsp
->walk_data
;
70 uintptr_t walk_addr
= wsp
->walk_addr
;
73 * Read the mapentry at the current walk address
75 if (mdb_vread(&uw
->me
, sizeof (mapentry_t
), walk_addr
) == -1) {
76 mdb_warn("failed to read mapentry_t at %p", walk_addr
);
81 * Check for empty list.
83 if (uw
->me
.me_next
== uw
->me
.me_prev
) {
88 * Check for end of list.
90 if (uw
->me
.me_next
== uw
->start_addr
) {
95 * Check for proper linkage
97 if (uw
->prev_addr
&& (uw
->me
.me_prev
!= uw
->prev_addr
)) {
98 mdb_warn("invalid linkage mapentry_t at %p", walk_addr
);
101 uw
->prev_addr
= (mapentry_t
*)walk_addr
;
104 * Save next address and call callback with current address
106 wsp
->walk_addr
= (uintptr_t)uw
->me
.me_next
;
107 return (wsp
->walk_callback(walk_addr
, wsp
->walk_data
,
112 delta2str(delta_t delta_type
)
114 switch (delta_type
) {
115 case DT_NONE
: return ("none");
116 case DT_SB
: return ("sb");
117 case DT_CG
: return ("cg");
118 case DT_SI
: return ("si");
119 case DT_AB
: return ("ab");
120 case DT_ABZERO
: return ("abzero");
121 case DT_DIR
: return ("dir");
122 case DT_INODE
: return ("inode");
123 case DT_FBI
: return ("fbi");
124 case DT_QR
: return ("quota");
125 case DT_COMMIT
: return ("commit");
126 case DT_CANCEL
: return ("cancel");
127 case DT_BOT
: return ("trans");
128 case DT_EOT
: return ("etrans");
129 case DT_UD
: return ("udata");
130 case DT_SUD
: return ("sudata");
131 case DT_SHAD
: return ("shadow");
132 default: return ("???");
138 mapentry_dcmd(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
142 if (!(flags
& DCMD_ADDRSPEC
))
145 if (DCMD_HDRSPEC(flags
)) {
146 mdb_printf("%<u>%?s %6s %8s %8s %s%</u>\n",
147 "ADDR", "TYPE", "SIZE", "TRANS", "HANDLER");
150 if (mdb_vread(&me
, sizeof (me
), addr
) == -1) {
151 mdb_warn("couldn't read ufslog mapentry at %p", addr
);
158 if (me
.me_delta
.d_typ
>= DT_MAX
) {
159 mdb_warn("Invalid delta type for mapentry at %p", addr
);
163 mdb_printf("%0?p %6s %8x %8x %a\n",
165 delta2str(me
.me_delta
.d_typ
),
174 uint64_t nentries
; /* number of mapentries */
175 uint64_t totalsize
; /* total number of bytes */
176 uint32_t transid
; /* first transaction id */
177 int transdiff
; /* transaction different */
178 uint32_t delta_cnt
[DT_MAX
]; /* count of each delta */
179 uint64_t delta_sum
[DT_MAX
]; /* total number of bytes for delta */
184 mapadd(uintptr_t *addr
, ufslogmap_walk_data_t
*uw
, mapstats_t
*msp
)
186 if (msp
->nentries
== 0) {
187 msp
->transid
= uw
->me
.me_tid
;
189 if (msp
->transid
!= uw
->me
.me_tid
) {
190 msp
->transdiff
= TRUE
;
194 msp
->totalsize
+= uw
->me
.me_nb
;
195 if (uw
->me
.me_dt
>= DT_MAX
) {
196 mdb_warn("Invalid delta type for mapentry at %p", addr
);
198 msp
->delta_cnt
[uw
->me
.me_dt
]++;
199 msp
->delta_sum
[uw
->me
.me_dt
] += uw
->me
.me_nb
;
206 mapstats_dcmd(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
211 if (!(flags
& DCMD_ADDRSPEC
))
214 msp
= mdb_zalloc(sizeof (mapstats_t
), UM_SLEEP
| UM_GC
);
215 msp
->transdiff
= FALSE
;
217 if (mdb_pwalk("ufslogmap", (mdb_walk_cb_t
)mapadd
, msp
, addr
) == -1) {
218 mdb_warn("can't walk ufslogmap for stats");
222 mdb_printf("Number of entries 0x%llx\n", msp
->nentries
);
223 mdb_printf("Total map size 0x%llx\n", msp
->totalsize
);
224 if (msp
->transdiff
) {
225 mdb_printf("Multiple transactions\n");
227 mdb_printf("All the same transaction id = %d\n", msp
->transid
);
230 mdb_printf("%<u>delta count(hex) avsize(hex)%</u>\n");
231 for (i
= 0; i
< DT_MAX
; i
++) {
232 if (msp
->delta_cnt
[i
]) {
233 mdb_printf("%6s %10X %10X\n",
234 delta2str(i
), msp
->delta_cnt
[i
],
235 msp
->delta_sum
[i
] / msp
->delta_cnt
[i
]);