Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6658825imu; Mon, 3 Dec 2018 00:11:48 -0800 (PST) X-Google-Smtp-Source: AFSGD/XA17vaMf3rsz8V3oPPw7cL9OZQ9iGie5z9wel2La71en8WBNh94u6+TLtblph8ip7PIEpN X-Received: by 2002:a17:902:9a02:: with SMTP id v2mr15365581plp.180.1543824708922; Mon, 03 Dec 2018 00:11:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543824708; cv=none; d=google.com; s=arc-20160816; b=Ad5z/1FoaAmg08n4KutxGCB40dlt1DCEzkBOPN1B6c1NG+Viafk3wggkIe/iMhaH60 BTC+l+4AJHB2ROo/tnYcvZXTXeJBtH0wlYur2FdFJk6WZVh7DyW6iCqSeQyMYTNr+pYQ p+opD/HFOoatQ6C3pg8JrRX5+xTCW7fG1TPptirAOem3UTUOzj7bIbZENXb+q305YS8E j/+UyPZmCakIITt5x7bUAKz+NfdGtZsZnOk9FVxAh7ac0sWMznmYPeXrxCp4HaOf+Yoc K8eXoItKskdb7Av+MT+/F+JcmKQevlIzBwn7EV7a2lbhCeZceGyJFVa9DnQPm9fu93I9 Mhog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=PfO5TCIhggOMo100A+2VfsCJCcVG6TP/e5t8XmzNFTc=; b=Epoi1SqwLXoFL0ho/C66rqdoDnO8ODix9wiwyItUTQFJB07FRVLLInj5V7gbP4hx4l eZ+0sn+RQWtyhipakrJcL9wfO86Br8jJhD13/gKDakqBisoL3MTAOQt3+LF7jLCh7gLL BR/aJf+uEpb5zZHP+KlUTIvohVv4hnj78tqZ11OI/WPTTske3s2Y5ec/8inqtyHanY9P h9LKl/wW2hoZQZORLmqPkFPxoGSNQ8febNihVpfD7ra7L2zvp+oEHrUCp6IgfqW/3e32 vak8pr+DqRKVisUAPc3Jp8Lsbv/Af7CMJmpiqJdpuOKJiI+3QbKhq87u8pyxj4z1N+OS gXGQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g10si15068159plm.1.2018.12.03.00.11.34; Mon, 03 Dec 2018 00:11:48 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725858AbeLCILE (ORCPT + 99 others); Mon, 3 Dec 2018 03:11:04 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:43978 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725830AbeLCILD (ORCPT ); Mon, 3 Dec 2018 03:11:03 -0500 X-Greylist: delayed 458 seconds by postgrey-1.27 at vger.kernel.org; Mon, 03 Dec 2018 03:11:03 EST Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 49AC787A84; Mon, 3 Dec 2018 08:03:22 +0000 (UTC) Received: from master.localdomain.com (unknown [10.64.242.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0C7D02166BA2; Mon, 3 Dec 2018 08:03:20 +0000 (UTC) From: Masatake YAMATO To: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, yamato@redhat.com Subject: [PATCH resend] eventfd: make eventfd files distinguishable in /proc/$PID/fd Date: Mon, 3 Dec 2018 17:03:17 +0900 Message-Id: <20181203080317.1028-1-yamato@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 03 Dec 2018 08:03:22 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 03 Dec 2018 08:03:22 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'yamato@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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