From patchwork Thu Apr 27 19:11:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sandhya Bankar X-Patchwork-Id: 9705703 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 C72CB602BE for ; Sat, 29 Apr 2017 07:44:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B3DA928671 for ; Sat, 29 Apr 2017 07:44:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A718828681; Sat, 29 Apr 2017 07:44:40 +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=-5.2 required=2.0 tests=BAYES_00, DATE_IN_PAST_24_48, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 5ED3228671 for ; Sat, 29 Apr 2017 07:44:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1952330AbdD2Hoh (ORCPT ); Sat, 29 Apr 2017 03:44:37 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:36765 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1951218AbdD2Hog (ORCPT ); Sat, 29 Apr 2017 03:44:36 -0400 Received: by mail-pf0-f194.google.com with SMTP id v14so20533466pfd.3; Sat, 29 Apr 2017 00:44:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=3wdcXQVOjCUhhin+5DpNNhaGNhLsjlk18e0O/BqT74k=; b=Q7fKPTu8d6EbQRpQcsZrPlk2M2qIuoKR8kNsPyDdlXkwINRIsONzgUUSTLqrkKm332 an4rBF0Ga2BxmF8T4XTFBb6xyk6rVg5xqSSj/tNS15xKipw5T7Aq3KsvEOs+g4GX2SJT H5pa7QjeSPSKWto+aFVMyCLICaEBsLoss5pdsoe28d4evLrMotiWxpw7mrBvhFQUTEWW E+n692/echhnHIwU6D0QMnUT78mpD30+nRq60JuZaEE/p/l06raxNqvSurhmUJDIdhjq wNw+GiO88zhH7Kmwt/g+Xqq6Mq9kZlcaAFf0tem+Bw4TamugYjfpU0t4vv66H6zxcVxi eY8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=3wdcXQVOjCUhhin+5DpNNhaGNhLsjlk18e0O/BqT74k=; b=K5BoOQsJ6BnBAOfVRp9xhXelQ2/mHs//oZI3KpqeqGpW8BJLjvbBoYIiSrFVPtyek0 hVLkLFH4eOiPEgKPbWhkuezJ/2Nldw6soqkBBFLYdBr3NrBn4sV2rf7Q2Vjly/BlLaON O5LQrKhHY0tymO8bEHrzRXUR1lJIWbBTp/HENiD/6klZVX69ffV9BhGL760ZgsGTBcCw k/RiFlTnEhocoOXfpjxrGUuv2iMA3pzJ6eswGPuUxC+VpIPx4HGUaBKC8Gcwnv/DGiIK WP60zg6XlXkapkfabepzZyBIu96fb+MHZY12BsMArHWVcNjHgjO5qV6DtfSVJldwj/6k rqJg== X-Gm-Message-State: AN3rC/5od82D7YqUbdyyTOS8F4W0T9qoqYdhTFyH89qQc5wBVSFxsfZS mE97n/aeCpXWww== X-Received: by 10.99.121.67 with SMTP id u64mr16211415pgc.230.1493451875876; Sat, 29 Apr 2017 00:44:35 -0700 (PDT) Received: from localhost.localdomain ([223.229.187.11]) by smtp.gmail.com with ESMTPSA id y29sm16469632pfj.90.2017.04.29.00.44.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 29 Apr 2017 00:44:35 -0700 (PDT) Date: Fri, 28 Apr 2017 00:41:26 +0530 From: Sandhya Bankar To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk, mawmilcox@microsoft.com, keescook@chromium.org, adobriyan@gmail.com, re.emese@gmail.com, riel@surriel.com Subject: [PATCH 08/13] vfs: Use idr_tag_get() in fd_is_open(). Message-ID: <803d5cf972ccf2328df353c29eeb1e65464f7028.1493315290.git.bankarsandhya512@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) 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 Use idr_tag_get() in fd_is_open() to know whether a given fd is allocated. Also move fd_is_open() to file.c and make it static as it is only called from one place. Signed-off-by: Sandhya Bankar Signed-off-by: Matthew Wilcox --- fs/file.c | 7 ++++++- include/linux/fdtable.h | 5 ----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/fs/file.c b/fs/file.c index e8c6ada..8d67968 100644 --- a/fs/file.c +++ b/fs/file.c @@ -222,6 +222,11 @@ static int expand_files(struct files_struct *files, unsigned int nr) return expanded; } +static inline bool fd_is_open(unsigned int fd, struct files_struct *files) +{ + return !idr_tag_get(&files->fd_idr, fd, IDR_FREE); +} + static inline void __set_close_on_exec(unsigned int fd, struct fdtable *fdt) { __set_bit(fd, fdt->close_on_exec); @@ -778,7 +783,7 @@ static int do_dup2(struct files_struct *files, */ fdt = files_fdtable(files); tofree = idr_find(&files->fd_idr, fd); - if (!tofree && fd_is_open(fd, fdt)) + if (!tofree && fd_is_open(fd, files)) goto Ebusy; get_file(file); if (tofree) { diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h index 6bece35..67259f4 100644 --- a/include/linux/fdtable.h +++ b/include/linux/fdtable.h @@ -34,11 +34,6 @@ static inline bool close_on_exec(unsigned int fd, const struct fdtable *fdt) return test_bit(fd, fdt->close_on_exec); } -static inline bool fd_is_open(unsigned int fd, const struct fdtable *fdt) -{ - return test_bit(fd, fdt->open_fds); -} - /* * Open file table structure */