Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1222424imu; Tue, 11 Dec 2018 15:10:26 -0800 (PST) X-Google-Smtp-Source: AFSGD/Ufv7hCYDPtRGMYAQKaQmfKTdyAXvIIRZkWvud9Iim0KfBvFk9QDPRxL6Q/E4VPDT3FePmL X-Received: by 2002:a63:2643:: with SMTP id m64mr16040514pgm.35.1544569826820; Tue, 11 Dec 2018 15:10:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544569826; cv=none; d=google.com; s=arc-20160816; b=enux6bKDpsfXs3L/D0c1KKsGQgQuP4uJ5qdPiWQDas3Hh2YO8UKYDGD+MON+mdYqFH 8uNxfESY6K6ruSKuPU2L8RA4RJqp9Mbf7AEwOdNAT3vtHACSEpyc22pLRrh260q7/DJh V973YT7IPbERvPIPlE5MpD84/KHUOYsNKA6NOM1ccv0QB47rWAN47O1VVvOMJuTCYvye 8Oll756dkzzzHmiaZY5NcIOzBub7OpOVjsyyWWrIYeWnBabS/UmUoW7gcuH47Hyf3QAH Bzqvl32K0GIpdDICI30YiVN3YitXpg0qtI/CV7jM6uxSTwsLJTBGS5zGbsp507tC5fIh ap/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=8CfYWTxvjkVt7BgsH1nB421z6fLy8ecK/XTmOKoh34s=; b=YJtZkds3IOmidTvvSAnm7MipkXgP3XW218GOegFC+F8RAOxu3exy/w6lDMfrbrDgc0 4oyt12IwQ3cg3cQPomJxkhVmrX3vXGkjdxgcrOP7S0pUmdPj2jlsgDVriGvTIXBPp2v5 xAM0XPj5/s6fyCWUvwPLQWIRIg2y5soGKKbbXy0Jka+wKueSSCDHxtPcQYezOB4hRsYg vehAT+X0ElJXVbV+yKDIVqr4rFj0Br4Eu3B8ZNi4hYFe6mw+xrk7+jKmi9tr1uEZoBzc Z3jipKjo4wQAQKFuVDnNdC1PpejgkXym/gRZm2C92PjuX9bFMKQMad9rLbvzVEtffeTu xiGg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m3si12065021pfh.58.2018.12.11.15.10.12; Tue, 11 Dec 2018 15:10:26 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726303AbeLKXJS (ORCPT + 99 others); Tue, 11 Dec 2018 18:09:18 -0500 Received: from mail.hallyn.com ([178.63.66.53]:60320 "EHLO mail.hallyn.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726269AbeLKXJQ (ORCPT ); Tue, 11 Dec 2018 18:09:16 -0500 Received: by mail.hallyn.com (Postfix, from userid 1001) id 3212FC32; Tue, 11 Dec 2018 17:09:14 -0600 (CST) Date: Tue, 11 Dec 2018 17:09:14 -0600 From: "Serge E. Hallyn" To: Masatake YAMATO Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH resend] eventfd: make eventfd files distinguishable in /proc/$PID/fd Message-ID: <20181211230914.GA2677@mail.hallyn.com> References: <20181209183546.5550-1-yamato@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181209183546.5550-1-yamato@redhat.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 10, 2018 at 03:35:46AM +0900, Masatake YAMATO wrote: > Finding endpoints of an IPC channel is one of essential task to > understand how a user program works. Procfs and netlink socket provide > enough hints to find endpoints for IPC channels like pipes, unix > sockets, and pseudo terminals. However, there is no simple way to find > endpoints for an eventfd file from userland. An inode number doesn't > hint. Unlike pipe, all eventfd files shares one inode object. > > To provide the way to find endpoints of an eventfd file, this patch > adds eventfd identifiers to the output of 'ls -l /proc/$pid/fd' like: > > ... > lrwx------. 1 qemu qemu 64 May 20 04:49 93 -> 'anon_inode:[eventfd:130]' > lrwx------. 1 qemu qemu 64 May 20 04:49 94 -> 'anon_inode:[eventfd:131]' > ... > > Here "130" and "131" are added as identifiers newly added. > In the case that ida_simple_get returns an error, this change doesn't add > an identifier; just use "[eventfd]" as before. > > Signed-off-by: Masatake YAMATO I'm going to love this when I need it :) Thanks. Acked-by: Serge Hallyn > --- > fs/eventfd.c | 14 +++++++++++++- > 1 file changed, 13 insertions(+), 1 deletion(-) > > diff --git a/fs/eventfd.c b/fs/eventfd.c > index 08d3bd602f73..c18952948110 100644 > --- a/fs/eventfd.c > +++ b/fs/eventfd.c > @@ -21,6 +21,11 @@ > #include > #include > #include > +#include > + > +/* Worst case buffer size needed for holding an integer. */ > +#define ITOA_MAX_LEN 12 > +DEFINE_IDA(eventfd_ida); > > struct eventfd_ctx { > struct kref kref; > @@ -35,6 +40,7 @@ struct eventfd_ctx { > */ > __u64 count; > unsigned int flags; > + int id; > }; > > /** > @@ -69,6 +75,8 @@ EXPORT_SYMBOL_GPL(eventfd_signal); > > static void eventfd_free_ctx(struct eventfd_ctx *ctx) > { > + if (ctx->id >= 0) > + ida_simple_remove(&eventfd_ida, ctx->id); > kfree(ctx); > } > > @@ -384,6 +392,7 @@ static int do_eventfd(unsigned int count, int flags) > { > struct eventfd_ctx *ctx; > int fd; > + char name[1 + 8 + ITOA_MAX_LEN + 1 + 1] = "[eventfd]"; > > /* Check the EFD_* constants for consistency. */ > BUILD_BUG_ON(EFD_CLOEXEC != O_CLOEXEC); > @@ -400,8 +409,11 @@ static int do_eventfd(unsigned int count, int flags) > init_waitqueue_head(&ctx->wqh); > ctx->count = count; > ctx->flags = flags; > + ctx->id = ida_simple_get(&eventfd_ida, 0, 0, GFP_KERNEL); > > - fd = anon_inode_getfd("[eventfd]", &eventfd_fops, ctx, > + if (ctx->id >= 0) > + snprintf(name, sizeof(name), "[eventfd:%d]", ctx->id); > + fd = anon_inode_getfd(name, &eventfd_fops, ctx, > O_RDWR | (flags & EFD_SHARED_FCNTL_FLAGS)); > if (fd < 0) > eventfd_free_ctx(ctx); > -- > 2.17.0