Skip to content

Commit 1a6d45f

Browse files
dhowellsbrauner
authored andcommitted
netfs: Provide helpers to perform NETFS_RREQ_IN_PROGRESS flag wangling
Provide helpers to clear and test the NETFS_RREQ_IN_PROGRESS and to insert the appropriate barrierage. Signed-off-by: David Howells <[email protected]> Link: https://lore.kernel.org/[email protected] Tested-by: Steve French <[email protected]> Reviewed-by: Paulo Alcantara <[email protected]> cc: [email protected] cc: [email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent 9df7b5e commit 1a6d45f

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

fs/netfs/internal.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,24 @@ static inline void netfs_wake_rreq_flag(struct netfs_io_request *rreq,
274274
}
275275
}
276276

277+
/*
278+
* Test the NETFS_RREQ_IN_PROGRESS flag, inserting an appropriate barrier.
279+
*/
280+
static inline bool netfs_check_rreq_in_progress(const struct netfs_io_request *rreq)
281+
{
282+
/* Order read of flags before read of anything else, such as error. */
283+
return test_bit_acquire(NETFS_RREQ_IN_PROGRESS, &rreq->flags);
284+
}
285+
286+
/*
287+
* Test the NETFS_SREQ_IN_PROGRESS flag, inserting an appropriate barrier.
288+
*/
289+
static inline bool netfs_check_subreq_in_progress(const struct netfs_io_subrequest *subreq)
290+
{
291+
/* Order read of flags before read of anything else, such as error. */
292+
return test_bit_acquire(NETFS_SREQ_IN_PROGRESS, &subreq->flags);
293+
}
294+
277295
/*
278296
* fscache-cache.c
279297
*/

fs/netfs/misc.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -356,14 +356,14 @@ void netfs_wait_for_in_progress_stream(struct netfs_io_request *rreq,
356356
DEFINE_WAIT(myself);
357357

358358
list_for_each_entry(subreq, &stream->subrequests, rreq_link) {
359-
if (!test_bit(NETFS_SREQ_IN_PROGRESS, &subreq->flags))
359+
if (!netfs_check_subreq_in_progress(subreq))
360360
continue;
361361

362362
trace_netfs_rreq(rreq, netfs_rreq_trace_wait_queue);
363363
for (;;) {
364364
prepare_to_wait(&rreq->waitq, &myself, TASK_UNINTERRUPTIBLE);
365365

366-
if (!test_bit(NETFS_SREQ_IN_PROGRESS, &subreq->flags))
366+
if (!netfs_check_subreq_in_progress(subreq))
367367
break;
368368

369369
trace_netfs_sreq(subreq, netfs_sreq_trace_wait_for);
@@ -400,7 +400,7 @@ static int netfs_collect_in_app(struct netfs_io_request *rreq,
400400
struct netfs_io_subrequest,
401401
rreq_link);
402402
if (subreq &&
403-
(!test_bit(NETFS_SREQ_IN_PROGRESS, &subreq->flags) ||
403+
(!netfs_check_subreq_in_progress(subreq) ||
404404
test_bit(NETFS_SREQ_MADE_PROGRESS, &subreq->flags))) {
405405
need_collect = true;
406406
break;
@@ -451,7 +451,7 @@ static ssize_t netfs_wait_for_request(struct netfs_io_request *rreq,
451451
}
452452
}
453453

454-
if (!test_bit(NETFS_RREQ_IN_PROGRESS, &rreq->flags))
454+
if (!netfs_check_rreq_in_progress(rreq))
455455
break;
456456

457457
schedule();
@@ -518,7 +518,7 @@ static void netfs_wait_for_pause(struct netfs_io_request *rreq,
518518
}
519519
}
520520

521-
if (!test_bit(NETFS_RREQ_IN_PROGRESS, &rreq->flags) ||
521+
if (!netfs_check_rreq_in_progress(rreq) ||
522522
!test_bit(NETFS_RREQ_PAUSE, &rreq->flags))
523523
break;
524524

fs/netfs/read_collect.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ static void netfs_collect_read_results(struct netfs_io_request *rreq)
218218
stream->collected_to = front->start;
219219
}
220220

221-
if (test_bit(NETFS_SREQ_IN_PROGRESS, &front->flags))
221+
if (netfs_check_subreq_in_progress(front))
222222
notes |= HIT_PENDING;
223223
smp_rmb(); /* Read counters after IN_PROGRESS flag. */
224224
transferred = READ_ONCE(front->transferred);
@@ -445,7 +445,7 @@ void netfs_read_collection_worker(struct work_struct *work)
445445
struct netfs_io_request *rreq = container_of(work, struct netfs_io_request, work);
446446

447447
netfs_see_request(rreq, netfs_rreq_trace_see_work);
448-
if (test_bit(NETFS_RREQ_IN_PROGRESS, &rreq->flags)) {
448+
if (netfs_check_rreq_in_progress(rreq)) {
449449
if (netfs_read_collection(rreq))
450450
/* Drop the ref from the IN_PROGRESS flag. */
451451
netfs_put_request(rreq, netfs_rreq_trace_put_work_ip);

fs/netfs/write_collect.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ static void netfs_collect_write_results(struct netfs_io_request *wreq)
240240
}
241241

242242
/* Stall if the front is still undergoing I/O. */
243-
if (test_bit(NETFS_SREQ_IN_PROGRESS, &front->flags)) {
243+
if (netfs_check_subreq_in_progress(front)) {
244244
notes |= HIT_PENDING;
245245
break;
246246
}
@@ -434,7 +434,7 @@ void netfs_write_collection_worker(struct work_struct *work)
434434
struct netfs_io_request *rreq = container_of(work, struct netfs_io_request, work);
435435

436436
netfs_see_request(rreq, netfs_rreq_trace_see_work);
437-
if (test_bit(NETFS_RREQ_IN_PROGRESS, &rreq->flags)) {
437+
if (netfs_check_rreq_in_progress(rreq)) {
438438
if (netfs_write_collection(rreq))
439439
/* Drop the ref from the IN_PROGRESS flag. */
440440
netfs_put_request(rreq, netfs_rreq_trace_put_work_ip);

0 commit comments

Comments
 (0)