All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH iproute2 0/7] Add support for devlink resource abstraction
@ 2018-02-14  8:55 Arkadi Sharshevsky
  2018-02-14  8:55 ` [PATCH iproute2 1/7] devlink: Change empty line indication with indentations Arkadi Sharshevsky
                   ` (8 more replies)
  0 siblings, 9 replies; 18+ messages in thread
From: Arkadi Sharshevsky @ 2018-02-14  8:55 UTC (permalink / raw)
  To: netdev; +Cc: davem, stephen, dsa, mlxsw, Arkadi Sharshevsky

Add support for devlink resource abstraction.

Arkadi Sharshevsky (7):
  devlink: Change empty line indication with indentations
  devlink: mnlg: Add support for extended ack
  devlink: Add support for devlink resource abstraction
  devlink: Add support for hot reload
  devlink: Move dpipe context from heap to stack
  devlink: Add support for resource/dpipe relation
  devlink: Update man pages and add resource man

 devlink/devlink.c           | 774 ++++++++++++++++++++++++++++++++++++++++----
 devlink/mnlg.c              |  53 ++-
 include/libnetlink.h        |   1 +
 include/list.h              |   5 +
 lib/libnetlink.c            |   4 +-
 man/man8/devlink-dev.8      |  15 +
 man/man8/devlink-resource.8 |  78 +++++
 man/man8/devlink.8          |   1 +
 8 files changed, 871 insertions(+), 60 deletions(-)
 create mode 100644 man/man8/devlink-resource.8

-- 
2.4.11

^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH iproute2 1/7] devlink: Change empty line indication with indentations
  2018-02-14  8:55 [PATCH iproute2 0/7] Add support for devlink resource abstraction Arkadi Sharshevsky
@ 2018-02-14  8:55 ` Arkadi Sharshevsky
  2018-02-14 15:11   ` Stephen Hemminger
  2018-02-14  8:55 ` [PATCH iproute2 2/7] devlink: mnlg: Add support for extended ack Arkadi Sharshevsky
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 18+ messages in thread
From: Arkadi Sharshevsky @ 2018-02-14  8:55 UTC (permalink / raw)
  To: netdev; +Cc: davem, stephen, dsa, mlxsw, Arkadi Sharshevsky

Currently multi-line objects are separated by new-lines. This patch
changes this behavior by using indentations for separation.

Signed-off-by: Arkadi Sharhsevsky <arkadis@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
---
 devlink/devlink.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/devlink/devlink.c b/devlink/devlink.c
index 57e71ac..8ef6041 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -35,6 +35,8 @@
 #define ESWITCH_INLINE_MODE_NETWORK "network"
 #define ESWITCH_INLINE_MODE_TRANSPORT "transport"
 
+static int g_new_line_count;
+
 #define pr_err(args...) fprintf(stderr, ##args)
 #define pr_out(args...)						\
 	do {							\
@@ -43,6 +45,7 @@
 			g_indent_newline = false;		\
 		}						\
 		fprintf(stdout, ##args);			\
+		g_new_line_count = 0;				\
 	} while (0)
 
 #define pr_out_sp(num, args...)					\
@@ -50,6 +53,7 @@
 		int ret = fprintf(stdout, ##args);		\
 		if (ret < num)					\
 			fprintf(stdout, "%*s", num - ret, "");	\
+		g_new_line_count = 0;				\
 	} while (0)
 
 static int g_indent_level;
@@ -77,8 +81,11 @@ static void __pr_out_indent_dec(void)
 
 static void __pr_out_newline(void)
 {
-	pr_out("\n");
-	g_indent_newline = true;
+	if (g_new_line_count < 1) {
+		pr_out("\n");
+		g_indent_newline = true;
+	}
+	g_new_line_count++;
 }
 
 static int _mnlg_socket_recv_run(struct mnlg_socket *nlg,
@@ -1401,20 +1408,22 @@ static void pr_out_array_start(struct dl *dl, const char *name)
 		jsonw_name(dl->jw, name);
 		jsonw_start_array(dl->jw);
 	} else {
-		if (!g_indent_newline)
-			__pr_out_newline();
-		pr_out("%s:", name);
+		__pr_out_indent_inc();
 		__pr_out_newline();
+		pr_out("%s:", name);
 		__pr_out_indent_inc();
+		__pr_out_newline();
 	}
 }
 
 static void pr_out_array_end(struct dl *dl)
 {
-	if (dl->json_output)
+	if (dl->json_output) {
 		jsonw_end_array(dl->jw);
-	else
+	} else {
+		__pr_out_indent_dec();
 		__pr_out_indent_dec();
+	}
 }
 
 static void pr_out_entry_start(struct dl *dl)
-- 
2.4.11

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH iproute2 2/7] devlink: mnlg: Add support for extended ack
  2018-02-14  8:55 [PATCH iproute2 0/7] Add support for devlink resource abstraction Arkadi Sharshevsky
  2018-02-14  8:55 ` [PATCH iproute2 1/7] devlink: Change empty line indication with indentations Arkadi Sharshevsky
@ 2018-02-14  8:55 ` Arkadi Sharshevsky
  2018-02-14 15:12   ` Stephen Hemminger
  2018-02-14  8:55 ` [PATCH iproute2 3/7] devlink: Add support for devlink resource abstraction Arkadi Sharshevsky
                   ` (6 subsequent siblings)
  8 siblings, 1 reply; 18+ messages in thread
From: Arkadi Sharshevsky @ 2018-02-14  8:55 UTC (permalink / raw)
  To: netdev; +Cc: davem, stephen, dsa, mlxsw, Arkadi Sharshevsky

Add support for extended ack.

Signed-off-by: Arkadi Sharshevsky <arkadis@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
---
 devlink/mnlg.c       | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 include/libnetlink.h |  1 +
 lib/libnetlink.c     |  4 ++--
 3 files changed, 54 insertions(+), 4 deletions(-)

diff --git a/devlink/mnlg.c b/devlink/mnlg.c
index 9e27de2..37c5687 100644
--- a/devlink/mnlg.c
+++ b/devlink/mnlg.c
@@ -18,6 +18,8 @@
 #include <libmnl/libmnl.h>
 #include <linux/genetlink.h>
 
+#include "libnetlink.h"
+#include "utils.h"
 #include "mnlg.h"
 
 struct mnlg_socket {
@@ -60,6 +62,39 @@ int mnlg_socket_send(struct mnlg_socket *nlg, const struct nlmsghdr *nlh)
 	return mnl_socket_sendto(nlg->nl, nlh, nlh->nlmsg_len);
 }
 
+static int mnlg_cb_noop(const struct nlmsghdr *nlh, void *data)
+{
+	return MNL_CB_OK;
+}
+
+static int mnlg_cb_error(const struct nlmsghdr *nlh, void *data)
+{
+	const struct nlmsgerr *err = mnl_nlmsg_get_payload(nlh);
+
+	if (nl_dump_ext_ack(nlh, NULL))
+		return MNL_CB_STOP;
+
+	/* Netlink subsystems returns the errno value with different signess */
+	if (err->error < 0)
+		errno = -err->error;
+	else
+		errno = err->error;
+
+	return err->error == 0 ? MNL_CB_STOP : MNL_CB_ERROR;
+}
+
+static int mnlg_cb_stop(const struct nlmsghdr *nlh, void *data)
+{
+	return MNL_CB_STOP;
+}
+
+static mnl_cb_t mnlg_cb_array[NLMSG_MIN_TYPE] = {
+	[NLMSG_NOOP]	= mnlg_cb_noop,
+	[NLMSG_ERROR]	= mnlg_cb_error,
+	[NLMSG_DONE]	= mnlg_cb_stop,
+	[NLMSG_OVERRUN]	= mnlg_cb_noop,
+};
+
 int mnlg_socket_recv_run(struct mnlg_socket *nlg, mnl_cb_t data_cb, void *data)
 {
 	int err;
@@ -69,8 +104,9 @@ int mnlg_socket_recv_run(struct mnlg_socket *nlg, mnl_cb_t data_cb, void *data)
 					  MNL_SOCKET_BUFFER_SIZE);
 		if (err <= 0)
 			break;
-		err = mnl_cb_run(nlg->buf, err, nlg->seq, nlg->portid,
-				 data_cb, data);
+		err = mnl_cb_run2(nlg->buf, err, nlg->seq, nlg->portid,
+				  data_cb, data, mnlg_cb_array,
+				  ARRAY_SIZE(mnlg_cb_array));
 	} while (err > 0);
 
 	return err;
@@ -220,6 +256,7 @@ struct mnlg_socket *mnlg_socket_open(const char *family_name, uint8_t version)
 {
 	struct mnlg_socket *nlg;
 	struct nlmsghdr *nlh;
+	int one = 1;
 	int err;
 
 	nlg = malloc(sizeof(*nlg));
@@ -234,6 +271,16 @@ struct mnlg_socket *mnlg_socket_open(const char *family_name, uint8_t version)
 	if (!nlg->nl)
 		goto err_mnl_socket_open;
 
+	err = mnl_socket_setsockopt(nlg->nl, NETLINK_CAP_ACK, &one,
+				    sizeof(one));
+	if (err)
+		goto err_mnl_set_ack;
+
+	err = mnl_socket_setsockopt(nlg->nl, NETLINK_EXT_ACK, &one,
+				    sizeof(one));
+	if (err)
+		goto err_mnl_set_ext_ack;
+
 	err = mnl_socket_bind(nlg->nl, 0, MNL_SOCKET_AUTOPID);
 	if (err < 0)
 		goto err_mnl_socket_bind;
@@ -258,6 +305,8 @@ struct mnlg_socket *mnlg_socket_open(const char *family_name, uint8_t version)
 err_mnlg_socket_recv_run:
 err_mnlg_socket_send:
 err_mnl_socket_bind:
+err_mnl_set_ext_ack:
+err_mnl_set_ack:
 	mnl_socket_close(nlg->nl);
 err_mnl_socket_open:
 	free(nlg->buf);
diff --git a/include/libnetlink.h b/include/libnetlink.h
index d632219..9d9249e 100644
--- a/include/libnetlink.h
+++ b/include/libnetlink.h
@@ -109,6 +109,7 @@ int rtnl_send(struct rtnl_handle *rth, const void *buf, int)
 	__attribute__((warn_unused_result));
 int rtnl_send_check(struct rtnl_handle *rth, const void *buf, int)
 	__attribute__((warn_unused_result));
+int nl_dump_ext_ack(const struct nlmsghdr *nlh, nl_ext_ack_fn_t errfn);
 
 int addattr(struct nlmsghdr *n, int maxlen, int type);
 int addattr8(struct nlmsghdr *n, int maxlen, int type, __u8 data);
diff --git a/lib/libnetlink.c b/lib/libnetlink.c
index 7ca47b2..8bb1c8d 100644
--- a/lib/libnetlink.c
+++ b/lib/libnetlink.c
@@ -65,7 +65,7 @@ static int err_attr_cb(const struct nlattr *attr, void *data)
 }
 
 /* dump netlink extended ack error message */
