Received: by 10.192.165.148 with SMTP id m20csp1106380imm; Wed, 2 May 2018 14:17:11 -0700 (PDT) X-Google-Smtp-Source: AB8JxZop+GcZcHDkj4rqwKGznLoQ9YXWJntJO3+pZ6VyGLUmTyv1xIGtBLFUY5pEFLqrymHdMsS/ X-Received: by 10.98.34.24 with SMTP id i24mr4283786pfi.53.1525295831763; Wed, 02 May 2018 14:17:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525295831; cv=none; d=google.com; s=arc-20160816; b=rrpaZimuxBSlcXdKPfZ7D7Lzg+/9pkxRB6M/g22E8FuNMuFv3fDg+AbB9rgSRLJ/+4 PrMuf7rKoVQFeWXgMRMugY8V631X7u6C1h0n8T0B7L7Br40x34pCHZgkkL3d11VR6ujE zcbNWIx+MtWSo0zQiwLSdYbuwXSFXfPd1SYtxedD5+438Dr3o7tQMda01rLyvQ0P5Woa XN01nGCODLr9uFoQxJ4TLn73O8qDHE5E9kQ2JyQpkiNaKFDxNC7BjYtM26eBEIcfgGjz NpbRV/CPPI/rZsaODtZrPdrMdb5PPpg2x7/I96cmebC9WE3uJk6Bfxqzd6BYh0KYpSq1 8xgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=fX/3jxpDkMnZ6H8w9eOZDvXFQlShFRVHH6rCP9RqGnc=; b=Hxgobb/wDS7Wh+/AVzUReO0MSnTUB2G46jrUt+NoYnG0hH+vJnULWnbDYyVEsJQHSy CI5RQCD4klcpWogrb4WRl7Z0lxTTvNbgA53XQQVFqRVNnif73eF547xJOZQVEwbal3f1 GLIrOXiK/r3hYAHFje91/HSnLSTWF4GwpfOE/m7UlnUftNEkvY1dECR67jVfDA+6crOM cbD4qXOw/iA0nyRdjE+Obu1dfXSCRb7ReYaGsyZHZnRsy5EXrGj9vxEbTfM5dvvKzkaO 7sATNOMdXGTkP20FFlZR/7wmuCowjd88vVFi7AoCZbso8GsHEps8symNRwgqp99X6evt tCXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=hDGQ72K6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s3-v6si9576438plp.241.2018.05.02.14.16.57; Wed, 02 May 2018 14:17:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=hDGQ72K6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751829AbeEBVPX (ORCPT + 99 others); Wed, 2 May 2018 17:15:23 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:37906 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751420AbeEBVPS (ORCPT ); Wed, 2 May 2018 17:15:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=fX/3jxpDkMnZ6H8w9eOZDvXFQlShFRVHH6rCP9RqGnc=; b=hDGQ72K6gwPYZGwaGl+16fwva FNHbMuFDpx8ypmrWjEbUrCHuIue0L1LF/Ajy/wMzpwJoaY+QeNoKvZzMJwdzaM1ZuHF5yiM8m4Oxq QyJdOnnbuHY62rv+IHm3CyNLuHnc0eADGd5k4xv8+UOHmfm5XOraT0vLj+5BbJ1wsl8RveMatAmIE Eeuiwe1l2F67LmaP4uQ3jN9ZZLAghwgDHoWK/Q43oBoF04PFrCeJYDb7vK9+ajDfhvvzeV8AQ2sHt hzSTLDliZBglJY0MVQ/Zi6CKHo9uaahidC4Aphok7qwP8l7nJy/xq6NqD+EVjjIx6YYuK8yo3vxuE GxZveSSFQ==; Received: from 089144213252.atnat0022.highway.a1.net ([89.144.213.252] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fDz5o-000896-TE; Wed, 02 May 2018 21:15:17 +0000 From: Christoph Hellwig To: viro@zeniv.linux.org.uk Cc: Avi Kivity , linux-aio@kvack.org, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 6/7] aio: implement IOCB_CMD_FSYNC and IOCB_CMD_FDSYNC Date: Wed, 2 May 2018 23:14:47 +0200 Message-Id: <20180502211448.18276-7-hch@lst.de> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180502211448.18276-1-hch@lst.de> References: <20180502211448.18276-1-hch@lst.de> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Simple workqueue offload for now, but prepared for adding a real aio_fsync method if the need arises. Based on an earlier patch from Dave Chinner. Signed-off-by: Christoph Hellwig Reviewed-by: Greg Kroah-Hartman Reviewed-by: Darrick J. Wong --- fs/aio.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/fs/aio.c b/fs/aio.c index d07c27b3fe88..61d2e6942951 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -156,6 +156,12 @@ struct kioctx { unsigned id; }; +struct fsync_iocb { + struct work_struct work; + struct file *file; + bool datasync; +}; + /* * We use ki_cancel == KIOCB_CANCELLED to indicate that a kiocb has been either * cancelled or completed (this makes a certain amount of sense because @@ -172,6 +178,7 @@ struct kioctx { struct aio_kiocb { union { struct kiocb rw; + struct fsync_iocb fsync; }; struct kioctx *ki_ctx; @@ -1573,6 +1580,36 @@ static ssize_t aio_write(struct kiocb *req, struct iocb *iocb, bool vectored, return ret; } +static void aio_fsync_work(struct work_struct *work) +{ + struct fsync_iocb *req = container_of(work, struct fsync_iocb, work); + int ret; + + ret = vfs_fsync(req->file, req->datasync); + fput(req->file); + aio_complete(container_of(req, struct aio_kiocb, fsync), ret, 0); +} + +static int aio_fsync(struct fsync_iocb *req, struct iocb *iocb, bool datasync) +{ + if (unlikely(iocb->aio_buf || iocb->aio_offset || iocb->aio_nbytes || + iocb->aio_rw_flags)) + return -EINVAL; + + req->file = fget(iocb->aio_fildes); + if (unlikely(!req->file)) + return -EBADF; + if (unlikely(!req->file->f_op->fsync)) { + fput(req->file); + return -EINVAL; + } + + req->datasync = datasync; + INIT_WORK(&req->work, aio_fsync_work); + schedule_work(&req->work); + return -EIOCBQUEUED; +} + static int io_submit_one(struct kioctx *ctx, struct iocb __user *user_iocb, struct iocb *iocb, bool compat) { @@ -1636,6 +1673,12 @@ static int io_submit_one(struct kioctx *ctx, struct iocb __user *user_iocb, case IOCB_CMD_PWRITEV: ret = aio_write(&req->rw, iocb, true, compat); break; + case IOCB_CMD_FSYNC: + ret = aio_fsync(&req->fsync, iocb, false); + break; + case IOCB_CMD_FDSYNC: + ret = aio_fsync(&req->fsync, iocb, true); + break; default: pr_debug("invalid aio operation %d\n", iocb->aio_lio_opcode); ret = -EINVAL; -- 2.17.0