From patchwork Tue Jan 15 02:55:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 10763873 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 0A5B013B4 for ; Tue, 15 Jan 2019 02:55:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF8D32CB05 for ; Tue, 15 Jan 2019 02:55:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DE52B2CB33; Tue, 15 Jan 2019 02:55:53 +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 82F372CB39 for ; Tue, 15 Jan 2019 02:55:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727963AbfAOCzw (ORCPT ); Mon, 14 Jan 2019 21:55:52 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:34521 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727960AbfAOCzv (ORCPT ); Mon, 14 Jan 2019 21:55:51 -0500 Received: by mail-pf1-f195.google.com with SMTP id h3so595754pfg.1 for ; Mon, 14 Jan 2019 18:55:50 -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=dvVSpCTDLkzAa0HlGl7Glbq/TudFLjKvX778OEvoz/k=; b=QYWwzZPa9eu0R3r96mVaH+sD7TkW0lmozYcIT7raUw1151ReLpzsg/dSy4O+t1mXJc dnQUDSH2oKih4WcbCn9qARB6GsyeJDg7tR53jDyqbdhBi6a+JFv1rEhBD3s1dOO6LUFC bcE40wTQMEOviP2O1Y/LDHI6gANBZoiMr6ud6DPUaJAK2wzpYOHFA40N6PrLwdVWSWxi AjIoxlJXDuR9+9VHG6P2ZU/ZyjGkI+R49kOLkKh5NYZZ4bv1xr4/VSMxg80zkfFK2rhJ rQNOHzKpf1yAVVX9SNX5QCsrDGIdWo6G+I4Umvw6y97JW1+uF64kfJGblLkpqpsaJgQ5 X/TQ== 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=dvVSpCTDLkzAa0HlGl7Glbq/TudFLjKvX778OEvoz/k=; b=c8rUeo29JLcxO/xYdzNS3Zzb8U4lb7oBKXLQqOf3Q912WslZeawkApIYXIxm6ETYtP t05AxoDX19sn55r0LbiI8sZFme0kisMyM3Y9vaZPeFRhPFEXkmtnT14bNQ7Pj2PKAtj+ bwDPfnsolGhKmhDNohO+wNCF5XghyFfNNE1r2TzRziIfaO5r8+TTqwN38p23g6OPgBfs 1LB3+//yDcTnYFhFiZCAJAWO5Q2CKJu5BLa/3F0qUUbyfM9DdzbR0gx7glm7Ys0W1HYC hO7a1zo3cMsdQOLTjbe3msI+ICK2pQWyLhdJFxXE1kFdy0PE0cd4QqbDhPSKp9xdEwnb 9sIA== X-Gm-Message-State: AJcUukcrzNW/4R8Ht3Rq70tEbO8EW6ORSPOptKYJSGid58asow6mTry8 oDsBnhvll+Y7GgA+RqgLYAxwQWLS/J7Dvw== X-Google-Smtp-Source: ALg8bN5FJEH8/MHHlCPHqrJdTbHX/L4WLJqsjNLtsSutxYIHLuTsXVShwmCCRTIbN0sr9jBcqm+d9A== X-Received: by 2002:a63:f444:: with SMTP id p4mr1692242pgk.124.1547520949830; Mon, 14 Jan 2019 18:55:49 -0800 (PST) Received: from x1.localdomain (66.29.188.166.static.utbb.net. [66.29.188.166]) by smtp.gmail.com with ESMTPSA id c23sm2415544pfi.83.2019.01.14.18.55.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Jan 2019 18:55:48 -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/16] io_uring: add fsync support Date: Mon, 14 Jan 2019 19:55:21 -0700 Message-Id: <20190115025531.13985-7-axboe@kernel.dk> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190115025531.13985-1-axboe@kernel.dk> References: <20190115025531.13985-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 | 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 148eb3af7dc4..7d74463217a6 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -449,6 +449,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) { @@ -474,6 +504,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 a1ebaa09e1b8..ac49bd179ed9 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -27,7 +27,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]; @@ -36,6 +36,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)