Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3268878pxb; Fri, 12 Feb 2021 13:52:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJzf2ei2elWh2KFXGUOBSCI0q08Av7j/NJeG28MnDcsr+LvokR5VuVv4W7cVSN+Hd/P3wp2N X-Received: by 2002:a05:6402:27cf:: with SMTP id c15mr5328371ede.179.1613166725465; Fri, 12 Feb 2021 13:52:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613166725; cv=none; d=google.com; s=arc-20160816; b=IUaseJeqHdzRIVu+ejEUxetCsoke24C9e6N3hZXWkO9Ctoj15rMl+WFoCPi+IN8BiY tN+UzeW2JKw/DGWsjfLfkOFFI0CjcF2tC8h8aYECSwy0FiiM9qwpjL78wDJRWJ2LnZfe 8fotkoCPvT6UuxehIhhw4/4wHfp1oCrqrUR+WIKZ2T5p593hBMsuvJ7NVNZEGwXvt5NR RrG8l/83Kg2Nfw/Af5K9WV+fnx0DSYIK9Rn9h950erdGdoOOeddW+KtVbx+vKfEAzHxO oHAIFbGGlZtrNUECjwYcZrmuNqj+wvsGtoeDqPALx2kcuCWukpUmo8sD8myENg1SIm5E essw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=cS1ezLdQ0GpYYaXeEj37KiGF8ivKwqVMArkRibybohQ=; b=EfoypK2UojIbQTSCh/STi7xlB8yB9gXFv1Q8MQVOuBM3u17jK2E4mXE+oAF3ljqof5 Pl63+l4u/FO2jg3tIqzcx8w56ec44VJHBCe3oqx7RXb3dyLbRYNv0r8Y+/XzNk1qbwkj +E/ZAIQFLx/kB8FUhTcKsk/adfM9BImZiP0engq7FpZE1hnaiVvrgmo5l+EK+P50Bo1l ilsYrPD+s7Sui49n6pG2KNJQgTtyWpL/+h6P+SzCqYPXuLxOoHzYhY9VC98UywtrnEfQ 9HZ7nbUfIhZ+Tgs/Vk9gszuObPcJOIu4zu1HOC1ozfXGEo0zT6L/I+TJh5KsyPW666L/ sIhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AIjlfvBM; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j23si7959597eje.690.2021.02.12.13.51.37; Fri, 12 Feb 2021 13:52:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AIjlfvBM; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229660AbhBLVui (ORCPT + 99 others); Fri, 12 Feb 2021 16:50:38 -0500 Received: from mail.kernel.org ([198.145.29.99]:36316 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229798AbhBLVug (ORCPT ); Fri, 12 Feb 2021 16:50:36 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id E565E64E26; Fri, 12 Feb 2021 21:49:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1613166595; bh=MGBYksKj9YOAWZcv1wlY9+qUNr0pAjdxQkdH40fJq6o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AIjlfvBMBYldwgNJwC6RDDvbaOl2bibqIp9RhKaNXyPmlwR42h433Ph5sVdNL7WZV M7DjPRdTzVhYtFCOzAalHr/xgeiEU0MxFQpkMXAUt1lduJy4aMFFFJ/qilFyy+5Ahp Vz2tay86tFXsmprhsa7KBy7ODkMWzGTisrNsMbaWHiC5sLzyBj0L0wJd6lzW3h4dcb 1GGMHrAH2K3kB0Cg6b2w3+ZtAw8FURQlBeTBgfiRZyet5zOSPrPvNdMU/7Is3n2jvZ chIy+ohF22NE1d/NRkeWbMg7KReH2/I0q5Q3otsK3OVjFlijPIADZyFpGQK+gNbOxH 0ySxleRHWswmQ== From: trondmy@kernel.org To: Anna Schumaker Cc: linux-nfs@vger.kernel.org Subject: [PATCH 2/3] NFS: Add support for eager writes Date: Fri, 12 Feb 2021 16:49:48 -0500 Message-Id: <20210212214949.4408-3-trondmy@kernel.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210212214949.4408-2-trondmy@kernel.org> References: <20210212214949.4408-1-trondmy@kernel.org> <20210212214949.4408-2-trondmy@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust Support eager writing to the server, meaning that we write the data to cache on the server, and wait for that to complete. This ensures that we see ENOSPC errors immediately. Signed-off-by: Trond Myklebust --- fs/nfs/file.c | 19 +++++++++++++++++-- fs/nfs/write.c | 17 ++++++++++++----- include/linux/nfs_fs_sb.h | 2 ++ 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/fs/nfs/file.c b/fs/nfs/file.c index 03fd1dcc96bd..16ad5050e046 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c @@ -606,8 +606,8 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from) { struct file *file = iocb->ki_filp; struct inode *inode = file_inode(file); - unsigned long written = 0; - ssize_t result; + unsigned int mntflags = NFS_SERVER(inode)->flags; + ssize_t result, written; errseq_t since; int error; @@ -648,6 +648,21 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from) written = result; iocb->ki_pos += written; + + if (mntflags & NFS_MOUNT_WRITE_EAGER) { + result = filemap_fdatawrite_range(file->f_mapping, + iocb->ki_pos - written, + iocb->ki_pos - 1); + if (result < 0) + goto out; + } + if (mntflags & NFS_MOUNT_WRITE_WAIT) { + result = filemap_fdatawait_range(file->f_mapping, + iocb->ki_pos - written, + iocb->ki_pos - 1); + if (result < 0) + goto out; + } result = generic_write_sync(iocb, written); if (result < 0) goto out; diff --git a/fs/nfs/write.c b/fs/nfs/write.c index 6193350356a8..82bdcb982186 100644 --- a/fs/nfs/write.c +++ b/fs/nfs/write.c @@ -712,16 +712,23 @@ int nfs_writepages(struct address_space *mapping, struct writeback_control *wbc) { struct inode *inode = mapping->host; struct nfs_pageio_descriptor pgio; - struct nfs_io_completion *ioc; + struct nfs_io_completion *ioc = NULL; + unsigned int mntflags = NFS_SERVER(inode)->flags; + int priority = 0; int err; nfs_inc_stats(inode, NFSIOS_VFSWRITEPAGES); - ioc = nfs_io_completion_alloc(GFP_KERNEL); - if (ioc) - nfs_io_completion_init(ioc, nfs_io_completion_commit, inode); + if (!(mntflags & NFS_MOUNT_WRITE_EAGER) || wbc->for_kupdate || + wbc->for_background || wbc->for_sync || wbc->for_reclaim) { + ioc = nfs_io_completion_alloc(GFP_KERNEL); + if (ioc) + nfs_io_completion_init(ioc, nfs_io_completion_commit, + inode); + priority = wb_priority(wbc); + } - nfs_pageio_init_write(&pgio, inode, wb_priority(wbc), false, + nfs_pageio_init_write(&pgio, inode, priority, false, &nfs_async_write_completion_ops); pgio.pg_io_completion = ioc; err = write_cache_pages(mapping, wbc, nfs_writepages_callback, &pgio); diff --git a/include/linux/nfs_fs_sb.h b/include/linux/nfs_fs_sb.h index 962e8313f007..6f76b32a0238 100644 --- a/include/linux/nfs_fs_sb.h +++ b/include/linux/nfs_fs_sb.h @@ -153,6 +153,8 @@ struct nfs_server { #define NFS_MOUNT_LOCAL_FCNTL 0x200000 #define NFS_MOUNT_SOFTERR 0x400000 #define NFS_MOUNT_SOFTREVAL 0x800000 +#define NFS_MOUNT_WRITE_EAGER 0x01000000 +#define NFS_MOUNT_WRITE_WAIT 0x02000000 unsigned int caps; /* server capabilities */ unsigned int rsize; /* read size */ -- 2.29.2