Commit 7399b886 authored by Jakub Kicinski's avatar Jakub Kicinski Committed by Jens Axboe

nbd: use the structured req attr check

Use the macro for checking presence of required attributes.
It has the advantage of reporting to the user which attr
was missing in a machine-readable format (extack).
Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
Reviewed-by: default avatarChaitanya Kulkarni <kch@nvidia.com>
Link: https://lore.kernel.org/r/20230224021301.1630703-2-kuba@kernel.orgSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 9195b317
...@@ -1934,11 +1934,11 @@ static int nbd_genl_connect(struct sk_buff *skb, struct genl_info *info) ...@@ -1934,11 +1934,11 @@ static int nbd_genl_connect(struct sk_buff *skb, struct genl_info *info)
return -EINVAL; return -EINVAL;
} }
} }
if (!info->attrs[NBD_ATTR_SOCKETS]) { if (GENL_REQ_ATTR_CHECK(info, NBD_ATTR_SOCKETS)) {
pr_err("must specify at least one socket\n"); pr_err("must specify at least one socket\n");
return -EINVAL; return -EINVAL;
} }
if (!info->attrs[NBD_ATTR_SIZE_BYTES]) { if (GENL_REQ_ATTR_CHECK(info, NBD_ATTR_SIZE_BYTES)) {
pr_err("must specify a size in bytes for the device\n"); pr_err("must specify a size in bytes for the device\n");
return -EINVAL; return -EINVAL;
} }
...@@ -2123,7 +2123,7 @@ static int nbd_genl_disconnect(struct sk_buff *skb, struct genl_info *info) ...@@ -2123,7 +2123,7 @@ static int nbd_genl_disconnect(struct sk_buff *skb, struct genl_info *info)
if (!netlink_capable(skb, CAP_SYS_ADMIN)) if (!netlink_capable(skb, CAP_SYS_ADMIN))
return -EPERM; return -EPERM;
if (!info->attrs[NBD_ATTR_INDEX]) { if (GENL_REQ_ATTR_CHECK(info, NBD_ATTR_INDEX)) {
pr_err("must specify an index to disconnect\n"); pr_err("must specify an index to disconnect\n");
return -EINVAL; return -EINVAL;
} }
...@@ -2161,7 +2161,7 @@ static int nbd_genl_reconfigure(struct sk_buff *skb, struct genl_info *info) ...@@ -2161,7 +2161,7 @@ static int nbd_genl_reconfigure(struct sk_buff *skb, struct genl_info *info)
if (!netlink_capable(skb, CAP_SYS_ADMIN)) if (!netlink_capable(skb, CAP_SYS_ADMIN))
return -EPERM; return -EPERM;
if (!info->attrs[NBD_ATTR_INDEX]) { if (GENL_REQ_ATTR_CHECK(info, NBD_ATTR_INDEX)) {
pr_err("must specify a device to reconfigure\n"); pr_err("must specify a device to reconfigure\n");
return -EINVAL; return -EINVAL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment