Skip to content

Commit 0e764b9

Browse files
dhowellsbrauner
authored andcommitted
netfs: Fix the handling of stream->front by removing it
The netfs_io_stream::front member is meant to point to the subrequest currently being collected on a stream, but it isn't actually used this way by direct write (which mostly ignores it). However, there's a tracepoint which looks at it. Further, stream->front is actually redundant with stream->subrequests.next. Fix the potential problem in the direct code by just removing the member and using stream->subrequests.next instead, thereby also simplifying the code. Fixes: a0b4c7a ("netfs: Fix unbuffered/DIO writes to dispatch subrequests in strict sequence") Reported-by: Paulo Alcantara <[email protected]> Signed-off-by: David Howells <[email protected]> Link: https://patch.msgid.link/[email protected] Reviewed-by: Paulo Alcantara (Red Hat) <[email protected]> cc: [email protected] cc: [email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent f621324 commit 0e764b9

9 files changed

Lines changed: 11 additions & 17 deletions

File tree

fs/netfs/buffered_read.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,8 @@ static void netfs_queue_read(struct netfs_io_request *rreq,
171171
spin_lock(&rreq->lock);
172172
list_add_tail(&subreq->rreq_link, &stream->subrequests);
173173
if (list_is_first(&subreq->rreq_link, &stream->subrequests)) {
174-
stream->front = subreq;
175174
if (!stream->active) {
176-
stream->collected_to = stream->front->start;
175+
stream->collected_to = subreq->start;
177176
/* Store list pointers before active flag */
178177
smp_store_release(&stream->active, true);
179178
}

fs/netfs/direct_read.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,8 @@ static int netfs_dispatch_unbuffered_reads(struct netfs_io_request *rreq)
7171
spin_lock(&rreq->lock);
7272
list_add_tail(&subreq->rreq_link, &stream->subrequests);
7373
if (list_is_first(&subreq->rreq_link, &stream->subrequests)) {
74-
stream->front = subreq;
7574
if (!stream->active) {
76-
stream->collected_to = stream->front->start;
75+
stream->collected_to = subreq->start;
7776
/* Store list pointers before active flag */
7877
smp_store_release(&stream->active, true);
7978
}

fs/netfs/direct_write.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ static int netfs_unbuffered_write(struct netfs_io_request *wreq)
111111
netfs_prepare_write(wreq, stream, wreq->start + wreq->transferred);
112112
subreq = stream->construct;
113113
stream->construct = NULL;
114-
stream->front = NULL;
115114
}
116115

117116
/* Check if (re-)preparation failed. */

fs/netfs/read_collect.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ static void netfs_collect_read_results(struct netfs_io_request *rreq)
205205
* in progress. The issuer thread may be adding stuff to the tail
206206
* whilst we're doing this.
207207
*/
208-
front = READ_ONCE(stream->front);
208+
front = list_first_entry_or_null(&stream->subrequests,
209+
struct netfs_io_subrequest, rreq_link);
209210
while (front) {
210211
size_t transferred;
211212

@@ -301,7 +302,6 @@ static void netfs_collect_read_results(struct netfs_io_request *rreq)
301302
list_del_init(&front->rreq_link);
302303
front = list_first_entry_or_null(&stream->subrequests,
303304
struct netfs_io_subrequest, rreq_link);
304-
stream->front = front;
305305
spin_unlock(&rreq->lock);
306306
netfs_put_subrequest(remove,
307307
notes & ABANDON_SREQ ?

fs/netfs/read_single.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ static int netfs_single_dispatch_read(struct netfs_io_request *rreq)
107107
spin_lock(&rreq->lock);
108108
list_add_tail(&subreq->rreq_link, &stream->subrequests);
109109
trace_netfs_sreq(subreq, netfs_sreq_trace_added);
110-
stream->front = subreq;
111110
/* Store list pointers before active flag */
112111
smp_store_release(&stream->active, true);
113112
spin_unlock(&rreq->lock);

fs/netfs/write_collect.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ static void netfs_collect_write_results(struct netfs_io_request *wreq)
228228
if (!smp_load_acquire(&stream->active))
229229
continue;
230230

231-
front = stream->front;
231+
front = list_first_entry_or_null(&stream->subrequests,
232+
struct netfs_io_subrequest, rreq_link);
232233
while (front) {
233234
trace_netfs_collect_sreq(wreq, front);
234235
//_debug("sreq [%x] %llx %zx/%zx",
@@ -279,7 +280,6 @@ static void netfs_collect_write_results(struct netfs_io_request *wreq)
279280
list_del_init(&front->rreq_link);
280281
front = list_first_entry_or_null(&stream->subrequests,
281282
struct netfs_io_subrequest, rreq_link);
282-
stream->front = front;
283283
spin_unlock(&wreq->lock);
284284
netfs_put_subrequest(remove,
285285
notes & SAW_FAILURE ?

fs/netfs/write_issue.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,8 @@ void netfs_prepare_write(struct netfs_io_request *wreq,
206206
spin_lock(&wreq->lock);
207207
list_add_tail(&subreq->rreq_link, &stream->subrequests);
208208
if (list_is_first(&subreq->rreq_link, &stream->subrequests)) {
209-
stream->front = subreq;
210209
if (!stream->active) {
211-
stream->collected_to = stream->front->start;
210+
stream->collected_to = subreq->start;
212211
/* Write list pointers before active flag */
213212
smp_store_release(&stream->active, true);
214213
}

include/linux/netfs.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ struct netfs_io_stream {
140140
void (*issue_write)(struct netfs_io_subrequest *subreq);
141141
/* Collection tracking */
142142
struct list_head subrequests; /* Contributory I/O operations */
143-
struct netfs_io_subrequest *front; /* Op being collected */
144143
unsigned long long collected_to; /* Position we've collected results to */
145144
size_t transferred; /* The amount transferred from this stream */
146145
unsigned short error; /* Aggregate error for the stream */

include/trace/events/netfs.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -740,19 +740,19 @@ TRACE_EVENT(netfs_collect_stream,
740740
__field(unsigned int, wreq)
741741
__field(unsigned char, stream)
742742
__field(unsigned long long, collected_to)
743-
__field(unsigned long long, front)
743+
__field(unsigned long long, issued_to)
744744
),
745745

746746
TP_fast_assign(
747747
__entry->wreq = wreq->debug_id;
748748
__entry->stream = stream->stream_nr;
749749
__entry->collected_to = stream->collected_to;
750-
__entry->front = stream->front ? stream->front->start : UINT_MAX;
750+
__entry->issued_to = atomic64_read(&wreq->issued_to);
751751
),
752752

753-
TP_printk("R=%08x[%x:] cto=%llx frn=%llx",
753+
TP_printk("R=%08x[%x:] cto=%llx ito=%llx",
754754
__entry->wreq, __entry->stream,
755-
__entry->collected_to, __entry->front)
755+
__entry->collected_to, __entry->issued_to)
756756
);
757757

758758
TRACE_EVENT(netfs_folioq,

0 commit comments

Comments
 (0)