-static int nl_dump_ext_ack(const struct nlmsghdr *nlh, nl_ext_ack_fn_t errfn)
+int nl_dump_ext_ack(const struct nlmsghdr *nlh, nl_ext_ack_fn_t errfn)
 {
 	struct nlattr *tb[NLMSGERR_ATTR_MAX + 1] = {};
 	const struct nlmsgerr *err = mnl_nlmsg_get_payload(nlh);
@@ -120,7 +120,7 @@ static int nl_dump_ext_ack(const struct nlmsghdr *nlh, nl_ext_ack_fn_t errfn)
 #warning "libmnl required for error support"
 
 /* No extended error ack without libmnl */
-static int nl_dump_ext_ack(const struct nlmsghdr *nlh, nl_ext_ack_fn_t errfn)
+int nl_dump_ext_ack(const struct nlmsghdr *nlh, nl_ext_ack_fn_t errfn)
 {
 	return 0;
 }
-- 
2.4.11

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH iproute2 3/7] devlink: Add support for devlink resource abstraction
  2018-02-14  8:55 [PATCH iproute2 0/7] Add support for devlink resource abstraction Arkadi Sharshevsky
  2018-02-14  8:55 ` [PATCH iproute2 1/7] devlink: Change empty line indication with indentations Arkadi Sharshevsky
  2018-02-14  8:55 ` [PATCH iproute2 2/7] devlink: mnlg: Add support for extended ack Arkadi Sharshevsky
@ 2018-02-14  8:55 ` Arkadi Sharshevsky
  2018-02-14  8:55 ` [PATCH iproute2 4/7] devlink: Add support for hot reload Arkadi Sharshevsky
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 18+ messages in thread
From: Arkadi Sharshevsky @ 2018-02-14  8:55 UTC (permalink / raw)
  To: netdev; +Cc: davem, stephen, dsa, mlxsw, Arkadi Sharshevsky

Add support for devlink resource abstraction. The resources are
represented by a tree based structure and are identified by a name and
a size. Some resources can present their real time occupancy.

First the resources exposed by the driver can be observed, for example:

$devlink resource show pci/0000:03:00.0
pci/0000:03:00.0:
  name kvd size 245760 unit entry
    resources:
      name linear size 98304 occ 0 unit entry size_min 0 size_max 147456 size_gran 128
      name hash_double size 60416 unit entry size_min 32768 size_max 180224 size_gran 128
      name hash_single size 87040 unit entry size_min 65536 size_max 212992 size_gran 128

Some resource's size can be changed. Examples:

$devlink resource set pci/0000:03:00.0 path /kvd/hash_single size 73088
$devlink resource set pci/0000:03:00.0 path /kvd/hash_double size 74368

The changes do not apply immediately, this can be validate by the 'size_new'
attribute, which represents the pending changed size. For example

$devlink resource show pci/0000:03:00.0
pci/0000:03:00.0:
  name kvd size 245760 unit entry size_valid false
  resources:
    name linear size 98304 size_new 147456 occ 0 unit entry size_min 0 size_max 147456 size_gran 128
    name hash_double size 60416 unit entry size_min 32768 size_max 180224 size_gran 128
    name hash_single size 87040 unit entry size_min 65536 size_max 212992 size_gran 128

In case of a pending change the nested resources present an indication
for a valid configuration of its children (sum of its children sizes
doesn't exceed the parent's size).

In order for the changes to take place hot reload is needed. The hot
reload through devlink will be introduced in the following patch.

Signed-off-by: Arkadi Sharshevsky <arkadis@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
---
 devlink/devlink.c | 490 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 include/list.h    |   5 +
 2 files changed, 494 insertions(+), 1 deletion(-)

diff --git a/devlink/devlink.c b/devlink/devlink.c
index 8ef6041..4c392a7 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -185,6 +185,8 @@ static void ifname_map_free(struct ifname_map *ifname_map)
 #define DL_OPT_DPIPE_TABLE_NAME	BIT(13)
 #define DL_OPT_DPIPE_TABLE_COUNTERS	BIT(14)
 #define DL_OPT_ESWITCH_ENCAP_MODE	BIT(15)
