From mboxrd@z Thu Jan 1 00:00:00 1970 From: Leon Romanovsky Subject: [RFC PATCH iproute2-next 2/3] rdma: Introduce command execution helper with required device name Date: Thu, 20 Sep 2018 14:22:31 +0300 Message-ID: <20180920112232.9602-3-leon@kernel.org> References: <20180920112232.9602-1-leon@kernel.org> Cc: Leon Romanovsky , netdev , RDMA mailing list , Stephen Hemminger To: David Ahern Return-path: Received: from mail.kernel.org ([198.145.29.99]:58918 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387593AbeITRFo (ORCPT ); Thu, 20 Sep 2018 13:05:44 -0400 In-Reply-To: <20180920112232.9602-1-leon@kernel.org> Sender: netdev-owner@vger.kernel.org List-ID: From: Leon Romanovsky In contradiction to various show commands, the set command explicitly requires to use device name as an argument. Provide new command execution helper which enforces it. Signed-off-by: Leon Romanovsky --- rdma/rdma.h | 1 + rdma/utils.c | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/rdma/rdma.h b/rdma/rdma.h index d4b7ba19..dde9e128 100644 --- a/rdma/rdma.h +++ b/rdma/rdma.h @@ -90,6 +90,7 @@ int cmd_link(struct rd *rd); int cmd_res(struct rd *rd); int rd_exec_cmd(struct rd *rd, const struct rd_cmd *c, const char *str); int rd_exec_dev(struct rd *rd, int (*cb)(struct rd *rd)); +int rd_exec_require_dev(struct rd *rd, int (*cb)(struct rd *rd)); int rd_exec_link(struct rd *rd, int (*cb)(struct rd *rd), bool strict_port); void rd_free(struct rd *rd); int rd_set_arg_to_devname(struct rd *rd); diff --git a/rdma/utils.c b/rdma/utils.c index 4840bf22..61f4aeb1 100644 --- a/rdma/utils.c +++ b/rdma/utils.c @@ -577,6 +577,16 @@ out: return ret; } +int rd_exec_require_dev(struct rd *rd, int (*cb)(struct rd *rd)) +{ + if (rd_no_arg(rd)) { + pr_err("Please provide device name.\n"); + return -EINVAL; + } + + return rd_exec_dev(rd, cb); +} + int rd_exec_cmd(struct rd *rd, const struct rd_cmd *cmds, const char *str) { const struct rd_cmd *c;