v9fs.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: Jeff Layton <jlayton@kernel.org>, Steve French <smfrench@gmail.com>
Cc: David Howells <dhowells@redhat.com>,
	Matthew Wilcox <willy@infradead.org>,
	Marc Dionne <marc.dionne@auristor.com>,
	Paulo Alcantara <pc@manguebit.com>,
	Shyam Prasad N <sprasad@microsoft.com>,
	Tom Talpey <tom@talpey.com>,
	Dominique Martinet <asmadeus@codewreck.org>,
	Eric Van Hensbergen <ericvh@kernel.org>,
	Ilya Dryomov <idryomov@gmail.com>,
	Christian Brauner <christian@brauner.io>,
	linux-cachefs@redhat.com, linux-afs@lists.infradead.org,
	linux-cifs@vger.kernel.org, linux-nfs@vger.kernel.org,
	ceph-devel@vger.kernel.org, v9fs@lists.linux.dev,
	linux-fsdevel@vger.kernel.org, linux-mm@kvack.org,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v5 19/40] netfs: Extend the netfs_io_*request structs to handle writes
Date: Thu, 21 Dec 2023 13:23:14 +0000	[thread overview]
Message-ID: <20231221132400.1601991-20-dhowells@redhat.com> (raw)
In-Reply-To: <20231221132400.1601991-1-dhowells@redhat.com>

Modify the netfs_io_request struct to act as a point around which writes
can be coordinated.  It represents and pins a range of pages that need
writing and a list of regions of dirty data in that range of pages.

If RMW is required, the original data can be downloaded into the bounce
buffer, decrypted if necessary, the modifications made, then the modified
data can be reencrypted/recompressed and sent back to the server.

Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
cc: linux-cachefs@redhat.com
cc: linux-fsdevel@vger.kernel.org
cc: linux-mm@kvack.org
---
 fs/netfs/internal.h          |  6 ++++++
 fs/netfs/main.c              |  3 ++-
 fs/netfs/objects.c           |  6 ++++++
 fs/netfs/stats.c             | 16 +++++++++++++---
 include/linux/netfs.h        | 15 ++++++++++++++-
 include/trace/events/netfs.h |  8 ++++++--
 6 files changed, 47 insertions(+), 7 deletions(-)

diff --git a/fs/netfs/internal.h b/fs/netfs/internal.h
index b908c7e0a901..2bf2e82b2ad7 100644
--- a/fs/netfs/internal.h
+++ b/fs/netfs/internal.h
@@ -110,6 +110,12 @@ extern atomic_t netfs_n_rh_write_begin;
 extern atomic_t netfs_n_rh_write_done;
 extern atomic_t netfs_n_rh_write_failed;
 extern atomic_t netfs_n_rh_write_zskip;
+extern atomic_t netfs_n_wh_upload;
+extern atomic_t netfs_n_wh_upload_done;
+extern atomic_t netfs_n_wh_upload_failed;
+extern atomic_t netfs_n_wh_write;
+extern atomic_t netfs_n_wh_write_done;
+extern atomic_t netfs_n_wh_write_failed;
 
 int netfs_stats_show(struct seq_file *m, void *v);
 
diff --git a/fs/netfs/main.c b/fs/netfs/main.c
index 97ce1436615b..ab6cac110676 100644
--- a/fs/netfs/main.c
+++ b/fs/netfs/main.c
@@ -25,10 +25,11 @@ MODULE_PARM_DESC(netfs_debug, "Netfs support debugging mask");
 LIST_HEAD(netfs_io_requests);
 DEFINE_SPINLOCK(netfs_proc_lock);
 