+#define DL_OPT_RESOURCE_PATH	BIT(16)
+#define DL_OPT_RESOURCE_SIZE	BIT(17)
 
 struct dl_opts {
 	uint32_t present; /* flags of present items */
@@ -205,6 +207,10 @@ struct dl_opts {
 	const char *dpipe_table_name;
 	bool dpipe_counters_enable;
 	bool eswitch_encap_mode;
+	const char *resource_path;
+	uint32_t resource_size;
+	uint32_t resource_id;
+	bool resource_id_valid;
 };
 
 struct dl {
@@ -953,6 +959,20 @@ static int dl_argv_parse(struct dl *dl, uint32_t o_required,
 			if (err)
 				return err;
 			o_found |= DL_OPT_ESWITCH_ENCAP_MODE;
+		} else if (dl_argv_match(dl, "path") &&
+			   (o_all & DL_OPT_RESOURCE_PATH)) {
+			dl_arg_inc(dl);
+			err = dl_argv_str(dl, &opts->resource_path);
+			if (err)
+				return err;
+			o_found |= DL_OPT_RESOURCE_PATH;
+		} else if (dl_argv_match(dl, "size") &&
+			   (o_all & DL_OPT_RESOURCE_SIZE)) {
+			dl_arg_inc(dl);
+			err = dl_argv_uint32_t(dl, &opts->resource_size);
+			if (err)
+				return err;
+			o_found |= DL_OPT_RESOURCE_SIZE;
 		} else {
 			pr_err("Unknown option \"%s\"\n", dl_argv(dl));
 			return -EINVAL;
@@ -1095,6 +1115,12 @@ static void dl_opts_put(struct nlmsghdr *nlh, struct dl *dl)
 	if (opts->present & DL_OPT_ESWITCH_ENCAP_MODE)
 		mnl_attr_put_u8(nlh, DEVLINK_ATTR_ESWITCH_ENCAP_MODE,
 				opts->eswitch_encap_mode);
+	if ((opts->present & DL_OPT_RESOURCE_PATH) && opts->resource_id_valid)
+		mnl_attr_put_u64(nlh, DEVLINK_ATTR_RESOURCE_ID,
+				 opts->resource_id);
+	if (opts->present & DL_OPT_RESOURCE_SIZE)
+		mnl_attr_put_u64(nlh, DEVLINK_ATTR_RESOURCE_SIZE,
+				 opts->resource_size);
 }
 
 static int dl_argv_parse_put(struct nlmsghdr *nlh, struct dl *dl,
@@ -2684,6 +2710,91 @@ struct dpipe_header {
 	unsigned int fields_count;
 };
 
+struct resource {
+	char *name;
+	uint64_t size;
+	uint64_t size_new;
+	uint64_t size_min;
+	uint64_t size_max;
+	uint64_t size_gran;
+	enum devlink_resource_unit unit;
+	bool size_valid;
+	uint64_t size_occ;
+	bool occ_valid;
+	uint64_t id;
+	struct list_head list;
+	struct list_head resource_list;
+	struct resource *parent;
+};
+
+struct resources {
+	struct list_head resource_list;
+};
+
+struct resource_ctx {
+	struct dl *dl;
+	int err;
+	struct resources *resources;
+	bool print_resources;
+	bool pending_change;
+};
+
+static struct resource *resource_alloc(void)
+{
+	struct resource *resource;
+
+	resource = calloc(1, sizeof(struct resource));
+	if (!resource)
+		return NULL;
+	INIT_LIST_HEAD(&resource->resource_list);
+	return resource;
+}
+
+static void resource_free(struct resource *resource)
+{
+	struct resource *child_resource, *tmp;
+
+	list_for_each_entry_safe(child_resource, tmp, &resource->resource_list,
+				 list) {
+		free(child_resource->name);
+		resource_free(child_resource);
+	}
+	free(resource);
+}
+
+static struct resources *resources_alloc(void)
+{
+	struct resources *resources;
+
+	resources = calloc(1, sizeof(struct resources));
+	if (!resources)
+		return NULL;
+	INIT_LIST_HEAD(&resources->resource_list);
+	return resources;
+}
+
+static void resources_free(struct resources *resources)
+{
+	struct resource *resource, *tmp;
+
+	list_for_each_entry_safe(resource, tmp, &resources->resource_list, list)
+		resource_free(resource);
+}
+
+static int resource_ctx_init(struct resource_ctx *ctx, struct dl *dl)
+{
+	ctx->resources = resources_alloc();
+	if (!ctx->resources)
+		return -ENOMEM;
+	ctx->dl = dl;
+	return 0;
+}
+
+static void resource_ctx_fini(struct resource_ctx *ctx)
+{
+	resources_free(ctx->resources);
+}
+
 struct dpipe_ctx {
 	struct dl *dl;
 	int err;
@@ -3248,6 +3359,66 @@ err_match_parse:
 	return -EINVAL;
 }
 
+static struct resource *
+resource_find(struct resources *resources, struct resource *resource,
+	      uint64_t resource_id)
+{
+	struct list_head *list_head;
+
+	if (!resource)
+		list_head = &resources->resource_list;
+	else
+		list_head = &resource->resource_list;
+
+	list_for_each_entry(resource, list_head, list) {
+		struct resource *child_resource;
+
+		if (resource->id == resource_id)
+			return resource;
+
+		child_resource = resource_find(resources, resource,
+					       resource_id);
+		if (child_resource)
+			return child_resource;
+	}
+	return NULL;
+}
+
+static void
+resource_path_print(struct dl *dl, struct resources *resources,
+		    uint64_t resource_id)
+{
+	struct resource *resource, *parent_resource;
+	const char del[] = "/";
+	int path_len = 0;
+	char *path;
+
+	resource = resource_find(resources, NULL, resource_id);
+	if (!resource)
+		return;
+
+	for (parent_resource = resource; parent_resource;
+	     parent_resource = parent_resource->parent)
+		path_len += strlen(parent_resource->name) + 1;
+
+	path_len++;
+	path = calloc(1, path_len);
+	if (!path)
+		return;
+
+	path += path_len - 1;
+	for (parent_resource = resource; parent_resource;
+		parent_resource = parent_resource->parent) {
+		path -= strlen(parent_resource->name);
+		memcpy(path, parent_resource->name,
+		       strlen(parent_resource->name));
+		path -= strlen(del);
+		memcpy(path, del, strlen(del));
+	}
+	pr_out_str(dl, "resource_path", path);
+	free(path);
+}
+
 static int dpipe_table_show(struct dpipe_ctx *ctx, struct nlattr *nl)
 {
 	struct nlattr *nla_table[DEVLINK_ATTR_MAX + 1] = {};
@@ -3810,11 +3981,325 @@ static int cmd_dpipe(struct dl *dl)
 	return -ENOENT;
 }
 
+static int
+resource_parse(struct resource_ctx *ctx, struct resource *resource,
+	       struct nlattr **nla_resource)
+{
+	if (!nla_resource[DEVLINK_ATTR_RESOURCE_NAME] ||
+	    !nla_resource[DEVLINK_ATTR_RESOURCE_SIZE] ||
+	    !nla_resource[DEVLINK_ATTR_RESOURCE_ID] ||
+	    !nla_resource[DEVLINK_ATTR_RESOURCE_UNIT] ||
+	    !nla_resource[DEVLINK_ATTR_RESOURCE_SIZE_MIN] ||
+	    !nla_resource[DEVLINK_ATTR_RESOURCE_SIZE_MAX] ||
+	    !nla_resource[DEVLINK_ATTR_RESOURCE_SIZE_GRAN]) {
+		return -EINVAL;
+	}
+
+	resource->name = strdup(mnl_attr_get_str(nla_resource[DEVLINK_ATTR_RESOURCE_NAME]));
+	resource->size = mnl_attr_get_u64(nla_resource[DEVLINK_ATTR_RESOURCE_SIZE]);
+	resource->id = mnl_attr_get_u64(nla_resource[DEVLINK_ATTR_RESOURCE_ID]);
+	resource->unit = mnl_attr_get_u8(nla_resource[DEVLINK_ATTR_RESOURCE_UNIT]);
+	resource->size_min = mnl_attr_get_u64(nla_resource[DEVLINK_ATTR_RESOURCE_SIZE_MIN]);
+	resource->size_max = mnl_attr_get_u64(nla_resource[DEVLINK_ATTR_RESOURCE_SIZE_MAX]);
+	resource->size_gran = mnl_attr_get_u64(nla_resource[DEVLINK_ATTR_RESOURCE_SIZE_GRAN]);
+
+	if (nla_resource[DEVLINK_ATTR_RESOURCE_SIZE_NEW])
+		resource->size_new = mnl_attr_get_u64(nla_resource[DEVLINK_ATTR_RESOURCE_SIZE_NEW]);
+	else
+		resource->size_new = resource->size;
+
+	if (nla_resource[DEVLINK_ATTR_RESOURCE_OCC]) {
+		resource->size_occ = mnl_attr_get_u64(nla_resource[DEVLINK_ATTR_RESOURCE_OCC]);
+		resource->occ_valid = true;
+	}
+
+	if (resource->size_new != resource->size)
+		ctx->pending_change = true;
+
+	return 0;
+}
+
+static int
+resource_get(struct resource_ctx *ctx, struct resource *resource,
+	     struct resource *parent_resource, struct nlattr *nl)
+{
+	struct nlattr *nla_resource[DEVLINK_ATTR_MAX + 1] = {};
+	struct nlattr *nla_child_resource;
+	struct nlattr *nla_resources;
+	bool top = false;
+	int err;
+
+	if (!resource) {
+		nla_resources = nl;
+		top = true;
+		goto out;
+	}
+
+	err = mnl_attr_parse_nested(nl, attr_cb, nla_resource);
+	if (err != MNL_CB_OK)
+		return -EINVAL;
+
+	err = resource_parse(ctx, resource, nla_resource);
+	if (err)
+		return err;
+
+	resource->parent = parent_resource;
+	if (!nla_resource[DEVLINK_ATTR_RESOURCE_LIST])
+		return 0;
+
+	resource->size_valid = !!mnl_attr_get_u8(nla_resource[DEVLINK_ATTR_RESOURCE_SIZE_VALID]);
+	nla_resources = nla_resource[DEVLINK_ATTR_RESOURCE_LIST];
+out:
+	mnl_attr_for_each_nested(nla_child_resource, nla_resources) {
+		struct resource *child_resource;
+		struct list_head *list;
+
+		child_resource = resource_alloc();
+		if (!child_resource)
+			return -ENOMEM;
+
+		if (top)
+			list = &ctx->resources->resource_list;
+		else
+			list = &resource->resource_list;
+
+		list_add_tail(&child_resource->list, list);
+		err = resource_get(ctx, child_resource, resource,
+				   nla_child_resource);
+		if (err)
+			return err;
+	}
+
+	return 0;
+}
+
+static const char *resource_unit_str_get(enum devlink_resource_unit unit)
+{
+	switch (unit) {
+	case DEVLINK_RESOURCE_UNIT_ENTRY: return "entry";
+	default: return "<unknown unit>";
+	}
+}
+
+static void resource_show(struct resource *resource,
+			  struct resource_ctx *ctx)
+{
+	struct resource *child_resource;
+	struct dl *dl = ctx->dl;
+
+	pr_out_str(dl, "name", resource->name);
+	if (dl->verbose)
+		resource_path_print(dl, ctx->resources, resource->id);
+	pr_out_uint(dl, "size", resource->size);
+	if (resource->size != resource->size_new)
+		pr_out_uint(dl, "size_new", resource->size_new);
+	if (resource->occ_valid)
+		pr_out_uint(dl, "occ", resource->size_occ);
+	pr_out_str(dl, "unit", resource_unit_str_get(resource->unit));
+
+	if (resource->size_min != resource->size_max) {
+		pr_out_uint(dl, "size_min", resource->size_min);
+		pr_out_uint(dl, "size_max", resource->size_max);
+		pr_out_uint(dl, "size_gran", resource->size_gran);
+	}
+
+	if (list_empty(&resource->resource_list))
+		return;
+
+	if (ctx->pending_change)
+		pr_out_str(dl, "size_valid", resource->size_valid ?
+			   "true" : "false");
+	pr_out_array_start(dl, "resources");
+	list_for_each_entry(child_resource, &resource->resource_list, list) {
+		pr_out_entry_start(dl);
+		resource_show(child_resource, ctx);
+		pr_out_entry_end(dl);
+	}
+	pr_out_array_end(dl);
+}
+
+static void
+resources_show(struct resource_ctx *ctx, struct nlattr **tb)
+{
+	struct resources *resources = ctx->resources;
+	struct resource *resource;
+
+	list_for_each_entry(resource, &resources->resource_list, list) {
+		pr_out_handle_start_arr(ctx->dl, tb);
+		resource_show(resource, ctx);
+		pr_out_handle_end(ctx->dl);
+	}
+}
+
+static int resources_get(struct resource_ctx *ctx, struct nlattr **tb)
+{
+	return resource_get(ctx, NULL, NULL, tb[DEVLINK_ATTR_RESOURCE_LIST]);
+}
+
+static int cmd_resource_dump_cb(const struct nlmsghdr *nlh, void *data)
+{
+	struct resource_ctx *ctx = data;
+	struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
+	struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
+	int err;
+
+	mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
+	if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] ||
+	    !tb[DEVLINK_ATTR_RESOURCE_LIST])
+		return MNL_CB_ERROR;
+
+	err = resources_get(ctx, tb);
+	if (err) {
+		ctx->err = err;
+		return MNL_CB_ERROR;
+	}
+
+	if (ctx->print_resources)
+		resources_show(ctx, tb);
+
+	return MNL_CB_OK;
+}
+
+static int cmd_resource_show(struct dl *dl)
+{
+	struct nlmsghdr *nlh;
+	struct resource_ctx ctx = {};
+	int err;
+
+	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_RESOURCE_DUMP,
+			       NLM_F_REQUEST | NLM_F_ACK);
+
+	err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE, 0);
+	if (err)
+		return err;
+
+	err = resource_ctx_init(&ctx, dl);
+	if (err)
+		return err;
+
+	ctx.print_resources = true;
+	pr_out_section_start(dl, "resources");
+	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_resource_dump_cb, &ctx);
+	pr_out_section_end(dl);
+	resource_ctx_fini(&ctx);
+	return err;
+}
+
+static void cmd_resource_help(void)
+{
+	pr_err("Usage: devlink resource show DEV\n"
+	       "       devlink resource set DEV path PATH size SIZE\n");
+}
+
+static struct resource *
+resource_find_by_name(struct list_head *list, char *name)
+{
+	struct resource *resource;
+
+	list_for_each_entry(resource, list, list) {
+		if (!strcmp(resource->name, name))
+			return resource;
+	}
+	return NULL;
+}
+
+static int
+resource_path_parse(struct resource_ctx *ctx, const char *resource_path,
+		    uint32_t *p_resource_id, bool *p_resource_valid)
+{
+	struct resource *resource;
+	uint32_t resource_id = 0;
+	char *resource_path_dup;
+	struct list_head *list;
+	const char del[] = "/";
+	char *resource_name;
+
+	resource_path_dup = strdup(resource_path);
+	list = &ctx->resources->resource_list;
+	resource_name = strtok(resource_path_dup, del);
+	while (resource_name != NULL) {
+		resource = resource_find_by_name(list, resource_name);
+		if (!resource)
+			goto err_resource_lookup;
+
+		list = &resource->resource_list;
+		resource_name = strtok(NULL, del);
+		resource_id = resource->id;
+	}
+	free(resource_path_dup);
+	*p_resource_valid = true;
+	*p_resource_id = resource_id;
+	return 0;
+
+err_resource_lookup:
+	free(resource_path_dup);
+	return -EINVAL;
+}
+
+static int cmd_resource_set(struct dl *dl)
+{
+	struct nlmsghdr *nlh;
+	struct resource_ctx ctx = {};
+	int err;
+
+	err = resource_ctx_init(&ctx, dl);
+	if (err)
+		return err;
+
+	ctx.print_resources = false;
+	err = dl_argv_parse(dl, DL_OPT_HANDLE | DL_OPT_RESOURCE_PATH |
+			    DL_OPT_RESOURCE_SIZE, 0);
+	if (err)
+		goto out;
+
+	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_RESOURCE_DUMP,
+			       NLM_F_REQUEST);
+	dl_opts_put(nlh, dl);
+	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_resource_dump_cb, &ctx);
+	if (err) {
+		pr_err("error getting resources %s\n", strerror(ctx.err));
+		goto out;
+	}
+
+	err = resource_path_parse(&ctx, dl->opts.resource_path,
+				  &dl->opts.resource_id,
+				  &dl->opts.resource_id_valid);
+	if (err) {
+		pr_err("error parsing resource path %s\n", strerror(err));
+		goto out;
+	}
+
+	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_RESOURCE_SET,
+			       NLM_F_REQUEST | NLM_F_ACK);
+
+	dl_opts_put(nlh, dl);
+	err = _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
+out:
+	resource_ctx_fini(&ctx);
+	return err;
+}
+
+static int cmd_resource(struct dl *dl)
+{
+	if (dl_argv_match(dl, "help") || dl_no_arg(dl)) {
+		cmd_resource_help();
+		return 0;
+	} else if (dl_argv_match(dl, "show")) {
+		dl_arg_inc(dl);
+		return cmd_resource_show(dl);
+	} else if (dl_argv_match(dl, "set")) {
+		dl_arg_inc(dl);
+		return cmd_resource_set(dl);
+	}
+	pr_err("Command \"%s\" not found\n", dl_argv(dl));
+	return -ENOENT;
+}
+
 static void help(void)
 {
 	pr_err("Usage: devlink [ OPTIONS ] OBJECT { COMMAND | help }\n"
 	       "       devlink [ -f[orce] ] -b[atch] filename\n"
-	       "where  OBJECT := { dev | port | sb | monitor | dpipe }\n"
+	       "where  OBJECT := { dev | port | sb | monitor | dpipe | resource }\n"
 	       "       OPTIONS := { -V[ersion] | -n[no-nice-names] | -j[json] | -p[pretty] | -v[verbose] }\n");
 }
 
