Skip to content

Commit

Permalink
ioctl() was not setting the correct errno value, which is used to signal
Browse files Browse the repository at this point in the history
non-error events as well. This fixes listing problems, and clone.
  • Loading branch information
lundman committed Jun 27, 2013
1 parent 4ef320e commit 97764d2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
6 changes: 6 additions & 0 deletions lib/libzfs/libzfs_iter.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,16 @@ zfs_iter_filesystems(zfs_handle_t *zhp, zfs_iter_f func, void *data)
zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 };
zfs_handle_t *nzhp;
int ret;
uint64_t allocated_size;

if (zhp->zfs_type != ZFS_TYPE_FILESYSTEM)
return (0);

if (zcmd_alloc_dst_nvlist(zhp->zfs_hdl, &zc, 0) != 0)
return (-1);

allocated_size = zc.zc_nvlist_dst_size;

while ((ret = zfs_do_list_ioctl(zhp, ZFS_IOC_DATASET_LIST_NEXT,
&zc)) == 0) {
/*
Expand All @@ -128,6 +131,9 @@ zfs_iter_filesystems(zfs_handle_t *zhp, zfs_iter_f func, void *data)
zcmd_free_nvlists(&zc);
return (ret);
}

zc.zc_nvlist_dst_size = allocated_size;

}
zcmd_free_nvlists(&zc);
return ((ret < 0) ? ret : 0);
Expand Down
2 changes: 1 addition & 1 deletion lib/libzfs/libzfs_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -4120,7 +4120,7 @@ zpool_label_disk(libzfs_handle_t *hdl, zpool_handle_t *zhp, char *name)
efi_free(vtoc);

zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, "try using "
"parted(8) and then provide a specific slice: %d"), rval);
"pdisk(9) and then provide a specific slice: %d"), rval);
return (zfs_error(hdl, EZFS_LABELFAILED, errbuf));
}

Expand Down
12 changes: 9 additions & 3 deletions lib/libzfs/libzfs_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,10 @@ zcmd_read_dst_nvlist(libzfs_handle_t *hdl, zfs_cmd_t *zc, nvlist_t **nvlp)
return (0);
}

/*
* OSX will return error=0 on error, but set zc_ioc_error to the real
* error code, we will then move that to errno, and return -1.
*/
int
zfs_ioctl(libzfs_handle_t *hdl, int request, zfs_cmd_t *zc)
{
Expand All @@ -1095,10 +1099,12 @@ zfs_ioctl(libzfs_handle_t *hdl, int request, zfs_cmd_t *zc)
error = ioctl(hdl->libzfs_fd, request, zc);

/* normal path, zfsdev_ioctl returns the real error in zc_ioc_error */
if (error == 0)
error = errno = zc->zc_ioc_error;
else
if ((error == 0) && zc->zc_ioc_error) {
error = -1;
errno = zc->zc_ioc_error;
} else if (error) {
errno = error;
}

if (hdl->libzfs_log_str) {
free(hdl->libzfs_log_str);
Expand Down
2 changes: 1 addition & 1 deletion module/zfs/zfs_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1956,7 +1956,7 @@ static int
zfs_ioc_dataset_list_next(zfs_cmd_t *zc)
{
objset_t *os;
int error;
int error = 0;
char *p;
size_t orig_len = strlen(zc->zc_name);

Expand Down

0 comments on commit 97764d2

Please sign in to comment.