Skip to content

Commit

Permalink
Fix error handling for "zpool online -e".
Browse files Browse the repository at this point in the history
The error handling code around zpool_relabel_disk() is either inexistent
or wrong. The function call itself is not checked, and
zpool_relabel_disk() is generating error messages from an unitialized
buffer.

Before:

    # zpool online -e homez sdb; echo $?
    `: cannot relabel 'sdb1': unable to open device: 2
    0

After:

    # zpool online -e homez sdb; echo $?
    cannot expand sdb: cannot relabel 'sdb1': unable to open device: 2
    1
  • Loading branch information
dechamps committed Jul 6, 2012
1 parent 42d3b99 commit 5534b70
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/libzfs/libzfs_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -2081,15 +2081,14 @@ zpool_get_physpath(zpool_handle_t *zhp, char *physpath, size_t phypath_size)
* the disk to use the new unallocated space.
*/
static int
zpool_relabel_disk(libzfs_handle_t *hdl, const char *path)
zpool_relabel_disk(libzfs_handle_t *hdl, const char *path, const char *msg)
{
char errbuf[1024];
int fd, error;

if ((fd = open(path, O_RDWR|O_DIRECT)) < 0) {
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "cannot "
"relabel '%s': unable to open device: %d"), path, errno);
return (zfs_error(hdl, EZFS_OPENFAILED, errbuf));
return (zfs_error(hdl, EZFS_OPENFAILED, msg));
}

/*
Expand All @@ -2102,7 +2101,7 @@ zpool_relabel_disk(libzfs_handle_t *hdl, const char *path)
if (error && error != VT_ENOSPC) {
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "cannot "
"relabel '%s': unable to read disk capacity"), path);
return (zfs_error(hdl, EZFS_NOCAP, errbuf));
return (zfs_error(hdl, EZFS_NOCAP, msg));
}
return (0);
}
Expand Down Expand Up @@ -2160,7 +2159,9 @@ zpool_vdev_online(zpool_handle_t *zhp, const char *path, int flags,

if (wholedisk) {
pathname += strlen(DISK_ROOT) + 1;
(void) zpool_relabel_disk(hdl, pathname);
int result = zpool_relabel_disk(hdl, pathname, msg);
if (result != 0)
return (result);
}
}

Expand Down

0 comments on commit 5534b70

Please sign in to comment.