@@ -3841,6 +4326,9 @@ static int dl_cmd(struct dl *dl, int argc, char **argv)
 	} else if (dl_argv_match(dl, "dpipe")) {
 		dl_arg_inc(dl);
 		return cmd_dpipe(dl);
+	} else if (dl_argv_match(dl, "resource")) {
+		dl_arg_inc(dl);
+		return cmd_resource(dl);
 	}
 	pr_err("Object \"%s\" not found\n", dl_argv(dl));
 	return -ENOENT;
diff --git a/include/list.h b/include/list.h
index 5af737c..5d86b13 100644
--- a/include/list.h
+++ b/include/list.h
@@ -108,6 +108,11 @@ static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
 	n->pprev = &h->first;
 }
 
+static inline int list_empty(const struct list_head *head)
+{
+	return head->next == head;
+}
+
 #define hlist_for_each(pos, head) \
 	for (pos = (head)->first; pos ; pos = pos->next)
 
-- 
2.4.11

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH iproute2 4/7] devlink: Add support for hot reload
  2018-02-14  8:55 [PATCH iproute2 0/7] Add support for devlink resource abstraction Arkadi Sharshevsky
                   ` (2 preceding siblings ...)
  2018-02-14  8:55 ` [PATCH iproute2 3/7] devlink: Add support for devlink resource abstraction Arkadi Sharshevsky
@ 2018-02-14  8:55 ` Arkadi Sharshevsky
  2018-02-14  8:55 ` [PATCH iproute2 5/7] devlink: Move dpipe context from heap to stack Arkadi Sharshevsky
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 18+ messages in thread
From: Arkadi Sharshevsky @ 2018-02-14  8:55 UTC (permalink / raw)
  To: netdev; +Cc: davem, stephen, dsa, mlxsw, Arkadi Sharshevsky

Add support for hot reload. It should be used in order for resource
updates to take place.

Signed-off-by: Arkadi Sharshevsky <arkadis@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
---
 devlink/devlink.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/devlink/devlink.c b/devlink/devlink.c
index 4c392a7..21835d9 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -1179,6 +1179,7 @@ static void cmd_dev_help(void)
 	pr_err("                               [ inline-mode { none | link | network | transport } ]\n");
 	pr_err("                               [ encap { disable | enable } ]\n");
 	pr_err("       devlink dev eswitch show DEV\n");
+	pr_err("       devlink dev reload DEV\n");
 }
 
 static bool cmp_arr_last_handle(struct dl *dl, const char *bus_name,
@@ -1620,6 +1621,31 @@ static int cmd_dev_show(struct dl *dl)
 	return err;
 }
 
+static void cmd_dev_reload_help(void)
+{
+	pr_err("Usage: devlink dev reload [ DEV ]\n");
+}
+
+static int cmd_dev_reload(struct dl *dl)
+{
+	struct nlmsghdr *nlh;
+	int err;
+
+	if (dl_argv_match(dl, "help") || dl_no_arg(dl)) {
+		cmd_dev_reload_help();
+		return 0;
+	}
+
+	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_RELOAD,
+			       NLM_F_REQUEST | NLM_F_ACK);
+
+	err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE, 0);
+	if (err)
+		return err;
+
+	return _mnlg_socket_sndrcv(dl->nlg, nlh, NULL, NULL);
+}
+
 static int cmd_dev(struct dl *dl)
 {
 	if (dl_argv_match(dl, "help")) {
@@ -1632,6 +1658,9 @@ static int cmd_dev(struct dl *dl)
 	} else if (dl_argv_match(dl, "eswitch")) {
 		dl_arg_inc(dl);
 		return cmd_dev_eswitch(dl);
+	} else if (dl_argv_match(dl, "reload")) {
+		dl_arg_inc(dl);
+		return cmd_dev_reload(dl);
 	}
 	pr_err("Command \"%s\" not found\n", dl_argv(dl));
 	return -ENOENT;
-- 
2.4.11

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH iproute2 5/7] devlink: Move dpipe context from heap to stack
  2018-02-14  8:55 [PATCH iproute2 0/7] Add support for devlink resource abstraction Arkadi Sharshevsky
                   ` (3 preceding siblings ...)
  2018-02-14  8:55 ` [PATCH iproute2 4/7] devlink: Add support for hot reload Arkadi Sharshevsky
@ 2018-02-14  8:55 ` Arkadi Sharshevsky
  2018-02-14  8:55 ` [PATCH iproute2 6/7] devlink: Add support for resource/dpipe relation Arkadi Sharshevsky
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 18+ messages in thread
From: Arkadi Sharshevsky @ 2018-02-14  8:55 UTC (permalink / raw)
  To: netdev; +Cc: davem, stephen, dsa, mlxsw, Arkadi Sharshevsky

Move dpipe context to stack instead of dynamically.

Signed-off-by: Arkadi Sharshevsky <arkadis@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
---
 devlink/devlink.c | 67 ++++++++++++++++++++++---------------------------------
 1 file changed, 27 insertions(+), 40 deletions(-)

diff --git a/devlink/devlink.c b/devlink/devlink.c
index 21835d9..aec36ff 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -2882,25 +2882,15 @@ static void dpipe_header_del(struct dpipe_header *header)
 	list_del(&header->list);
 }
 
-static struct dpipe_ctx *dpipe_ctx_alloc(struct dl *dl)
+static int dpipe_ctx_init(struct dpipe_ctx *ctx, struct dl *dl)
 {
-	struct dpipe_ctx *ctx;
-
-	ctx = calloc(1, sizeof(struct dpipe_ctx));
-	if (!ctx)
-		return NULL;
 	ctx->dl = dl;
 	INIT_LIST_HEAD(&ctx->global_headers);
 	INIT_LIST_HEAD(&ctx->local_headers);
-	return ctx;
-}
-
-static void dpipe_ctx_free(struct dpipe_ctx *ctx)
-{
-	free(ctx);
+	return 0;
 }
 
-static void dpipe_ctx_clear(struct dpipe_ctx *ctx)
+static void dpipe_ctx_fini(struct dpipe_ctx *ctx)
 {
 	struct dpipe_header *header, *tmp;
 
@@ -3171,7 +3161,7 @@ static int cmd_dpipe_header_cb(const struct nlmsghdr *nlh, void *data)
 static int cmd_dpipe_headers_show(struct dl *dl)
 {
 	struct nlmsghdr *nlh;
-	struct dpipe_ctx *ctx;
+	struct dpipe_ctx ctx = {};
 	uint16_t flags = NLM_F_REQUEST | NLM_F_ACK;
 	int err;
 
@@ -3181,20 +3171,19 @@ static int cmd_dpipe_headers_show(struct dl *dl)
 	if (err)
 		return err;
 
-	ctx = dpipe_ctx_alloc(dl);
-	if (!ctx)
-		return -ENOMEM;
+	err = dpipe_ctx_init(&ctx, dl);
+	if (err)
+		return err;
 
-	ctx->print_headers = true;
+	ctx.print_headers = true;
 
 	pr_out_section_start(dl, "header");
-	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dpipe_header_cb, ctx);
+	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dpipe_header_cb, &ctx);
 	if (err)
