diff options
author | loli10K <[email protected]> | 2019-01-25 18:47:52 +0100 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2019-01-25 09:47:52 -0800 |
commit | 7646af20ad3406afde8b02b9b58eb0e58af66700 (patch) | |
tree | d8c88713b82e81b5a3c66b2261f994d618646c83 | |
parent | 8fccfa8e17d30b4dae82f0cd33346f39b79f4822 (diff) |
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 <[email protected]>
Reviewed by: Tom Caputi <[email protected]>
Signed-off-by: loli10K <[email protected]>
Closes #8279
-rw-r--r-- | cmd/zfs/zfs_main.c | 14 |
1 files changed, 12 insertions, 2 deletions
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) |