Skip to content

Commit d5ee8a1

Browse files
ahrensChristopher Siden
authored andcommitted
3654 zdb should print number of ganged blocks
3655 ::rrwlock and ::refcount print errors on non-debug kernels 3656 remove unused function zap_cursor_move_to_key() 3657 mdb_ctf_vread() should allow conversion of pointer to uintptr_t Reviewed by: George Wilson <george.wilson@delphix.com> Reviewed by: Christopher Siden <christopher.siden@delphix.com> Reviewed by: Dan McDonald <danmcd@nexenta.com> Approved by: Garrett D'Amore <garrett@damore.org>
1 parent b1fa632 commit d5ee8a1

File tree

7 files changed

+125
-154
lines changed

7 files changed

+125
-154
lines changed

usr/src/cmd/mdb/common/mdb/mdb_ctf.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,12 +1159,6 @@ vread_helper(mdb_ctf_id_t modid, char *modbuf,
11591159
return (-1); /* errno is set for us */
11601160
}
11611161

1162-
if (tgtkind != modkind) {
1163-
mdb_ctf_warn(flags, "unexpected kind for type %s (%s)\n",
1164-
typename, tgtname);
1165-
return (set_errno(EMDB_INCOMPAT));
1166-
}
1167-
11681162
if ((modsz = mdb_ctf_type_size(modid)) == -1UL) {
11691163
mdb_ctf_warn(flags, "couldn't determine type size of "
11701164
"mdb module type %s\n", mdbtypename);
@@ -1176,7 +1170,17 @@ vread_helper(mdb_ctf_id_t modid, char *modbuf,
11761170
return (-1); /* errno is set for us */
11771171
}
11781172

1179-
switch (modkind) {
1173+
if (tgtkind == CTF_K_POINTER && modkind == CTF_K_INTEGER &&
1174+
strcmp(mdbtypename, "uintptr_t") == 0) {
1175+
/* allow them to convert a pointer to a uintptr_t */
1176+
ASSERT(modsz == tgtsz);
1177+
} else if (tgtkind != modkind) {
1178+
mdb_ctf_warn(flags, "unexpected kind for type %s (%s)\n",
1179+
typename, tgtname);
1180+
return (set_errno(EMDB_INCOMPAT));
1181+
}
1182+
1183+
switch (tgtkind) {
11801184
case CTF_K_INTEGER:
11811185
case CTF_K_FLOAT:
11821186
/*

usr/src/cmd/mdb/common/modules/zfs/zfs.c

Lines changed: 74 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ typedef struct mdb_dmu_buf_impl {
380380
struct {
381381
uint64_t db_object;
382382
} db;
383-
void *db_objset;
383+
uintptr_t db_objset;
384384
uint64_t db_level;
385385
uint64_t db_blkid;
386386
struct {
@@ -416,7 +416,7 @@ dbuf(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
416416
(void) mdb_snprintf(blkidname, sizeof (blkidname), "%llx",
417417
(u_longlong_t)db.db_blkid);
418418

419-
if (objset_name((uintptr_t)db.db_objset, path)) {
419+
if (objset_name(db.db_objset, path)) {
420420
return (DCMD_ERR);
421421
}
422422

@@ -1078,7 +1078,7 @@ spa_print(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
10781078
}
10791079

10801080
typedef struct mdb_spa_config_spa {
1081-
nvlist_t *spa_config;
1081+
uintptr_t spa_config;
10821082
} mdb_spa_config_spa_t;
10831083

10841084
/*
@@ -1101,12 +1101,12 @@ spa_print_config(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
11011101
addr, 0) == -1)
11021102
return (DCMD_ERR);
11031103

1104-
if (spa.spa_config == NULL) {
1104+
if (spa.spa_config == 0) {
11051105
mdb_printf("(none)\n");
11061106
return (DCMD_OK);
11071107
}
11081108

1109-
return (mdb_call_dcmd("nvlist", (uintptr_t)spa.spa_config, flags,
1109+
return (mdb_call_dcmd("nvlist", spa.spa_config, flags,
11101110
0, NULL));
11111111
}
11121112

@@ -1736,11 +1736,11 @@ typedef struct zio_print_args {
17361736
typedef struct mdb_zio {
17371737
enum zio_type io_type;
17381738
enum zio_stage io_stage;
1739-
void *io_waiter;
1740-
void *io_spa;
1739+
uintptr_t io_waiter;
1740+
uintptr_t io_spa;
17411741
struct {
17421742
struct {
1743-
void *list_next;
1743+
uintptr_t list_next;
17441744
} list_head;
17451745
} io_parent_list;
17461746
int io_error;
@@ -1797,8 +1797,8 @@ zio_print_cb(uintptr_t addr, zio_print_args_t *zpa)
17971797
} else {
17981798
mdb_printf("%*s%-*p %-5s %-16s ", indent, "",
17991799
ZIO_MAXWIDTH - indent, addr, type, stage);
1800-
if (zio.io_waiter)
1801-
mdb_printf("%-16p ", zio.io_waiter);
1800+
if (zio.io_waiter != 0)
1801+
mdb_printf("%-16lx ", zio.io_waiter);
18021802
else
18031803
mdb_printf("%-16s ", "-");
18041804
#ifdef _KERNEL
@@ -2065,7 +2065,7 @@ spa_walk_step(mdb_walk_state_t *wsp)
20652065
static int
20662066
zio_walk_init(mdb_walk_state_t *wsp)
20672067
{
2068-
wsp->walk_data = (void *)wsp->walk_addr;
2068+
wsp->walk_data = &wsp->walk_addr;
20692069

20702070
if (mdb_layered_walk("zio_cache", wsp) == -1) {
20712071
mdb_warn("failed to walk 'zio_cache'\n");
@@ -2079,12 +2079,13 @@ static int
20792079
zio_walk_step(mdb_walk_state_t *wsp)
20802080
{
20812081
mdb_zio_t zio;
2082+
uintptr_t *spap = wsp->walk_data;
20822083

20832084
if (mdb_ctf_vread(&zio, ZFS_STRUCT "zio", "mdb_zio_t",
20842085
wsp->walk_addr, 0) == -1)
20852086
return (WALK_ERR);
20862087

2087-
if (wsp->walk_data != NULL && wsp->walk_data != zio.io_spa)
2088+
if (*spap != 0 && *spap != zio.io_spa)
20882089
return (WALK_NEXT);
20892090

20902091
return (wsp->walk_callback(wsp->walk_addr, &zio, wsp->walk_cbdata));
@@ -2099,16 +2100,17 @@ static int
20992100
zio_walk_root_step(mdb_walk_state_t *wsp)
21002101
{
21012102
mdb_zio_t zio;
2103+
uintptr_t *spap = wsp->walk_data;
21022104

21032105
if (mdb_ctf_vread(&zio, ZFS_STRUCT "zio", "mdb_zio_t",
21042106
wsp->walk_addr, 0) == -1)
21052107
return (WALK_ERR);
21062108

2107-
if (wsp->walk_data != NULL && wsp->walk_data != zio.io_spa)
2109+
if (*spap != 0 && *spap != zio.io_spa)
21082110
return (WALK_NEXT);
21092111

21102112
/* If the parent list is not empty, ignore */
2111-
if ((uintptr_t)zio.io_parent_list.list_head.list_next !=
2113+
if (zio.io_parent_list.list_head.list_next !=
21122114
wsp->walk_addr +
21132115
mdb_ctf_offsetof_by_name(ZFS_STRUCT "zio", "io_parent_list") +
21142116
mdb_ctf_offsetof_by_name("struct list", "list_head"))
@@ -2288,41 +2290,35 @@ zfs_blkstats(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
22882290
return (DCMD_OK);
22892291
}
22902292

2293+
typedef struct mdb_reference {
2294+
uintptr_t ref_holder;
2295+
uintptr_t ref_removed;
2296+
uint64_t ref_number;
2297+
} mdb_reference_t;
2298+
22912299
/* ARGSUSED */
22922300
static int
22932301
reference_cb(uintptr_t addr, const void *ignored, void *arg)
22942302
{
2295-
static int gotid;
2296-
static mdb_ctf_id_t ref_id;
2297-
uintptr_t ref_holder;
2298-
uintptr_t ref_removed;
2299-
uint64_t ref_number;
2303+
mdb_reference_t ref;
23002304
boolean_t holder_is_str = B_FALSE;
23012305
char holder_str[128];
23022306
boolean_t removed = (boolean_t)arg;
23032307

2304-
if (!gotid) {
2305-
if (mdb_ctf_lookup_by_name("struct reference", &ref_id) == -1) {
2306-
mdb_warn("couldn't find struct reference");
2307-
return (WALK_ERR);
2308-
}
2309-
gotid = TRUE;
2310-
}
2311-
2312-
if (GETMEMBID(addr, &ref_id, ref_holder, ref_holder) ||
2313-
GETMEMBID(addr, &ref_id, ref_removed, ref_removed) ||
2314-
GETMEMBID(addr, &ref_id, ref_number, ref_number))
2315-
return (WALK_ERR);
2308+
if (mdb_ctf_vread(&ref, "reference_t", "mdb_reference_t", addr,
2309+
0) == -1)
2310+
return (DCMD_ERR);
23162311

2317-
if (mdb_readstr(holder_str, sizeof (holder_str), ref_holder) != -1)
2312+
if (mdb_readstr(holder_str, sizeof (holder_str),
2313+
ref.ref_holder) != -1)
23182314
holder_is_str = strisprint(holder_str);
23192315

23202316
if (removed)
23212317
mdb_printf("removed ");
23222318
mdb_printf("reference ");
2323-
if (ref_number != 1)
2324-
mdb_printf("with count=%llu ", ref_number);
2325-
mdb_printf("with tag %p", (void*)ref_holder);
2319+
if (ref.ref_number != 1)
2320+
mdb_printf("with count=%llu ", ref.ref_number);
2321+
mdb_printf("with tag %lx", ref.ref_holder);
23262322
if (holder_is_str)
23272323
mdb_printf(" \"%s\"", holder_str);
23282324
mdb_printf(", held at:\n");
@@ -2331,7 +2327,7 @@ reference_cb(uintptr_t addr, const void *ignored, void *arg)
23312327

23322328
if (removed) {
23332329
mdb_printf("removed at:\n");
2334-
(void) mdb_call_dcmd("whatis", ref_removed,
2330+
(void) mdb_call_dcmd("whatis", ref.ref_removed,
23352331
DCMD_ADDRSPEC, 0, NULL);
23362332
}
23372333

@@ -2340,15 +2336,26 @@ reference_cb(uintptr_t addr, const void *ignored, void *arg)
23402336
return (WALK_NEXT);
23412337
}
23422338

2339+
typedef struct mdb_refcount {
2340+
uint64_t rc_count;
2341+
} mdb_refcount_t;
2342+
2343+
typedef struct mdb_refcount_removed {
2344+
uint64_t rc_removed_count;
2345+
} mdb_refcount_removed_t;
2346+
2347+
typedef struct mdb_refcount_tracked {
2348+
boolean_t rc_tracked;
2349+
} mdb_refcount_tracked_t;
2350+
23432351
/* ARGSUSED */
23442352
static int
23452353
refcount(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
23462354
{
2347-
uint64_t rc_count, rc_removed_count;
2348-
uintptr_t rc_list, rc_removed;
2349-
static int gotid;
2350-
static mdb_ctf_id_t rc_id;
2351-
ulong_t off;
2355+
mdb_refcount_t rc;
2356+
mdb_refcount_removed_t rcr;
2357+
mdb_refcount_tracked_t rct;
2358+
int off;
23522359
boolean_t released = B_FALSE;
23532360

23542361
if (!(flags & DCMD_ADDRSPEC))
@@ -2359,48 +2366,41 @@ refcount(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
23592366
NULL) != argc)
23602367
return (DCMD_USAGE);
23612368

2362-
if (!gotid) {
2363-
/*
2364-
* The refcount structure is different when compiled debug
2365-
* vs nondebug. Therefore, we want to make sure we get the
2366-
* refcount definition from the ZFS module, in case it has
2367-
* been compiled debug but genunix is nondebug.
2368-
*/
2369-
if (mdb_ctf_lookup_by_name(ZFS_STRUCT "refcount",
2370-
&rc_id) == -1) {
2371-
mdb_warn("couldn't find struct refcount");
2372-
return (DCMD_ERR);
2373-
}
2374-
gotid = TRUE;
2375-
}
2376-
2377-
if (GETMEMBID(addr, &rc_id, rc_count, rc_count))
2369+
if (mdb_ctf_vread(&rc, "refcount_t", "mdb_refcount_t", addr,
2370+
0) == -1)
23782371
return (DCMD_ERR);
23792372

2380-
if (GETMEMBID(addr, &rc_id, rc_removed_count, rc_removed_count)) {
2381-
mdb_printf("refcount_t at %p has %llu current holds\n",
2382-
addr, (longlong_t)rc_count);
2373+
if (mdb_ctf_vread(&rcr, "refcount_t", "mdb_refcount_removed_t", addr,
2374+
MDB_CTF_VREAD_QUIET) == -1) {
2375+
mdb_printf("refcount_t at %p has %llu holds (untracked)\n",
2376+
addr, (longlong_t)rc.rc_count);
23832377
return (DCMD_OK);
23842378
}
23852379

2380+
if (mdb_ctf_vread(&rct, "refcount_t", "mdb_refcount_tracked_t", addr,
2381+
MDB_CTF_VREAD_QUIET) == -1) {
2382+
/* If this is an old target, it might be tracked. */
2383+
rct.rc_tracked = B_TRUE;
2384+
}
2385+
23862386
mdb_printf("refcount_t at %p has %llu current holds, "
23872387
"%llu recently released holds\n",
2388-
addr, (longlong_t)rc_count, (longlong_t)rc_removed_count);
2388+
addr, (longlong_t)rc.rc_count, (longlong_t)rcr.rc_removed_count);
23892389

2390-
if (rc_count > 0)
2390+
if (rct.rc_tracked && rc.rc_count > 0)
23912391
mdb_printf("current holds:\n");
2392-
if (mdb_ctf_offsetof(rc_id, "rc_list", &off) == -1)
2392+
off = mdb_ctf_offsetof_by_name("refcount_t", "rc_list");
2393+
if (off == -1)
23932394
return (DCMD_ERR);
2394-
rc_list = addr + off/NBBY;
2395-
mdb_pwalk("list", reference_cb, (void*)B_FALSE, rc_list);
2395+
mdb_pwalk("list", reference_cb, (void*)B_FALSE, addr + off);
2396+
2397+
if (released && rcr.rc_removed_count > 0) {
2398+
mdb_printf("released holds:\n");
23962399

2397-
if (released) {
2398-
if (rc_removed_count > 0)
2399-
mdb_printf("released holds:\n");
2400-
if (mdb_ctf_offsetof(rc_id, "rc_removed", &off) == -1)
2400+
off = mdb_ctf_offsetof_by_name("refcount_t", "rc_removed");
2401+
if (off == -1)
24012402
return (DCMD_ERR);
2402-
rc_removed = addr + off/NBBY;
2403-
mdb_pwalk("list", reference_cb, (void*)B_TRUE, rc_removed);
2403+
mdb_pwalk("list", reference_cb, (void*)B_FALSE, addr + off);
24042404
}
24052405

24062406
return (DCMD_OK);
@@ -3004,7 +3004,7 @@ zfs_aces_walk_step(mdb_walk_state_t *wsp)
30043004
}
30053005

30063006
typedef struct mdb_zfs_rrwlock {
3007-
kthread_t *rr_writer;
3007+
uintptr_t rr_writer;
30083008
boolean_t rr_writer_wanted;
30093009
} mdb_zfs_rrwlock_t;
30103010

@@ -3025,8 +3025,8 @@ rrwlock(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
30253025
0) == -1)
30263026
return (DCMD_ERR);
30273027

3028-
if (rrw.rr_writer != NULL) {
3029-
mdb_printf("write lock held by thread %p\n", rrw.rr_writer);
3028+
if (rrw.rr_writer != 0) {
3029+
mdb_printf("write lock held by thread %lx\n", rrw.rr_writer);
30303030
return (DCMD_OK);
30313031
}
30323032

0 commit comments

Comments
 (0)