-		pr_err("error get headers %s\n", strerror(ctx->err));
+		pr_err("error get headers %s\n", strerror(ctx.err));
 	pr_out_section_end(dl);
 
-	dpipe_ctx_clear(ctx);
-	dpipe_ctx_free(ctx);
+	dpipe_ctx_fini(&ctx);
 	return err;
 }
 
@@ -3532,13 +3521,13 @@ static int cmd_dpipe_table_show_cb(const struct nlmsghdr *nlh, void *data)
 static int cmd_dpipe_table_show(struct dl *dl)
 {
 	struct nlmsghdr *nlh;
-	struct dpipe_ctx *ctx;
+	struct dpipe_ctx ctx = {};
 	uint16_t flags = NLM_F_REQUEST;
 	int err;
 
-	ctx = dpipe_ctx_alloc(dl);
-	if (!ctx)
-		return -ENOMEM;
+	err = dpipe_ctx_init(&ctx, dl);
+	if (err)
+		return err;
 
 	err = dl_argv_parse(dl, DL_OPT_HANDLE, DL_OPT_DPIPE_TABLE_NAME);
 	if (err)
@@ -3546,9 +3535,9 @@ static int cmd_dpipe_table_show(struct dl *dl)
 
 	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_DPIPE_HEADERS_GET, flags);
 	dl_opts_put(nlh, dl);
-	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dpipe_header_cb, ctx);
+	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dpipe_header_cb, &ctx);
 	if (err) {
-		pr_err("error get headers %s\n", strerror(ctx->err));
+		pr_err("error get headers %s\n", strerror(ctx.err));
 		goto out;
 	}
 
@@ -3557,11 +3546,10 @@ static int cmd_dpipe_table_show(struct dl *dl)
 	dl_opts_put(nlh, dl);
 
 	pr_out_section_start(dl, "table");
-	_mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dpipe_table_show_cb, ctx);
+	_mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dpipe_table_show_cb, &ctx);
 	pr_out_section_end(dl);
 out:
-	dpipe_ctx_clear(ctx);
-	dpipe_ctx_free(ctx);
+	dpipe_ctx_fini(&ctx);
 	return err;
 }
 
@@ -3930,13 +3918,13 @@ static int cmd_dpipe_table_entry_dump_cb(const struct nlmsghdr *nlh, void *data)
 static int cmd_dpipe_table_dump(struct dl *dl)
 {
 	struct nlmsghdr *nlh;
-	struct dpipe_ctx *ctx;
+	struct dpipe_ctx ctx = {};
 	uint16_t flags = NLM_F_REQUEST;
 	int err;
 
-	ctx = dpipe_ctx_alloc(dl);
-	if (!ctx)
-		return -ENOMEM;
+	err = dpipe_ctx_init(&ctx, dl);
+	if (err)
+		return err;
 
 	err = dl_argv_parse(dl, DL_OPT_HANDLE | DL_OPT_DPIPE_TABLE_NAME, 0);
 	if (err)
@@ -3944,9 +3932,9 @@ static int cmd_dpipe_table_dump(struct dl *dl)
 
 	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_DPIPE_HEADERS_GET, flags);
 	dl_opts_put(nlh, dl);
-	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dpipe_header_cb, ctx);
+	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dpipe_header_cb, &ctx);
 	if (err) {
-		pr_err("error get headers %s\n", strerror(ctx->err));
+		pr_err("error get headers %s\n", strerror(ctx.err));
 		goto out;
 	}
 
@@ -3955,11 +3943,10 @@ static int cmd_dpipe_table_dump(struct dl *dl)
 	dl_opts_put(nlh, dl);
 
 	pr_out_section_start(dl, "table_entry");
-	_mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dpipe_table_entry_dump_cb, ctx);
+	_mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dpipe_table_entry_dump_cb, &ctx);
 	pr_out_section_end(dl);
 out:
-	dpipe_ctx_clear(ctx);
-	dpipe_ctx_free(ctx);
+	dpipe_ctx_fini(&ctx);
 	return err;
 }
 
-- 
2.4.11

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH iproute2 6/7] devlink: Add support for resource/dpipe relation
  2018-02-14  8:55 [PATCH iproute2 0/7] Add support for devlink resource abstraction Arkadi Sharshevsky
                   ` (4 preceding siblings ...)
  2018-02-14  8:55 ` [PATCH iproute2 5/7] devlink: Move dpipe context from heap to stack Arkadi Sharshevsky
@ 2018-02-14  8:55 ` Arkadi Sharshevsky
  2018-02-23 16:40   ` Stephen Hemminger
  2018-02-14  8:55 ` [PATCH iproute2 7/7] devlink: Update man pages and add resource man Arkadi Sharshevsky
                   ` (2 subsequent siblings)
  8 siblings, 1 reply; 18+ messages in thread
From: Arkadi Sharshevsky @ 2018-02-14  8:55 UTC (permalink / raw)
  To: netdev; +Cc: davem, stephen, dsa, mlxsw, Arkadi Sharshevsky

Dpipe - Each dpipe table can have one resource which is mapped to it.
The resource is presented via its full path. Furthermore, the number
of units consumed by single table entry is presented.

Resource - Each resource presents the dpipe tables that use it.

Signed-off-by: Arkadi Sharshevsky <arkadis@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
---
 devlink/devlink.c | 201 +++++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 175 insertions(+), 26 deletions(-)

diff --git a/devlink/devlink.c b/devlink/devlink.c
index aec36ff..47120ce 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -2739,6 +2739,17 @@ struct dpipe_header {
 	unsigned int fields_count;
 };
 
+struct dpipe_table {
+	struct list_head list;
+	char *name;
+	unsigned int resource_id;
+	bool resource_valid;
+};
+
+struct dpipe_tables {
+	struct list_head table_list;
+};
+
 struct resource {
 	char *name;
 	uint64_t size;
@@ -2764,6 +2775,7 @@ struct resource_ctx {
 	struct dl *dl;
 	int err;
 	struct resources *resources;
+	struct dpipe_tables *tables;
 	bool print_resources;
 	bool pending_change;
 };
@@ -2829,7 +2841,10 @@ struct dpipe_ctx {
 	int err;
 	struct list_head global_headers;
 	struct list_head local_headers;
+	struct dpipe_tables *tables;
+	struct resources *resources;
 	bool print_headers;
+	bool print_tables;
 };
 
 static struct dpipe_header *dpipe_header_alloc(unsigned int fields_count)
@@ -2882,8 +2897,42 @@ static void dpipe_header_del(struct dpipe_header *header)
 	list_del(&header->list);
 }
 
+static struct dpipe_table *dpipe_table_alloc(void)
+{
+	return calloc(1, sizeof(struct dpipe_table));
+}
+
+static void dpipe_table_free(struct dpipe_table *table)
+{
+	free(table);
+}
+
+static struct dpipe_tables *dpipe_tables_alloc(void)
+{
+	struct dpipe_tables *tables;
+
+	tables = calloc(1, sizeof(struct dpipe_tables));
+	if (!tables)
+		return NULL;
+	INIT_LIST_HEAD(&tables->table_list);
+	return tables;
+}
+
+static void dpipe_tables_free(struct dpipe_tables *tables)
+{
+	struct dpipe_table *table, *tmp;
+
+	list_for_each_entry_safe(table, tmp, &tables->table_list, list)
+		dpipe_table_free(table);
+	free(tables);
+}
+
 static int dpipe_ctx_init(struct dpipe_ctx *ctx, struct dl *dl)
 {
+	ctx->tables = dpipe_tables_alloc();
+	if (!ctx->tables)
+		return -ENOMEM;
+
 	ctx->dl = dl;
 	INIT_LIST_HEAD(&ctx->global_headers);
 	INIT_LIST_HEAD(&ctx->local_headers);
@@ -2906,6 +2955,7 @@ static void dpipe_ctx_fini(struct dpipe_ctx *ctx)
 		dpipe_header_clear(header);
 		dpipe_header_free(header);
 	}
