From: Jiri Pirko <jiri@resnulli.us>
To: David Ahern <dsahern@gmail.com>
Cc: netdev@vger.kernel.org, stephen@networkplumber.org,
daniel.machon@microchip.com
Subject: Re: [patch iproute2-next v2 3/5] devlink: introduce support for netns id for nested handle
Date: Tue, 19 Sep 2023 19:19:09 +0200 [thread overview]
Message-ID: <ZQnYDVBeuIRn7uwK@nanopsycho> (raw)
In-Reply-To: <3652856a-1cda-c050-04da-fe2204949ff5@gmail.com>
Tue, Sep 19, 2023 at 04:03:27PM CEST, dsahern@gmail.com wrote:
>On 9/19/23 5:56 AM, Jiri Pirko wrote:
>> @@ -2723,6 +2725,40 @@ static bool should_arr_last_handle_end(struct dl *dl, const char *bus_name,
>> !cmp_arr_last_handle(dl, bus_name, dev_name);
>> }
>>
>> +struct netns_name_by_id_ctx {
>> + int32_t id;
>> + char *name;
>> + struct rtnl_handle *rth;
>> +};
>> +
>> +static int netns_name_by_id_func(char *nsname, void *arg)
>> +{
>> + struct netns_name_by_id_ctx *ctx = arg;
>> + int32_t ret;
>> +
>> + ret = netns_netnsid_from_name(ctx->rth, nsname);
>> + if (ret < 0 || ret != ctx->id)
>> + return 0;
>> + ctx->name = strdup(nsname);
>> + return 1;
>> +}
>> +
>> +static char *netns_name_by_id(int32_t id)
>> +{
>> + struct rtnl_handle rth;
>> + struct netns_name_by_id_ctx ctx = {
>> + .id = id,
>> + .rth = &rth,
>> + };
>> +
>> + if (rtnl_open(&rth, 0) < 0)
>> + return NULL;
>> + netns_foreach(netns_name_by_id_func, &ctx);
>> + rtnl_close(&rth);
>> +
>> + return ctx.name;
>> +}
>> +
>
>The above is not devlink specific, so it should go in lib/namespace.c as
>well.
>
>Name wise it should be consistent with the last patch, so either
>netns_id_to_name or netns_name_from_id based on the name from the
>refactoring in patch 2.
Okay.
>
>
>> static void pr_out_nested_handle(struct nlattr *nla_nested_dl)
>> {
>> struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
>> @@ -2740,6 +2776,30 @@ static void pr_out_nested_handle(struct nlattr *nla_nested_dl)
>> sprintf(buf, "%s/%s", mnl_attr_get_str(tb[DEVLINK_ATTR_BUS_NAME]),
>> mnl_attr_get_str(tb[DEVLINK_ATTR_DEV_NAME]));
>> print_string(PRINT_ANY, "nested_devlink", " nested_devlink %s", buf);
>> +
>> + if (tb[DEVLINK_ATTR_NETNS_ID]) {
>> + int32_t id = mnl_attr_get_u32(tb[DEVLINK_ATTR_NETNS_ID]);
>> +
>> + if (id >= 0) {
>> + char *name = netns_name_by_id(id);
>> +
>> + if (name) {
>> + print_string(PRINT_ANY,
>> + "nested_devlink_netns",
>> + " nested_devlink_netns %s", name);
>> + free(name);
>> + } else {
>> + print_int(PRINT_ANY,
>> + "nested_devlink_netnsid",
>> + " nested_devlink_netnsid %d", id);
>> + }
>> + } else {
>> + print_string(PRINT_FP, NULL,
>> + " nested_devlink_netnsid %s", "unknown");
>> + print_int(PRINT_JSON,
>> + "nested_devlink_netnsid", NULL, id);
>> + }
>
>Also, devlink in the name here provides no addititional value (devlink
>is the command name) and why add 'nested'? The attribute is just
>NETNS_ID, so why not just 'netnsid' here.
Well, it is a netnsid of the nested devlink instance, not the object
(e.g. port) itself. Omitting that would be misleading. Any idea how to
do this differently?
>
>
>> + }
>> }
>>
>> static void __pr_out_handle_start(struct dl *dl, struct nlattr **tb,
>
next prev parent reply other threads:[~2023-09-19 17:19 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-19 11:56 [patch iproute2-next v2 0/5] expose devlink instances relationships Jiri Pirko
2023-09-19 11:56 ` [patch iproute2-next v2 1/5] devlink: update headers Jiri Pirko
2023-09-19 11:56 ` [patch iproute2-next v2 2/5] ip/ipnetns: move internals of get_netnsid_from_name() into namespace.c Jiri Pirko
2023-09-19 14:03 ` David Ahern
2023-09-19 17:19 ` Jiri Pirko
2023-09-19 11:56 ` [patch iproute2-next v2 3/5] devlink: introduce support for netns id for nested handle Jiri Pirko
2023-09-19 14:03 ` David Ahern
2023-09-19 17:19 ` Jiri Pirko [this message]
2023-09-19 18:48 ` David Ahern
2023-09-20 7:30 ` Jiri Pirko
2023-09-29 11:30 ` Jiri Pirko
2023-10-03 16:37 ` David Ahern
2023-10-03 17:17 ` Jiri Pirko
2023-10-04 15:20 ` David Ahern
2023-10-05 7:22 ` Jiri Pirko
2023-09-19 11:56 ` [patch iproute2-next v2 4/5] devlink: print nested handle for port function Jiri Pirko
2023-09-19 11:56 ` [patch iproute2-next v2 5/5] devlink: print nested devlink handle for devlink dev Jiri Pirko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZQnYDVBeuIRn7uwK@nanopsycho \
--to=jiri@resnulli.us \
--cc=daniel.machon@microchip.com \
--cc=dsahern@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox