From patchwork Sun May 20 20:18:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masatake YAMATO X-Patchwork-Id: 10413589 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CEBFD601F9 for ; Sun, 20 May 2018 20:18:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B648A27F60 for ; Sun, 20 May 2018 20:18:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AA77F27F89; Sun, 20 May 2018 20:18:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 48AE927F60 for ; Sun, 20 May 2018 20:18:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751678AbeETUSb (ORCPT ); Sun, 20 May 2018 16:18:31 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:55078 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751636AbeETUSb (ORCPT ); Sun, 20 May 2018 16:18:31 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C4E1F40122A4; Sun, 20 May 2018 20:18:30 +0000 (UTC) Received: from master.localdomain.com (unknown [10.64.242.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id CD74A2026609; Sun, 20 May 2018 20:18:29 +0000 (UTC) From: Masatake YAMATO To: linux-fsdevel@vger.kernel.org Cc: yamato@redhat.com Subject: [PATCH] eventfd: make eventfd files distinguishable in /proc/$PID/fd Date: Mon, 21 May 2018 05:18:23 +0900 Message-Id: <20180520201823.14293-1-yamato@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Sun, 20 May 2018 20:18:30 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Sun, 20 May 2018 20:18:30 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'yamato@redhat.com' RCPT:'' Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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);