Skip to content

Commit

Permalink
Fix missing vdev names in zpool status output
Browse files Browse the repository at this point in the history
Top-level vdev names in zpool status output should follow a <type-id> naming
convention.  In the case of raidz devices, the type portion of the name was
missing.

This commit fixes a bug in zpool_vdev_name() where in this snprintf call

	(void) snprintf(buf, sizeof (buf), "%s-%llu", path,
		(u_longlong_t)id);

buf and path may point to the same location.  The result is that buf ends up
containing only the "-id" part.  This only occurred for raidz devices because
the code for appending the parity level to the type string stored its result in
buf then set path to point there.  To fix this we allocate a new temporary
buffer on the stack instead of reusing buf.

Signed-off-by: Brian Behlendorf <[email protected]>
Closes #57
  • Loading branch information
nedbass authored and behlendorf committed Sep 23, 2010
1 parent 368f4c1 commit 858219c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/libzfs/libzfs_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -3047,6 +3047,8 @@ set_path(zpool_handle_t *zhp, nvlist_t *nv, const char *path)
(void) ioctl(zhp->zpool_hdl->libzfs_fd, ZFS_IOC_VDEV_SETPATH, &zc);
}

#define PATH_BUF_LEN 64

/*
* Given a vdev, return the name to display in iostat. If the vdev has a path,
* we use that, stripping off any leading "/dev/dsk/"; if not, we use the type.
Expand All @@ -3068,7 +3070,7 @@ zpool_vdev_name(libzfs_handle_t *hdl, zpool_handle_t *zhp, nvlist_t *nv,
{
char *path, *devid, *type;
uint64_t value;
char buf[64];
char buf[PATH_BUF_LEN];
vdev_stat_t *vs;
uint_t vsc;

Expand Down Expand Up @@ -3160,11 +3162,13 @@ zpool_vdev_name(libzfs_handle_t *hdl, zpool_handle_t *zhp, nvlist_t *nv,
* If it's a raidz device, we need to stick in the parity level.
*/
if (strcmp(path, VDEV_TYPE_RAIDZ) == 0) {
char tmpbuf[PATH_BUF_LEN];

verify(nvlist_lookup_uint64(nv, ZPOOL_CONFIG_NPARITY,
&value) == 0);
(void) snprintf(buf, sizeof (buf), "%s%llu", path,
(void) snprintf(tmpbuf, sizeof (tmpbuf), "%s%llu", path,
(u_longlong_t)value);
path = buf;
path = tmpbuf;
}

/*
Expand Down

0 comments on commit 858219c

Please sign in to comment.