From patchwork Wed Jan 16 17:49:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 10766503 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 25DDD13B4 for ; Wed, 16 Jan 2019 17:50:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1547A2EFE5 for ; Wed, 16 Jan 2019 17:50:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 083062EF92; Wed, 16 Jan 2019 17:50:25 +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=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham 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 932BE2EF93 for ; Wed, 16 Jan 2019 17:50:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727692AbfAPRuX (ORCPT ); Wed, 16 Jan 2019 12:50:23 -0500 Received: from mail-it1-f193.google.com ([209.85.166.193]:55962 "EHLO mail-it1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727685AbfAPRuX (ORCPT ); Wed, 16 Jan 2019 12:50:23 -0500 Received: by mail-it1-f193.google.com with SMTP id m62so4367644ith.5 for ; Wed, 16 Jan 2019 09:50:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=OupOW3VwHB6tWHT8SUdnb9w+rLEOXhO4z2r3B9lMfmc=; b=V35gud4RSLl8GBWK/qK4AZ3/fTcG8HgmILJ7vBRmj9gt4hsHT6MIiJcXh68R6Air61 i3NSXKnx3vB1sMyq1RWE5TV0Io2y4w93glHXw2ktDf58iC4XE9CmK75xFg+E165giC3s Bogv9stSJv6xDzMFtbhUMyxUXEWercXCfvbSwcN/pisktctzAuppiZTYVh2OTwJ9ecNu 3kKIq8Rp9KmX8r7gon0NNCCekBLrQHkdo60QgiETFSVD9bW6OZz+BuK+3LmbBhdgA6Jp 5ktkvNNhTSBRM3KWEGI0QE+9z9C2odh31cXBZGEL0Z/64i9h1InjpPAOfh5y8swlIChB t1Yg== 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=OupOW3VwHB6tWHT8SUdnb9w+rLEOXhO4z2r3B9lMfmc=; b=L3l/zd3ralElPmmEumlC7zMyz2vdVCVCzjAC+3lPGpcQjpinunsoVqYou3m2AgCly3 LuSMSPIZajHbmHviZRqYIW+isfxvEpPbMLBbUzGUl+r01xfCKTYtB8HRctHdklLpVobG EAFPOMnGnZFdEdG3kNnyYwPqqsha3CABh7OgEPZSqqSGi5gKzFdvz6fjavqJeEJ0kQ/U O4X7yO9P6JK7NRFRpGQbeHrANHYZL+cHRvjK/zWph9zWH/Rjma6kvMuhf8mRXxJ5lDz8 Fe1JE8RHU4X4+l3J7kcmlPQL9MGiPKFpeWQnf6JQkrH+UbpIb0AARS8iSzr7fe5qptvf k4aw== X-Gm-Message-State: AJcUukd4GNIlSuXEnNx96rLDQ6zyjRa/SRz5zNYaWQoYgHdZP2xixnoW 1OTHDOjg1OAktto87WSHMYn+vg== X-Google-Smtp-Source: ALg8bN7qhbgAAeG18WwVcHx8zYCyZRCu5hghjF5mZkB6Z4/hFZBRCEiAFwQhz913LVZLJGY+orWdiA== X-Received: by 2002:a24:a64f:: with SMTP id r15mr6217194iti.101.1547661022505; Wed, 16 Jan 2019 09:50:22 -0800 (PST) Received: from x1.localdomain ([216.160.245.98]) by smtp.gmail.com with ESMTPSA id x128sm3705690itb.8.2019.01.16.09.50.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Jan 2019 09:50:21 -0800 (PST) From: Jens Axboe To: linux-fsdevel@vger.kernel.org, linux-aio@kvack.org, linux-block@vger.kernel.org, linux-arch@vger.kernel.org Cc: hch@lst.de, jmoyer@redhat.com, avi@scylladb.com, Jens Axboe Subject: [PATCH 06/15] io_uring: add fsync support Date: Wed, 16 Jan 2019 10:49:54 -0700 Message-Id: <20190116175003.17880-7-axboe@kernel.dk> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190116175003.17880-1-axboe@kernel.dk> References: <20190116175003.17880-1-axboe@kernel.dk> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Christoph Hellwig Add a new fsync opcode, which either syncs a range if one is passed, or the whole file if the offset and length fields are both cleared to zero. A flag is provided to use fdatasync semantics, that is only force out metadata which is required to retrieve the file data, but not others like metadata. Signed-off-by: Christoph Hellwig Signed-off-by: Jens Axboe --- fs/io_uring.c | 33 +++++++++++++++++++++++++++++++++ include/uapi/linux/io_uring.h | 8 +++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 54dac6213a4f..47959f28d5e0 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -457,6 +457,36 @@ static int io_nop(struct io_kiocb *req, const struct io_uring_sqe *sqe) return 0; } +static int io_fsync(struct io_kiocb *req, const struct io_uring_sqe *sqe, + bool force_nonblock) +{ + struct io_ring_ctx *ctx = req->ctx; + loff_t end = sqe->off + sqe->len; + struct file *file; + int ret; + + /* fsync always requires a blocking context */ + if (force_nonblock) + return -EAGAIN; + + if (unlikely(sqe->addr)) + return -EINVAL; + if (unlikely(sqe->fsync_flags & ~IORING_FSYNC_DATASYNC)) + return -EINVAL; + + file = fget(sqe->fd); + if (unlikely(!file)) + return -EBADF; + + ret = vfs_fsync_range(file, sqe->off, end > 0 ? end : LLONG_MAX, + sqe->fsync_flags & IORING_FSYNC_DATASYNC); + + fput(file); + io_cqring_fill_event(ctx, sqe->user_data, ret, 0); + io_free_req(req); + return 0; +} + static int __io_submit_sqe(struct io_ring_ctx *ctx, struct io_kiocb *req, struct sqe_submit *s, bool force_nonblock) { @@ -482,6 +512,9 @@ static int __io_submit_sqe(struct io_ring_ctx *ctx, struct io_kiocb *req, case IORING_OP_WRITEV: ret = io_write(req, sqe, force_nonblock); break; + case IORING_OP_FSYNC: + ret = io_fsync(req, sqe, force_nonblock); + break; default: ret = -EINVAL; break; diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index 0b1dfc2a278a..3f5f9a8642cb 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -24,7 +24,7 @@ struct io_uring_sqe { __u32 len; /* buffer size or number of iovecs */ union { __kernel_rwf_t rw_flags; - __u32 __resv; + __u32 fsync_flags; }; __u64 user_data; /* data to be passed back at completion time */ __u64 __pad2[3]; @@ -33,6 +33,12 @@ struct io_uring_sqe { #define IORING_OP_NOP 0 #define IORING_OP_READV 1 #define IORING_OP_WRITEV 2 +#define IORING_OP_FSYNC 3 + +/* + * sqe->fsync_flags + */ +#define IORING_FSYNC_DATASYNC (1 << 0) /* * IO completion data structure (Completion Queue Entry)