]> git.proxmox.com Git - mirror_zfs.git/commit - lib/libzfs/libzfs_util.c
Add basic zfs ioc input nvpair validation
authorDon Brady <don.brady@delphix.com>
Sun, 2 Sep 2018 19:14:01 +0000 (15:14 -0400)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Sun, 2 Sep 2018 19:14:01 +0000 (12:14 -0700)
commitb83a0e2dc1b972e3ae5c0c17b714941b4604dfd6
tree1165e7298a9ca33290ec1988da3acb4cd5065541
parente8bcb693d6a19962291e4429f2dc4ce60693bef7
Add basic zfs ioc input nvpair validation

We want newer versions of libzfs_core to run against an existing
zfs kernel module (i.e. a deferred reboot or module reload after
an update).

Programmatically document, via a zfs_ioc_key_t, the valid arguments
for the ioc commands that rely on nvpair input arguments (i.e. non
legacy commands from libzfs_core). Automatically verify the expected
pairs before dispatching a command.

This initial phase focuses on the non-legacy ioctls. A follow-on
change can address the legacy ioctl input from the zfs_cmd_t.

The zfs_ioc_key_t for zfs_keys_channel_program looks like:

static const zfs_ioc_key_t zfs_keys_channel_program[] = {
       {"program",     DATA_TYPE_STRING,               0},
       {"arg",         DATA_TYPE_UNKNOWN,              0},
       {"sync",        DATA_TYPE_BOOLEAN_VALUE,        ZK_OPTIONAL},
       {"instrlimit",  DATA_TYPE_UINT64,               ZK_OPTIONAL},
       {"memlimit",    DATA_TYPE_UINT64,               ZK_OPTIONAL},
};

Introduce four input errors to identify specific input failures
(in addition to generic argument value errors like EINVAL, ERANGE,
EBADF, and E2BIG).

ZFS_ERR_IOC_CMD_UNAVAIL the ioctl number is not supported by kernel
ZFS_ERR_IOC_ARG_UNAVAIL an input argument is not supported by kernel
ZFS_ERR_IOC_ARG_REQUIRED a required input argument is missing
ZFS_ERR_IOC_ARG_BADTYPE an input argument has an invalid type

Reviewed-by: Matthew Ahrens <mahrens@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Don Brady <don.brady@delphix.com>
Closes #7780
15 files changed:
cmd/zfs/zfs_main.c
configure.ac
include/libzfs.h
include/sys/fs/zfs.h
lib/libzfs/libzfs_util.c
lib/libzfs_core/libzfs_core.c
module/zfs/zfs_ioctl.c
tests/runfiles/linux.run
tests/zfs-tests/cmd/Makefile.am
tests/zfs-tests/cmd/libzfs_input_check/.gitignore [new file with mode: 0644]
tests/zfs-tests/cmd/libzfs_input_check/Makefile.am [new file with mode: 0644]
tests/zfs-tests/cmd/libzfs_input_check/libzfs_input_check.c [new file with mode: 0644]
tests/zfs-tests/include/commands.cfg
tests/zfs-tests/tests/functional/libzfs/Makefile.am
tests/zfs-tests/tests/functional/libzfs/libzfs_input.ksh [new file with mode: 0755]