From patchwork Mon Jan 11 22:07:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin LaHaise X-Patchwork-Id: 8012401 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 70CCABEEE5 for ; Mon, 11 Jan 2016 22:10:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9B516201BB for ; Mon, 11 Jan 2016 22:10:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BBE01200E3 for ; Mon, 11 Jan 2016 22:10:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761136AbcAKWH3 (ORCPT ); Mon, 11 Jan 2016 17:07:29 -0500 Received: from kanga.kvack.org ([205.233.56.17]:52461 "EHLO kanga.kvack.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1761035AbcAKWHZ (ORCPT ); Mon, 11 Jan 2016 17:07:25 -0500 Received: by kanga.kvack.org (Postfix, from userid 63042) id CFDD9828FD; Mon, 11 Jan 2016 17:07:23 -0500 (EST) Date: Mon, 11 Jan 2016 17:07:23 -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 07/13] aio: enabled thread based async fsync Message-ID: <80934665e0dd2360e2583522c7c7569e5a92be0e.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 a fully asynchronous fsync and fdatasync operations in aio using the aio thread queuing mechanism. Signed-off-by: Benjamin LaHaise Signed-off-by: Benjamin LaHaise --- fs/aio.c | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/fs/aio.c b/fs/aio.c index 88af450..576b780 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -224,8 +224,9 @@ static const struct file_operations aio_ring_fops; 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); -static bool aio_may_use_threads(void) +static __always_inline bool aio_may_use_threads(void) { #if IS_ENABLED(CONFIG_AIO_THREAD) return !!(aio_auto_threads & 1); @@ -1654,6 +1655,26 @@ ssize_t generic_async_write_iter(struct kiocb *iocb, struct iov_iter *iter) AIO_THREAD_NEED_TASK); } EXPORT_SYMBOL(generic_async_write_iter); + +static long aio_thread_op_fsync(struct aio_kiocb *iocb) +{ + return vfs_fsync(iocb->common.ki_filp, 0); +} + +static long aio_thread_op_fdatasync(struct aio_kiocb *iocb) +{ + return vfs_fsync(iocb->common.ki_filp, 1); +} + +ssize_t aio_fsync(struct kiocb *iocb, int datasync) +{ + struct aio_kiocb *req; + + req = container_of(iocb, struct aio_kiocb, common); + + return aio_thread_queue_iocb(req, datasync ? aio_thread_op_fdatasync + : aio_thread_op_fsync, 0); +} #endif /* IS_ENABLED(CONFIG_AIO_THREAD) */ /* @@ -1664,7 +1685,7 @@ static ssize_t aio_run_iocb(struct aio_kiocb *req, unsigned opcode, char __user *buf, size_t len, bool compat) { struct file *file = req->common.ki_filp; - ssize_t ret; + ssize_t ret = -EINVAL; int rw; fmode_t mode; rw_iter_op *iter_op; @@ -1730,17 +1751,17 @@ rw_common: break; case IOCB_CMD_FDSYNC: - if (!file->f_op->aio_fsync) - return -EINVAL; - - ret = file->f_op->aio_fsync(&req->common, 1); + if (file->f_op->aio_fsync) + ret = file->f_op->aio_fsync(&req->common, 1); + else if (file->f_op->fsync && (aio_may_use_threads())) + ret = aio_fsync(&req->common, 1); break; case IOCB_CMD_FSYNC: - if (!file->f_op->aio_fsync) - return -EINVAL; - - ret = file->f_op->aio_fsync(&req->common, 0); + if (file->f_op->aio_fsync) + ret = file->f_op->aio_fsync(&req->common, 0); + else if (file->f_op->fsync && (aio_may_use_threads())) + ret = aio_fsync(&req->common, 0); break; default: