Skip to content

Commit 16af134

Browse files
committed
netfs: Extend the netfs_io_*request structs to handle writes
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 <[email protected]> Reviewed-by: Jeff Layton <[email protected]> cc: [email protected] cc: [email protected] cc: [email protected]
1 parent 768ddb1 commit 16af134

File tree

6 files changed

+47
-7
lines changed

6 files changed

+47
-7
lines changed

fs/netfs/internal.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ extern atomic_t netfs_n_rh_write_begin;
110110
extern atomic_t netfs_n_rh_write_done;
111111
extern atomic_t netfs_n_rh_write_failed;
112112
extern atomic_t netfs_n_rh_write_zskip;
113+
extern atomic_t netfs_n_wh_upload;
114+
extern atomic_t netfs_n_wh_upload_done;
115+
extern atomic_t netfs_n_wh_upload_failed;
116+
extern atomic_t netfs_n_wh_write;
117+
extern atomic_t netfs_n_wh_write_done;
118+
extern atomic_t netfs_n_wh_write_failed;
113119

114120
int netfs_stats_show(struct seq_file *m, void *v);
115121

fs/netfs/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ MODULE_PARM_DESC(netfs_debug, "Netfs support debugging mask");
2525
LIST_HEAD(netfs_io_requests);
2626
DEFINE_SPINLOCK(netfs_proc_lock);
2727

