Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: Leon Romanovsky <leonro@nvidia.com>
To: David Ahern <dsahern@kernel.org>
Cc: <stephen@networkplumber.org>, <netdev@vger.kernel.org>,
	<linux-rdma@vger.kernel.org>, David Ahern <dahern@nvidia.com>
Subject: Re: [PATCH iproute2-next 2/4] iplink: Update iplink_parse to use netns_get_fd_pid
Date: Sun, 10 May 2026 13:01:48 +0300	[thread overview]
Message-ID: <20260510100148.GC15586@unreal> (raw)
In-Reply-To: <20260507150836.28105-3-dsahern@kernel.org>

On Thu, May 07, 2026 at 09:08:33AM -0600, David Ahern wrote:
> From: David Ahern <dahern@nvidia.com>
> 
> Drop the open coding of proc/pid/ns/net in favor of
> netns_get_fd_pid.
> 
> Signed-off-by: David Ahern <dahern@nvidia.com>
> ---
>  ip/iplink.c | 12 +++---------
>  1 file changed, 3 insertions(+), 9 deletions(-)
> 
> diff --git a/ip/iplink.c b/ip/iplink.c
> index eae51438..6c4586ee 100644
> --- a/ip/iplink.c
> +++ b/ip/iplink.c
> @@ -650,19 +650,13 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type)
>  			if (offload && name == dev)
>  				dev = NULL;
>  		} else if (strcmp(*argv, "netns") == 0) {
> -			int pid;
> -
>  			NEXT_ARG();
>  			if (netns != -1)
>  				duparg("netns", *argv);
> +			/* try by name then by pid */
>  			netns = netns_get_fd(*argv);
> -			if (netns < 0 && get_integer(&pid, *argv, 0) == 0) {
> -				char path[PATH_MAX];
> -
> -				snprintf(path, sizeof(path), "/proc/%d/ns/net",
> -					 pid);
> -				netns = open(path, O_RDONLY);
> -			}
> +			if (netns < 0)
> +				netns = netns_get_fd_pid(*argv);

It would be good to have a single function that handles the entire
netns_get_fd() → netns < 0 → netns_get_fd_pid() sequence internally. This
logic is used by at least iplink and rdmatool.

Thanks

  reply	other threads:[~2026-05-10 10:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-07 15:08 [PATCH iproute2-next 0/4] Allow rdma dev netns to take a pid David Ahern
2026-05-07 15:08 ` [PATCH iproute2-next 1/4] namespace: Add function to return fd for netns by pid David Ahern
2026-05-07 15:08 ` [PATCH iproute2-next 2/4] iplink: Update iplink_parse to use netns_get_fd_pid David Ahern
2026-05-10 10:01   ` Leon Romanovsky [this message]
2026-05-07 15:08 ` [PATCH iproute2-next 3/4] rdma: Allow netns to be specified by pid David Ahern
2026-05-07 15:08 ` [PATCH iproute2-next 4/4] rdma-dev: Update man page to reflect netns as a pid David Ahern

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=20260510100148.GC15586@unreal \
    --to=leonro@nvidia.com \
    --cc=dahern@nvidia.com \
    --cc=dsahern@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --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