-static const char *netfs_origins[] = {
+static const char *netfs_origins[nr__netfs_io_origin] = {
 	[NETFS_READAHEAD]	= "RA",
 	[NETFS_READPAGE]	= "RP",
 	[NETFS_READ_FOR_WRITE]	= "RW",
+	[NETFS_WRITEBACK]	= "WB",
 };
 
 /*
diff --git a/fs/netfs/objects.c b/fs/netfs/objects.c
index 4df5e5eeada6..65a17dd4ab49 100644
--- a/fs/netfs/objects.c
+++ b/fs/netfs/objects.c
@@ -20,6 +20,7 @@ struct netfs_io_request *netfs_alloc_request(struct address_space *mapping,
 	struct inode *inode = file ? file_inode(file) : mapping->host;
 	struct netfs_inode *ctx = netfs_inode(inode);
 	struct netfs_io_request *rreq;
+	bool cached = netfs_is_cache_enabled(ctx);
 	int ret;
 
 	rreq = kzalloc(ctx->ops->io_request_size ?: sizeof(struct netfs_io_request),
@@ -37,7 +38,10 @@ struct netfs_io_request *netfs_alloc_request(struct address_space *mapping,
 	rreq->debug_id	= atomic_inc_return(&debug_ids);
 	INIT_LIST_HEAD(&rreq->subrequests);
 	refcount_set(&rreq->ref, 1);
+
 	__set_bit(NETFS_RREQ_IN_PROGRESS, &rreq->flags);
+	if (cached)
+		__set_bit(NETFS_RREQ_WRITE_TO_CACHE, &rreq->flags);
 	if (rreq->netfs_ops->init_request) {
 		ret = rreq->netfs_ops->init_request(rreq, file);
 		if (ret < 0) {
@@ -46,6 +50,7 @@ struct netfs_io_request *netfs_alloc_request(struct address_space *mapping,
 		}
 	}
 
+	trace_netfs_rreq_ref(rreq->debug_id, 1, netfs_rreq_trace_new);
 	netfs_proc_add_rreq(rreq);
 	netfs_stat(&netfs_n_rh_rreq);
 	return rreq;
@@ -129,6 +134,7 @@ struct netfs_io_subrequest *netfs_alloc_subrequest(struct netfs_io_request *rreq
 			 sizeof(struct netfs_io_subrequest),
 			 GFP_KERNEL);
 	if (subreq) {
+		INIT_WORK(&subreq->work, NULL);
 		INIT_LIST_HEAD(&subreq->rreq_link);
 		refcount_set(&subreq->ref, 2);
 		subreq->rreq = rreq;
diff --git a/fs/netfs/stats.c b/fs/netfs/stats.c
index 6025dc485f7e..c1f85cd595a4 100644
--- a/fs/netfs/stats.c
+++ b/fs/netfs/stats.c
@@ -27,6 +27,12 @@ atomic_t netfs_n_rh_write_begin;
 atomic_t netfs_n_rh_write_done;
 atomic_t netfs_n_rh_write_failed;
 atomic_t netfs_n_rh_write_zskip;
+atomic_t netfs_n_wh_upload;
+atomic_t netfs_n_wh_upload_done;
+atomic_t netfs_n_wh_upload_failed;
+atomic_t netfs_n_wh_write;
+atomic_t netfs_n_wh_write_done;
+atomic_t netfs_n_wh_write_failed;
 
 int netfs_stats_show(struct seq_file *m, void *v)
 {
@@ -50,10 +56,14 @@ int netfs_stats_show(struct seq_file *m, void *v)
 		   atomic_read(&netfs_n_rh_read),
 		   atomic_read(&netfs_n_rh_read_done),
 		   atomic_read(&netfs_n_rh_read_failed));
+	seq_printf(m, "Netfs  : UL=%u us=%u uf=%u\n",
+		   atomic_read(&netfs_n_wh_upload),
+		   atomic_read(&netfs_n_wh_upload_done),
+		   atomic_read(&netfs_n_wh_upload_failed));
 	seq_printf(m, "Netfs  : WR=%u ws=%u wf=%u\n",
-		   atomic_read(&netfs_n_rh_write),
-		   atomic_read(&netfs_n_rh_write_done),
-		   atomic_read(&netfs_n_rh_write_failed));
+		   atomic_read(&netfs_n_wh_write),
+		   atomic_read(&netfs_n_wh_write_done),
+		   atomic_read(&netfs_n_wh_write_failed));
 	return fscache_stats_show(m);
 }
 EXPORT_SYMBOL(netfs_stats_show);
diff --git a/include/linux/netfs.h b/include/linux/netfs.h
index 2ece21fccb02..d08bd37bc3ce 100644
--- a/include/linux/netfs.h
+++ b/include/linux/netfs.h
@@ -118,6 +118,9 @@ enum netfs_io_source {
 	NETFS_DOWNLOAD_FROM_SERVER,
 	NETFS_READ_FROM_CACHE,
 	NETFS_INVALID_READ,
+	NETFS_UPLOAD_TO_SERVER,
+	NETFS_WRITE_TO_CACHE,
+	NETFS_INVALID_WRITE,
 } __mode(byte);
 
 typedef void (*netfs_io_terminated_t)(void *priv, ssize_t transferred_or_error,
@@ -149,9 +152,14 @@ struct netfs_cache_resources {
 };
 
 /*
- * Descriptor for a single component subrequest.
+ * Descriptor for a single component subrequest.  Each operation represents an
+ * individual read/write from/to a server, a cache, a journal, etc..
+ *
+ * The buffer iterator is persistent for the life of the subrequest struct and
+ * the pages it points to can be relied on to exist for the duration.
  */
 struct netfs_io_subrequest {
+	struct work_struct	work;
 	struct netfs_io_request *rreq;		/* Supervising I/O request */
 	struct list_head	rreq_link;	/* Link in rreq->subrequests */
 	struct iov_iter		io_iter;	/* Iterator for this subrequest */
@@ -176,6 +184,8 @@ enum netfs_io_origin {
 	NETFS_READAHEAD,		/* This read was triggered by readahead */
 	NETFS_READPAGE,			/* This read is a synchronous read */
 	NETFS_READ_FOR_WRITE,		/* This read is to prepare a write */
+	NETFS_WRITEBACK,		/* This write was triggered by writepages */
+	nr__netfs_io_origin
 } __mode(byte);
 
 /*
@@ -199,6 +209,7 @@ struct netfs_io_request {
 	__counted_by(direct_bv_count);
 	unsigned int		direct_bv_count; /* Number of elements in direct_bv[] */
 	unsigned int		debug_id;
+	unsigned int		subreq_counter;	/* Next subreq->debug_index */
 	atomic_t		nr_outstanding;	/* Number of ops in progress */
 	atomic_t		nr_copy_ops;	/* Number of copy-to-cache ops in progress */
 	size_t			submitted;	/* Amount submitted for I/O so far */
@@ -217,6 +228,8 @@ struct netfs_io_request {
 #define NETFS_RREQ_DONT_UNLOCK_FOLIOS	3	/* Don't unlock the folios on completion */
 #define NETFS_RREQ_FAILED		4	/* The request failed */
 #define NETFS_RREQ_IN_PROGRESS		5	/* Unlocked when the request completes */
+#define NETFS_RREQ_WRITE_TO_CACHE	7	/* Need to write to the cache */
+#define NETFS_RREQ_UPLOAD_TO_SERVER	8	/* Need to write to the server */
 	const struct netfs_request_ops *netfs_ops;
 };
 
diff --git a/include/trace/events/netfs.h b/include/trace/events/netfs.h
index fce6d0bc78e5..4ea4e34d279f 100644
--- a/include/trace/events/netfs.h
+++ b/include/trace/events/netfs.h
@@ -24,7 +24,8 @@
 #define netfs_rreq_origins					\
 	EM(NETFS_READAHEAD,			"RA")		\
 	EM(NETFS_READPAGE,			"RP")		\
-	E_(NETFS_READ_FOR_WRITE,		"RW")
+	EM(NETFS_READ_FOR_WRITE,		"RW")		\
+	E_(NETFS_WRITEBACK,			"WB")
 
 #define netfs_rreq_traces					\
 	EM(netfs_rreq_trace_assess,		"ASSESS ")	\
@@ -39,7 +40,10 @@
 	EM(NETFS_FILL_WITH_ZEROES,		"ZERO")		\
 	EM(NETFS_DOWNLOAD_FROM_SERVER,		"DOWN")		\
 	EM(NETFS_READ_FROM_CACHE,		"READ")		\
-	E_(NETFS_INVALID_READ,			"INVL")		\
+	EM(NETFS_INVALID_READ,			"INVL")		\
+	EM(NETFS_UPLOAD_TO_SERVER,		"UPLD")		\
+	EM(NETFS_WRITE_TO_CACHE,		"WRIT")		\
+	E_(NETFS_INVALID_WRITE,			"INVL")
 
 #define netfs_sreq_traces					\
 	EM(netfs_sreq_trace_download_instead,	"RDOWN")	\


  parent reply	other threads:[~2023-12-21 13:25 UTC|newest]

Thread overview: 75+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-21 13:22 [PATCH v5 00/40] netfs, afs, 9p: Delegate high-level I/O to netfslib David Howells
2023-12-21 13:22 ` [PATCH v5 01/40] afs: Remove whitespace before most ')' from the trace header David Howells
2023-12-21 13:22 ` [PATCH v5 02/40] afs: Automatically generate trace tag enums David Howells
2023-12-21 13:22 ` [PATCH v5 03/40] netfs, fscache: Move fs/fscache/* into fs/netfs/ David Howells
2023-12-21 13:22 ` [PATCH v5 04/40] netfs, fscache: Combine fscache with netfs David Howells
2023-12-21 13:23 ` [PATCH v5 05/40] netfs, fscache: Remove ->begin_cache_operation David Howells
2023-12-21 13:23 ` [PATCH v5 06/40] netfs, fscache: Move /proc/fs/fscache to /proc/fs/netfs and put in a symlink David Howells
2024-01-03 16:49   ` Marc Dionne
2023-12-21 13:23 ` [PATCH v5 07/40] netfs: Move pinning-for-writeback from fscache to netfs David Howells
2023-12-21 13:23 ` [PATCH v5 08/40] netfs: Add a procfile to list in-progress requests David Howells
2023-12-21 13:23 ` [PATCH v5 09/40] netfs: Allow the netfs to make the io (sub)request alloc larger David Howells
2023-12-21 13:23 ` [PATCH v5 10/40] netfs: Add a ->free_subrequest() op David Howells
2023-12-21 13:23 ` [PATCH v5 11/40] afs: Don't use folio->private to record partial modification David Howells
2023-12-21 13:23 ` [PATCH v5 12/40] netfs: Provide invalidate_folio and release_folio calls David Howells
2023-12-21 13:23 ` [PATCH v5 13/40] netfs: Implement unbuffered/DIO vs buffered I/O locking David Howells
2023-12-21 13:23 ` [PATCH v5 14/40] netfs: Add iov_iters to (sub)requests to describe various buffers David Howells
2023-12-21 13:23 ` [PATCH v5 15/40] netfs: Add support for DIO buffering David Howells
2023-12-26 16:54   ` Nathan Chancellor
2023-12-28 10:47     ` Christian Brauner
2023-12-28 16:58       ` Nathan Chancellor
2023-12-21 13:23 ` [PATCH v5 16/40] netfs: Provide tools to create a buffer in an xarray David Howells
2023-12-21 13:23 ` [PATCH v5 17/40] netfs: Add func to calculate pagecount/size-limited span of an iterator David Howells
2023-12-21 13:23 ` [PATCH v5 18/40] netfs: Limit subrequest by size or number of segments David Howells
2023-12-21 13:23 ` David Howells [this message]
2023-12-21 13:23 ` [PATCH v5 20/40] netfs: Add a hook to allow tell the netfs to update its i_size David Howells
2023-12-21 13:23 ` [PATCH v5 21/40] netfs: Make netfs_put_request() handle a NULL pointer David Howells
2023-12-21 13:23 ` [PATCH v5 22/40] netfs: Make the refcounting of netfs_begin_read() easier to use David Howells
2023-12-21 13:23 ` [PATCH v5 23/40] netfs: Prep to use folio->private for write grouping and streaming write David Howells
2023-12-21 13:23 ` [PATCH v5 24/40] netfs: Dispatch write requests to process a writeback slice David Howells
2023-12-21 13:23 ` [PATCH v5 25/40] netfs: Provide func to copy data to pagecache for buffered write David Howells
2023-12-21 13:23 ` [PATCH v5 26/40] netfs: Make netfs_read_folio() handle streaming-write pages David Howells
2023-12-21 13:23 ` [PATCH v5 27/40] netfs: Allocate multipage folios in the writepath David Howells
2023-12-21 13:23 ` [PATCH v5 28/40] netfs: Implement unbuffered/DIO read support David Howells
2023-12-21 13:23 ` [PATCH v5 29/40] netfs: Implement unbuffered/DIO write support David Howells
2023-12-21 13:23 ` [PATCH v5 30/40] netfs: Implement buffered write API David Howells
2023-12-21 13:23 ` [PATCH v5 31/40] netfs: Allow buffered shared-writeable mmap through netfs_page_mkwrite() David Howells
2023-12-21 13:23 ` [PATCH v5 32/40] netfs: Provide netfs_file_read_iter() David Howells
2023-12-21 13:23 ` [PATCH v5 33/40] netfs, cachefiles: Pass upper bound length to allow expansion David Howells
2024-01-02 14:04   ` Gao Xiang
2024-01-02 17:11   ` David Howells
2024-01-02 20:37     ` Gao Xiang
2024-01-03 10:15     ` Jia Zhu
2023-12-21 13:23 ` [PATCH v5 34/40] netfs: Provide a writepages implementation David Howells
2023-12-21 13:23 ` [PATCH v5 35/40] netfs: Provide a launder_folio implementation David Howells
2023-12-21 13:23 ` [PATCH v5 36/40] netfs: Implement a write-through caching option David Howells
2023-12-21 13:23 ` [PATCH v5 37/40] netfs: Optimise away reads above the point at which there can be no data David Howells
2023-12-21 23:01   ` Nathan Chancellor
2023-12-22 11:49   ` David Howells
2023-12-22 12:00   ` [PATCH] Fix oops in NFS David Howells
2024-01-05  4:52     ` Matthew Wilcox
2024-01-05 10:12     ` David Howells
2024-01-05 13:17       ` Matthew Wilcox
2024-01-05 17:20         ` Dominique Martinet
2024-01-05 11:48     ` David Howells
2024-01-05 14:33     ` David Howells
2023-12-21 13:23 ` [PATCH v5 38/40] netfs: Export the netfs_sreq tracepoint David Howells
2023-12-21 13:23 ` [PATCH v5 39/40] afs: Use the netfs write helpers David Howells
2023-12-21 13:23 ` [PATCH v5 40/40] 9p: Use netfslib read/write_iter David Howells
2024-01-03  7:22   ` Dominique Martinet
2024-01-03 19:52     ` Eric Van Hensbergen
2024-01-03 12:08   ` David Howells
2024-01-03 12:39   ` David Howells
2024-01-03 13:00     ` Dominique Martinet
2024-05-09 17:15   ` Andrea Righi
2024-05-09 21:33   ` David Howells
2024-05-10  5:53     ` Andrea Righi
2024-05-10  7:57     ` David Howells
2023-12-22 13:02 ` [PATCH] Fix EROFS Kconfig David Howells
2023-12-23  3:55   ` Jingbo Xu
2023-12-23 13:32     ` Gao Xiang
2024-01-02 15:39 ` [PATCH v5 40/40] 9p: Use netfslib read/write_iter David Howells
2024-01-02 21:49 ` [PATCH] 9p: Fix initialisation of netfs_inode for 9p David Howells
2024-01-03 13:10   ` Dominique Martinet
2024-01-03 13:59   ` David Howells
2024-01-03 14:04   ` David Howells

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231221132400.1601991-20-dhowells@redhat.com \
    --to=dhowells@redhat.com \
    --cc=asmadeus@codewreck.org \
    --cc=ceph-devel@vger.kernel.org \
    --cc=christian@brauner.io \
    --cc=ericvh@kernel.org \
    --cc=idryomov@gmail.com \
    --cc=jlayton@kernel.org \
    --cc=linux-afs@lists.infradead.org \
    --cc=linux-cachefs@redhat.com \
    --cc=linux-cifs@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=marc.dionne@auristor.com \
    --cc=netdev@vger.kernel.org \
    --cc=pc@manguebit.com \
    --cc=smfrench@gmail.com \
    --cc=sprasad@microsoft.com \
    --cc=tom@talpey.com \
    --cc=v9fs@lists.linux.dev \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).