From patchwork Fri Jan 18 16:12:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 10770783 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 A78E613B5 for ; Fri, 18 Jan 2019 16:12:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 98D042F3B0 for ; Fri, 18 Jan 2019 16:12:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8D4222F571; Fri, 18 Jan 2019 16:12:50 +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=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 350212F3B0 for ; Fri, 18 Jan 2019 16:12:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727903AbfARQMs (ORCPT ); Fri, 18 Jan 2019 11:12:48 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:44064 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727825AbfARQMs (ORCPT ); Fri, 18 Jan 2019 11:12:48 -0500 Received: by mail-pg1-f195.google.com with SMTP id t13so6254015pgr.11 for ; Fri, 18 Jan 2019 08:12:47 -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=B+ngOqxtkell8tMitE8QAbzC+xS03+bz1EA2WKjHVWQ=; b=b55XYKNn1eBDlEJOscP4/EvADszggrtPnUgZLmEZVccomiGNkrYvP8v3Ba5HM0FZlI /N3LVqYXNylPVY2U0K6cqLCDAc2NwIb+RQftc3RirQFAahsljwaiXVuBI1+E2MD4I6T3 MmtCFX7h8I6zNHll7WmNrjse5xdd+uB1u+JasLHrajgD+S7Wh1BhfsANHgP+/ddN9XDd uU31U8iMF+37CT01RmEF40ZjSfoIZ2W2nbRukzicdYUQlUSB8zhQ7PIs36ZSBuw8rfzl ie519csaqhPcmBG/E1OTyB4Cd4GN5mGQAwjJOmMa9RuAEU5ql77jf82DQgGei7beQTvE b6Tg== 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=B+ngOqxtkell8tMitE8QAbzC+xS03+bz1EA2WKjHVWQ=; b=NCnUbk5dvr9Bxr0jBz9+jEEKUkZNdLW7lyUddHU/+R187vh0Z8qBVEZ2+z0bLE0SKr V7nZqYydKrxSinhzr1d93zpsBRmZ3AXjs26ZahiKf9u/oVScBH/LmP5Y1IxtggXyNfJt 5o4a9aEN/jPIFrUjh2hR+vhZ3YCcPymiCkFQb2fzmaNb9wEhuHIJYjEUKPIYzfAN6vav oxVdVpV9Uc81yCC85nTwufEau/AhhgRbSCJQLu3Moioe+s0ArZSq4ccwVq4coOexwvMk hdwHmV7NIz5MZiGcARf7/dItTZhwSbUzg9JCPAGLSn8RFnenvh7x9C6K0RI8nsrDQBpR pJcA== X-Gm-Message-State: AJcUukeih2onv8qUPg4q4AjNhHxSsIvCC8KSuRMhIOsENmceya43lmLO 5Gd6eC96yHTSLhI+vcCxXB1hhquCmNO1cw== X-Google-Smtp-Source: ALg8bN6j16HsXbr7xqXEPoSo0EbI6cwDlwrCk0TxFaKdNOLoKqGGbxqrXC3d7IH6nGRymNdD+e6+jQ== X-Received: by 2002:a63:981:: with SMTP id 123mr18405305pgj.444.1547827966871; Fri, 18 Jan 2019 08:12:46 -0800 (PST) Received: from x1.localdomain (66.29.188.166.static.utbb.net. [66.29.188.166]) by smtp.gmail.com with ESMTPSA id m20sm5317804pgv.93.2019.01.18.08.12.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Jan 2019 08:12:45 -0800 (PST) From: Jens Axboe To: linux-fsdevel@vger.kernel.org, linux-aio@kvack.org, linux-block@vger.kernel.org Cc: hch@lst.de, jmoyer@redhat.com, avi@scylladb.com, Jens Axboe Subject: [PATCH 06/17] io_uring: add fsync support Date: Fri, 18 Jan 2019 09:12:14 -0700 Message-Id: <20190118161225.4545-7-axboe@kernel.dk> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190118161225.4545-1-axboe@kernel.dk> References: <20190118161225.4545-1-axboe@kernel.dk> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@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 | 34 ++++++++++++++++++++++++++++++++++ include/uapi/linux/io_uring.h | 8 +++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 2952d0a82dd3..f464f6ca2b7d 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -4,6 +4,7 @@ * supporting fast/efficient IO. * * Copyright (C) 2018-2019 Jens Axboe + * Copyright (c) 2018-2019 Christoph Hellwig */ #include #include @@ -465,6 +466,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 || sqe->ioprio)) + 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_add_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) { @@ -486,6 +517,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 ce65db9269a8..ca503ded73e3 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -26,7 +26,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]; @@ -35,6 +35,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)