From patchwork Thu Sep 7 18:42:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Padovan X-Patchwork-Id: 9942693 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 09126602CC for ; Thu, 7 Sep 2017 18:44:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 04DD2287FA for ; Thu, 7 Sep 2017 18:44:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EDBDB287FE; Thu, 7 Sep 2017 18:44:03 +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=-6.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=unavailable 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 9139A287FA for ; Thu, 7 Sep 2017 18:44:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932297AbdIGSna (ORCPT ); Thu, 7 Sep 2017 14:43:30 -0400 Received: from mail-qt0-f194.google.com ([209.85.216.194]:32909 "EHLO mail-qt0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932287AbdIGSn2 (ORCPT ); Thu, 7 Sep 2017 14:43:28 -0400 Received: by mail-qt0-f194.google.com with SMTP id h15so337897qta.0; Thu, 07 Sep 2017 11:43:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+jaWhrZJQn4Aqi5qGjIxhySxJT6a7wUiz+4QMzMLaDU=; b=hgrknq4jzwoyMeEXZQGn5BDjHyMTkdd4ImCo/S9zskvdbd9PtWczdph0KM5qNNpHc9 OUBo8PRkghdLnC8R4JnCtKmfBEni2Ir5U959WMitagj7u1JjEPLbQvBgP3t1QeJLpKzI MZOAVroON1O11n6UiMiP6t50RkZNC1fagVqH2PC9OBSjuU67A7g7/BOzkrymMKgWHG8v QVTO9dHTBBcczos06NJcdmNM6hKUgI2bXmeo+pSDpLFaRvVR8wEb59DsokbL5wcfCIAy ZdsdeyCC5CFypi6UoFCd1JIVLlGjm0hIfmRaTJacOkS9ee8PY65cSawOlpt4aGwDN2Ir OHHA== X-Gm-Message-State: AHPjjUgc2vnBW5h1ylZAL+XmCphAH7PZJJyO4WEHfPUZahp/56h5YuKg vF/1oiY3dLAIMjgy3JQ= X-Google-Smtp-Source: AOwi7QDpk7gj/0urjG5YHbYjeeN5Nm0WUxiQIW1djXPVrP4laDduzzW1eiXE9SdU7T6x3kkBrOUiMw== X-Received: by 10.237.62.200 with SMTP id o8mr464089qtf.294.1504809807090; Thu, 07 Sep 2017 11:43:27 -0700 (PDT) Received: from localhost.localdomain ([187.10.21.246]) by smtp.gmail.com with ESMTPSA id v30sm213216qtg.70.2017.09.07.11.43.22 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Sep 2017 11:43:26 -0700 (PDT) From: Gustavo Padovan To: linux-media@vger.kernel.org Cc: Hans Verkuil , Mauro Carvalho Chehab , Shuah Khan , linux-kernel@vger.kernel.org, Gustavo Padovan , Alexander Viro , linux-fsdevel@vger.kernel.org, Riley Andrews Subject: [PATCH v3 14/15] fs/files: export close_fd() symbol Date: Thu, 7 Sep 2017 15:42:25 -0300 Message-Id: <20170907184226.27482-15-gustavo@padovan.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170907184226.27482-1-gustavo@padovan.org> References: <20170907184226.27482-1-gustavo@padovan.org> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Gustavo Padovan Rename __close_fd() to close_fd() and export it to be able close files in modules using file descriptors. The usecase that motivates this change happens in V4L2 where we send events to userspace with a fd that has file installed in it. But if for some reason we have to cancel the video stream we need to close the files that haven't been shared with userspace yet. Thus the export of close_fd() becomes necessary. fd_install() happens when we call an ioctl to queue a buffer, but we only share the fd with userspace later, and that may happen in a kernel thread instead. Cc: Alexander Viro Cc: linux-fsdevel@vger.kernel.org Cc: Riley Andrews Signed-off-by: Gustavo Padovan --- This is more like a question, I don't know how unhappy people will be with this proposal to expose close_fd(). I'm all ears for more interesting ways of doing it! --- drivers/android/binder.c | 2 +- fs/file.c | 5 +++-- fs/open.c | 2 +- include/linux/fdtable.h | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/android/binder.c b/drivers/android/binder.c index f7665c31feca..5a9bc73012df 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -440,7 +440,7 @@ static long task_close_fd(struct binder_proc *proc, unsigned int fd) if (proc->files == NULL) return -ESRCH; - retval = __close_fd(proc->files, fd); + retval = close_fd(proc->files, fd); /* can't restart close syscall because file table entry was cleared */ if (unlikely(retval == -ERESTARTSYS || retval == -ERESTARTNOINTR || diff --git a/fs/file.c b/fs/file.c index 1fc7fbbb4510..111d387ac190 100644 --- a/fs/file.c +++ b/fs/file.c @@ -618,7 +618,7 @@ EXPORT_SYMBOL(fd_install); /* * The same warnings as for __alloc_fd()/__fd_install() apply here... */ -int __close_fd(struct files_struct *files, unsigned fd) +int close_fd(struct files_struct *files, unsigned fd) { struct file *file; struct fdtable *fdt; @@ -640,6 +640,7 @@ int __close_fd(struct files_struct *files, unsigned fd) spin_unlock(&files->file_lock); return -EBADF; } +EXPORT_SYMBOL(close_fd); void do_close_on_exec(struct files_struct *files) { @@ -856,7 +857,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags) struct files_struct *files = current->files; if (!file) - return __close_fd(files, fd); + return close_fd(files, fd); if (fd >= rlimit(RLIMIT_NOFILE)) return -EBADF; diff --git a/fs/open.c b/fs/open.c index 35bb784763a4..30907d967443 100644 --- a/fs/open.c +++ b/fs/open.c @@ -1152,7 +1152,7 @@ EXPORT_SYMBOL(filp_close); */ SYSCALL_DEFINE1(close, unsigned int, fd) { - int retval = __close_fd(current->files, fd); + int retval = close_fd(current->files, fd); /* can't restart close syscall because file table entry was cleared */ if (unlikely(retval == -ERESTARTSYS || diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h index 6e84b2cae6ad..511fd38d5e4b 100644 --- a/include/linux/fdtable.h +++ b/include/linux/fdtable.h @@ -115,7 +115,7 @@ extern int __alloc_fd(struct files_struct *files, unsigned start, unsigned end, unsigned flags); extern void __fd_install(struct files_struct *files, unsigned int fd, struct file *file); -extern int __close_fd(struct files_struct *files, +extern int close_fd(struct files_struct *files, unsigned int fd); extern struct kmem_cache *files_cachep;