+	dpipe_tables_free(ctx->tables);
 }
 
 static const char *dpipe_header_id2s(struct dpipe_ctx *ctx,
@@ -3440,8 +3490,10 @@ resource_path_print(struct dl *dl, struct resources *resources,
 static int dpipe_table_show(struct dpipe_ctx *ctx, struct nlattr *nl)
 {
 	struct nlattr *nla_table[DEVLINK_ATTR_MAX + 1] = {};
+	struct dpipe_table *table;
+	uint32_t resource_units;
 	bool counters_enabled;
-	const char *name;
+	bool resource_valid;
 	uint32_t size;
 	int err;
 
@@ -3457,15 +3509,36 @@ static int dpipe_table_show(struct dpipe_ctx *ctx, struct nlattr *nl)
 		return -EINVAL;
 	}
 
-	name = mnl_attr_get_str(nla_table[DEVLINK_ATTR_DPIPE_TABLE_NAME]);
+	table = dpipe_table_alloc();
+	if (!table)
+		return -ENOMEM;
+
+	table->name = strdup(mnl_attr_get_str(nla_table[DEVLINK_ATTR_DPIPE_TABLE_NAME]));
 	size = mnl_attr_get_u32(nla_table[DEVLINK_ATTR_DPIPE_TABLE_SIZE]);
 	counters_enabled = !!mnl_attr_get_u8(nla_table[DEVLINK_ATTR_DPIPE_TABLE_COUNTERS_ENABLED]);
 
-	pr_out_str(ctx->dl, "name", name);
+	resource_valid = !!nla_table[DEVLINK_ATTR_DPIPE_TABLE_RESOURCE_ID];
+	if (resource_valid) {
+		table->resource_id = mnl_attr_get_u64(nla_table[DEVLINK_ATTR_DPIPE_TABLE_RESOURCE_ID]);
+		table->resource_valid = true;
+	}
+
+	list_add_tail(&table->list, &ctx->tables->table_list);
+	if (!ctx->print_tables)
+		return 0;
+
+	pr_out_str(ctx->dl, "name", table->name);
 	pr_out_uint(ctx->dl, "size", size);
 	pr_out_str(ctx->dl, "counters_enabled",
 		   counters_enabled ? "true" : "false");
 
+	if (resource_valid) {
+		resource_units = mnl_attr_get_u32(nla_table[DEVLINK_ATTR_DPIPE_TABLE_RESOURCE_UNITS]);
+		resource_path_print(ctx->dl, ctx->resources,
+				    table->resource_id);
+		pr_out_uint(ctx->dl, "resource_units", resource_units);
+	}
+
 	pr_out_array_start(ctx->dl, "match");
 	if (dpipe_table_matches_show(ctx, nla_table[DEVLINK_ATTR_DPIPE_TABLE_MATCHES]))
 		goto err_matches_show;
@@ -3490,15 +3563,18 @@ static int dpipe_tables_show(struct dpipe_ctx *ctx, struct nlattr **tb)
 	struct nlattr *nla_table;
 
 	mnl_attr_for_each_nested(nla_table, nla_tables) {
-		pr_out_handle_start_arr(ctx->dl, tb);
+		if (ctx->print_tables)
+			pr_out_handle_start_arr(ctx->dl, tb);
 		if (dpipe_table_show(ctx, nla_table))
 			goto err_table_show;
-		pr_out_handle_end(ctx->dl);
+		if (ctx->print_tables)
+			pr_out_handle_end(ctx->dl);
 	}
 	return 0;
 
 err_table_show:
-	pr_out_handle_end(ctx->dl);
+	if (ctx->print_tables)
+		pr_out_handle_end(ctx->dl);
 	return -EINVAL;
 }
 
@@ -3518,38 +3594,68 @@ static int cmd_dpipe_table_show_cb(const struct nlmsghdr *nlh, void *data)
 	return MNL_CB_OK;
 }
 
+static int cmd_resource_dump_cb(const struct nlmsghdr *nlh, void *data);
+
 static int cmd_dpipe_table_show(struct dl *dl)
 {
 	struct nlmsghdr *nlh;
-	struct dpipe_ctx ctx = {};
+	struct dpipe_ctx dpipe_ctx = {};
+	struct resource_ctx resource_ctx = {};
 	uint16_t flags = NLM_F_REQUEST;
 	int err;
 
-	err = dpipe_ctx_init(&ctx, dl);
+	err = dl_argv_parse(dl, DL_OPT_HANDLE, DL_OPT_DPIPE_TABLE_NAME);
 	if (err)
 		return err;
 
-	err = dl_argv_parse(dl, DL_OPT_HANDLE, DL_OPT_DPIPE_TABLE_NAME);
+	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_DPIPE_HEADERS_GET, flags);
+
+	err = dpipe_ctx_init(&dpipe_ctx, dl);
 	if (err)
-		goto out;
+		return err;
+
+	dpipe_ctx.print_tables = true;
 
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_DPIPE_HEADERS_GET, flags);
 	dl_opts_put(nlh, dl);
-	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dpipe_header_cb, &ctx);
+	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dpipe_header_cb,
+				  &dpipe_ctx);
 	if (err) {
-		pr_err("error get headers %s\n", strerror(ctx.err));
-		goto out;
+		pr_err("error get headers %s\n", strerror(dpipe_ctx.err));
+		goto err_headers_get;
+	}
+
+	err = resource_ctx_init(&resource_ctx, dl);
+	if (err)
+		goto err_resource_ctx_init;
+
+	resource_ctx.print_resources = false;
+	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_RESOURCE_DUMP, flags);
+	dl_opts_put(nlh, dl);
+	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_resource_dump_cb,
+				  &resource_ctx);
+	if (err) {
+		pr_err("error get resources %s\n", strerror(resource_ctx.err));
+		goto err_resource_dump;
 	}
 
+	dpipe_ctx.resources = resource_ctx.resources;
 	flags = NLM_F_REQUEST | NLM_F_ACK;
 	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_DPIPE_TABLE_GET, flags);
 	dl_opts_put(nlh, dl);
 
 	pr_out_section_start(dl, "table");
-	_mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dpipe_table_show_cb, &ctx);
+	_mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dpipe_table_show_cb, &dpipe_ctx);
 	pr_out_section_end(dl);
-out:
-	dpipe_ctx_fini(&ctx);
+
+	resource_ctx_fini(&resource_ctx);
+	dpipe_ctx_fini(&dpipe_ctx);
+	return 0;
+
+err_resource_dump:
+	resource_ctx_fini(&resource_ctx);
+err_resource_ctx_init:
+err_headers_get:
+	dpipe_ctx_fini(&dpipe_ctx);
 	return err;
 }
 
@@ -4101,7 +4207,9 @@ static void resource_show(struct resource *resource,
 			  struct resource_ctx *ctx)
 {
 	struct resource *child_resource;
+	struct dpipe_table *table;
 	struct dl *dl = ctx->dl;
+	bool array = false;
 
 	pr_out_str(dl, "name", resource->name);
 	if (dl->verbose)
@@ -4119,6 +4227,27 @@ static void resource_show(struct resource *resource,
 		pr_out_uint(dl, "size_gran", resource->size_gran);
 	}
 
+	list_for_each_entry(table, &ctx->tables->table_list, list)
+		if (table->resource_id == resource->id &&
+		    table->resource_valid)
+			array = true;
+
+	if (array)
+		pr_out_array_start(dl, "dpipe_tables");
+	else
+		pr_out_str(dl, "dpipe_tables", "none");
+
+	list_for_each_entry(table, &ctx->tables->table_list, list) {
+		if (table->resource_id != resource->id ||
+		    !table->resource_valid)
+			continue;
+		pr_out_entry_start(dl);
+		pr_out_str(dl, "table_name", table->name);
+		pr_out_entry_end(dl);
+	}
+	if (array)
+		pr_out_array_end(dl);
+
 	if (list_empty(&resource->resource_list))
 		return;
 
@@ -4179,25 +4308,45 @@ static int cmd_resource_dump_cb(const struct nlmsghdr *nlh, void *data)
 static int cmd_resource_show(struct dl *dl)
 {
 	struct nlmsghdr *nlh;
-	struct resource_ctx ctx = {};
+	struct dpipe_ctx dpipe_ctx = {};
+	struct resource_ctx resource_ctx = {};
 	int err;
 
-	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_RESOURCE_DUMP,
-			       NLM_F_REQUEST | NLM_F_ACK);
-
-	err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLE, 0);
+	err = dl_argv_parse(dl, DL_OPT_HANDLE, 0);
 	if (err)
 		return err;
 
-	err = resource_ctx_init(&ctx, dl);
+	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_DPIPE_TABLE_GET,
+			       NLM_F_REQUEST);
+	dl_opts_put(nlh, dl);
+
+	err = dpipe_ctx_init(&dpipe_ctx, dl);
 	if (err)
 		return err;
 
-	ctx.print_resources = true;
+	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_dpipe_table_show_cb,
+				  &dpipe_ctx);
+	if (err) {
+		pr_err("error get tables %s\n", strerror(dpipe_ctx.err));
+		goto out;
+	}
+
+	err = resource_ctx_init(&resource_ctx, dl);
+	if (err)
+		goto out;
+
+	resource_ctx.print_resources = true;
+	resource_ctx.tables = dpipe_ctx.tables;
+	nlh = mnlg_msg_prepare(dl->nlg, DEVLINK_CMD_RESOURCE_DUMP,
+			       NLM_F_REQUEST | NLM_F_ACK);
+	dl_opts_put(nlh, dl);
 	pr_out_section_start(dl, "resources");
-	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_resource_dump_cb, &ctx);
+	err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_resource_dump_cb,
+				  &resource_ctx);
 	pr_out_section_end(dl);
-	resource_ctx_fini(&ctx);
+	resource_ctx_fini(&resource_ctx);
+out:
+	dpipe_ctx_fini(&dpipe_ctx);
 	return err;
 }
 
-- 
2.4.11

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH iproute2 7/7] devlink: Update man pages and add resource man
  2018-02-14  8:55 [PATCH iproute2 0/7] Add support for devlink resource abstraction Arkadi Sharshevsky
                   ` (5 preceding siblings ...)
  2018-02-14  8:55 ` [PATCH iproute2 6/7] devlink: Add support for resource/dpipe relation Arkadi Sharshevsky