28-
static const char *netfs_origins[] = {
28+
static const char *netfs_origins[nr__netfs_io_origin] = {
2929
[NETFS_READAHEAD] = "RA",
3030
[NETFS_READPAGE] = "RP",
3131
[NETFS_READ_FOR_WRITE] = "RW",
32+
[NETFS_WRITEBACK] = "WB",
3233
};
3334

3435
/*

fs/netfs/objects.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ struct netfs_io_request *netfs_alloc_request(struct address_space *mapping,
2020
struct inode *inode = file ? file_inode(file) : mapping->host;
2121
struct netfs_inode *ctx = netfs_inode(inode);
2222
struct netfs_io_request *rreq;
23+
bool cached = netfs_is_cache_enabled(ctx);
2324
int ret;
2425

2526
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,
3738
rreq->debug_id = atomic_inc_return(&debug_ids);
3839
INIT_LIST_HEAD(&rreq->subrequests);
3940
refcount_set(&rreq->ref, 1);
41+
4042
__set_bit(NETFS_RREQ_IN_PROGRESS, &rreq->flags);
43+
if (cached)
44+
__set_bit(NETFS_RREQ_WRITE_TO_CACHE, &rreq->flags);
4145
if (rreq->netfs_ops->init_request) {
4246
ret = rreq->netfs_ops->init_request(rreq, file);
4347
if (ret < 0) {
@@ -46,6 +50,7 @@ struct netfs_io_request *netfs_alloc_request(struct address_space *mapping,
4650
}
4751
}
4852

53+
trace_netfs_rreq_ref(rreq->debug_id, 1, netfs_rreq_trace_new);
4954
netfs_proc_add_rreq(rreq);
5055
netfs_stat(&netfs_n_rh_rreq);
5156
return rreq;
@@ -129,6 +134,7 @@ struct netfs_io_subrequest *netfs_alloc_subrequest(struct netfs_io_request *rreq
129134
sizeof(struct netfs_io_subrequest),
130135
GFP_KERNEL);
131136
if (subreq) {
137+
INIT_WORK(&subreq->work, NULL);
132138
INIT_LIST_HEAD(&subreq->rreq_link);
133139
refcount_set(&subreq->ref, 2);
134140
subreq->rreq = rreq;

fs/netfs/stats.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ atomic_t netfs_n_rh_write_begin;
2727
atomic_t netfs_n_rh_write_done;
2828
atomic_t netfs_n_rh_write_failed;
2929
atomic_t netfs_n_rh_write_zskip;
30+
atomic_t netfs_n_wh_upload;
31+
atomic_t netfs_n_wh_upload_done;
32+
atomic_t netfs_n_wh_upload_failed;
33+
atomic_t netfs_n_wh_write;
34+
atomic_t netfs_n_wh_write_done;
35+
atomic_t netfs_n_wh_write_failed;
3036

3137
int netfs_stats_show(struct seq_file *m, void *v)
3238
{
@@ -50,10 +56,14 @@ int netfs_stats_show(struct seq_file *m, void *v)
5056
atomic_read(&netfs_n_rh_read),
5157
atomic_read(&netfs_n_rh_read_done),
5258
atomic_read(&netfs_n_rh_read_failed));
59+
seq_printf(m, "Netfs : UL=%u us=%u uf=%u\n",
60+
atomic_read(&netfs_n_wh_upload),
61+
atomic_read(&netfs_n_wh_upload_done),
62+
atomic_read(&netfs_n_wh_upload_failed));
5363
seq_printf(m, "Netfs : WR=%u ws=%u wf=%u\n",
54-
atomic_read(&netfs_n_rh_write),
55-
atomic_read(&netfs_n_rh_write_done),
56-
atomic_read(&netfs_n_rh_write_failed));
64+
atomic_read(&netfs_n_wh_write),
65+
atomic_read(&netfs_n_wh_write_done),
66+
atomic_read(&netfs_n_wh_write_failed));
5767
return fscache_stats_show(m);
5868
}
5969
EXPORT_SYMBOL(netfs_stats_show);

include/linux/netfs.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ enum netfs_io_source {
118118
NETFS_DOWNLOAD_FROM_SERVER,
119119
NETFS_READ_FROM_CACHE,
120120
NETFS_INVALID_READ,
121+
NETFS_UPLOAD_TO_SERVER,
122+
NETFS_WRITE_TO_CACHE,
123+
NETFS_INVALID_WRITE,
121124
} __mode(byte);
122125

123126
typedef void (*netfs_io_terminated_t)(void *priv, ssize_t transferred_or_error,
@@ -149,9 +152,14 @@ struct netfs_cache_resources {
149152
};
150153

151154
/*
152-
* Descriptor for a single component subrequest.
155+
* Descriptor for a single component subrequest. Each operation represents an
156+
* individual read/write from/to a server, a cache, a journal, etc..
157+
*
158+
* The buffer iterator is persistent for the life of the subrequest struct and
159+
* the pages it points to can be relied on to exist for the duration.
153160
*/
154161
struct netfs_io_subrequest {
162+
struct work_struct work;
155163
struct netfs_io_request *rreq; /* Supervising I/O request */
156164
struct list_head rreq_link; /* Link in rreq->subrequests */
157165
struct iov_iter io_iter; /* Iterator for this subrequest */
@@ -176,6 +184,8 @@ enum netfs_io_origin {
176184
NETFS_READAHEAD, /* This read was triggered by readahead */
177185
NETFS_READPAGE, /* This read is a synchronous read */
178186
NETFS_READ_FOR_WRITE, /* This read is to prepare a write */
187+
NETFS_WRITEBACK, /* This write was triggered by writepages */
188+
nr__netfs_io_origin
179189
} __mode(byte);
180190

181191
/*
@@ -198,6 +208,7 @@ struct netfs_io_request {
198208
struct bio_vec *direct_bv; /* DIO buffer list (when handling iovec-iter) */
199209
unsigned int direct_bv_count; /* Number of elements in direct_bv[] */
200210
unsigned int debug_id;
211+
unsigned int subreq_counter; /* Next subreq->debug_index */
201212
atomic_t nr_outstanding; /* Number of ops in progress */
202213
atomic_t nr_copy_ops; /* Number of copy-to-cache ops in progress */
203214
size_t submitted; /* Amount submitted for I/O so far */
@@ -216,6 +227,8 @@ struct netfs_io_request {
216227
#define NETFS_RREQ_DONT_UNLOCK_FOLIOS 3 /* Don't unlock the folios on completion */
217228
#define NETFS_RREQ_FAILED 4 /* The request failed */
218229
#define NETFS_RREQ_IN_PROGRESS 5 /* Unlocked when the request completes */
230+
#define NETFS_RREQ_WRITE_TO_CACHE 7 /* Need to write to the cache */
231+
#define NETFS_RREQ_UPLOAD_TO_SERVER 8 /* Need to write to the server */
219232
const struct netfs_request_ops *netfs_ops;
220233
};
221234

include/trace/events/netfs.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
#define netfs_rreq_origins \
2525
EM(NETFS_READAHEAD, "RA") \
2626
EM(NETFS_READPAGE, "RP") \
27-
E_(NETFS_READ_FOR_WRITE, "RW")
27+
EM(NETFS_READ_FOR_WRITE, "RW") \
28+
E_(NETFS_WRITEBACK, "WB")
2829

2930
#define netfs_rreq_traces \
3031
EM(netfs_rreq_trace_assess, "ASSESS ") \
@@ -39,7 +40,10 @@
3940
EM(NETFS_FILL_WITH_ZEROES, "ZERO") \
4041
EM(NETFS_DOWNLOAD_FROM_SERVER, "DOWN") \
4142
EM(NETFS_READ_FROM_CACHE, "READ") \
42-
E_(NETFS_INVALID_READ, "INVL") \
43+
EM(NETFS_INVALID_READ, "INVL") \
44+
EM(NETFS_UPLOAD_TO_SERVER, "UPLD") \
45+
EM(NETFS_WRITE_TO_CACHE, "WRIT") \
46+
E_(NETFS_INVALID_WRITE, "INVL")
4347

4448
#define netfs_sreq_traces \
4549
EM(netfs_sreq_trace_download_instead, "RDOWN") \

0 commit comments

Comments
 (0)