From patchwork Mon Jan 11 22:07:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin LaHaise X-Patchwork-Id: 8012371 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 0C796BEEE5 for ; Mon, 11 Jan 2016 22:08:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 207E1201C7 for ; Mon, 11 Jan 2016 22:08:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 22196201BB for ; Mon, 11 Jan 2016 22:08:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761260AbcAKWHs (ORCPT ); Mon, 11 Jan 2016 17:07:48 -0500 Received: from kanga.kvack.org ([205.233.56.17]:53147 "EHLO kanga.kvack.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1761252AbcAKWHq (ORCPT ); Mon, 11 Jan 2016 17:07:46 -0500 Received: by kanga.kvack.org (Postfix, from userid 63042) id 9A03F82A87; Mon, 11 Jan 2016 17:07:45 -0500 (EST) Date: Mon, 11 Jan 2016 17:07:45 -0500 From: Benjamin LaHaise To: linux-aio@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, linux-mm@kvack.org Cc: Alexander Viro , Andrew Morton , Linus Torvalds Subject: [PATCH 10/13] aio: add async unlinkat functionality Message-ID: <3872f0076fb0a1b7e9e71c6735bac9ed55b27bdb.1452549431.git.bcrl@kvack.org> References: Mime-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.2i Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 Enable asynchronous deletion of files by adding support for an aio unlinkat operation. Signed-off-by: Benjamin LaHaise Signed-off-by: Benjamin LaHaise --- fs/aio.c | 42 +++++++++++++++++++++++++++++++++--------- fs/namei.c | 2 +- include/linux/fs.h | 1 + include/uapi/linux/aio_abi.h | 1 + 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/fs/aio.c b/fs/aio.c index 346786b..3a70492 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -232,7 +232,11 @@ static const struct address_space_operations aio_ctx_aops; static void aio_complete(struct kiocb *kiocb, long res, long res2); ssize_t aio_fsync(struct kiocb *iocb, int datasync); long aio_poll(struct aio_kiocb *iocb); -long aio_openat(struct aio_kiocb *req); + +typedef long (*do_foo_at_t)(int fd, const char *filename, int flags, int mode); +long aio_do_openat(int fd, const char *filename, int flags, int mode); +long aio_do_unlinkat(int fd, const char *filename, int flags, int mode); +long aio_foo_at(struct aio_kiocb *req, do_foo_at_t do_foo_at); static __always_inline bool aio_may_use_threads(void) { @@ -1763,7 +1767,19 @@ long aio_poll(struct aio_kiocb *req) return aio_thread_queue_iocb(req, aio_thread_op_poll, 0); } -static long aio_thread_op_openat(struct aio_kiocb *req) +long aio_do_openat(int fd, const char *filename, int flags, int mode) +{ + return do_sys_open(fd, filename, flags, mode); +} + +long aio_do_unlinkat(int fd, const char *filename, int flags, int mode) +{ + if (flags || mode) + return -EINVAL; + return do_unlinkat(fd, filename); +} + +static long aio_thread_op_foo_at(struct aio_kiocb *req) { u64 buf, offset; long ret; @@ -1777,18 +1793,21 @@ static long aio_thread_op_openat(struct aio_kiocb *req) else if (unlikely(__get_user(offset, &req->ki_user_iocb->aio_offset))) ret = -EFAULT; else { - ret = do_sys_open((s32)fd, - (const char __user *)(long)buf, - (int)offset, - (unsigned short)(offset >> 32)); + do_foo_at_t do_foo_at = (void *)req->ki_data; + + ret = do_foo_at((s32)fd, + (const char __user *)(long)buf, + (int)offset, + (unsigned short)(offset >> 32)); } unuse_mm(req->ki_ctx->mm); return ret; } -long aio_openat(struct aio_kiocb *req) +long aio_foo_at(struct aio_kiocb *req, do_foo_at_t do_foo_at) { - return aio_thread_queue_iocb(req, aio_thread_op_openat, + req->ki_data = (unsigned long)(void *)do_foo_at; + return aio_thread_queue_iocb(req, aio_thread_op_foo_at, AIO_THREAD_NEED_TASK | AIO_THREAD_NEED_FILES | AIO_THREAD_NEED_CRED); @@ -1895,7 +1914,12 @@ rw_common: case IOCB_CMD_OPENAT: if (aio_may_use_threads()) - ret = aio_openat(req); + ret = aio_foo_at(req, aio_do_openat); + break; + + case IOCB_CMD_UNLINKAT: + if (aio_may_use_threads()) + ret = aio_foo_at(req, aio_do_unlinkat); break; default: diff --git a/fs/namei.c b/fs/namei.c index 0c3974c..84ecc7e 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3828,7 +3828,7 @@ EXPORT_SYMBOL(vfs_unlink); * writeout happening, and we don't want to prevent access to the directory * while waiting on the I/O. */ -static long do_unlinkat(int dfd, const char __user *pathname) +long do_unlinkat(int dfd, const char __user *pathname) { int error; struct filename *name; diff --git a/include/linux/fs.h b/include/linux/fs.h index b3dc406..9051771 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1509,6 +1509,7 @@ extern int vfs_symlink(struct inode *, struct dentry *, const char *); extern int vfs_link(struct dentry *, struct inode *, struct dentry *, struct inode **); extern int vfs_rmdir(struct inode *, struct dentry *); extern int vfs_unlink(struct inode *, struct dentry *, struct inode **); +extern long do_unlinkat(int dfd, const char __user *pathname); extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *, struct inode **, unsigned int); extern int vfs_whiteout(struct inode *, struct dentry *); diff --git a/include/uapi/linux/aio_abi.h b/include/uapi/linux/aio_abi.h index 0e16988..63a0d41 100644 --- a/include/uapi/linux/aio_abi.h +++ b/include/uapi/linux/aio_abi.h @@ -46,6 +46,7 @@ enum { IOCB_CMD_PWRITEV = 8, IOCB_CMD_OPENAT = 9, + IOCB_CMD_UNLINKAT = 10, }; /*