@ 2018-02-14  8:55 ` Arkadi Sharshevsky
  2018-02-15  3:41 ` [PATCH iproute2 0/7] Add support for devlink resource abstraction David Ahern
  2018-02-23 16:41 ` Stephen Hemminger
  8 siblings, 0 replies; 18+ messages in thread
From: Arkadi Sharshevsky @ 2018-02-14  8:55 UTC (permalink / raw)
  To: netdev; +Cc: davem, stephen, dsa, mlxsw, Arkadi Sharshevsky

Add resource man, and update dev manual for reload command.

Signed-off-by: Arkadi Sharshevsky <arkadis@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
---
 man/man8/devlink-dev.8      | 15 +++++++++
 man/man8/devlink-resource.8 | 78 +++++++++++++++++++++++++++++++++++++++++++++
 man/man8/devlink.8          |  1 +
 3 files changed, 94 insertions(+)
 create mode 100644 man/man8/devlink-resource.8

diff --git a/man/man8/devlink-dev.8 b/man/man8/devlink-dev.8
index b074d57..7c749dd 100644
--- a/man/man8/devlink-dev.8
+++ b/man/man8/devlink-dev.8
@@ -42,6 +42,10 @@ devlink-dev \- devlink device configuration
 .BR "devlink dev eswitch show"
 .IR DEV
 
+.ti -8
+.BR "devlink dev reload"
+.IR DEV
+
 .SH "DESCRIPTION"
 .SS devlink dev show - display devlink device attributes
 
@@ -94,6 +98,12 @@ Set eswitch encapsulation support
 .I enable
 - Enable encapsulation support
 
+.SS devlink dev reload - perform hot reload of the driver.
+
+.PP
+.I "DEV"
+- Specifies the devlink device to reload.
+
 .SH "EXAMPLES"
 .PP
 devlink dev show
@@ -114,6 +124,11 @@ Shows the eswitch mode of specified devlink device.
 devlink dev eswitch set pci/0000:01:00.0 mode switchdev
 .RS 4
 Sets the eswitch mode of specified devlink device to switchdev.
+.RE
+.PP
+devlink dev reload pci/0000:01:00.0
+.RS 4
+Performs hot reload of specified devlink device.
 
 .SH SEE ALSO
 .BR devlink (8),
diff --git a/man/man8/devlink-resource.8 b/man/man8/devlink-resource.8
new file mode 100644
index 0000000..b8f7880
--- /dev/null
+++ b/man/man8/devlink-resource.8
@@ -0,0 +1,78 @@
+.TH DEVLINK\-RESOURCE 8 "11 Feb 2018" "iproute2" "Linux"
+.SH NAME
+devlink-resource \- devlink device resource configuration
+.SH SYNOPSIS
+.sp
+.ad l
+.in +8
+.ti -8
+.B devlink
+.RI "[ " OPTIONS " ]"
+.B resource
+.RI  " { " COMMAND " | "
+.BR help " }"
+.sp
+
+.ti -8
+.IR OPTIONS " := { "
+\fB\-v\fR[\fIerbose\fR] }
+
+.ti -8
+.B devlink resource show
+.IR DEV
+
+.ti -8
+.B devlink resource help
+
+.ti -8
+.BR "devlink resource set"
+.IR DEV
+.BI path " RESOURCE_PATH"
+.BI size " RESOURCE_SIZE"
+
+.SH "DESCRIPTION"
+.SS devlink resource show - display devlink device's resosources
+
+.PP
+.I "DEV"
+- specifies the devlink device to show.
+
+.in +4
+Format is:
+.in +2
+BUS_NAME/BUS_ADDRESS
+
+.SS devlink resource set - sets resource size of specific resource
+
+.PP
+.I "DEV"
+- specifies the devlink device.
+
+.TP
+.BI path " RESOURCE_PATH"
+Resource's path.
+
+.TP
+.BI size " RESOURCE_SIZE"
+The new resource's size.
+
+.SH "EXAMPLES"
+.PP
+devlink resource show pci/0000:01:00.0
+.RS 4
+Shows the resources of the specified devlink device.
+.RE
+.PP
+devlink resource set pci/0000:01:00.0 /kvd/linear 98304
+.RS 4
+Sets the size of the specified resource for the specified devlink device.
+
+.SH SEE ALSO
+.BR devlink (8),
+.BR devlink-port (8),
+.BR devlink-sb (8),
+.BR devlink-monitor (8),
+.br
+
+.SH AUTHOR
+Arkadi Sharshevsky <arkadis@mellanox.com>
diff --git a/man/man8/devlink.8 b/man/man8/devlink.8
index a975ef3..b83909d 100644
--- a/man/man8/devlink.8
+++ b/man/man8/devlink.8
@@ -103,6 +103,7 @@ Exit status is 0 if command was successful or a positive integer upon failure.
 .BR devlink-port (8),
 .BR devlink-monitor (8),
 .BR devlink-sb (8),
+.BR devlink-resource (8),
 .br
 
 .SH REPORTING BUGS
-- 
2.4.11

^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH iproute2 1/7] devlink: Change empty line indication with indentations
  2018-02-14  8:55 ` [PATCH iproute2 1/7] devlink: Change empty line indication with indentations Arkadi Sharshevsky
@ 2018-02-14 15:11   ` Stephen Hemminger
  2018-02-14 15:17     ` Jiri Pirko
  0 siblings, 1 reply; 18+ messages in thread
From: Stephen Hemminger @ 2018-02-14 15:11 UTC (permalink / raw)
  To: Arkadi Sharshevsky; +Cc: netdev, davem, dsa, mlxsw

On Wed, 14 Feb 2018 10:55:16 +0200
Arkadi Sharshevsky <arkadis@mellanox.com> wrote:

> Currently multi-line objects are separated by new-lines. This patch
> changes this behavior by using indentations for separation.
> 
> Signed-off-by: Arkadi Sharhsevsky <arkadis@mellanox.com>
> Acked-by: Jiri Pirko <jiri@mellanox.com>

OT but you should rally implement JSON here.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH iproute2 2/7] devlink: mnlg: Add support for extended ack
  2018-02-14  8:55 ` [PATCH iproute2 2/7] devlink: mnlg: Add support for extended ack Arkadi Sharshevsky
@ 2018-02-14 15:12   ` Stephen Hemminger
  2018-02-15 11:57     ` Arkadi Sharshevsky
  0 siblings, 1 reply; 18+ messages in thread
From: Stephen Hemminger @ 2018-02-14 15:12 UTC (permalink / raw)
  To: Arkadi Sharshevsky; +Cc: netdev, davem, dsa, mlxsw

On Wed, 14 Feb 2018 10:55:17 +0200
Arkadi Sharshevsky <arkadis@mellanox.com> wrote:

> +static mnl_cb_t mnlg_cb_array[NLMSG_MIN_TYPE] = {
> +	[NLMSG_NOOP]	= mnlg_cb_noop,
> +	[NLMSG_ERROR]	= mnlg_cb_error,
> +	[NLMSG_DONE]	= mnlg_cb_stop,
> +	[NLMSG_OVERRUN]	= mnlg_cb_noop,
> +};
> +

Could be const?

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH iproute2 1/7] devlink: Change empty line indication with indentations
  2018-02-14 15:11   ` Stephen Hemminger
@ 2018-02-14 15:17     ` Jiri Pirko
  0 siblings, 0 replies; 18+ messages in thread
From: Jiri Pirko @ 2018-02-14 15:17 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: Arkadi Sharshevsky, netdev, davem, dsa, mlxsw

Wed, Feb 14, 2018 at 04:11:33PM CET, stephen@networkplumber.org wrote:
>On Wed, 14 Feb 2018 10:55:16 +0200
>Arkadi Sharshevsky <arkadis@mellanox.com> wrote:
>
>> Currently multi-line objects are separated by new-lines. This patch
>> changes this behavior by using indentations for separation.
>> 
>> Signed-off-by: Arkadi Sharhsevsky <arkadis@mellanox.com>
>> Acked-by: Jiri Pirko <jiri@mellanox.com>
>
>OT but you should rally implement JSON here.

It is already implemeted.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH iproute2 0/7] Add support for devlink resource abstraction
  2018-02-14  8:55 [PATCH iproute2 0/7] Add support for devlink resource abstraction Arkadi Sharshevsky
                   ` (6 preceding siblings ...)
  2018-02-14  8:55 ` [PATCH iproute2 7/7] devlink: Update man pages and add resource man Arkadi Sharshevsky
@ 2018-02-15  3:41 ` David Ahern
  2018-02-22 10:19   ` Arkadi Sharshevsky
  2018-02-23 16:41 ` Stephen Hemminger
  8 siblings, 1 reply; 18+ messages in thread
From: David Ahern @ 2018-02-15  3:41 UTC (permalink / raw)
  To: Arkadi Sharshevsky, netdev, stephen; +Cc: davem, mlxsw

On 2/14/18 1:55 AM, Arkadi Sharshevsky wrote:
> Add support for devlink resource abstraction.
> 
> Arkadi Sharshevsky (7):
>   devlink: Change empty line indication with indentations
>   devlink: mnlg: Add support for extended ack
>   devlink: Add support for devlink resource abstraction
>   devlink: Add support for hot reload
>   devlink: Move dpipe context from heap to stack
>   devlink: Add support for resource/dpipe relation
>   devlink: Update man pages and add resource man
> 
>  devlink/devlink.c           | 774 ++++++++++++++++++++++++++++++++++++++++----
>  devlink/mnlg.c              |  53 ++-
>  include/libnetlink.h        |   1 +
>  include/list.h              |   5 +
>  lib/libnetlink.c            |   4 +-
>  man/man8/devlink-dev.8      |  15 +
>  man/man8/devlink-resource.8 |  78 +++++
>  man/man8/devlink.8          |   1 +
>  8 files changed, 871 insertions(+), 60 deletions(-)
>  create mode 100644 man/man8/devlink-resource.8
> 

Looks ok to me.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH iproute2 2/7] devlink: mnlg: Add support for extended ack
  2018-02-14 15:12   ` Stephen Hemminger
@ 2018-02-15 11:57     ` Arkadi Sharshevsky
  2018-02-15 18:15       ` Stephen Hemminger
  0 siblings, 1 reply; 18+ messages in thread
From: Arkadi Sharshevsky @ 2018-02-15 11:57 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev, davem, dsa, mlxsw, Jiri Pirko



On 02/14/2018 05:12 PM, Stephen Hemminger wrote:
> On Wed, 14 Feb 2018 10:55:17 +0200
> Arkadi Sharshevsky <arkadis@mellanox.com> wrote:
> 
>> +static mnl_cb_t mnlg_cb_array[NLMSG_MIN_TYPE] = {
>> +	[NLMSG_NOOP]	= mnlg_cb_noop,
>> +	[NLMSG_ERROR]	= mnlg_cb_error,
>> +	[NLMSG_DONE]	= mnlg_cb_stop,
>> +	[NLMSG_OVERRUN]	= mnlg_cb_noop,
>> +};
>> +
> 
> Could be const?
> 

I pass the array to mnl_cb_run2() which will discard the 'const'
qualifier. So I dont think this is very beneficial.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH iproute2 2/7] devlink: mnlg: Add support for extended ack
  2018-02-15 11:57     ` Arkadi Sharshevsky
