From patchwork Mon Sep 14 13:45:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 7176271 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 41E129F314 for ; Mon, 14 Sep 2015 13:49:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4169A206E2 for ; Mon, 14 Sep 2015 13:49:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4DD26206C0 for ; Mon, 14 Sep 2015 13:49:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755665AbbINNtC (ORCPT ); Mon, 14 Sep 2015 09:49:02 -0400 Received: from mail-yk0-f171.google.com ([209.85.160.171]:35425 "EHLO mail-yk0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754396AbbINNqF (ORCPT ); Mon, 14 Sep 2015 09:46:05 -0400 Received: by ykdu9 with SMTP id u9so153505943ykd.2 for ; Mon, 14 Sep 2015 06:46:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=vRfYRdPoDtb00hnJNaIn7LPRp8EPQJHqJJEt68eji0c=; b=hUwdHBkQxVv0bP3OKGpx0Ys57L8oDJHtIpHRyMlTAVRzekF0x764ygza2iSuGZY/KL GBiUkGg3EVFWqjvz+k9triOtQTg1YHD+321DLmyEFC3og89HI2ay+hd7ZhgYtxT4ePAs GnkhVp7pQDabPO+5xU1yTtvZzz8+MhcATMfky/gX5oMvpCtB2awti+px+CmMjY9+F946 67+iNPDv4WgyK7ez3zpFSJ7pbuQEHXVpgccMCcdL9loBznVNlyOMgeHXtKqU/lhIw2gi w66+Nc5f3duTWhkcK3i25YxTPLJUr3NDGvADzSN+2KwmNJWZ6FAvoaajdzmsj3UZeffQ 8g3g== X-Gm-Message-State: ALoCoQlFPrZH9INrnnIPMwq1Yp2MzsjZ/472IFus3sbVrg9HFEwMwK6hr4E+06ihaMlM6NaGLexH X-Received: by 10.13.229.1 with SMTP id o1mr4203605ywe.62.1442238364167; Mon, 14 Sep 2015 06:46:04 -0700 (PDT) Received: from tlielax.poochiereds.net ([2606:a000:1105:8e:3a60:77ff:fe93:a95d]) by smtp.googlemail.com with ESMTPSA id a4sm9601131ywc.15.2015.09.14.06.46.03 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Sep 2015 06:46:03 -0700 (PDT) From: Jeff Layton X-Google-Original-From: Jeff Layton To: Al Viro Cc: bfields@fieldses.org, linux-nfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/4] fs: add fput_queue Date: Mon, 14 Sep 2015 09:45:54 -0400 Message-Id: <1442238355-8203-4-git-send-email-jeff.layton@primarydata.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1442238355-8203-1-git-send-email-jeff.layton@primarydata.com> References: <1442238355-8203-1-git-send-email-jeff.layton@primarydata.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Jeff Layton --- fs/file_table.c | 18 ++++++++++++++++++ include/linux/file.h | 1 + 2 files changed, 19 insertions(+) diff --git a/fs/file_table.c b/fs/file_table.c index d63f4a399d39..1ad2e3fd2064 100644 --- a/fs/file_table.c +++ b/fs/file_table.c @@ -297,6 +297,24 @@ void fput(struct file *file) } EXPORT_SYMBOL(fput); +/** + * fput_queue - do an fput without using task_work + * @file: file of which to put the reference + * + * If we need to ensure that the final __fput is done on a file before + * returning to userland, then we can't queue it to task_work. For that we + * borrow the infrastructure used by kthreads, and the task can then just + * called flush_delayed_fput to ensure that the final fput has completed. + */ +void fput_queue(struct file *file) +{ + if (atomic_long_dec_and_test(&file->f_count)) { + if (llist_add(&file->f_u.fu_llist, &delayed_fput_list)) + schedule_delayed_work(&delayed_fput_work, 1); + } +} +EXPORT_SYMBOL(fput_queue); + /* * synchronous analog of fput(); for kernel threads that might be needed * in some umount() (and thus can't use flush_delayed_fput() without diff --git a/include/linux/file.h b/include/linux/file.h index f87d30882a24..543b0e2faf2c 100644 --- a/include/linux/file.h +++ b/include/linux/file.h @@ -12,6 +12,7 @@ struct file; extern void fput(struct file *); +extern void fput_queue(struct file *); struct file_operations; struct vfsmount;