]> git.proxmox.com Git - mirror_zfs.git/commitdiff
zfs userspace dumps core when used on ZVOLs
authorloli10K <loli10K@users.noreply.github.com>
Fri, 25 Jan 2019 17:47:52 +0000 (18:47 +0100)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Fri, 25 Jan 2019 17:47:52 +0000 (09:47 -0800)
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 <behlendorf1@llnl.gov>
Reviewed by: Tom Caputi <tcaputi@datto.com>
Signed-off-by: loli10K <ezomori.nozomu@gmail.com>
Closes #8279

cmd/zfs/zfs_main.c

index b8258a9cf53be4c3ad634683748463831cdc0981..ab2b99b02df6713a342cdfe7375182785395b3c9 100644 (file)
@@ -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)