@ 2018-02-15 18:15       ` Stephen Hemminger
  0 siblings, 0 replies; 18+ messages in thread
From: Stephen Hemminger @ 2018-02-15 18:15 UTC (permalink / raw)
  To: Arkadi Sharshevsky; +Cc: netdev, davem, dsa, mlxsw, Jiri Pirko

On Thu, 15 Feb 2018 13:57:18 +0200
Arkadi Sharshevsky <arkadis@mellanox.com> wrote:

> On 02/14/2018 05:12 PM, Stephen Hemminger wrote:
> > On Wed, 14 Feb 2018 10:55:17 +0200
> > Arkadi Sharshevsky <arkadis@mellanox.com> wrote:
> >   
> >> +static mnl_cb_t mnlg_cb_array[NLMSG_MIN_TYPE] = {
> >> +	[NLMSG_NOOP]	= mnlg_cb_noop,
> >> +	[NLMSG_ERROR]	= mnlg_cb_error,
> >> +	[NLMSG_DONE]	= mnlg_cb_stop,
> >> +	[NLMSG_OVERRUN]	= mnlg_cb_noop,
> >> +};
> >> +  
> > 
> > Could be const?
> >   
> 
> I pass the array to mnl_cb_run2() which will discard the 'const'
> qualifier. So I dont think this is very beneficial.

Thanks, makes sense,

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH iproute2 0/7] Add support for devlink resource abstraction
  2018-02-15  3:41 ` [PATCH iproute2 0/7] Add support for devlink resource abstraction David Ahern
@ 2018-02-22 10:19   ` Arkadi Sharshevsky
  2018-02-22 15:02     ` David Ahern
  0 siblings, 1 reply; 18+ messages in thread
From: Arkadi Sharshevsky @ 2018-02-22 10:19 UTC (permalink / raw)
  To: David Ahern, netdev, stephen; +Cc: davem, mlxsw



On 02/15/2018 05:41 AM, David Ahern wrote:
> On 2/14/18 1:55 AM, Arkadi Sharshevsky wrote:
>> Add support for devlink resource abstraction.
>>
>> Arkadi Sharshevsky (7):
>>   devlink: Change empty line indication with indentations
>>   devlink: mnlg: Add support for extended ack
>>   devlink: Add support for devlink resource abstraction
>>   devlink: Add support for hot reload
>>   devlink: Move dpipe context from heap to stack
>>   devlink: Add support for resource/dpipe relation
>>   devlink: Update man pages and add resource man
>>
>>  devlink/devlink.c           | 774 ++++++++++++++++++++++++++++++++++++++++----
>>  devlink/mnlg.c              |  53 ++-
>>  include/libnetlink.h        |   1 +
>>  include/list.h              |   5 +
>>  lib/libnetlink.c            |   4 +-
>>  man/man8/devlink-dev.8      |  15 +
>>  man/man8/devlink-resource.8 |  78 +++++
>>  man/man8/devlink.8          |   1 +
>>  8 files changed, 871 insertions(+), 60 deletions(-)
>>  create mode 100644 man/man8/devlink-resource.8
>>
> 
> Looks ok to me.
> 

Hi David, noticed it wasn't applied yet.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH iproute2 0/7] Add support for devlink resource abstraction
  2018-02-22 10:19   ` Arkadi Sharshevsky
@ 2018-02-22 15:02     ` David Ahern
  0 siblings, 0 replies; 18+ messages in thread
From: David Ahern @ 2018-02-22 15:02 UTC (permalink / raw)
  To: Arkadi Sharshevsky, netdev, stephen; +Cc: davem, mlxsw

On 2/22/18 3:19 AM, Arkadi Sharshevsky wrote:
> 
> 
> On 02/15/2018 05:41 AM, David Ahern wrote:
>> On 2/14/18 1:55 AM, Arkadi Sharshevsky wrote:
>>> Add support for devlink resource abstraction.
>>>
>>> Arkadi Sharshevsky (7):
>>>   devlink: Change empty line indication with indentations
>>>   devlink: mnlg: Add support for extended ack
>>>   devlink: Add support for devlink resource abstraction
>>>   devlink: Add support for hot reload
>>>   devlink: Move dpipe context from heap to stack
>>>   devlink: Add support for resource/dpipe relation
>>>   devlink: Update man pages and add resource man
>>>
>>>  devlink/devlink.c           | 774 ++++++++++++++++++++++++++++++++++++++++----
>>>  devlink/mnlg.c              |  53 ++-
>>>  include/libnetlink.h        |   1 +
>>>  include/list.h              |   5 +
>>>  lib/libnetlink.c            |   4 +-
>>>  man/man8/devlink-dev.8      |  15 +
>>>  man/man8/devlink-resource.8 |  78 +++++
>>>  man/man8/devlink.8          |   1 +
>>>  8 files changed, 871 insertions(+), 60 deletions(-)
>>>  create mode 100644 man/man8/devlink-resource.8
>>>
>>
>> Looks ok to me.
>>
> 
> Hi David, noticed it wasn't applied yet.
> 

The feature is in 4.16, so seems like it should be applied to the master
branch. Patchworks should show them assigned to Stephen.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH iproute2 6/7] devlink: Add support for resource/dpipe relation
  2018-02-14  8:55 ` [PATCH iproute2 6/7] devlink: Add support for resource/dpipe relation Arkadi Sharshevsky
@ 2018-02-23 16:40   ` Stephen Hemminger
  0 siblings, 0 replies; 18+ messages in thread
From: Stephen Hemminger @ 2018-02-23 16:40 UTC (permalink / raw)
  To: Arkadi Sharshevsky; +Cc: netdev, davem, dsa, mlxsw

On Wed, 14 Feb 2018 10:55:21 +0200
Arkadi Sharshevsky <arkadis@mellanox.com> wrote:

> @@ -3457,15 +3509,36 @@ static int dpipe_table_show(struct dpipe_ctx *ctx, struct nlattr *nl)
>  		return -EINVAL;
>  	}
>  
> -	name = mnl_attr_get_str(nla_table[DEVLINK_ATTR_DPIPE_TABLE_NAME]);
> +	table = dpipe_table_alloc();
> +	if (!table)
> +		return -ENOMEM;
> +
> +	table->name = strdup(mnl_attr_get_str(nla_table[DEVLINK_ATTR_DPIPE_TABLE_NAME]));
>  	size = mnl_attr_get_u32(nla_table[DEVLINK_ATTR_DPIPE_TABLE_SIZE]);
>  	counters_enabled = !!mnl_attr_get_u8(nla_table[DEVLINK_ATTR_DPIPE_TABLE_COUNTERS_ENABLED]);

The use of long variable names in devlink is making for very long lines.
Please consider adopting a more concise style in future revisions.

Je n’ai fait celle-ci plus longue que parce que je n’ai pas eu le loisir de la faire plus courte.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH iproute2 0/7] Add support for devlink resource abstraction
  2018-02-14  8:55 [PATCH iproute2 0/7] Add support for devlink resource abstraction Arkadi Sharshevsky
                   ` (7 preceding siblings ...)
  2018-02-15  3:41 ` [PATCH iproute2 0/7] Add support for devlink resource abstraction David Ahern
@ 2018-02-23 16:41 ` Stephen Hemminger
  8 siblings, 0 replies; 18+ messages in thread
From: Stephen Hemminger @ 2018-02-23 16:41 UTC (permalink / raw)
  To: Arkadi Sharshevsky; +Cc: netdev, davem, dsa, mlxsw

On Wed, 14 Feb 2018 10:55:15 +0200
Arkadi Sharshevsky <arkadis@mellanox.com> wrote:

> Add support for devlink resource abstraction.
> 
> Arkadi Sharshevsky (7):
>   devlink: Change empty line indication with indentations
>   devlink: mnlg: Add support for extended ack
>   devlink: Add support for devlink resource abstraction
>   devlink: Add support for hot reload
>   devlink: Move dpipe context from heap to stack
>   devlink: Add support for resource/dpipe relation
>   devlink: Update man pages and add resource man
> 
>  devlink/devlink.c           | 774 ++++++++++++++++++++++++++++++++++++++++----
>  devlink/mnlg.c              |  53 ++-
>  include/libnetlink.h        |   1 +
>  include/list.h              |   5 +
>  lib/libnetlink.c            |   4 +-
>  man/man8/devlink-dev.8      |  15 +
>  man/man8/devlink-resource.8 |  78 +++++
>  man/man8/devlink.8          |   1 +
>  8 files changed, 871 insertions(+), 60 deletions(-)
>  create mode 100644 man/man8/devlink-resource.8
> 

I applied all these, but please try and make devlink less wordy.

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2018-02-23 16:41 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-14  8:55 [PATCH iproute2 0/7] Add support for devlink resource abstraction Arkadi Sharshevsky
2018-02-14  8:55 ` [PATCH iproute2 1/7] devlink: Change empty line indication with indentations Arkadi Sharshevsky
2018-02-14 15:11   ` Stephen Hemminger
2018-02-14 15:17     ` Jiri Pirko
2018-02-14  8:55 ` [PATCH iproute2 2/7] devlink: mnlg: Add support for extended ack Arkadi Sharshevsky
2018-02-14 15:12   ` Stephen Hemminger
2018-02-15 11:57     ` Arkadi Sharshevsky
2018-02-15 18:15       ` Stephen Hemminger
2018-02-14  8:55 ` [PATCH iproute2 3/7] devlink: Add support for devlink resource abstraction Arkadi Sharshevsky
2018-02-14  8:55 ` [PATCH iproute2 4/7] devlink: Add support for hot reload Arkadi Sharshevsky
2018-02-14  8:55 ` [PATCH iproute2 5/7] devlink: Move dpipe context from heap to stack Arkadi Sharshevsky
2018-02-14  8:55 ` [PATCH iproute2 6/7] devlink: Add support for resource/dpipe relation Arkadi Sharshevsky
2018-02-23 16:40   ` Stephen Hemminger
2018-02-14  8:55 ` [PATCH iproute2 7/7] devlink: Update man pages and add resource man Arkadi Sharshevsky
2018-02-15  3:41 ` [PATCH iproute2 0/7] Add support for devlink resource abstraction David Ahern
2018-02-22 10:19   ` Arkadi Sharshevsky
2018-02-22 15:02     ` David Ahern
2018-02-23 16:41 ` Stephen Hemminger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.