From: loli10K Date: Fri, 25 Jan 2019 17:47:52 +0000 (+0100) Subject: zfs userspace dumps core when used on ZVOLs X-Git-Tag: zfs-0.8.0-rc4~151 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7646af20ad3406afde8b02b9b58eb0e58af66700;p=zfs zfs userspace dumps core when used on ZVOLs If you try to get the userspace, groupspace or projectspace on a ZVOL, the generated error results in passing EINVAL to zfs_standard_error_fmt() when we should return a specific error to inform the user that those properties aren't available on volumes. Reviewed-by: Brian Behlendorf Reviewed by: Tom Caputi Signed-off-by: loli10K Closes #8279 --- diff --git a/cmd/zfs/zfs_main.c b/cmd/zfs/zfs_main.c index b8258a9cf..ab2b99b02 100644 --- a/cmd/zfs/zfs_main.c +++ b/cmd/zfs/zfs_main.c @@ -3037,8 +3037,15 @@ zfs_do_userspace(int argc, char **argv) } while (delim != NULL); } - if ((zhp = zfs_open(g_zfs, argv[0], ZFS_TYPE_DATASET)) == NULL) + if ((zhp = zfs_open(g_zfs, argv[0], ZFS_TYPE_FILESYSTEM | + ZFS_TYPE_SNAPSHOT)) == NULL) return (1); + if (zhp->zfs_head_type != ZFS_TYPE_FILESYSTEM) { + (void) fprintf(stderr, gettext("operation is only applicable " + "to filesystems and their snapshots\n")); + zfs_close(zhp); + return (1); + } if ((avl_pool = uu_avl_pool_create("us_avl_pool", sizeof (us_node_t), offsetof(us_node_t, usn_avlnode), us_compare, UU_DEFAULT)) == NULL) @@ -3069,9 +3076,12 @@ zfs_do_userspace(int argc, char **argv) continue; cb.cb_prop = p; - if ((ret = zfs_userspace(zhp, p, userspace_cb, &cb)) != 0) + if ((ret = zfs_userspace(zhp, p, userspace_cb, &cb)) != 0) { + zfs_close(zhp); return (ret); + } } + zfs_close(zhp); /* Sort the list */ if ((node = uu_avl_first(avl_tree)) == NULL)